The pcre2_jit_stack_assign is changed to use the matching context.

This commit is contained in:
Zoltán Herczeg 2014-11-06 14:37:09 +00:00
parent d4d9ca954d
commit 7d9caa5b41
7 changed files with 53 additions and 44 deletions

View File

@ -455,11 +455,11 @@ PCRE2_EXP_DECL int pcre2_jit_match(const pcre2_code *, \
PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, uint32_t, \ PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, uint32_t, \
pcre2_match_data *, pcre2_match_context *, \ pcre2_match_data *, pcre2_match_context *, \
pcre2_jit_stack *); \ pcre2_jit_stack *); \
PCRE2_EXP_DECL void pcre2_jit_free_unused_memory(pcre2_general_context *);\ PCRE2_EXP_DECL void pcre2_jit_free_unused_memory(pcre2_general_context *); \
PCRE2_EXP_DECL \ PCRE2_EXP_DECL \
pcre2_jit_stack *pcre2_jit_stack_create(pcre2_general_context *, \ pcre2_jit_stack *pcre2_jit_stack_create(pcre2_general_context *, \
PCRE2_SIZE, PCRE2_SIZE); \ PCRE2_SIZE, PCRE2_SIZE); \
PCRE2_EXP_DECL void pcre2_jit_stack_assign(const pcre2_code *, \ PCRE2_EXP_DECL void pcre2_jit_stack_assign(pcre2_match_context *, \
pcre2_jit_callback, void *); \ pcre2_jit_callback, void *); \
PCRE2_EXP_DECL void pcre2_jit_stack_free(pcre2_jit_stack *); PCRE2_EXP_DECL void pcre2_jit_stack_free(pcre2_jit_stack *);

View File

@ -129,7 +129,8 @@ switch (what)
#ifdef SUPPORT_JIT #ifdef SUPPORT_JIT
{ {
const char *v = PRIV(jit_get_target)(); const char *v = PRIV(jit_get_target)();
return (where == NULL)? (int)strlen(v) : return (where == NULL)?
(int)((strlen(v) + 1) * sizeof(PCRE2_UCHAR)) :
PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v); PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v);
} }
#else #else
@ -171,7 +172,8 @@ switch (what)
#else #else
const char *v = "Unicode not supported"; const char *v = "Unicode not supported";
#endif #endif
return (where == NULL)? (int)strlen(v) : return (where == NULL)?
(int)((strlen(v) + 1) * sizeof(PCRE2_UCHAR)) :
PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v); PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v);
} }
break; break;
@ -208,7 +210,8 @@ switch (what)
const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)? const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)?
XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) : XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) :
XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE); XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE);
return (where == NULL)? (int)strlen(v) : return (where == NULL)?
(int)((strlen(v) + 1) * sizeof(PCRE2_UCHAR)) :
PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v); PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v);
} }
} }

View File

@ -577,6 +577,10 @@ typedef struct pcre2_real_match_context {
void *callout_data; void *callout_data;
uint32_t match_limit; uint32_t match_limit;
uint32_t recursion_limit; uint32_t recursion_limit;
#ifdef SUPPORT_JIT
pcre2_jit_callback jit_callback;
void *jit_callback_data;
#endif
} pcre2_real_match_context; } pcre2_real_match_context;
/* The real compiled code structure */ /* The real compiled code structure */

View File

@ -195,8 +195,6 @@ typedef struct executable_functions {
void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES]; void *executable_funcs[JIT_NUMBER_OF_COMPILE_MODES];
sljit_uw *read_only_data[JIT_NUMBER_OF_COMPILE_MODES]; sljit_uw *read_only_data[JIT_NUMBER_OF_COMPILE_MODES];
sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES]; sljit_uw executable_sizes[JIT_NUMBER_OF_COMPILE_MODES];
pcre2_jit_callback callback;
void *callback_data;
sljit_ui top_bracket; sljit_ui top_bracket;
sljit_ui limit_match; sljit_ui limit_match;
} executable_functions; } executable_functions;

