On Thu, Apr 14, 2016 at 03:33:25PM +0200, Pino Toscano wrote:
On Tuesday 12 April 2016 08:41:37 Richard W.M. Jones wrote:
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);
This causes warnings on 32bit platforms though:
perl_edit-c.c: In function 'virt_customize_edit_file_perl': perl_edit-c.c:40:18: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] guestfs_h *g = (guestfs_h *) Int64_val (gpv); ^ What about the following patch?
Subject: [PATCH] customize: cast value to intptr_t for pointer usage
Cast a Int64 OCaml value to intptr_t before casting it to a pointer, so this avoids warnings about casting an int to pointer.
Fixes commit 80a13b7216340b2bee437c39db2375b61804e133. --- customize/perl_edit-c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/customize/perl_edit-c.c b/customize/perl_edit-c.c index 7191bef..9558d07 100644 --- a/customize/perl_edit-c.c +++ b/customize/perl_edit-c.c @@ -37,7 +37,7 @@ virt_customize_edit_file_perl (value verbosev, value gv, value gpv, { CAMLparam5 (verbosev, gv, gpv, filev, exprv); int r; - guestfs_h *g = (guestfs_h *) Int64_val (gpv); + guestfs_h *g = (guestfs_h *) (intptr_t) Int64_val (gpv);
r = edit_file_perl (g, String_val (filev), String_val (exprv), NULL, Bool_val (verbosev));
ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/