Richard W.M. Jones
2019-Sep-05 08:58 UTC
[Libguestfs] [PATCH] ocaml: Change calls to caml_named_value() to cope with const value* return.
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
Pino Toscano
2019-Sep-05 09:50 UTC
Re: [Libguestfs] [PATCH] ocaml: Change calls to caml_named_value() to cope with const value* return.
On Thursday, 5 September 2019 10:58:41 CEST Richard W.M. Jones wrote:> 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"LGTM. -- Pino Toscano
Seemingly Similar Threads
- [PATCH 1/1] ocaml: make const the return value of caml_named_value()
- [PATCH 0/1] Build fix for future OCaml 4.09
- [PATCH 0/9] build: Require OCaml >= 4.02.
- [PATCH] mllib: cast integer pointers to intptr_t as intermediate step
- [supermin PATCH 1/2] rpm: extend the Multiple_matches exception