diff options
Diffstat (limited to 'gl/regex_internal.h')
-rw-r--r-- | gl/regex_internal.h | 298 |
1 files changed, 112 insertions, 186 deletions
diff --git a/gl/regex_internal.h b/gl/regex_internal.h index a2b8f16..57a455b 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-2022 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> |
@@ -33,36 +32,35 @@ | |||
33 | #include <stdbool.h> | 32 | #include <stdbool.h> |
34 | #include <stdint.h> | 33 | #include <stdint.h> |
35 | 34 | ||
35 | #ifndef _LIBC | ||
36 | # include <dynarray.h> | ||
37 | #endif | ||
38 | |||
39 | #include <intprops.h> | ||
40 | #include <verify.h> | ||
41 | |||
42 | #if defined DEBUG && DEBUG != 0 | ||
43 | # include <assert.h> | ||
44 | # define DEBUG_ASSERT(x) assert (x) | ||
45 | #else | ||
46 | # define DEBUG_ASSERT(x) assume (x) | ||
47 | #endif | ||
48 | |||
36 | #ifdef _LIBC | 49 | #ifdef _LIBC |
37 | # include <bits/libc-lock.h> | 50 | # include <libc-lock.h> |
38 | # define lock_define(name) __libc_lock_define (, name) | 51 | # define lock_define(name) __libc_lock_define (, name) |
39 | # define lock_init(lock) (__libc_lock_init (lock), 0) | 52 | # define lock_init(lock) (__libc_lock_init (lock), 0) |
40 | # define lock_fini(lock) 0 | 53 | # define lock_fini(lock) ((void) 0) |
41 | # define lock_lock(lock) __libc_lock_lock (lock) | 54 | # define lock_lock(lock) __libc_lock_lock (lock) |
42 | # define lock_unlock(lock) __libc_lock_unlock (lock) | 55 | # define lock_unlock(lock) __libc_lock_unlock (lock) |
43 | #elif defined GNULIB_LOCK | 56 | #elif defined GNULIB_LOCK && !defined GNULIB_REGEX_SINGLE_THREAD |
44 | # include "glthread/lock.h" | 57 | # include "glthread/lock.h" |
45 | /* Use gl_lock_define if empty macro arguments are known to work. | 58 | # 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)) | 59 | # define lock_init(lock) glthread_lock_init (&(lock)) |
62 | # define lock_fini(lock) glthread_lock_destroy (&(lock)) | 60 | # define lock_fini(lock) glthread_lock_destroy (&(lock)) |
63 | # define lock_lock(lock) glthread_lock_lock (&(lock)) | 61 | # define lock_lock(lock) glthread_lock_lock (&(lock)) |
64 | # define lock_unlock(lock) glthread_lock_unlock (&(lock)) | 62 | # define lock_unlock(lock) glthread_lock_unlock (&(lock)) |
65 | #elif defined GNULIB_PTHREAD | 63 | #elif defined GNULIB_PTHREAD && !defined GNULIB_REGEX_SINGLE_THREAD |
66 | # include <pthread.h> | 64 | # include <pthread.h> |
67 | # define lock_define(name) pthread_mutex_t name; | 65 | # define lock_define(name) pthread_mutex_t name; |
68 | # define lock_init(lock) pthread_mutex_init (&(lock), 0) | 66 | # define lock_init(lock) pthread_mutex_init (&(lock), 0) |
@@ -83,11 +81,18 @@ | |||
83 | # define isblank(ch) ((ch) == ' ' || (ch) == '\t') | 81 | # define isblank(ch) ((ch) == ' ' || (ch) == '\t') |
84 | #endif | 82 | #endif |
85 | 83 | ||
84 | /* regex code assumes isascii has its usual numeric meaning, | ||
85 | even if the portable character set uses EBCDIC encoding, | ||
86 | and even if wint_t is wider than int. */ | ||
87 | #ifndef _LIBC | ||
88 | # undef isascii | ||
89 | # define isascii(c) (((c) & ~0x7f) == 0) | ||
90 | #endif | ||
91 | |||
86 | #ifdef _LIBC | 92 | #ifdef _LIBC |
87 | # ifndef _RE_DEFINE_LOCALE_FUNCTIONS | 93 | # ifndef _RE_DEFINE_LOCALE_FUNCTIONS |
88 | # define _RE_DEFINE_LOCALE_FUNCTIONS 1 | 94 | # define _RE_DEFINE_LOCALE_FUNCTIONS 1 |
89 | # include <locale/localeinfo.h> | 95 | # include <locale/localeinfo.h> |
90 | # include <locale/elem-hash.h> | ||
91 | # include <locale/coll-lookup.h> | 96 | # include <locale/coll-lookup.h> |
92 | # endif | 97 | # endif |
93 | #endif | 98 | #endif |
@@ -101,6 +106,7 @@ | |||
101 | __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES) | 106 | __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES) |
102 | # endif | 107 | # endif |
103 | #else | 108 | #else |
109 | # undef gettext | ||
104 | # define gettext(msgid) (msgid) | 110 | # define gettext(msgid) (msgid) |
105 | #endif | 111 | #endif |
106 | 112 | ||
@@ -110,16 +116,6 @@ | |||
110 | # define gettext_noop(String) String | 116 | # define gettext_noop(String) String |
111 | #endif | 117 | #endif |
112 | 118 | ||
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. */ | 119 | /* Number of ASCII characters. */ |
124 | #define ASCII_CHARS 0x80 | 120 | #define ASCII_CHARS 0x80 |
125 | 121 | ||
@@ -135,45 +131,60 @@ | |||
135 | /* Rename to standard API for using out of glibc. */ | 131 | /* Rename to standard API for using out of glibc. */ |
136 | #ifndef _LIBC | 132 | #ifndef _LIBC |
137 | # undef __wctype | 133 | # undef __wctype |
134 | # undef __iswalnum | ||
138 | # undef __iswctype | 135 | # undef __iswctype |
136 | # undef __towlower | ||
137 | # undef __towupper | ||
139 | # define __wctype wctype | 138 | # define __wctype wctype |
139 | # define __iswalnum iswalnum | ||
140 | # define __iswctype iswctype | 140 | # define __iswctype iswctype |
141 | # define __towlower towlower | ||
142 | # define __towupper towupper | ||
141 | # define __btowc btowc | 143 | # define __btowc btowc |
142 | # define __mbrtowc mbrtowc | 144 | # define __mbrtowc mbrtowc |
143 | # define __wcrtomb wcrtomb | 145 | # define __wcrtomb wcrtomb |
144 | # define __regfree regfree | 146 | # define __regfree regfree |
145 | # define attribute_hidden | ||
146 | #endif /* not _LIBC */ | 147 | #endif /* not _LIBC */ |
147 | 148 | ||
148 | #if __GNUC__ < 3 + (__GNUC_MINOR__ < 1) | 149 | /* Types related to integers. Unless protected by #ifdef _LIBC, the |
149 | # define __attribute__(arg) | 150 | regex code should avoid exact-width types like int32_t and uint64_t |
150 | #endif | 151 | as some non-GCC platforms lack them, an issue when this code is |
152 | used in Gnulib. */ | ||
151 | 153 | ||
152 | typedef __re_idx_t Idx; | 154 | #ifndef SSIZE_MAX |
153 | #ifdef _REGEX_LARGE_OFFSETS | 155 | # 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 | 156 | #endif |
158 | 157 | #ifndef ULONG_WIDTH | |
159 | /* Special return value for failure to match. */ | 158 | # define ULONG_WIDTH REGEX_UINTEGER_WIDTH (ULONG_MAX) |
160 | #define REG_MISSING ((Idx) -1) | 159 | /* The number of usable bits in an unsigned integer type with maximum |
161 | 160 | value MAX, as an int expression suitable in #if. Cover all known | |
162 | /* Special return value for internal error. */ | 161 | practical hosts. This implementation exploits the fact that MAX is |
163 | #define REG_ERROR ((Idx) -2) | 162 | 1 less than a power of 2, and merely counts the number of 1 bits in |
164 | 163 | 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. */ | 164 | # define REGEX_UINTEGER_WIDTH(max) REGEX_COB128 (max) |
166 | #ifdef _REGEX_LARGE_OFFSETS | 165 | # define REGEX_COB128(n) (REGEX_COB64 ((n) >> 31 >> 31 >> 2) + REGEX_COB64 (n)) |
167 | # define REG_VALID_INDEX(n) ((Idx) (n) < REG_ERROR) | 166 | # define REGEX_COB64(n) (REGEX_COB32 ((n) >> 31 >> 1) + REGEX_COB32 (n)) |
168 | #else | 167 | # define REGEX_COB32(n) (REGEX_COB16 ((n) >> 16) + REGEX_COB16 (n)) |
169 | # define REG_VALID_INDEX(n) (0 <= (n)) | 168 | # define REGEX_COB16(n) (REGEX_COB8 ((n) >> 8) + REGEX_COB8 (n)) |
169 | # define REGEX_COB8(n) (REGEX_COB4 ((n) >> 4) + REGEX_COB4 (n)) | ||
170 | # define REGEX_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + ((n) & 1)) | ||
171 | # if ULONG_MAX / 2 + 1 != 1ul << (ULONG_WIDTH - 1) | ||
172 | # error "ULONG_MAX out of range" | ||
173 | # endif | ||
170 | #endif | 174 | #endif |
171 | 175 | ||
172 | /* Test whether N is a valid nonzero index. */ | 176 | /* The type of indexes into strings. This is signed, not size_t, |
177 | since the API requires indexes to fit in regoff_t anyway, and using | ||
178 | signed integers makes the code a bit smaller and presumably faster. | ||
179 | The traditional GNU regex implementation uses int for indexes. | ||
180 | The POSIX-compatible implementation uses a possibly-wider type. | ||
181 | The name 'Idx' is three letters to minimize the hassle of | ||
182 | reindenting a lot of regex code that formerly used 'int'. */ | ||
183 | typedef regoff_t Idx; | ||
173 | #ifdef _REGEX_LARGE_OFFSETS | 184 | #ifdef _REGEX_LARGE_OFFSETS |
174 | # define REG_VALID_NONZERO_INDEX(n) ((Idx) ((n) - 1) < (Idx) (REG_ERROR - 1)) | 185 | # define IDX_MAX SSIZE_MAX |
175 | #else | 186 | #else |
176 | # define REG_VALID_NONZERO_INDEX(n) (0 < (n)) | 187 | # define IDX_MAX INT_MAX |
177 | #endif | 188 | #endif |
178 | 189 | ||
179 | /* A hash value, suitable for computing hash tables. */ | 190 | /* A hash value, suitable for computing hash tables. */ |
@@ -184,36 +195,8 @@ typedef __re_size_t re_hashval_t; | |||
184 | typedef unsigned long int bitset_word_t; | 195 | typedef unsigned long int bitset_word_t; |
185 | /* All bits set in a bitset_word_t. */ | 196 | /* All bits set in a bitset_word_t. */ |
186 | #define BITSET_WORD_MAX ULONG_MAX | 197 | #define BITSET_WORD_MAX ULONG_MAX |
187 | 198 | /* Number of bits in a bitset_word_t. */ | |
188 | /* Number of bits in a bitset_word_t. For portability to hosts with | 199 | #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 | 200 | ||
218 | /* Number of bitset_word_t values in a bitset_t. */ | 201 | /* Number of bitset_word_t values in a bitset_t. */ |
219 | #define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS) | 202 | #define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS) |
@@ -264,10 +247,8 @@ typedef enum | |||
264 | SIMPLE_BRACKET = 3, | 247 | SIMPLE_BRACKET = 3, |
265 | OP_BACK_REF = 4, | 248 | OP_BACK_REF = 4, |
266 | OP_PERIOD = 5, | 249 | OP_PERIOD = 5, |
267 | #ifdef RE_ENABLE_I18N | ||
268 | COMPLEX_BRACKET = 6, | 250 | COMPLEX_BRACKET = 6, |
269 | OP_UTF8_PERIOD = 7, | 251 | OP_UTF8_PERIOD = 7, |
270 | #endif /* RE_ENABLE_I18N */ | ||
271 | 252 | ||
272 | /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used | 253 | /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used |
273 | when the debugger shows values of this enum type. */ | 254 | when the debugger shows values of this enum type. */ |
@@ -305,30 +286,29 @@ typedef enum | |||
305 | 286 | ||
306 | } re_token_type_t; | 287 | } re_token_type_t; |
307 | 288 | ||
308 | #ifdef RE_ENABLE_I18N | ||
309 | typedef struct | 289 | typedef struct |
310 | { | 290 | { |
311 | /* Multibyte characters. */ | 291 | /* Multibyte characters. */ |
312 | wchar_t *mbchars; | 292 | wchar_t *mbchars; |
313 | 293 | ||
294 | #ifdef _LIBC | ||
314 | /* Collating symbols. */ | 295 | /* Collating symbols. */ |
315 | # ifdef _LIBC | ||
316 | int32_t *coll_syms; | 296 | int32_t *coll_syms; |
317 | # endif | 297 | #endif |
318 | 298 | ||
299 | #ifdef _LIBC | ||
319 | /* Equivalence classes. */ | 300 | /* Equivalence classes. */ |
320 | # ifdef _LIBC | ||
321 | int32_t *equiv_classes; | 301 | int32_t *equiv_classes; |
322 | # endif | 302 | #endif |
323 | 303 | ||
324 | /* Range expressions. */ | 304 | /* Range expressions. */ |
325 | # ifdef _LIBC | 305 | #ifdef _LIBC |
326 | uint32_t *range_starts; | 306 | uint32_t *range_starts; |
327 | uint32_t *range_ends; | 307 | uint32_t *range_ends; |
328 | # else /* not _LIBC */ | 308 | #else |
329 | wchar_t *range_starts; | 309 | wchar_t *range_starts; |
330 | wchar_t *range_ends; | 310 | wchar_t *range_ends; |
331 | # endif /* not _LIBC */ | 311 | #endif |
332 | 312 | ||
333 | /* Character classes. */ | 313 | /* Character classes. */ |
334 | wctype_t *char_classes; | 314 | wctype_t *char_classes; |
@@ -351,7 +331,6 @@ typedef struct | |||
351 | /* # of character classes. */ | 331 | /* # of character classes. */ |
352 | Idx nchar_classes; | 332 | Idx nchar_classes; |
353 | } re_charset_t; | 333 | } re_charset_t; |
354 | #endif /* RE_ENABLE_I18N */ | ||
355 | 334 | ||
356 | typedef struct | 335 | typedef struct |
357 | { | 336 | { |
@@ -359,13 +338,11 @@ typedef struct | |||
359 | { | 338 | { |
360 | unsigned char c; /* for CHARACTER */ | 339 | unsigned char c; /* for CHARACTER */ |
361 | re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */ | 340 | re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */ |
362 | #ifdef RE_ENABLE_I18N | ||
363 | re_charset_t *mbcset; /* for COMPLEX_BRACKET */ | 341 | re_charset_t *mbcset; /* for COMPLEX_BRACKET */ |
364 | #endif /* RE_ENABLE_I18N */ | ||
365 | Idx idx; /* for BACK_REF */ | 342 | Idx idx; /* for BACK_REF */ |
366 | re_context_type ctx_type; /* for ANCHOR */ | 343 | re_context_type ctx_type; /* for ANCHOR */ |
367 | } opr; | 344 | } opr; |
368 | #if __GNUC__ >= 2 && !defined __STRICT_ANSI__ | 345 | #if (__GNUC__ >= 2 || defined __clang__) && !defined __STRICT_ANSI__ |
369 | re_token_type_t type : 8; | 346 | re_token_type_t type : 8; |
370 | #else | 347 | #else |
371 | re_token_type_t type; | 348 | re_token_type_t type; |
@@ -373,12 +350,10 @@ typedef struct | |||
373 | unsigned int constraint : 10; /* context constraint */ | 350 | unsigned int constraint : 10; /* context constraint */ |
374 | unsigned int duplicated : 1; | 351 | unsigned int duplicated : 1; |
375 | unsigned int opt_subexp : 1; | 352 | unsigned int opt_subexp : 1; |
376 | #ifdef RE_ENABLE_I18N | ||
377 | unsigned int accept_mb : 1; | 353 | unsigned int accept_mb : 1; |
378 | /* These 2 bits can be moved into the union if needed (e.g. if running out | 354 | /* 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). */ | 355 | of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */ |
380 | unsigned int mb_partial : 1; | 356 | unsigned int mb_partial : 1; |
381 | #endif | ||
382 | unsigned int word_char : 1; | 357 | unsigned int word_char : 1; |
383 | } re_token_t; | 358 | } re_token_t; |
384 | 359 | ||
@@ -393,12 +368,10 @@ struct re_string_t | |||
393 | REG_ICASE, upper cases of the string are stored, otherwise MBS points | 368 | REG_ICASE, upper cases of the string are stored, otherwise MBS points |
394 | the same address that RAW_MBS points. */ | 369 | the same address that RAW_MBS points. */ |
395 | unsigned char *mbs; | 370 | unsigned char *mbs; |
396 | #ifdef RE_ENABLE_I18N | ||
397 | /* Store the wide character string which is corresponding to MBS. */ | 371 | /* Store the wide character string which is corresponding to MBS. */ |
398 | wint_t *wcs; | 372 | wint_t *wcs; |
399 | Idx *offsets; | 373 | Idx *offsets; |
400 | mbstate_t cur_state; | 374 | mbstate_t cur_state; |
401 | #endif | ||
402 | /* Index in RAW_MBS. Each character mbs[i] corresponds to | 375 | /* Index in RAW_MBS. Each character mbs[i] corresponds to |
403 | raw_mbs[raw_mbs_idx + i]. */ | 376 | raw_mbs[raw_mbs_idx + i]. */ |
404 | Idx raw_mbs_idx; | 377 | Idx raw_mbs_idx; |
@@ -446,24 +419,9 @@ struct re_dfa_t; | |||
446 | typedef struct re_dfa_t re_dfa_t; | 419 | typedef struct re_dfa_t re_dfa_t; |
447 | 420 | ||
448 | #ifndef _LIBC | 421 | #ifndef _LIBC |
449 | # define internal_function | 422 | # define IS_IN(libc) false |
450 | #endif | 423 | #endif |
451 | 424 | ||
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) \ | 425 | #define re_string_peek_byte(pstr, offset) \ |
468 | ((pstr)->mbs[(pstr)->cur_idx + offset]) | 426 | ((pstr)->mbs[(pstr)->cur_idx + offset]) |
469 | #define re_string_fetch_byte(pstr) \ | 427 | #define re_string_fetch_byte(pstr) \ |
@@ -481,25 +439,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)) | 439 | #define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx)) |
482 | #define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) | 440 | #define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) |
483 | 441 | ||
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 | 442 | #ifdef _LIBC |
504 | # define MALLOC_0_IS_NONNULL 1 | 443 | # define MALLOC_0_IS_NONNULL 1 |
505 | #elif !defined MALLOC_0_IS_NONNULL | 444 | #elif !defined MALLOC_0_IS_NONNULL |
@@ -556,7 +495,7 @@ typedef struct bin_tree_storage_t bin_tree_storage_t; | |||
556 | 495 | ||
557 | #define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_') | 496 | #define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_') |
558 | #define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR) | 497 | #define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR) |
559 | #define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_') | 498 | #define IS_WIDE_WORD_CHAR(ch) (__iswalnum (ch) || (ch) == L'_') |
560 | #define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR) | 499 | #define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR) |
561 | 500 | ||
562 | #define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \ | 501 | #define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \ |
@@ -636,20 +575,15 @@ struct re_backref_cache_entry | |||
636 | Idx str_idx; | 575 | Idx str_idx; |
637 | Idx subexp_from; | 576 | Idx subexp_from; |
638 | Idx subexp_to; | 577 | Idx subexp_to; |
578 | bitset_word_t eps_reachable_subexps_map; | ||
639 | char more; | 579 | char more; |
640 | char unused; | ||
641 | unsigned short int eps_reachable_subexps_map; | ||
642 | }; | 580 | }; |
643 | 581 | ||
644 | typedef struct | 582 | typedef struct |
645 | { | 583 | { |
646 | /* The string object corresponding to the input string. */ | 584 | /* The string object corresponding to the input string. */ |
647 | re_string_t input; | 585 | re_string_t input; |
648 | #if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) | ||
649 | const re_dfa_t *const dfa; | 586 | const re_dfa_t *const dfa; |
650 | #else | ||
651 | const re_dfa_t *dfa; | ||
652 | #endif | ||
653 | /* EFLAGS of the argument of regexec. */ | 587 | /* EFLAGS of the argument of regexec. */ |
654 | int eflags; | 588 | int eflags; |
655 | /* Where the matching ends. */ | 589 | /* Where the matching ends. */ |
@@ -769,31 +703,31 @@ typedef struct | |||
769 | 703 | ||
770 | /* Functions for bitset_t operation. */ | 704 | /* Functions for bitset_t operation. */ |
771 | 705 | ||
772 | static void | 706 | static inline void |
773 | bitset_set (bitset_t set, Idx i) | 707 | bitset_set (bitset_t set, Idx i) |
774 | { | 708 | { |
775 | set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS; | 709 | set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS; |
776 | } | 710 | } |
777 | 711 | ||
778 | static void | 712 | static inline void |
779 | bitset_clear (bitset_t set, Idx i) | 713 | bitset_clear (bitset_t set, Idx i) |
780 | { | 714 | { |
781 | set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS); | 715 | set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS); |
782 | } | 716 | } |
783 | 717 | ||
784 | static bool | 718 | static inline bool |
785 | bitset_contain (const bitset_t set, Idx i) | 719 | bitset_contain (const bitset_t set, Idx i) |
786 | { | 720 | { |
787 | return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; | 721 | return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; |
788 | } | 722 | } |
789 | 723 | ||
790 | static void | 724 | static inline void |
791 | bitset_empty (bitset_t set) | 725 | bitset_empty (bitset_t set) |
792 | { | 726 | { |
793 | memset (set, '\0', sizeof (bitset_t)); | 727 | memset (set, '\0', sizeof (bitset_t)); |
794 | } | 728 | } |
795 | 729 | ||
796 | static void | 730 | static inline void |
797 | bitset_set_all (bitset_t set) | 731 | bitset_set_all (bitset_t set) |
798 | { | 732 | { |
799 | memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS)); | 733 | memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS)); |
@@ -802,13 +736,13 @@ bitset_set_all (bitset_t set) | |||
802 | ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; | 736 | ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; |
803 | } | 737 | } |
804 | 738 | ||
805 | static void | 739 | static inline void |
806 | bitset_copy (bitset_t dest, const bitset_t src) | 740 | bitset_copy (bitset_t dest, const bitset_t src) |
807 | { | 741 | { |
808 | memcpy (dest, src, sizeof (bitset_t)); | 742 | memcpy (dest, src, sizeof (bitset_t)); |
809 | } | 743 | } |
810 | 744 | ||
811 | static void __attribute__ ((unused)) | 745 | static inline void |
812 | bitset_not (bitset_t set) | 746 | bitset_not (bitset_t set) |
813 | { | 747 | { |
814 | int bitset_i; | 748 | int bitset_i; |
@@ -820,7 +754,7 @@ bitset_not (bitset_t set) | |||
820 | & ~set[BITSET_WORDS - 1]); | 754 | & ~set[BITSET_WORDS - 1]); |
821 | } | 755 | } |
822 | 756 | ||
823 | static void __attribute__ ((unused)) | 757 | static inline void |
824 | bitset_merge (bitset_t dest, const bitset_t src) | 758 | bitset_merge (bitset_t dest, const bitset_t src) |
825 | { | 759 | { |
826 | int bitset_i; | 760 | int bitset_i; |
@@ -828,7 +762,7 @@ bitset_merge (bitset_t dest, const bitset_t src) | |||
828 | dest[bitset_i] |= src[bitset_i]; | 762 | dest[bitset_i] |= src[bitset_i]; |
829 | } | 763 | } |
830 | 764 | ||
831 | static void __attribute__ ((unused)) | 765 | static inline void |
832 | bitset_mask (bitset_t dest, const bitset_t src) | 766 | bitset_mask (bitset_t dest, const bitset_t src) |
833 | { | 767 | { |
834 | int bitset_i; | 768 | int bitset_i; |
@@ -836,10 +770,9 @@ bitset_mask (bitset_t dest, const bitset_t src) | |||
836 | dest[bitset_i] &= src[bitset_i]; | 770 | dest[bitset_i] &= src[bitset_i]; |
837 | } | 771 | } |
838 | 772 | ||
839 | #ifdef RE_ENABLE_I18N | ||
840 | /* Functions for re_string. */ | 773 | /* Functions for re_string. */ |
841 | static int | 774 | static int |
842 | internal_function __attribute__ ((pure, unused)) | 775 | __attribute__ ((pure, unused)) |
843 | re_string_char_size_at (const re_string_t *pstr, Idx idx) | 776 | re_string_char_size_at (const re_string_t *pstr, Idx idx) |
844 | { | 777 | { |
845 | int byte_idx; | 778 | int byte_idx; |
@@ -852,7 +785,7 @@ re_string_char_size_at (const re_string_t *pstr, Idx idx) | |||
852 | } | 785 | } |
853 | 786 | ||
854 | static wint_t | 787 | static wint_t |
855 | internal_function __attribute__ ((pure, unused)) | 788 | __attribute__ ((pure, unused)) |
856 | re_string_wchar_at (const re_string_t *pstr, Idx idx) | 789 | re_string_wchar_at (const re_string_t *pstr, Idx idx) |
857 | { | 790 | { |
858 | if (pstr->mb_cur_max == 1) | 791 | if (pstr->mb_cur_max == 1) |
@@ -860,15 +793,17 @@ re_string_wchar_at (const re_string_t *pstr, Idx idx) | |||
860 | return (wint_t) pstr->wcs[idx]; | 793 | return (wint_t) pstr->wcs[idx]; |
861 | } | 794 | } |
862 | 795 | ||
863 | # ifndef NOT_IN_libc | 796 | #ifdef _LIBC |
797 | # include <locale/weight.h> | ||
798 | #endif | ||
799 | |||
864 | static int | 800 | static int |
865 | internal_function __attribute__ ((pure, unused)) | 801 | __attribute__ ((pure, unused)) |
866 | re_string_elem_size_at (const re_string_t *pstr, Idx idx) | 802 | re_string_elem_size_at (const re_string_t *pstr, Idx idx) |
867 | { | 803 | { |
868 | # ifdef _LIBC | 804 | #ifdef _LIBC |
869 | const unsigned char *p, *extra; | 805 | const unsigned char *p, *extra; |
870 | const int32_t *table, *indirect; | 806 | const int32_t *table, *indirect; |
871 | # include <locale/weight.h> | ||
872 | uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); | 807 | uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); |
873 | 808 | ||
874 | if (nrules != 0) | 809 | if (nrules != 0) |
@@ -879,31 +814,22 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx) | |||
879 | indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, | 814 | indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, |
880 | _NL_COLLATE_INDIRECTMB); | 815 | _NL_COLLATE_INDIRECTMB); |
881 | p = pstr->mbs + idx; | 816 | p = pstr->mbs + idx; |
882 | findidx (&p, pstr->len - idx); | 817 | findidx (table, indirect, extra, &p, pstr->len - idx); |
883 | return p - pstr->mbs - idx; | 818 | return p - pstr->mbs - idx; |
884 | } | 819 | } |
885 | else | 820 | #endif /* _LIBC */ |
886 | # endif /* _LIBC */ | 821 | |
887 | return 1; | 822 | return 1; |
888 | } | 823 | } |
889 | # endif | ||
890 | #endif /* RE_ENABLE_I18N */ | ||
891 | 824 | ||
892 | #ifndef __GNUC_PREREQ | 825 | #ifdef _LIBC |
893 | # if defined __GNUC__ && defined __GNUC_MINOR__ | 826 | # if __GNUC__ >= 7 |
894 | # define __GNUC_PREREQ(maj, min) \ | 827 | # define FALLTHROUGH __attribute__ ((__fallthrough__)) |
895 | ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) | ||
896 | # else | 828 | # else |
897 | # define __GNUC_PREREQ(maj, min) 0 | 829 | # define FALLTHROUGH ((void) 0) |
898 | # endif | 830 | # 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 | 831 | #else |
906 | # define __attribute_warn_unused_result__ /* empty */ | 832 | # include "attribute.h" |
907 | #endif | 833 | #endif |
908 | 834 | ||
909 | #endif /* _REGEX_INTERNAL_H */ | 835 | #endif /* _REGEX_INTERNAL_H */ |