]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Make DEBUG_ONLY work with toplevel commas (Change part 3)
authorOliver Kurth <okurth@vmware.com>
Sun, 21 Jul 2019 00:15:19 +0000 (17:15 -0700)
committerOliver Kurth <okurth@vmware.com>
Sun, 21 Jul 2019 00:15:19 +0000 (17:15 -0700)
Now that all the C pre-processors in use support variadic macros, make
DEBUG_ONLY work with toplevel commas (i.e. commas which are outside of
any parentheses pair). This is useful in at least 2 ways:

In C code, to easily pass debug arguments to functions in debug builds
without any overhead in non-debug builds.

  void
  foo(DEBUG_ONLY(int debugArg,) // IN
  int nonDebugArg)          // IN
  {
  ASSERT(DebugFunc(debugArg));
  NonDebugFunc(nonDebugArg);
  }

  foo(DEBUG_ONLY(debugArg,) nonDebugArg);

In asm code.

  DEBUG_ONLY(mov x0, #0)

open-vm-tools/lib/include/vm_basic_defs.h

index e75fb2550f883e4161050f91c608f5aa449bdc1b..aa9396fe45dead330afe134e60d6e0db8215b252 100644 (file)
@@ -593,10 +593,10 @@ typedef int pid_t;
 #undef DEBUG_ONLY
 #ifdef VMX86_DEBUG
 #define vmx86_debug      1
-#define DEBUG_ONLY(x)    x
+#define DEBUG_ONLY(...)  __VA_ARGS__
 #else
 #define vmx86_debug      0
-#define DEBUG_ONLY(x)
+#define DEBUG_ONLY(...)
 #endif
 
 #ifdef VMX86_STATS