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 () =
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. *)
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
(* 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
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";
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"
| _ -> ()