[PATCH 2.5/3] build: wrap macro body in one-shot do-while loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* src/libvirt.c (VIR_DOMAIN_DEBUG_1): Convert to single statement.
Suggested by Jiri Denemark.
---

> Personally I would prefer this macro to be ``do { ... } while (0)'' but that a
> preexisting issue and given that it's only used at the beginning of functions
> I guess I can live without this modification.

I think this falls under the trivial rule, so I'm posting it as part
of the series.

> Heh, that's a pure ugliness. But at least it's a self-contained ugliness and
> serves a good purpose. ACK

I've pushed 2 and 2.5 now.

 src/libvirt.c |   35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index 79278b9..0726df4 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -313,7 +313,12 @@ static struct gcry_thread_cbs virTLSThreadImpl = {

 /* Helper macros to implement VIR_DOMAIN_DEBUG using just C99.  This
  * assumes you pass fewer than 10 arguments to VIR_DOMAIN_DEBUG, but
- * can easily be expanded if needed.  */
+ * can easily be expanded if needed.
+ *
+ * Note that gcc provides extensions of "define a(b...) b" or
+ * "define a(b,...) b,##__VA_ARGS__" as a means of eliding a comma
+ * when no var-args are present, but we don't want to require gcc.
+ */
 #define VIR_ARG10(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, ...) _10
 #define VIR_HAS_COMMA(...) VIR_ARG10(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 0)

@@ -330,19 +335,21 @@ static struct gcry_thread_cbs virTLSThreadImpl = {
     VIR_DOMAIN_DEBUG_1(dom, "%s", "")

 /* Internal use only, when VIR_DOMAIN_DEBUG has three or more arguments.  */
-#define VIR_DOMAIN_DEBUG_1(dom, fmt, ...)                 \
-    char _uuidstr[VIR_UUID_STRING_BUFLEN];                \
-    const char *_domname = NULL;                          \
-                                                          \
-    if (!VIR_IS_DOMAIN(dom)) {                            \
-        memset(_uuidstr, 0, sizeof(_uuidstr));            \
-    } else {                                              \
-        virUUIDFormat((dom)->uuid, _uuidstr);             \
-        _domname = (dom)->name;                           \
-    }                                                     \
-                                                          \
-    VIR_DEBUG("dom=%p, (VM: name=%s, uuid=%s), " fmt,         \
-          dom, NULLSTR(_domname), _uuidstr, __VA_ARGS__)
+#define VIR_DOMAIN_DEBUG_1(dom, fmt, ...)                               \
+    do {                                                                \
+        char _uuidstr[VIR_UUID_STRING_BUFLEN];                          \
+        const char *_domname = NULL;                                    \
+                                                                        \
+        if (!VIR_IS_DOMAIN(dom)) {                                      \
+            memset(_uuidstr, 0, sizeof(_uuidstr));                      \
+        } else {                                                        \
+            virUUIDFormat((dom)->uuid, _uuidstr);                       \
+            _domname = (dom)->name;                                     \
+        }                                                               \
+                                                                        \
+        VIR_DEBUG("dom=%p, (VM: name=%s, uuid=%s), " fmt,               \
+                  dom, NULLSTR(_domname), _uuidstr, __VA_ARGS__);       \
+    } while (0)

 /**
  * VIR_DOMAIN_DEBUG:
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]