View File

@ -158,8 +158,8 @@ if (oveccount > max_oveccount)
oveccount = max_oveccount; oveccount = max_oveccount;
arguments.oveccount = oveccount << 1; arguments.oveccount = oveccount << 1;
if (jit_stack == NULL && functions->callback != NULL) if (jit_stack == NULL && mcontext->jit_callback != NULL)
jit_stack = functions->callback(functions->callback_data); jit_stack = mcontext->jit_callback(mcontext->jit_callback_data);
convert_executable_func.executable_func = functions->executable_funcs[index]; convert_executable_func.executable_func = functions->executable_funcs[index];
if (jit_stack != NULL) if (jit_stack != NULL)

View File

@ -132,7 +132,7 @@ return jit_stack;
*************************************************/ *************************************************/
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
pcre2_jit_stack_assign(const pcre2_code *code, pcre2_jit_callback callback, pcre2_jit_stack_assign(pcre2_match_context *mcontext, pcre2_jit_callback callback,
void *callback_data) void *callback_data)
{ {
#ifndef SUPPORT_JIT #ifndef SUPPORT_JIT
@ -141,17 +141,9 @@ pcre2_jit_stack_assign(const pcre2_code *code, pcre2_jit_callback callback,
(void)callback_data; (void)callback_data;
#else /* SUPPORT_JIT */ #else /* SUPPORT_JIT */
pcre2_real_code *re = (pcre2_real_code *)code; if (mcontext == NULL) return;
executable_functions *functions; mcontext->jit_callback = callback;
mcontext->jit_callback_data = callback_data;
if (re == NULL) return;
functions = (executable_functions *)re->executable_jit;
if (functions != NULL)
{
functions->callback = callback;
functions->callback_data = callback_data;
}
#endif /* SUPPORT_JIT */ #endif /* SUPPORT_JIT */
} }

View File

@ -858,16 +858,16 @@ static pcre2_jit_stack_8 *getstack8(void)
return stack8; return stack8;
} }
static void setstack8(pcre2_code_8 *code) static void setstack8(pcre2_match_context_8 *mcontext)
{ {
if (!code) { if (!mcontext) {
if (stack8) if (stack8)
pcre2_jit_stack_free_8(stack8); pcre2_jit_stack_free_8(stack8);
stack8 = NULL; stack8 = NULL;
return; return;
} }
pcre2_jit_stack_assign_8(code, callback8, getstack8()); pcre2_jit_stack_assign_8(mcontext, callback8, getstack8());
} }
#endif /* SUPPORT_PCRE2_8 */ #endif /* SUPPORT_PCRE2_8 */
@ -881,18 +881,18 @@ static pcre2_jit_stack_16 *getstack16(void)
return stack16; return stack16;
} }
static void setstack16(pcre2_code_16 *code) static void setstack16(pcre2_match_context_16 *mcontext)
{ {
if (!code) { if (!mcontext) {
if (stack16) if (stack16)
pcre2_jit_stack_free_16(stack16); pcre2_jit_stack_free_16(stack16);
stack16 = NULL; stack16 = NULL;
return; return;
} }
pcre2_jit_stack_assign_16(code, callback16, getstack16()); pcre2_jit_stack_assign_16(mcontext, callback16, getstack16());
} }
#endif /* SUPPORT_PCRE2_8 */ #endif /* SUPPORT_PCRE2_16 */
#ifdef SUPPORT_PCRE2_32 #ifdef SUPPORT_PCRE2_32
static pcre2_jit_stack_32 *stack32; static pcre2_jit_stack_32 *stack32;
@ -904,18 +904,18 @@ static pcre2_jit_stack_32 *getstack32(void)
return stack32; return stack32;
} }
static void setstack32(pcre2_code_32 *code) static void setstack32(pcre2_match_context_32 *mcontext)
{ {
if (!code) { if (!mcontext) {
if (stack32) if (stack32)
pcre2_jit_stack_free_32(stack32); pcre2_jit_stack_free_32(stack32);
stack32 = NULL; stack32 = NULL;
return; return;
} }
pcre2_jit_stack_assign_32(code, callback32, getstack32()); pcre2_jit_stack_assign_32(mcontext, callback32, getstack32());
} }
#endif /* SUPPORT_PCRE2_8 */ #endif /* SUPPORT_PCRE2_32 */
#ifdef SUPPORT_PCRE2_16 #ifdef SUPPORT_PCRE2_16
@ -1082,6 +1082,7 @@ static int regression_tests(void)
pcre2_compile_context_8 *ccontext8; pcre2_compile_context_8 *ccontext8;
pcre2_match_data_8 *mdata8_1; pcre2_match_data_8 *mdata8_1;
pcre2_match_data_8 *mdata8_2; pcre2_match_data_8 *mdata8_2;
pcre2_match_context_8 *mcontext8;
PCRE2_SIZE *ovector8_1 = NULL; PCRE2_SIZE *ovector8_1 = NULL;
PCRE2_SIZE *ovector8_2 = NULL; PCRE2_SIZE *ovector8_2 = NULL;
int return_value8[2]; int return_value8[2];
@ -1091,6 +1092,7 @@ static int regression_tests(void)
pcre2_compile_context_16 *ccontext16; pcre2_compile_context_16 *ccontext16;
pcre2_match_data_16 *mdata16_1; pcre2_match_data_16 *mdata16_1;
pcre2_match_data_16 *mdata16_2; pcre2_match_data_16 *mdata16_2;
pcre2_match_context_16 *mcontext16;
PCRE2_SIZE *ovector16_1 = NULL; PCRE2_SIZE *ovector16_1 = NULL;
PCRE2_SIZE *ovector16_2 = NULL; PCRE2_SIZE *ovector16_2 = NULL;
int return_value16[2]; int return_value16[2];
@ -1101,6 +1103,7 @@ static int regression_tests(void)
pcre2_compile_context_32 *ccontext32; pcre2_compile_context_32 *ccontext32;
pcre2_match_data_32 *mdata32_1; pcre2_match_data_32 *mdata32_1;
pcre2_match_data_32 *mdata32_2; pcre2_match_data_32 *mdata32_2;
pcre2_match_context_32 *mcontext32;
PCRE2_SIZE *ovector32_1 = NULL; PCRE2_SIZE *ovector32_1 = NULL;
PCRE2_SIZE *ovector32_2 = NULL; PCRE2_SIZE *ovector32_2 = NULL;
int return_value32[2]; int return_value32[2];
@ -1265,10 +1268,12 @@ static int regression_tests(void)
return_value8[1] = -1000; return_value8[1] = -1000;
mdata8_1 = pcre2_match_data_create_8(OVECTOR_SIZE, NULL); mdata8_1 = pcre2_match_data_create_8(OVECTOR_SIZE, NULL);
mdata8_2 = pcre2_match_data_create_8(OVECTOR_SIZE, NULL); mdata8_2 = pcre2_match_data_create_8(OVECTOR_SIZE, NULL);
if (!mdata8_1 || !mdata8_2) { mcontext8 = pcre2_match_context_create_8(NULL);
if (!mdata8_1 || !mdata8_2 || !mcontext8) {
printf("\n8 bit: Cannot allocate match data\n"); printf("\n8 bit: Cannot allocate match data\n");
pcre2_match_data_free_8(mdata8_1); pcre2_match_data_free_8(mdata8_1);
pcre2_match_data_free_8(mdata8_2); pcre2_match_data_free_8(mdata8_2);
pcre2_match_context_free_8(mcontext8);
pcre2_code_free_8(re8); pcre2_code_free_8(re8);
re8 = NULL; re8 = NULL;
} else { } else {
@ -1286,12 +1291,12 @@ static int regression_tests(void)
if (pcre2_jit_compile_8(re8, jit_compile_mode)) { if (pcre2_jit_compile_8(re8, jit_compile_mode)) {
printf("\n8 bit: JIT compiler does not support \"%s\"\n", current->pattern); printf("\n8 bit: JIT compiler does not support \"%s\"\n", current->pattern);
} else if ((counter & 0x1) != 0) { } else if ((counter & 0x1) != 0) {
setstack8(re8); setstack8(mcontext8);
return_value8[0] = pcre2_match_8(re8, (PCRE2_SPTR8)current->input, strlen(current->input), return_value8[0] = pcre2_match_8(re8, (PCRE2_SPTR8)current->input, strlen(current->input),
current->start_offset & OFFSET_MASK, current->match_options, mdata8_1, NULL); current->start_offset & OFFSET_MASK, current->match_options, mdata8_1, mcontext8);
} else { } else {
return_value8[0] = pcre2_jit_match_8(re8, (PCRE2_SPTR8)current->input, strlen(current->input), return_value8[0] = pcre2_jit_match_8(re8, (PCRE2_SPTR8)current->input, strlen(current->input),
current->start_offset & OFFSET_MASK, current->match_options, mdata8_1, NULL, getstack8()); current->start_offset & OFFSET_MASK, current->match_options, mdata8_1, mcontext8, getstack8());
} }
} }
#endif #endif
@ -1301,10 +1306,12 @@ static int regression_tests(void)
return_value16[1] = -1000; return_value16[1] = -1000;
mdata16_1 = pcre2_match_data_create_16(OVECTOR_SIZE, NULL); mdata16_1 = pcre2_match_data_create_16(OVECTOR_SIZE, NULL);
mdata16_2 = pcre2_match_data_create_16(OVECTOR_SIZE, NULL); mdata16_2 = pcre2_match_data_create_16(OVECTOR_SIZE, NULL);
if (!mdata16_1 || !mdata16_2) { mcontext16 = pcre2_match_context_create_16(NULL);
if (!mdata16_1 || !mdata16_2 || !mcontext16) {
printf("\n16 bit: Cannot allocate match data\n"); printf("\n16 bit: Cannot allocate match data\n");
pcre2_match_data_free_16(mdata16_1); pcre2_match_data_free_16(mdata16_1);
pcre2_match_data_free_16(mdata16_2); pcre2_match_data_free_16(mdata16_2);
pcre2_match_context_free_16(mcontext16);
pcre2_code_free_16(re16); pcre2_code_free_16(re16);
re16 = NULL; re16 = NULL;
} else { } else {
@ -1327,12 +1334,12 @@ static int regression_tests(void)
if (pcre2_jit_compile_16(re16, jit_compile_mode)) { if (pcre2_jit_compile_16(re16, jit_compile_mode)) {
printf("\n16 bit: JIT compiler does not support \"%s\"\n", current->pattern); printf("\n16 bit: JIT compiler does not support \"%s\"\n", current->pattern);
} else if ((counter & 0x1) != 0) { } else if ((counter & 0x1) != 0) {
setstack16(re16); setstack16(mcontext16);
return_value16[0] = pcre2_match_16(re16, regtest_buf16, length16, return_value16[0] = pcre2_match_16(re16, regtest_buf16, length16,
current->start_offset & OFFSET_MASK, current->match_options, mdata16_1, NULL); current->start_offset & OFFSET_MASK, current->match_options, mdata16_1, mcontext16);
} else { } else {
return_value16[0] = pcre2_jit_match_16(re16, regtest_buf16, length16, return_value16[0] = pcre2_jit_match_16(re16, regtest_buf16, length16,
current->start_offset & OFFSET_MASK, current->match_options, mdata16_1, NULL, getstack16()); current->start_offset & OFFSET_MASK, current->match_options, mdata16_1, mcontext16, getstack16());
} }
} }
#endif #endif
@ -1342,10 +1349,12 @@ static int regression_tests(void)
return_value32[1] = -1000; return_value32[1] = -1000;
mdata32_1 = pcre2_match_data_create_32(OVECTOR_SIZE, NULL); mdata32_1 = pcre2_match_data_create_32(OVECTOR_SIZE, NULL);
mdata32_2 = pcre2_match_data_create_32(OVECTOR_SIZE, NULL); mdata32_2 = pcre2_match_data_create_32(OVECTOR_SIZE, NULL);
if (!mdata32_1 || !mdata32_2) { mcontext32 = pcre2_match_context_create_32(NULL);
if (!mdata32_1 || !mdata32_2 || !mcontext32) {
printf("\n32 bit: Cannot allocate match data\n"); printf("\n32 bit: Cannot allocate match data\n");
pcre2_match_data_free_32(mdata32_1); pcre2_match_data_free_32(mdata32_1);
pcre2_match_data_free_32(mdata32_2); pcre2_match_data_free_32(mdata32_2);
pcre2_match_context_free_32(mcontext32);
pcre2_code_free_32(re32); pcre2_code_free_32(re32);
re32 = NULL; re32 = NULL;
} else { } else {
@ -1368,12 +1377,12 @@ static int regression_tests(void)
if (pcre2_jit_compile_32(re32, jit_compile_mode)) { if (pcre2_jit_compile_32(re32, jit_compile_mode)) {
printf("\n32 bit: JIT compiler does not support \"%s\"\n", current->pattern); printf("\n32 bit: JIT compiler does not support \"%s\"\n", current->pattern);
} else if ((counter & 0x1) != 0) { } else if ((counter & 0x1) != 0) {
setstack32(re32); setstack32(mcontext32);
return_value32[0] = pcre2_match_32(re32, regtest_buf32, length32, return_value32[0] = pcre2_match_32(re32, regtest_buf32, length32,
current->start_offset & OFFSET_MASK, current->match_options, mdata32_1, NULL); current->start_offset & OFFSET_MASK, current->match_options, mdata32_1, mcontext32);
} else { } else {
return_value32[0] = pcre2_jit_match_32(re32, regtest_buf32, length32, return_value32[0] = pcre2_jit_match_32(re32, regtest_buf32, length32,
current->start_offset & OFFSET_MASK, current->match_options, mdata32_1, NULL, getstack32()); current->start_offset & OFFSET_MASK, current->match_options, mdata32_1, mcontext32, getstack32());
} }
} }
#endif #endif
@ -1642,16 +1651,19 @@ static int regression_tests(void)
pcre2_code_free_8(re8); pcre2_code_free_8(re8);
pcre2_match_data_free_8(mdata8_1); pcre2_match_data_free_8(mdata8_1);
pcre2_match_data_free_8(mdata8_2); pcre2_match_data_free_8(mdata8_2);
pcre2_match_context_free_8(mcontext8);
#endif #endif
#ifdef SUPPORT_PCRE2_16 #ifdef SUPPORT_PCRE2_16
pcre2_code_free_16(re16); pcre2_code_free_16(re16);
pcre2_match_data_free_16(mdata16_1); pcre2_match_data_free_16(mdata16_1);
pcre2_match_data_free_16(mdata16_2); pcre2_match_data_free_16(mdata16_2);
pcre2_match_context_free_16(mcontext16);
#endif #endif
#ifdef SUPPORT_PCRE2_32 #ifdef SUPPORT_PCRE2_32
pcre2_code_free_32(re32); pcre2_code_free_32(re32);
pcre2_match_data_free_32(mdata32_1); pcre2_match_data_free_32(mdata32_1);
pcre2_match_data_free_32(mdata32_2); pcre2_match_data_free_32(mdata32_2);
pcre2_match_context_free_32(mcontext32);
#endif #endif
if (is_successful) { if (is_successful) {