[Libguestfs] [PATCH 2/3] Fix rstructs_used handling in guestfish generated code.
Richard W.M. Jones
rjones at redhat.com
Sat Oct 31 13:46:23 UTC 2009
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
-------------- next part --------------
>From 72bbe38ea39ebcb290a2228ba721a68ea59b1bec Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones at redhat.com>
Date: Sat, 31 Oct 2009 13:38:14 +0000
Subject: [PATCH 2/3] Fix rstructs_used handling in guestfish generated code.
rstructs_used wasn't correctly generating code for guestfish
because guestfish doesn't make all functions visible. Since the
calculation of rstructs_used was over all functions (including
ones not available in guestfish) it could have generated
unnecessary functions.
In fact this error didn't affect us before - but I discovered
it when I added some extra struct-returning functions (future
commit).
---
src/generator.ml | 24 +++++++-----------------
1 files changed, 7 insertions(+), 17 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml
index 4e056e2..2cabd4a 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -3915,7 +3915,7 @@ type rstructs_used_t = RStructOnly | RStructListOnly | RStructAndList
* == there are functions returning both RStruct (_, structname)
* and RStructList (_, structname)
*)
-let rstructs_used =
+let rstructs_used_by functions =
(* ||| is a "logical OR" for rstructs_used_t *)
let (|||) a b =
match a, b with
@@ -3944,21 +3944,11 @@ let rstructs_used =
| RStruct (_, structname) -> update structname RStructOnly
| RStructList (_, structname) -> update structname RStructListOnly
| _ -> ()
- ) all_functions;
+ ) functions;
(* return key->values as a list of (key,value) *)
Hashtbl.fold (fun key value xs -> (key, value) :: xs) h []
-(* debug:
-let () =
- List.iter (
- function
- | sn, RStructOnly -> printf "%s RStructOnly\n" sn
- | sn, RStructListOnly -> printf "%s RStructListOnly\n" sn
- | sn, RStructAndList -> printf "%s RStructAndList\n" sn
- ) rstructs_used
-*)
-
(* Used for testing language bindings. *)
type callt =
| CallString of string
@@ -6334,19 +6324,19 @@ and generate_fish_cmds () =
(* generate the function for typ *)
emit_print_list_function typ
| typ, _ -> () (* empty *)
- ) rstructs_used;
+ ) (rstructs_used_by all_functions);
(* Emit a print_TYPE function definition only if that function is used. *)
List.iter (
function
- | typ, RStructOnly ->
+ | typ, (RStructOnly | RStructAndList) ->
pr "static void print_%s (struct guestfs_%s *%s)\n" typ typ typ;
pr "{\n";
pr " print_%s_indent (%s, \"\");\n" typ typ;
pr "}\n";
pr "\n";
| typ, _ -> () (* empty *)
- ) rstructs_used;
+ ) (rstructs_used_by all_functions);
(* run_<action> actions *)
List.iter (
@@ -6942,7 +6932,7 @@ copy_table (char * const * argv)
(* generate the function for typ *)
emit_ocaml_copy_list_function typ
| typ, _ -> () (* empty *)
- ) rstructs_used;
+ ) (rstructs_used_by all_functions);
(* The wrappers. *)
List.iter (
@@ -7888,7 +7878,7 @@ py_guestfs_close (PyObject *self, PyObject *args)
(* generate the function for typ *)
emit_put_list_function typ
| typ, _ -> () (* empty *)
- ) rstructs_used;
+ ) (rstructs_used_by all_functions);
(* Python wrapper functions. *)
List.iter (
--
1.6.5.rc2
More information about the Libguestfs
mailing list