diff --git a/ChangeLog b/ChangeLog index b0e74d386..bb3bb06ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -72,6 +72,9 @@ The condition could erroneously be treated as true if a branch matched but overran the current position. This bug was in the interpreter only; matching with JIT was correct. +12. Add a new error code (PCRE2_ERROR_JIT_UNSUPPORTED) which is yielded +for unsupported jit features. + Version 10.44 07-June-2024 -------------------------- diff --git a/doc/pcre2_jit_compile.3 b/doc/pcre2_jit_compile.3 index d6b79c909..6b0984246 100644 --- a/doc/pcre2_jit_compile.3 +++ b/doc/pcre2_jit_compile.3 @@ -23,11 +23,12 @@ details are given in the documentation. .P The availability of JIT support can be tested by calling -\fBpcre2_compile_jit()\fP with a NULL first argument and the single option -PCRE2_JIT_TEST_ALLOC. Such a call returns zero if JIT is available and has a -working allocator. Otherwise it returns PCRE2_ERROR_NOMEMORY if JIT is -available but cannot allocate executable memory, or PCRE2_ERROR_NULL if JIT -support is not compiled. +\fBpcre2_compile_jit()\fP with a single option PCRE2_JIT_TEST_ALLOC (the +code argument is ignored, so a NULL value is accepted). Such a call +returns zero if JIT is available and has a working allocator. Otherwise +it returns PCRE2_ERROR_NOMEMORY if JIT is available but cannot allocate +executable memory, or PCRE2_ERROR_JIT_UNSUPPORTED if JIT support is not +compiled. .P Otherwise, the first argument must be a pointer that was returned by a successful call to \fBpcre2_compile()\fP, and the second must contain one or @@ -46,7 +47,8 @@ for success, or a negative error code otherwise. In particular, PCRE2_ERROR_JIT_BADOPTION is returned if JIT is not supported or if an unknown bit is set in \fIoptions\fP. The function can also return PCRE2_ERROR_NOMEMORY if JIT is unable to allocate executable memory for the compiler, even if it was -because of a system security restriction. +because of a system security restriction. In a few cases, the function may +return with PCRE2_ERROR_JIT_UNSUPPORTED for unsupported features. .P There is a complete description of the PCRE2 native API in the .\" HREF diff --git a/doc/pcre2jit.3 b/doc/pcre2jit.3 index 05b58e347..50d937f6c 100644 --- a/doc/pcre2jit.3 +++ b/doc/pcre2jit.3 @@ -54,11 +54,11 @@ executable memory in which to build its compiled code. The only guarantee from be used. .P As of release 10.45 there is a more informative way to test for JIT support. If -\fBpcre2_compile_jit()\fP is called with a NULL first argument and the single -option PCRE2_JIT_TEST_ALLOC, it returns zero if JIT is available and has a -working allocator. Otherwise it returns PCRE2_ERROR_NOMEMORY if JIT is -available but cannot allocate executable memory, or PCRE2_ERROR_NULL if JIT -support is not compiled. +\fBpcre2_compile_jit()\fP is called with the single option PCRE2_JIT_TEST_ALLOC +it returns zero if JIT is available and has a working allocator. Otherwise it +returns PCRE2_ERROR_NOMEMORY if JIT is available but cannot allocate executable +memory, or PCRE2_ERROR_JIT_UNSUPPORTED if JIT support is not compiled. The +code argument is ignored, so it can be a NULL value. .P A simple program does not need to check availability in order to use JIT when possible. The API is implemented in a way that falls back to the interpretive diff --git a/src/pcre2.h.in b/src/pcre2.h.in index e4118a475..a13362daf 100644 --- a/src/pcre2.h.in +++ b/src/pcre2.h.in @@ -408,6 +408,7 @@ released, the numbers must not be changed. */ #define PCRE2_ERROR_INTERNAL_DUPMATCH (-65) #define PCRE2_ERROR_DFA_UINVALID_UTF (-66) #define PCRE2_ERROR_INVALIDOFFSET (-67) +#define PCRE2_ERROR_JIT_UNSUPPORTED (-68) /* Request types for pcre2_pattern_info() */ diff --git a/src/pcre2_error.c b/src/pcre2_error.c index fbf03a12c..ea7337608 100644 --- a/src/pcre2_error.c +++ b/src/pcre2_error.c @@ -276,6 +276,7 @@ static const unsigned char match_error_texts[] = "internal error - duplicate substitution match\0" "PCRE2_MATCH_INVALID_UTF is not supported for DFA matching\0" "INTERNAL ERROR: invalid substring offset\0" + "feature is not supported by the JIT compiler\0" ; diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c index 8bec4558d..435411b39 100644 --- a/src/pcre2_jit_compile.c +++ b/src/pcre2_jit_compile.c @@ -14280,7 +14280,7 @@ common->ovector_start += sizeof(sljit_sw); if (!check_opcode_types(common, common->start, ccend)) { SLJIT_FREE(common->optimized_cbracket, allocator_data); - return PCRE2_ERROR_NOMEMORY; + return PCRE2_ERROR_JIT_UNSUPPORTED; } /* Checking flags and updating ovector_start. */ @@ -14865,15 +14865,19 @@ if (executable_allocator_is_working == -1) } else executable_allocator_is_working = 0; } +#endif if (options & PCRE2_JIT_TEST_ALLOC) { if (options != PCRE2_JIT_TEST_ALLOC) return PCRE2_ERROR_JIT_BADOPTION; +#ifdef SUPPORT_JIT return executable_allocator_is_working ? 0 : PCRE2_ERROR_NOMEMORY; - } +#else + return PCRE2_ERROR_JIT_UNSUPPORTED; #endif + } if (code == NULL) return PCRE2_ERROR_NULL; diff --git a/src/pcre2test.c b/src/pcre2test.c index 1c60a8817..cbd32b194 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -8616,7 +8616,7 @@ if (arg != NULL && arg[0] != CHAR_MINUS) { case 0: break; case PCRE2_ERROR_NOMEMORY: yield = 1; break; - case PCRE2_ERROR_NULL: yield = 2; break; + case PCRE2_ERROR_JIT_UNSUPPORTED: yield = 2; break; default: yield = 3; break; } printf("%d\n", yield); diff --git a/testdata/testoutput17 b/testdata/testoutput17 index 00c4bd4c9..9ca1c3ad4 100644 --- a/testdata/testoutput17 +++ b/testdata/testoutput17 @@ -6,11 +6,11 @@ # JIT does not support this pattern (callout at start of condition). /(?(?C1)(?=a)a)/I -JIT compilation was not successful (no more memory) +JIT compilation was not successful (feature is not supported by the JIT compiler) Capture group count = 0 May match empty string Subject length lower bound = 0 -JIT compilation was not successful (no more memory) +JIT compilation was not successful (feature is not supported by the JIT compiler) # The following pattern cannot be compiled by JIT.