Remove the _ prototype, as Maintainers is used by makemeta, and in turn
[p5sagit/p5-mst-13.2.git] / regexec.c
index 2fb1fbe..e64846f 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -397,7 +397,7 @@ Perl_re_intuit_start(pTHX_ REGEXP * const rx, SV *sv, char *strpos,
 
     RX_MATCH_UTF8_set(rx,do_utf8);
 
-    if (prog->extflags & RXf_UTF8) {
+    if (RX_UTF8(rx)) {
        PL_reg_flags |= RF_utf8;
     }
     DEBUG_EXECUTE_r( 
@@ -1806,7 +1806,7 @@ Perl_regexec_flags(pTHX_ REGEXP * const rx, char *stringarg, register char *stre
     PL_reg_eval_set = 0;
     PL_reg_maxiter = 0;
 
-    if (prog->extflags & RXf_UTF8)
+    if (RX_UTF8(rx))
        PL_reg_flags |= RF_utf8;
 
     /* Mark beginning of line for ^ and lookbehind. */
@@ -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) ) {
@@ -2255,15 +2255,24 @@ S_regtry(pTHX_ regmatch_info *reginfo, char **startpos)
            Newxz(PL_reg_curpm, 1, PMOP);
 #ifdef USE_ITHREADS
             {
-               SV* const repointer = newSViv(0);
-                /* so we know which PL_regex_padav element is PL_reg_curpm */
-                SvFLAGS(repointer) |= SVf_BREAK;
-                av_push(PL_regex_padav,repointer);
+               SV* const repointer = &PL_sv_undef;
+                /* this regexp is also owned by the new PL_reg_curpm, which
+                  will try to free it.  */
+                av_push(PL_regex_padav, repointer);
                 PL_reg_curpm->op_pmoffset = av_len(PL_regex_padav);
                 PL_regex_pad = AvARRAY(PL_regex_padav);
             }
 #endif      
         }
+#ifdef USE_ITHREADS
+       /* It seems that non-ithreads works both with and without this code.
+          So for efficiency reasons it seems best not to have the code
+          compiled when it is not needed.  */
+       /* This is safe against NULLs: */
+       ReREFCNT_dec(PM_GETRE(PL_reg_curpm));
+       /* PM_reg_curpm owns a reference to this regexp.  */
+       ReREFCNT_inc(rx);
+#endif
        PM_SETRE(PL_reg_curpm, rx);
        PL_reg_oldcurpm = PL_curpm;
        PL_curpm = PL_reg_curpm;
@@ -3633,7 +3642,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
 #define ST st->u.eval
        {
            SV *ret;
-           SV *re_sv;
+           REGEXP *re_sv;
             regexp *re;
             regexp_internal *rei;
             regnode *startpoint;
@@ -3720,13 +3729,13 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
                        SV *const sv = SvRV(ret);
 
                        if (SvTYPE(sv) == SVt_REGEXP) {
-                           rx = sv;
+                           rx = (REGEXP*) sv;
                        } else if (SvSMAGICAL(sv)) {
                            mg = mg_find(sv, PERL_MAGIC_qr);
                            assert(mg);
                        }
                    } else if (SvTYPE(ret) == SVt_REGEXP) {
-                       rx = ret;
+                       rx = (REGEXP*) ret;
                    } else if (SvSMAGICAL(ret)) {
                        if (SvGMAGICAL(ret)) {
                            /* I don't believe that there is ever qr magic
@@ -3745,8 +3754,8 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
                    }
 
                    if (mg) {
-                       rx = mg->mg_obj; /*XXX:dmq*/
-                       assert(re);
+                       rx = (REGEXP *) mg->mg_obj; /*XXX:dmq*/
+                       assert(rx);
                    }
                    if (rx) {
                        rx = reg_temp_copy(rx);
@@ -3755,7 +3764,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
@@ -3763,7 +3783,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
                            /* This isn't a first class regexp. Instead, it's
                               caching a regexp onto an existing, Perl visible
                               scalar.  */
-                           sv_magic(ret, rx, PERL_MAGIC_qr, 0, 0);
+                           sv_magic(ret, (SV*) rx, PERL_MAGIC_qr, 0, 0);
                        }
                        PL_regsize = osize;
                    }
@@ -3796,8 +3816,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;
 
@@ -3805,7 +3829,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, regnode *prog)
                PL_reg_maxiter = 0;
 
                ST.toggle_reg_flags = PL_reg_flags;
-               if (re->extflags & RXf_UTF8)
+               if (RX_UTF8(re_sv))
                    PL_reg_flags |= RF_utf8;
                else
                    PL_reg_flags &= ~RF_utf8;
@@ -3840,6 +3864,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 +3882,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);