diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2021-08-29 18:53:55 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2021-08-29 18:53:55 +0300 |
commit | 0e1761697d8ed24b07cf23035f5dd01d09056e3a (patch) | |
tree | 0bfa58691f81e87f3098d736bc0409c4dd5fc40c /support | |
parent | 6696453c1a733436cbb9ca41c7c75eeb4e0b428a (diff) | |
download | egawk-0e1761697d8ed24b07cf23035f5dd01d09056e3a.tar.gz egawk-0e1761697d8ed24b07cf23035f5dd01d09056e3a.tar.bz2 egawk-0e1761697d8ed24b07cf23035f5dd01d09056e3a.zip |
Sync support with GNULIB updates.
Diffstat (limited to 'support')
-rw-r--r-- | support/ChangeLog | 7 | ||||
-rw-r--r-- | support/cdefs.h | 33 | ||||
-rw-r--r-- | support/dfa.c | 46 | ||||
-rw-r--r-- | support/dfa.h | 26 | ||||
-rw-r--r-- | support/libc-config.h | 3 | ||||
-rw-r--r-- | support/malloc/dynarray_at_failure.c | 3 | ||||
-rw-r--r-- | support/regex.c | 1 | ||||
-rw-r--r-- | support/regex.h | 50 | ||||
-rw-r--r-- | support/regex_internal.c | 9 | ||||
-rw-r--r-- | support/regexec.c | 4 | ||||
-rw-r--r-- | support/verify.h | 4 | ||||
-rw-r--r-- | support/xalloc.h | 11 |
12 files changed, 157 insertions, 40 deletions
diff --git a/support/ChangeLog b/support/ChangeLog index 81b564aa..e57a25af 100644 --- a/support/ChangeLog +++ b/support/ChangeLog @@ -1,3 +1,10 @@ +2021-08-29 Arnold D. Robbins <arnold@skeeve.com> + + * cdefs.h, dfa.c, dfa.h, libc-config.h, malloc/dynarray_at_failure.c, + regex.c, regex.h, regex_internal.c, regexec.c, verify.h: + Sync with GNULIB, yet again lots of churn. + * xalloc.h (ximemdup0): Yet another stupid new function. + 2021-08-15 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (AR): Set from @AR@ so that it can be set diff --git a/support/cdefs.h b/support/cdefs.h index b883b256..4dac9d26 100644 --- a/support/cdefs.h +++ b/support/cdefs.h @@ -261,10 +261,6 @@ #if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__) # define __attribute_maybe_unused__ __attribute__ ((__unused__)) -/* Once the next version of the C standard comes out, we can - do something like the following here: - #elif defined __STDC_VERSION__ && 202???L <= __STDC_VERSION__ - # define __attribute_maybe_unused__ [[__maybe_unused__]] */ #else # define __attribute_maybe_unused__ /* Ignore */ #endif @@ -336,6 +332,16 @@ # define __nonnull(params) __attribute_nonnull__ (params) #endif +/* The returns_nonnull function attribute marks the return type of the function + as always being non-null. */ +#ifndef __returns_nonnull +# if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__) +# define __returns_nonnull __attribute__ ((__returns_nonnull__)) +# else +# define __returns_nonnull +# endif +#endif + /* If fortification mode, we warn about unused results of certain function calls which can lead to problems. */ #if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__) @@ -598,9 +604,26 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf array according to access mode, or at least one element when size-index is not provided: access (access-mode, <ref-index> [, <size-index>]) */ -#define __attr_access(x) __attribute__ ((__access__ x)) +# define __attr_access(x) __attribute__ ((__access__ x)) +# if __GNUC_PREREQ (11, 0) +# define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno))) +# else +# define __attr_access_none(argno) +# endif #else # define __attr_access(x) +# define __attr_access_none(argno) +#endif + +#if __GNUC_PREREQ (11, 0) +/* Designates dealloc as a function to call to deallocate objects + allocated by the declared function. */ +# define __attr_dealloc(dealloc, argno) \ + __attribute__ ((__malloc__ (dealloc, argno))) +# define __attr_dealloc_free __attr_dealloc (__builtin_free, 1) +#else +# define __attr_dealloc(dealloc, argno) +# define __attr_dealloc_free #endif /* Specify that a function such as setjmp or vfork may return diff --git a/support/dfa.c b/support/dfa.c index 7e05a78d..459f10f7 100644 --- a/support/dfa.c +++ b/support/dfa.c @@ -26,6 +26,7 @@ #include "flexmember.h" #include "idx.h" +#include "verify.h" #include <assert.h> #include <ctype.h> @@ -35,6 +36,13 @@ #include <limits.h> #include <string.h> +/* Pacify gcc -Wanalyzer-null-dereference in areas where GCC + understandably cannot deduce that the input comes from a + well-formed regular expression. There's little point to the + runtime overhead of 'assert' instead of 'assume_nonnull' when the + MMU will check anyway. */ +#define assume_nonnull(x) assume ((x) != NULL) + static bool streq (char const *a, char const *b) { @@ -582,7 +590,7 @@ struct dfa /* dfaexec implementation. */ char *(*dfaexec) (struct dfa *, char const *, char *, - bool, ptrdiff_t *, bool *); + bool, idx_t *, bool *); /* Other cached information derived from the locale. */ struct localeinfo localeinfo; @@ -3344,7 +3352,7 @@ skip_remains_mb (struct dfa *d, unsigned char const *p, static inline char * dfaexec_main (struct dfa *d, char const *begin, char *end, bool allow_nl, - ptrdiff_t *count, bool multibyte) + idx_t *count, bool multibyte) { if (MAX_TRCOUNT <= d->sindex) { @@ -3527,14 +3535,14 @@ dfaexec_main (struct dfa *d, char const *begin, char *end, bool allow_nl, static char * dfaexec_mb (struct dfa *d, char const *begin, char *end, - bool allow_nl, ptrdiff_t *count, bool *backref) + bool allow_nl, idx_t *count, bool *backref) { return dfaexec_main (d, begin, end, allow_nl, count, true); } static char * dfaexec_sb (struct dfa *d, char const *begin, char *end, - bool allow_nl, ptrdiff_t *count, bool *backref) + bool allow_nl, idx_t *count, bool *backref) { return dfaexec_main (d, begin, end, allow_nl, count, false); } @@ -3543,7 +3551,7 @@ dfaexec_sb (struct dfa *d, char const *begin, char *end, any regexp that uses a construct not supported by this code. */ static char * dfaexec_noop (struct dfa *d, char const *begin, char *end, - bool allow_nl, ptrdiff_t *count, bool *backref) + bool allow_nl, idx_t *count, bool *backref) { *backref = true; return (char *) begin; @@ -3555,7 +3563,7 @@ dfaexec_noop (struct dfa *d, char const *begin, char *end, char * dfaexec (struct dfa *d, char const *begin, char *end, - bool allow_nl, ptrdiff_t *count, bool *backref) + bool allow_nl, idx_t *count, bool *backref) { return d->dfaexec (d, begin, end, allow_nl, count, backref); } @@ -3913,10 +3921,8 @@ freelist (char **cpp) } static char ** -enlist (char **cpp, char *new, idx_t len) +enlistnew (char **cpp, char *new) { - new = memcpy (ximalloc (len + 1), new, len); - new[len] = '\0'; /* Is there already something in the list that's new (or longer)? */ idx_t i; for (i = 0; cpp[i] != NULL; i++) @@ -3944,6 +3950,12 @@ enlist (char **cpp, char *new, idx_t len) return cpp; } +static char ** +enlist (char **cpp, char const *str, idx_t len) +{ + return enlistnew (cpp, ximemdup0 (str, len)); +} + /* Given pointers to two strings, return a pointer to an allocated list of their distinct common substrings. */ static char ** @@ -3974,7 +3986,7 @@ static char ** addlists (char **old, char **new) { for (; *new; new++) - old = enlist (old, *new, strlen (*new)); + old = enlistnew (old, xstrdup (*new)); return old; } @@ -4090,6 +4102,7 @@ dfamust (struct dfa const *d) case STAR: case QMARK: + assume_nonnull (mp); resetmust (mp); break; @@ -4097,7 +4110,9 @@ dfamust (struct dfa const *d) { char **new; must *rmp = mp; + assume_nonnull (rmp); must *lmp = mp = mp->prev; + assume_nonnull (lmp); idx_t j, ln, rn, n; /* Guaranteed to be. Unlikely, but ... */ @@ -4138,10 +4153,12 @@ dfamust (struct dfa const *d) break; case PLUS: + assume_nonnull (mp); mp->is[0] = '\0'; break; case END: + assume_nonnull (mp); assert (!mp->prev); for (idx_t i = 0; mp->in[i] != NULL; i++) if (strlen (mp->in[i]) > strlen (result)) @@ -4159,7 +4176,9 @@ dfamust (struct dfa const *d) case CAT: { must *rmp = mp; + assume_nonnull (rmp); must *lmp = mp = mp->prev; + assume_nonnull (lmp); /* In. Everything in left, plus everything in right, plus concatenation of @@ -4169,11 +4188,10 @@ dfamust (struct dfa const *d) { idx_t lrlen = strlen (lmp->right); idx_t rllen = strlen (rmp->left); - char *tp = ximalloc (lrlen + rllen); + char *tp = ximalloc (lrlen + rllen + 1); + memcpy (tp + lrlen, rmp->left, rllen + 1); memcpy (tp, lmp->right, lrlen); - memcpy (tp + lrlen, rmp->left, rllen); - lmp->in = enlist (lmp->in, tp, lrlen + rllen); - free (tp); + lmp->in = enlistnew (lmp->in, tp); } /* Left-hand */ if (lmp->is[0] != '\0') diff --git a/support/dfa.h b/support/dfa.h index 19a4127b..315a20d9 100644 --- a/support/dfa.h +++ b/support/dfa.h @@ -21,9 +21,11 @@ #ifndef DFA_H_ #define DFA_H_ +#include "idx.h" #include <regex.h> #include <stdbool.h> #include <stddef.h> +#include <stdlib.h> #ifdef __cplusplus extern "C" { @@ -46,7 +48,10 @@ struct dfa; /* Needed when Gnulib is not used. */ #ifndef _GL_ATTRIBUTE_MALLOC -# define _GL_ATTRIBUTE_MALLOC +# define _GL_ATTRIBUTE_MALLOC +# define _GL_ATTRIBUTE_DEALLOC_FREE +# define _GL_ATTRIBUTE_DEALLOC(x,y) +# define _GL_ATTRIBUTE_RETURNS_NONNULL #endif /* Entry points. */ @@ -55,7 +60,9 @@ struct dfa; It should be initialized via dfasyntax or dfacopysyntax before other use. The returned pointer should be passed directly to free() after calling dfafree() on it. */ -extern struct dfa *dfaalloc (void) _GL_ATTRIBUTE_MALLOC; +extern struct dfa *dfaalloc (void) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE + _GL_ATTRIBUTE_RETURNS_NONNULL; /* DFA options that can be ORed together, for dfasyntax's 4th arg. */ enum @@ -81,20 +88,23 @@ extern void dfasyntax (struct dfa *, struct localeinfo const *, extern void dfacopysyntax (struct dfa *, struct dfa const *); /* Parse the given string of given length into the given struct dfa. */ -extern void dfaparse (char const *, ptrdiff_t, struct dfa *); +extern void dfaparse (char const *, idx_t, struct dfa *); -/* Allocate and return a struct dfamust from a struct dfa that was - initialized by dfaparse and not yet given to dfacomp. */ -extern struct dfamust *dfamust (struct dfa const *); +struct dfamust; /* Free the storage held by the components of a struct dfamust. */ extern void dfamustfree (struct dfamust *); +/* Allocate and return a struct dfamust from a struct dfa that was + initialized by dfaparse and not yet given to dfacomp. */ +extern struct dfamust *dfamust (struct dfa const *) + _GL_ATTRIBUTE_DEALLOC (dfamustfree, 1); + /* Compile the given string of the given length into the given struct dfa. The last argument says whether to build a searching or an exact matcher. A null first argument means the struct dfa has already been initialized by dfaparse; the second argument is ignored. */ -extern void dfacomp (char const *, ptrdiff_t, struct dfa *, bool); +extern void dfacomp (char const *, idx_t, struct dfa *, bool); /* Search through a buffer looking for a match to the given struct dfa. Find the first occurrence of a string matching the regexp in the @@ -109,7 +119,7 @@ extern void dfacomp (char const *, ptrdiff_t, struct dfa *, bool); encountered a back-reference. The caller can use this to decide whether to fall back on a backtracking matcher. */ extern char *dfaexec (struct dfa *d, char const *begin, char *end, - bool allow_nl, ptrdiff_t *count, bool *backref); + bool allow_nl, idx_t *count, bool *backref); /* Return a superset for D. The superset matches everything that D matches, along with some other strings (though the latter should be diff --git a/support/libc-config.h b/support/libc-config.h index f68749fc..886c11f3 100644 --- a/support/libc-config.h +++ b/support/libc-config.h @@ -117,6 +117,9 @@ # undef __THROW # undef __THROWNL # undef __attr_access +# undef __attr_access_none +# undef __attr_dealloc +# undef __attr_dealloc_free # undef __attribute__ # undef __attribute_alloc_size__ # undef __attribute_artificial__ diff --git a/support/malloc/dynarray_at_failure.c b/support/malloc/dynarray_at_failure.c index 4f840db7..8dd68507 100644 --- a/support/malloc/dynarray_at_failure.c +++ b/support/malloc/dynarray_at_failure.c @@ -18,11 +18,11 @@ #ifndef _LIBC # include <libc-config.h> +# include <stdlib.h> #endif #include <dynarray.h> #include <stdio.h> -#include <stdlib.h> void __libc_dynarray_at_failure (size_t size, size_t index) @@ -32,6 +32,7 @@ __libc_dynarray_at_failure (size_t size, size_t index) __snprintf (buf, sizeof (buf), "Fatal glibc error: " "array index %zu not less than array length %zu\n", index, size); + __libc_fatal (buf); #else abort (); #endif diff --git a/support/regex.c b/support/regex.c index 7296be0f..d3286397 100644 --- a/support/regex.c +++ b/support/regex.c @@ -24,6 +24,7 @@ # if __GNUC_PREREQ (4, 6) # pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" +# pragma GCC diagnostic ignored "-Wvla" # endif # if __GNUC_PREREQ (4, 3) # pragma GCC diagnostic ignored "-Wold-style-definition" diff --git a/support/regex.h b/support/regex.h index 8e4ef455..adb69768 100644 --- a/support/regex.h +++ b/support/regex.h @@ -522,6 +522,30 @@ typedef struct /* Declarations for routines. */ +#ifndef _REGEX_NELTS +# if (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \ + && !defined __STDC_NO_VLA__) +# define _REGEX_NELTS(n) n +# else +# define _REGEX_NELTS(n) +# endif +#endif + +#if defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wvla" +#endif + +#ifndef _Attr_access_ +# ifdef __attr_access +# define _Attr_access_(arg) __attr_access (arg) +# elif defined __GNUC__ && 10 <= __GNUC__ +# define _Attr_access_(x) __attribute__ ((__access__ x)) +# else +# define _Attr_access_(x) +# endif +#endif + #ifdef __USE_GNU /* Sets the current default syntax to SYNTAX, and return the old syntax. You can also simply assign to the 're_syntax_options' variable. */ @@ -536,7 +560,8 @@ extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); 'regcomp', with a malloc'ed value, or set to NULL before calling 'regfree'. */ extern const char *re_compile_pattern (const char *__pattern, size_t __length, - struct re_pattern_buffer *__buffer); + struct re_pattern_buffer *__buffer) + _Attr_access_ ((__read_only__, 1, 2)); /* Compile a fastmap for the compiled pattern in BUFFER; used to @@ -553,7 +578,8 @@ extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); extern regoff_t re_search (struct re_pattern_buffer *__buffer, const char *__String, regoff_t __length, regoff_t __start, regoff_t __range, - struct re_registers *__regs); + struct re_registers *__regs) + _Attr_access_ ((__read_only__, 2, 3)); /* Like 're_search', but search in the concatenation of STRING1 and @@ -563,14 +589,17 @@ extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer, const char *__string2, regoff_t __length2, regoff_t __start, regoff_t __range, struct re_registers *__regs, - regoff_t __stop); + regoff_t __stop) + _Attr_access_ ((__read_only__, 2, 3)) + _Attr_access_ ((__read_only__, 4, 5)); /* Like 're_search', but return how many characters in STRING the regexp in BUFFER matched, starting at position START. */ extern regoff_t re_match (struct re_pattern_buffer *__buffer, const char *__String, regoff_t __length, - regoff_t __start, struct re_registers *__regs); + regoff_t __start, struct re_registers *__regs) + _Attr_access_ ((__read_only__, 2, 3)); /* Relates to 're_match' as 're_search_2' relates to 're_search'. */ @@ -578,7 +607,9 @@ extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer, const char *__string1, regoff_t __length1, const char *__string2, regoff_t __length2, regoff_t __start, struct re_registers *__regs, - regoff_t __stop); + regoff_t __stop) + _Attr_access_ ((__read_only__, 2, 3)) + _Attr_access_ ((__read_only__, 4, 5)); /* Set REGS to hold NUM_REGS registers, storing them in STARTS and @@ -647,14 +678,19 @@ extern int regcomp (regex_t *_Restrict_ __preg, extern int regexec (const regex_t *_Restrict_ __preg, const char *_Restrict_ __String, size_t __nmatch, - regmatch_t __pmatch[_Restrict_arr_], + regmatch_t __pmatch[_Restrict_arr_ + _REGEX_NELTS (__nmatch)], int __eflags); extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg, - char *_Restrict_ __errbuf, size_t __errbuf_size); + char *_Restrict_ __errbuf, size_t __errbuf_size) + _Attr_access_ ((__write_only__, 3, 4)); extern void regfree (regex_t *__preg); +#if defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__) +# pragma GCC diagnostic pop +#endif #ifdef __cplusplus } diff --git a/support/regex_internal.c b/support/regex_internal.c index 55f6b66d..aefcfa2f 100644 --- a/support/regex_internal.c +++ b/support/regex_internal.c @@ -1211,6 +1211,10 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src) if (__glibc_unlikely (dest->nelem == 0)) { + /* Although we already guaranteed above that dest->alloc != 0 and + therefore dest->elems != NULL, add a debug assertion to pacify + GCC 11.2.1's -fanalyzer. */ + DEBUG_ASSERT (dest->elems); dest->nelem = src->nelem; memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx)); return REG_NOERROR; @@ -1286,7 +1290,10 @@ re_node_set_insert (re_node_set *set, Idx elem) if (__glibc_unlikely (set->nelem) == 0) { - /* We already guaranteed above that set->alloc != 0. */ + /* Although we already guaranteed above that set->alloc != 0 and + therefore set->elems != NULL, add a debug assertion to pacify + GCC 11.2 -fanalyzer. */ + DEBUG_ASSERT (set->elems); set->elems[0] = elem; ++set->nelem; return true; diff --git a/support/regexec.c b/support/regexec.c index 5e4eb497..83e9aaf8 100644 --- a/support/regexec.c +++ b/support/regexec.c @@ -191,7 +191,7 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len); int regexec (const regex_t *__restrict preg, const char *__restrict string, - size_t nmatch, regmatch_t pmatch[], int eflags) + size_t nmatch, regmatch_t pmatch[_REGEX_NELTS (nmatch)], int eflags) { reg_errcode_t err; Idx start, length; @@ -235,7 +235,7 @@ int attribute_compat_text_section __compat_regexec (const regex_t *__restrict preg, const char *__restrict string, size_t nmatch, - regmatch_t pmatch[], int eflags) + regmatch_t pmatch[_REGEX_NELTS (nmatch)], int eflags) { return regexec (preg, string, nmatch, pmatch, eflags & (REG_NOTBOL | REG_NOTEOL)); diff --git a/support/verify.h b/support/verify.h index 3485a7e6..a8ca59b0 100644 --- a/support/verify.h +++ b/support/verify.h @@ -25,7 +25,7 @@ works as per C11. This is supported by GCC 4.6.0+ and by clang 4+. Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as - per C2X. This is supported by GCC 9.1+. + per C2x. This is supported by GCC 9.1+. Support compilers claiming conformance to the relevant standard, and also support GCC when not pedantic. If we were willing to slow @@ -202,7 +202,7 @@ template <int w> This macro requires three or more arguments but uses at most the first two, so that the _Static_assert macro optionally defined below supports - both the C11 two-argument syntax and the C2X one-argument syntax. + both the C11 two-argument syntax and the C2x one-argument syntax. Unfortunately, unlike C11, this implementation must appear as an ordinary declaration, and cannot appear inside struct { ... }. */ diff --git a/support/xalloc.h b/support/xalloc.h index bb893294..38a14873 100644 --- a/support/xalloc.h +++ b/support/xalloc.h @@ -436,5 +436,16 @@ xpalloc (void *pa, idx_t *nitems, idx_t nitems_incr_min, return pa; } +/* Clone an object P of size S, with error checking. Append + a terminating NUL byte. */ + +char * +ximemdup0 (void const *p, idx_t s) +{ + char *result = malloc(s + 1); + result[s] = 0; + return memcpy (result, p, s); +} + #endif /* !XALLOC_H_ */ |