From: Nicholas Clark Date: Sat, 29 Dec 2007 00:17:41 +0000 (+0000) Subject: Wrap wrapped and wraplen from struct regexp in macros RW_WRAPPED() and X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=866c78d1cf6feeffe34601c244c137d8b30ec2e4;p=p5sagit%2Fp5-mst-13.2.git Wrap wrapped and wraplen from struct regexp in macros RW_WRAPPED() and RX_WRAPLEN() to preserve source compatibility when they get moved around. p4raw-id: //depot/perl@32758 --- diff --git a/dump.c b/dump.c index e62da78..126fe89 100644 --- a/dump.c +++ b/dump.c @@ -1285,7 +1285,8 @@ Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32 if (mg->mg_type == PERL_MAGIC_qr) { const regexp * const re = (regexp *)mg->mg_obj; SV * const dsv = sv_newmortal(); - const char * const s = pv_pretty(dsv, re->wrapped, re->wraplen, + 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)) diff --git a/ext/re/re.xs b/ext/re/re.xs index fa82127..94cb2f5 100644 --- a/ext/re/re.xs +++ b/ext/re/re.xs @@ -126,7 +126,7 @@ PPCODE: } else { /* Scalar, so use the string that Perl would return */ /* return the pattern in (?msix:..) format */ - pattern = sv_2mortal(newSVpvn(re->wrapped,re->wraplen)); + pattern = sv_2mortal(newSVpvn(RX_WRAPPED(re),RX_WRAPLEN(re))); if (re->extflags & RXf_UTF8) SvUTF8_on(pattern); XPUSHs(pattern); diff --git a/regcomp.c b/regcomp.c index ff099f5..070b183 100644 --- a/regcomp.c +++ b/regcomp.c @@ -4289,12 +4289,12 @@ redo_first_pass: U16 reganch = (U16)((r->extflags & RXf_PMf_STD_PMMOD) >> 12); const char *fptr = STD_PAT_MODS; /*"msix"*/ char *p; - r->wraplen = plen + has_minus + has_p + has_runon + RX_WRAPLEN(r) = plen + has_minus + has_p + has_runon + (sizeof(STD_PAT_MODS) - 1) + (sizeof("(?:)") - 1); - Newx(r->wrapped, r->wraplen + 1, char ); - p = r->wrapped; + Newx(RX_WRAPPED(r), RX_WRAPLEN(r) + 1, char ); + p = RX_WRAPPED(r); *p++='('; *p++='?'; if (has_p) *p++ = KEEPCOPY_PAT_MOD; /*'p'*/ @@ -4318,8 +4318,8 @@ redo_first_pass: *p++ = ':'; Copy(RExC_precomp, p, plen, char); - assert ((r->wrapped - p) < 16); - r->pre_prefix = p - r->wrapped; + assert ((RX_WRAPPED(r) - p) < 16); + r->pre_prefix = p - RX_WRAPPED(r); p += plen; if (has_runon) *p++ = '\n'; @@ -9146,7 +9146,7 @@ Perl_pregfree(pTHX_ struct regexp *r) CALLREGFREE_PVT(r); /* free the private data */ if (r->paren_names) SvREFCNT_dec(r->paren_names); - Safefree(r->wrapped); + Safefree(RX_WRAPPED(r)); } if (r->substrs) { if (r->anchored_substr) @@ -9419,7 +9419,7 @@ Perl_re_dup(pTHX_ const regexp *r, CLONE_PARAMS *param) } } - ret->wrapped = SAVEPVN(ret->wrapped, ret->wraplen+1); + RX_WRAPPED(ret) = SAVEPVN(RX_WRAPPED(ret), RX_WRAPLEN(ret)+1); ret->paren_names = hv_dup_inc(ret->paren_names, param); if (ret->pprivate) @@ -9587,8 +9587,8 @@ Perl_reg_stringify(pTHX_ MAGIC *mg, STRLEN *lp, U32 *flags, I32 *haseval ) { if (flags) *flags = ((re->extflags & RXf_UTF8) ? 1 : 0); if (lp) - *lp = re->wraplen; - return re->wrapped; + *lp = RX_WRAPLEN(re); + return RX_WRAPPED(re); } /* diff --git a/regexp.h b/regexp.h index 37d92c5..623a4bb 100644 --- a/regexp.h +++ b/regexp.h @@ -358,6 +358,9 @@ and check for NULL. 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) + #endif /* PLUGGABLE_RE_EXTENSION */