|
|
5ce0c7 |
From 3b4082b239ec0976b366293067e42f91d56cfcd5 Mon Sep 17 00:00:00 2001
|
|
|
5ce0c7 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
5ce0c7 |
Date: Thu, 6 Feb 2020 10:15:29 +0000
|
|
|
5ce0c7 |
Subject: [PATCH] ocaml: Use caml_alloc_initialized_string instead of memcpy.
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
Since about 2017 OCaml has had a function for creating an initialized
|
|
|
5ce0c7 |
string. This uses the function instead of caml_alloc_string + memcpy
|
|
|
5ce0c7 |
(which doesn't work for OCaml 4.10) and defines a replacement if the
|
|
|
5ce0c7 |
function is missing.
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
Note this requires configure.ac in libguestfs.git and virt-v2v.git to
|
|
|
5ce0c7 |
define HAVE_CAML_ALLOC_INITIALIZED_STRING.
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
(cherry picked from commit 398dc56a6cb5d6d01506338fa94ef580e668d5e9)
|
|
|
5ce0c7 |
---
|
|
|
5ce0c7 |
common/mlpcre/pcre-c.c | 16 ++++++++++++++--
|
|
|
5ce0c7 |
common/mlvisit/visit-c.c | 16 ++++++++++++++--
|
|
|
5ce0c7 |
common/mlxml/xml-c.c | 16 ++++++++++++++--
|
|
|
5ce0c7 |
3 files changed, 42 insertions(+), 6 deletions(-)
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
diff --git a/common/mlpcre/pcre-c.c b/common/mlpcre/pcre-c.c
|
|
|
5ce0c7 |
index 07f99b8d6..7dbba5857 100644
|
|
|
5ce0c7 |
--- a/common/mlpcre/pcre-c.c
|
|
|
5ce0c7 |
+++ b/common/mlpcre/pcre-c.c
|
|
|
5ce0c7 |
@@ -39,6 +39,19 @@
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
+/* Replacement if caml_alloc_initialized_string is missing, added
|
|
|
5ce0c7 |
+ * to OCaml runtime in 2017.
|
|
|
5ce0c7 |
+ */
|
|
|
5ce0c7 |
+#ifndef HAVE_CAML_ALLOC_INITIALIZED_STRING
|
|
|
5ce0c7 |
+static inline value
|
|
|
5ce0c7 |
+caml_alloc_initialized_string (mlsize_t len, const char *p)
|
|
|
5ce0c7 |
+{
|
|
|
5ce0c7 |
+ value sv = caml_alloc_string (len);
|
|
|
5ce0c7 |
+ memcpy ((char *) String_val (sv), p, len);
|
|
|
5ce0c7 |
+ return sv;
|
|
|
5ce0c7 |
+}
|
|
|
5ce0c7 |
+#endif
|
|
|
5ce0c7 |
+
|
|
|
5ce0c7 |
/* Data on the most recent match is stored in this thread-local
|
|
|
5ce0c7 |
* variable. It is freed either by the next call to PCRE.matches or
|
|
|
5ce0c7 |
* by (clean) thread exit.
|
|
|
5ce0c7 |
@@ -257,8 +270,7 @@ guestfs_int_pcre_sub (value nv)
|
|
|
5ce0c7 |
if (len < 0)
|
|
|
5ce0c7 |
raise_pcre_error ("pcre_get_substring", len);
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
- strv = caml_alloc_string (len);
|
|
|
5ce0c7 |
- memcpy (String_val (strv), str, len);
|
|
|
5ce0c7 |
+ strv = caml_alloc_initialized_string (len, str);
|
|
|
5ce0c7 |
CAMLreturn (strv);
|
|
|
5ce0c7 |
}
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
diff --git a/common/mlvisit/visit-c.c b/common/mlvisit/visit-c.c
|
|
|
5ce0c7 |
index 201f6d762..d5585ca94 100644
|
|
|
5ce0c7 |
--- a/common/mlvisit/visit-c.c
|
|
|
5ce0c7 |
+++ b/common/mlvisit/visit-c.c
|
|
|
5ce0c7 |
@@ -35,6 +35,19 @@
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
+/* Replacement if caml_alloc_initialized_string is missing, added
|
|
|
5ce0c7 |
+ * to OCaml runtime in 2017.
|
|
|
5ce0c7 |
+ */
|
|
|
5ce0c7 |
+#ifndef HAVE_CAML_ALLOC_INITIALIZED_STRING
|
|
|
5ce0c7 |
+static inline value
|
|
|
5ce0c7 |
+caml_alloc_initialized_string (mlsize_t len, const char *p)
|
|
|
5ce0c7 |
+{
|
|
|
5ce0c7 |
+ value sv = caml_alloc_string (len);
|
|
|
5ce0c7 |
+ memcpy ((char *) String_val (sv), p, len);
|
|
|
5ce0c7 |
+ return sv;
|
|
|
5ce0c7 |
+}
|
|
|
5ce0c7 |
+#endif
|
|
|
5ce0c7 |
+
|
|
|
5ce0c7 |
struct visitor_function_wrapper_args {
|
|
|
5ce0c7 |
/* In both case we are pointing to local roots, hence why these are
|
|
|
5ce0c7 |
* value* not value.
|
|
|
5ce0c7 |
@@ -198,8 +211,7 @@ copy_xattr (const struct guestfs_xattr *xattr)
|
|
|
5ce0c7 |
rv = caml_alloc (2, 0);
|
|
|
5ce0c7 |
v = caml_copy_string (xattr->attrname);
|
|
|
5ce0c7 |
Store_field (rv, 0, v);
|
|
|
5ce0c7 |
- v = caml_alloc_string (xattr->attrval_len);
|
|
|
5ce0c7 |
- memcpy (String_val (v), xattr->attrval, xattr->attrval_len);
|
|
|
5ce0c7 |
+ v = caml_alloc_initialized_string (xattr->attrval_len, xattr->attrval);
|
|
|
5ce0c7 |
Store_field (rv, 1, v);
|
|
|
5ce0c7 |
CAMLreturn (rv);
|
|
|
5ce0c7 |
}
|
|
|
5ce0c7 |
diff --git a/common/mlxml/xml-c.c b/common/mlxml/xml-c.c
|
|
|
5ce0c7 |
index d3db7e227..a0fa0fc3d 100644
|
|
|
5ce0c7 |
--- a/common/mlxml/xml-c.c
|
|
|
5ce0c7 |
+++ b/common/mlxml/xml-c.c
|
|
|
5ce0c7 |
@@ -40,6 +40,19 @@
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
+/* Replacement if caml_alloc_initialized_string is missing, added
|
|
|
5ce0c7 |
+ * to OCaml runtime in 2017.
|
|
|
5ce0c7 |
+ */
|
|
|
5ce0c7 |
+#ifndef HAVE_CAML_ALLOC_INITIALIZED_STRING
|
|
|
5ce0c7 |
+static inline value
|
|
|
5ce0c7 |
+caml_alloc_initialized_string (mlsize_t len, const char *p)
|
|
|
5ce0c7 |
+{
|
|
|
5ce0c7 |
+ value sv = caml_alloc_string (len);
|
|
|
5ce0c7 |
+ memcpy ((char *) String_val (sv), p, len);
|
|
|
5ce0c7 |
+ return sv;
|
|
|
5ce0c7 |
+}
|
|
|
5ce0c7 |
+#endif
|
|
|
5ce0c7 |
+
|
|
|
5ce0c7 |
/* xmlDocPtr type */
|
|
|
5ce0c7 |
#define docptr_val(v) (*((xmlDocPtr *)Data_custom_val(v)))
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
@@ -183,8 +196,7 @@ mllib_xml_to_string (value docv, value formatv)
|
|
|
5ce0c7 |
doc = docptr_val (docv);
|
|
|
5ce0c7 |
xmlDocDumpFormatMemory (doc, &mem, &size, Bool_val (formatv));
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
- strv = caml_alloc_string (size);
|
|
|
5ce0c7 |
- memcpy (String_val (strv), mem, size);
|
|
|
5ce0c7 |
+ strv = caml_alloc_initialized_string (size, mem);
|
|
|
5ce0c7 |
free (mem);
|
|
|
5ce0c7 |
|
|
|
5ce0c7 |
CAMLreturn (strv);
|
|
|
5ce0c7 |
--
|
|
|
5ce0c7 |
2.18.4
|
|
|
5ce0c7 |
|