summaryrefslogtreecommitdiffstats
path: root/gl/regex_internal.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/regex_internal.h')
-rw-r--r--gl/regex_internal.h263
1 files changed, 100 insertions, 163 deletions
diff --git a/gl/regex_internal.h b/gl/regex_internal.h
index a2b8f16..1245e78 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-2021 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,10 @@
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 119#if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE) || _LIBC
114# define RE_ENABLE_I18N 120# define RE_ENABLE_I18N
115#endif 121#endif
116 122
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. */ 123/* Number of ASCII characters. */
124#define ASCII_CHARS 0x80 124#define ASCII_CHARS 0x80
125 125
@@ -135,45 +135,55 @@
135/* Rename to standard API for using out of glibc. */ 135/* Rename to standard API for using out of glibc. */
136#ifndef _LIBC 136#ifndef _LIBC
137# undef __wctype 137# undef __wctype
138# undef __iswalnum
138# undef __iswctype 139# undef __iswctype
140# undef __towlower
141# undef __towupper
139# define __wctype wctype 142# define __wctype wctype
143# define __iswalnum iswalnum
140# define __iswctype iswctype 144# define __iswctype iswctype
145# define __towlower towlower
146# define __towupper towupper
141# define __btowc btowc 147# define __btowc btowc
142# define __mbrtowc mbrtowc 148# define __mbrtowc mbrtowc
143# define __wcrtomb wcrtomb 149# define __wcrtomb wcrtomb
144# define __regfree regfree 150# define __regfree regfree
145# define attribute_hidden
146#endif /* not _LIBC */ 151#endif /* not _LIBC */
147 152
148#if __GNUC__ < 3 + (__GNUC_MINOR__ < 1) 153#ifndef SSIZE_MAX
149# define __attribute__(arg) 154# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
150#endif
151
152typedef __re_idx_t Idx;
153#ifdef _REGEX_LARGE_OFFSETS
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'. */
182typedef 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;
184typedef unsigned long int bitset_word_t; 194typedef 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)
@@ -365,7 +347,7 @@ typedef struct
365 Idx idx; /* for BACK_REF */ 347 Idx idx; /* for BACK_REF */
366 re_context_type ctx_type; /* for ANCHOR */ 348 re_context_type ctx_type; /* for ANCHOR */
367 } opr; 349 } opr;
368#if __GNUC__ >= 2 && !defined __STRICT_ANSI__ 350#if (__GNUC__ >= 2 || defined __clang__) && !defined __STRICT_ANSI__
369 re_token_type_t type : 8; 351 re_token_type_t type : 8;
370#else 352#else
371 re_token_type_t type; 353 re_token_type_t type;
@@ -446,24 +428,9 @@ struct re_dfa_t;
446typedef struct re_dfa_t re_dfa_t; 428typedef struct re_dfa_t re_dfa_t;
447 429
448#ifndef _LIBC 430#ifndef _LIBC
449# define internal_function 431# define IS_IN(libc) false
450#endif 432#endif
451 433
452#ifndef NOT_IN_libc
453static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
454 Idx new_buf_len)
455 internal_function;
456# ifdef RE_ENABLE_I18N
457static void build_wcs_buffer (re_string_t *pstr) internal_function;
458static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
459 internal_function;
460# endif /* RE_ENABLE_I18N */
461static void build_upper_buffer (re_string_t *pstr) internal_function;
462static void re_string_translate_buffer (re_string_t *pstr) internal_function;
463static 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) \ 434#define re_string_peek_byte(pstr, offset) \
468 ((pstr)->mbs[(pstr)->cur_idx + offset]) 435 ((pstr)->mbs[(pstr)->cur_idx + offset])
469#define re_string_fetch_byte(pstr) \ 436#define re_string_fetch_byte(pstr) \
@@ -481,25 +448,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)) 448#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
482#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) 449#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
483 450
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 451#ifdef _LIBC
504# define MALLOC_0_IS_NONNULL 1 452# define MALLOC_0_IS_NONNULL 1
505#elif !defined MALLOC_0_IS_NONNULL 453#elif !defined MALLOC_0_IS_NONNULL
@@ -556,7 +504,7 @@ typedef struct bin_tree_storage_t bin_tree_storage_t;
556 504
557#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_') 505#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
558#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR) 506#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
559#define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_') 507#define IS_WIDE_WORD_CHAR(ch) (__iswalnum (ch) || (ch) == L'_')
560#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR) 508#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
561 509
562#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \ 510#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
@@ -636,20 +584,15 @@ struct re_backref_cache_entry
636 Idx str_idx; 584 Idx str_idx;
637 Idx subexp_from; 585 Idx subexp_from;
638 Idx subexp_to; 586 Idx subexp_to;
587 bitset_word_t eps_reachable_subexps_map;
639 char more; 588 char more;
640 char unused;
641 unsigned short int eps_reachable_subexps_map;
642}; 589};
643 590
644typedef struct 591typedef struct
645{ 592{
646 /* The string object corresponding to the input string. */ 593 /* The string object corresponding to the input string. */
647 re_string_t input; 594 re_string_t input;
648#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
649 const re_dfa_t *const dfa; 595 const re_dfa_t *const dfa;
650#else
651 const re_dfa_t *dfa;
652#endif
653 /* EFLAGS of the argument of regexec. */ 596 /* EFLAGS of the argument of regexec. */
654 int eflags; 597 int eflags;
655 /* Where the matching ends. */ 598 /* Where the matching ends. */
@@ -769,31 +712,31 @@ typedef struct
769 712
770/* Functions for bitset_t operation. */ 713/* Functions for bitset_t operation. */
771 714
772static void 715static inline void
773bitset_set (bitset_t set, Idx i) 716bitset_set (bitset_t set, Idx i)
774{ 717{
775 set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS; 718 set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
776} 719}
777 720
778static void 721static inline void
779bitset_clear (bitset_t set, Idx i) 722bitset_clear (bitset_t set, Idx i)
780{ 723{
781 set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS); 724 set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
782} 725}
783 726
784static bool 727static inline bool
785bitset_contain (const bitset_t set, Idx i) 728bitset_contain (const bitset_t set, Idx i)
786{ 729{
787 return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; 730 return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
788} 731}
789 732
790static void 733static inline void
791bitset_empty (bitset_t set) 734bitset_empty (bitset_t set)
792{ 735{
793 memset (set, '\0', sizeof (bitset_t)); 736 memset (set, '\0', sizeof (bitset_t));
794} 737}
795 738
796static void 739static inline void
797bitset_set_all (bitset_t set) 740bitset_set_all (bitset_t set)
798{ 741{
799 memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS)); 742 memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
@@ -802,13 +745,13 @@ bitset_set_all (bitset_t set)
802 ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; 745 ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
803} 746}
804 747
805static void 748static inline void
806bitset_copy (bitset_t dest, const bitset_t src) 749bitset_copy (bitset_t dest, const bitset_t src)
807{ 750{
808 memcpy (dest, src, sizeof (bitset_t)); 751 memcpy (dest, src, sizeof (bitset_t));
809} 752}
810 753
811static void __attribute__ ((unused)) 754static inline void
812bitset_not (bitset_t set) 755bitset_not (bitset_t set)
813{ 756{
814 int bitset_i; 757 int bitset_i;
@@ -820,7 +763,7 @@ bitset_not (bitset_t set)
820 & ~set[BITSET_WORDS - 1]); 763 & ~set[BITSET_WORDS - 1]);
821} 764}
822 765
823static void __attribute__ ((unused)) 766static inline void
824bitset_merge (bitset_t dest, const bitset_t src) 767bitset_merge (bitset_t dest, const bitset_t src)
825{ 768{
826 int bitset_i; 769 int bitset_i;
@@ -828,7 +771,7 @@ bitset_merge (bitset_t dest, const bitset_t src)
828 dest[bitset_i] |= src[bitset_i]; 771 dest[bitset_i] |= src[bitset_i];
829} 772}
830 773
831static void __attribute__ ((unused)) 774static inline void
832bitset_mask (bitset_t dest, const bitset_t src) 775bitset_mask (bitset_t dest, const bitset_t src)
833{ 776{
834 int bitset_i; 777 int bitset_i;
@@ -839,7 +782,7 @@ bitset_mask (bitset_t dest, const bitset_t src)
839#ifdef RE_ENABLE_I18N 782#ifdef RE_ENABLE_I18N
840/* Functions for re_string. */ 783/* Functions for re_string. */
841static int 784static int
842internal_function __attribute__ ((pure, unused)) 785__attribute__ ((pure, unused))
843re_string_char_size_at (const re_string_t *pstr, Idx idx) 786re_string_char_size_at (const re_string_t *pstr, Idx idx)
844{ 787{
845 int byte_idx; 788 int byte_idx;
@@ -852,7 +795,7 @@ re_string_char_size_at (const re_string_t *pstr, Idx idx)
852} 795}
853 796
854static wint_t 797static wint_t
855internal_function __attribute__ ((pure, unused)) 798__attribute__ ((pure, unused))
856re_string_wchar_at (const re_string_t *pstr, Idx idx) 799re_string_wchar_at (const re_string_t *pstr, Idx idx)
857{ 800{
858 if (pstr->mb_cur_max == 1) 801 if (pstr->mb_cur_max == 1)
@@ -860,15 +803,17 @@ re_string_wchar_at (const re_string_t *pstr, Idx idx)
860 return (wint_t) pstr->wcs[idx]; 803 return (wint_t) pstr->wcs[idx];
861} 804}
862 805
863# ifndef NOT_IN_libc 806# ifdef _LIBC
807# include <locale/weight.h>
808# endif
809
864static int 810static int
865internal_function __attribute__ ((pure, unused)) 811__attribute__ ((pure, unused))
866re_string_elem_size_at (const re_string_t *pstr, Idx idx) 812re_string_elem_size_at (const re_string_t *pstr, Idx idx)
867{ 813{
868# ifdef _LIBC 814# ifdef _LIBC
869 const unsigned char *p, *extra; 815 const unsigned char *p, *extra;
870 const int32_t *table, *indirect; 816 const int32_t *table, *indirect;
871# include <locale/weight.h>
872 uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); 817 uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
873 818
874 if (nrules != 0) 819 if (nrules != 0)
@@ -879,31 +824,23 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx)
879 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, 824 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
880 _NL_COLLATE_INDIRECTMB); 825 _NL_COLLATE_INDIRECTMB);
881 p = pstr->mbs + idx; 826 p = pstr->mbs + idx;
882 findidx (&p, pstr->len - idx); 827 findidx (table, indirect, extra, &p, pstr->len - idx);
883 return p - pstr->mbs - idx; 828 return p - pstr->mbs - idx;
884 } 829 }
885 else 830 else
886# endif /* _LIBC */ 831# endif /* _LIBC */
887 return 1; 832 return 1;
888} 833}
889# endif
890#endif /* RE_ENABLE_I18N */ 834#endif /* RE_ENABLE_I18N */
891 835
892#ifndef __GNUC_PREREQ 836#ifdef _LIBC
893# if defined __GNUC__ && defined __GNUC_MINOR__ 837# if __GNUC__ >= 7
894# define __GNUC_PREREQ(maj, min) \ 838# define FALLTHROUGH __attribute__ ((__fallthrough__))
895 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
896# else 839# else
897# define __GNUC_PREREQ(maj, min) 0 840# define FALLTHROUGH ((void) 0)
898# endif 841# 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 842#else
906# define __attribute_warn_unused_result__ /* empty */ 843# include "attribute.h"
907#endif 844#endif
908 845
909#endif /* _REGEX_INTERNAL_H */ 846#endif /* _REGEX_INTERNAL_H */