[Bf-blender-cvs] [da36efdf487] master: GHOST: expand GHOST_PRINT/PRINTF without WITH_GHOST_DEBUG

Campbell Barton noreply at git.blender.org
Sun Oct 23 08:41:29 CEST 2022


Commit: da36efdf487b35df20a6110348e919df203dec63
Author: Campbell Barton
Date:   Sun Oct 23 17:28:15 2022 +1100
Branches: master
https://developer.blender.org/rBda36efdf487b35df20a6110348e919df203dec63

GHOST: expand GHOST_PRINT/PRINTF without WITH_GHOST_DEBUG

It was too easy accidentally break builds without WITH_GHOST_DEBUG
enabled because the arguments were ignored. Now they are expanded in an
`if (0) {...}` block, so invalid expressions result in errors.

===================================================================

M	intern/ghost/intern/GHOST_Debug.h

===================================================================

diff --git a/intern/ghost/intern/GHOST_Debug.h b/intern/ghost/intern/GHOST_Debug.h
index ec1a0b34be6..64eff7f9aed 100644
--- a/intern/ghost/intern/GHOST_Debug.h
+++ b/intern/ghost/intern/GHOST_Debug.h
@@ -15,29 +15,41 @@
 #  endif
 #endif
 
-#if defined(WITH_GHOST_DEBUG) || (!defined(NDEBUG))
-#  include <iostream>
-#  include <stdio.h>  //for printf()
-#endif                // WITH_GHOST_DEBUG
+#include <iostream>
+#include <stdio.h> /* For `printf()`. */
 
 #if defined(WITH_GHOST_DEBUG)
 #  define GHOST_PRINT(x) \
     { \
       std::cout << x; \
     } \
-    (void)0
+    ((void)0)
 #  define GHOST_PRINTF(x, ...) \
     { \
       printf(x, __VA_ARGS__); \
     } \
-    (void)0
+    ((void)0)
 #else
-#  define GHOST_PRINT(x)
-#  define GHOST_PRINTF(x, ...)
+/* Expand even when `WITH_GHOST_DEBUG` is disabled to prevent expressions
+ * becoming invalid even when the option is disable. */
+#  define GHOST_PRINT(x) \
+    { \
+      if (false) { \
+        std::cout << x; \
+      } \
+    } \
+    ((void)0)
+#  define GHOST_PRINTF(x, ...) \
+    { \
+      if (false) { \
+        printf(x, __VA_ARGS__); \
+      } \
+    } \
+    ((void)0)
+
 #endif /* `!defined(WITH_GHOST_DEBUG)` */
 
 #ifdef WITH_ASSERT_ABORT
-#  include <stdio.h>   //for fprintf()
 #  include <stdlib.h>  //for abort()
 #  define GHOST_ASSERT(x, info) \
     { \
@@ -48,7 +60,7 @@
         abort(); \
       } \
     } \
-    (void)0
+    ((void)0)
 /* Assert in non-release builds too. */
 #elif defined(WITH_GHOST_DEBUG) || (!defined(NDEBUG))
 #  define GHOST_ASSERT(x, info) \
@@ -59,7 +71,7 @@
         GHOST_PRINT("\n"); \
       } \
     } \
-    (void)0
+    ((void)0)
 #else /* `defined(WITH_GHOST_DEBUG) || (!defined(NDEBUG))` */
 #  define GHOST_ASSERT(x, info) ((void)0)
 #endif /* `defined(WITH_GHOST_DEBUG) || (!defined(NDEBUG))` */



More information about the Bf-blender-cvs mailing list