vlog: Fix VLOG and VLOG_RL macros' treatment of LEVEL argument.
authorBen Pfaff <blp@nicira.com>
Thu, 7 Apr 2011 21:39:36 +0000 (14:39 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 19 Apr 2011 16:32:18 +0000 (09:32 -0700)
These macros expanded the LEVEL argument without protecting it with
parentheses, which meant that an argument like 'cond ? VLL_DBG : VLL_WARN'
did not have the desired effect (and caused a GCC warning).

This commit fixes the problem and avoids expanding LEVEL more than once,
too.

lib/vlog.h

index d982db2..bbc00ad 100644 (file)
@@ -234,16 +234,18 @@ void vlog_rate_limit(const struct vlog_module *, enum vlog_level,
 void vlog_usage(void);
 
 /* Implementation details. */
-#define VLOG(LEVEL, ...)                            \
-    do {                                            \
-        if (THIS_MODULE->min_level >= LEVEL) {      \
-            vlog(THIS_MODULE, LEVEL, __VA_ARGS__);  \
-        }                                           \
+#define VLOG(LEVEL, ...)                                \
+    do {                                                \
+        enum vlog_level level__ = LEVEL;                \
+        if (THIS_MODULE->min_level >= level__) {        \
+            vlog(THIS_MODULE, level__, __VA_ARGS__);    \
+        }                                               \
     } while (0)
 #define VLOG_RL(RL, LEVEL, ...)                                     \
     do {                                                            \
-        if (THIS_MODULE->min_level >= LEVEL) {                      \
-            vlog_rate_limit(THIS_MODULE, LEVEL, RL, __VA_ARGS__);   \
+        enum vlog_level level__ = LEVEL;                            \
+        if (THIS_MODULE->min_level >= level__) {                    \
+            vlog_rate_limit(THIS_MODULE, level__, RL, __VA_ARGS__); \
         }                                                           \
     } while (0)
 #define VLOG_ONCE(LEVEL, ...)                       \