Skip to content

Commit 3161a1f

Browse files
committed
pcre2test: keep track of internal API with sljit platform names
SLJIT platform names used to be 64 bytes wide, but had since grown. Add a new header to keep track of those internal API numbers and use that to size the needed buffers accurately. While at it, do the same for the standalone JIT test which used by default a more realistic power of 2 buffer size.
1 parent 3b91977 commit 3161a1f

File tree

6 files changed

+60
-8
lines changed

6 files changed

+60
-8
lines changed

doc/pcre2api.3

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,9 @@ documentation for more details.
12961296
.sp
12971297
PCRE2_CONFIG_JITTARGET
12981298
.sp
1299-
The \fIwhere\fP argument should point to a buffer that is at least 64 code
1300-
units long. (The exact length required can be found by calling
1299+
The \fIwhere\fP argument should point to a buffer that is at least
1300+
.\" DEFINE PCRE2_JITTARGET_BUFFSIZE_LIMIT
1301+
71 code units long. (The exact length required can be found by calling
13011302
\fBpcre2_config()\fP with \fBwhere\fP set to NULL.) The buffer is filled with a
13021303
string that contains the name of the architecture for which the JIT compiler is
13031304
configured, for example "x86 32bit (little endian + unaligned)". If JIT support

maint/LintMan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use vars qw /$opt_verbose/;
1414
my $file;
1515
my %defs;
1616

17-
foreach $file ("../src/config.h.generic")
17+
foreach $file ("../src/config.h.generic", "../src/pcre2_api_internal.h")
1818
{
1919
open (INCLUDE, $file) or die "Failed to open include $file\n";
2020

maint/UpdateAlways

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
# Detrail A Perl script that removes trailing spaces from files.
2121

22-
# LintMan A Perl script that lints man pages looking for inconsistencies.
22+
# LintMan A Perl script that lints man pages looking for inconsistencies
23+
# in numerical configuration or API values.
2324

2425
# doc/index.html.src
2526
# A file that is copied as index.html into the doc/html directory

src/pcre2_api_internal.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*************************************************
2+
* Perl-Compatible Regular Expressions *
3+
*************************************************/
4+
5+
/* PCRE2 is a library of functions to support regular expressions whose syntax
6+
and semantics are as close as possible to those of the Perl 5 language.
7+
8+
Written by Philip Hazel
9+
Original API code Copyright (c) 1997-2012 University of Cambridge
10+
New API code Copyright (c) 2016-2024 University of Cambridge
11+
12+
-----------------------------------------------------------------------------
13+
Redistribution and use in source and binary forms, with or without
14+
modification, are permitted provided that the following conditions are met:
15+
16+
* Redistributions of source code must retain the above copyright notice,
17+
this list of conditions and the following disclaimer.
18+
19+
* Redistributions in binary form must reproduce the above copyright
20+
notice, this list of conditions and the following disclaimer in the
21+
documentation and/or other materials provided with the distribution.
22+
23+
* Neither the name of the University of Cambridge nor the names of its
24+
contributors may be used to endorse or promote products derived from
25+
this software without specific prior written permission.
26+
27+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37+
POSSIBILITY OF SUCH DAMAGE.
38+
-----------------------------------------------------------------------------
39+
*/
40+
41+
#ifndef PCRE2_API_INTERNAL_H_IDEMPOTENT_GUARD
42+
#define PCRE2_API_INTERNAL_H_IDEMPOTENT_GUARD
43+
44+
#define PCRE2_JITTARGET_BUFFSIZE_LIMIT 71 /* sljit */
45+
46+
#endif /* PCRE2_API_INTERNAL_H_IDEMPOTENT_GUARD */
47+
48+
/* End of pcre2_api_internal.h */

src/pcre2_jit_test.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
5151

5252
#define PCRE2_CODE_UNIT_WIDTH 0
5353
#include "pcre2.h"
54+
#include "pcre2_api_internal.h"
5455

5556
/*
5657
Letter characters:
@@ -1228,11 +1229,11 @@ static int regression_tests(void)
12281229
#endif
12291230

12301231
#if defined SUPPORT_PCRE2_8
1231-
PCRE2_UCHAR8 cpu_info[128];
1232+
PCRE2_UCHAR8 cpu_info[PCRE2_JITTARGET_BUFFSIZE_LIMIT];
12321233
#elif defined SUPPORT_PCRE2_16
1233-
PCRE2_UCHAR16 cpu_info[128];
1234+
PCRE2_UCHAR16 cpu_info[PCRE2_JITTARGET_BUFFSIZE_LIMIT];
12341235
#elif defined SUPPORT_PCRE2_32
1235-
PCRE2_UCHAR32 cpu_info[128];
1236+
PCRE2_UCHAR32 cpu_info[PCRE2_JITTARGET_BUFFSIZE_LIMIT];
12361237
#endif
12371238
#if defined SUPPORT_UNICODE && ((defined(SUPPORT_PCRE2_8) + defined(SUPPORT_PCRE2_16) + defined(SUPPORT_PCRE2_32)) >= 2)
12381239
int return_value;

src/pcre2test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ needs to be when compiling one of the libraries). */
314314
#include "pcre2.h"
315315
#include "pcre2posix.h"
316316
#include "pcre2_internal.h"
317+
#include "pcre2_api_internal.h"
317318

318319
/* We need access to some of the data tables that PCRE2 uses. The previous
319320
definition of PCRE2_PCRE2TEST makes some minor changes in the files. The
@@ -3046,7 +3047,7 @@ fprintf(f, "Unicode version %s", buf);
30463047
static void
30473048
print_jit_target(FILE *f)
30483049
{
3049-
char buf[VERSION_SIZE];
3050+
char buf[PCRE2_JITTARGET_BUFFSIZE_LIMIT];
30503051
config_str(PCRE2_CONFIG_JITTARGET, buf);
30513052
fputs(buf, f);
30523053
}

0 commit comments

Comments
 (0)