[Libguestfs] [PATCH] ocaml: Change calls to caml_named_value() to cope with const value* return.

Richard W.M. Jones rjones at redhat.com
Thu Sep 5 08:58:41 UTC 2019


In OCaml >= 4.09 the return value pointer of caml_named_value is
declared const.

Based on Pino Toscano's original patch to ocaml-augeas.
---
 common/mlpcre/pcre-c.c   | 3 +--
 common/mltools/uri-c.c   | 6 ++----
 common/mlvisit/visit-c.c | 4 +---
 generator/daemon.ml      | 2 +-
 4 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/common/mlpcre/pcre-c.c b/common/mlpcre/pcre-c.c
index be054a004..d23f17e05 100644
--- a/common/mlpcre/pcre-c.c
+++ b/common/mlpcre/pcre-c.c
@@ -73,12 +73,11 @@ init (void)
 static void
 raise_pcre_error (const char *msg, int errcode)
 {
-  value *exn = caml_named_value ("PCRE.Error");
   value args[2];
 
   args[0] = caml_copy_string (msg);
   args[1] = Val_int (errcode);
-  caml_raise_with_args (*exn, 2, args);
+  caml_raise_with_args (*caml_named_value ("PCRE.Error"), 2, args);
 }
 
 /* Wrap and unwrap pcre regular expression handles, with a finalizer. */
diff --git a/common/mltools/uri-c.c b/common/mltools/uri-c.c
index 2a8837cd9..e03647c7b 100644
--- a/common/mltools/uri-c.c
+++ b/common/mltools/uri-c.c
@@ -46,10 +46,8 @@ guestfs_int_mllib_parse_uri (value argv /* arg value, not an array! */)
   int r;
 
   r = parse_uri (String_val (argv), &uri);
-  if (r == -1) {
-    value *exn = caml_named_value ("URI.Parse_failed");
-    caml_raise (*exn);
-  }
+  if (r == -1)
+    caml_raise (*caml_named_value ("URI.Parse_failed"));
 
   /* Convert the struct into an OCaml tuple. */
   rv = caml_alloc_tuple (5);
diff --git a/common/mlvisit/visit-c.c b/common/mlvisit/visit-c.c
index 7137c4998..201f6d762 100644
--- a/common/mlvisit/visit-c.c
+++ b/common/mlvisit/visit-c.c
@@ -53,7 +53,6 @@ value
 guestfs_int_mllib_visit (value gv, value dirv, value fv)
 {
   CAMLparam3 (gv, dirv, fv);
-  value *visit_failure_exn;
   guestfs_h *g = (guestfs_h *) (intptr_t) Int64_val (gv);
   struct visitor_function_wrapper_args args;
   /* The dir string could move around when we call the
@@ -84,8 +83,7 @@ guestfs_int_mllib_visit (value gv, value dirv, value fv)
      * already printed the error to stderr (XXX - fix), so we raise a
      * generic exception.
      */
-    visit_failure_exn = caml_named_value ("Visit.Failure");
-    caml_raise (*visit_failure_exn);
+    caml_raise (*caml_named_value ("Visit.Failure"));
   }
   free (dir);
 
diff --git a/generator/daemon.ml b/generator/daemon.ml
index a4e136aaa..b67c4d20b 100644
--- a/generator/daemon.ml
+++ b/generator/daemon.ml
@@ -746,7 +746,7 @@ let generate_daemon_caml_stubs () =
       let nr_args = List.length args_do_function in
 
       pr "{\n";
-      pr "  static value *cb = NULL;\n";
+      pr "  static const value *cb = NULL;\n";
       pr "  CAMLparam0 ();\n";
       pr "  CAMLlocal2 (v, retv);\n";
       pr "  CAMLlocalN (args, %d);\n"
-- 
2.23.0




More information about the Libguestfs mailing list