bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] c-ctype, regex, verify: port to gcc -std=c90 -pedantic


From: Paul Eggert
Subject: [PATCH] c-ctype, regex, verify: port to gcc -std=c90 -pedantic
Date: Wed, 29 May 2013 18:52:20 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6

Avoid constructions that are rejected by gcc -std=c90 -pedantic.
This fixes a porting bug I recently reintroduced in regex, and
some other instances that I discovered while testing the fix.
* lib/c-ctype.h [__STRICT_ANSI__]: Avoid ({ ... }).
* lib/regcomp.c (utf8_sb_map) [__STRICT_ANSI__]: Avoid [0 ... N] = E.
* lib/regex_internal.h [!_LIBC && GNULIB_LOCK]: Do not use a macro
with an empty argument if this is a pedantic pre-C99 GCC.
* lib/verify.h: Do not use _Static_assert if this is a pedantic
pre-C11 GCC.
---
 ChangeLog            | 11 +++++++++++
 lib/c-ctype.h        |  3 ++-
 lib/regcomp.c        |  2 +-
 lib/regex_internal.h | 17 ++++++++++++++++-
 lib/verify.h         |  4 +++-
 5 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8097562..6cfb46b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2013-05-29  Paul Eggert  <address@hidden>
 
+       c-ctype, regex, verify: port to gcc -std=c90 -pedantic
+       Avoid constructions that are rejected by gcc -std=c90 -pedantic.
+       This fixes a porting bug I recently reintroduced in regex, and
+       some other instances that I discovered while testing the fix.
+       * lib/c-ctype.h [__STRICT_ANSI__]: Avoid ({ ... }).
+       * lib/regcomp.c (utf8_sb_map) [__STRICT_ANSI__]: Avoid [0 ... N] = E.
+       * lib/regex_internal.h [!_LIBC && GNULIB_LOCK]: Do not use a macro
+       with an empty argument if this is a pedantic pre-C99 GCC.
+       * lib/verify.h: Do not use _Static_assert if this is a pedantic
+       pre-C11 GCC.
+
        regex: adapt to locking regime instead of depending on pthread
        Instead of depending on pthread, adapt to whatever thread
        modules are in use.  Problem reported by Ludovic Court├Ęs in
diff --git a/lib/c-ctype.h b/lib/c-ctype.h
index 36144b8..5347d34 100644
--- a/lib/c-ctype.h
+++ b/lib/c-ctype.h
@@ -136,7 +136,8 @@ extern int c_tolower (int c) _GL_ATTRIBUTE_CONST;
 extern int c_toupper (int c) _GL_ATTRIBUTE_CONST;
 
 
-#if defined __GNUC__ && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ && 
!defined NO_C_CTYPE_MACROS
+#if (defined __GNUC__ && !defined __STRICT_ANSI__ && defined __OPTIMIZE__ \
+     && !defined __OPTIMIZE_SIZE__ && !defined NO_C_CTYPE_MACROS)
 
 /* ASCII optimizations. */
 
diff --git a/lib/regcomp.c b/lib/regcomp.c
index 5344381..4de2ed2 100644
--- a/lib/regcomp.c
+++ b/lib/regcomp.c
@@ -586,7 +586,7 @@ weak_alias (__regerror, regerror)
 static const bitset_t utf8_sb_map =
 {
   /* Set the first 128 bits.  */
-# ifdef __GNUC__
+# if defined __GNUC__ && !defined __STRICT_ANSI__
   [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX
 # else
 #  if 4 * BITSET_WORD_BITS < ASCII_CHARS
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 0f917e6..c92fb1a 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -42,7 +42,22 @@
 # define lock_unlock(lock) __libc_lock_unlock (lock)
 #elif defined GNULIB_LOCK
 # include "glthread/lock.h"
-# define lock_define(name) gl_lock_define (, name)
+  /* Use gl_lock_define if empty macro arguments are known to work.
+     Otherwise, fall back on less-portable substitutes.  */
+# if ((defined __GNUC__ && !defined __STRICT_ANSI__) \
+      || (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__))
+#  define lock_define(name) gl_lock_define (, name)
+# elif USE_POSIX_THREADS
+#  define lock_define(name) pthread_mutex_t name;
+# elif USE_PTH_THREADS
+#  define lock_define(name) pth_mutex_t name;
+# elif USE_SOLARIS_THREADS
+#  define lock_define(name) mutex_t name;
+# elif USE_WINDOWS_THREADS
+#  define lock_define(name) gl_lock_t name;
+# else
+#  define lock_define(name)
+# endif
 # define lock_init(lock) glthread_lock_init (&(lock))
 # define lock_fini(lock) glthread_lock_destroy (&(lock))
 # define lock_lock(lock) glthread_lock_lock (&(lock))
diff --git a/lib/verify.h b/lib/verify.h
index cb8e90b..03492ef 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -31,7 +31,9 @@
    Use this only with GCC.  If we were willing to slow 'configure'
    down we could also use it with other compilers, but since this
    affects only the quality of diagnostics, why bother?  */
-# if (4 < __GNUC__ || (__GNUC__ == 4 && 6 <= __GNUC_MINOR__)) && !defined 
__cplusplus
+# if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \
+      && (201112L <= __STDC_VERSION__  || !defined __STRICT_ANSI__) \
+      && !defined __cplusplus)
 #  define _GL_HAVE__STATIC_ASSERT 1
 # endif
 /* The condition (99 < __GNUC__) is temporary, until we know about the
-- 
1.7.11.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]