From c7f4bc19c1ee8f37deade9317364d2ca014562ca Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Wed, 21 Feb 2018 18:27:46 +0900 Subject: [PATCH] remove content and content_end member from OnigCalloutArgsStruct --- src/regcomp.c | 23 +---------- src/regexec.c | 105 +++++++++++++++++++++++++++---------------------- src/regint.h | 7 ++-- src/regparse.c | 10 ++--- 4 files changed, 69 insertions(+), 76 deletions(-) diff --git a/src/regcomp.c b/src/regcomp.c index 8afbecf..1c7d791 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -330,7 +330,7 @@ add_mem_num(regex_t* reg, int num) return 0; } -#ifdef USE_CALLOUT +#if 0 static int add_pointer(regex_t* reg, void* addr) { @@ -1542,15 +1542,6 @@ compile_gimmick_node(GimmickNode* node, regex_t* reg) case ONIG_CALLOUT_OF_CODE: case ONIG_CALLOUT_OF_NAME: { - RegexExt* ext; - UChar* pattern; - - ext = onig_get_regex_ext(reg); - CHECK_NULL_RETURN_MEMERR(ext); - pattern = ext->pattern; - if (IS_NULL(pattern)) - return ONIGERR_PARSER_BUG; - r = add_opcode(reg, (node->detail_type == ONIG_CALLOUT_OF_CODE) ? OP_CALLOUT_CODE : OP_CALLOUT_NAME); if (r != 0) return r; @@ -1562,18 +1553,6 @@ compile_gimmick_node(GimmickNode* node, regex_t* reg) if (r != 0) return r; r = add_mem_num(reg, node->dirs); if (r != 0) return r; - if (node->code_start >= 0) { - r = add_pointer(reg, pattern + node->code_start); - if (r != 0) return r; - r = add_pointer(reg, pattern + node->code_end); - if (r != 0) return r; - } - else { - r = add_pointer(reg, 0); - if (r != 0) return r; - r = add_pointer(reg, 0); - if (r != 0) return r; - } } break; diff --git a/src/regexec.c b/src/regexec.c index 7159c09..5626bb4 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -534,15 +534,11 @@ onig_print_compiled_byte_code(FILE* f, UChar* bp, UChar** nextp, UChar* start, case OP_CALLOUT_CODE: { int dirs; - UChar* code_start; - UChar* code_end; GET_MEMNUM_INC(mem, bp); // number GET_MEMNUM_INC(dirs, bp); - GET_POINTER_INC(code_start, bp); - GET_POINTER_INC(code_end, bp); - fprintf(f, ":%d:%d:%p:%p", mem, dirs, code_start, code_end); + fprintf(f, ":%d:%d", mem, dirs); } break; @@ -550,16 +546,12 @@ onig_print_compiled_byte_code(FILE* f, UChar* bp, UChar** nextp, UChar* start, { int dirs; int id; - UChar* code_start; - UChar* code_end; GET_MEMNUM_INC(id, bp); // id GET_MEMNUM_INC(mem, bp); // number GET_MEMNUM_INC(dirs, bp); - GET_POINTER_INC(code_start, bp); - GET_POINTER_INC(code_end, bp); - fprintf(f, ":%d:%d:%d:%p:%p", id, mem, dirs, code_start, code_end); + fprintf(f, ":%d:%d:%d:%p:%p", id, mem, dirs); } break; #endif @@ -862,13 +854,11 @@ onig_region_copy(OnigRegion* to, OnigRegion* from) } #ifdef USE_CALLOUT -#define CALLOUT_BODY(func, ain, aof, aname_id, anum, cstart, cend, user, args, result) do { \ +#define CALLOUT_BODY(func, ain, aof, aname_id, anum, user, args, result) do { \ args.in = (ain);\ args.of = (aof);\ args.name_id = (aname_id);\ args.num = anum;\ - args.content = cstart;\ - args.content_end = cend;\ args.regex = reg;\ args.subject = str;\ args.subject_end = end;\ @@ -883,10 +873,10 @@ onig_region_copy(OnigRegion* to, OnigRegion* from) result = (func)(&args, user);\ } while (0) -#define RETRACTION_CALLOUT(func, aof, aname_id, anum, cstart, cend, user) do {\ +#define RETRACTION_CALLOUT(func, aof, aname_id, anum, user) do {\ int result;\ OnigCalloutArgs args;\ - CALLOUT_BODY(func, ONIG_CALLOUT_IN_RETRACTION, aof, aname_id, anum, cstart, cend, user, args, result);\ + CALLOUT_BODY(func, ONIG_CALLOUT_IN_RETRACTION, aof, aname_id, anum, user, args, result);\ switch (result) {\ case ONIG_CALLOUT_FAIL:\ goto fail;\ @@ -999,8 +989,6 @@ struct OnigCalloutArgsStruct { OnigCalloutOf of; int name_id; /* name id or ONIG_NO_NAME_ID */ int num; - const OnigUChar* content; - const OnigUChar* content_end; OnigRegex regex; const OnigUChar* subject; const OnigUChar* subject_end; @@ -1502,23 +1490,19 @@ stack_double(int is_alloca, char** arg_alloc_base, }\ } while (0) -#define STACK_PUSH_CALLOUT_CODE(anum, xcontent, xcontent_end) do {\ +#define STACK_PUSH_CALLOUT_CODE(anum) do {\ STACK_ENSURE(1);\ stk->type = STK_CALLOUT;\ stk->zid = ONIG_NO_NAME_ID;\ - stk->u.callout.num = (anum);\ - stk->u.callout.content = (xcontent);\ - stk->u.callout.content_end = (xcontent_end);\ + stk->u.callout.num = (anum);\ STACK_INC;\ } while(0) -#define STACK_PUSH_CALLOUT_NAME(aid, anum, xcontent, xcontent_end) do {\ +#define STACK_PUSH_CALLOUT_NAME(aid, anum) do {\ STACK_ENSURE(1);\ stk->type = STK_CALLOUT;\ stk->zid = (aid);\ - stk->u.callout.num = (anum);\ - stk->u.callout.content = (xcontent);\ - stk->u.callout.content_end = (xcontent_end);\ + stk->u.callout.num = (anum);\ STACK_INC;\ } while(0) @@ -1551,7 +1535,7 @@ stack_double(int is_alloca, char** arg_alloc_base, aof = ONIG_CALLOUT_OF_NAME;\ func = onig_get_callout_start_func_from_name_id(stk->zid);\ }\ - RETRACTION_CALLOUT(func, aof, stk->zid, stk->u.callout.num, stk->u.callout.content, stk->u.callout.content_end, msa->mp->callout_user_data);\ + RETRACTION_CALLOUT(func, aof, stk->zid, stk->u.callout.num, msa->mp->callout_user_data);\ } #else #define POP_CALLOUT_CASE @@ -3678,8 +3662,6 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, case OP_CALLOUT_NAME: SOP_IN(OP_CALLOUT_NAME); { - UChar* content_start; - UChar* content_end; int call_result; int num; int dirs; @@ -3692,13 +3674,10 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, callout_common_entry: GET_MEMNUM_INC(num, p); GET_MEMNUM_INC(dirs, p); - GET_POINTER_INC(content_start, p); - GET_POINTER_INC(content_end, p); if (IS_NOT_NULL(func) && (dirs & ONIG_CALLOUT_IN_PROGRESS) != 0) { CALLOUT_BODY(func, ONIG_CALLOUT_IN_PROGRESS, of, name_id, - num, content_start, content_end, - msa->mp->callout_user_data, args, call_result); + num, msa->mp->callout_user_data, args, call_result); switch (call_result) { case ONIG_CALLOUT_FAIL: goto fail; @@ -3723,13 +3702,13 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, if (of == ONIG_CALLOUT_OF_NAME) { func = onig_get_callout_start_func_from_name_id(name_id); if (IS_NOT_NULL(func)) { - STACK_PUSH_CALLOUT_NAME(name_id, num, content_start, content_end); + STACK_PUSH_CALLOUT_NAME(name_id, num); } } else { func = msa->mp->retraction_callout_of_code; if (IS_NOT_NULL(func)) { - STACK_PUSH_CALLOUT_CODE(num, content_start, content_end); + STACK_PUSH_CALLOUT_CODE(num); } } } @@ -4926,13 +4905,29 @@ onig_get_name_id_of_callout_args(OnigCalloutArgs* args) extern const UChar* onig_get_content_of_callout_args(OnigCalloutArgs* args) { - return args->content; + int num; + CalloutListEntry* e; + + num = args->num; + e = onig_reg_callout_list_at(args->regex, num); + if (IS_NULL(e)) return 0; + if (e->of == ONIG_CALLOUT_OF_NAME) return 0; + + return e->u.content.start; } extern const UChar* onig_get_content_end_of_callout_args(OnigCalloutArgs* args) { - return args->content_end; + int num; + CalloutListEntry* e; + + num = args->num; + e = onig_reg_callout_list_at(args->regex, num); + if (IS_NULL(e)) return 0; + if (e->of == ONIG_CALLOUT_OF_NAME) return 0; + + return e->u.content.end; } extern const UChar* @@ -5043,12 +5038,19 @@ onig_builtin_success(OnigCalloutArgs* args ARG_UNUSED, void* user_data ARG_UNUSE } extern int -onig_builtin_error(OnigCalloutArgs* a, void* user_data ARG_UNUSED) +onig_builtin_error(OnigCalloutArgs* args, void* user_data ARG_UNUSED) { - long n; + int n; + int num; + CalloutListEntry* e; + + num = args->num; + e = onig_reg_callout_list_at(args->regex, num); + if (IS_NULL(e)) return 0; + //if (e->of != ONIG_CALLOUT_OF_NAME) return 0; - if (a->content != 0 && a->content_end > a->content) { - n = strtol((char* )a->content, 0, 10); + if (e->u.arg.types[0] == ONIG_TYPE_INT) { + n = e->u.arg.vals[0].i; if (n >= 0) { n = ONIGERR_INVALID_CALLOUT_BODY; } @@ -5057,7 +5059,7 @@ onig_builtin_error(OnigCalloutArgs* a, void* user_data ARG_UNUSED) n = ONIG_CALLOUT_FAIL; } - return (int )n; + return n; } #endif /* USE_CALLOUT */ @@ -5069,19 +5071,30 @@ onig_initialize_builtin_callouts(void) return ONIG_NO_SUPPORT_CONFIG; #else -#define B1(name, func) do {\ +#define B0(name, func) do {\ id = onig_set_callout_of_name((UChar* )#name, (UChar* )(#name + strlen(#name)),\ ONIG_CALLOUT_IN_BOTH,\ onig_builtin_ ## func, 0, 0, 0, 0);\ if (id < 0) return id;\ } while(0) +#define B1(name, func, ts) do {\ + id = onig_set_callout_of_name((UChar* )#name, (UChar* )(#name + strlen(#name)),\ + ONIG_CALLOUT_IN_PROGRESS,\ + onig_builtin_ ## func, 1, (ts), 0, 0);\ + if (id < 0) return id;\ +} while(0) + int id; + OnigType t_int; + + t_int = ONIG_TYPE_INT; + + B0(FAIL, fail); + B0(SUCCESS, success); + B0(ABORT, abort); - B1(FAIL, fail); - B1(SUCCESS, success); - B1(ABORT, abort); - B1(ERROR, error); + B1(ERROR, error, &t_int); return ONIG_NORMAL; #endif /* USE_CALLOUT */ diff --git a/src/regint.h b/src/regint.h index d55f31d..eadd4bc 100644 --- a/src/regint.h +++ b/src/regint.h @@ -642,7 +642,7 @@ enum OpCode { OP_UPDATE_VAR, #ifdef USE_CALLOUT OP_CALLOUT_CODE, /* (?{...}) (?{{...}}) */ - OP_CALLOUT_NAME, /* (*NAME) (*NAME:...) */ + OP_CALLOUT_NAME, /* (*name) (*name[tag](args...)) */ #endif /* no need: IS_DYNAMIC_OPTION() == 0 */ @@ -745,8 +745,8 @@ typedef int ModeType; #define SIZE_OP_UPDATE_VAR (SIZE_OPCODE + SIZE_UPDATE_VAR_TYPE + SIZE_MEMNUM) #ifdef USE_CALLOUT -#define SIZE_OP_CALLOUT_CODE (SIZE_OPCODE + SIZE_MEMNUM + SIZE_MEMNUM + SIZE_POINTER + SIZE_POINTER) -#define SIZE_OP_CALLOUT_NAME (SIZE_OPCODE + SIZE_MEMNUM + SIZE_MEMNUM + SIZE_MEMNUM + SIZE_POINTER + SIZE_POINTER) +#define SIZE_OP_CALLOUT_CODE (SIZE_OPCODE + SIZE_MEMNUM + SIZE_MEMNUM) +#define SIZE_OP_CALLOUT_NAME (SIZE_OPCODE + SIZE_MEMNUM + SIZE_MEMNUM + SIZE_MEMNUM) #endif #define MC_ESC(syn) (syn)->meta_char_table.esc @@ -832,6 +832,7 @@ extern OnigCalloutFunc onig_get_callout_start_func_from_name_id(int id); extern OnigCalloutFunc onig_get_callout_end_func_from_name_id(int id); extern int onig_callout_tag_table_free(void* table); extern void onig_free_callout_list(int n, CalloutListEntry* list); +extern CalloutListEntry* onig_reg_callout_list_at(regex_t* reg, int num); #endif diff --git a/src/regparse.c b/src/regparse.c index aacb287..d9cb6e1 100644 --- a/src/regparse.c +++ b/src/regparse.c @@ -2392,12 +2392,12 @@ onig_free_callout_list(int n, CalloutListEntry* list) xfree(list); } -static CalloutListEntry* -reg_callout_list_at(ScanEnv* env, int num) +extern CalloutListEntry* +onig_reg_callout_list_at(regex_t* reg, int num) { RegexExt* ext; - ext = onig_get_regex_ext(env->reg); + ext = onig_get_regex_ext(reg); CHECK_NULL_RETURN(ext); if (num < 0 || num > ext->callout_num) @@ -6438,7 +6438,7 @@ parse_callout_of_code(Node** np, int cterm, UChar** src, UChar* end, ScanEnv* en if (r != ONIG_NORMAL) return r; } - e = reg_callout_list_at(env, num); + e = onig_reg_callout_list_at(env->reg, num); e->of = ONIG_CALLOUT_OF_CODE; e->in = in; e->name_id = ONIG_NO_NAME_ID; @@ -6690,7 +6690,7 @@ parse_callout_of_name(Node** np, int cterm, UChar** src, UChar* end, ScanEnv* en if (r != ONIG_NORMAL) return r; } - e = reg_callout_list_at(env, num); + e = onig_reg_callout_list_at(env->reg, num); e->of = ONIG_CALLOUT_OF_NAME; e->in = in; e->name_id = name_id; -- 2.40.0