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. *)
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif
+/* Define GUESTFS_WARN_DEPRECATED=1 to warn about deprecated API functions. */
+#define GUESTFS_DEPRECATED_BY(s)
+#if GUESTFS_WARN_DEPRECATED
+# if defined(__GNUC__) && GUESTFS_GCC_VERSION >= 40500 /* gcc >= 4.5 */
+# undef GUESTFS_DEPRECATED_BY
+# define GUESTFS_DEPRECATED_BY(s) __attribute__((__deprecated__(\"change the program to use guestfs_\" s \" instead of this deprecated function\")))
+# endif
+#endif /* GUESTFS_WARN_DEPRECATED */
+
/* The handle. */
#ifndef GUESTFS_TYPEDEF_H
#define GUESTFS_TYPEDEF_H 1
#endif
#define LIBGUESTFS_HAVE_SET_EVENT_CALLBACK 1
-int guestfs_set_event_callback (guestfs_h *g,
- guestfs_event_callback cb,
- uint64_t event_bitmask,
- int flags,
- void *opaque);
+extern int guestfs_set_event_callback (guestfs_h *g,
+ guestfs_event_callback cb,
+ uint64_t event_bitmask,
+ int flags,
+ void *opaque);
#define LIBGUESTFS_HAVE_DELETE_EVENT_CALLBACK 1
-void guestfs_delete_event_callback (guestfs_h *g, int event_handle);
+extern void guestfs_delete_event_callback (guestfs_h *g, int event_handle);
-/* Old-style event handling. In new code use guestfs_set_event_callback. */
+/* Old-style event handling. */
#ifndef GUESTFS_TYPEDEF_LOG_MESSAGE_CB
#define GUESTFS_TYPEDEF_LOG_MESSAGE_CB 1
typedef void (*guestfs_log_message_cb) (guestfs_h *g, void *opaque, char *buf, int len);
typedef void (*guestfs_progress_cb) (guestfs_h *g, void *opaque, int proc_nr, int serial, uint64_t position, uint64_t total);
#endif
-extern void guestfs_set_log_message_callback (guestfs_h *g, guestfs_log_message_cb cb, void *opaque);
-extern void guestfs_set_subprocess_quit_callback (guestfs_h *g, guestfs_subprocess_quit_cb cb, void *opaque);
-extern void guestfs_set_launch_done_callback (guestfs_h *g, guestfs_launch_done_cb cb, void *opaque);
+extern void guestfs_set_log_message_callback (guestfs_h *g, guestfs_log_message_cb cb, void *opaque)
+ GUESTFS_DEPRECATED_BY(\"set_event_callback\");
+extern void guestfs_set_subprocess_quit_callback (guestfs_h *g, guestfs_subprocess_quit_cb cb, void *opaque)
+ GUESTFS_DEPRECATED_BY(\"set_event_callback\");
+extern void guestfs_set_launch_done_callback (guestfs_h *g, guestfs_launch_done_cb cb, void *opaque)
+ GUESTFS_DEPRECATED_BY(\"set_event_callback\");
#define LIBGUESTFS_HAVE_SET_CLOSE_CALLBACK 1
-extern void guestfs_set_close_callback (guestfs_h *g, guestfs_close_cb cb, void *opaque);
+extern void guestfs_set_close_callback (guestfs_h *g, guestfs_close_cb cb, void *opaque)
+ GUESTFS_DEPRECATED_BY(\"set_event_callback\");
#define LIBGUESTFS_HAVE_SET_PROGRESS_CALLBACK 1
-extern void guestfs_set_progress_callback (guestfs_h *g, guestfs_progress_cb cb, void *opaque);
+extern void guestfs_set_progress_callback (guestfs_h *g, guestfs_progress_cb cb, void *opaque)
+ GUESTFS_DEPRECATED_BY(\"set_event_callback\");
+
+/* User cancellation. */
+#define LIBGUESTFS_HAVE_USER_CANCEL 1
+extern void guestfs_user_cancel (guestfs_h *g);
/* Private data area. */
#define LIBGUESTFS_HAVE_SET_PRIVATE 1
List.iter (
fun (shortname, (ret, args, optargs as style), _, flags, _, _, _) ->
let deprecated =
- List.exists (function DeprecatedBy _ -> true | _ -> false) flags in
+ try
+ Some (find_map (function DeprecatedBy fn -> Some fn | _ -> None)
+ flags)
+ with Not_found -> None in
let test0 =
String.length shortname >= 5 && String.sub shortname 0 5 = "test0" in
let debug =
String.length shortname >= 5 && String.sub shortname 0 5 = "debug" in
- if not deprecated && not test0 && not debug then
+ if deprecated = None && not test0 && not debug then
pr "#define LIBGUESTFS_HAVE_%s 1\n" (String.uppercase shortname);
- generate_prototype ~single_line:true ~newline:true ~handle:"g"
- ~prefix:"guestfs_" shortname style;
+ if optargs <> [] then (
+ iteri (
+ fun i argt ->
+ let uc_shortname = String.uppercase shortname in
+ let n = name_of_argt argt in
+ let uc_n = String.uppercase n in
+ pr "#define GUESTFS_%s_%s %d\n" uc_shortname uc_n i;
+ ) optargs;
+ );
+
+ generate_prototype ~single_line:true ~semicolon:false
+ ~handle:"g" ~prefix:"guestfs_" shortname style;
+ (match deprecated with
+ | Some fn -> pr "\n GUESTFS_DEPRECATED_BY (%S);\n" fn
+ | None -> pr ";\n"
+ );
if optargs <> [] then (
generate_prototype ~single_line:true ~newline:true ~handle:"g"
~prefix:"guestfs_" ~suffix:"_va" ~optarg_proto:VA
shortname style;
+ pr "\n";
pr "struct guestfs_%s_argv {\n" shortname;
pr " uint64_t bitmask;\n";
iteri (
let uc_shortname = String.uppercase shortname in
let n = name_of_argt argt in
let uc_n = String.uppercase n in
- pr "#define GUESTFS_%s_%s %d\n" uc_shortname uc_n i;
- pr "#define GUESTFS_%s_%s_BITMASK (UINT64_C(1)<<%d)\n" uc_shortname uc_n i;
- pr "/* The field below is only valid in this struct if the\n";
- pr " * GUESTFS_%s_%s_BITMASK bit is set\n" uc_shortname uc_n;
- pr " * in the bitmask above, otherwise the contents are ignored.\n";
- pr " */\n";
+ pr "\n";
+ pr "# define GUESTFS_%s_%s_BITMASK (UINT64_C(1)<<%d)\n" uc_shortname uc_n i;
+ pr " /* The field below is only valid in this struct if the\n";
+ pr " * GUESTFS_%s_%s_BITMASK bit is set\n" uc_shortname uc_n;
+ pr " * in the bitmask above. If not, the field is ignored.\n";
+ pr " */\n";
pr " %s%s;\n" c_type n
) optargs;
pr "};\n";
+ pr "\n";
generate_prototype ~single_line:true ~newline:true ~handle:"g"
~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
| RBufferOut _ ->
pr "%s guestfs___print_BufferOut (trace_fp, %s, *size_r);\n" indent rv
| RStringList _ | RHashtable _ ->
- pr "%s fputs (\"[\\\"\", trace_fp);\n" indent;
+ pr "%s fputs (\"[\", trace_fp);\n" indent;
pr "%s for (i = 0; %s[i]; ++i) {\n" indent rv;
- pr "%s if (i > 0) fputs (\"\\\", \\\"\", trace_fp);\n" indent;
+ pr "%s if (i > 0) fputs (\", \", trace_fp);\n" indent;
+ pr "%s fputs (\"\\\"\", trace_fp);\n" indent;
pr "%s fputs (%s[i], trace_fp);\n" indent rv;
+ pr "%s fputs (\"\\\"\", trace_fp);\n" indent;
pr "%s }\n" indent;
- pr "%s fputs (\"\\\"]\", trace_fp);\n" indent;
+ pr "%s fputs (\"]\", trace_fp);\n" indent;
| RStruct (_, typ) ->
(* XXX There is code generated for guestfish for printing
* these structures. We need to make it generally available
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"
| _ -> ()
"guestfs_set_private";
"guestfs_set_progress_callback";
"guestfs_set_subprocess_quit_callback";
+ "guestfs_user_cancel";
(* Unofficial parts of the API: the bindings code use these
* functions, so it is useful to export them.