From: Nicholas Clark Date: Wed, 2 Jan 2008 12:06:05 +0000 (+0000) Subject: Wrap all deferences of struct regexp* in macros RX_*() [and for X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=07bc277f32c1d7aff237dd3f55d558b5d4b93314;p=p5sagit%2Fp5-mst-13.2.git Wrap all deferences of struct regexp* in macros RX_*() [and for regcomp.c and regexec.c RXp_* where necessary] so that in future we can maintain source compatibility when we add an extra level of dereferencing. p4raw-id: //depot/perl@32802 --- diff --git a/dump.c b/dump.c index 126fe89..9010c65 100644 --- a/dump.c +++ b/dump.c @@ -552,7 +552,7 @@ Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, const PMOP *pm) Perl_dump_indent(aTHX_ level, file, "PMf_REPL = "); op_dump(pm->op_pmreplrootu.op_pmreplroot); } - if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) { + if (pm->op_pmflags || (PM_GETRE(pm) && RX_CHECK_SUBSTR(PM_GETRE(pm)))) { SV * const tmpsv = pm_description(pm); Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : ""); SvREFCNT_dec(tmpsv); @@ -579,15 +579,15 @@ S_pm_description(pTHX_ const PMOP *pm) #endif if (regex) { - if (regex->extflags & RXf_TAINTED) + if (RX_EXTFLAGS(regex) & RXf_TAINTED) sv_catpv(desc, ",TAINTED"); - if (regex->check_substr) { - if (!(regex->extflags & RXf_NOSCAN)) + if (RX_CHECK_SUBSTR(regex)) { + if (!(RX_EXTFLAGS(regex) & RXf_NOSCAN)) sv_catpv(desc, ",SCANFIRST"); - if (regex->extflags & RXf_CHECK_ALL) + if (RX_EXTFLAGS(regex) & RXf_CHECK_ALL) sv_catpv(desc, ",ALL"); } - if (regex->extflags & RXf_SKIPWHITE) + if (RX_EXTFLAGS(regex) & RXf_SKIPWHITE) sv_catpv(desc, ",SKIPWHITE"); } @@ -1283,17 +1283,17 @@ Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32 Perl_dump_indent(aTHX_ level, file, " MG_OBJ = 0x%"UVxf"\n", PTR2UV(mg->mg_obj)); if (mg->mg_type == PERL_MAGIC_qr) { - const regexp * const re = (regexp *)mg->mg_obj; + REGEXP* const re = (REGEXP *)mg->mg_obj; SV * const dsv = sv_newmortal(); const char * const s = pv_pretty(dsv, RX_WRAPPED(re), RX_WRAPLEN(re), 60, NULL, NULL, ( PERL_PV_PRETTY_QUOTE | PERL_PV_ESCAPE_RE | PERL_PV_PRETTY_ELLIPSES | - ((re->extflags & RXf_UTF8) ? PERL_PV_ESCAPE_UNI : 0)) + ((RX_EXTFLAGS(re) & RXf_UTF8) ? PERL_PV_ESCAPE_UNI : 0)) ); Perl_dump_indent(aTHX_ level+1, file, " PAT = %s\n", s); Perl_dump_indent(aTHX_ level+1, file, " REFCNT = %"IVdf"\n", - (IV)re->refcnt); + (IV)RX_REFCNT(re)); } if (mg->mg_flags & MGf_REFCOUNTED) do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */ diff --git a/ext/B/B.xs b/ext/B/B.xs index 6d5d2ab..a6f1d22 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -1121,7 +1121,7 @@ PMOP_reflags(o) ST(0) = sv_newmortal(); rx = PM_GETRE(o); if (rx) - sv_setuv(ST(0), rx->extflags); + sv_setuv(ST(0), RX_EXTFLAGS(rx)); #endif @@ -1512,7 +1512,7 @@ MODULE = B PACKAGE = B::REGEXP IV REGEX(sv) - B::PVMG sv + B::REGEXP sv CODE: RETVAL = PTR2IV(((struct xregexp *)SvANY(sv))->xrx_regexp); OUTPUT: @@ -1520,7 +1520,7 @@ REGEX(sv) SV* precomp(sv) - B::PVMG sv + B::REGEXP sv REGEXP* rx = NO_INIT CODE: rx = ((struct xregexp *)SvANY(sv))->xrx_regexp; diff --git a/ext/re/re.xs b/ext/re/re.xs index 72e4a70..dc73b75 100644 --- a/ext/re/re.xs +++ b/ext/re/re.xs @@ -107,7 +107,7 @@ PPCODE: const char *fptr = INT_PAT_MODS; char ch; - U16 match_flags = (U16)((re->extflags & PMf_COMPILETIME) + U16 match_flags = (U16)((RX_EXTFLAGS(re) & PMf_COMPILETIME) >> RXf_PMf_STD_PMMOD_SHIFT); while((ch = *fptr++)) { @@ -118,7 +118,7 @@ PPCODE: } pattern = sv_2mortal(newSVpvn(RX_PRECOMP(re),RX_PRELEN(re))); - if (re->extflags & RXf_UTF8) SvUTF8_on(pattern); + if (RX_EXTFLAGS(re) & RXf_UTF8) SvUTF8_on(pattern); /* return the pattern and the modifiers */ XPUSHs(pattern); @@ -128,7 +128,7 @@ PPCODE: /* Scalar, so use the string that Perl would return */ /* return the pattern in (?msix:..) format */ pattern = sv_2mortal(newSVpvn(RX_WRAPPED(re),RX_WRAPLEN(re))); - if (re->extflags & RXf_UTF8) + if (RX_EXTFLAGS(re) & RXf_UTF8) SvUTF8_on(pattern); XPUSHs(pattern); XSRETURN(1); @@ -169,15 +169,15 @@ PPCODE: { SV *an = &PL_sv_no; SV *fl = &PL_sv_no; - if (re->anchored_substr) { - an = newSVsv(re->anchored_substr); - } else if (re->anchored_utf8) { - an = newSVsv(re->anchored_utf8); + if (RX_ANCHORED_SUBSTR(re)) { + an = newSVsv(RX_ANCHORED_SUBSTR(re)); + } else if (RX_ANCHORED_UTF8(re)) { + an = newSVsv(RX_ANCHORED_UTF8(re)); } - if (re->float_substr) { - fl = newSVsv(re->float_substr); - } else if (re->float_utf8) { - fl = newSVsv(re->float_utf8); + if (RX_FLOAT_SUBSTR(re)) { + fl = newSVsv(RX_FLOAT_SUBSTR(re)); + } else if (RX_FLOAT_UTF8(re)) { + fl = newSVsv(RX_FLOAT_UTF8(re)); } XPUSHs(an); XPUSHs(fl); diff --git a/mg.c b/mg.c index 2a1eefd..b81570d 100644 --- a/mg.c +++ b/mg.c @@ -516,14 +516,14 @@ Perl_magic_regdata_cnt(pTHX_ SV *sv, MAGIC *mg) if (rx) { if (mg->mg_obj) { /* @+ */ /* return the number possible */ - return rx->nparens; + return RX_NPARENS(rx); } else { /* @- */ - I32 paren = rx->lastparen; + I32 paren = RX_LASTPAREN(rx); /* return the last filled */ while ( paren >= 0 - && (rx->offs[paren].start == -1 - || rx->offs[paren].end == -1) ) + && (RX_OFFS(rx)[paren].start == -1 + || RX_OFFS(rx)[paren].end == -1) ) paren--; return (U32)paren; } @@ -545,9 +545,9 @@ Perl_magic_regdatum_get(pTHX_ SV *sv, MAGIC *mg) register I32 t; if (paren < 0) return 0; - if (paren <= (I32)rx->nparens && - (s = rx->offs[paren].start) != -1 && - (t = rx->offs[paren].end) != -1) + if (paren <= (I32)RX_NPARENS(rx) && + (s = RX_OFFS(rx)[paren].start) != -1 && + (t = RX_OFFS(rx)[paren].end) != -1) { register I32 i; if (mg->mg_obj) /* @+ */ @@ -556,7 +556,7 @@ Perl_magic_regdatum_get(pTHX_ SV *sv, MAGIC *mg) i = s; if (i > 0 && RX_MATCH_UTF8(rx)) { - const char * const b = rx->subbeg; + const char * const b = RX_SUBBEG(rx); if (b) i = utf8_length((U8*)b, (U8*)(b+i)); } @@ -632,14 +632,14 @@ Perl_magic_len(pTHX_ SV *sv, MAGIC *mg) } case '+': if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { - paren = rx->lastparen; + paren = RX_LASTPAREN(rx); if (paren) goto getparen; } return 0; case '\016': /* ^N */ if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { - paren = rx->lastcloseparen; + paren = RX_LASTCLOSEPAREN(rx); if (paren) goto getparen; } @@ -886,8 +886,8 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg) break; case '+': if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { - if (rx->lastparen) { - CALLREG_NUMBUF_FETCH(rx,rx->lastparen,sv); + if (RX_LASTPAREN(rx)) { + CALLREG_NUMBUF_FETCH(rx,RX_LASTPAREN(rx),sv); break; } } @@ -895,8 +895,8 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg) break; case '\016': /* ^N */ if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { - if (rx->lastcloseparen) { - CALLREG_NUMBUF_FETCH(rx,rx->lastcloseparen,sv); + if (RX_LASTCLOSEPAREN(rx)) { + CALLREG_NUMBUF_FETCH(rx,RX_LASTCLOSEPAREN(rx),sv); break; } diff --git a/op.c b/op.c index 3828894..42f997d 100644 --- a/op.c +++ b/op.c @@ -3532,7 +3532,7 @@ Perl_pmruntime(pTHX_ OP *o, OP *expr, bool isreg) if (curop == repl && !(repl_has_vars && (!PM_GETRE(pm) - || PM_GETRE(pm)->extflags & RXf_EVAL_SEEN))) + || RX_EXTFLAGS(PM_GETRE(pm)) & RXf_EVAL_SEEN))) { pm->op_pmflags |= PMf_CONST; /* const for long enough */ prepend_elem(o->op_type, scalar(repl), o); diff --git a/perl.h b/perl.h index 95702e1..3bad1eb 100644 --- a/perl.h +++ b/perl.h @@ -201,13 +201,13 @@ #define CALLREGCOMP_ENG(prog, sv, flags) \ CALL_FPTR(((prog)->comp))(aTHX_ sv, flags) #define CALLREGEXEC(prog,stringarg,strend,strbeg,minend,screamer,data,flags) \ - CALL_FPTR((prog)->engine->exec)(aTHX_ (prog),(stringarg),(strend), \ + CALL_FPTR(RX_ENGINE(prog)->exec)(aTHX_ (prog),(stringarg),(strend), \ (strbeg),(minend),(screamer),(data),(flags)) #define CALLREG_INTUIT_START(prog,sv,strpos,strend,flags,data) \ - CALL_FPTR((prog)->engine->intuit)(aTHX_ (prog), (sv), (strpos), \ + CALL_FPTR(RX_ENGINE(prog)->intuit)(aTHX_ (prog), (sv), (strpos), \ (strend),(flags),(data)) #define CALLREG_INTUIT_STRING(prog) \ - CALL_FPTR((prog)->engine->checkstr)(aTHX_ (prog)) + CALL_FPTR(RX_ENGINE(prog)->checkstr)(aTHX_ (prog)) #define CALLREG_AS_STR(mg,lp,flags,haseval) \ Perl_reg_stringify(aTHX_ (mg), (lp), (flags), (haseval)) @@ -217,56 +217,56 @@ Perl_pregfree(aTHX_ (prog)) #define CALLREGFREE_PVT(prog) \ - if(prog) CALL_FPTR((prog)->engine->free)(aTHX_ (prog)) + if(prog) CALL_FPTR(RX_ENGINE(prog)->free)(aTHX_ (prog)) #define CALLREG_NUMBUF_FETCH(rx,paren,usesv) \ - CALL_FPTR((rx)->engine->numbered_buff_FETCH)(aTHX_ (rx),(paren),(usesv)) + CALL_FPTR(RX_ENGINE(rx)->numbered_buff_FETCH)(aTHX_ (rx),(paren),(usesv)) #define CALLREG_NUMBUF_STORE(rx,paren,value) \ - CALL_FPTR((rx)->engine->numbered_buff_STORE)(aTHX_ (rx),(paren),(value)) + CALL_FPTR(RX_ENGINE(rx)->numbered_buff_STORE)(aTHX_ (rx),(paren),(value)) #define CALLREG_NUMBUF_LENGTH(rx,sv,paren) \ - CALL_FPTR((rx)->engine->numbered_buff_LENGTH)(aTHX_ (rx),(sv),(paren)) + CALL_FPTR(RX_ENGINE(rx)->numbered_buff_LENGTH)(aTHX_ (rx),(sv),(paren)) #define CALLREG_NAMED_BUFF_FETCH(rx, key, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), (key), NULL, ((flags) | RXapif_FETCH)) + CALL_FPTR(RX_ENGINE(rx)->named_buff)(aTHX_ (rx), (key), NULL, ((flags) | RXapif_FETCH)) #define CALLREG_NAMED_BUFF_STORE(rx, key, value, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), (key), (value), ((flags) | RXapif_STORE)) + CALL_FPTR(RX_ENGINE(rx)->named_buff)(aTHX_ (rx), (key), (value), ((flags) | RXapif_STORE)) #define CALLREG_NAMED_BUFF_DELETE(rx, key, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx),(key), NULL, ((flags) | RXapif_DELETE)) + CALL_FPTR(RX_ENGINE(rx)->named_buff)(aTHX_ (rx),(key), NULL, ((flags) | RXapif_DELETE)) #define CALLREG_NAMED_BUFF_CLEAR(rx, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_CLEAR)) + CALL_FPTR(RX_ENGINE(rx)->named_buff)(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_CLEAR)) #define CALLREG_NAMED_BUFF_EXISTS(rx, key, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), (key), NULL, ((flags) | RXapif_EXISTS)) + CALL_FPTR(RX_ENGINE(rx)->named_buff)(aTHX_ (rx), (key), NULL, ((flags) | RXapif_EXISTS)) #define CALLREG_NAMED_BUFF_FIRSTKEY(rx, flags) \ - CALL_FPTR((rx)->engine->named_buff_iter)(aTHX_ (rx), NULL, ((flags) | RXapif_FIRSTKEY)) + CALL_FPTR(RX_ENGINE(rx)->named_buff_iter)(aTHX_ (rx), NULL, ((flags) | RXapif_FIRSTKEY)) #define CALLREG_NAMED_BUFF_NEXTKEY(rx, lastkey, flags) \ - CALL_FPTR((rx)->engine->named_buff_iter)(aTHX_ (rx), (lastkey), ((flags) | RXapif_NEXTKEY)) + CALL_FPTR(RX_ENGINE(rx)->named_buff_iter)(aTHX_ (rx), (lastkey), ((flags) | RXapif_NEXTKEY)) #define CALLREG_NAMED_BUFF_SCALAR(rx, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_SCALAR)) + CALL_FPTR(RX_ENGINE(rx)->named_buff)(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_SCALAR)) #define CALLREG_NAMED_BUFF_COUNT(rx) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, RXapif_REGNAMES_COUNT) + CALL_FPTR(RX_ENGINE(rx)->named_buff)(aTHX_ (rx), NULL, NULL, RXapif_REGNAMES_COUNT) #define CALLREG_NAMED_BUFF_ALL(rx, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, flags) + CALL_FPTR(RX_ENGINE(rx)->named_buff)(aTHX_ (rx), NULL, NULL, flags) #define CALLREG_PACKAGE(rx) \ - CALL_FPTR((rx)->engine->qr_package)(aTHX_ (rx)) + CALL_FPTR(RX_ENGINE(rx)->qr_package)(aTHX_ (rx)) #if defined(USE_ITHREADS) #define CALLREGDUPE(prog,param) \ Perl_re_dup(aTHX_ (prog),(param)) #define CALLREGDUPE_PVT(prog,param) \ - (prog ? CALL_FPTR((prog)->engine->dupe)(aTHX_ (prog),(param)) \ + (prog ? CALL_FPTR(RX_ENGINE(prog)->dupe)(aTHX_ (prog),(param)) \ : (REGEXP *)NULL) #endif diff --git a/pp.c b/pp.c index 937b7ce..78e0e36 100644 --- a/pp.c +++ b/pp.c @@ -4669,8 +4669,8 @@ PP(pp_split) DIE(aTHX_ "panic: pp_split"); rx = PM_GETRE(pm); - TAINT_IF((rx->extflags & RXf_PMf_LOCALE) && - (rx->extflags & (RXf_WHITE | RXf_SKIPWHITE))); + TAINT_IF((RX_EXTFLAGS(rx) & RXf_PMf_LOCALE) && + (RX_EXTFLAGS(rx) & (RXf_WHITE | RXf_SKIPWHITE))); RX_MATCH_UTF8_set(rx, do_utf8); @@ -4712,12 +4712,12 @@ PP(pp_split) } base = SP - PL_stack_base; orig = s; - if (rx->extflags & RXf_SKIPWHITE) { + if (RX_EXTFLAGS(rx) & RXf_SKIPWHITE) { if (do_utf8) { while (*s == ' ' || is_utf8_space((U8*)s)) s += UTF8SKIP(s); } - else if (rx->extflags & RXf_PMf_LOCALE) { + else if (RX_EXTFLAGS(rx) & RXf_PMf_LOCALE) { while (isSPACE_LC(*s)) s++; } @@ -4726,13 +4726,13 @@ PP(pp_split) s++; } } - if (rx->extflags & PMf_MULTILINE) { + if (RX_EXTFLAGS(rx) & PMf_MULTILINE) { multiline = 1; } if (!limit) limit = maxiters + 2; - if (rx->extflags & RXf_WHITE) { + if (RX_EXTFLAGS(rx) & RXf_WHITE) { while (--limit) { m = s; /* this one uses 'm' and is a negative test */ @@ -4745,7 +4745,7 @@ PP(pp_split) else m += t; } - } else if (rx->extflags & RXf_PMf_LOCALE) { + } else if (RX_EXTFLAGS(rx) & RXf_PMf_LOCALE) { while (m < strend && !isSPACE_LC(*m)) ++m; } else { @@ -4772,7 +4772,7 @@ PP(pp_split) if (do_utf8) { while (s < strend && ( *s == ' ' || is_utf8_space((U8*)s) )) s += UTF8SKIP(s); - } else if (rx->extflags & RXf_PMf_LOCALE) { + } else if (RX_EXTFLAGS(rx) & RXf_PMf_LOCALE) { while (s < strend && isSPACE_LC(*s)) ++s; } else { @@ -4781,7 +4781,7 @@ PP(pp_split) } } } - else if (rx->extflags & RXf_START_ONLY) { + else if (RX_EXTFLAGS(rx) & RXf_START_ONLY) { while (--limit) { for (m = s; m < strend && *m != '\n'; m++) ; @@ -4797,7 +4797,7 @@ PP(pp_split) s = m; } } - else if (rx->extflags & RXf_NULL && !(s >= strend)) { + else if (RX_EXTFLAGS(rx) & RXf_NULL && !(s >= strend)) { /* Pre-extend the stack, either the number of bytes or characters in the string or a limited amount, triggered by: @@ -4844,15 +4844,15 @@ PP(pp_split) } } } - else if (do_utf8 == ((rx->extflags & RXf_UTF8) != 0) && - (rx->extflags & RXf_USE_INTUIT) && !rx->nparens - && (rx->extflags & RXf_CHECK_ALL) - && !(rx->extflags & RXf_ANCH)) { - const int tail = (rx->extflags & RXf_INTUIT_TAIL); + else if (do_utf8 == ((RX_EXTFLAGS(rx) & RXf_UTF8) != 0) && + (RX_EXTFLAGS(rx) & RXf_USE_INTUIT) && !RX_NPARENS(rx) + && (RX_EXTFLAGS(rx) & RXf_CHECK_ALL) + && !(RX_EXTFLAGS(rx) & RXf_ANCH)) { + const int tail = (RX_EXTFLAGS(rx) & RXf_INTUIT_TAIL); SV * const csv = CALLREG_INTUIT_STRING(rx); - len = rx->minlenret; - if (len == 1 && !(rx->extflags & RXf_UTF8) && !tail) { + len = RX_MINLENRET(rx); + if (len == 1 && !(RX_EXTFLAGS(rx) & RXf_UTF8) && !tail) { const char c = *SvPV_nolen_const(csv); while (--limit) { for (m = s; m < strend && *m != c; m++) @@ -4894,7 +4894,7 @@ PP(pp_split) } } else { - maxiters += slen * rx->nparens; + maxiters += slen * RX_NPARENS(rx); while (s < strend && --limit) { I32 rex_return; @@ -4905,25 +4905,25 @@ PP(pp_split) if (rex_return == 0) break; TAINT_IF(RX_MATCH_TAINTED(rx)); - if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) { + if (RX_MATCH_COPIED(rx) && RX_SUBBEG(rx) != orig) { m = s; s = orig; - orig = rx->subbeg; + orig = RX_SUBBEG(rx); s = orig + (m - s); strend = s + (strend - m); } - m = rx->offs[0].start + orig; + m = RX_OFFS(rx)[0].start + orig; dstr = newSVpvn(s, m-s); if (make_mortal) sv_2mortal(dstr); if (do_utf8) (void)SvUTF8_on(dstr); XPUSHs(dstr); - if (rx->nparens) { + if (RX_NPARENS(rx)) { I32 i; - for (i = 1; i <= (I32)rx->nparens; i++) { - s = rx->offs[i].start + orig; - m = rx->offs[i].end + orig; + for (i = 1; i <= (I32)RX_NPARENS(rx); i++) { + s = RX_OFFS(rx)[i].start + orig; + m = RX_OFFS(rx)[i].end + orig; /* japhy (07/27/01) -- the (m && s) test doesn't catch parens that didn't match -- they should be set to @@ -4940,7 +4940,7 @@ PP(pp_split) XPUSHs(dstr); } } - s = rx->offs[0].end + orig; + s = RX_OFFS(rx)[0].end + orig; } } diff --git a/pp_ctl.c b/pp_ctl.c index 5cbfd06..88d0d19 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -133,7 +133,7 @@ PP(pp_regcomp) if (!re || !RX_PRECOMP(re) || RX_PRELEN(re) != (I32)len || memNE(RX_PRECOMP(re), t, len)) { - const regexp_engine *eng = re ? re->engine : NULL; + const regexp_engine *eng = re ? RX_ENGINE(re) : NULL; U32 pm_flags = pm->op_pmflags & PMf_COMPILETIME; if (re) { ReREFCNT_dec(re); @@ -166,9 +166,9 @@ PP(pp_regcomp) #ifndef INCOMPLETE_TAINTS if (PL_tainting) { if (PL_tainted) - re->extflags |= RXf_TAINTED; + RX_EXTFLAGS(re) |= RXf_TAINTED; else - re->extflags &= ~RXf_TAINTED; + RX_EXTFLAGS(re) &= ~RXf_TAINTED; } #endif @@ -266,21 +266,21 @@ PP(pp_substcont) } cx->sb_iters = saviters; } - if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) { + if (RX_MATCH_COPIED(rx) && RX_SUBBEG(rx) != orig) { m = s; s = orig; - cx->sb_orig = orig = rx->subbeg; + cx->sb_orig = orig = RX_SUBBEG(rx); s = orig + (m - s); cx->sb_strend = s + (cx->sb_strend - m); } - cx->sb_m = m = rx->offs[0].start + orig; + cx->sb_m = m = RX_OFFS(rx)[0].start + orig; if (m > s) { if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ)) sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv); else sv_catpvn(dstr, s, m-s); } - cx->sb_s = rx->offs[0].end + orig; + cx->sb_s = RX_OFFS(rx)[0].end + orig; { /* Update the pos() information. */ SV * const sv = cx->sb_targ; MAGIC *mg; @@ -313,11 +313,11 @@ Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx) U32 i; PERL_UNUSED_CONTEXT; - if (!p || p[1] < rx->nparens) { + if (!p || p[1] < RX_NPARENS(rx)) { #ifdef PERL_OLD_COPY_ON_WRITE - i = 7 + rx->nparens * 2; + i = 7 + RX_NPARENS(rx) * 2; #else - i = 6 + rx->nparens * 2; + i = 6 + RX_NPARENS(rx) * 2; #endif if (!p) Newx(p, i, UV); @@ -326,7 +326,7 @@ Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx) *rsp = (void*)p; } - *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? rx->subbeg : NULL); + *p++ = PTR2UV(RX_MATCH_COPIED(rx) ? RX_SUBBEG(rx) : NULL); RX_MATCH_COPIED_off(rx); #ifdef PERL_OLD_COPY_ON_WRITE @@ -334,13 +334,13 @@ Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx) rx->saved_copy = NULL; #endif - *p++ = rx->nparens; + *p++ = RX_NPARENS(rx); - *p++ = PTR2UV(rx->subbeg); - *p++ = (UV)rx->sublen; - for (i = 0; i <= rx->nparens; ++i) { - *p++ = (UV)rx->offs[i].start; - *p++ = (UV)rx->offs[i].end; + *p++ = PTR2UV(RX_SUBBEG(rx)); + *p++ = (UV)RX_SUBLEN(rx); + for (i = 0; i <= RX_NPARENS(rx); ++i) { + *p++ = (UV)RX_OFFS(rx)[i].start; + *p++ = (UV)RX_OFFS(rx)[i].end; } } @@ -362,13 +362,13 @@ Perl_rxres_restore(pTHX_ void **rsp, REGEXP *rx) *p++ = 0; #endif - rx->nparens = *p++; + RX_NPARENS(rx) = *p++; - rx->subbeg = INT2PTR(char*,*p++); - rx->sublen = (I32)(*p++); - for (i = 0; i <= rx->nparens; ++i) { - rx->offs[i].start = (I32)(*p++); - rx->offs[i].end = (I32)(*p++); + RX_SUBBEG(rx) = INT2PTR(char*,*p++); + RX_SUBLEN(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++); } } diff --git a/pp_hot.c b/pp_hot.c index c6b5c5c..e686b2a 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1195,7 +1195,7 @@ PP(pp_qr) SV * const pkg = CALLREG_PACKAGE(rx); SV * const rv = sv_newmortal(); SV * const sv = newSVrv(rv, pkg ? SvPV_nolen(pkg) : NULL); - if (rx->extflags & RXf_TAINTED) + if (RX_EXTFLAGS(rx) & RXf_TAINTED) SvTAINTED_on(rv); sv_upgrade(sv, SVt_REGEXP); ((struct xregexp *)SvANY(sv))->xrx_regexp = ReREFCNT_inc(rx); @@ -1238,7 +1238,7 @@ PP(pp_match) if (!s) DIE(aTHX_ "panic: pp_match"); strend = s + len; - rxtainted = ((rx->extflags & RXf_TAINTED) || + rxtainted = ((RX_EXTFLAGS(rx) & RXf_TAINTED) || (PL_tainted && (pm->op_pmflags & PMf_RETAINT))); TAINT_NOT; @@ -1266,27 +1266,27 @@ PP(pp_match) rx = PM_GETRE(pm); } - if (rx->minlen > (I32)len) + if (RX_MINLEN(rx) > (I32)len) goto failure; truebase = t = s; /* XXXX What part of this is needed with true \G-support? */ if ((global = dynpm->op_pmflags & PMf_GLOBAL)) { - rx->offs[0].start = -1; + RX_OFFS(rx)[0].start = -1; if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) { MAGIC* const mg = mg_find(TARG, PERL_MAGIC_regex_global); if (mg && mg->mg_len >= 0) { - if (!(rx->extflags & RXf_GPOS_SEEN)) - rx->offs[0].end = rx->offs[0].start = mg->mg_len; - else if (rx->extflags & RXf_ANCH_GPOS) { + if (!(RX_EXTFLAGS(rx) & RXf_GPOS_SEEN)) + RX_OFFS(rx)[0].end = RX_OFFS(rx)[0].start = mg->mg_len; + else if (RX_EXTFLAGS(rx) & RXf_ANCH_GPOS) { r_flags |= REXEC_IGNOREPOS; - rx->offs[0].end = rx->offs[0].start = mg->mg_len; - } else if (rx->extflags & RXf_GPOS_FLOAT) + RX_OFFS(rx)[0].end = RX_OFFS(rx)[0].start = mg->mg_len; + } else if (RX_EXTFLAGS(rx) & RXf_GPOS_FLOAT) gpos = mg->mg_len; else - rx->offs[0].end = rx->offs[0].start = mg->mg_len; - minmatch = (mg->mg_flags & MGf_MINMATCH) ? rx->gofs + 1 : 0; + RX_OFFS(rx)[0].end = RX_OFFS(rx)[0].start = mg->mg_len; + minmatch = (mg->mg_flags & MGf_MINMATCH) ? RX_GOFS(rx) + 1 : 0; update_minmatch = 0; } } @@ -1296,34 +1296,34 @@ PP(pp_match) /g matches against large strings. So far a solution to this problem appears to be quite tricky. Test for the unsafe vars are TODO for now. */ - if (( !global && rx->nparens) + if (( !global && RX_NPARENS(rx)) || SvTEMP(TARG) || PL_sawampersand || - (rx->extflags & (RXf_EVAL_SEEN|RXf_PMf_KEEPCOPY))) + (RX_EXTFLAGS(rx) & (RXf_EVAL_SEEN|RXf_PMf_KEEPCOPY))) r_flags |= REXEC_COPY_STR; if (SvSCREAM(TARG)) r_flags |= REXEC_SCREAM; play_it_again: - if (global && rx->offs[0].start != -1) { - t = s = rx->offs[0].end + truebase - rx->gofs; - if ((s + rx->minlen) > strend || s < truebase) + if (global && RX_OFFS(rx)[0].start != -1) { + t = s = RX_OFFS(rx)[0].end + truebase - RX_GOFS(rx); + if ((s + RX_MINLEN(rx)) > strend || s < truebase) goto nope; if (update_minmatch++) minmatch = had_zerolen; } - if (rx->extflags & RXf_USE_INTUIT && - DO_UTF8(TARG) == ((rx->extflags & RXf_UTF8) != 0)) { + if (RX_EXTFLAGS(rx) & RXf_USE_INTUIT && + DO_UTF8(TARG) == ((RX_EXTFLAGS(rx) & RXf_UTF8) != 0)) { /* FIXME - can PL_bostr be made const char *? */ PL_bostr = (char *)truebase; s = CALLREG_INTUIT_START(rx, TARG, (char *)s, (char *)strend, r_flags, NULL); if (!s) goto nope; - if ( (rx->extflags & RXf_CHECK_ALL) + if ( (RX_EXTFLAGS(rx) & RXf_CHECK_ALL) && !PL_sawampersand - && !(rx->extflags & RXf_PMf_KEEPCOPY) - && ((rx->extflags & RXf_NOSCAN) - || !((rx->extflags & RXf_INTUIT_TAIL) + && !(RX_EXTFLAGS(rx) & RXf_PMf_KEEPCOPY) + && ((RX_EXTFLAGS(rx) & RXf_NOSCAN) + || !((RX_EXTFLAGS(rx) & RXf_INTUIT_TAIL) && (r_flags & REXEC_SCREAM))) && !SvROK(TARG)) /* Cannot trust since INTUIT cannot guess ^ */ goto yup; @@ -1350,7 +1350,7 @@ play_it_again: RX_MATCH_TAINTED_on(rx); TAINT_IF(RX_MATCH_TAINTED(rx)); if (gimme == G_ARRAY) { - const I32 nparens = rx->nparens; + const I32 nparens = RX_NPARENS(rx); I32 i = (global && !nparens) ? 1 : 0; SPAGAIN; /* EVAL blocks could move the stack. */ @@ -1358,10 +1358,10 @@ play_it_again: EXTEND_MORTAL(nparens + i); for (i = !i; i <= nparens; i++) { PUSHs(sv_newmortal()); - if ((rx->offs[i].start != -1) && rx->offs[i].end != -1 ) { - const I32 len = rx->offs[i].end - rx->offs[i].start; - s = rx->offs[i].start + truebase; - if (rx->offs[i].end < 0 || rx->offs[i].start < 0 || + if ((RX_OFFS(rx)[i].start != -1) && RX_OFFS(rx)[i].end != -1 ) { + const I32 len = RX_OFFS(rx)[i].end - RX_OFFS(rx)[i].start; + s = RX_OFFS(rx)[i].start + truebase; + if (RX_OFFS(rx)[i].end < 0 || RX_OFFS(rx)[i].start < 0 || len < 0 || len > strend - s) DIE(aTHX_ "panic: pp_match start/end pointers"); sv_setpvn(*SP, s, len); @@ -1382,17 +1382,17 @@ play_it_again: mg = sv_magicext(TARG, NULL, PERL_MAGIC_regex_global, &PL_vtbl_mglob, NULL, 0); } - if (rx->offs[0].start != -1) { - mg->mg_len = rx->offs[0].end; - if (rx->offs[0].start + rx->gofs == (UV)rx->offs[0].end) + if (RX_OFFS(rx)[0].start != -1) { + mg->mg_len = RX_OFFS(rx)[0].end; + if (RX_OFFS(rx)[0].start + RX_GOFS(rx) == (UV)RX_OFFS(rx)[0].end) mg->mg_flags |= MGf_MINMATCH; else mg->mg_flags &= ~MGf_MINMATCH; } } - had_zerolen = (rx->offs[0].start != -1 - && (rx->offs[0].start + rx->gofs - == (UV)rx->offs[0].end)); + had_zerolen = (RX_OFFS(rx)[0].start != -1 + && (RX_OFFS(rx)[0].start + RX_GOFS(rx) + == (UV)RX_OFFS(rx)[0].end)); PUTBACK; /* EVAL blocks may use stack */ r_flags |= REXEC_IGNOREPOS | REXEC_NOT_FIRST; goto play_it_again; @@ -1417,9 +1417,9 @@ play_it_again: mg = sv_magicext(TARG, NULL, PERL_MAGIC_regex_global, &PL_vtbl_mglob, NULL, 0); } - if (rx->offs[0].start != -1) { - mg->mg_len = rx->offs[0].end; - if (rx->offs[0].start + rx->gofs == (UV)rx->offs[0].end) + if (RX_OFFS(rx)[0].start != -1) { + mg->mg_len = RX_OFFS(rx)[0].end; + if (RX_OFFS(rx)[0].start + RX_GOFS(rx) == (UV)RX_OFFS(rx)[0].end) mg->mg_flags |= MGf_MINMATCH; else mg->mg_flags &= ~MGf_MINMATCH; @@ -1442,24 +1442,24 @@ yup: /* Confirmed by INTUIT */ #endif } if (RX_MATCH_COPIED(rx)) - Safefree(rx->subbeg); + Safefree(RX_SUBBEG(rx)); RX_MATCH_COPIED_off(rx); - rx->subbeg = NULL; + RX_SUBBEG(rx) = NULL; if (global) { /* FIXME - should rx->subbeg be const char *? */ - rx->subbeg = (char *) truebase; - rx->offs[0].start = s - truebase; + RX_SUBBEG(rx) = (char *) truebase; + RX_OFFS(rx)[0].start = s - truebase; if (RX_MATCH_UTF8(rx)) { - char * const t = (char*)utf8_hop((U8*)s, rx->minlenret); - rx->offs[0].end = t - truebase; + char * const t = (char*)utf8_hop((U8*)s, RX_MINLENRET(rx)); + RX_OFFS(rx)[0].end = t - truebase; } else { - rx->offs[0].end = s - truebase + rx->minlenret; + RX_OFFS(rx)[0].end = s - truebase + RX_MINLENRET(rx); } - rx->sublen = strend - truebase; + RX_SUBLEN(rx) = strend - truebase; goto gotcha; } - if (PL_sawampersand || rx->extflags & RXf_PMf_KEEPCOPY) { + if (PL_sawampersand || RX_EXTFLAGS(rx) & RXf_PMf_KEEPCOPY) { I32 off; #ifdef PERL_OLD_COPY_ON_WRITE if (SvIsCOW(TARG) || (SvFLAGS(TARG) & CAN_COW_MASK) == CAN_COW_FLAGS) { @@ -1470,29 +1470,29 @@ yup: /* Confirmed by INTUIT */ (int)(t-truebase)); } rx->saved_copy = sv_setsv_cow(rx->saved_copy, TARG); - rx->subbeg = (char *) SvPVX_const(rx->saved_copy) + (t - truebase); + RX_SUBBEG(rx) = (char *) SvPVX_const(rx->saved_copy) + (t - truebase); assert (SvPOKp(rx->saved_copy)); } else #endif { - rx->subbeg = savepvn(t, strend - t); + RX_SUBBEG(rx) = savepvn(t, strend - t); #ifdef PERL_OLD_COPY_ON_WRITE rx->saved_copy = NULL; #endif } - rx->sublen = strend - t; + RX_SUBLEN(rx) = strend - t; RX_MATCH_COPIED_on(rx); - off = rx->offs[0].start = s - t; - rx->offs[0].end = off + rx->minlenret; + off = RX_OFFS(rx)[0].start = s - t; + RX_OFFS(rx)[0].end = off + RX_MINLENRET(rx); } else { /* startp/endp are used by @- @+. */ - rx->offs[0].start = s - truebase; - rx->offs[0].end = s - truebase + rx->minlenret; + RX_OFFS(rx)[0].start = s - truebase; + RX_OFFS(rx)[0].end = s - truebase + RX_MINLENRET(rx); } - /* including rx->nparens in the below code seems highly suspicious. + /* including RX_NPARENS(rx) in the below code seems highly suspicious. -dmq */ - rx->nparens = rx->lastparen = rx->lastcloseparen = 0; /* used by @-, @+, and $^N */ + RX_NPARENS(rx) = RX_LASTPAREN(rx) = RX_LASTCLOSEPAREN(rx) = 0; /* used by @-, @+, and $^N */ LEAVE_SCOPE(oldsave); RETPUSHYES; @@ -2074,7 +2074,7 @@ PP(pp_subst) s = SvPV_mutable(TARG, len); if (!SvPOKp(TARG) || SvTYPE(TARG) == SVt_PVGV) force_on_match = 1; - rxtainted = ((rx->extflags & RXf_TAINTED) || + rxtainted = ((RX_EXTFLAGS(rx) & RXf_TAINTED) || (PL_tainted && (pm->op_pmflags & PMf_RETAINT))); if (PL_tainted) rxtainted |= 2; @@ -2096,25 +2096,25 @@ PP(pp_subst) pm = PL_curpm; rx = PM_GETRE(pm); } - r_flags = (rx->nparens || SvTEMP(TARG) || PL_sawampersand - || (rx->extflags & (RXf_EVAL_SEEN|RXf_PMf_KEEPCOPY)) ) + r_flags = (RX_NPARENS(rx) || SvTEMP(TARG) || PL_sawampersand + || (RX_EXTFLAGS(rx) & (RXf_EVAL_SEEN|RXf_PMf_KEEPCOPY)) ) ? REXEC_COPY_STR : 0; if (SvSCREAM(TARG)) r_flags |= REXEC_SCREAM; orig = m = s; - if (rx->extflags & RXf_USE_INTUIT) { + if (RX_EXTFLAGS(rx) & RXf_USE_INTUIT) { PL_bostr = orig; s = CALLREG_INTUIT_START(rx, TARG, s, strend, r_flags, NULL); if (!s) goto nope; /* How to do it in subst? */ -/* if ( (rx->extflags & RXf_CHECK_ALL) +/* if ( (RX_EXTFLAGS(rx) & RXf_CHECK_ALL) && !PL_sawampersand - && !(rx->extflags & RXf_KEEPCOPY) - && ((rx->extflags & RXf_NOSCAN) - || !((rx->extflags & RXf_INTUIT_TAIL) + && !(RX_EXTFLAGS(rx) & RXf_KEEPCOPY) + && ((RX_EXTFLAGS(rx) & RXf_NOSCAN) + || !((RX_EXTFLAGS(rx) & RXf_INTUIT_TAIL) && (r_flags & REXEC_SCREAM)))) goto yup; */ @@ -2152,8 +2152,8 @@ PP(pp_subst) #ifdef PERL_OLD_COPY_ON_WRITE && !is_cow #endif - && (I32)clen <= rx->minlenret && (once || !(r_flags & REXEC_COPY_STR)) - && !(rx->extflags & RXf_LOOKBEHIND_SEEN) + && (I32)clen <= RX_MINLENRET(rx) && (once || !(r_flags & REXEC_COPY_STR)) + && !(RX_EXTFLAGS(rx) & RXf_LOOKBEHIND_SEEN) && (!doutf8 || SvUTF8(TARG))) { if (!matched) { @@ -2178,8 +2178,8 @@ PP(pp_subst) SvSCREAM_off(TARG); /* disable possible screamer */ if (once) { rxtainted |= RX_MATCH_TAINTED(rx); - m = orig + rx->offs[0].start; - d = orig + rx->offs[0].end; + m = orig + RX_OFFS(rx)[0].start; + d = orig + RX_OFFS(rx)[0].end; s = orig; if (m - s > strend - d) { /* faster to shorten from end */ if (clen) { @@ -2219,7 +2219,7 @@ PP(pp_subst) if (iters++ > maxiters) DIE(aTHX_ "Substitution loop"); rxtainted |= RX_MATCH_TAINTED(rx); - m = rx->offs[0].start + orig; + m = RX_OFFS(rx)[0].start + orig; if ((i = m - s)) { if (s != d) Move(s, d, i, char); @@ -2229,7 +2229,7 @@ PP(pp_subst) Copy(c, d, clen, char); d += clen; } - s = rx->offs[0].end + orig; + s = RX_OFFS(rx)[0].end + orig; } while (CALLREGEXEC(rx, s, strend, orig, s == m, TARG, NULL, /* don't match same null twice */ @@ -2284,19 +2284,19 @@ PP(pp_subst) if (iters++ > maxiters) DIE(aTHX_ "Substitution loop"); rxtainted |= RX_MATCH_TAINTED(rx); - if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) { + if (RX_MATCH_COPIED(rx) && RX_SUBBEG(rx) != orig) { m = s; s = orig; - orig = rx->subbeg; + orig = RX_SUBBEG(rx); s = orig + (m - s); strend = s + (strend - m); } - m = rx->offs[0].start + orig; + m = RX_OFFS(rx)[0].start + orig; if (doutf8 && !SvUTF8(dstr)) sv_catpvn_utf8_upgrade(dstr, s, m - s, nsv); else sv_catpvn(dstr, s, m-s); - s = rx->offs[0].end + orig; + s = RX_OFFS(rx)[0].end + orig; if (clen) sv_catpvn(dstr, c, clen); if (once) diff --git a/regcomp.c b/regcomp.c index 10e63f5..3612dca 100644 --- a/regcomp.c +++ b/regcomp.c @@ -4290,12 +4290,12 @@ redo_first_pass: >> RXf_PMf_STD_PMMOD_SHIFT); const char *fptr = STD_PAT_MODS; /*"msix"*/ char *p; - RX_WRAPLEN(r) = plen + has_minus + has_p + has_runon + RXp_WRAPLEN(r) = plen + has_minus + has_p + has_runon + (sizeof(STD_PAT_MODS) - 1) + (sizeof("(?:)") - 1); - Newx(RX_WRAPPED(r), RX_WRAPLEN(r) + 1, char ); - p = RX_WRAPPED(r); + Newx(RXp_WRAPPED(r), RXp_WRAPLEN(r) + 1, char ); + p = RXp_WRAPPED(r); *p++='('; *p++='?'; if (has_p) *p++ = KEEPCOPY_PAT_MOD; /*'p'*/ @@ -4319,8 +4319,8 @@ redo_first_pass: *p++ = ':'; Copy(RExC_precomp, p, plen, char); - assert ((RX_WRAPPED(r) - p) < 16); - r->pre_prefix = p - RX_WRAPPED(r); + assert ((RXp_WRAPPED(r) - p) < 16); + r->pre_prefix = p - RXp_WRAPPED(r); p += plen; if (has_runon) *p++ = '\n'; @@ -4797,15 +4797,15 @@ reStudy: #ifdef STUPID_PATTERN_CHECKS if (RX_PRELEN(r) == 0) r->extflags |= RXf_NULL; - if (r->extflags & RXf_SPLIT && RX_PRELEN(r) == 1 && RX_PRECOMP(r)[0] == ' ') + if (r->extflags & RXf_SPLIT && RX_PRELEN(r) == 1 && RXp_PRECOMP(r)[0] == ' ') /* XXX: this should happen BEFORE we compile */ r->extflags |= (RXf_SKIPWHITE|RXf_WHITE); - else if (RX_PRELEN(r) == 3 && memEQ("\\s+", RX_PRECOMP(r), 3)) + else if (RX_PRELEN(r) == 3 && memEQ("\\s+", RXp_PRECOMP(r), 3)) r->extflags |= RXf_WHITE; - else if (RX_PRELEN(r) == 1 && RX_PRECOMP(r)[0] == '^') + else if (RX_PRELEN(r) == 1 && RXp_PRECOMP(r)[0] == '^') r->extflags |= RXf_START_ONLY; #else - if (r->extflags & RXf_SPLIT && RX_PRELEN(r) == 1 && RX_PRECOMP(r)[0] == ' ') + if (r->extflags & RXf_SPLIT && RXp_PRELEN(r) == 1 && RXp_PRECOMP(r)[0] == ' ') /* XXX: this should happen BEFORE we compile */ r->extflags |= (RXf_SKIPWHITE|RXf_WHITE); else { @@ -5103,16 +5103,16 @@ Perl_reg_numbered_buff_fetch(pTHX_ REGEXP * const rx, const I32 paren, SV * cons sv_setpvn(sv, s, i); PL_tainted = oldtainted; if ( (rx->extflags & RXf_CANY_SEEN) - ? (RX_MATCH_UTF8(rx) + ? (RXp_MATCH_UTF8(rx) && (!i || is_utf8_string((U8*)s, i))) - : (RX_MATCH_UTF8(rx)) ) + : (RXp_MATCH_UTF8(rx)) ) { SvUTF8_on(sv); } else SvUTF8_off(sv); if (PL_tainting) { - if (RX_MATCH_TAINTED(rx)) { + if (RXp_MATCH_TAINTED(rx)) { if (SvTYPE(sv) >= SVt_PVMG) { MAGIC* const mg = SvMAGIC(sv); MAGIC* mgt; @@ -5194,7 +5194,7 @@ Perl_reg_numbered_buff_length(pTHX_ REGEXP * const rx, const SV * const sv, } } getlen: - if (i > 0 && RX_MATCH_UTF8(rx)) { + if (i > 0 && RXp_MATCH_UTF8(rx)) { const char * const s = rx->subbeg + s1; const U8 *ep; STRLEN el; @@ -9147,7 +9147,7 @@ Perl_pregfree(pTHX_ struct regexp *r) CALLREGFREE_PVT(r); /* free the private data */ if (r->paren_names) SvREFCNT_dec(r->paren_names); - Safefree(RX_WRAPPED(r)); + Safefree(RXp_WRAPPED(r)); } if (r->substrs) { if (r->anchored_substr) @@ -9245,7 +9245,7 @@ Perl_regfree_internal(pTHX_ REGEXP * const r) { SV *dsv= sv_newmortal(); RE_PV_QUOTED_DECL(s, (r->extflags & RXf_UTF8), - dsv, RX_PRECOMP(r), RX_PRELEN(r), 60); + dsv, RXp_PRECOMP(r), RXp_PRELEN(r), 60); PerlIO_printf(Perl_debug_log,"%sFreeing REx:%s %s\n", PL_colors[4],PL_colors[5],s); } @@ -9420,7 +9420,7 @@ Perl_re_dup(pTHX_ const regexp *r, CLONE_PARAMS *param) } } - RX_WRAPPED(ret) = SAVEPVN(RX_WRAPPED(ret), RX_WRAPLEN(ret)+1); + RXp_WRAPPED(ret) = SAVEPVN(RXp_WRAPPED(ret), RXp_WRAPLEN(ret)+1); ret->paren_names = hv_dup_inc(ret->paren_names, param); if (ret->pprivate) @@ -9584,9 +9584,9 @@ Perl_reg_stringify(pTHX_ MAGIC *mg, STRLEN *lp, U32 *flags, I32 *haseval ) { dVAR; const regexp * const re = (regexp *)mg->mg_obj; if (haseval) - *haseval = re->seen_evals; + *haseval = RX_SEEN_EVALS(re); if (flags) - *flags = ((re->extflags & RXf_UTF8) ? 1 : 0); + *flags = ((RX_EXTFLAGS(re) & RXf_UTF8) ? 1 : 0); if (lp) *lp = RX_WRAPLEN(re); return RX_WRAPPED(re); @@ -9682,7 +9682,7 @@ Perl_save_re_context(pTHX) const REGEXP * const rx = PM_GETRE(PL_curpm); if (rx) { U32 i; - for (i = 1; i <= rx->nparens; i++) { + for (i = 1; i <= RX_NPARENS(rx); i++) { char digits[TYPE_CHARS(long)]; const STRLEN len = my_snprintf(digits, sizeof(digits), "%lu", (long)i); GV *const *const gvp diff --git a/regcomp.h b/regcomp.h index 645e386..d3c75f0 100644 --- a/regcomp.h +++ b/regcomp.h @@ -528,7 +528,10 @@ struct reg_data { #define check_offset_max substrs->data[2].max_offset #define check_end_shift substrs->data[2].end_shift - +#define RX_ANCHORED_SUBSTR(rx) ((rx)->anchored_substr) +#define RX_ANCHORED_UTF8(rx) ((rx)->anchored_utf8) +#define RX_FLOAT_SUBSTR(rx) ((rx)->float_substr) +#define RX_FLOAT_UTF8(rx) ((rx)->float_utf8) /* trie related stuff */ diff --git a/regexec.c b/regexec.c index 724b870..59fc53e 100644 --- a/regexec.c +++ b/regexec.c @@ -536,7 +536,7 @@ Perl_re_intuit_start(pTHX_ REGEXP * const prog, SV *sv, char *strpos, else goto fail_finish; /* we may be pointing at the wrong string */ - if (s && RX_MATCH_COPIED(prog)) + if (s && RXp_MATCH_COPIED(prog)) s = strbeg + (s - SvPVX_const(sv)); if (data) *data->scream_olds = s; @@ -2009,7 +2009,7 @@ Perl_regexec_flags(pTHX_ REGEXP * const prog, char *stringarg, register char *st (unsigned char*)strend, must, multiline ? FBMrf_MULTILINE : 0))) ) { /* we may be pointing at the wrong string */ - if ((flags & REXEC_SCREAM) && RX_MATCH_COPIED(prog)) + if ((flags & REXEC_SCREAM) && RXp_MATCH_COPIED(prog)) s = strbeg + (s - SvPVX_const(sv)); DEBUG_EXECUTE_r( did_match = 1 ); if (HOPc(s, -back_max) > last1) { @@ -2087,7 +2087,7 @@ Perl_regexec_flags(pTHX_ REGEXP * const prog, char *stringarg, register char *st if (!last) last = scream_olds; /* Only one occurrence. */ /* we may be pointing at the wrong string */ - else if (RX_MATCH_COPIED(prog)) + else if (RXp_MATCH_COPIED(prog)) s = strbeg + (s - SvPVX_const(sv)); } else { @@ -2264,7 +2264,7 @@ S_regtry(pTHX_ regmatch_info *reginfo, char **startpos) PM_SETRE(PL_reg_curpm, prog); PL_reg_oldcurpm = PL_curpm; PL_curpm = PL_reg_curpm; - if (RX_MATCH_COPIED(prog)) { + if (RXp_MATCH_COPIED(prog)) { /* Here is a serious problem: we cannot rewrite subbeg, since it may be needed if this match fails. Thus $` inside (?{}) could fail... */ @@ -2273,7 +2273,7 @@ S_regtry(pTHX_ regmatch_info *reginfo, char **startpos) #ifdef PERL_OLD_COPY_ON_WRITE PL_nrs = prog->saved_copy; #endif - RX_MATCH_COPIED_off(prog); + RXp_MATCH_COPIED_off(prog); } else PL_reg_oldsaved = NULL; @@ -2558,7 +2558,7 @@ S_debug_start_match(pTHX_ const regexp *prog, const bool do_utf8, reginitcolors(); { RE_PV_QUOTED_DECL(s0, utf8_pat, PERL_DEBUG_PAD_ZERO(0), - RX_PRECOMP(prog), RX_PRELEN(prog), 60); + RXp_PRECOMP(prog), RXp_PRELEN(prog), 60); RE_PV_QUOTED_DECL(s1, do_utf8, PERL_DEBUG_PAD_ZERO(1), start, end - start, 60); @@ -3762,7 +3762,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog) PL_regsize = osize; } } - RX_MATCH_COPIED_off(re); + RXp_MATCH_COPIED_off(re); re->subbeg = rex->subbeg; re->sublen = rex->sublen; rei = RXi_GET(re); @@ -5880,7 +5880,7 @@ restore_pos(pTHX_ void *arg) #ifdef PERL_OLD_COPY_ON_WRITE rex->saved_copy = PL_nrs; #endif - RX_MATCH_COPIED_on(rex); + RXp_MATCH_COPIED_on(rex); } PL_reg_magic->mg_len = PL_reg_oldpos; PL_reg_eval_set = 0; diff --git a/regexp.h b/regexp.h index 2960665..17dfbb6 100644 --- a/regexp.h +++ b/regexp.h @@ -341,29 +341,53 @@ and check for NULL. */ #define RX_HAS_CUTGROUP(prog) ((prog)->intflags & PREGf_CUTGROUP_SEEN) -#define RX_MATCH_TAINTED(prog) ((prog)->extflags & RXf_TAINTED_SEEN) -#define RX_MATCH_TAINTED_on(prog) ((prog)->extflags |= RXf_TAINTED_SEEN) -#define RX_MATCH_TAINTED_off(prog) ((prog)->extflags &= ~RXf_TAINTED_SEEN) +#define RXp_MATCH_TAINTED(prog) (RXp_EXTFLAGS(prog) & RXf_TAINTED_SEEN) +#define RX_MATCH_TAINTED(prog) (RX_EXTFLAGS(prog) & RXf_TAINTED_SEEN) +#define RX_MATCH_TAINTED_on(prog) (RX_EXTFLAGS(prog) |= RXf_TAINTED_SEEN) +#define RX_MATCH_TAINTED_off(prog) (RX_EXTFLAGS(prog) &= ~RXf_TAINTED_SEEN) #define RX_MATCH_TAINTED_set(prog, t) ((t) \ ? RX_MATCH_TAINTED_on(prog) \ : RX_MATCH_TAINTED_off(prog)) -#define RX_MATCH_COPIED(prog) ((prog)->extflags & RXf_COPY_DONE) -#define RX_MATCH_COPIED_on(prog) ((prog)->extflags |= RXf_COPY_DONE) -#define RX_MATCH_COPIED_off(prog) ((prog)->extflags &= ~RXf_COPY_DONE) +#define RXp_MATCH_COPIED(prog) (RXp_EXTFLAGS(prog) & RXf_COPY_DONE) +#define RX_MATCH_COPIED(prog) (RX_EXTFLAGS(prog) & RXf_COPY_DONE) +#define RXp_MATCH_COPIED_on(prog) (RXp_EXTFLAGS(prog) |= RXf_COPY_DONE) +#define RX_MATCH_COPIED_on(prog) (RX_EXTFLAGS(prog) |= RXf_COPY_DONE) +#define RXp_MATCH_COPIED_off(prog) (RXp_EXTFLAGS(prog) &= ~RXf_COPY_DONE) +#define RX_MATCH_COPIED_off(prog) (RX_EXTFLAGS(prog) &= ~RXf_COPY_DONE) #define RX_MATCH_COPIED_set(prog,t) ((t) \ ? RX_MATCH_COPIED_on(prog) \ : RX_MATCH_COPIED_off(prog)) -/* For source compatibility. We used to store these explicitly. */ -#define RX_PRECOMP(prog) ((prog)->wrapped + (prog)->pre_prefix) +#define RXp_PRECOMP(rx) ((rx)->wrapped + (rx)->pre_prefix) /* FIXME? Are we hardcoding too much here and constraining plugin extension writers? Specifically, the value 1 assumes that the wrapped version always has exactly one character at the end, a ')'. Will that always be true? */ -#define RX_PRELEN(prog) ((prog)->wraplen - (prog)->pre_prefix - 1) -#define RX_WRAPPED(prog) ((prog)->wrapped) -#define RX_WRAPLEN(prog) ((prog)->wraplen) +#define RXp_PRELEN(rx) ((rx)->wraplen - (rx)->pre_prefix - 1) +#define RXp_WRAPPED(rx) ((rx)->wrapped) +#define RXp_WRAPLEN(rx) ((rx)->wraplen) +#define RXp_EXTFLAGS(rx) ((rx)->extflags) +/* For source compatibility. We used to store these explicitly. */ +#define RX_PRECOMP(prog) ((prog)->wrapped + (prog)->pre_prefix) +#define RX_PRELEN(prog) ((prog)->wraplen - (prog)->pre_prefix - 1) +#define RX_WRAPPED(prog) ((prog)->wrapped) +#define RX_WRAPLEN(prog) ((prog)->wraplen) +#define RX_CHECK_SUBSTR(prog) ((prog)->check_substr) +#define RX_EXTFLAGS(prog) ((prog)->extflags) +#define RX_REFCNT(prog) ((prog)->refcnt) +#define RX_ENGINE(prog) ((prog)->engine) +#define RX_SUBBEG(prog) ((prog)->subbeg) +#define RX_OFFS(prog) ((prog)->offs) +#define RX_NPARENS(prog) ((prog)->nparens) +#define RX_SUBLEN(prog) ((prog)->sublen) +#define RX_SUBBEG(prog) ((prog)->subbeg) +#define RX_MINLEN(prog) ((prog)->minlen) +#define RX_MINLENRET(prog) ((prog)->minlenret) +#define RX_GOFS(prog) ((prog)->gofs) +#define RX_LASTPAREN(prog) ((prog)->lastparen) +#define RX_LASTCLOSEPAREN(prog) ((prog)->lastcloseparen) +#define RX_SEEN_EVALS(prog) ((prog)->seen_evals) #endif /* PLUGGABLE_RE_EXTENSION */ @@ -375,20 +399,21 @@ and check for NULL. SV_CHECK_THINKFIRST_COW_DROP(rx->saved_copy); \ } \ if (RX_MATCH_COPIED(rx)) { \ - Safefree(rx->subbeg); \ + Safefree(RX_SUBBEG(rx)); \ RX_MATCH_COPIED_off(rx); \ }} STMT_END #else #define RX_MATCH_COPY_FREE(rx) \ STMT_START {if (RX_MATCH_COPIED(rx)) { \ - Safefree(rx->subbeg); \ + Safefree(RX_SUBBEG(rx)); \ RX_MATCH_COPIED_off(rx); \ }} STMT_END #endif -#define RX_MATCH_UTF8(prog) ((prog)->extflags & RXf_MATCH_UTF8) -#define RX_MATCH_UTF8_on(prog) ((prog)->extflags |= RXf_MATCH_UTF8) -#define RX_MATCH_UTF8_off(prog) ((prog)->extflags &= ~RXf_MATCH_UTF8) +#define RXp_MATCH_UTF8(prog) (RXp_EXTFLAGS(prog) & RXf_MATCH_UTF8) +#define RX_MATCH_UTF8(prog) (RX_EXTFLAGS(prog) & RXf_MATCH_UTF8) +#define RX_MATCH_UTF8_on(prog) (RX_EXTFLAGS(prog) |= RXf_MATCH_UTF8) +#define RX_MATCH_UTF8_off(prog) (RX_EXTFLAGS(prog) &= ~RXf_MATCH_UTF8) #define RX_MATCH_UTF8_set(prog, t) ((t) \ ? (RX_MATCH_UTF8_on(prog), (PL_reg_match_utf8 = 1)) \ : (RX_MATCH_UTF8_off(prog), (PL_reg_match_utf8 = 0)))