summaryrefslogtreecommitdiffstats
path: root/gl/m4/regex.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/regex.m4')
-rw-r--r--gl/m4/regex.m4157
1 files changed, 100 insertions, 57 deletions
diff --git a/gl/m4/regex.m4 b/gl/m4/regex.m4
index 95784e4b..0945c11a 100644
--- a/gl/m4/regex.m4
+++ b/gl/m4/regex.m4
@@ -1,7 +1,6 @@
1# serial 56 1# serial 64
2 2
3# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 3# Copyright (C) 1996-2001, 2003-2013 Free Software Foundation, Inc.
4# 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5# 4#
6# This file is free software; the Free Software Foundation 5# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it, 6# gives unlimited permission to copy and/or distribute it,
@@ -14,8 +13,6 @@ AC_PREREQ([2.50])
14 13
15AC_DEFUN([gl_REGEX], 14AC_DEFUN([gl_REGEX],
16[ 15[
17 AC_CHECK_HEADERS_ONCE([locale.h])
18
19 AC_ARG_WITH([included-regex], 16 AC_ARG_WITH([included-regex],
20 [AS_HELP_STRING([--without-included-regex], 17 [AS_HELP_STRING([--without-included-regex],
21 [don't compile regex; this is the default on systems 18 [don't compile regex; this is the default on systems
@@ -30,31 +27,41 @@ AC_DEFUN([gl_REGEX],
30 # following run test, then default to *not* using the included regex.c. 27 # following run test, then default to *not* using the included regex.c.
31 # If cross compiling, assume the test would fail and use the included 28 # If cross compiling, assume the test would fail and use the included
32 # regex.c. 29 # regex.c.
30 AC_CHECK_DECLS_ONCE([alarm])
33 AC_CACHE_CHECK([for working re_compile_pattern], 31 AC_CACHE_CHECK([for working re_compile_pattern],
34 [gl_cv_func_re_compile_pattern_working], 32 [gl_cv_func_re_compile_pattern_working],
35 [AC_RUN_IFELSE( 33 [AC_RUN_IFELSE(
36 [AC_LANG_PROGRAM( 34 [AC_LANG_PROGRAM(
37 [AC_INCLUDES_DEFAULT[ 35 [[#include <regex.h>
38 #if HAVE_LOCALE_H 36
39 #include <locale.h> 37 #include <locale.h>
40 #endif 38 #include <limits.h>
41 #include <limits.h> 39 #include <string.h>
42 #include <regex.h> 40 #if HAVE_DECL_ALARM
43 ]], 41 # include <unistd.h>
44 [[static struct re_pattern_buffer regex; 42 # include <signal.h>
43 #endif
44 ]],
45 [[int result = 0;
46 static struct re_pattern_buffer regex;
45 unsigned char folded_chars[UCHAR_MAX + 1]; 47 unsigned char folded_chars[UCHAR_MAX + 1];
46 int i; 48 int i;
47 const char *s; 49 const char *s;
48 struct re_registers regs; 50 struct re_registers regs;
49 51
50 #if HAVE_LOCALE_H 52#if HAVE_DECL_ALARM
51 /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html 53 /* Some builds of glibc go into an infinite loop on this test. */
52 This test needs valgrind to catch the bug on Debian 54 signal (SIGALRM, SIG_DFL);
53 GNU/Linux 3.1 x86, but it might catch the bug better 55 alarm (2);
54 on other platforms and it shouldn't hurt to try the 56#endif
55 test here. */ 57 if (setlocale (LC_ALL, "en_US.UTF-8"))
56 if (setlocale (LC_ALL, "en_US.UTF-8")) 58 {
57 { 59 {
60 /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html
61 This test needs valgrind to catch the bug on Debian
62 GNU/Linux 3.1 x86, but it might catch the bug better
63 on other platforms and it shouldn't hurt to try the
64 test here. */
58 static char const pat[] = "insert into"; 65 static char const pat[] = "insert into";
59 static char const data[] = 66 static char const data[] =
60 "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK"; 67 "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK";
@@ -63,26 +70,57 @@ AC_DEFUN([gl_REGEX],
63 memset (&regex, 0, sizeof regex); 70 memset (&regex, 0, sizeof regex);
64 s = re_compile_pattern (pat, sizeof pat - 1, &regex); 71 s = re_compile_pattern (pat, sizeof pat - 1, &regex);
65 if (s) 72 if (s)
66 return 1; 73 result |= 1;
67 if (re_search (&regex, data, sizeof data - 1, 74 else if (re_search (&regex, data, sizeof data - 1,
68 0, sizeof data - 1, &regs) 75 0, sizeof data - 1, &regs)
69 != -1) 76 != -1)
70 return 1; 77 result |= 1;
71 if (! setlocale (LC_ALL, "C"))
72 return 1;
73 } 78 }
74 #endif 79
80 {
81 /* This test is from glibc bug 15078.
82 The test case is from Andreas Schwab in
83 <http://www.sourceware.org/ml/libc-alpha/2013-01/msg00967.html>.
84 */
85 static char const pat[] = "[^x]x";
86 static char const data[] =
87 /* <U1000><U103B><U103D><U1014><U103A><U102F><U1015><U103A> */
88 "\xe1\x80\x80"
89 "\xe1\x80\xbb"
90 "\xe1\x80\xbd"
91 "\xe1\x80\x94"
92 "\xe1\x80\xba"
93 "\xe1\x80\xaf"
94 "\xe1\x80\x95"
95 "\xe1\x80\xba"
96 "x";
97 re_set_syntax (0);
98 memset (&regex, 0, sizeof regex);
99 s = re_compile_pattern (pat, sizeof pat - 1, &regex);
100 if (s)
101 result |= 1;
102 else
103 {
104 i = re_search (&regex, data, sizeof data - 1,
105 0, sizeof data - 1, 0);
106 if (i != 0 && i != 21)
107 result |= 1;
108 }
109 }
110
111 if (! setlocale (LC_ALL, "C"))
112 return 1;
113 }
75 114
76 /* This test is from glibc bug 3957, reported by Andrew Mackey. */ 115 /* This test is from glibc bug 3957, reported by Andrew Mackey. */
77 re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE); 116 re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE);
78 memset (&regex, 0, sizeof regex); 117 memset (&regex, 0, sizeof regex);
79 s = re_compile_pattern ("a[^x]b", 6, &regex); 118 s = re_compile_pattern ("a[^x]b", 6, &regex);
80 if (s) 119 if (s)
81 return 1; 120 result |= 2;
82
83 /* This should fail, but succeeds for glibc-2.5. */ 121 /* This should fail, but succeeds for glibc-2.5. */
84 if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1) 122 else if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1)
85 return 1; 123 result |= 2;
86 124
87 /* This regular expression is from Spencer ere test number 75 125 /* This regular expression is from Spencer ere test number 75
88 in grep-2.3. */ 126 in grep-2.3. */
@@ -94,7 +132,7 @@ AC_DEFUN([gl_REGEX],
94 s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex); 132 s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
95 /* This should fail with _Invalid character class name_ error. */ 133 /* This should fail with _Invalid character class name_ error. */
96 if (!s) 134 if (!s)
97 return 1; 135 result |= 4;
98 136
99 /* Ensure that [b-a] is diagnosed as invalid, when 137 /* Ensure that [b-a] is diagnosed as invalid, when
100 using RE_NO_EMPTY_RANGES. */ 138 using RE_NO_EMPTY_RANGES. */
@@ -102,34 +140,31 @@ AC_DEFUN([gl_REGEX],
102 memset (&regex, 0, sizeof regex); 140 memset (&regex, 0, sizeof regex);
103 s = re_compile_pattern ("a[b-a]", 6, &regex); 141 s = re_compile_pattern ("a[b-a]", 6, &regex);
104 if (s == 0) 142 if (s == 0)
105 return 1; 143 result |= 8;
106 144
107 /* This should succeed, but does not for glibc-2.1.3. */ 145 /* This should succeed, but does not for glibc-2.1.3. */
108 memset (&regex, 0, sizeof regex); 146 memset (&regex, 0, sizeof regex);
109 s = re_compile_pattern ("{1", 2, &regex); 147 s = re_compile_pattern ("{1", 2, &regex);
110
111 if (s) 148 if (s)
112 return 1; 149 result |= 8;
113 150
114 /* The following example is derived from a problem report 151 /* The following example is derived from a problem report
115 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */ 152 against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
116 memset (&regex, 0, sizeof regex); 153 memset (&regex, 0, sizeof regex);
117 s = re_compile_pattern ("[an\371]*n", 7, &regex); 154 s = re_compile_pattern ("[an\371]*n", 7, &regex);
118 if (s) 155 if (s)
119 return 1; 156 result |= 8;
120
121 /* This should match, but does not for glibc-2.2.1. */ 157 /* This should match, but does not for glibc-2.2.1. */
122 if (re_match (&regex, "an", 2, 0, &regs) != 2) 158 else if (re_match (&regex, "an", 2, 0, &regs) != 2)
123 return 1; 159 result |= 8;
124 160
125 memset (&regex, 0, sizeof regex); 161 memset (&regex, 0, sizeof regex);
126 s = re_compile_pattern ("x", 1, &regex); 162 s = re_compile_pattern ("x", 1, &regex);
127 if (s) 163 if (s)
128 return 1; 164 result |= 8;
129
130 /* glibc-2.2.93 does not work with a negative RANGE argument. */ 165 /* glibc-2.2.93 does not work with a negative RANGE argument. */
131 if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1) 166 else if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
132 return 1; 167 result |= 8;
133 168
134 /* The version of regex.c in older versions of gnulib 169 /* The version of regex.c in older versions of gnulib
135 ignored RE_ICASE. Detect that problem too. */ 170 ignored RE_ICASE. Detect that problem too. */
@@ -137,10 +172,9 @@ AC_DEFUN([gl_REGEX],
137 memset (&regex, 0, sizeof regex); 172 memset (&regex, 0, sizeof regex);
138 s = re_compile_pattern ("x", 1, &regex); 173 s = re_compile_pattern ("x", 1, &regex);
139 if (s) 174 if (s)
140 return 1; 175 result |= 16;
141 176 else if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
142 if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0) 177 result |= 16;
143 return 1;
144 178
145 /* Catch a bug reported by Vin Shelton in 179 /* Catch a bug reported by Vin Shelton in
146 http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html 180 http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html
@@ -151,21 +185,27 @@ AC_DEFUN([gl_REGEX],
151 memset (&regex, 0, sizeof regex); 185 memset (&regex, 0, sizeof regex);
152 s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex); 186 s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex);
153 if (s) 187 if (s)
154 return 1; 188 result |= 32;
155 189
156 /* REG_STARTEND was added to glibc on 2004-01-15. 190 /* REG_STARTEND was added to glibc on 2004-01-15.
157 Reject older versions. */ 191 Reject older versions. */
158 if (! REG_STARTEND) 192 if (! REG_STARTEND)
159 return 1; 193 result |= 64;
160 194
161 /* Reject hosts whose regoff_t values are too narrow. 195#if 0
162 These include glibc 2.3.5 on hosts with 64-bit ptrdiff_t 196 /* It would be nice to reject hosts whose regoff_t values are too
163 and 32-bit int. */ 197 narrow (including glibc on hosts with 64-bit ptrdiff_t and
198 32-bit int), but we should wait until glibc implements this
199 feature. Otherwise, support for equivalence classes and
200 multibyte collation symbols would always be broken except
201 when compiling --without-included-regex. */
164 if (sizeof (regoff_t) < sizeof (ptrdiff_t) 202 if (sizeof (regoff_t) < sizeof (ptrdiff_t)
165 || sizeof (regoff_t) < sizeof (ssize_t)) 203 || sizeof (regoff_t) < sizeof (ssize_t))
166 return 1; 204 result |= 64;
205#endif
167 206
168 return 0;]])], 207 return result;
208 ]])],
169 [gl_cv_func_re_compile_pattern_working=yes], 209 [gl_cv_func_re_compile_pattern_working=yes],
170 [gl_cv_func_re_compile_pattern_working=no], 210 [gl_cv_func_re_compile_pattern_working=no],
171 dnl When crosscompiling, assume it is not working. 211 dnl When crosscompiling, assume it is not working.
@@ -180,6 +220,9 @@ AC_DEFUN([gl_REGEX],
180 esac 220 esac
181 221
182 if test $ac_use_included_regex = yes; then 222 if test $ac_use_included_regex = yes; then
223 AC_DEFINE([_REGEX_INCLUDE_LIMITS_H], [1],
224 [Define if you want <regex.h> to include <limits.h>, so that it
225 consistently overrides <limits.h>'s RE_DUP_MAX.])
183 AC_DEFINE([_REGEX_LARGE_OFFSETS], [1], 226 AC_DEFINE([_REGEX_LARGE_OFFSETS], [1],
184 [Define if you want regoff_t to be at least as wide POSIX requires.]) 227 [Define if you want regoff_t to be at least as wide POSIX requires.])
185 AC_DEFINE([re_syntax_options], [rpl_re_syntax_options], 228 AC_DEFINE([re_syntax_options], [rpl_re_syntax_options],
@@ -212,8 +255,6 @@ AC_DEFUN([gl_REGEX],
212 [Define to rpl_regerror if the replacement should be used.]) 255 [Define to rpl_regerror if the replacement should be used.])
213 AC_DEFINE([regfree], [rpl_regfree], 256 AC_DEFINE([regfree], [rpl_regfree],
214 [Define to rpl_regfree if the replacement should be used.]) 257 [Define to rpl_regfree if the replacement should be used.])
215 AC_LIBOBJ([regex])
216 gl_PREREQ_REGEX
217 fi 258 fi
218]) 259])
219 260
@@ -224,7 +265,9 @@ AC_DEFUN([gl_PREREQ_REGEX],
224 AC_REQUIRE([AC_C_INLINE]) 265 AC_REQUIRE([AC_C_INLINE])
225 AC_REQUIRE([AC_C_RESTRICT]) 266 AC_REQUIRE([AC_C_RESTRICT])
226 AC_REQUIRE([AC_TYPE_MBSTATE_T]) 267 AC_REQUIRE([AC_TYPE_MBSTATE_T])
268 AC_REQUIRE([gl_EEMALLOC])
269 AC_REQUIRE([gl_GLIBC21])
227 AC_CHECK_HEADERS([libintl.h]) 270 AC_CHECK_HEADERS([libintl.h])
228 AC_CHECK_FUNCS_ONCE([isblank iswctype wcscoll]) 271 AC_CHECK_FUNCS_ONCE([isblank iswctype wcscoll])
229 AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>]) 272 AC_CHECK_DECLS([isblank], [], [], [[#include <ctype.h>]])
230]) 273])