From: K.Kosako Date: Tue, 26 Feb 2019 02:19:22 +0000 (+0900) Subject: add ocs member into regex_t X-Git-Tag: v6.9.2_rc1~65^2~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=984298d2e9df42770828c5f5f163d62a8a402455;p=onig add ocs member into regex_t --- diff --git a/src/regcomp.c b/src/regcomp.c index 2efa5d3..8fa7f65 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -112,14 +112,27 @@ static int ops_init(regex_t* reg, int init_alloc_size) { Operation* p; - size_t size = sizeof(Operation) * init_alloc_size; + size_t size; if (init_alloc_size > 0) { + size = sizeof(Operation) * init_alloc_size; p = (Operation* )xrealloc(reg->ops, size); CHECK_NULL_RETURN_MEMERR(p); +#ifdef USE_DIRECT_THREADED_CODE + { + enum OpCode* cp; + size = sizeof(enum OpCode) * init_alloc_size; + cp = (enum OpCode* )xrealloc(reg->ocs, size); + CHECK_NULL_RETURN_MEMERR(cp); + reg->ocs = cp; + } +#endif } else { - p = (Operation* )0; + p = (Operation* )0; +#ifdef USE_DIRECT_THREADED_CODE + reg->ocs = (enum OpCode* )0; +#endif } reg->ops = p; @@ -135,17 +148,27 @@ ops_expand(regex_t* reg, int n) { #define MIN_OPS_EXPAND_SIZE 4 +#ifdef USE_DIRECT_THREADED_CODE + enum OpCode* cp; +#endif Operation* p; size_t size; if (n <= 0) n = MIN_OPS_EXPAND_SIZE; n += reg->ops_alloc; - size = sizeof(Operation) * n; + size = sizeof(Operation) * n; p = (Operation* )xrealloc(reg->ops, size); CHECK_NULL_RETURN_MEMERR(p); +#ifdef USE_DIRECT_THREADED_CODE + size = sizeof(enum OpCode) * n; + cp = (enum OpCode* )xrealloc(reg->ocs, size); + CHECK_NULL_RETURN_MEMERR(cp); + reg->ocs = cp; +#endif + reg->ops = p; reg->ops_alloc = n; if (reg->ops_used == 0) @@ -181,8 +204,18 @@ ops_free(regex_t* reg) if (IS_NULL(reg->ops)) return ; for (i = 0; i < (int )reg->ops_used; i++) { - Operation* op = reg->ops + i; - switch (op->opcode) { + enum OpCode opcode; + Operation* op; + + op = reg->ops + i; + +#ifdef USE_DIRECT_THREADED_CODE + opcode = *(reg->ocs + i); +#else + opcode = op->opcode; +#endif + + switch (opcode) { case OP_EXACTMBN: xfree(op->exact_len_n.s); break; @@ -224,6 +257,10 @@ ops_free(regex_t* reg) } xfree(reg->ops); +#ifdef USE_DIRECT_THREADED_CODE + xfree(reg->ocs); + reg->ocs = 0; +#endif reg->ops = 0; reg->ops_curr = 0; @@ -383,7 +420,12 @@ add_op(regex_t* reg, int opcode) r = ops_new(reg); if (r != ONIG_NORMAL) return r; +#ifdef USE_DIRECT_THREADED_CODE + *(reg->ocs + (reg->ops_curr - reg->ops)) = opcode; +#else reg->ops_curr->opcode = opcode; +#endif + return 0; } diff --git a/src/regexec.c b/src/regexec.c index e351534..ab12d9c 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -298,7 +298,8 @@ bitset_on_num(BitSetRef bs) } extern void -onig_print_compiled_byte_code(FILE* f, Operation* p, Operation* start, OnigEncoding enc) +onig_print_compiled_byte_code(FILE* f, regex_t* reg, int index, + Operation* start, OnigEncoding enc) { int i, n; RelAddrType addr; @@ -307,9 +308,19 @@ onig_print_compiled_byte_code(FILE* f, Operation* p, Operation* start, OnigEncod OnigCodePoint code; ModeType mode; UChar *q; + Operation* p; + enum OpCode opcode; - fprintf(f, "%s", op2name(p->opcode)); - switch (p->opcode) { + p = reg->ops + index; + +#ifdef USE_DIRECT_THREADED_CODE + opcode = reg->ocs[index]; +#else + opcode = p->opcode; +#endif + + fprintf(f, "%s", op2name(opcode)); + switch (opcode) { case OP_EXACT1: p_string(f, 1, p->exact.s); break; case OP_EXACT2: @@ -358,7 +369,7 @@ onig_print_compiled_byte_code(FILE* f, Operation* p, Operation* start, OnigEncod case OP_CCLASS: case OP_CCLASS_NOT: - n = bitset_on_num(p->cclass.bs); + n = bitset_on_num(p->cclass.bsp); fprintf(f, ":%d", n); break; case OP_CCLASS_MB: @@ -381,7 +392,7 @@ onig_print_compiled_byte_code(FILE* f, Operation* p, Operation* start, OnigEncod OnigCodePoint* codes; codes = (OnigCodePoint* )p->cclass_mix.mb; - n = bitset_on_num(p->cclass_mix.bs); + n = bitset_on_num(p->cclass_mix.bsp); GET_CODE_POINT(ncode, codes); codes++; @@ -598,7 +609,7 @@ onig_print_compiled_byte_code(FILE* f, Operation* p, Operation* start, OnigEncod break; default: - fprintf(stderr, "onig_print_compiled_byte_code: undefined code %d\n", p->opcode); + fprintf(stderr, "onig_print_compiled_byte_code: undefined code %d\n", opcode); break; } } @@ -621,7 +632,7 @@ onig_print_compiled_byte_code_list(FILE* f, regex_t* reg) int pos = bp - start; fprintf(f, "%4d: ", pos); - onig_print_compiled_byte_code(f, bp, start, reg->enc); + onig_print_compiled_byte_code(f, reg, pos, start, reg->enc); fprintf(f, "\n"); bp++; } @@ -2417,10 +2428,11 @@ typedef struct { fputs((char* )buf, stderr);\ for (i = 0; i < 20 - (bp - buf); i++) fputc(' ', stderr);\ if (xp == FinishCode)\ - fprintf(stderr, "----: ");\ - else\ + fprintf(stderr, "----: finish");\ + else {\ fprintf(stderr, "%4d: ", (int )(xp - reg->ops));\ - onig_print_compiled_byte_code(stderr, xp, reg->ops, encode);\ + onig_print_compiled_byte_code(stderr, reg, (int )(xp - reg->ops), reg->ops, encode);\ + }\ fprintf(stderr, "\n");\ } while(0); #else @@ -2437,7 +2449,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, { #if defined(USE_DIRECT_THREADED_CODE) - static Operation FinishCode[] = { { .opaddr=&&L_FINISH, .opcode=OP_FINISH } }; + static Operation FinishCode[] = { { .opaddr=&&L_FINISH } }; #else static Operation FinishCode[] = { { OP_FINISH } }; #endif @@ -2579,7 +2591,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, if (IS_NULL(msa)) { for (i = 0; i < reg->ops_used; i++) { const void* addr; - addr = opcode_to_label[p->opcode]; + addr = opcode_to_label[reg->ocs[i]]; p->opaddr = addr; p++; } @@ -3606,7 +3618,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, #endif empty_check_found: /* empty loop founded, skip next instruction */ -#ifdef ONIG_DEBUG +#if defined(ONIG_DEBUG) && !defined(USE_DIRECT_THREADED_CODE) switch (p->opcode) { case OP_JUMP: case OP_PUSH: @@ -4061,7 +4073,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, STACK_SAVE; return ONIGERR_UNDEFINED_BYTECODE; -#ifdef ONIG_DEBUG +#if defined(ONIG_DEBUG) && !defined(USE_DIRECT_THREADED_CODE) unexpected_bytecode_error: STACK_SAVE; return ONIGERR_UNEXPECTED_BYTECODE; diff --git a/src/regint.h b/src/regint.h index 65ffdd5..7d7f6d2 100644 --- a/src/regint.h +++ b/src/regint.h @@ -911,10 +911,6 @@ typedef struct { } callout_name; #endif }; - -#ifdef USE_DIRECT_THREADED_CODE - enum OpCode opcode; -#endif } Operation; typedef struct { @@ -931,6 +927,9 @@ typedef struct { struct re_pattern_buffer { /* common members of BBuf(bytes-buffer) */ Operation* ops; +#ifdef USE_DIRECT_THREADED_CODE + enum OpCode* ocs; +#endif Operation* ops_curr; unsigned int ops_used; /* used space for ops */ unsigned int ops_alloc; /* allocated space for ops */