From ec3b75e5ffd1abea1400f6609ae9c61eab0dfa71 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 1 Feb 2013 13:43:38 +0000 Subject: [PATCH] Rearrange internal header files. This commit rearranges the internal header files. "src/guestfs-internal.h" is just for the library, as before. "src/guestfs-internal-frontend.h" is for use by all library, bindings, tools C code, but NOT the daemon. "src/guestfs-internal-all.h" is for use by all C code including the daemon. This is just code motion, but it has some important consequences: (1) We can use the CLEANUP_* macros in bindings and tools code. (2) We can get rid of TMP_TEMPLATE_ON_STACK. (3) We will (in future) be able to stop bindings and tools code from using the safe_* allocation functions (which are NOT safe to use outside the library alone). --- daemon/Makefile.am | 5 +- daemon/daemon.h | 22 +----- fish/display.c | 2 +- fish/edit.c | 2 +- fish/fish.c | 2 +- fish/fish.h | 25 +------ fish/hexedit.c | 2 +- fish/more.c | 2 +- fish/options.h | 35 +--------- fuse/guestmount.h | 13 +--- generator/c.ml | 18 +++-- generator/java.ml | 1 + ocaml/guestfs-c.c | 2 +- ocaml/guestfs-c.h | 14 +--- python/guestfs-py-byhand.c | 2 +- python/guestfs-py.h | 3 +- src/guestfs-internal-all.h | 65 ++++++++++++++++++ src/guestfs-internal-frontend.h | 117 ++++++++++++++++++++++++++++++++ src/guestfs-internal.h | 104 +--------------------------- 19 files changed, 218 insertions(+), 218 deletions(-) create mode 100644 src/guestfs-internal-all.h create mode 100644 src/guestfs-internal-frontend.h diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 91970b9b4..eac90580a 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -196,7 +196,10 @@ guestfsd_LDADD = \ $(LIBINTL) \ $(SERVENT_LIB) -guestfsd_CPPFLAGS = -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib +guestfsd_CPPFLAGS = \ + -I$(top_srcdir)/gnulib/lib \ + -I$(top_builddir)/gnulib/lib \ + -I$(top_builddir)/src guestfsd_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ $(AUGEAS_CFLAGS) \ diff --git a/daemon/daemon.h b/daemon/daemon.h index 25773952c..c9feb1375 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -30,6 +30,8 @@ #include "guestfs_protocol.h" +#include "guestfs-internal-all.h" + /*-- in guestfsd.c --*/ extern int verbose; @@ -389,26 +391,6 @@ is_zero (const char *buffer, size_t size) } \ while (0) -#ifndef __attribute__ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) -# define __attribute__(x) /* empty */ -# endif -#endif - -#ifndef ATTRIBUTE_UNUSED -# define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) -#endif - -#define STREQ(a,b) (strcmp((a),(b)) == 0) -#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) -#define STRNEQ(a,b) (strcmp((a),(b)) != 0) -#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0) -#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0) -#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0) -#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0) -#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0) -#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) - #ifdef HAVE_ATTRIBUTE_CLEANUP #define CLEANUP_FREE __attribute__((cleanup(cleanup_free))) #define CLEANUP_FREE_STRING_LIST \ diff --git a/fish/display.c b/fish/display.c index a5889db89..b820725d7 100644 --- a/fish/display.c +++ b/fish/display.c @@ -33,7 +33,7 @@ int run_display (const char *cmd, size_t argc, char *argv[]) { - TMP_TEMPLATE_ON_STACK (filename); + TMP_TEMPLATE_ON_STACK (g, filename); char *remote; const char *display; char buf[256]; diff --git a/fish/edit.c b/fish/edit.c index be3fb9ad7..5793054cf 100644 --- a/fish/edit.c +++ b/fish/edit.c @@ -39,7 +39,7 @@ static int copy_attributes (const char *src, const char *dest); int run_edit (const char *cmd, size_t argc, char *argv[]) { - TMP_TEMPLATE_ON_STACK (filename); + TMP_TEMPLATE_ON_STACK (g, filename); char buf[256]; const char *editor; char *remotefilename, *newname; diff --git a/fish/fish.c b/fish/fish.c index 5892d7746..71da49531 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -1812,7 +1812,7 @@ file_in (const char *arg) static char * file_in_heredoc (const char *endmarker) { - TMP_TEMPLATE_ON_STACK (template); + TMP_TEMPLATE_ON_STACK (g, template); int fd; size_t markerlen; char buffer[BUFSIZ]; diff --git a/fish/fish.h b/fish/fish.h index 4bccdf7d5..b4a14fcfb 100644 --- a/fish/fish.h +++ b/fish/fish.h @@ -21,31 +21,10 @@ #include +#include "guestfs-internal-frontend.h" + #include "fish-cmds.h" -#ifndef SOCK_CLOEXEC -#define SOCK_CLOEXEC 0 -#endif - -#define _(str) dgettext(PACKAGE, (str)) -#define N_(str) dgettext(PACKAGE, (str)) - -#define STREQ(a,b) (strcmp((a),(b)) == 0) -#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) -#define STRNEQ(a,b) (strcmp((a),(b)) != 0) -#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0) -#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0) -#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0) -#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0) -#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0) -#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) - -#define TMP_TEMPLATE_ON_STACK(var) \ - char *ttos_tmpdir = guestfs_get_tmpdir (g); \ - char var[strlen (ttos_tmpdir) + 32]; \ - sprintf (var, "%s/guestfishXXXXXX", ttos_tmpdir); \ - free (ttos_tmpdir) - /* in fish.c */ extern guestfs_h *g; extern int read_only; diff --git a/fish/hexedit.c b/fish/hexedit.c index 1057a3153..88c133f2d 100644 --- a/fish/hexedit.c +++ b/fish/hexedit.c @@ -101,7 +101,7 @@ run_hexedit (const char *cmd, size_t argc, char *argv[]) int r; struct stat oldstat, newstat; char buf[BUFSIZ]; - TMP_TEMPLATE_ON_STACK (tmp); + TMP_TEMPLATE_ON_STACK (g, tmp); int fd = mkstemp (tmp); if (fd == -1) { perror ("mkstemp"); diff --git a/fish/more.c b/fish/more.c index c5a94d392..b7064b2ed 100644 --- a/fish/more.c +++ b/fish/more.c @@ -31,7 +31,7 @@ int run_more (const char *cmd, size_t argc, char *argv[]) { - TMP_TEMPLATE_ON_STACK (filename); + TMP_TEMPLATE_ON_STACK (g, filename); char buf[256]; char *remote; const char *pager; diff --git a/fish/options.h b/fish/options.h index 137b2d728..d775edd49 100644 --- a/fish/options.h +++ b/fish/options.h @@ -19,40 +19,7 @@ #ifndef OPTIONS_H #define OPTIONS_H -#ifndef _ -#define _(str) dgettext(PACKAGE, (str)) -#endif -#ifndef N_ -#define N_(str) dgettext(PACKAGE, (str)) -#endif - -#ifndef STREQ -#define STREQ(a,b) (strcmp((a),(b)) == 0) -#endif -#ifndef STRCASEEQ -#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) -#endif -#ifndef STRNEQ -#define STRNEQ(a,b) (strcmp((a),(b)) != 0) -#endif -#ifndef STRCASENEQ -#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0) -#endif -#ifndef STREQLEN -#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0) -#endif -#ifndef STRCASEEQLEN -#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0) -#endif -#ifndef STRNEQLEN -#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0) -#endif -#ifndef STRCASENEQLEN -#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0) -#endif -#ifndef STRPREFIX -#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) -#endif +#include "guestfs-internal-frontend.h" /* Provided by guestfish or guestmount. */ extern guestfs_h *g; diff --git a/fuse/guestmount.h b/fuse/guestmount.h index 3f54c303a..6753bb467 100644 --- a/fuse/guestmount.h +++ b/fuse/guestmount.h @@ -25,18 +25,7 @@ #ifndef GUESTMOUNT_H_ #define GUESTMOUNT_H_ -#define _(str) dgettext(PACKAGE, (str)) -#define N_(str) dgettext(PACKAGE, (str)) - -#define STREQ(a,b) (strcmp((a),(b)) == 0) -#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) -#define STRNEQ(a,b) (strcmp((a),(b)) != 0) -#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0) -#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0) -#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0) -#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0) -#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0) -#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) +#include "guestfs-internal-frontend.h" static inline char * bad_cast (char const *s) diff --git a/generator/c.ml b/generator/c.ml index 87c6f48c2..4b5e574c7 100644 --- a/generator/c.ml +++ b/generator/c.ml @@ -690,11 +690,6 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_next_private (guestfs_h *g, const char * /* 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); "; @@ -1650,11 +1645,22 @@ and generate_linker_script () = (* Unofficial parts of the API: the bindings code use these * functions, so it is useful to export them. *) + "guestfs___cleanup_free"; + "guestfs___cleanup_free_string_list"; + "guestfs___cleanup_hash_free"; + "guestfs___cleanup_unlink_free"; +(* + "guestfs___cleanup_xmlBufferFree"; + "guestfs___cleanup_xmlFreeDoc"; + "guestfs___cleanup_xmlFreeTextWriter"; + "guestfs___cleanup_xmlXPathFreeContext"; + "guestfs___cleanup_xmlXPathFreeObject"; +*) + "guestfs___for_each_disk"; "guestfs___safe_calloc"; "guestfs___safe_malloc"; "guestfs___safe_strdup"; "guestfs___safe_memdup"; - "guestfs___for_each_disk"; ] in let functions = List.flatten ( diff --git a/generator/java.ml b/generator/java.ml index 12f4e0b31..a7ad39a36 100644 --- a/generator/java.ml +++ b/generator/java.ml @@ -549,6 +549,7 @@ and generate_java_c () = #include \"com_redhat_et_libguestfs_GuestFS.h\" #include \"guestfs.h\" +#include \"guestfs-internal-frontend.h\" /* This is the opaque data passed between _set_event_callback and * the C wrapper which calls the Java event callback. diff --git a/ocaml/guestfs-c.c b/ocaml/guestfs-c.c index 0b3369fd5..45437da31 100644 --- a/ocaml/guestfs-c.c +++ b/ocaml/guestfs-c.c @@ -1,5 +1,5 @@ /* libguestfs - * Copyright (C) 2009-2012 Red Hat Inc. + * Copyright (C) 2009-2013 Red Hat Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/ocaml/guestfs-c.h b/ocaml/guestfs-c.h index 8d3792108..fecaecf1e 100644 --- a/ocaml/guestfs-c.h +++ b/ocaml/guestfs-c.h @@ -1,5 +1,5 @@ /* libguestfs - * Copyright (C) 2009-2012 Red Hat Inc. + * Copyright (C) 2009-2013 Red Hat Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,6 +19,8 @@ #ifndef GUESTFS_OCAML_C_H #define GUESTFS_OCAML_C_H +#include "guestfs-internal-frontend.h" + #define Guestfs_val(v) (*((guestfs_h **)Data_custom_val(v))) extern void ocaml_guestfs_raise_error (guestfs_h *g, const char *func) Noreturn; @@ -27,14 +29,4 @@ extern void ocaml_guestfs_raise_closed (const char *func) extern char **ocaml_guestfs_strings_val (guestfs_h *g, value sv); extern void ocaml_guestfs_free_strings (char **r); -# ifdef __GNUC__ -# ifndef ATTRIBUTE_UNUSED -# define ATTRIBUTE_UNUSED __attribute__((__unused__)) -# endif -#else -# ifndef ATTRIBUTE_UNUSED -# define ATTRIBUTE_UNUSED -# endif -#endif - #endif /* GUESTFS_OCAML_C_H */ diff --git a/python/guestfs-py-byhand.c b/python/guestfs-py-byhand.c index 3f2e637d5..4fdae3759 100644 --- a/python/guestfs-py-byhand.c +++ b/python/guestfs-py-byhand.c @@ -1,5 +1,5 @@ /* libguestfs python bindings - * Copyright (C) 2009-2012 Red Hat Inc. + * Copyright (C) 2009-2013 Red Hat Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/python/guestfs-py.h b/python/guestfs-py.h index da4e4e8a9..56e907ae2 100644 --- a/python/guestfs-py.h +++ b/python/guestfs-py.h @@ -1,5 +1,5 @@ /* libguestfs python bindings - * Copyright (C) 2009-2012 Red Hat Inc. + * Copyright (C) 2009-2013 Red Hat Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,6 +20,7 @@ #define guestfs_py_h #include "guestfs.h" +#include "guestfs-internal-frontend.h" #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; diff --git a/src/guestfs-internal-all.h b/src/guestfs-internal-all.h new file mode 100644 index 000000000..3b28f4c9a --- /dev/null +++ b/src/guestfs-internal-all.h @@ -0,0 +1,65 @@ +/* libguestfs + * Copyright (C) 2013 Red Hat Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* NB: This contains ONLY definitions which are shared by libguestfs + * daemon, library, bindings and tools (ie. ALL C code). + */ + +#ifndef GUESTFS_INTERNAL_ALL_H_ +#define GUESTFS_INTERNAL_ALL_H_ + +#define STREQ(a,b) (strcmp((a),(b)) == 0) +#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) +#define STRNEQ(a,b) (strcmp((a),(b)) != 0) +#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0) +#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0) +#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0) +#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0) +#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0) +#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) +#define STRSUFFIX(a,b) (strlen((a)) >= strlen((b)) && STREQ((a)+strlen((a))-strlen((b)),(b))) + +#ifndef SOCK_CLOEXEC +#define SOCK_CLOEXEC 0 +#endif + +#ifdef __APPLE__ +#define UNIX_PATH_MAX 104 +#else +#define UNIX_PATH_MAX 108 +#endif + +#ifndef MAX +#define MAX(a,b) ((a)>(b)?(a):(b)) +#endif + +#ifdef __APPLE__ +#define xdr_uint32_t xdr_u_int32_t +#endif + +#ifndef __attribute__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) +# define __attribute__(x) /* empty */ +# endif +#endif + +#ifndef ATTRIBUTE_UNUSED +# define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +#endif + +#endif /* GUESTFS_INTERNAL_ALL_H_ */ diff --git a/src/guestfs-internal-frontend.h b/src/guestfs-internal-frontend.h new file mode 100644 index 000000000..3bac56fdf --- /dev/null +++ b/src/guestfs-internal-frontend.h @@ -0,0 +1,117 @@ +/* libguestfs + * Copyright (C) 2013 Red Hat Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* NB: This contains ONLY definitions which are shared by libguestfs + * library, bindings and tools (NOT the daemon). + * + * If a definition is only needed by a single component of libguestfs, + * then it should NOT be here! + * + * The daemon does NOT use this header. If you need a place to put + * something shared with absolutely everything including the daemon, + * put it in 'src/guestfs-internal-all.h'. + */ + +#ifndef GUESTFS_INTERNAL_FRONTEND_H_ +#define GUESTFS_INTERNAL_FRONTEND_H_ + +#include "guestfs-internal-all.h" + +#define _(str) dgettext(PACKAGE, (str)) +#define N_(str) dgettext(PACKAGE, (str)) + +#ifdef HAVE_ATTRIBUTE_CLEANUP +#define CLEANUP_FREE __attribute__((cleanup(guestfs___cleanup_free))) +#define CLEANUP_FREE_STRING_LIST \ + __attribute__((cleanup(guestfs___cleanup_free_string_list))) +#define CLEANUP_HASH_FREE \ + __attribute__((cleanup(guestfs___cleanup_hash_free))) +#define CLEANUP_UNLINK_FREE \ + __attribute__((cleanup(guestfs___cleanup_unlink_free))) +#ifdef HAVE_LIBXML2 +#define CLEANUP_XMLBUFFERFREE \ + __attribute__((cleanup(guestfs___cleanup_xmlBufferFree))) +#define CLEANUP_XMLFREEDOC \ + __attribute__((cleanup(guestfs___cleanup_xmlFreeDoc))) +#define CLEANUP_XMLFREETEXTWRITER \ + __attribute__((cleanup(guestfs___cleanup_xmlFreeTextWriter))) +#define CLEANUP_XMLXPATHFREECONTEXT \ + __attribute__((cleanup(guestfs___cleanup_xmlXPathFreeContext))) +#define CLEANUP_XMLXPATHFREEOBJECT \ + __attribute__((cleanup(guestfs___cleanup_xmlXPathFreeObject))) +#endif +#else +#define CLEANUP_FREE +#define CLEANUP_FREE_STRING_LIST +#define CLEANUP_HASH_FREE +#define CLEANUP_UNLINK_FREE +#ifdef HAVE_LIBXML2 +#define CLEANUP_XMLBUFFERFREE +#define CLEANUP_XMLFREEDOC +#define CLEANUP_XMLFREETEXTWRITER +#define CLEANUP_XMLXPATHFREECONTEXT +#define CLEANUP_XMLXPATHFREEOBJECT +#endif +#endif + +#define TMP_TEMPLATE_ON_STACK(g,var) \ + char *ttos_tmpdir = guestfs_get_tmpdir (g); \ + char var[strlen (ttos_tmpdir) + 32]; \ + sprintf (var, "%s/libguestfsXXXXXX", ttos_tmpdir); \ + free (ttos_tmpdir) + +/* NB: At some point we will stop exporting these safe_* allocation + * functions outside the library, so don't use them in new tools or + * bindings code. + */ +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 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 + +/* These functions are used internally by the CLEANUP_* macros. + * Don't call them directly. + */ +extern GUESTFS_DLL_PUBLIC void guestfs___cleanup_free (void *ptr); +extern GUESTFS_DLL_PUBLIC void guestfs___cleanup_free_string_list (void *ptr); +extern GUESTFS_DLL_PUBLIC void guestfs___cleanup_hash_free (void *ptr); +extern GUESTFS_DLL_PUBLIC void guestfs___cleanup_unlink_free (void *ptr); + +#ifdef HAVE_LIBXML2 +extern void guestfs___cleanup_xmlBufferFree (void *ptr); +extern void guestfs___cleanup_xmlFreeDoc (void *ptr); +extern void guestfs___cleanup_xmlFreeTextWriter (void *ptr); +extern void guestfs___cleanup_xmlXPathFreeContext (void *ptr); +extern void guestfs___cleanup_xmlXPathFreeObject (void *ptr); +#endif + +#endif /* GUESTFS_INTERNAL_FRONTEND_H_ */ diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h index ae14d6f39..0467558f4 100644 --- a/src/guestfs-internal.h +++ b/src/guestfs-internal.h @@ -34,23 +34,7 @@ #include "hash.h" -#ifndef SOCK_CLOEXEC -#define SOCK_CLOEXEC 0 -#endif - -#define STREQ(a,b) (strcmp((a),(b)) == 0) -#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0) -#define STRNEQ(a,b) (strcmp((a),(b)) != 0) -#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0) -#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0) -#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0) -#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0) -#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0) -#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0) -#define STRSUFFIX(a,b) (strlen((a)) >= strlen((b)) && STREQ((a)+strlen((a))-strlen((b)),(b))) - -#define _(str) dgettext(PACKAGE, (str)) -#define N_(str) dgettext(PACKAGE, (str)) +#include "guestfs-internal-frontend.h" #if ENABLE_PROBES #include @@ -72,60 +56,6 @@ #define TRACE4(name, arg1, arg2, arg3, arg4) #endif -#ifdef HAVE_ATTRIBUTE_CLEANUP -#define CLEANUP_FREE __attribute__((cleanup(guestfs___cleanup_free))) -#define CLEANUP_FREE_STRING_LIST \ - __attribute__((cleanup(guestfs___cleanup_free_string_list))) -#define CLEANUP_HASH_FREE \ - __attribute__((cleanup(guestfs___cleanup_hash_free))) -#define CLEANUP_UNLINK_FREE \ - __attribute__((cleanup(guestfs___cleanup_unlink_free))) -#ifdef HAVE_LIBXML2 -#define CLEANUP_XMLBUFFERFREE \ - __attribute__((cleanup(guestfs___cleanup_xmlBufferFree))) -#define CLEANUP_XMLFREEDOC \ - __attribute__((cleanup(guestfs___cleanup_xmlFreeDoc))) -#define CLEANUP_XMLFREETEXTWRITER \ - __attribute__((cleanup(guestfs___cleanup_xmlFreeTextWriter))) -#define CLEANUP_XMLXPATHFREECONTEXT \ - __attribute__((cleanup(guestfs___cleanup_xmlXPathFreeContext))) -#define CLEANUP_XMLXPATHFREEOBJECT \ - __attribute__((cleanup(guestfs___cleanup_xmlXPathFreeObject))) -#endif -#else -#define CLEANUP_FREE -#define CLEANUP_FREE_STRING_LIST -#define CLEANUP_HASH_FREE -#define CLEANUP_UNLINK_FREE -#ifdef HAVE_LIBXML2 -#define CLEANUP_XMLBUFFERFREE -#define CLEANUP_XMLFREEDOC -#define CLEANUP_XMLFREETEXTWRITER -#define CLEANUP_XMLXPATHFREECONTEXT -#define CLEANUP_XMLXPATHFREEOBJECT -#endif -#endif - -#define TMP_TEMPLATE_ON_STACK(g,var) \ - char *ttos_tmpdir = guestfs_get_tmpdir (g); \ - char var[strlen (ttos_tmpdir) + 32]; \ - sprintf (var, "%s/libguestfsXXXXXX", ttos_tmpdir); \ - free (ttos_tmpdir) - -#ifdef __APPLE__ -#define UNIX_PATH_MAX 104 -#else -#define UNIX_PATH_MAX 108 -#endif - -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - -#ifdef __APPLE__ -#define xdr_uint32_t xdr_u_int32_t -#endif - /* Some limits on what the inspection code will read, for safety. */ /* Small text configuration files. @@ -492,38 +422,6 @@ struct guestfs_message_header; 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, ...) - __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 - -/* These functions are used internally by the CLEANUP_* macros. - * Don't call them directly. - */ -extern void guestfs___cleanup_free (void *ptr); -extern void guestfs___cleanup_free_string_list (void *ptr); -extern void guestfs___cleanup_hash_free (void *ptr); -extern void guestfs___cleanup_unlink_free (void *ptr); - -#ifdef HAVE_LIBXML2 -extern void guestfs___cleanup_xmlBufferFree (void *ptr); -extern void guestfs___cleanup_xmlFreeDoc (void *ptr); -extern void guestfs___cleanup_xmlFreeTextWriter (void *ptr); -extern void guestfs___cleanup_xmlXPathFreeContext (void *ptr); -extern void guestfs___cleanup_xmlXPathFreeObject (void *ptr); -#endif - /* errors.c */ extern void guestfs___init_error_handler (guestfs_h *g);