Skip to content

Commit 1acf27e

Browse files
committed
pcre2test: dynamically allocate buffer for JITTARGET
in preparation for deprecating the use of static buffers, increase its size to the next power of 2.
1 parent 3b91977 commit 1acf27e

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

doc/pcre2api.3

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,8 @@ 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 suitable aligned and
1300+
at least 128 code units long. (The exact length required can be found by calling
13011301
\fBpcre2_config()\fP with \fBwhere\fP set to NULL.) The buffer is filled with a
13021302
string that contains the name of the architecture for which the JIT compiler is
13031303
configured, for example "x86 32bit (little endian + unaligned)". If JIT support

src/pcre2test.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,7 +3037,15 @@ config_str(PCRE2_CONFIG_UNICODE_VERSION, buf);
30373037
fprintf(f, "Unicode version %s", buf);
30383038
}
30393039

3040-
3040+
#if defined(__s390x__) || \
3041+
((defined(__ppc64__) || defined(__powerpc64__) || (defined(_ARCH_PPC64) && defined(__64BIT__)) || \
3042+
(defined(_POWER) && defined(__64BIT__))) && !defined(__LITTLE_ENDIAN__)) || \
3043+
(defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC) || defined(_ARCH_PWR) || defined(_ARCH_PWR2) || defined(_POWER)) || \
3044+
(((defined(__mips__) && !defined(_LP64)) || defined(__mips64)) && !defined(__MIPSEL__))
3045+
#define PCRE2_BIG_ENDIAN 1
3046+
#else
3047+
#define PCRE2_LITTLE_ENDIAN 1
3048+
#endif
30413049

30423050
/*************************************************
30433051
* Print JIT target *
@@ -3046,9 +3054,20 @@ fprintf(f, "Unicode version %s", buf);
30463054
static void
30473055
print_jit_target(FILE *f)
30483056
{
3049-
char buf[VERSION_SIZE];
3050-
config_str(PCRE2_CONFIG_JITTARGET, buf);
3051-
fputs(buf, f);
3057+
PCRE2_SIZE len = pcre2_config(PCRE2_CONFIG_JITTARGET, NULL);
3058+
const int bytes_per_codepoint = test_mode / 8;
3059+
char *buf = malloc(len * 4);
3060+
3061+
pcre2_config(PCRE2_CONFIG_JITTARGET, buf);
3062+
for (int i = 0; i < len; i++)
3063+
{
3064+
#ifdef PCRE2_LITTLE_ENDIAN
3065+
putc(*(buf + (i * bytes_per_codepoint)), f);
3066+
#else
3067+
putc(*(buf + (bytes_per_codepoint * i + (bytes_per_codepoint - 1))), f);
3068+
#endif
3069+
}
3070+
free(buf);
30523071
}
30533072

30543073

0 commit comments

Comments
 (0)