bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH 2/4] regex: simplify by assuming C99


From: Paul Eggert
Subject: [PATCH 2/4] regex: simplify by assuming C99
Date: Wed, 9 Oct 2019 18:34:25 -0700

* config/srclist.txt: Comment out regex_internal.h and regexec.c
temporarily.
* lib/regex_internal.h (lock_define, re_match_context_t):
Simplify by assuming C99 macros and const.
* lib/regexec.c (re_search_internal): Simplify by assuming C99
initializers.  Remove unnecessary assignment, as mctx is now
safely initialized earlier.
---
 ChangeLog            |  9 +++++++++
 config/srclist.txt   |  4 ++--
 lib/regex_internal.h | 21 +--------------------
 lib/regexec.c        | 11 -----------
 4 files changed, 12 insertions(+), 33 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8251b8396..4f96c8cbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2019-10-09  Paul Eggert  <address@hidden>
 
+       regex: simplify by assuming C99
+       * config/srclist.txt: Comment out regex_internal.h and regexec.c
+       temporarily.
+       * lib/regex_internal.h (lock_define, re_match_context_t):
+       Simplify by assuming C99 macros and const.
+       * lib/regexec.c (re_search_internal): Simplify by assuming C99
+       initializers.  Remove unnecessary assignment, as mctx is now
+       safely initialized earlier.
+
        regex: avoid copying of uninitialized storage
        * config/srclist.txt: Comment out regcomp.c temporarily.
        * lib/regcomp.c (build_charclass_op, create_tree) [! (GCC_LINT||lint)]:
diff --git a/config/srclist.txt b/config/srclist.txt
index bceaee863..c53fb90a8 100644
--- a/config/srclist.txt
+++ b/config/srclist.txt
@@ -56,8 +56,8 @@ $LIBCSRC malloc/scratch_buffer_set_array_size.c       
lib/malloc
 $LIBCSRC posix/regex.c                 lib
 $LIBCSRC posix/regex.h                 lib
 $LIBCSRC posix/regex_internal.c                lib
-$LIBCSRC posix/regex_internal.h                lib
-$LIBCSRC posix/regexec.c               lib
+#$LIBCSRC posix/regex_internal.h       lib
+#$LIBCSRC posix/regexec.c              lib
 $LIBCSRC time/timegm.c                 lib
 $LIBCSRC time/mktime.c                 lib
 $LIBCSRC time/mktime-internal.h                lib
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 5462419b7..9c0e1f1d1 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -44,22 +44,7 @@
 # define lock_unlock(lock) __libc_lock_unlock (lock)
 #elif defined GNULIB_LOCK && !defined USE_UNLOCKED_IO
 # include "glthread/lock.h"
-  /* 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_define(name) gl_lock_define (, name)
 # define lock_init(lock) glthread_lock_init (&(lock))
 # define lock_fini(lock) glthread_lock_destroy (&(lock))
 # define lock_lock(lock) glthread_lock_lock (&(lock))
@@ -618,11 +603,7 @@ typedef struct
 {
   /* The string object corresponding to the input string.  */
   re_string_t input;
-#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
   const re_dfa_t *const dfa;
-#else
-  const re_dfa_t *dfa;
-#endif
   /* EFLAGS of the argument of regexec.  */
   int eflags;
   /* Where the matching ends.  */
diff --git a/lib/regexec.c b/lib/regexec.c
index 4ff30a79c..f7d2b5b20 100644
--- a/lib/regexec.c
+++ b/lib/regexec.c
@@ -597,21 +597,12 @@ re_search_internal (const regex_t *preg, const char 
*string, Idx length,
   Idx extra_nmatch;
   bool sb;
   int ch;
-#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
   re_match_context_t mctx = { .dfa = dfa };
-#else
-  re_match_context_t mctx;
-#endif
   char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate
                    && start != last_start && !preg->can_be_null)
                   ? preg->fastmap : NULL);
   RE_TRANSLATE_TYPE t = preg->translate;
 
-#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 
199901L))
-  memset (&mctx, '\0', sizeof (re_match_context_t));
-  mctx.dfa = dfa;
-#endif
-
   extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0;
   nmatch -= extra_nmatch;
 
@@ -677,8 +668,6 @@ re_search_internal (const regex_t *preg, const char 
*string, Idx length,
          goto free_return;
        }
     }
-  else
-    mctx.state_log = NULL;
 
   match_first = start;
   mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
-- 
2.21.0




reply via email to

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