Richard W.M. Jones
2009-Nov-06 12:35 UTC
[Libguestfs] [PATCH 0/3] Three small fixes (pushed already)
I pushed these already. One seems to be an obvious fix for 32 bit platforms. The other two are tidy-ups for the OCaml bindings which won't interest most people. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora -------------- next part -------------->From e1f5472395b08033c60054e8f87f3c61126c4fa4 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Fri, 6 Nov 2009 09:14:31 +0000 Subject: [PATCH 1/3] Fixes for compiling on 32 bit. --- fish/alloc.c | 14 +++++++------- fuse/guestmount.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fish/alloc.c b/fish/alloc.c index fd5be2c..ad2dccc 100644 --- a/fish/alloc.c +++ b/fish/alloc.c @@ -140,12 +140,12 @@ parse_size (const char *str, off_t *size_rtn) */ if (sscanf (str, "%"SCNu64"%c", &size, &type) == 2) { switch (type) { - case 'k': case 'K': size *= 1024L; break; - case 'm': case 'M': size *= 1024L * 1024; break; - case 'g': case 'G': size *= 1024L * 1024 * 1024; break; - case 't': case 'T': size *= 1024L * 1024 * 1024 * 1024; break; - case 'p': case 'P': size *= 1024L * 1024 * 1024 * 1024 * 1024; break; - case 'e': case 'E': size *= 1024L * 1024 * 1024 * 1024 * 1024 * 1024; break; + case 'k': case 'K': size *= 1024ULL; break; + case 'm': case 'M': size *= 1024ULL * 1024ULL; break; + case 'g': case 'G': size *= 1024ULL * 1024ULL * 1024ULL; break; + case 't': case 'T': size *= 1024ULL * 1024ULL * 1024ULL * 1024ULL; break; + case 'p': case 'P': size *= 1024ULL * 1024ULL * 1024ULL * 1024ULL * 1024ULL; break; + case 'e': case 'E': size *= 1024ULL * 1024ULL * 1024ULL * 1024ULL * 1024ULL * 1024ULL; break; case 's': size *= 512; break; default: fprintf (stderr, _("could not parse size specification '%s'\n"), str); @@ -153,7 +153,7 @@ parse_size (const char *str, off_t *size_rtn) } } else if (sscanf (str, "%"SCNu64, &size) == 1) - size *= 1024; + size *= 1024ULL; else { fprintf (stderr, _("could not parse size specification '%s'\n"), str); return -1; diff --git a/fuse/guestmount.c b/fuse/guestmount.c index 3ae614c..8812ac2 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -619,7 +619,7 @@ fg_read (const char *path, char *buf, size_t size, off_t offset, size_t rsize; if (verbose) - fprintf (stderr, "fg_read: %s: size %zu offset %zu\n", + fprintf (stderr, "fg_read: %s: size %zu offset %ju\n", path, size, offset); /* The guestfs protocol limits size to somewhere over 2MB. We just -- 1.6.2.5 -------------- next part -------------->From 79125c4dea9c69d08b522ed7c85f26dc6ee1bcb3 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Fri, 6 Nov 2009 10:48:37 +0000 Subject: [PATCH 2/3] ocaml: General improvements to generated code. --- ocaml/guestfs_c.c | 11 +++++++++++ ocaml/guestfs_c.h | 2 ++ src/generator.ml | 37 +++++++++++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/ocaml/guestfs_c.c b/ocaml/guestfs_c.c index 80dcf99..f7d8dff 100644 --- a/ocaml/guestfs_c.c +++ b/ocaml/guestfs_c.c @@ -93,6 +93,17 @@ ocaml_guestfs_raise_error (guestfs_h *g, const char *func) CAMLnoreturn; } +void +ocaml_guestfs_raise_closed (const char *func) +{ + CAMLparam0 (); + CAMLlocal1 (v); + + v = caml_copy_string (func); + caml_raise_with_arg (*caml_named_value ("ocaml_guestfs_closed"), v); + CAMLnoreturn; +} + /* Guestfs.create */ CAMLprim value ocaml_guestfs_create (void) diff --git a/ocaml/guestfs_c.h b/ocaml/guestfs_c.h index b4a7661..cd1d73b 100644 --- a/ocaml/guestfs_c.h +++ b/ocaml/guestfs_c.h @@ -22,6 +22,8 @@ #define Guestfs_val(v) (*((guestfs_h **)Data_custom_val(v))) extern void ocaml_guestfs_raise_error (guestfs_h *g, const char *func) Noreturn; +extern void ocaml_guestfs_raise_closed (const char *func) + Noreturn; extern char **ocaml_guestfs_strings_val (guestfs_h *g, value sv); extern void ocaml_guestfs_free_strings (char **r); diff --git a/src/generator.ml b/src/generator.ml index a06e208..8b83496 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -6963,12 +6963,21 @@ type t exception Error of string (** This exception is raised when there is an error. *) +exception Handle_closed of string +(** This exception is raised if you use a {!Guestfs.t} handle + after calling {!close} on it. The string is the name of + the function. *) + val create : unit -> t +(** Create a {!Guestfs.t} handle. *) val close : t -> unit -(** Handles are closed by the garbage collector when they become - unreferenced, but callers can also call this in order to - provide predictable cleanup. *) +(** Close the {!Guestfs.t} handle and free up all resources used + by it immediately. + + Handles are closed by the garbage collector when they become + unreferenced, but callers can call this in order to provide + predictable cleanup. *) "; generate_ocaml_structure_decls (); @@ -6979,7 +6988,7 @@ val close : t -> unit generate_ocaml_prototype name style; pr "(** %s *)\n" shortdesc; pr "\n" - ) all_functions + ) all_functions_sorted (* Generate the OCaml bindings implementation. *) and generate_ocaml_ml () @@ -6987,12 +6996,17 @@ and generate_ocaml_ml () pr "\ type t + exception Error of string +exception Handle_closed of string + external create : unit -> t = \"ocaml_guestfs_create\" external close : t -> unit = \"ocaml_guestfs_close\" +(* Give the exceptions names, so they can be raised from the C code. *) let () - Callback.register_exception \"ocaml_guestfs_error\" (Error \"\") + Callback.register_exception \"ocaml_guestfs_error\" (Error \"\"); + Callback.register_exception \"ocaml_guestfs_closed\" (Handle_closed \"\") "; @@ -7002,7 +7016,7 @@ let () List.iter ( fun (name, style, _, _, _, shortdesc, _) -> generate_ocaml_prototype ~is_external:true name style; - ) all_functions + ) all_functions_sorted (* Generate the OCaml bindings C implementation. *) and generate_ocaml_c () @@ -7138,6 +7152,12 @@ copy_table (char * const * argv) (* The wrappers. *) List.iter ( fun (name, style, _, _, _, _, _) -> + pr "/* Automatically generated wrapper for function\n"; + pr " * "; + generate_ocaml_prototype name style; + pr " */\n"; + pr "\n"; + let params "gv" :: List.map (fun arg -> name_of_argt arg ^ "v") (snd style) in @@ -7147,6 +7167,7 @@ copy_table (char * const * argv) pr "/* Emit prototype to appease gcc's -Wmissing-prototypes. */\n"; pr "CAMLprim value ocaml_guestfs_%s (value %s" name (List.hd params); List.iter (pr ", value %s") (List.tl params); pr ");\n"; + pr "\n"; pr "CAMLprim value\n"; pr "ocaml_guestfs_%s (value %s" name (List.hd params); @@ -7172,7 +7193,7 @@ copy_table (char * const * argv) pr " guestfs_h *g = Guestfs_val (gv);\n"; pr " if (g == NULL)\n"; - pr " caml_failwith (\"%s: used handle after closing it\");\n" name; + pr " ocaml_guestfs_raise_closed (\"%s\");\n" name; pr "\n"; List.iter ( @@ -7296,7 +7317,7 @@ copy_table (char * const * argv) pr "}\n"; pr "\n" ) - ) all_functions + ) all_functions_sorted and generate_ocaml_structure_decls () List.iter ( -- 1.6.2.5 -------------- next part -------------->From c0465ca3ae5cd55dbc5dc6d3a511ae5431985d3b Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Fri, 6 Nov 2009 12:32:57 +0000 Subject: [PATCH 3/3] ocaml: Sort the dependencies so they are stable between machines. --- ocaml/.depend | 6 +++--- ocaml/Makefile.am | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ocaml/.depend b/ocaml/.depend index 8ed7c5b..3f743d5 100644 --- a/ocaml/.depend +++ b/ocaml/.depend @@ -1,8 +1,8 @@ -guestfs.cmi: guestfs_inspector.cmi: +guestfs.cmi: bindtests.cmo: guestfs.cmi bindtests.cmx: guestfs.cmx -guestfs.cmo: guestfs.cmi -guestfs.cmx: guestfs.cmi guestfs_inspector.cmo: guestfs_inspector.cmi guestfs_inspector.cmx: guestfs_inspector.cmi +guestfs.cmo: guestfs.cmi +guestfs.cmx: guestfs.cmi diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am index 032a551..bb7407a 100644 --- a/ocaml/Makefile.am +++ b/ocaml/Makefile.am @@ -103,7 +103,7 @@ depend: .depend .depend: $(wildcard *.mli) $(wildcard *.ml) rm -f $@ $@-t - $(OCAMLFIND) ocamldep $^ | sed 's/ *$$//' > $@-t + $(OCAMLFIND) ocamldep $^ | sed 's/ *$$//' | sort > $@-t mv $@-t $@ include .depend -- 1.6.2.5
Jim Meyering
2009-Nov-09 11:18 UTC
[Libguestfs] [PATCH 0/3] Three small fixes (pushed already)
Richard W.M. Jones wrote:> I pushed these already. One seems to be an obvious fix > for 32 bit platforms. The other two are tidy-ups for the > OCaml bindings which won't interest most people.The ULL-adding parts look fine. The sscanf-improving part is probably fine, too but I have a strong aversion to using sscanf for any parsing that I want to be robust, since it doesn't detect overflow. I.e., it will map an input of 2^64 to 0.
Possibly Parallel Threads
- [PATCH] qemu: Upstream regression of -stdio serial option.
- [PATCH 0/4] Introduce "pulse mode" progress messages to the daemon.
- virt-resize
- [PATCH] Rejig configure.ac tests for qemu vmchannel support.
- [PATCH 0/5] Four fixes for FUSE support and a test script