This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move the declaration of two variables into the only block that uses
[perl5.git] / regexec.c
index d1f6b8e..e382a2a 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -1652,9 +1652,8 @@ S_find_byclass(pTHX_ regexp * prog, const regnode *c, char *s,
 static void 
 S_swap_match_buff (pTHX_ regexp *prog) {
     I32 *t;
-    RXi_GET_DECL(prog,progi);
 
-    if (!progi->swap) {
+    if (!prog->swap) {
     /* We have to be careful. If the previous successful match
        was from this regex we don't want a subsequent paritally
        successful match to clobber the old results. 
@@ -1662,16 +1661,16 @@ S_swap_match_buff (pTHX_ regexp *prog) {
        to the re, and switch the buffer each match. If we fail
        we switch it back, otherwise we leave it swapped.
     */
-        Newxz(progi->swap, 1, regexp_paren_ofs);
+        Newxz(prog->swap, 1, regexp_paren_ofs);
         /* no need to copy these */
-        Newxz(progi->swap->startp, prog->nparens + 1, I32);
-        Newxz(progi->swap->endp, prog->nparens + 1, I32);
+        Newxz(prog->swap->startp, 2 * (prog->nparens + 1), I32);
+       prog->swap->endp = prog->swap->startp + prog->nparens + 1;
     }
-    t = progi->swap->startp;
-    progi->swap->startp = prog->startp;
+    t = prog->swap->startp;
+    prog->swap->startp = prog->startp;
     prog->startp = t;
-    t = progi->swap->endp;
-    progi->swap->endp = prog->endp;
+    t = prog->swap->endp;
+    prog->swap->endp = prog->endp;
     prog->endp = t;
 }    
 
@@ -1997,7 +1996,7 @@ Perl_regexec_flags(pTHX_ register regexp *prog, char *stringarg, register char *
            SV * const prop = sv_newmortal();
            regprop(prog, prop, c);
            {
-               RE_PV_QUOTED_DECL(quoted,UTF,PERL_DEBUG_PAD_ZERO(1),
+               RE_PV_QUOTED_DECL(quoted,do_utf8,PERL_DEBUG_PAD_ZERO(1),
                    s,strend-s,60);
                PerlIO_printf(Perl_debug_log,
                    "Matching stclass %.*s against %s (%d chars)\n",
@@ -2149,8 +2148,6 @@ STATIC I32                        /* 0 failure, 1 success */
 S_regtry(pTHX_ regmatch_info *reginfo, char **startpos)
 {
     dVAR;
-    register I32 *sp;
-    register I32 *ep;
     CHECKPOINT lastcp;
     regexp *prog = reginfo->prog;
     RXi_GET_DECL(prog,progi);
@@ -2260,9 +2257,9 @@ S_regtry(pTHX_ regmatch_info *reginfo, char **startpos)
      * on those tests seems to be returning null fields from matches.
      * --jhi */
 #if 1
-    sp = PL_regstartp;
-    ep = PL_regendp;
     if (prog->nparens) {
+       I32 *sp = PL_regstartp;
+       I32 *ep = PL_regendp;
        register I32 i;
        for (i = prog->nparens; i > (I32)*PL_reglastparen; i--) {
            *++sp = -1;
@@ -2314,7 +2311,7 @@ S_regtry(pTHX_ regmatch_info *reginfo, char **startpos)
 STATIC regmatch_state *
 S_push_slab(pTHX)
 {
-#if PERL_VERSION < 9
+#if PERL_VERSION < 9 && !defined(PERL_CORE)
     dMY_CXT;
 #endif
     regmatch_slab *s = PL_regmatch_slab->next;
@@ -2485,7 +2482,7 @@ regmatch(), slabs allocated since entry are freed.
        PerlIO_printf(Perl_debug_log,                       \
            "    %*s"pp" %s%s%s%s%s\n",                     \
            depth*2, "",                                    \
-           reg_name[st->resume_state],                     \
+           PL_reg_name[st->resume_state],                     \
            ((st==yes_state||st==mark_state) ? "[" : ""),   \
            ((st==yes_state) ? "Y" : ""),                   \
            ((st==mark_state) ? "M" : ""),                  \
@@ -2611,10 +2608,14 @@ S_reg_check_named_buff_matched(pTHX_ const regexp *rex, const regnode *scan) {
     return 0;
 }
 
+#define SETREX(Re1,Re2) \
+    if (PL_reg_eval_set) PM_SETRE((PL_reg_curpm), (Re2)); \
+    Re1 = (Re2)
+
 STATIC I32                     /* 0 failure, 1 success */
 S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
 {
-#if PERL_VERSION < 9
+#if PERL_VERSION < 9 && !defined(PERL_CORE)
     dMY_CXT;
 #endif
     dVAR;
@@ -3654,8 +3655,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
                    }
 
                    if (mg) {
-                       re = (regexp *)mg->mg_obj;
-                       (void)ReREFCNT_inc(re);
+                       re = reg_temp_copy((regexp *)mg->mg_obj); /*XXX:dmq*/
                    }
                    else {
                        STRLEN len;
@@ -3674,6 +3674,9 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
                        PL_regsize = osize;
                    }
                }
+                RX_MATCH_COPIED_off(re);
+                re->subbeg = rex->subbeg;
+                re->sublen = rex->sublen;
                rei = RXi_GET(re);
                 DEBUG_EXECUTE_r(
                     debug_start_match(re, do_utf8, locinput, PL_regeol, 
@@ -3715,7 +3718,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
 
                ST.prev_rex = rex;
                ST.prev_curlyx = cur_curlyx;
-               rex = re;
+               SETREX(rex,re);
                rexi = rei;
                cur_curlyx = NULL;
                ST.B = next;
@@ -3735,7 +3738,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
            /* note: this is called twice; first after popping B, then A */
            PL_reg_flags ^= ST.toggle_reg_flags; 
            ReREFCNT_dec(rex);
-           rex = ST.prev_rex;
+           SETREX(rex,ST.prev_rex);
            rexi = RXi_GET(rex);
            regcpblow(ST.cp);
            cur_eval = ST.prev_eval;
@@ -3751,7 +3754,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
            /* note: this is called twice; first after popping B, then A */
            PL_reg_flags ^= ST.toggle_reg_flags; 
            ReREFCNT_dec(rex);
-           rex = ST.prev_rex;
+           SETREX(rex,ST.prev_rex);
            rexi = RXi_GET(rex); 
            PL_reginput = locinput;
            REGCP_UNWIND(ST.lastcp);
@@ -4760,7 +4763,7 @@ NULL
                PL_reg_flags ^= st->u.eval.toggle_reg_flags; 
 
                st->u.eval.prev_rex = rex;              /* inner */
-               rex  = cur_eval->u.eval.prev_rex;       /* outer */
+               SETREX(rex,cur_eval->u.eval.prev_rex);
                rexi = RXi_GET(rex);
                cur_curlyx = cur_eval->u.eval.prev_curlyx;
                ReREFCNT_inc(rex);
@@ -5008,7 +5011,7 @@ NULL
                     }
                     PerlIO_printf(Perl_error_log, "%*s#%-3d %-10s %s\n",
                         REPORT_CODE_OFF + 2 + depth * 2,"",
-                        curd, reg_name[cur->resume_state],
+                        curd, PL_reg_name[cur->resume_state],
                         (curyes == cur) ? "yes" : ""
                     );
                     if (curyes == cur)