[Libguestfs] [libnbd PATCH 1/2] generator: Tweak print_c_arg_list to take alternate first arg

Eric Blake eblake at redhat.com
Tue Jul 16 04:38:11 UTC 2019


The next patch plans to refactor callbacks to make it possible to
share the same opaque data, but to do so, we want to generate more
than one function with the same canned first argument, different from
our top-level function first argument of struct nbd_handle.  Update
the ~handle argument to be 'string option'.
---
 generator/generator | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/generator/generator b/generator/generator
index caa6353..ad12b36 100755
--- a/generator/generator
+++ b/generator/generator
@@ -3164,12 +3164,14 @@ let rec name_of_arg = function
 | UInt32 n -> [n]
 | UInt64 n -> [n]

-let rec print_c_arg_list ?(handle = false) args =
+let rec print_c_arg_list ?(handle = None) args =
   pr "(";
   let comma = ref false in
-  if handle then (
-    comma := true;
-    pr "struct nbd_handle *h";
+  (match handle with
+   | Some arg ->
+      comma := true;
+      pr "%s" arg
+   | None -> ()
   );
   List.iter (
     fun arg ->
@@ -3214,7 +3216,7 @@ let print_call name args ret =
    | RString -> pr "char *"
   );
   pr "nbd_%s " name;
-  print_c_arg_list ~handle:true args
+  print_c_arg_list ~handle:(Some "struct nbd_handle *h") args

 let print_extern name args ret =
   pr "extern ";
@@ -3360,7 +3362,7 @@ let generate_lib_api_c () =

     pr "%s\n" ret_c_type;
     pr "nbd_%s " name;
-    print_c_arg_list ~handle:true args;
+    print_c_arg_list ~handle:(Some "struct nbd_handle *h") args;
     pr "\n";
     pr "{\n";
     (match ret with
-- 
2.20.1




More information about the Libguestfs mailing list