diff options
author | Yves Orton <demerphq@gmail.com> | 2022-11-04 18:18:49 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2022-11-10 08:53:27 +0100 |
commit | d7c0b58cf68aeb7b08eee56a9e693a161f3f9106 (patch) | |
tree | 555699e8b51789a7f34f204e09d2b57c8331313e | |
parent | af94e2b4109a87a2c399caa8aea8cbbcad6696f3 (diff) | |
download | perl-d7c0b58cf68aeb7b08eee56a9e693a161f3f9106.tar.gz |
regcomp.c - add a PARNO() macro to wrap the ARG() macro
We used the ARG() macro to access the parno data for the OPEN
and CLOSE regops. This made it difficult to find what needed to
change when the type and size or location of this data in the
node was modified. Replacing this access with a specific macro
makes the code more legible and future proof.
This was actually backported from finding everything that broke
by changing the regnode type for OPEN and CLOSE to 2L and moving
the paren parameter to the 2L slot. We might do something like this
in the future and separating the PARNO() macros from their
implementation will make it easier.
-rw-r--r-- | regcomp.c | 26 | ||||
-rw-r--r-- | regcomp.h | 3 | ||||
-rw-r--r-- | regexec.c | 8 |
3 files changed, 21 insertions, 16 deletions
@@ -4722,7 +4722,7 @@ S_study_chunk(pTHX_ /* vars about capture buffers in the pattern */ I32 pars = 0; /* count of OPEN opcodes */ - I32 is_par = OP(scan) == OPEN ? ARG(scan) : 0; /* is this op an OPEN? */ + I32 is_par = OP(scan) == OPEN ? PARNO(scan) : 0; /* is this op an OPEN? */ /* vars about whether this pattern contains something that can match * infinitely long strings, eg, X* or X+ */ @@ -5838,13 +5838,13 @@ S_study_chunk(pTHX_ if (RExC_open_parens) { /*open->CURLYM*/ - RExC_open_parens[ARG(nxt1)] = REGNODE_OFFSET(oscan); + RExC_open_parens[PARNO(nxt1)] = REGNODE_OFFSET(oscan); /*close->while*/ - RExC_close_parens[ARG(nxt1)] = REGNODE_OFFSET(nxt) + 2; + RExC_close_parens[PARNO(nxt1)] = REGNODE_OFFSET(nxt) + 2; } /* Now we know that nxt2 is the only contents: */ - oscan->flags = (U8)ARG(nxt); + oscan->flags = (U8)PARNO(nxt); OP(oscan) = CURLYN; OP(nxt1) = NOTHING; /* was OPEN. */ @@ -5886,13 +5886,13 @@ S_study_chunk(pTHX_ /* note that we have changed the type of oscan to CURLYM here */ regnode *nxt1 = REGNODE_AFTER_type(oscan, tregnode_CURLYM); /* OPEN*/ - oscan->flags = (U8)ARG(nxt); + oscan->flags = (U8)PARNO(nxt); if (RExC_open_parens) { /*open->CURLYM*/ - RExC_open_parens[ARG(nxt1)] = REGNODE_OFFSET(oscan); + RExC_open_parens[PARNO(nxt1)] = REGNODE_OFFSET(oscan); /*close->NOTHING*/ - RExC_close_parens[ARG(nxt1)] = REGNODE_OFFSET(nxt2) + RExC_close_parens[PARNO(nxt1)] = REGNODE_OFFSET(nxt2) + 1; } OP(nxt1) = OPTIMIZED; /* was OPEN. */ @@ -6558,21 +6558,21 @@ S_study_chunk(pTHX_ #endif } else if (OP(scan) == OPEN) { - if (stopparen != (I32)ARG(scan)) + if (stopparen != (I32)PARNO(scan)) pars++; } else if (OP(scan) == CLOSE) { - if (stopparen == (I32)ARG(scan)) { + if (stopparen == (I32)PARNO(scan)) { break; } - if ((I32)ARG(scan) == is_par) { + if ((I32)PARNO(scan) == is_par) { next = regnext(scan); if ( next && (OP(next) != WHILEM) && next < last) is_par = 0; /* Disable optimization */ } if (data) { - *(data->last_closep) = ARG(scan); + *(data->last_closep) = PARNO(scan); *(data->last_close_opp) = scan; } } @@ -21973,7 +21973,9 @@ Perl_regprop(pTHX_ const regexp *prog, SV *sv, const regnode *o, const regmatch_ || k == GROUPP || op == ACCEPT) { AV *name_list= NULL; - U32 parno= op == ACCEPT ? (U32)ARG2L(o) : ARG(o); + U32 parno= (op == ACCEPT) ? (U32)ARG2L(o) : + (op == OPEN || op == CLOSE) ? (U32)PARNO(o) : + (U32)ARG(o); Perl_sv_catpvf(aTHX_ sv, "%" UVuf, (UV)parno); /* Parenth number */ if ( RXp_PAREN_NAMES(prog) ) { name_list= MUTABLE_AV(progi->data->data[progi->name_list_idx]); @@ -386,6 +386,8 @@ struct regnode_ssc { ((struct regnode_string *)p)->string) #define OPERANDs(p) STRINGs(p) +#define PARNO(p) ARG(p) /* APPLIES for OPEN and CLOSE only */ + /* Long strings. Currently limited to length 18 bits, which handles a 262000 * byte string. The limiting factor is the 16 bit 'next_off' field, which * points to the next regnode, so the furthest away it can be is 2**16. On @@ -436,6 +438,7 @@ struct regnode_ssc { #define ARG2_LOC(p) (((struct regnode_2 *)p)->arg2) #define ARG2L_LOC(p) (((struct regnode_2L *)p)->arg2) + /* These should no longer be used directly in most cases. Please use * the REGNODE_AFTER() macros instead. */ #define NODE_STEP_REGNODE 1 /* sizeof(regnode)/sizeof(regnode) */ @@ -183,7 +183,7 @@ static const char non_utf8_target_but_utf8_required[] #define JUMPABLE(rn) ( \ OP(rn) == OPEN || \ (OP(rn) == CLOSE && \ - !EVAL_CLOSE_PAREN_IS(cur_eval,ARG(rn)) ) || \ + !EVAL_CLOSE_PAREN_IS(cur_eval,PARNO(rn)) ) || \ OP(rn) == EVAL || \ OP(rn) == SUSPEND || OP(rn) == IFMATCH || \ OP(rn) == PLUS || OP(rn) == MINMOD || \ @@ -8455,7 +8455,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog) #undef ST case OPEN: /* ( */ - n = ARG(scan); /* which paren pair */ + n = PARNO(scan); /* which paren pair */ rex->offs[n].start_tmp = locinput - reginfo->strbeg; if (n > maxopenparen) maxopenparen = n; @@ -8477,7 +8477,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog) case CLOSE: /* ) */ - n = ARG(scan); /* which paren pair */ + n = PARNO(scan); /* which paren pair */ CLOSE_CAPTURE(n, rex->offs[n].start_tmp, locinput - reginfo->strbeg); if ( EVAL_CLOSE_PAREN_IS( cur_eval, n ) ) @@ -8513,7 +8513,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog) if ( OP(cursor) != CLOSE ) continue; - n = ARG(cursor); + n = PARNO(cursor); if ( n > lastopen ) /* might be OPEN/CLOSE in the way */ continue; /* so skip this one */ |