[PATCH 1/3] build: avoid gcc preprocessor extensions

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

 



Use of ',##__VA_ARGS__' is a gcc extension not guaranteed by
C99; thankfully, we can avoid it by lumping the format argument
into the var-args set.

* src/util/logging.h (VIR_DEBUG_INT, VIR_INFO_INT, VIR_WARN_INT)
(VIR_ERROR_INT, VIR_DEBUG, VIR_INFO, VIR_WARN, VIR_ERROR): Stick
to C99 var-arg macro syntax.
* examples/domain-events/events-c/event-test.c (VIR_DEBUG):
Simplify.
---

This one turned out to be much simpler than I was fearing; any
time we guarantee that (fmt,...) expands to (fmt,##__VA_ARGS__),
then we just use one fewer argument (...) expanding to (__VA_ARGS__).

 examples/domain-events/events-c/event-test.c |    3 +-
 src/util/logging.h                           |   34 +++++++++++++-------------
 2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
index 52ec5d0..2da58b8 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -8,8 +8,7 @@
 #include <libvirt/libvirt.h>
 #include <libvirt/virterror.h>

-#define VIR_DEBUG(fmt, ...) printf("%s:%d: " fmt "\n", \
-        __func__, __LINE__, ##__VA_ARGS__)
+#define VIR_DEBUG(fmt) printf("%s:%d: " fmt "\n", __func__, __LINE__)
 #define STREQ(a,b) (strcmp(a,b) == 0)

 #ifndef ATTRIBUTE_UNUSED
diff --git a/src/util/logging.h b/src/util/logging.h
index e948077..6683e6f 100644
--- a/src/util/logging.h
+++ b/src/util/logging.h
@@ -31,28 +31,28 @@
  * defined at runtime from the libvirt daemon configuration file
  */
 # ifdef ENABLE_DEBUG
-#  define VIR_DEBUG_INT(category, f, l, fmt,...)                             \
-    virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, fmt, ##__VA_ARGS__)
+#  define VIR_DEBUG_INT(category, f, l, ...)                            \
+    virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__)
 # else
-#  define VIR_DEBUG_INT(category, f, l, fmt,...) \
+#  define VIR_DEBUG_INT(category, f, l, ...)    \
     do { } while (0)
 # endif /* !ENABLE_DEBUG */

-# define VIR_INFO_INT(category, f, l, fmt,...)                              \
-    virLogMessage(category, VIR_LOG_INFO, f, l, 0, fmt, ##__VA_ARGS__)
-# define VIR_WARN_INT(category, f, l, fmt,...)                              \
-    virLogMessage(category, VIR_LOG_WARN, f, l, 0, fmt, ##__VA_ARGS__)
-# define VIR_ERROR_INT(category, f, l, fmt,...)                             \
-    virLogMessage(category, VIR_LOG_ERROR, f, l, 0, fmt, ##__VA_ARGS__)
+# define VIR_INFO_INT(category, f, l, ...)                              \
+    virLogMessage(category, VIR_LOG_INFO, f, l, 0, __VA_ARGS__)
+# define VIR_WARN_INT(category, f, l, ...)                              \
+    virLogMessage(category, VIR_LOG_WARN, f, l, 0, __VA_ARGS__)
+# define VIR_ERROR_INT(category, f, l, ...)                             \
+    virLogMessage(category, VIR_LOG_ERROR, f, l, 0, __VA_ARGS__)

-# define VIR_DEBUG(fmt,...)                                                  \
-        VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
-# define VIR_INFO(fmt,...)                                                   \
-        VIR_INFO_INT("file." __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
-# define VIR_WARN(fmt,...)                                                   \
-        VIR_WARN_INT("file." __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
-# define VIR_ERROR(fmt,...)                                                  \
-        VIR_ERROR_INT("file." __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)
+# define VIR_DEBUG(...)                                                 \
+        VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
+# define VIR_INFO(...)                                                  \
+        VIR_INFO_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
+# define VIR_WARN(...)                                                  \
+        VIR_WARN_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
+# define VIR_ERROR(...)                                                 \
+        VIR_ERROR_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)

 /*
  * To be made public
-- 
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]