Skip to content

Commit ec48bfc

Browse files
authored
pcre2_config: address inconsistency with the linksize reported in non 8-bit libraries (#775)
pcre2_config: add PCRE2_CONFIG_EFFECTIVE_LINKSIZE PCRE2_CONFIG_LINKSIZE can be used to determine the linksize that the library was configured to use, but the actual size (and therefore the maximum size of patterns that can be processed) is not visible. Add PCRE2_CONFIG_EFFECTIVE_LINKSIZE to gather that value and use it in `pcre2test` for reporting `linksize`; move the logic to derive one from the other out of the API documentation and test scripts to improve maintainability and while at it enable test8 in Windows for all link sizes.
1 parent 859d833 commit ec48bfc

File tree

8 files changed

+150
-105
lines changed

8 files changed

+150
-105
lines changed

RunTest

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,6 @@ while [ $# -gt 0 ] ; do
337337
shift
338338
done
339339

340-
# Find which optional facilities are available.
341-
342-
$sim $pcre2test -C linksize >/dev/null
343-
link_size=$?
344-
if [ $link_size -lt 2 ] ; then
345-
echo "RunTest: Failed to find internal link size"
346-
exit 1
347-
fi
348-
if [ $link_size -gt 4 ] ; then
349-
echo "RunTest: Failed to find internal link size"
350-
exit 1
351-
fi
352-
353340
# If it is possible to set the system stack size and -bigstack was given,
354341
# set up a large stack.
355342

@@ -725,12 +712,8 @@ for bmode in "$test8" "$test16" "$test32"; do
725712

726713
if [ $do8 = yes ] ; then
727714
echo $title8
728-
bits_link_size=$link_size
729-
if [ $bits = "16" -a $link_size = "3" ] ; then
730-
bits_link_size=4
731-
elif [ $bits = "32" ] ; then
732-
bits_link_size=4
733-
fi
715+
$sim $pcre2test -$bits -C linksize >/dev/null
716+
bits_link_size=$?
734717
if [ $utf -eq 0 ] ; then
735718
echo " Skipped because UTF-$bits support is not available"
736719
else

RunTest.bat

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
@echo off
22
@rem
33
@rem MS Windows batch file to run pcre2test on testfiles with the correct
4-
@rem options. This file must use CRLF linebreaks to function properly,
5-
@rem and requires both pcre2test and pcre2grep.
4+
@rem options. This file must use CRLF linebreaks to function properly.
65
@rem
76
@rem ------------------------ HISTORY ----------------------------------
87
@rem This file was originally contributed to PCRE1 by Ralf Junker, and touched
@@ -14,7 +13,7 @@
1413
@rem
1514
@rem Sheri Pierce added logic to skip feature dependent tests
1615
@rem tests 4 5 7 10 12 14 19 22 25 and 26 require Unicode support
17-
@rem 8 requires Unicode and link size 2
16+
@rem 8 requires Unicode
1817
@rem 16 requires absence of jit support
1918
@rem 17 requires presence of jit support
2019
@rem Sheri P also added override tests for study and jit testing
@@ -57,8 +56,6 @@ call :conferror
5756
exit /b 1
5857
)
5958

60-
%pcre2test% -C linksize >NUL
61-
set link_size=%ERRORLEVEL%
6259
%pcre2test% -C pcre2-8 >NUL
6360
set support8=%ERRORLEVEL%
6461
%pcre2test% -C pcre2-16 >NUL
@@ -269,9 +266,8 @@ if [%3] == [] (
269266
)
270267

271268
if %1 == 8 (
272-
set bits_link_size=%link_size%
273-
if %bits% EQU 16 if %link_size% EQU 3 set bits_link_size=4
274-
if %bits% EQU 32 set bits_link_size=4
269+
%pcre2test% -%bits% -C linksize >NUL
270+
set bits_link_size=!ERRORLEVEL!
275271
set outnum=%1-%bits%-!bits_link_size!
276272
) else if %1 == 11 (
277273
set outnum=%1-%bits%
@@ -379,10 +375,6 @@ if %unicode% EQU 0 (
379375
goto :eof
380376

381377
:do8
382-
if NOT %link_size% EQU 2 (
383-
echo Test 8 Skipped because link size is not 2.
384-
goto :eof
385-
)
386378
if %unicode% EQU 0 (
387379
echo Test 8 Skipped due to absence of Unicode support.
388380
goto :eof

doc/index.html.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ in the library.
129129
<td>Free a compile context</td></tr>
130130

131131
<tr><td><a href="pcre2_config.html">pcre2_config</a></td>
132-
<td>Show build-time configuration options</td></tr>
132+
<td>Show build-time related configuration options</td></tr>
133133

134134
<tr><td><a href="pcre2_convert_context_copy.html">pcre2_convert_context_copy</a></td>
135135
<td>Copy a convert context</td></tr>

doc/pcre2_config.3

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,37 @@ PCRE2_CONFIG_UNICODE_VERSION, and PCRE2_CONFIG_VERSION it must point to a
2929
buffer that is large enough to hold the string. For all other codes it must
3030
point to a uint32_t integer variable. The available codes are:
3131
.sp
32-
PCRE2_CONFIG_BSR Indicates what \eR matches by default:
33-
PCRE2_BSR_UNICODE
34-
PCRE2_BSR_ANYCRLF
35-
PCRE2_CONFIG_COMPILED_WIDTHS Which of 8/16/32 support was compiled
36-
PCRE2_CONFIG_DEPTHLIMIT Default backtracking depth limit
37-
PCRE2_CONFIG_HEAPLIMIT Default heap memory limit
32+
PCRE2_CONFIG_BSR Indicates what \eR matches by default:
33+
PCRE2_BSR_UNICODE
34+
PCRE2_BSR_ANYCRLF
35+
PCRE2_CONFIG_COMPILED_WIDTHS Which of 8/16/32 support was compiled
36+
PCRE2_CONFIG_DEPTHLIMIT Default backtracking depth limit
37+
PCRE2_CONFIG_EFFECTIVE_LINKSIZE How many bytes are used for link size
38+
PCRE2_CONFIG_HEAPLIMIT Default heap memory limit
3839
.\" JOIN
39-
PCRE2_CONFIG_JIT Availability of just-in-time compiler
40-
support (1=yes 0=no)
40+
PCRE2_CONFIG_JIT Availability of just-in-time compiler
41+
support (1=yes 0=no)
4142
.\" JOIN
42-
PCRE2_CONFIG_JITTARGET Information (a string) about the target
43-
architecture for the JIT compiler
44-
PCRE2_CONFIG_LINKSIZE Configured internal link size (2, 3, 4)
45-
PCRE2_CONFIG_MATCHLIMIT Default internal resource limit
43+
PCRE2_CONFIG_JITTARGET Information (a string) about the target
44+
architecture for the JIT compiler
45+
PCRE2_CONFIG_LINKSIZE Configured internal link size (2, 3, 4)
46+
PCRE2_CONFIG_MATCHLIMIT Default internal resource limit
4647
PCRE2_CONFIG_NEVER_BACKSLASH_C Whether or not \eC is disabled
47-
PCRE2_CONFIG_NEWLINE Code for the default newline sequence:
48-
PCRE2_NEWLINE_CR
49-
PCRE2_NEWLINE_LF
50-
PCRE2_NEWLINE_CRLF
51-
PCRE2_NEWLINE_ANY
52-
PCRE2_NEWLINE_ANYCRLF
53-
PCRE2_NEWLINE_NUL
54-
PCRE2_CONFIG_PARENSLIMIT Default parentheses nesting limit
55-
PCRE2_CONFIG_RECURSIONLIMIT Obsolete: use PCRE2_CONFIG_DEPTHLIMIT
56-
PCRE2_CONFIG_STACKRECURSE Obsolete: always returns 0
48+
PCRE2_CONFIG_NEWLINE Code for the default newline sequence:
49+
PCRE2_NEWLINE_CR
50+
PCRE2_NEWLINE_LF
51+
PCRE2_NEWLINE_CRLF
52+
PCRE2_NEWLINE_ANY
53+
PCRE2_NEWLINE_ANYCRLF
54+
PCRE2_NEWLINE_NUL
55+
PCRE2_CONFIG_PARENSLIMIT Default parentheses nesting limit
56+
PCRE2_CONFIG_RECURSIONLIMIT Obsolete: use PCRE2_CONFIG_DEPTHLIMIT
57+
PCRE2_CONFIG_STACKRECURSE Obsolete: always returns 0
5758
.\" JOIN
58-
PCRE2_CONFIG_UNICODE Availability of Unicode support (1=yes
59-
0=no)
60-
PCRE2_CONFIG_UNICODE_VERSION The Unicode version (a string)
61-
PCRE2_CONFIG_VERSION The PCRE2 version (a string)
59+
PCRE2_CONFIG_UNICODE Availability of Unicode support
60+
(1=yes 0=no)
61+
PCRE2_CONFIG_UNICODE_VERSION The Unicode version (a string)
62+
PCRE2_CONFIG_VERSION The PCRE2 version (a string)
6263
.sp
6364
The function yields a non-negative value on success or the negative value
6465
PCRE2_ERROR_BADOPTION otherwise. This is also the result for the

doc/pcre2api.3

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ compiled patterns on disc or elsewhere, and reloading them later.
497497
.P
498498
Finally, there are functions for finding out information about a compiled
499499
pattern (\fBpcre2_pattern_info()\fP) and about the configuration with which
500-
PCRE2 was built (\fBpcre2_config()\fP).
500+
PCRE2 was built (\fBpcre2_config()\fP) and that it is using.
501501
.P
502502
Functions with names ending with \fB_free()\fP are used for freeing memory
503503
blocks of various sorts. In all cases, if one of these functions is called with
@@ -1265,6 +1265,13 @@ The output is a uint32_t integer that gives the default limit for the depth of
12651265
nested backtracking in \fBpcre2_match()\fP or the depth of nested recursions,
12661266
lookarounds, and atomic groups in \fBpcre2_dfa_match()\fP. Further details are
12671267
given with \fBpcre2_set_depth_limit()\fP above.
1268+
.sp
1269+
PCRE2_CONFIG_EFFECTIVE_LINKSIZE
1270+
.sp
1271+
The output is a uint32_t integer that contains the number of bytes the library
1272+
uses for internal linkage in compiled regular expressions. Its value is derived
1273+
from the value that was provided at build time and that is described below by
1274+
PCRE2_CONFIG_LINKSIZE.
12681275
.sp
12691276
PCRE2_CONFIG_HEAPLIMIT
12701277
.sp
@@ -1300,13 +1307,14 @@ for the terminating zero.
13001307
.sp
13011308
PCRE2_CONFIG_LINKSIZE
13021309
.sp
1303-
The output is a uint32_t integer that contains the number of bytes used for
1304-
internal linkage in compiled regular expressions. When PCRE2 is configured, the
1305-
value can be set to 2, 3, or 4, with the default being 2. This is the value
1306-
that is returned by \fBpcre2_config()\fP. However, when the 16-bit library is
1307-
compiled, a value of 3 is rounded up to 4, and when the 32-bit library is
1308-
compiled, internal linkages always use 4 bytes, so the configured value is not
1309-
relevant.
1310+
The output is a uint32_t integer that contains the number of bytes the library
1311+
was instructed to use for internal linkage in compiled regular expressions.
1312+
When PCRE2 is configured, the value can be set to 2, 3, or 4, with the default
1313+
being 2 for most libraries.
1314+
.P
1315+
The actual number of bytes used depends on the size of the code units that the
1316+
library supports and can be higher. See PCRE2_CONFIG_EFFECTIVE_LINKSIZE above
1317+
for details.
13101318
.P
13111319
The default value of 2 for the 8-bit and 16-bit libraries is sufficient for all
13121320
but the most massive patterns, since it allows the size of the compiled pattern

src/pcre2.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ released, the numbers must not be changed. */
487487
#define PCRE2_CONFIG_NEVER_BACKSLASH_C 13
488488
#define PCRE2_CONFIG_COMPILED_WIDTHS 14
489489
#define PCRE2_CONFIG_TABLES_LENGTH 15
490+
#define PCRE2_CONFIG_EFFECTIVE_LINKSIZE 16
490491

491492
/* Optimization directives for pcre2_set_optimize().
492493
For binary compatibility, only add to this list; do not renumber. */

src/pcre2_config.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ pcre2_config(uint32_t what, void *where)
7272
{
7373
if (where == NULL) /* Requests a length */
7474
{
75-
switch(what)
75+
switch (what)
7676
{
7777
default:
7878
return PCRE2_ERROR_BADOPTION;
7979

8080
case PCRE2_CONFIG_BSR:
8181
case PCRE2_CONFIG_COMPILED_WIDTHS:
8282
case PCRE2_CONFIG_DEPTHLIMIT:
83+
case PCRE2_CONFIG_EFFECTIVE_LINKSIZE:
8384
case PCRE2_CONFIG_HEAPLIMIT:
8485
case PCRE2_CONFIG_JIT:
8586
case PCRE2_CONFIG_LINKSIZE:
@@ -117,13 +118,13 @@ switch (what)
117118
case PCRE2_CONFIG_COMPILED_WIDTHS:
118119
*((uint32_t *)where) = 0
119120
#ifdef SUPPORT_PCRE2_8
120-
+ 1
121+
+ (1 << 0)
121122
#endif
122123
#ifdef SUPPORT_PCRE2_16
123-
+ 2
124+
+ (1 << 1)
124125
#endif
125126
#ifdef SUPPORT_PCRE2_32
126-
+ 4
127+
+ (1 << 2)
127128
#endif
128129
;
129130
break;
@@ -132,6 +133,10 @@ switch (what)
132133
*((uint32_t *)where) = MATCH_LIMIT_DEPTH;
133134
break;
134135

136+
case PCRE2_CONFIG_EFFECTIVE_LINKSIZE:
137+
*((uint32_t *)where) = LINK_SIZE * sizeof(PCRE2_UCHAR);
138+
break;
139+
135140
case PCRE2_CONFIG_HEAPLIMIT:
136141
*((uint32_t *)where) = HEAP_LIMIT;
137142
break;
@@ -199,8 +204,7 @@ switch (what)
199204
#endif
200205
return (int)(1 + ((where == NULL)?
201206
strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
202-
}
203-
break;
207+
}
204208

205209
case PCRE2_CONFIG_UNICODE:
206210
#if defined SUPPORT_UNICODE
@@ -237,6 +241,7 @@ switch (what)
237241
return (int)(1 + ((where == NULL)?
238242
strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
239243
}
244+
240245
}
241246

242247
return 0;

0 commit comments

Comments
 (0)