Fix regexec.c so $^N and $+ are correctly updated so that they work properly inside...
[p5sagit/p5-mst-13.2.git] / regexec.c
index 479ad1f..6496694 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -2150,8 +2150,8 @@ got_it:
 
     if (PL_reg_eval_set)
        restore_pos(aTHX_ prog);
-    if (prog->paren_names) 
-        (void)hv_iterinit(prog->paren_names);
+    if (RXp_PAREN_NAMES(prog)) 
+        (void)hv_iterinit(RXp_PAREN_NAMES(prog));
 
     /* make sure $`, $&, $', and $digit will work later */
     if ( !(flags & REXEC_NOT_FIRST) ) {
@@ -3746,7 +3746,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
 
                    if (mg) {
                        rx = mg->mg_obj; /*XXX:dmq*/
-                       assert(re);
+                       assert(rx);
                    }
                    if (rx) {
                        rx = reg_temp_copy(rx);
@@ -3755,7 +3755,18 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
                        U32 pm_flags = 0;
                        const I32 osize = PL_regsize;
 
-                       if (DO_UTF8(ret)) pm_flags |= RXf_UTF8;
+                       if (DO_UTF8(ret)) {
+                           assert (SvUTF8(ret));
+                       } else if (SvUTF8(ret)) {
+                           /* Not doing UTF-8, despite what the SV says. Is
+                              this only if we're trapped in use 'bytes'?  */
+                           /* Make a copy of the octet sequence, but without
+                              the flag on, as the compiler now honours the
+                              SvUTF8 flag on ret.  */
+                           STRLEN len;
+                           const char *const p = SvPV(ret, len);
+                           ret = newSVpvn_flags(p, len, SVs_TEMP);
+                       }
                        rx = CALLREGCOMP(ret, pm_flags);
                        if (!(SvFLAGS(ret)
                              & (SVs_TEMP | SVs_PADTMP | SVf_READONLY
@@ -3796,8 +3807,12 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
                
                PL_regoffs = re->offs; /* essentially NOOP on GOSUB */
                
-               *PL_reglastparen = 0;
-               *PL_reglastcloseparen = 0;
+               /* see regtry, specifically PL_reglast(?:close)?paren is a pointer! (i dont know why) :dmq */
+               PL_reglastparen = &re->lastparen;
+               PL_reglastcloseparen = &re->lastcloseparen;
+               re->lastparen = 0;
+               re->lastcloseparen = 0;
+
                PL_reginput = locinput;
                PL_regsize = 0;
 
@@ -3840,6 +3855,10 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
            regcpblow(ST.cp);
            cur_eval = ST.prev_eval;
            cur_curlyx = ST.prev_curlyx;
+           
+           PL_reglastparen = &rex->lastparen;
+           PL_reglastcloseparen = &rex->lastcloseparen;
+           
            /* XXXX This is too dramatic a measure... */
            PL_reg_maxiter = 0;
             if ( nochange_depth )
@@ -3854,6 +3873,9 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
            SETREX(rex_sv,ST.prev_rex);
            rex = (struct regexp *)SvANY(rex_sv);
            rexi = RXi_GET(rex); 
+           PL_reglastparen = &rex->lastparen;
+           PL_reglastcloseparen = &rex->lastcloseparen;
+
            PL_reginput = locinput;
            REGCP_UNWIND(ST.lastcp);
            regcppop(rex);