X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=regcomp.c;h=0872c2ca8c50ebf44e33a8a1afc29708eecd67c2;hb=2680586ee66b8de4d2b5f26a2013220f2bec9d5f;hp=2d5f813fe4c903ab570cee94a8b3c5105c4255b3;hpb=bcbdfc13881cc3060cda9d2aa649ae89efc53a22;p=p5sagit%2Fp5-mst-13.2.git diff --git a/regcomp.c b/regcomp.c index 2d5f813..0872c2c 100644 --- a/regcomp.c +++ b/regcomp.c @@ -147,6 +147,7 @@ static char* regwhite _((char *, char *)); static char* nextchar _((void)); static void re_croak2 _((const char* pat1,const char* pat2,...)) __attribute__((noreturn)); static char* regpposixcc _((I32 value)); +static void clear_re _((void *r)); #endif /* Length of a variant. */ @@ -171,7 +172,8 @@ typedef struct { } scan_data_t; #endif -static scan_data_t zero_scan_data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +static scan_data_t zero_scan_data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0 }; #define SF_BEFORE_EOL (SF_BEFORE_SEOL|SF_BEFORE_MEOL) #define SF_BEFORE_SEOL 0x1 @@ -207,6 +209,12 @@ static scan_data_t zero_scan_data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; #define CHR_DIST(a,b) (UTF ? utf8_distance(a,b) : a - b) STATIC void +clear_re(void *r) +{ + ReREFCNT_dec((regexp *)r); +} + +STATIC void scan_commit(scan_data_t *data) { dTHR; @@ -868,7 +876,12 @@ pregcomp(char *exp, char *xend, PMOP *pm) r->prelen = xend - exp; r->precomp = PL_regprecomp; r->subbeg = r->subbase = NULL; - r->nparens = PL_regnpar - 1; /* set early to validate backrefs */ + r->nparens = PL_regnpar - 1; /* set early to validate backrefs */ + + r->substrs = 0; /* Useful during FAIL. */ + r->startp = 0; /* Useful during FAIL. */ + r->endp = 0; /* Useful during FAIL. */ + PL_regcomp_rx = r; /* Second pass: emit code. */ @@ -1159,10 +1172,10 @@ reg(I32 paren, I32 *flagp) rop = sv_compile_2op(sv, &sop, "re", &av); - n = add_data(3, "nso"); + n = add_data(3, "nop"); PL_regcomp_rx->data->data[n] = (void*)rop; - PL_regcomp_rx->data->data[n+1] = (void*)av; - PL_regcomp_rx->data->data[n+2] = (void*)sop; + PL_regcomp_rx->data->data[n+1] = (void*)sop; + PL_regcomp_rx->data->data[n+2] = (void*)av; SvREFCNT_dec(sv); } else { /* First pass */ @@ -1378,8 +1391,11 @@ reg(I32 paren, I32 *flagp) } /* Check for proper termination. */ - if (paren && (PL_regcomp_parse >= PL_regxend || *nextchar() != ')')) { - FAIL("unmatched () in regexp"); + if (paren) { + PL_regflags = oregflags; + if (PL_regcomp_parse >= PL_regxend || *nextchar() != ')') { + FAIL("unmatched () in regexp"); + } } else if (!paren && PL_regcomp_parse < PL_regxend) { if (*PL_regcomp_parse == ')') { @@ -1389,9 +1405,6 @@ reg(I32 paren, I32 *flagp) FAIL("junk on end of regexp"); /* "Can't happen". */ /* NOTREACHED */ } - if (paren != 0) { - PL_regflags = oregflags; - } return(ret); } @@ -3111,13 +3124,30 @@ pregfree(struct regexp *r) } if (r->data) { int n = r->data->count; + AV* new_comppad = NULL; + AV* old_comppad; + SV** old_curpad; + while (--n >= 0) { switch (r->data->what[n]) { case 's': SvREFCNT_dec((SV*)r->data->data[n]); break; + case 'p': + new_comppad = (AV*)r->data->data[n]; + break; case 'o': + if (new_comppad == NULL) + croak("panic: pregfree comppad"); + old_comppad = PL_comppad; + old_curpad = PL_curpad; + PL_comppad = new_comppad; + PL_curpad = AvARRAY(new_comppad); op_free((OP_4tree*)r->data->data[n]); + PL_comppad = old_comppad; + PL_curpad = old_curpad; + SvREFCNT_dec((SV*)new_comppad); + new_comppad = NULL; break; case 'n': break;