From 62e775c350edfddeafd829ca3edcdf3a8065eb00 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 15 Dec 2012 17:19:53 +0000 Subject: [PATCH] Change the handling of private functions, safe_malloc etc. Rename guestfs_safe_malloc et al to guestfs___safe_malloc etc. To use the private functions, code now has to define -DGUESTFS_PRIVATE_FUNCTIONS=1. This will make it easier for us in future to work out which programs are using these functions and to minimize both the number of programs and the functions they are calling. Note that the Perl, Python, OCaml, Ruby and Java bindings use guestfs_safe_* calls. None of the other bindings do. This is a bug (in the bindings using those functions): these functions will call the out of memory callback on failure. This function defaults to abort(), and since this happens from a language binding, there is no way to change this default. --- align/Makefile.am | 1 + align/domains.c | 4 ---- df/Makefile.am | 1 + df/domains.c | 4 ---- examples/guestfs-performance.pod | 6 +++--- generator/c.ml | 27 +++++++++++++++------------ generator/java.ml | 4 ++-- generator/ocaml.ml | 8 ++++---- generator/perl.ml | 4 ++-- generator/ruby.ml | 4 ++-- java/Makefile.am | 7 ++++--- ocaml/Makefile.am | 1 + ocaml/guestfs-c.c | 10 +++++----- perl/Makefile.PL.in | 2 +- python/Makefile.am | 7 +++++-- python/guestfs-py-byhand.c | 2 +- src/Makefile.am | 1 + src/alloc.c | 14 +++++++------- src/events.c | 8 ++++---- src/guestfs-internal.h | 24 ++++++++++++------------ src/libvirt-domain.c | 10 +++++----- 21 files changed, 76 insertions(+), 73 deletions(-) diff --git a/align/Makefile.am b/align/Makefile.am index 74cb2b522..cd80c191b 100644 --- a/align/Makefile.am +++ b/align/Makefile.am @@ -41,6 +41,7 @@ virt_alignment_scan_SOURCES = \ virt_alignment_scan_CFLAGS = \ -DGUESTFS_WARN_DEPRECATED=1 \ + -DGUESTFS_PRIVATE_FUNCTIONS=1 \ -I$(top_srcdir)/src -I$(top_builddir)/src \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib \ diff --git a/align/domains.c b/align/domains.c index 1f03fd398..e76dee95c 100644 --- a/align/domains.c +++ b/align/domains.c @@ -30,10 +30,6 @@ #include "progname.h" -#if defined(HAVE_LIBVIRT) && defined(HAVE_LIBXML2) -#define GUESTFS_PRIVATE_FOR_EACH_DISK 1 -#endif - #include "guestfs.h" #include "options.h" #include "scan.h" diff --git a/df/Makefile.am b/df/Makefile.am index f52d275d5..eeec48498 100644 --- a/df/Makefile.am +++ b/df/Makefile.am @@ -44,6 +44,7 @@ virt_df_SOURCES = \ virt_df_CFLAGS = \ -DGUESTFS_WARN_DEPRECATED=1 \ + -DGUESTFS_PRIVATE_FUNCTIONS=1 \ -I$(top_srcdir)/src -I$(top_builddir)/src \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib \ diff --git a/df/domains.c b/df/domains.c index d125ba23b..505bf2273 100644 --- a/df/domains.c +++ b/df/domains.c @@ -30,10 +30,6 @@ #include "progname.h" -#if defined(HAVE_LIBVIRT) && defined(HAVE_LIBXML2) -#define GUESTFS_PRIVATE_FOR_EACH_DISK 1 -#endif - #include "guestfs.h" #include "options.h" #include "virt-df.h" diff --git a/examples/guestfs-performance.pod b/examples/guestfs-performance.pod index e005813c9..e00f3dd30 100644 --- a/examples/guestfs-performance.pod +++ b/examples/guestfs-performance.pod @@ -368,9 +368,9 @@ example: xxxx (+0): guestfs_create xxxx (+29): guestfs_set_pgroup g=0x17a9de0 pgroup=0x1 xxxx (+9): guestfs_add_drive_opts_argv g=0x17a9de0 [...] - xxxx (+8): guestfs_safe_strdup g=0x17a9de0 str=0x7f8a153bed5d - xxxx (+19): guestfs_safe_malloc g=0x17a9de0 nbytes=0x38 - xxxx (+5): guestfs_safe_strdup g=0x17a9de0 str=0x17a9f60 + xxxx (+8): guestfs___safe_strdup g=0x17a9de0 str=0x7f8a153bed5d + xxxx (+19): guestfs___safe_malloc g=0x17a9de0 nbytes=0x38 + xxxx (+5): guestfs___safe_strdup g=0x17a9de0 str=0x17a9f60 xxxx (+10): guestfs_launch g=0x17a9de0 xxxx (+4): launch_start [etc] diff --git a/generator/c.ml b/generator/c.ml index f2dd1bcfd..b9d4b3566 100644 --- a/generator/c.ml +++ b/generator/c.ml @@ -677,20 +677,23 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_next_private (guestfs_h *g, const char * pr "\ +#if GUESTFS_PRIVATE_FUNCTIONS + /* Private functions. * * These are NOT part of the public, stable API, and can change at any * time! We export them because they are used by some of the language * bindings. */ -extern GUESTFS_DLL_PUBLIC void *guestfs_safe_malloc (guestfs_h *g, size_t nbytes); -extern GUESTFS_DLL_PUBLIC void *guestfs_safe_calloc (guestfs_h *g, size_t n, size_t s); -extern GUESTFS_DLL_PUBLIC char *guestfs_safe_strdup (guestfs_h *g, const char *str); -extern GUESTFS_DLL_PUBLIC void *guestfs_safe_memdup (guestfs_h *g, const void *ptr, size_t size); -#ifdef GUESTFS_PRIVATE_FOR_EACH_DISK -extern GUESTFS_DLL_PUBLIC int guestfs___for_each_disk (guestfs_h *g, virDomainPtr dom, int (*)(guestfs_h *g, const char *filename, const char *format, int readonly, void *data), void *data); -#endif -/* End of private functions. */ + +extern GUESTFS_DLL_PUBLIC void *guestfs___safe_malloc (guestfs_h *g, size_t nbytes); +extern GUESTFS_DLL_PUBLIC void *guestfs___safe_calloc (guestfs_h *g, size_t n, size_t s); +extern GUESTFS_DLL_PUBLIC char *guestfs___safe_strdup (guestfs_h *g, const char *str); +extern GUESTFS_DLL_PUBLIC void *guestfs___safe_memdup (guestfs_h *g, const void *ptr, size_t size); + +extern GUESTFS_DLL_PUBLIC int guestfs___for_each_disk (guestfs_h *g, /* virDomainPtr */ void *dom, int (*)(guestfs_h *g, const char *filename, const char *format, int readonly, void *data), void *data); + +#endif /* End of private functions. */ #ifdef __cplusplus } @@ -1594,10 +1597,10 @@ and generate_linker_script () = (* Unofficial parts of the API: the bindings code use these * functions, so it is useful to export them. *) - "guestfs_safe_calloc"; - "guestfs_safe_malloc"; - "guestfs_safe_strdup"; - "guestfs_safe_memdup"; + "guestfs___safe_calloc"; + "guestfs___safe_malloc"; + "guestfs___safe_strdup"; + "guestfs___safe_memdup"; "guestfs___for_each_disk"; ] in let functions = diff --git a/generator/java.ml b/generator/java.ml index a8eea1aea..c83bf80f8 100644 --- a/generator/java.ml +++ b/generator/java.ml @@ -622,7 +622,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close pr " %s_size = (*env)->GetArrayLength (env, j%s);\n" n n | StringList n | DeviceList n -> pr " %s_len = (*env)->GetArrayLength (env, j%s);\n" n n; - pr " %s = guestfs_safe_malloc (g, sizeof (char *) * (%s_len+1));\n" n n; + pr " %s = guestfs___safe_malloc (g, sizeof (char *) * (%s_len+1));\n" n n; pr " for (i = 0; i < %s_len; ++i) {\n" n; pr " jobject o = (*env)->GetObjectArrayElement (env, j%s, i);\n" n; @@ -648,7 +648,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close n n | OStringList n -> pr " %s_len = (*env)->GetArrayLength (env, j%s);\n" n n; - pr " %s = guestfs_safe_malloc (g, sizeof (char *) * (%s_len+1));\n" n n; + pr " %s = guestfs___safe_malloc (g, sizeof (char *) * (%s_len+1));\n" n n; pr " for (i = 0; i < %s_len; ++i) {\n" n; pr " jobject o = (*env)->GetObjectArrayElement (env, j%s, i);\n" n; diff --git a/generator/ocaml.ml b/generator/ocaml.ml index f9ac5ca5e..1ecdea812 100644 --- a/generator/ocaml.ml +++ b/generator/ocaml.ml @@ -503,14 +503,14 @@ copy_table (char * const * argv) | FileOut n | Key n -> (* Copy strings in case the GC moves them: RHBZ#604691 *) - pr " char *%s = guestfs_safe_strdup (g, String_val (%sv));\n" n n + pr " char *%s = guestfs___safe_strdup (g, String_val (%sv));\n" n n | OptString n -> pr " char *%s =\n" n; pr " %sv != Val_int (0) ?\n" n; - pr " guestfs_safe_strdup (g, String_val (Field (%sv, 0))) : NULL;\n" n + pr " guestfs___safe_strdup (g, String_val (Field (%sv, 0))) : NULL;\n" n | BufferIn n -> pr " size_t %s_size = caml_string_length (%sv);\n" n n; - pr " char *%s = guestfs_safe_memdup (g, String_val (%sv), %s_size);\n" n n n + pr " char *%s = guestfs___safe_memdup (g, String_val (%sv), %s_size);\n" n n n | StringList n | DeviceList n -> pr " char **%s = ocaml_guestfs_strings_val (g, %sv);\n" n n | Bool n -> @@ -539,7 +539,7 @@ copy_table (char * const * argv) | OInt _ -> pr "Int_val (Field (%sv, 0))" n | OInt64 _ -> pr "Int64_val (Field (%sv, 0))" n | OString _ -> - pr "guestfs_safe_strdup (g, String_val (Field (%sv, 0)))" n + pr "guestfs___safe_strdup (g, String_val (Field (%sv, 0)))" n | OStringList n -> pr "ocaml_guestfs_strings_val (g, Field (%sv, 0))\n" n ); diff --git a/generator/perl.ml b/generator/perl.ml index b4c4caf4b..aa5ca260c 100644 --- a/generator/perl.ml +++ b/generator/perl.ml @@ -170,7 +170,7 @@ get_all_event_callbacks (guestfs_h *g, size_t *len_rtn) } /* Copy them into the return array. */ - r = guestfs_safe_malloc (g, sizeof (SV *) * (*len_rtn)); + r = guestfs___safe_malloc (g, sizeof (SV *) * (*len_rtn)); i = 0; cb = guestfs_first_private (g, &key); @@ -458,7 +458,7 @@ user_cancel (g) pr " /* Note av_len returns index of final element. */\n"; pr " len = av_len (av) + 1;\n"; pr "\n"; - pr " r = guestfs_safe_malloc (g, (len+1) * sizeof (char *));\n"; + pr " r = guestfs___safe_malloc (g, (len+1) * sizeof (char *));\n"; pr " for (i = 0; i < len; ++i) {\n"; pr " svp = av_fetch (av, i, 0);\n"; pr " r[i] = SvPV_nolen (*svp);\n"; diff --git a/generator/ruby.ml b/generator/ruby.ml index 6cc17fc20..daf94a5c9 100644 --- a/generator/ruby.ml +++ b/generator/ruby.ml @@ -207,7 +207,7 @@ ruby_set_event_callback (VALUE gv, VALUE cbv, VALUE event_bitmaskv) event_bitmask = NUM2ULL (event_bitmaskv); - root = guestfs_safe_malloc (g, sizeof *root); + root = guestfs___safe_malloc (g, sizeof *root); *root = cbv; eh = guestfs_set_event_callback (g, ruby_event_callback_wrapper, @@ -352,7 +352,7 @@ get_all_event_callbacks (guestfs_h *g, size_t *len_rtn) } /* Copy them into the return array. */ - r = guestfs_safe_malloc (g, sizeof (VALUE *) * (*len_rtn)); + r = guestfs___safe_malloc (g, sizeof (VALUE *) * (*len_rtn)); i = 0; root = guestfs_first_private (g, &key); diff --git a/java/Makefile.am b/java/Makefile.am index 3ce593bd3..b655ae9c1 100644 --- a/java/Makefile.am +++ b/java/Makefile.am @@ -77,9 +77,10 @@ libguestfs_jni_la_SOURCES = \ libguestfs_jni_la_LIBADD = $(top_builddir)/src/libguestfs.la libguestfs_jni_la_LDFLAGS = -version-info $(JNI_VERSION_INFO) -shared libguestfs_jni_la_CFLAGS = \ - $(WARN_CFLAGS) $(WERROR_CFLAGS) \ - -I$(top_srcdir)/src -I$(top_builddir)/src \ - $(JNI_CFLAGS) + -DGUESTFS_PRIVATE_FUNCTIONS=1 \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) \ + -I$(top_srcdir)/src -I$(top_builddir)/src \ + $(JNI_CFLAGS) BUILT_SOURCES = com_redhat_et_libguestfs_GuestFS.h diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am index a17f6166e..3bd2a7841 100644 --- a/ocaml/Makefile.am +++ b/ocaml/Makefile.am @@ -64,6 +64,7 @@ mlguestfs.cmxa: libguestfsocaml.a guestfs.cmx -L$(top_builddir)/src/.libs -lguestfs libguestfsocaml_a_CFLAGS = \ + -DGUESTFS_PRIVATE_FUNCTIONS=1 \ -I$(top_builddir) -I$(OCAMLLIB) -I$(top_srcdir)/ocaml \ -I$(top_srcdir)/src -I$(top_builddir)/src \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ diff --git a/ocaml/guestfs-c.c b/ocaml/guestfs-c.c index 90eea547e..0b3369fd5 100644 --- a/ocaml/guestfs-c.c +++ b/ocaml/guestfs-c.c @@ -168,7 +168,7 @@ ocaml_guestfs_create (value environmentv, value close_on_exitv, value unitv) /* Store the OCaml handle into the C handle. This is only so we can * map the C handle to the OCaml handle in event_callback_wrapper. */ - v = guestfs_safe_malloc (g, sizeof *v); + v = guestfs___safe_malloc (g, sizeof *v); *v = gv; /* XXX This global root is generational, but we cannot rely on every * user having the OCaml 3.11 version which supports this. @@ -201,9 +201,9 @@ ocaml_guestfs_strings_val (guestfs_h *g, value sv) char **r; size_t i; - r = guestfs_safe_malloc (g, sizeof (char *) * (Wosize_val (sv) + 1)); + r = guestfs___safe_malloc (g, sizeof (char *) * (Wosize_val (sv) + 1)); for (i = 0; i < Wosize_val (sv); ++i) - r[i] = guestfs_safe_strdup (g, String_val (Field (sv, i))); + r[i] = guestfs___safe_strdup (g, String_val (Field (sv, i))); r[i] = NULL; CAMLreturnT (char **, r); @@ -246,7 +246,7 @@ ocaml_guestfs_set_event_callback (value gv, value closure, value events) event_bitmask = event_bitmask_of_event_list (events); - value *root = guestfs_safe_malloc (g, sizeof *root); + value *root = guestfs___safe_malloc (g, sizeof *root); *root = closure; eh = guestfs_set_event_callback (g, event_callback_wrapper, @@ -309,7 +309,7 @@ get_all_event_callbacks (guestfs_h *g, size_t *len_rtn) } /* Copy them into the return array. */ - r = guestfs_safe_malloc (g, sizeof (value *) * (*len_rtn)); + r = guestfs___safe_malloc (g, sizeof (value *) * (*len_rtn)); i = 0; root = guestfs_first_private (g, &key); diff --git a/perl/Makefile.PL.in b/perl/Makefile.PL.in index 9fbeb4572..11a976a4d 100644 --- a/perl/Makefile.PL.in +++ b/perl/Makefile.PL.in @@ -27,5 +27,5 @@ WriteMakefile ( LIBS => '-L@top_builddir@/src/.libs -lguestfs', INC => '-I@top_builddir@/src -I@top_srcdir@/src', TYPEMAPS => [ '@srcdir@/typemap' ], - CCFLAGS => $Config{ccflags} . ' @CFLAGS@', + CCFLAGS => $Config{ccflags} . ' -DGUESTFS_PRIVATE_FUNCTIONS=1 @CFLAGS@', ); diff --git a/python/Makefile.am b/python/Makefile.am index 84941b301..8000f1c69 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -40,8 +40,11 @@ python_DATA = guestfs.py python_LTLIBRARIES = libguestfsmod.la libguestfsmod_la_SOURCES = guestfs-py.c guestfs-py.h guestfs-py-byhand.c -libguestfsmod_la_CFLAGS = -Wall -I$(PYTHON_INCLUDEDIR) \ - -I$(top_srcdir)/src -I$(top_builddir)/src +libguestfsmod_la_CFLAGS = \ + -DGUESTFS_PRIVATE_FUNCTIONS=1 \ + -Wall \ + -I$(PYTHON_INCLUDEDIR) \ + -I$(top_srcdir)/src -I$(top_builddir)/src libguestfsmod_la_LIBADD = $(top_builddir)/src/libguestfs.la libguestfsmod_la_LDFLAGS = -avoid-version -shared diff --git a/python/guestfs-py-byhand.c b/python/guestfs-py-byhand.c index 6cbbf5064..5edaaf2da 100644 --- a/python/guestfs-py-byhand.c +++ b/python/guestfs-py-byhand.c @@ -219,7 +219,7 @@ get_all_event_callbacks (guestfs_h *g, size_t *len_rtn) } /* Copy them into the return array. */ - r = guestfs_safe_malloc (g, sizeof (PyObject *) * (*len_rtn)); + r = guestfs___safe_malloc (g, sizeof (PyObject *) * (*len_rtn)); i = 0; cb = guestfs_first_private (g, &key); diff --git a/src/Makefile.am b/src/Makefile.am index dafc48819..1057245b3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -195,6 +195,7 @@ libguestfs_la_LIBADD += liberrnostring.la libprotocol.la libguestfs_la_CFLAGS = \ -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' \ -DGUESTFS_WARN_DEPRECATED=1 \ + -DGUESTFS_PRIVATE_FUNCTIONS=1 \ -DLIBOSINFO_DB_PATH='"$(datadir)/libosinfo/db"' \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ $(GPROF_CFLAGS) $(GCOV_CFLAGS) \ diff --git a/src/alloc.c b/src/alloc.c index dc64bbd8c..25d7f428c 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -27,7 +27,7 @@ #include "guestfs-internal.h" void * -guestfs_safe_malloc (guestfs_h *g, size_t nbytes) +guestfs___safe_malloc (guestfs_h *g, size_t nbytes) { void *ptr = malloc (nbytes); if (nbytes > 0 && !ptr) g->abort_cb (); @@ -60,7 +60,7 @@ guestfs_safe_malloc (guestfs_h *g, size_t nbytes) /* Allocate zeroed memory for N elements of S bytes, with error checking. S must be nonzero. */ void * -guestfs_safe_calloc (guestfs_h *g, size_t n, size_t s) +guestfs___safe_calloc (guestfs_h *g, size_t n, size_t s) { /* From gnulib's calloc function in xmalloc.c. */ void *p; @@ -75,7 +75,7 @@ guestfs_safe_calloc (guestfs_h *g, size_t n, size_t s) } void * -guestfs_safe_realloc (guestfs_h *g, void *ptr, size_t nbytes) +guestfs___safe_realloc (guestfs_h *g, void *ptr, size_t nbytes) { void *p = realloc (ptr, nbytes); if (nbytes > 0 && !p) g->abort_cb (); @@ -83,7 +83,7 @@ guestfs_safe_realloc (guestfs_h *g, void *ptr, size_t nbytes) } char * -guestfs_safe_strdup (guestfs_h *g, const char *str) +guestfs___safe_strdup (guestfs_h *g, const char *str) { char *s = strdup (str); if (!s) g->abort_cb (); @@ -91,7 +91,7 @@ guestfs_safe_strdup (guestfs_h *g, const char *str) } char * -guestfs_safe_strndup (guestfs_h *g, const char *str, size_t n) +guestfs___safe_strndup (guestfs_h *g, const char *str, size_t n) { char *s = strndup (str, n); if (!s) g->abort_cb (); @@ -99,7 +99,7 @@ guestfs_safe_strndup (guestfs_h *g, const char *str, size_t n) } void * -guestfs_safe_memdup (guestfs_h *g, const void *ptr, size_t size) +guestfs___safe_memdup (guestfs_h *g, const void *ptr, size_t size) { void *p = malloc (size); if (!p) g->abort_cb (); @@ -108,7 +108,7 @@ guestfs_safe_memdup (guestfs_h *g, const void *ptr, size_t size) } char * -guestfs_safe_asprintf (guestfs_h *g, const char *fs, ...) +guestfs___safe_asprintf (guestfs_h *g, const char *fs, ...) { va_list args; char *msg; diff --git a/src/events.c b/src/events.c index 947422834..67dba2333 100644 --- a/src/events.c +++ b/src/events.c @@ -57,8 +57,8 @@ guestfs_set_event_callback (guestfs_h *g, int event_handle = (int) g->nr_events; g->events = - guestfs_safe_realloc (g, g->events, - (g->nr_events+1) * sizeof (struct event)); + safe_realloc (g, g->events, + (g->nr_events+1) * sizeof (struct event)); g->nr_events++; g->events[event_handle].event_bitmask = event_bitmask; @@ -242,8 +242,8 @@ replace_old_style_event_callback (guestfs_h *g, /* i == g->nr_events */ g->events = - guestfs_safe_realloc (g, g->events, - (g->nr_events+1) * sizeof (struct event)); + safe_realloc (g, g->events, + (g->nr_events+1) * sizeof (struct event)); g->nr_events++; replace: diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index df52f7427..870207bd7 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -459,20 +459,20 @@ struct guestfs_message_error; struct guestfs_progress; /* alloc.c */ -extern void *guestfs_safe_realloc (guestfs_h *g, void *ptr, size_t nbytes); -extern char *guestfs_safe_strdup (guestfs_h *g, const char *str); -extern char *guestfs_safe_strndup (guestfs_h *g, const char *str, size_t n); -extern void *guestfs_safe_memdup (guestfs_h *g, const void *ptr, size_t size); -extern char *guestfs_safe_asprintf (guestfs_h *g, const char *fs, ...) +extern void *guestfs___safe_realloc (guestfs_h *g, void *ptr, size_t nbytes); +extern char *guestfs___safe_strdup (guestfs_h *g, const char *str); +extern char *guestfs___safe_strndup (guestfs_h *g, const char *str, size_t n); +extern void *guestfs___safe_memdup (guestfs_h *g, const void *ptr, size_t size); +extern char *guestfs___safe_asprintf (guestfs_h *g, const char *fs, ...) __attribute__((format (printf,2,3))); -#define safe_calloc guestfs_safe_calloc -#define safe_malloc guestfs_safe_malloc -#define safe_realloc guestfs_safe_realloc -#define safe_strdup guestfs_safe_strdup -#define safe_strndup guestfs_safe_strndup -#define safe_memdup guestfs_safe_memdup -#define safe_asprintf guestfs_safe_asprintf +#define safe_calloc guestfs___safe_calloc +#define safe_malloc guestfs___safe_malloc +#define safe_realloc guestfs___safe_realloc +#define safe_strdup guestfs___safe_strdup +#define safe_strndup guestfs___safe_strndup +#define safe_memdup guestfs___safe_memdup +#define safe_asprintf guestfs___safe_asprintf /* errors.c */ extern void guestfs___init_error_handler (guestfs_h *g); diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index f65686ce5..8d3804dfb 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -33,10 +33,6 @@ #include #endif -#if defined(HAVE_LIBVIRT) && defined(HAVE_LIBXML2) -#define GUESTFS_PRIVATE_FOR_EACH_DISK 1 -#endif - #include "guestfs.h" #include "guestfs-internal.h" #include "guestfs-internal-actions.h" @@ -161,16 +157,20 @@ guestfs__add_domain (guestfs_h *g, const char *domain_name, * The callback function 'f' is called once for each disk. * * Returns number of disks, or -1 if there was an error. + * + * 'domv' is declared void* for convenience so it can appear as a + * private function in the public header. */ int guestfs___for_each_disk (guestfs_h *g, - virDomainPtr dom, + void *domv, int (*f) (guestfs_h *g, const char *filename, const char *format, int readonly, void *data), void *data) { + virDomainPtr dom = domv; int i, nr_added = 0, r = -1; virErrorPtr err; xmlDocPtr doc = NULL;