diff options
-rw-r--r-- | mg.c | 8 | ||||
-rw-r--r-- | pp.c | 8 | ||||
-rw-r--r-- | pp_ctl.c | 12 | ||||
-rw-r--r-- | pp_hot.c | 36 | ||||
-rw-r--r-- | regcomp.c | 4 | ||||
-rw-r--r-- | regcomp_debug.c | 8 | ||||
-rw-r--r-- | regexec.c | 78 | ||||
-rw-r--r-- | regexp.h | 21 |
8 files changed, 88 insertions, 87 deletions
@@ -643,9 +643,7 @@ Perl_magic_regdata_cnt(pTHX_ SV *sv, MAGIC *mg) I32 paren = RX_LASTPAREN(rx); /* return the last filled */ - while ( paren >= 0 - && (RX_OFFS(rx)[paren].start == -1 - || RX_OFFS(rx)[paren].end == -1) ) + while ( paren >= 0 && !RX_OFFS_VALID(rx,paren) ) paren--; if (n == '-') { /* @- */ @@ -680,8 +678,8 @@ Perl_magic_regdatum_get(pTHX_ SV *sv, MAGIC *mg) if (paren < 0) return 0; if (paren <= (I32)RX_NPARENS(rx) && - (s = RX_OFFS(rx)[paren].start) != -1 && - (t = RX_OFFS(rx)[paren].end) != -1) + ((s = RX_OFFS_START(rx,paren)) != -1) && + ((t = RX_OFFS_END(rx,paren)) != -1)) { SSize_t i; @@ -6503,7 +6503,7 @@ PP(pp_split) /* we never pass the REXEC_COPY_STR flag, so it should * never get copied */ assert(!RX_MATCH_COPIED(rx)); - m = RX_OFFS(rx)[0].start + orig; + m = RX_OFFS_START(rx,0) + orig; if (gimme_scalar) { iters++; @@ -6518,8 +6518,8 @@ PP(pp_split) if (RX_NPARENS(rx)) { I32 i; for (i = 1; i <= (I32)RX_NPARENS(rx); i++) { - s = RX_OFFS(rx)[i].start + orig; - m = RX_OFFS(rx)[i].end + orig; + s = orig + RX_OFFS_START(rx,i); + m = orig + RX_OFFS_END(rx,i); /* japhy (07/27/01) -- the (m && s) test doesn't catch parens that didn't match -- they should be set to @@ -6541,7 +6541,7 @@ PP(pp_split) } } - s = RX_OFFS(rx)[0].end + orig; + s = RX_OFFS_END(rx,0) + orig; } } @@ -320,14 +320,14 @@ PP(pp_substcont) s = orig + (m - s); cx->sb_strend = s + (cx->sb_strend - m); } - cx->sb_m = m = RX_OFFS(rx)[0].start + orig; + cx->sb_m = m = RX_OFFS_START(rx,0) + orig; if (m > s) { if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ)) sv_catpvn_nomg_utf8_upgrade(dstr, s, m - s, nsv); else sv_catpvn_nomg(dstr, s, m-s); } - cx->sb_s = RX_OFFS(rx)[0].end + orig; + cx->sb_s = RX_OFFS_END(rx,0) + orig; { /* Update the pos() information. */ SV * const sv = (pm->op_pmflags & PMf_NONDESTRUCT) ? cx->sb_dstr : cx->sb_targ; @@ -407,8 +407,8 @@ Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx) *p++ = (UV)RX_SUBOFFSET(rx); *p++ = (UV)RX_SUBCOFFSET(rx); for (i = 0; i <= RX_NPARENS(rx); ++i) { - *p++ = (UV)RX_OFFS(rx)[i].start; - *p++ = (UV)RX_OFFS(rx)[i].end; + *p++ = (UV)RX_OFFSp(rx)[i].start; + *p++ = (UV)RX_OFFSp(rx)[i].end; } } @@ -438,8 +438,8 @@ S_rxres_restore(pTHX_ void **rsp, REGEXP *rx) RX_SUBOFFSET(rx) = (I32)*p++; RX_SUBCOFFSET(rx) = (I32)*p++; for (i = 0; i <= RX_NPARENS(rx); ++i) { - RX_OFFS(rx)[i].start = (I32)(*p++); - RX_OFFS(rx)[i].end = (I32)(*p++); + RX_OFFSp(rx)[i].start = (I32)(*p++); + RX_OFFSp(rx)[i].end = (I32)(*p++); } } @@ -3189,7 +3189,7 @@ PP(pp_match) if (global && (gimme != G_LIST || (dynpm->op_pmflags & PMf_CONTINUE))) { if (!mg) mg = sv_magicext_mglob(TARG); - MgBYTEPOS_set(mg, TARG, truebase, RXp_OFFS(prog)[0].end); + MgBYTEPOS_set(mg, TARG, truebase, RXp_OFFS_END(prog,0)); if (RXp_ZERO_LEN(prog)) mg->mg_flags |= MGf_MINMATCH; else @@ -3211,20 +3211,16 @@ PP(pp_match) EXTEND(SP, nparens + i); EXTEND_MORTAL(nparens + i); for (i = !i; i <= nparens; i++) { - if (LIKELY((RXp_OFFS(prog)[i].start != -1) - && RXp_OFFS(prog)[i].end != -1 )) + if (LIKELY(RXp_OFFS_VALID(prog,i))) { - const I32 len = RXp_OFFS(prog)[i].end - RXp_OFFS(prog)[i].start; - const char * const s = RXp_OFFS(prog)[i].start + truebase; - if (UNLIKELY( RXp_OFFS(prog)[i].end < 0 - || RXp_OFFS(prog)[i].start < 0 - || len < 0 - || len > strend - s) + const I32 len = RXp_OFFS_END(prog,i) - RXp_OFFS_START(prog,i); + const char * const s = RXp_OFFS_START(prog,i) + truebase; + if ( UNLIKELY( len < 0 || len > strend - s) ) DIE(aTHX_ "panic: pp_match start/end pointers, i=%ld, " "start=%ld, end=%ld, s=%p, strend=%p, len=%" UVuf, - (long) i, (long) RXp_OFFS(prog)[i].start, - (long)RXp_OFFS(prog)[i].end, s, strend, (UV) len); + (long) i, (long) RXp_OFFS_START(prog,i), + (long)RXp_OFFS_END(prog,i), s, strend, (IV) len); PUSHs(newSVpvn_flags(s, len, (DO_UTF8(TARG)) ? SVf_UTF8|SVs_TEMP @@ -3235,7 +3231,7 @@ PP(pp_match) } } if (global) { - curpos = (UV)RXp_OFFS(prog)[0].end; + curpos = (UV)RXp_OFFS_END(prog,0); had_zerolen = RXp_ZERO_LEN(prog); PUTBACK; /* EVAL blocks may use stack */ r_flags |= REXEC_IGNOREPOS | REXEC_NOT_FIRST; @@ -4519,8 +4515,8 @@ PP(pp_subst) char *d, *m; if (RXp_MATCH_TAINTED(prog)) /* run time pattern taint, eg locale */ rxtainted |= SUBST_TAINT_PAT; - m = orig + RXp_OFFS(prog)[0].start; - d = orig + RXp_OFFS(prog)[0].end; + m = orig + RXp_OFFS_START(prog,0); + d = orig + RXp_OFFS_END(prog,0); s = orig; if (m - s > strend - d) { /* faster to shorten from end */ I32 i; @@ -4550,7 +4546,7 @@ PP(pp_subst) } else { char *d, *m; - d = s = RXp_OFFS(prog)[0].start + orig; + d = s = RXp_OFFS_START(prog,0) + orig; do { I32 i; if (UNLIKELY(iters++ > maxiters)) @@ -4558,7 +4554,7 @@ PP(pp_subst) /* run time pattern taint, eg locale */ if (UNLIKELY(RXp_MATCH_TAINTED(prog))) rxtainted |= SUBST_TAINT_PAT; - m = RXp_OFFS(prog)[0].start + orig; + m = RXp_OFFS_START(prog,0) + orig; if ((i = m - s)) { if (s != d) Move(s, d, i, char); @@ -4568,7 +4564,7 @@ PP(pp_subst) Copy(c, d, clen, char); d += clen; } - s = RXp_OFFS(prog)[0].end + orig; + s = RXp_OFFS_END(prog,0) + orig; } while (CALLREGEXEC(rx, s, strend, orig, s == m, /* don't match same null twice */ TARG, NULL, @@ -4611,7 +4607,7 @@ PP(pp_subst) if (RXp_MATCH_TAINTED(prog)) /* run time pattern taint, eg locale */ rxtainted |= SUBST_TAINT_PAT; repl = dstr; - s = RXp_OFFS(prog)[0].start + orig; + s = RXp_OFFS_START(prog,0) + orig; dstr = newSVpvn_flags(orig, s-orig, SVs_TEMP | (DO_UTF8(TARG) ? SVf_UTF8 : 0)); if (!c) { @@ -4641,9 +4637,9 @@ PP(pp_subst) s = orig + (old_s - old_orig); strend = s + (strend - old_s); } - m = RXp_OFFS(prog)[0].start + orig; + m = RXp_OFFS_START(prog,0) + orig; sv_catpvn_nomg_maybeutf8(dstr, s, m - s, DO_UTF8(TARG)); - s = RXp_OFFS(prog)[0].end + orig; + s = RXp_OFFS_END(prog,0) + orig; if (first) { /* replacement already stringified */ if (clen) @@ -15718,9 +15718,9 @@ S_handle_names_wildcard(pTHX_ const char * wname, /* wildcard name to match */ * so we could match anywhere in that string. We have to rule out * matching a code point line */ char * this_name_start = all_names_start - + RX_OFFS(subpattern_re)->start; + + RX_OFFS_START(subpattern_re,0); char * this_name_end = all_names_start - + RX_OFFS(subpattern_re)->end; + + RX_OFFS_END(subpattern_re,0); char * cp_start; char * cp_end; UV cp = 0; /* Silences some compilers */ diff --git a/regcomp_debug.c b/regcomp_debug.c index c7c42f6941..0b2cc06170 100644 --- a/regcomp_debug.c +++ b/regcomp_debug.c @@ -514,15 +514,15 @@ Perl_regprop(pTHX_ const regexp *prog, SV *sv, const regnode *o, const regmatch_ } if ( k == REF && reginfo) { U32 n = ARG(o); /* which paren pair */ - I32 ln = prog->offs[n].start; - if (prog->lastparen < n || ln == -1 || prog->offs[n].end == -1) + I32 ln = RXp_OFFS_START(prog,n); + if (prog->lastparen < n || ln == -1 || RXp_OFFS_END(prog,n) == -1) Perl_sv_catpvf(aTHX_ sv, ": FAIL"); - else if (ln == prog->offs[n].end) + else if (ln == RXp_OFFS_END(prog,n)) Perl_sv_catpvf(aTHX_ sv, ": ACCEPT - EMPTY STRING"); else { const char *s = reginfo->strbeg + ln; Perl_sv_catpvf(aTHX_ sv, ": "); - Perl_pv_pretty( aTHX_ sv, s, prog->offs[n].end - prog->offs[n].start, 32, 0, 0, + Perl_pv_pretty( aTHX_ sv, s, RXp_OFFS_END(prog,n) - RXp_OFFS_START(prog,n), 32, 0, 0, PERL_PV_ESCAPE_UNI_DETECT|PERL_PV_PRETTY_NOCLEAR|PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_QUOTE ); } } @@ -3499,7 +3499,7 @@ S_reg_set_capture_string(pTHX_ REGEXP * const rx, } if (max == -1) max = (PL_sawampersand & SAWAMPERSAND_LEFT) - ? prog->offs[0].start + ? RXp_OFFS_START(prog,0) : 0; assert(max >= 0 && max <= strend - strbeg); } @@ -3514,17 +3514,18 @@ S_reg_set_capture_string(pTHX_ REGEXP * const rx, * by a capture. Due to lookbehind, this may be to * the left of $&, so we have to scan all captures */ while (min && n <= prog->lastparen) { - if ( prog->offs[n].start != -1 - && prog->offs[n].start < min) + I32 start = RXp_OFFS_START(prog,n); + if ( start != -1 + && start < min) { - min = prog->offs[n].start; + min = start; } n++; } if ((PL_sawampersand & SAWAMPERSAND_RIGHT) - && min > prog->offs[0].end + && min > RXp_OFFS_END(prog,0) ) - min = prog->offs[0].end; + min = RXp_OFFS_END(prog,0); } @@ -4215,7 +4216,7 @@ Perl_regexec_flags(pTHX_ REGEXP * const rx, char *stringarg, char *strend, /* s/// doesn't like it if $& is earlier than where we asked it to * start searching (which can happen on something like /.\G/) */ if ( (flags & REXEC_FAIL_ON_UNDERFLOW) - && (prog->offs[0].start < stringarg - strbeg)) + && (RXp_OFFS_START(prog,0) < stringarg - strbeg)) { /* this should only be possible under \G */ assert(prog->intflags & PREGf_GPOS_SEEN); @@ -4513,7 +4514,7 @@ S_reg_check_named_buff_matched(const regexp *rex, const regnode *scan) for ( n=0; n<SvIVX(sv_dat); n++ ) { if ((I32)rex->lastparen >= nums[n] && - rex->offs[nums[n]].end != -1) + RXp_OFFS_END(rex,nums[n]) != -1) { return nums[n]; } @@ -8531,7 +8532,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog) case GROUPP: /* (?(1)) */ n = ARG(scan); /* which paren pair */ - sw = cBOOL(rex->lastparen >= n && rex->offs[n].end != -1); + sw = cBOOL(rex->lastparen >= n && RXp_OFFS_END(rex,n) != -1); break; case GROUPPN: /* (?(<name>)) */ @@ -11814,8 +11815,7 @@ Perl_reg_named_buff_fetch(pTHX_ REGEXP * const r, SV * const namesv, AV * const retarray = (flags & RXapif_ALL) ? newAV_alloc_x(SvIVX(sv_dat)) : NULL; for ( i=0; i<SvIVX(sv_dat); i++ ) { if ((I32)(rx->nparens) >= nums[i] - && rx->offs[nums[i]].start != -1 - && rx->offs[nums[i]].end != -1) + && RXp_OFFS_VALID(rx,nums[i])) { ret = newSVpvs(""); CALLREG_NUMBUF_FETCH(r, nums[i], ret); @@ -11894,8 +11894,7 @@ Perl_reg_named_buff_nextkey(pTHX_ REGEXP * const r, const U32 flags) I32 *nums = (I32*)SvPVX(sv_dat); for ( i = 0; i < SvIVX(sv_dat); i++ ) { if ((I32)(rx->lastparen) >= nums[i] && - rx->offs[nums[i]].start != -1 && - rx->offs[nums[i]].end != -1) + RXp_OFFS_VALID(rx,nums[i])) { parno = nums[i]; break; @@ -11956,8 +11955,7 @@ Perl_reg_named_buff_all(pTHX_ REGEXP * const r, const U32 flags) I32 *nums = (I32*)SvPVX(sv_dat); for ( i = 0; i < SvIVX(sv_dat); i++ ) { if ((I32)(rx->lastparen) >= nums[i] && - rx->offs[nums[i]].start != -1 && - rx->offs[nums[i]].end != -1) + RXp_OFFS_VALID(rx,nums[i])) { parno = nums[i]; break; @@ -11978,7 +11976,7 @@ Perl_reg_numbered_buff_fetch(pTHX_ REGEXP * const r, const I32 paren, { struct regexp *const rx = ReANY(r); char *s = NULL; - SSize_t i = 0; + SSize_t i,t = 0; SSize_t s1, t1; I32 n = paren; @@ -12010,24 +12008,23 @@ Perl_reg_numbered_buff_fetch(pTHX_ REGEXP * const r, const I32 paren, n = RX_BUFF_IDX_FULLMATCH; if ((n == RX_BUFF_IDX_PREMATCH || n == RX_BUFF_IDX_CARET_PREMATCH) - && rx->offs[0].start != -1) + && (i = RXp_OFFS_START(rx,0)) != -1) { /* $`, ${^PREMATCH} */ - i = rx->offs[0].start; s = rx->subbeg; } else if ((n == RX_BUFF_IDX_POSTMATCH || n == RX_BUFF_IDX_CARET_POSTMATCH) - && rx->offs[0].end != -1) + && (t = RXp_OFFS_END(rx,0)) != -1) { /* $', ${^POSTMATCH} */ - s = rx->subbeg - rx->suboffset + rx->offs[0].end; - i = rx->sublen + rx->suboffset - rx->offs[0].end; + s = rx->subbeg - rx->suboffset + t; + i = rx->sublen + rx->suboffset - t; } else if (inRANGE(n, 0, (I32)rx->nparens) && - (s1 = rx->offs[n].start) != -1 && - (t1 = rx->offs[n].end) != -1) + ((s1 = RXp_OFFS_START(rx,n)) != -1 && + (t1 = RXp_OFFS_END(rx,n)) != -1)) { /* $&, ${^MATCH}, $1 ... */ i = t1 - s1; @@ -12123,33 +12120,32 @@ Perl_reg_numbered_buff_length(pTHX_ REGEXP * const r, const SV * const sv, switch (paren) { case RX_BUFF_IDX_CARET_PREMATCH: /* ${^PREMATCH} */ case RX_BUFF_IDX_PREMATCH: /* $` */ - if (rx->offs[0].start != -1) { - i = rx->offs[0].start; - if (i > 0) { - s1 = 0; - t1 = i; - goto getlen; - } + if ( (i= RXp_OFFS_START(rx,0)) != -1) { + if (i > 0) { + s1 = 0; + t1 = i; + goto getlen; } + } return 0; case RX_BUFF_IDX_CARET_POSTMATCH: /* ${^POSTMATCH} */ case RX_BUFF_IDX_POSTMATCH: /* $' */ - if (rx->offs[0].end != -1) { - i = rx->sublen - rx->offs[0].end; - if (i > 0) { - s1 = rx->offs[0].end; - t1 = rx->sublen; - goto getlen; - } + if ( (i = RXp_OFFS_END(rx,0)) != -1) { + i = rx->sublen - i; + if (i > 0) { + s1 = RXp_OFFS_END(rx,0); + t1 = rx->sublen; + goto getlen; } + } return 0; default: /* $& / ${^MATCH}, $1, $2, ... */ - if (paren <= (I32)rx->nparens && - (s1 = rx->offs[paren].start) != -1 && - (t1 = rx->offs[paren].end) != -1) - { + if (paren <= (I32)rx->nparens && + (s1 = RXp_OFFS_START(rx,paren)) != -1 && + (t1 = RXp_OFFS_END(rx,paren)) != -1) + { i = t1 - s1; goto getlen; } else { @@ -174,7 +174,18 @@ typedef struct regexp { } regexp; -# define RXp_PAREN_NAMES(rx) ((rx)->paren_names) +#define RXp_PAREN_NAMES(rx) ((rx)->paren_names) + +#define RXp_OFFS_START(rx,n) ((rx)->offs[(n)].start) + +#define RXp_OFFS_END(rx,n) ((rx)->offs[(n)].end) + +#define RXp_OFFS_VALID(rx,n) \ + ( (rx)->offs[(n)].end != -1 && (rx)->offs[(n)].start != -1 ) + +#define RX_OFFS_START(rx_sv,n) RXp_OFFS_START(ReANY(rx_sv),n) +#define RX_OFFS_END(rx_sv,n) RXp_OFFS_END(ReANY(rx_sv),n) +#define RX_OFFS_VALID(rx_sv,n) RXp_OFFS_VALID(ReANY(rx_sv),n) /* used for high speed searches */ typedef struct re_scream_pos_data_s @@ -538,8 +549,8 @@ and check for NULL. # define RXp_SUBOFFSET(prog) (prog->suboffset) # define RX_SUBOFFSET(rx_sv) (RXp_SUBOFFSET(ReANY(rx_sv))) # define RX_SUBCOFFSET(rx_sv) (ReANY(rx_sv)->subcoffset) -# define RXp_OFFS(prog) (prog->offs) -# define RX_OFFS(rx_sv) (RXp_OFFS(ReANY(rx_sv))) +# define RXp_OFFSp(prog) (prog->offs) +# define RX_OFFSp(rx_sv) (RXp_OFFSp(ReANY(rx_sv))) # define RXp_NPARENS(prog) (prog->nparens) # define RX_NPARENS(rx_sv) (RXp_NPARENS(ReANY(rx_sv))) # define RX_SUBLEN(rx_sv) (ReANY(rx_sv)->sublen) @@ -555,8 +566,8 @@ and check for NULL. # define RX_SAVED_COPY(rx_sv) (RXp_SAVED_COPY(ReANY(rx_sv))) /* last match was zero-length */ # define RXp_ZERO_LEN(prog) \ - (RXp_OFFS(prog)[0].start + (SSize_t)RXp_GOFS(prog) \ - == RXp_OFFS(prog)[0].end) + (RXp_OFFS_START(prog,0) + (SSize_t)RXp_GOFS(prog) \ + == RXp_OFFS_END(prog,0)) # define RX_ZERO_LEN(rx_sv) (RXp_ZERO_LEN(ReANY(rx_sv))) #endif /* PLUGGABLE_RE_EXTENSION */ |