From adb5db58d850ce6d15380177a63c68276f863c98 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 28 Jun 2011 08:50:14 +0100 Subject: [PATCH] generator: Fix functions with both RBufferOut and optional args. No current function returns RBufferOut and has optional args. Such functions would be generated incorrectly. RBufferOut implies a silent "size_t *size_r" argument is added after the regular arguments and before the optional arguments. Various changes to the code generator need to be made to take this into account. --- generator/generator_c.ml | 22 +++++++++++++--------- generator/generator_java.ml | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 61cb0a3..2e9607b 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -135,7 +135,8 @@ let rec generate_prototype ?(extern = true) ?(static = false) if newline then pr "\n" (* Generate C call arguments, eg "(handle, foo, bar)" *) -and generate_c_call_args ?handle (ret, args, optargs) = +and generate_c_call_args ?handle ?(implicit_size_ptr = "&size") + (ret, args, optargs) = pr "("; let comma = ref false in let next () = @@ -155,11 +156,11 @@ and generate_c_call_args ?handle (ret, args, optargs) = next (); pr "%s" (name_of_argt arg) ) args; - (* For RBufferOut calls, add implicit &size parameter. *) + (* For RBufferOut calls, add implicit size pointer parameter. *) (match ret with | RBufferOut _ -> next (); - pr "&size" + pr "%s" implicit_size_ptr | _ -> () ); (* For calls with optional arguments, add implicit optargs parameter. *) @@ -1025,7 +1026,7 @@ trace_send_line (guestfs_h *g) reject_unknown_optargs shortname style; trace_call shortname style; pr " r = guestfs__%s " shortname; - generate_c_call_args ~handle:"g" style; + generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style; pr ";\n"; pr "\n"; (match errcode_of_ret ret with @@ -1371,9 +1372,12 @@ trace_send_line (guestfs_h *g) (* Get the name of the last regular argument. *) let last_arg = - match args with - | [] -> "g" - | args -> name_of_argt (List.hd (List.rev args)) in + match ret with + | RBufferOut _ -> "size_r" + | _ -> + match args with + | [] -> "g" + | args -> name_of_argt (List.hd (List.rev args)) in let rtype = match ret with @@ -1394,7 +1398,7 @@ trace_send_line (guestfs_h *g) pr "\n"; pr " va_start (optargs, %s);\n" last_arg; pr " %sr = guestfs_%s_va " rtype shortname; - generate_c_call_args ~handle:"g" style; + generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style; pr ";\n"; pr " va_end (optargs);\n"; pr "\n"; @@ -1451,7 +1455,7 @@ trace_send_line (guestfs_h *g) pr " }\n"; pr "\n"; pr " return guestfs_%s_argv " shortname; - generate_c_call_args ~handle:"g" style; + generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style; pr ";\n"; pr "}\n\n" | _ -> () diff --git a/generator/generator_java.ml b/generator/generator_java.ml index 767c94c..97bee84 100644 --- a/generator/generator_java.ml +++ b/generator/generator_java.ml @@ -576,7 +576,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close let cols = cols_of_struct typ in generate_java_struct_list_return typ jtyp cols | RBufferOut _ -> - pr " jr = (*env)->NewStringUTF (env, r); /* XXX size */\n"; + pr " jr = (*env)->NewStringUTF (env, r); // XXX size\n"; pr " free (r);\n"; pr " return jr;\n" ); -- 1.8.3.1