From 752aec78b012dbeb8997658bf574dfba690bcfed Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Sat, 31 Oct 2009 13:38:14 +0000 Subject: [PATCH] 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 file 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_ 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.8.3.1