]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Move the VIR_AUTO(CLEAN|PTR) helper macros into a separate header
authorPeter Krempa <pkrempa@redhat.com>
Mon, 1 Apr 2019 13:14:30 +0000 (15:14 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 10 Apr 2019 07:12:03 +0000 (09:12 +0200)
Keeping them with viralloc.h forcibly pulls in the other stuff from
viralloc.h into other header files. This in turn creates a mess
as more and more headers pull in the 'viral' header file.

If we want to make 'viralloc.h' omnipresent we should pick a different
approach.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
31 files changed:
src/Makefile.am
src/conf/domain_capabilities.h
src/conf/storage_conf.h
src/qemu/qemu_firmware.h
src/qemu/qemu_migration_params.h
src/util/Makefile.inc.am
src/util/viralloc.h
src/util/virauthconfig.h
src/util/virautoclean.h [new file with mode: 0644]
src/util/virbitmap.h
src/util/virbuffer.h
src/util/vircommand.h
src/util/virerror.h
src/util/virfile.h
src/util/virfirewall.h
src/util/virhash.h
src/util/virjson.h
src/util/virmacaddr.h
src/util/virmdev.h
src/util/virnetdev.h
src/util/virnetdevip.h
src/util/virnetdevvlan.h
src/util/virnetlink.h
src/util/virpci.h
src/util/virperf.h
src/util/virscsi.h
src/util/virscsivhost.h
src/util/virsocketaddr.h
src/util/virstoragefile.h
src/util/virusb.h
src/util/virxml.h

index a73f43c4835b63a5c31e20057668a98608112506..b3b1e172ff5c5bb683dbf8ca7b5992f9519c44ee 100644 (file)
@@ -662,6 +662,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
                util/virarch.c \
                util/viratomic.c \
                util/viratomic.h \
+               util/virautoclean.h \
                util/virbitmap.c \
                util/virbuffer.c \
                util/vircgroup.c \
@@ -874,6 +875,7 @@ libvirt_nss_la_SOURCES = \
                util/viralloc.h \
                util/viratomic.c \
                util/viratomic.h \
+               util/virautoclean.h \
                util/virbitmap.c \
                util/virbitmap.h \
                util/virbuffer.c \
index 26f4b8c3945c12321756ceb4892ab7592c2c1838..4ba981d7f89ac9a4999fbcbce9c02baa15b3405c 100644 (file)
@@ -24,6 +24,7 @@
 # include "internal.h"
 # include "domain_conf.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 typedef const char * (*virDomainCapsValToStr)(int value);
 
index 87db8edadb6b979ccf17087ed96c4646b6fe534a..d848fa0fb7ecd47395605e911f09365db74360a9 100644 (file)
@@ -30,6 +30,7 @@
 # include "device_conf.h"
 # include "object_event.h"
 # include "storage_adapter_conf.h"
+# include "virautoclean.h"
 
 # include <libxml/tree.h>
 
index 7f8a0e4a1574cb3f9e881942a74a828faf974c38..8e193fb35c0e25668cf197698c649a1a2378accf 100644 (file)
@@ -24,6 +24,7 @@
 # include "domain_conf.h"
 # include "viralloc.h"
 # include "qemu_conf.h"
+# include "virautoclean.h"
 
 typedef struct _qemuFirmware qemuFirmware;
 typedef qemuFirmware *qemuFirmwarePtr;
index 0515339d9145bd99499cdfe5980b79b90b985006..303c266969abf0dd8631daa2b90574b865f96113 100644 (file)
@@ -28,6 +28,7 @@
 # include "virxml.h"
 # include "qemu_monitor.h"
 # include "qemu_conf.h"
+# include "virautoclean.h"
 
 typedef enum {
     QEMU_MIGRATION_CAP_XBZRLE,
index aa5c6cbe03c92298ef32a19254c89186b782e901..6b24245aa112d5b570705307e9a82bbbc70f2b4d 100644 (file)
@@ -15,6 +15,7 @@ UTIL_SOURCES = \
        util/virauth.h \
        util/virauthconfig.c \
        util/virauthconfig.h \
+       util/virautoclean.h \
        util/virbitmap.c \
        util/virbitmap.h \
        util/virbuffer.c \
index 93ec36aae2dd599d215a4a683c3423970a354adb..92c71d9a1add05b6f50fa4d3cdc98bf11b234576 100644 (file)
@@ -606,42 +606,6 @@ int virAllocTestCount(void);
 void virAllocTestOOM(int n, int m);
 void virAllocTestHook(void (*func)(int, void*), void *data);
 
-# define VIR_AUTOPTR_FUNC_NAME(type) type##AutoPtrFree
-
-/**
- * VIR_DEFINE_AUTOPTR_FUNC:
- * @type: type of the variable to be freed automatically
- * @func: cleanup function to be automatically called
- *
- * This macro defines a function for automatic freeing of
- * resources allocated to a variable of type @type. This newly
- * defined function works as a necessary wrapper around @func.
- */
-# define VIR_DEFINE_AUTOPTR_FUNC(type, func) \
-    static inline void VIR_AUTOPTR_FUNC_NAME(type)(type **_ptr) \
-    { \
-        if (*_ptr) \
-            (func)(*_ptr); \
-        *_ptr = NULL; \
-    }
-
-# define VIR_AUTOCLEAN_FUNC_NAME(type) type##AutoClean
-
-/**
- * VIR_DEFINE_AUTOCLEAN_FUNC:
- * @type: type of the variable to be cleared automatically
- * @func: cleanup function to be automatically called
- *
- * This macro defines a function for automatic clearing of
- * resources in a stack'd variable of type @type. Note that @func must
- * take pointer to @type.
- */
-# define VIR_DEFINE_AUTOCLEAN_FUNC(type, func) \
-    static inline void VIR_AUTOCLEAN_FUNC_NAME(type)(type *_ptr) \
-    { \
-        (func)(_ptr); \
-    }
-
 /**
  * VIR_AUTOFREE:
  * @type: type of the variable to be freed automatically
@@ -652,34 +616,4 @@ void virAllocTestHook(void (*func)(int, void*), void *data);
  */
 # define VIR_AUTOFREE(type) __attribute__((cleanup(virFree))) type
 
-/**
- * VIR_AUTOPTR:
- * @type: type of the variable to be freed automatically
- *
- * Macro to automatically free the memory allocated to
- * the variable declared with it by calling the function
- * defined by VIR_DEFINE_AUTOPTR_FUNC when the variable
- * goes out of scope.
- *
- * Note that this macro must NOT be used with vectors! The freeing function
- * will not free any elements beyond the first.
- */
-# define VIR_AUTOPTR(type) \
-    __attribute__((cleanup(VIR_AUTOPTR_FUNC_NAME(type)))) type *
-
-/**
- * VIR_AUTOCLEAN:
- * @type: type of the variable to be cleared automatically
- *
- * Macro to automatically call clearing function registered for variable of @type
- * when the variable goes out of scope.
- * The cleanup function is registered by VIR_DEFINE_AUTOCLEAN_FUNC macro for
- * the given type.
- *
- * Note that this macro must NOT be used with vectors! The cleaning function
- * will not clean any elements beyond the first.
- */
-# define VIR_AUTOCLEAN(type) \
-    __attribute__((cleanup(VIR_AUTOCLEAN_FUNC_NAME(type)))) type
-
 #endif /* LIBVIRT_VIRALLOC_H */
index 603ef89d25e4157bea17acdceb06619d6d496daa..9da0366e811bca30b04f9c868ec34649f70ecfeb 100644 (file)
@@ -23,6 +23,7 @@
 
 # include "internal.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 typedef struct _virAuthConfig virAuthConfig;
 typedef virAuthConfig *virAuthConfigPtr;
diff --git a/src/util/virautoclean.h b/src/util/virautoclean.h
new file mode 100644 (file)
index 0000000..b632023
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * virautoclean.h: automatic scope-based memory clearing helper macros for
+ *                 use in header files
+ *
+ * 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.1 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, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef LIBVIRT_VIRAUTOCLEAN_H
+# define LIBVIRT_VIRAUTOCLEAN_H
+
+# define VIR_AUTOPTR_FUNC_NAME(type) type##AutoPtrFree
+
+/**
+ * VIR_DEFINE_AUTOPTR_FUNC:
+ * @type: type of the variable to be freed automatically
+ * @func: cleanup function to be automatically called
+ *
+ * This macro defines a function for automatic freeing of
+ * resources allocated to a variable of type @type. This newly
+ * defined function works as a necessary wrapper around @func.
+ */
+# define VIR_DEFINE_AUTOPTR_FUNC(type, func) \
+    static inline void VIR_AUTOPTR_FUNC_NAME(type)(type **_ptr) \
+    { \
+        if (*_ptr) \
+            (func)(*_ptr); \
+        *_ptr = NULL; \
+    }
+
+# define VIR_AUTOCLEAN_FUNC_NAME(type) type##AutoClean
+
+/**
+ * VIR_DEFINE_AUTOCLEAN_FUNC:
+ * @type: type of the variable to be cleared automatically
+ * @func: cleanup function to be automatically called
+ *
+ * This macro defines a function for automatic clearing of
+ * resources in a stack'd variable of type @type. Note that @func must
+ * take pointer to @type.
+ */
+# define VIR_DEFINE_AUTOCLEAN_FUNC(type, func) \
+    static inline void VIR_AUTOCLEAN_FUNC_NAME(type)(type *_ptr) \
+    { \
+        (func)(_ptr); \
+    }
+
+/**
+ * VIR_AUTOPTR:
+ * @type: type of the variable to be freed automatically
+ *
+ * Macro to automatically free the memory allocated to
+ * the variable declared with it by calling the function
+ * defined by VIR_DEFINE_AUTOPTR_FUNC when the variable
+ * goes out of scope.
+ *
+ * Note that this macro must NOT be used with vectors! The freeing function
+ * will not free any elements beyond the first.
+ */
+# define VIR_AUTOPTR(type) \
+    __attribute__((cleanup(VIR_AUTOPTR_FUNC_NAME(type)))) type *
+
+/**
+ * VIR_AUTOCLEAN:
+ * @type: type of the variable to be cleared automatically
+ *
+ * Macro to automatically call clearing function registered for variable of @type
+ * when the variable goes out of scope.
+ * The cleanup function is registered by VIR_DEFINE_AUTOCLEAN_FUNC macro for
+ * the given type.
+ *
+ * Note that this macro must NOT be used with vectors! The cleaning function
+ * will not clean any elements beyond the first.
+ */
+# define VIR_AUTOCLEAN(type) \
+    __attribute__((cleanup(VIR_AUTOCLEAN_FUNC_NAME(type)))) type
+
+#endif /* LIBVIRT_VIRAUTOCLEAN_H */
index c54e203971f0ae1ff08dd2d3dbca238054fbc169..b4d36732921724b6d87948adca0ffcff04554752 100644 (file)
@@ -24,6 +24,7 @@
 
 # include "internal.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 # include <sys/types.h>
 
index 18957ae02cd4d4ff38140d015b4c3d530ca1f154..2f5efdf2b74e50eb09f894b75f5da29fd48860ae 100644 (file)
@@ -25,6 +25,7 @@
 
 # include "internal.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 
 /**
index efdc5dd00d12b3c6c37c28956d0d5447675bb4f6..fab852cebfc939240904974e23fad1a618901c68 100644 (file)
@@ -25,6 +25,7 @@
 # include "internal.h"
 # include "virbuffer.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 typedef struct _virCommand virCommand;
 typedef virCommand *virCommandPtr;
index 213bc3f606b9a8f6023a703e1646c72a3f0639fa..4f691550bce313a9a302d80ceecbaa1a416a58f6 100644 (file)
@@ -24,6 +24,7 @@
 
 # include "internal.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 # define VIR_ERROR_MAX_LENGTH 1024
 
index df35a32bccaf92baf741ae7e27a18d303597d2ad..4f50ba9a5bcf48b39dca82040ad83e223f86dd30 100644 (file)
@@ -31,6 +31,7 @@
 # include "virbitmap.h"
 # include "virstoragefile.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 typedef enum {
     VIR_FILE_CLOSE_PRESERVE_ERRNO = 1 << 0,
index e3ad1adb6b8b7d156d1c4d43ce9c2df2463bce3d..63bf915233274c88a675e40da12b8313b80e5796 100644 (file)
@@ -23,6 +23,7 @@
 
 # include "internal.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 typedef struct _virFirewall virFirewall;
 typedef virFirewall *virFirewallPtr;
index 2df1a5d12a8a08a3235d172577aed30571ad69c0..b1de808b1865de1fa96455303d772536eba1dda3 100644 (file)
@@ -12,6 +12,7 @@
 
 
 # include "viralloc.h"
+# include "virautoclean.h"
 
 /*
  * The hash table.
index ec8660379466641bee81f1d0c448145069bd3545..724d0283cc0e6bd60706637af1ab12d6ad8f9880 100644 (file)
@@ -27,6 +27,7 @@
 # include "virbitmap.h"
 # include "viralloc.h"
 # include "virbuffer.h"
+# include "virautoclean.h"
 
 # include <stdarg.h>
 
index 1deaf087e082641f7919c772cdaab14a06ec590a..6cb0ce326425aa8992b96b98178837d890d40515 100644 (file)
@@ -23,6 +23,7 @@
 
 # include "internal.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 # define VIR_MAC_BUFLEN 6
 # define VIR_MAC_HEXLEN (VIR_MAC_BUFLEN * 2)
index d787d354e4691778f697a17fea281a8978855358..9cc041e0dea38a18a511dda1d4732c79b743dac5 100644 (file)
@@ -23,6 +23,7 @@
 # include "virobject.h"
 # include "virutil.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 typedef enum {
     VIR_MDEV_MODEL_TYPE_VFIO_PCI = 0,
index 6f6094eebe8572d28f5b5e138eb7a6d8f23bfc92..262611f1798902407cc5f19b4545b23ada5e9bd6 100644 (file)
@@ -27,6 +27,7 @@
 # include "virpci.h"
 # include "virnetdevvlan.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 # ifdef HAVE_STRUCT_IFREQ
 typedef struct ifreq virIfreq;
index 376ac32c4788394df64f6b01b91961e5f8dddcb4..d885d09a009912bd538056ed346395dedc70a2bd 100644 (file)
@@ -20,6 +20,7 @@
 # define LIBVIRT_VIRNETDEVIP_H
 
 # include "virsocketaddr.h"
+# include "virautoclean.h"
 
 typedef struct _virNetDevIPAddr virNetDevIPAddr;
 typedef virNetDevIPAddr *virNetDevIPAddrPtr;
index 2a1375955083e5479930eede132c3f590cd2a0f9..ff4fb94abca8c696469eead89c662b3bc152c8bc 100644 (file)
@@ -22,6 +22,7 @@
 # include <virutil.h>
 
 # include "viralloc.h"
+# include "virautoclean.h"
 
 typedef enum {
     VIR_NATIVE_VLAN_MODE_DEFAULT = 0,
index 9dd7b3c3ed83f5189ac8ee4c319535f14d89331e..4405e87e1733f7ff85d1242a12023723c94fdfcb 100644 (file)
@@ -23,6 +23,7 @@
 # include "internal.h"
 # include "virmacaddr.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 # if defined(__linux__) && defined(HAVE_LIBNL)
 
index c8fc1e8bf628b6f8a02f0972438dc8f893a7756e..41651e2de422d4285efbfe6499f56a254dc1f94b 100644 (file)
@@ -26,6 +26,7 @@
 # include "virobject.h"
 # include "virutil.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 typedef struct _virPCIDevice virPCIDevice;
 typedef virPCIDevice *virPCIDevicePtr;
index 3cd26563b4be944ebb1684ff27eb6526b2d2a278..b625bb6846b85041690c2fb41cdd575a2f937df1 100644 (file)
@@ -21,6 +21,7 @@
 
 # include "virutil.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 /* Some Intel processor families introduced some RDT (Resource Director
  * Technology) features to monitor or control shared resource based on
index 70e113b4861a0f3ac562d4778d483f139f881c64..70673483d0110495fd918bbbc39907778b66787e 100644 (file)
@@ -24,6 +24,7 @@
 # include "internal.h"
 # include "virobject.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 typedef struct _virSCSIDevice virSCSIDevice;
 typedef virSCSIDevice *virSCSIDevicePtr;
index d28773482c886e1ed5256cda52ea6513badc4b80..5e9978c19cf04ccf87d0705732b5cfe5f0c929a5 100644 (file)
@@ -25,6 +25,7 @@
 # include "virobject.h"
 # include "virutil.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 typedef struct _virSCSIVHostDevice virSCSIVHostDevice;
 typedef virSCSIVHostDevice *virSCSIVHostDevicePtr;
index f6caa4fcf5429bb9cf02574965035c3c5020f584..2cc3f94b804984df80b8cc3d072083f7f94fac72 100644 (file)
@@ -27,6 +27,7 @@
 
 # include "internal.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 /* On architectures which lack these limits, define them (ie. Cygwin).
  * Note that the libvirt code should be robust enough to handle the
index 420c8a57f3b3edd6db38bb06a8eceb69d9f2a927..79cfb9cb40579fc2ce1777daff919a6fe4391dd9 100644 (file)
@@ -30,6 +30,7 @@
 # include "virstorageencryption.h"
 # include "virutil.h"
 # include "virsecret.h"
+# include "virautoclean.h"
 
 /* Minimum header size required to probe all known formats with
  * virStorageFileProbeFormat, or obtain metadata from a known format.
index 6ed71606d4e8b874540829746ff994858a70d5dd..d3067e36e31bf130a8d14f253d8eb5f34cc2ec75 100644 (file)
@@ -24,6 +24,7 @@
 # include "internal.h"
 # include "virobject.h"
 # include "viralloc.h"
+# include "virautoclean.h"
 
 # define USB_DEVFS "/dev/bus/usb/"
 
index 4875e88f2e6a0aa47542d19f8fd12b9ea1055833..38031b62c5876577b94e558eec5d1a981eaf1372 100644 (file)
@@ -29,6 +29,7 @@
 # include <libxml/relaxng.h>
 
 # include "virbuffer.h"
+# include "virautoclean.h"
 
 int              virXPathBoolean(const char *xpath,
                                  xmlXPathContextPtr ctxt);