From: Paul Eggert Date: Thu, 10 Oct 2019 00:33:58 +0000 (-0700) Subject: regex: simplify by assuming C99 X-Git-Tag: v1.0~4635 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=48f07576b8cd935b48e1050551f45ab1a79b9f01;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 8251b83969..4f96c8cbff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2019-10-09 Paul Eggert + 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 bceaee8631..c53fb90a85 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 5462419b78..9c0e1f1d17 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 4ff30a79c0..f7d2b5b20d 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