Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions doc/pcre2api.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH PCRE2API 3 "19 October 2025" "PCRE2 10.48-DEV"
.TH PCRE2API 3 "29 October 2025" "PCRE2 10.48-DEV"
.SH NAME
PCRE2 - Perl-compatible regular expressions (revised API)
.sp
Expand Down Expand Up @@ -1296,14 +1296,15 @@ documentation for more details.
.sp
PCRE2_CONFIG_JITTARGET
.sp
The \fIwhere\fP argument should point to a buffer that is at least 64 code
units long. (The exact length required can be found by calling
\fBpcre2_config()\fP with \fBwhere\fP set to NULL.) The buffer is filled with a
string that contains the name of the architecture for which the JIT compiler is
configured, for example "x86 32bit (little endian + unaligned)". If JIT support
is not available, PCRE2_ERROR_BADOPTION is returned, otherwise the number of
code units used is returned. This is the length of the string, plus one unit
for the terminating zero.
The \fIwhere\fP argument should point to a buffer that is suitably aligned and
wide enough to hold the full string. The exact length required is returned when
calling \fBpcre2_config()\fP with \fBwhere\fP set to NULL first. The buffer is
filled with a string that contains the name of the architecture for which the JIT
compiler is configured at build time, for example, a 64-bit ARM CPU that supports
the Armv8.1 extension writes "ARM-64 (LSE) 64bit (little endian + unaligned)".
If JIT support is not available, PCRE2_ERROR_BADOPTION is returned, otherwise
the number of code units used is returned. This is the length of the string,
plus one code unit for the NUL character.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is missing an historical overview and an explanation of why the use of static buffers is discouraged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with it. I can revise it in the next commit

.sp
PCRE2_CONFIG_LINKSIZE
.sp
Expand Down Expand Up @@ -4606,6 +4607,6 @@ Cambridge, England.
.rs
.sp
.nf
Last updated: 19 October 2025
Last updated: 29 October 2025
Copyright (c) 1997-2024 University of Cambridge.
.fi
12 changes: 6 additions & 6 deletions src/pcre2test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2942,9 +2942,9 @@ static int pcre2_config(uint32_t what, void *where)
DISPATCH(return, pcre2_config_, (what, where));
}

static void config_str(uint32_t what, char *where)
static char *config_str(uint32_t what, char *where, int size)
{
DISPATCH(, config_str_, (what, where));
DISPATCH(return, config_str_, (what, where, size));
}

static BOOL decode_modifiers(uint8_t *p, int ctx, patctl *pctl, datctl *dctl)
Expand Down Expand Up @@ -3014,7 +3014,7 @@ static void
print_version(FILE *f, BOOL include_mode)
{
char buf[VERSION_SIZE];
config_str(PCRE2_CONFIG_VERSION, buf);
config_str(PCRE2_CONFIG_VERSION, buf, sizeof(buf));
fprintf(f, "PCRE2 version %s", buf);
if (include_mode)
{
Expand All @@ -3033,7 +3033,7 @@ static void
print_unicode_version(FILE *f)
{
char buf[VERSION_SIZE];
config_str(PCRE2_CONFIG_UNICODE_VERSION, buf);
config_str(PCRE2_CONFIG_UNICODE_VERSION, buf, sizeof(buf));
fprintf(f, "Unicode version %s", buf);
}

Expand All @@ -3046,9 +3046,9 @@ fprintf(f, "Unicode version %s", buf);
static void
print_jit_target(FILE *f)
{
char buf[VERSION_SIZE];
config_str(PCRE2_CONFIG_JITTARGET, buf);
char *buf = config_str(PCRE2_CONFIG_JITTARGET, NULL, 0);
fputs(buf, f);
free(buf);
}


Expand Down
35 changes: 26 additions & 9 deletions src/pcre2test_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,24 +558,41 @@ return 0;

Arguments:
what the item to read
where the 8-bit buffer to receive the string
where the 8-bit buffer to receive the string (NULLABLE)
size sizeof(where) or 0 to ask for the buffer to be allocated

Returns: the string where the data was written
*/

static void
config_str(uint32_t what, char *where)
static char *
config_str(uint32_t what, char *where, int size)
{
int r1, r2;
PCRE2_UCHAR buf[VERSION_SIZE];
int r2;
PCRE2_UCHAR *buf;
int needed_len;

r1 = pcre2_config(what, NULL);
r2 = pcre2_config(what, buf);
if (r1 < 0 || r1 != r2 || r1 >= VERSION_SIZE)
needed_len = pcre2_config(what, NULL);
if (needed_len <= 0)
{
cfprintf(clr_test_error, stderr, "pcre2test: Error in pcre2_config(%d)\n", what);
exit(1);
}
else if (size != 0 && needed_len > size)
{
cfprintf(clr_test_error, stderr,
"pcre2test: Static buffer provided to pcre2_config(%d) too small\n", what);
exit(1);
}

buf = malloc(needed_len * sizeof(PCRE2_UCHAR));
r2 = pcre2_config(what, buf);
PCRE2_ASSERT(r2 == needed_len);

if (where == NULL) where = malloc(needed_len);
while (r2-- > 0) where[r2] = (char)buf[r2];
free(buf);

while (r1-- > 0) where[r1] = (char)buf[r1];
return where;
}


Expand Down