We can now use the Guestfs.c_pointer method to access the underlying
guestfs_h *. So no need to use internal APIs for this.
---
customize/perl_edit-c.c | 18 ++++++------------
customize/perl_edit.ml | 10 ++++++++--
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/customize/perl_edit-c.c b/customize/perl_edit-c.c
index 753d990..7191bef 100644
--- a/customize/perl_edit-c.c
+++ b/customize/perl_edit-c.c
@@ -25,30 +25,24 @@
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>
+#include <caml/fail.h>
#include "file-edit.h"
-/**
- * We try to reuse the internals of the OCaml binding (for extracting
- * the guestfs handle, and raising errors); hopefully this should be safe,
- * as long as it's kept internal within the libguestfs sources.
- */
-#include "../ocaml/guestfs-c.h"
-
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
value
-virt_customize_edit_file_perl (value verbosev, value gv, value filev,
- value exprv)
+virt_customize_edit_file_perl (value verbosev, value gv, value gpv,
+ value filev, value exprv)
{
- CAMLparam4 (verbosev, gv, filev, exprv);
+ CAMLparam5 (verbosev, gv, gpv, filev, exprv);
int r;
- guestfs_h *g = Guestfs_val (gv);
+ guestfs_h *g = (guestfs_h *) Int64_val (gpv);
r = edit_file_perl (g, String_val (filev), String_val (exprv), NULL,
Bool_val (verbosev));
if (r == -1)
- guestfs_int_ocaml_raise_error (g, "edit_file_perl");
+ caml_failwith (guestfs_last_error (g) ? : "edit_file_perl: unknown
error");
CAMLreturn (Val_unit);
}
diff --git a/customize/perl_edit.ml b/customize/perl_edit.ml
index f1f06cc..5cd250b 100644
--- a/customize/perl_edit.ml
+++ b/customize/perl_edit.ml
@@ -18,6 +18,12 @@
open Common_utils
-external c_edit_file : verbose:bool -> Guestfs.t -> string -> string -> unit
+external c_edit_file : verbose:bool -> Guestfs.t -> int64 -> string -> string
-> unit
= "virt_customize_edit_file_perl"
-let edit_file g file expr = c_edit_file (verbose ()) g file expr
+let edit_file g file expr =
+ (* Note we pass original 'g' even though it is not used by the
+ * callee. This is so that 'g' is kept as a root on the stack, and
+ * so cannot be garbage collected while we are in the c_edit_file
+ * function.
+ *)
+ c_edit_file (verbose ()) g (Guestfs.c_pointer g) file expr
--
2.7.4