From: Richard W.M. Jones Date: Mon, 4 Oct 2010 19:29:05 +0000 (+0100) Subject: ocaml: Create the handle when the object is instantiated. X-Git-Tag: 1.5.22~18 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=6af1cd7245de0183404ea6aadda4c2f63f9f616b ocaml: Create the handle when the object is instantiated. Previously we had only one handle shared between all objects .. oops. This fixes commit 67636f721056d2f2250b0ff8acd981a0294536a9. --- diff --git a/generator/generator_ocaml.ml b/generator/generator_ocaml.ml index e5dfc68..483d65a 100644 --- a/generator/generator_ocaml.ml +++ b/generator/generator_ocaml.ml @@ -101,12 +101,14 @@ val clear_progress_callback : t -> unit [Guestfs.add_drive g filename]. Apart from the different style, it offers exactly the same functionality. + Calling [new guestfs ()] creates both the object and the handle. + Note that methods that take no parameters (except the implicit handle) get an extra unit [()] parameter. This is so you can create a closure from the method easily. For example [g#get_verbose ()] calls the method, whereas [g#get_verbose] is a function. *) -class guestfs : object +class guestfs : unit -> object method close : unit -> unit method set_progress_callback : progress_cb -> unit method clear_progress_callback : unit -> unit @@ -124,7 +126,7 @@ class guestfs : object pr "\n" ) all_functions_sorted; - pr " end\n" + pr "end\n" (* Generate the OCaml bindings implementation. *) and generate_ocaml_ml () = @@ -163,7 +165,7 @@ let () = (* OO API. *) pr " -class guestfs = +class guestfs () = let g = create () in object method close () = close g diff --git a/ocaml/t/guestfs_005_load.ml b/ocaml/t/guestfs_005_load.ml index 523f764..8b4492a 100644 --- a/ocaml/t/guestfs_005_load.ml +++ b/ocaml/t/guestfs_005_load.ml @@ -20,5 +20,5 @@ let _ = Guestfs.create (* Also try the OO style. *) let _ = - let g = new Guestfs.guestfs in + let g = new Guestfs.guestfs () in g#get_verbose ()