summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-10-31 13:38:14 +0000
committerRichard Jones <rjones@redhat.com>2009-11-02 16:02:06 +0000
commit752aec78b012dbeb8997658bf574dfba690bcfed (patch)
tree240e49c2468bed300ea76662eaba16e2e649357b
parent32ab3c183836ab434ab739bea8238593d70db2ac (diff)
downloadlibguestfs-752aec78b012dbeb8997658bf574dfba690bcfed.tar.gz
libguestfs-752aec78b012dbeb8997658bf574dfba690bcfed.tar.xz
libguestfs-752aec78b012dbeb8997658bf574dfba690bcfed.zip
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).
-rwxr-xr-xsrc/generator.ml24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/generator.ml b/src/generator.ml
index 4e056e29..2cabd4a6 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 (