diff options
author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2023-03-11 10:34:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-11 10:34:47 (GMT) |
commit | 75342b53853a898bdd93c7d3da9374115bab6b6d (patch) | |
tree | 0c0af2b796bcdd8ddd42187beb5badb420db8dea /gl/regex_internal.h | |
parent | 6bbe0b7b0f609ecab831dec9be7690842bf0a0fc (diff) | |
parent | 357787868b5201ec3e874e7a225b1c944cbbdb4d (diff) | |
download | monitoring-plugins-75342b53853a898bdd93c7d3da9374115bab6b6d.tar.gz |
Merge branch 'master' into patch-1refs/pull/1842/head
Diffstat (limited to 'gl/regex_internal.h')
-rw-r--r-- | gl/regex_internal.h | 299 |
1 files changed, 112 insertions, 187 deletions
diff --git a/gl/regex_internal.h b/gl/regex_internal.h index a2b8f16..149ec2e 100644 --- a/gl/regex_internal.h +++ b/gl/regex_internal.h | |||
@@ -1,26 +1,25 @@ | |||
1 | /* Extended regular expression matching and search library. | 1 | /* Extended regular expression matching and search library. |
2 | Copyright (C) 2002-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 2002-2023 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. | 4 | Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. |
5 | 5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | 6 | The GNU C Library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU General Public | 7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 3 of the License, or (at your option) any later version. | 9 | version 2.1 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | The GNU C Library is distributed in the hope that it will be useful, | 11 | The GNU C Library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | General Public License for more details. | 14 | Lesser General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public | 16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, see | 17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | 18 | <https://www.gnu.org/licenses/>. */ |
19 | 19 | ||
20 | #ifndef _REGEX_INTERNAL_H | 20 | #ifndef _REGEX_INTERNAL_H |
21 | #define _REGEX_INTERNAL_H 1 | 21 | #define _REGEX_INTERNAL_H 1 |
22 | 22 | ||
23 | #include <assert.h> | ||
24 | #include <ctype.h> | 23 | #include <ctype.h> |
25 | #include <stdio.h> | 24 | #include <stdio.h> |
26 | #include <stdlib.h> | 25 | #include <stdlib.h> |
@@ -30,39 +29,37 @@ | |||
30 | #include <locale.h> | 29 | #include <locale.h> |
31 | #include <wchar.h> | 30 | #include <wchar.h> |
32 | #include <wctype.h> | 31 | #include <wctype.h> |
33 | #include <stdbool.h> | ||
34 | #include <stdint.h> | 32 | #include <stdint.h> |
35 | 33 | ||
34 | #ifndef _LIBC | ||
35 | # include <dynarray.h> | ||
36 | #endif | ||
37 | |||
38 | #include <intprops.h> | ||
39 | #include <verify.h> | ||
40 | |||
41 | #if defined DEBUG && DEBUG != 0 | ||
42 | # include <assert.h> | ||
43 | # define DEBUG_ASSERT(x) assert (x) | ||
44 | #else | ||
45 | # define DEBUG_ASSERT(x) assume (x) | ||
46 | #endif | ||
47 | |||
36 | #ifdef _LIBC | 48 | #ifdef _LIBC |
37 | # include <bits/libc-lock.h> | 49 | # include <libc-lock.h> |
38 | # define lock_define(name) __libc_lock_define (, name) | 50 | # define lock_define(name) __libc_lock_define (, name) |
39 | # define lock_init(lock) (__libc_lock_init (lock), 0) | 51 | # define lock_init(lock) (__libc_lock_init (lock), 0) |
40 | # define lock_fini(lock) 0 | 52 | # define lock_fini(lock) ((void) 0) |
41 | # define lock_lock(lock) __libc_lock_lock (lock) | 53 | # define lock_lock(lock) __libc_lock_lock (lock) |
42 | # define lock_unlock(lock) __libc_lock_unlock (lock) | 54 | # define lock_unlock(lock) __libc_lock_unlock (lock) |
43 | #elif defined GNULIB_LOCK | 55 | #elif defined GNULIB_LOCK && !defined GNULIB_REGEX_SINGLE_THREAD |
44 | # include "glthread/lock.h" | 56 | # include "glthread/lock.h" |
45 | /* Use gl_lock_define if empty macro arguments are known to work. | 57 | # define lock_define(name) gl_lock_define (, name) |
46 | Otherwise, fall back on less-portable substitutes. */ | ||
47 | # if ((defined __GNUC__ && !defined __STRICT_ANSI__) \ | ||
48 | || (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__)) | ||
49 | # define lock_define(name) gl_lock_define (, name) | ||
50 | # elif USE_POSIX_THREADS | ||
51 | # define lock_define(name) pthread_mutex_t name; | ||
52 | # elif USE_PTH_THREADS | ||
53 | # define lock_define(name) pth_mutex_t name; | ||
54 | # elif USE_SOLARIS_THREADS | ||
55 | # define lock_define(name) mutex_t name; | ||
56 | # elif USE_WINDOWS_THREADS | ||
57 | # define lock_define(name) gl_lock_t name; | ||
58 | # else | ||
59 | # define lock_define(name) | ||
60 | # endif | ||
61 | # define lock_init(lock) glthread_lock_init (&(lock)) | 58 | # define lock_init(lock) glthread_lock_init (&(lock)) |
62 | # define lock_fini(lock) glthread_lock_destroy (&(lock)) | 59 | # define lock_fini(lock) glthread_lock_destroy (&(lock)) |
63 | # define lock_lock(lock) glthread_lock_lock (&(lock)) | 60 | # define lock_lock(lock) glthread_lock_lock (&(lock)) |
64 | # define lock_unlock(lock) glthread_lock_unlock (&(lock)) | 61 | # define lock_unlock(lock) glthread_lock_unlock (&(lock)) |
65 | #elif defined GNULIB_PTHREAD | 62 | #elif defined GNULIB_PTHREAD && !defined GNULIB_REGEX_SINGLE_THREAD |
66 | # include <pthread.h> | 63 | # include <pthread.h> |
67 | # define lock_define(name) pthread_mutex_t name; | 64 | # define lock_define(name) pthread_mutex_t name; |
68 | # define lock_init(lock) pthread_mutex_init (&(lock), 0) | 65 | # define lock_init(lock) pthread_mutex_init (&(lock), 0) |
@@ -83,11 +80,18 @@ | |||
83 | # define isblank(ch) ((ch) == ' ' || (ch) == '\t') | 80 | # define isblank(ch) ((ch) == ' ' || (ch) == '\t') |
84 | #endif | 81 | #endif |
85 | 82 | ||
83 | /* regex code assumes isascii has its usual numeric meaning, | ||
84 | even if the portable character set uses EBCDIC encoding, | ||
85 | and even if wint_t is wider than int. */ | ||
86 | #ifndef _LIBC | ||
87 | # undef isascii | ||
88 | # define isascii(c) (((c) & ~0x7f) == 0) | ||
89 | #endif | ||
90 | |||
86 | #ifdef _LIBC | 91 | #ifdef _LIBC |
87 | # ifndef _RE_DEFINE_LOCALE_FUNCTIONS | 92 | # ifndef _RE_DEFINE_LOCALE_FUNCTIONS |
88 | # define _RE_DEFINE_LOCALE_FUNCTIONS 1 | 93 | # define _RE_DEFINE_LOCALE_FUNCTIONS 1 |
89 | # include <locale/localeinfo.h> | 94 | # include <locale/localeinfo.h> |
90 | # include <locale/elem-hash.h> | ||
91 | # include <locale/coll-lookup.h> | 95 | # include <locale/coll-lookup.h> |
92 | # endif | 96 | # endif |
93 | #endif | 97 | #endif |
@@ -101,6 +105,7 @@ | |||
101 | __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES) | 105 | __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES) |
102 | # endif | 106 | # endif |
103 | #else | 107 | #else |
108 | # undef gettext | ||
104 | # define gettext(msgid) (msgid) | 109 | # define gettext(msgid) (msgid) |
105 | #endif | 110 | #endif |
106 | 111 | ||
@@ -110,16 +115,6 @@ | |||
110 | # define gettext_noop(String) String | 115 | # define gettext_noop(String) String |
111 | #endif | 116 | #endif |
112 | 117 | ||
113 | #if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE && HAVE_WCSCOLL) || _LIBC | ||
114 | # define RE_ENABLE_I18N | ||
115 | #endif | ||
116 | |||
117 | #if __GNUC__ >= 3 | ||
118 | # define BE(expr, val) __builtin_expect (expr, val) | ||
119 | #else | ||
120 | # define BE(expr, val) (expr) | ||
121 | #endif | ||
122 | |||
123 | /* Number of ASCII characters. */ | 118 | /* Number of ASCII characters. */ |
124 | #define ASCII_CHARS 0x80 | 119 | #define ASCII_CHARS 0x80 |
125 | 120 | ||
@@ -135,45 +130,60 @@ | |||
135 | /* Rename to standard API for using out of glibc. */ | 130 | /* Rename to standard API for using out of glibc. */ |
136 | #ifndef _LIBC | 131 | #ifndef _LIBC |
137 | # undef __wctype | 132 | # undef __wctype |
133 | # undef __iswalnum | ||
138 | # undef __iswctype | 134 | # undef __iswctype |
135 | # undef __towlower | ||
136 | # undef __towupper | ||
139 | # define __wctype wctype | 137 | # define __wctype wctype |
138 | # define __iswalnum iswalnum | ||
140 | # define __iswctype iswctype | 139 | # define __iswctype iswctype |
140 | # define __towlower towlower | ||
141 | # define __towupper towupper | ||
141 | # define __btowc btowc | 142 | # define __btowc btowc |
142 | # define __mbrtowc mbrtowc | 143 | # define __mbrtowc mbrtowc |
143 | # define __wcrtomb wcrtomb | 144 | # define __wcrtomb wcrtomb |
144 | # define __regfree regfree | 145 | # define __regfree regfree |
145 | # define attribute_hidden | ||
146 | #endif /* not _LIBC */ | 146 | #endif /* not _LIBC */ |
147 | 147 | ||
148 | #if __GNUC__ < 3 + (__GNUC_MINOR__ < 1) | 148 | /* Types related to integers. Unless protected by #ifdef _LIBC, the |
149 | # define __attribute__(arg) | 149 | regex code should avoid exact-width types like int32_t and uint64_t |
150 | #endif | 150 | as some non-GCC platforms lack them, an issue when this code is |
151 | used in Gnulib. */ | ||
151 | 152 | ||
152 | typedef __re_idx_t Idx; | 153 | #ifndef SSIZE_MAX |
153 | #ifdef _REGEX_LARGE_OFFSETS | 154 | # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) |
154 | # define IDX_MAX (SIZE_MAX - 2) | ||
155 | #else | ||
156 | # define IDX_MAX INT_MAX | ||
157 | #endif | 155 | #endif |
158 | 156 | #ifndef ULONG_WIDTH | |
159 | /* Special return value for failure to match. */ | 157 | # define ULONG_WIDTH REGEX_UINTEGER_WIDTH (ULONG_MAX) |
160 | #define REG_MISSING ((Idx) -1) | 158 | /* The number of usable bits in an unsigned integer type with maximum |
161 | 159 | value MAX, as an int expression suitable in #if. Cover all known | |
162 | /* Special return value for internal error. */ | 160 | practical hosts. This implementation exploits the fact that MAX is |
163 | #define REG_ERROR ((Idx) -2) | 161 | 1 less than a power of 2, and merely counts the number of 1 bits in |
164 | 162 | MAX; "COBn" means "count the number of 1 bits in the low-order n bits". */ | |
165 | /* Test whether N is a valid index, and is not one of the above. */ | 163 | # define REGEX_UINTEGER_WIDTH(max) REGEX_COB128 (max) |
166 | #ifdef _REGEX_LARGE_OFFSETS | 164 | # define REGEX_COB128(n) (REGEX_COB64 ((n) >> 31 >> 31 >> 2) + REGEX_COB64 (n)) |
167 | # define REG_VALID_INDEX(n) ((Idx) (n) < REG_ERROR) | 165 | # define REGEX_COB64(n) (REGEX_COB32 ((n) >> 31 >> 1) + REGEX_COB32 (n)) |
168 | #else | 166 | # define REGEX_COB32(n) (REGEX_COB16 ((n) >> 16) + REGEX_COB16 (n)) |
169 | # define REG_VALID_INDEX(n) (0 <= (n)) | 167 | # define REGEX_COB16(n) (REGEX_COB8 ((n) >> 8) + REGEX_COB8 (n)) |
168 | # define REGEX_COB8(n) (REGEX_COB4 ((n) >> 4) + REGEX_COB4 (n)) | ||
169 | # define REGEX_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + ((n) & 1)) | ||
170 | # if ULONG_MAX / 2 + 1 != 1ul << (ULONG_WIDTH - 1) | ||
171 | # error "ULONG_MAX out of range" | ||
172 | # endif | ||
170 | #endif | 173 | #endif |
171 | 174 | ||
172 | /* Test whether N is a valid nonzero index. */ | 175 | /* The type of indexes into strings. This is signed, not size_t, |
176 | since the API requires indexes to fit in regoff_t anyway, and using | ||
177 | signed integers makes the code a bit smaller and presumably faster. | ||
178 | The traditional GNU regex implementation uses int for indexes. | ||
179 | The POSIX-compatible implementation uses a possibly-wider type. | ||
180 | The name 'Idx' is three letters to minimize the hassle of | ||
181 | reindenting a lot of regex code that formerly used 'int'. */ | ||
182 | typedef regoff_t Idx; | ||
173 | #ifdef _REGEX_LARGE_OFFSETS | 183 | #ifdef _REGEX_LARGE_OFFSETS |
174 | # define REG_VALID_NONZERO_INDEX(n) ((Idx) ((n) - 1) < (Idx) (REG_ERROR - 1)) | 184 | # define IDX_MAX SSIZE_MAX |
175 | #else | 185 | #else |
176 | # define REG_VALID_NONZERO_INDEX(n) (0 < (n)) | 186 | # define IDX_MAX INT_MAX |
177 | #endif | 187 | #endif |
178 | 188 | ||
179 | /* A hash value, suitable for computing hash tables. */ | 189 | /* A hash value, suitable for computing hash tables. */ |
@@ -184,36 +194,8 @@ typedef __re_size_t re_hashval_t; | |||
184 | typedef unsigned long int bitset_word_t; | 194 | typedef unsigned long int bitset_word_t; |
185 | /* All bits set in a bitset_word_t. */ | 195 | /* All bits set in a bitset_word_t. */ |
186 | #define BITSET_WORD_MAX ULONG_MAX | 196 | #define BITSET_WORD_MAX ULONG_MAX |
187 | 197 | /* Number of bits in a bitset_word_t. */ | |
188 | /* Number of bits in a bitset_word_t. For portability to hosts with | 198 | #define BITSET_WORD_BITS ULONG_WIDTH |
189 | padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)'; | ||
190 | instead, deduce it directly from BITSET_WORD_MAX. Avoid | ||
191 | greater-than-32-bit integers and unconditional shifts by more than | ||
192 | 31 bits, as they're not portable. */ | ||
193 | #if BITSET_WORD_MAX == 0xffffffffUL | ||
194 | # define BITSET_WORD_BITS 32 | ||
195 | #elif BITSET_WORD_MAX >> 31 >> 4 == 1 | ||
196 | # define BITSET_WORD_BITS 36 | ||
197 | #elif BITSET_WORD_MAX >> 31 >> 16 == 1 | ||
198 | # define BITSET_WORD_BITS 48 | ||
199 | #elif BITSET_WORD_MAX >> 31 >> 28 == 1 | ||
200 | # define BITSET_WORD_BITS 60 | ||
201 | #elif BITSET_WORD_MAX >> 31 >> 31 >> 1 == 1 | ||
202 | # define BITSET_WORD_BITS 64 | ||
203 | #elif BITSET_WORD_MAX >> 31 >> 31 >> 9 == 1 | ||
204 | # define BITSET_WORD_BITS 72 | ||
205 | #elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 3 == 1 | ||
206 | # define BITSET_WORD_BITS 128 | ||
207 | #elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 == 1 | ||
208 | # define BITSET_WORD_BITS 256 | ||
209 | #elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 > 1 | ||
210 | # define BITSET_WORD_BITS 257 /* any value > SBC_MAX will do here */ | ||
211 | # if BITSET_WORD_BITS <= SBC_MAX | ||
212 | # error "Invalid SBC_MAX" | ||
213 | # endif | ||
214 | #else | ||
215 | # error "Add case for new bitset_word_t size" | ||
216 | #endif | ||
217 | 199 | ||
218 | /* Number of bitset_word_t values in a bitset_t. */ | 200 | /* Number of bitset_word_t values in a bitset_t. */ |
219 | #define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS) | 201 | #define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS) |
@@ -264,10 +246,8 @@ typedef enum | |||
264 | SIMPLE_BRACKET = 3, | 246 | SIMPLE_BRACKET = 3, |
265 | OP_BACK_REF = 4, | 247 | OP_BACK_REF = 4, |
266 | OP_PERIOD = 5, | 248 | OP_PERIOD = 5, |
267 | #ifdef RE_ENABLE_I18N | ||
268 | COMPLEX_BRACKET = 6, | 249 | COMPLEX_BRACKET = 6, |
269 | OP_UTF8_PERIOD = 7, | 250 | OP_UTF8_PERIOD = 7, |
270 | #endif /* RE_ENABLE_I18N */ | ||
271 | 251 | ||
272 | /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used | 252 | /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used |
273 | when the debugger shows values of this enum type. */ | 253 | when the debugger shows values of this enum type. */ |
@@ -305,30 +285,29 @@ typedef enum | |||
305 | 285 | ||
306 | } re_token_type_t; | 286 | } re_token_type_t; |
307 | 287 | ||
308 | #ifdef RE_ENABLE_I18N | ||
309 | typedef struct | 288 | typedef struct |
310 | { | 289 | { |
311 | /* Multibyte characters. */ | 290 | /* Multibyte characters. */ |
312 | wchar_t *mbchars; | 291 | wchar_t *mbchars; |
313 | 292 | ||
293 | #ifdef _LIBC | ||
314 | /* Collating symbols. */ | 294 | /* Collating symbols. */ |
315 | # ifdef _LIBC | ||
316 | int32_t *coll_syms; | 295 | int32_t *coll_syms; |
317 | # endif | 296 | #endif |
318 | 297 | ||
298 | #ifdef _LIBC | ||
319 | /* Equivalence classes. */ | 299 | /* Equivalence classes. */ |
320 | # ifdef _LIBC | ||
321 | int32_t *equiv_classes; | 300 | int32_t *equiv_classes; |
322 | # endif | 301 | #endif |
323 | 302 | ||
324 | /* Range expressions. */ | 303 | /* Range expressions. */ |
325 | # ifdef _LIBC | 304 | #ifdef _LIBC |
326 | uint32_t *range_starts; | 305 | uint32_t *range_starts; |
327 | uint32_t *range_ends; | 306 | uint32_t *range_ends; |
328 | # else /* not _LIBC */ | 307 | #else |
329 | wchar_t *range_starts; | 308 | wchar_t *range_starts; |
330 | wchar_t *range_ends; | 309 | wchar_t *range_ends; |
331 | # endif /* not _LIBC */ | 310 | #endif |
332 | 311 | ||
333 | /* Character classes. */ | 312 | /* Character classes. */ |
334 | wctype_t *char_classes; | 313 | wctype_t *char_classes; |
@@ -351,7 +330,6 @@ typedef struct | |||
351 | /* # of character classes. */ | 330 | /* # of character classes. */ |
352 | Idx nchar_classes; | 331 | Idx nchar_classes; |
353 | } re_charset_t; | 332 | } re_charset_t; |
354 | #endif /* RE_ENABLE_I18N */ | ||
355 | 333 | ||
356 | typedef struct | 334 | typedef struct |
357 | { | 335 | { |
@@ -359,13 +337,11 @@ typedef struct | |||
359 | { | 337 | { |
360 | unsigned char c; /* for CHARACTER */ | 338 | unsigned char c; /* for CHARACTER */ |
361 | re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */ | 339 | re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */ |
362 | #ifdef RE_ENABLE_I18N | ||
363 | re_charset_t *mbcset; /* for COMPLEX_BRACKET */ | 340 | re_charset_t *mbcset; /* for COMPLEX_BRACKET */ |
364 | #endif /* RE_ENABLE_I18N */ | ||
365 | Idx idx; /* for BACK_REF */ | 341 | Idx idx; /* for BACK_REF */ |
366 | re_context_type ctx_type; /* for ANCHOR */ | 342 | re_context_type ctx_type; /* for ANCHOR */ |
367 | } opr; | 343 | } opr; |
368 | #if __GNUC__ >= 2 && !defined __STRICT_ANSI__ | 344 | #if (__GNUC__ >= 2 || defined __clang__) && !defined __STRICT_ANSI__ |
369 | re_token_type_t type : 8; | 345 | re_token_type_t type : 8; |
370 | #else | 346 | #else |
371 | re_token_type_t type; | 347 | re_token_type_t type; |
@@ -373,12 +349,10 @@ typedef struct | |||
373 | unsigned int constraint : 10; /* context constraint */ | 349 | unsigned int constraint : 10; /* context constraint */ |
374 | unsigned int duplicated : 1; | 350 | unsigned int duplicated : 1; |
375 | unsigned int opt_subexp : 1; | 351 | unsigned int opt_subexp : 1; |
376 | #ifdef RE_ENABLE_I18N | ||
377 | unsigned int accept_mb : 1; | 352 | unsigned int accept_mb : 1; |
378 | /* These 2 bits can be moved into the union if needed (e.g. if running out | 353 | /* These 2 bits can be moved into the union if needed (e.g. if running out |
379 | of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */ | 354 | of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */ |
380 | unsigned int mb_partial : 1; | 355 | unsigned int mb_partial : 1; |
381 | #endif | ||
382 | unsigned int word_char : 1; | 356 | unsigned int word_char : 1; |
383 | } re_token_t; | 357 | } re_token_t; |
384 | 358 | ||
@@ -393,12 +367,10 @@ struct re_string_t | |||
393 | REG_ICASE, upper cases of the string are stored, otherwise MBS points | 367 | REG_ICASE, upper cases of the string are stored, otherwise MBS points |
394 | the same address that RAW_MBS points. */ | 368 | the same address that RAW_MBS points. */ |
395 | unsigned char *mbs; | 369 | unsigned char *mbs; |
396 | #ifdef RE_ENABLE_I18N | ||
397 | /* Store the wide character string which is corresponding to MBS. */ | 370 | /* Store the wide character string which is corresponding to MBS. */ |
398 | wint_t *wcs; | 371 | wint_t *wcs; |
399 | Idx *offsets; | 372 | Idx *offsets; |
400 | mbstate_t cur_state; | 373 | mbstate_t cur_state; |
401 | #endif | ||
402 | /* Index in RAW_MBS. Each character mbs[i] corresponds to | 374 | /* Index in RAW_MBS. Each character mbs[i] corresponds to |
403 | raw_mbs[raw_mbs_idx + i]. */ | 375 | raw_mbs[raw_mbs_idx + i]. */ |
404 | Idx raw_mbs_idx; | 376 | Idx raw_mbs_idx; |
@@ -446,24 +418,9 @@ struct re_dfa_t; | |||
446 | typedef struct re_dfa_t re_dfa_t; | 418 | typedef struct re_dfa_t re_dfa_t; |
447 | 419 | ||
448 | #ifndef _LIBC | 420 | #ifndef _LIBC |
449 | # define internal_function | 421 | # define IS_IN(libc) false |
450 | #endif | 422 | #endif |
451 | 423 | ||
452 | #ifndef NOT_IN_libc | ||
453 | static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr, | ||
454 | Idx new_buf_len) | ||
455 | internal_function; | ||
456 | # ifdef RE_ENABLE_I18N | ||
457 | static void build_wcs_buffer (re_string_t *pstr) internal_function; | ||
458 | static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr) | ||
459 | internal_function; | ||
460 | # endif /* RE_ENABLE_I18N */ | ||
461 | static void build_upper_buffer (re_string_t *pstr) internal_function; | ||
462 | static void re_string_translate_buffer (re_string_t *pstr) internal_function; | ||
463 | static unsigned int re_string_context_at (const re_string_t *input, Idx idx, | ||
464 | int eflags) | ||
465 | internal_function __attribute__ ((pure)); | ||
466 | #endif | ||
467 | #define re_string_peek_byte(pstr, offset) \ | 424 | #define re_string_peek_byte(pstr, offset) \ |
468 | ((pstr)->mbs[(pstr)->cur_idx + offset]) | 425 | ((pstr)->mbs[(pstr)->cur_idx + offset]) |
469 | #define re_string_fetch_byte(pstr) \ | 426 | #define re_string_fetch_byte(pstr) \ |
@@ -481,25 +438,6 @@ static unsigned int re_string_context_at (const re_string_t *input, Idx idx, | |||
481 | #define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx)) | 438 | #define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx)) |
482 | #define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) | 439 | #define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) |
483 | 440 | ||
484 | #if defined _LIBC || HAVE_ALLOCA | ||
485 | # include <alloca.h> | ||
486 | #endif | ||
487 | |||
488 | #ifndef _LIBC | ||
489 | # if HAVE_ALLOCA | ||
490 | /* The OS usually guarantees only one guard page at the bottom of the stack, | ||
491 | and a page size can be as small as 4096 bytes. So we cannot safely | ||
492 | allocate anything larger than 4096 bytes. Also care for the possibility | ||
493 | of a few compiler-allocated temporary stack slots. */ | ||
494 | # define __libc_use_alloca(n) ((n) < 4032) | ||
495 | # else | ||
496 | /* alloca is implemented with malloc, so just use malloc. */ | ||
497 | # define __libc_use_alloca(n) 0 | ||
498 | # undef alloca | ||
499 | # define alloca(n) malloc (n) | ||
500 | # endif | ||
501 | #endif | ||
502 | |||
503 | #ifdef _LIBC | 441 | #ifdef _LIBC |
504 | # define MALLOC_0_IS_NONNULL 1 | 442 | # define MALLOC_0_IS_NONNULL 1 |
505 | #elif !defined MALLOC_0_IS_NONNULL | 443 | #elif !defined MALLOC_0_IS_NONNULL |
@@ -556,7 +494,7 @@ typedef struct bin_tree_storage_t bin_tree_storage_t; | |||
556 | 494 | ||
557 | #define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_') | 495 | #define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_') |
558 | #define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR) | 496 | #define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR) |
559 | #define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_') | 497 | #define IS_WIDE_WORD_CHAR(ch) (__iswalnum (ch) || (ch) == L'_') |
560 | #define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR) | 498 | #define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR) |
561 | 499 | ||
562 | #define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \ | 500 | #define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \ |
@@ -636,20 +574,15 @@ struct re_backref_cache_entry | |||
636 | Idx str_idx; | 574 | Idx str_idx; |
637 | Idx subexp_from; | 575 | Idx subexp_from; |
638 | Idx subexp_to; | 576 | Idx subexp_to; |
577 | bitset_word_t eps_reachable_subexps_map; | ||
639 | char more; | 578 | char more; |
640 | char unused; | ||
641 | unsigned short int eps_reachable_subexps_map; | ||
642 | }; | 579 | }; |
643 | 580 | ||
644 | typedef struct | 581 | typedef struct |
645 | { | 582 | { |
646 | /* The string object corresponding to the input string. */ | 583 | /* The string object corresponding to the input string. */ |
647 | re_string_t input; | 584 | re_string_t input; |
648 | #if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) | ||
649 | const re_dfa_t *const dfa; | 585 | const re_dfa_t *const dfa; |
650 | #else | ||
651 | const re_dfa_t *dfa; | ||
652 | #endif | ||
653 | /* EFLAGS of the argument of regexec. */ | 586 | /* EFLAGS of the argument of regexec. */ |
654 | int eflags; | 587 | int eflags; |
655 | /* Where the matching ends. */ | 588 | /* Where the matching ends. */ |
@@ -769,31 +702,31 @@ typedef struct | |||
769 | 702 | ||
770 | /* Functions for bitset_t operation. */ | 703 | /* Functions for bitset_t operation. */ |
771 | 704 | ||
772 | static void | 705 | static inline void |
773 | bitset_set (bitset_t set, Idx i) | 706 | bitset_set (bitset_t set, Idx i) |
774 | { | 707 | { |
775 | set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS; | 708 | set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS; |
776 | } | 709 | } |
777 | 710 | ||
778 | static void | 711 | static inline void |
779 | bitset_clear (bitset_t set, Idx i) | 712 | bitset_clear (bitset_t set, Idx i) |
780 | { | 713 | { |
781 | set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS); | 714 | set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS); |
782 | } | 715 | } |
783 | 716 | ||
784 | static bool | 717 | static inline bool |
785 | bitset_contain (const bitset_t set, Idx i) | 718 | bitset_contain (const bitset_t set, Idx i) |
786 | { | 719 | { |
787 | return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; | 720 | return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; |
788 | } | 721 | } |
789 | 722 | ||
790 | static void | 723 | static inline void |
791 | bitset_empty (bitset_t set) | 724 | bitset_empty (bitset_t set) |
792 | { | 725 | { |
793 | memset (set, '\0', sizeof (bitset_t)); | 726 | memset (set, '\0', sizeof (bitset_t)); |
794 | } | 727 | } |
795 | 728 | ||
796 | static void | 729 | static inline void |
797 | bitset_set_all (bitset_t set) | 730 | bitset_set_all (bitset_t set) |
798 | { | 731 | { |
799 | memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS)); | 732 | memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS)); |
@@ -802,13 +735,13 @@ bitset_set_all (bitset_t set) | |||
802 | ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; | 735 | ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; |
803 | } | 736 | } |
804 | 737 | ||
805 | static void | 738 | static inline void |
806 | bitset_copy (bitset_t dest, const bitset_t src) | 739 | bitset_copy (bitset_t dest, const bitset_t src) |
807 | { | 740 | { |
808 | memcpy (dest, src, sizeof (bitset_t)); | 741 | memcpy (dest, src, sizeof (bitset_t)); |
809 | } | 742 | } |
810 | 743 | ||
811 | static void __attribute__ ((unused)) | 744 | static inline void |
812 | bitset_not (bitset_t set) | 745 | bitset_not (bitset_t set) |
813 | { | 746 | { |
814 | int bitset_i; | 747 | int bitset_i; |
@@ -820,7 +753,7 @@ bitset_not (bitset_t set) | |||
820 | & ~set[BITSET_WORDS - 1]); | 753 | & ~set[BITSET_WORDS - 1]); |
821 | } | 754 | } |
822 | 755 | ||
823 | static void __attribute__ ((unused)) | 756 | static inline void |
824 | bitset_merge (bitset_t dest, const bitset_t src) | 757 | bitset_merge (bitset_t dest, const bitset_t src) |
825 | { | 758 | { |
826 | int bitset_i; | 759 | int bitset_i; |
@@ -828,7 +761,7 @@ bitset_merge (bitset_t dest, const bitset_t src) | |||
828 | dest[bitset_i] |= src[bitset_i]; | 761 | dest[bitset_i] |= src[bitset_i]; |
829 | } | 762 | } |
830 | 763 | ||
831 | static void __attribute__ ((unused)) | 764 | static inline void |
832 | bitset_mask (bitset_t dest, const bitset_t src) | 765 | bitset_mask (bitset_t dest, const bitset_t src) |
833 | { | 766 | { |
834 | int bitset_i; | 767 | int bitset_i; |
@@ -836,10 +769,9 @@ bitset_mask (bitset_t dest, const bitset_t src) | |||
836 | dest[bitset_i] &= src[bitset_i]; | 769 | dest[bitset_i] &= src[bitset_i]; |
837 | } | 770 | } |
838 | 771 | ||
839 | #ifdef RE_ENABLE_I18N | ||
840 | /* Functions for re_string. */ | 772 | /* Functions for re_string. */ |
841 | static int | 773 | static int |
842 | internal_function __attribute__ ((pure, unused)) | 774 | __attribute__ ((pure, unused)) |
843 | re_string_char_size_at (const re_string_t *pstr, Idx idx) | 775 | re_string_char_size_at (const re_string_t *pstr, Idx idx) |
844 | { | 776 | { |
845 | int byte_idx; | 777 | int byte_idx; |
@@ -852,7 +784,7 @@ re_string_char_size_at (const re_string_t *pstr, Idx idx) | |||
852 | } | 784 | } |
853 | 785 | ||
854 | static wint_t | 786 | static wint_t |
855 | internal_function __attribute__ ((pure, unused)) | 787 | __attribute__ ((pure, unused)) |
856 | re_string_wchar_at (const re_string_t *pstr, Idx idx) | 788 | re_string_wchar_at (const re_string_t *pstr, Idx idx) |
857 | { | 789 | { |
858 | if (pstr->mb_cur_max == 1) | 790 | if (pstr->mb_cur_max == 1) |
@@ -860,15 +792,17 @@ re_string_wchar_at (const re_string_t *pstr, Idx idx) | |||
860 | return (wint_t) pstr->wcs[idx]; | 792 | return (wint_t) pstr->wcs[idx]; |
861 | } | 793 | } |
862 | 794 | ||
863 | # ifndef NOT_IN_libc | 795 | #ifdef _LIBC |
796 | # include <locale/weight.h> | ||
797 | #endif | ||
798 | |||
864 | static int | 799 | static int |
865 | internal_function __attribute__ ((pure, unused)) | 800 | __attribute__ ((pure, unused)) |
866 | re_string_elem_size_at (const re_string_t *pstr, Idx idx) | 801 | re_string_elem_size_at (const re_string_t *pstr, Idx idx) |
867 | { | 802 | { |
868 | # ifdef _LIBC | 803 | #ifdef _LIBC |
869 | const unsigned char *p, *extra; | 804 | const unsigned char *p, *extra; |
870 | const int32_t *table, *indirect; | 805 | const int32_t *table, *indirect; |
871 | # include <locale/weight.h> | ||
872 | uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); | 806 | uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); |
873 | 807 | ||
874 | if (nrules != 0) | 808 | if (nrules != 0) |
@@ -879,31 +813,22 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx) | |||
879 | indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, | 813 | indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, |
880 | _NL_COLLATE_INDIRECTMB); | 814 | _NL_COLLATE_INDIRECTMB); |
881 | p = pstr->mbs + idx; | 815 | p = pstr->mbs + idx; |
882 | findidx (&p, pstr->len - idx); | 816 | findidx (table, indirect, extra, &p, pstr->len - idx); |
883 | return p - pstr->mbs - idx; | 817 | return p - pstr->mbs - idx; |
884 | } | 818 | } |
885 | else | 819 | #endif /* _LIBC */ |
886 | # endif /* _LIBC */ | 820 | |
887 | return 1; | 821 | return 1; |
888 | } | 822 | } |
889 | # endif | ||
890 | #endif /* RE_ENABLE_I18N */ | ||
891 | 823 | ||
892 | #ifndef __GNUC_PREREQ | 824 | #ifdef _LIBC |
893 | # if defined __GNUC__ && defined __GNUC_MINOR__ | 825 | # if __GNUC__ >= 7 |
894 | # define __GNUC_PREREQ(maj, min) \ | 826 | # define FALLTHROUGH __attribute__ ((__fallthrough__)) |
895 | ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) | ||
896 | # else | 827 | # else |
897 | # define __GNUC_PREREQ(maj, min) 0 | 828 | # define FALLTHROUGH ((void) 0) |
898 | # endif | 829 | # endif |
899 | #endif | ||
900 | |||
901 | #if __GNUC_PREREQ (3,4) | ||
902 | # undef __attribute_warn_unused_result__ | ||
903 | # define __attribute_warn_unused_result__ \ | ||
904 | __attribute__ ((__warn_unused_result__)) | ||
905 | #else | 830 | #else |
906 | # define __attribute_warn_unused_result__ /* empty */ | 831 | # include "attribute.h" |
907 | #endif | 832 | #endif |
908 | 833 | ||
909 | #endif /* _REGEX_INTERNAL_H */ | 834 | #endif /* _REGEX_INTERNAL_H */ |