changeset 13318:a69ddb2f39de

Further improvements to verify.h, suggested by Eric Blake. * lib/verify.h (_GL_CONCAT, _GL_CONCAT0, _GL_GENSYM): Renamed from the GL_* versions, to avoid collision with OpenGL. (_GL_COUNTER): New macro, so that we can fall back on __LINE__ if __COUNTER__ doesn't work. Test that __COUNTER__ increments rather than testing merely whether it's defined.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 05 May 2010 13:57:26 -0700
parents f4cec457476e
children 71829b55c10f
files ChangeLog lib/verify.h
diffstat 2 files changed, 22 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2010-05-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+	Further improvements to verify.h, suggested by Eric Blake.
+	* lib/verify.h (_GL_CONCAT, _GL_CONCAT0, _GL_GENSYM): Renamed from
+	the GL_* versions, to avoid collision with OpenGL.
+	(_GL_COUNTER): New macro, so that we can fall back on __LINE__ if
+	__COUNTER__ doesn't work.  Test that __COUNTER__ increments rather
+	than testing merely whether it's defined.
+
 	Modify verify.h to pacify gcc -Wredundant_decls.
 	* lib/verify.h (GL_CONCAT, GL_CONCAT0, GL_GENSYM): New macros.
 	These use the prefix "GL_" since they're likely to be useful elsewhere.
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -69,9 +69,9 @@
      if the entity names are not disambiguated.  A workaround is to
      attach the current line number to the entity name:
 
-       #define GL_CONCAT0(x, y) x##y
-       #define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
-       extern struct {...} * GL_CONCAT(dummy,__LINE__);
+       #define _GL_CONCAT0(x, y) x##y
+       #define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
+       extern struct {...} * _GL_CONCAT(dummy,__LINE__);
 
      But this has the problem that two invocations of verify from
      within the same macro would collide, since the __LINE__ value
@@ -123,19 +123,22 @@
      Use a template type to work around the problem.  */
 
 /* Concatenate two preprocessor tokens.  */
-# define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
-# define GL_CONCAT0(x, y) x##y
+# define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
+# define _GL_CONCAT0(x, y) x##y
 
-/* __COUNTER__ evaluates to 0, 1, 2,..., adding one one each time the
-   preprocessor uses it.  If the preprocessor doesn't support this
-   builtin macro, define it to 0.  */
-# ifndef __COUNTER__
-#  define __COUNTER__ 0
+/* _GL_COUNTER is an integer, preferably one that changes each time we
+   use it.  Use __COUNTER__ if it works, falling back on __LINE__
+   otherwise.  __LINE__ isn't perfect, but it's better than a
+   constant.  */
+# if defined __COUNTER__ && __COUNTER__ != __COUNTER__
+#  define _GL_COUNTER __COUNTER__
+# else
+#  define _GL_COUNTER __LINE__
 # endif
 
 /* Generate a symbol with the given prefix, making it unique if
    possible.  */
-# define GL_GENSYM(prefix) GL_CONCAT(prefix, __COUNTER__)
+# define _GL_GENSYM(prefix) _GL_CONCAT(prefix, _GL_COUNTER)
 
 /* Verify requirement R at compile-time, as an integer constant expression.
    Return 1.  */
@@ -155,6 +158,6 @@
    trailing ';'.  */
 
 # define verify(R) \
-    extern int (* GL_GENSYM(verify_function) (void)) [verify_true (R)]
+    extern int (* _GL_GENSYM(verify_function) (void)) [verify_true (R)]
 
 #endif