avoid stash pointers in optree under USE_ITHREADS
[p5sagit/p5-mst-13.2.git] / pp_hot.c
index 8afa2f8..f2e8e21 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -58,9 +58,9 @@ PP(pp_gvsv)
     djSP;
     EXTEND(SP,1);
     if (PL_op->op_private & OPpLVAL_INTRO)
-       PUSHs(save_scalar(cGVOP->op_gv));
+       PUSHs(save_scalar(cGVOP));
     else
-       PUSHs(GvSV(cGVOP->op_gv));
+       PUSHs(GvSV(cGVOP));
     RETURN;
 }
 
@@ -95,7 +95,7 @@ PP(pp_stringify)
 PP(pp_gv)
 {
     djSP;
-    XPUSHs((SV*)cGVOP->op_gv);
+    XPUSHs((SV*)cGVOP);
     RETURN;
 }
 
@@ -271,7 +271,7 @@ PP(pp_add)
 PP(pp_aelemfast)
 {
     djSP;
-    AV *av = GvAV((GV*)cSVOP->op_sv);
+    AV *av = GvAV(cGVOP);
     U32 lval = PL_op->op_flags & OPf_MOD;
     SV** svp = av_fetch(av, PL_op->op_private, lval);
     SV *sv = (svp ? *svp : &PL_sv_undef);
@@ -1085,9 +1085,9 @@ Perl_do_readline(pTHX)
        if (!fp) {
            if (IoFLAGS(io) & IOf_ARGV) {
                if (IoFLAGS(io) & IOf_START) {
-                   IoFLAGS(io) &= ~IOf_START;
                    IoLINES(io) = 0;
                    if (av_len(GvAVn(PL_last_in_gv)) < 0) {
+                       IoFLAGS(io) &= ~IOf_START;
                        do_open(PL_last_in_gv,"-",1,FALSE,O_RDONLY,0,Nullfp);
                        sv_setpvn(GvSV(PL_last_in_gv), "-", 1);
                        SvSETMAGIC(GvSV(PL_last_in_gv));
@@ -1098,7 +1098,6 @@ Perl_do_readline(pTHX)
                fp = nextargv(PL_last_in_gv);
                if (!fp) { /* Note: fp != IoIFP(io) */
                    (void)do_close(PL_last_in_gv, FALSE); /* now it does*/
-                   IoFLAGS(io) |= IOf_START;
                }
            }
            else if (type == OP_GLOB) {
@@ -1296,7 +1295,6 @@ Perl_do_readline(pTHX)
                if (fp)
                    continue;
                (void)do_close(PL_last_in_gv, FALSE);
-               IoFLAGS(io) |= IOf_START;
            }
            else if (type == OP_GLOB) {
                if (!do_close(PL_last_in_gv, FALSE) && ckWARN(WARN_CLOSED)) {
@@ -1914,16 +1912,15 @@ PP(pp_leavesub)
     PMOP *newpm;
     I32 gimme;
     register PERL_CONTEXT *cx;
-    struct block_sub cxsub;
+    SV *sv;
 
     POPBLOCK(cx,newpm);
-    POPSUB1(cx);       /* Delay POPSUB2 until stack values are safe */
  
     TAINT_NOT;
     if (gimme == G_SCALAR) {
        MARK = newsp + 1;
        if (MARK <= SP) {
-           if (cxsub.cv && CvDEPTH(cxsub.cv) > 1) {
+           if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
                if (SvTEMP(TOPs)) {
                    *MARK = SvREFCNT_inc(TOPs);
                    FREETMPS;
@@ -1953,10 +1950,11 @@ PP(pp_leavesub)
     }
     PUTBACK;
     
-    POPSUB2();         /* Stack values are safe: release CV and @_ ... */
+    POPSUB(cx,sv);     /* Stack values are safe: release CV and @_ ... */
     PL_curpm = newpm;  /* ... and pop $1 et al */
 
     LEAVE;
+    LEAVESUB(sv);
     return pop_return();
 }
 
@@ -1970,10 +1968,9 @@ PP(pp_leavesublv)
     PMOP *newpm;
     I32 gimme;
     register PERL_CONTEXT *cx;
-    struct block_sub cxsub;
+    SV *sv;
 
     POPBLOCK(cx,newpm);
-    POPSUB1(cx);       /* Delay POPSUB2 until stack values are safe */
  
     TAINT_NOT;
 
@@ -1988,7 +1985,7 @@ PP(pp_leavesublv)
        if (gimme == G_SCALAR)
            goto temporise;
        if (gimme == G_ARRAY) {
-           if (!CvLVALUE(cxsub.cv))
+           if (!CvLVALUE(cx->blk_sub.cv))
                goto temporise_array;
            EXTEND_MORTAL(SP - newsp);
            for (mark = newsp + 1; mark <= SP; mark++) {
@@ -1999,7 +1996,7 @@ PP(pp_leavesublv)
                else {
                    /* Can be a localized value subject to deletion. */
                    PL_tmps_stack[++PL_tmps_ix] = *mark;
-                   SvREFCNT_inc(*mark);
+                   (void)SvREFCNT_inc(*mark);
                }
            }
        }
@@ -2008,9 +2005,11 @@ PP(pp_leavesublv)
        /* Here we go for robustness, not for speed, so we change all
         * the refcounts so the caller gets a live guy. Cannot set
         * TEMP, so sv_2mortal is out of question. */
-       if (!CvLVALUE(cxsub.cv)) {
-           POPSUB2();
+       if (!CvLVALUE(cx->blk_sub.cv)) {
+           POPSUB(cx,sv);
            PL_curpm = newpm;
+           LEAVE;
+           LEAVESUB(sv);
            DIE(aTHX_ "Can't modify non-lvalue subroutine call");
        }
        if (gimme == G_SCALAR) {
@@ -2018,20 +2017,24 @@ PP(pp_leavesublv)
            EXTEND_MORTAL(1);
            if (MARK == SP) {
                if (SvFLAGS(TOPs) & (SVs_TEMP | SVs_PADTMP | SVf_READONLY)) {
-                   POPSUB2();
+                   POPSUB(cx,sv);
                    PL_curpm = newpm;
+                   LEAVE;
+                   LEAVESUB(sv);
                    DIE(aTHX_ "Can't return a %s from lvalue subroutine",
                        SvREADONLY(TOPs) ? "readonly value" : "temporary");
                }
                else {                  /* Can be a localized value
                                         * subject to deletion. */
                    PL_tmps_stack[++PL_tmps_ix] = *mark;
-                   SvREFCNT_inc(*mark);
+                   (void)SvREFCNT_inc(*mark);
                }
            }
            else {                      /* Should not happen? */
-               POPSUB2();
+               POPSUB(cx,sv);
                PL_curpm = newpm;
+               LEAVE;
+               LEAVESUB(sv);
                DIE(aTHX_ "%s returned from lvalue subroutine in scalar context",
                    (MARK > SP ? "Empty array" : "Array"));
            }
@@ -2043,8 +2046,10 @@ PP(pp_leavesublv)
                if (SvFLAGS(*mark) & (SVs_TEMP | SVs_PADTMP | SVf_READONLY)) {
                    /* Might be flattened array after $#array =  */
                    PUTBACK;
-                   POPSUB2();
+                   POPSUB(cx,sv);
                    PL_curpm = newpm;
+                   LEAVE;
+                   LEAVESUB(sv);
                    DIE(aTHX_ "Can't return %s from lvalue subroutine",
                        (*mark != &PL_sv_undef)
                        ? (SvREADONLY(TOPs)
@@ -2055,7 +2060,7 @@ PP(pp_leavesublv)
                    mortalize:
                    /* Can be a localized value subject to deletion. */
                    PL_tmps_stack[++PL_tmps_ix] = *mark;
-                   SvREFCNT_inc(*mark);
+                   (void)SvREFCNT_inc(*mark);
                }
            }
        }
@@ -2065,7 +2070,7 @@ PP(pp_leavesublv)
          temporise:
            MARK = newsp + 1;
            if (MARK <= SP) {
-               if (cxsub.cv && CvDEPTH(cxsub.cv) > 1) {
+               if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
                    if (SvTEMP(TOPs)) {
                        *MARK = SvREFCNT_inc(TOPs);
                        FREETMPS;
@@ -2097,10 +2102,11 @@ PP(pp_leavesublv)
     }
     PUTBACK;
     
-    POPSUB2();         /* Stack values are safe: release CV and @_ ... */
+    POPSUB(cx,sv);     /* Stack values are safe: release CV and @_ ... */
     PL_curpm = newpm;  /* ... and pop $1 et al */
 
     LEAVE;
+    LEAVESUB(sv);
     return pop_return();
 }
 
@@ -2288,10 +2294,10 @@ try_autoload:
            while (MgOWNER(mg))
                COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
            MgOWNER(mg) = thr;
-           DEBUG_S(PerlIO_printf(PerlIO_stderr(), "%p: pp_entersub lock %p\n",
+           DEBUG_S(PerlIO_printf(Perl_debug_log, "%p: pp_entersub lock %p\n",
                                  thr, sv);)
            MUTEX_UNLOCK(MgMUTEXP(mg));
-           SAVEDESTRUCTOR(Perl_unlock_condpair, sv);
+           SAVEDESTRUCTOR_X(Perl_unlock_condpair, sv);
        }
        MUTEX_LOCK(CvMUTEXP(cv));
     }
@@ -2330,13 +2336,13 @@ try_autoload:
            /* We already have a clone to use */
            MUTEX_UNLOCK(CvMUTEXP(cv));
            cv = *(CV**)svp;
-           DEBUG_S(PerlIO_printf(PerlIO_stderr(),
+           DEBUG_S(PerlIO_printf(Perl_debug_log,
                                  "entersub: %p already has clone %p:%s\n",
                                  thr, cv, SvPEEK((SV*)cv)));
            CvOWNER(cv) = thr;
            SvREFCNT_inc(cv);
            if (CvDEPTH(cv) == 0)
-               SAVEDESTRUCTOR(unset_cvowner, (void*) cv);
+               SAVEDESTRUCTOR_X(unset_cvowner, (void*) cv);
        }
        else {
            /* (2) => grab ownership of cv. (3) => make clone */
@@ -2344,7 +2350,7 @@ try_autoload:
                CvOWNER(cv) = thr;
                SvREFCNT_inc(cv);
                MUTEX_UNLOCK(CvMUTEXP(cv));
-               DEBUG_S(PerlIO_printf(PerlIO_stderr(),
+               DEBUG_S(PerlIO_printf(Perl_debug_log,
                            "entersub: %p grabbing %p:%s in stash %s\n",
                            thr, cv, SvPEEK((SV*)cv), CvSTASH(cv) ?
                                HvNAME(CvSTASH(cv)) : "(none)"));
@@ -2354,7 +2360,7 @@ try_autoload:
                CV *clonecv;
                SvREFCNT_inc(cv); /* don't let it vanish from under us */
                MUTEX_UNLOCK(CvMUTEXP(cv));
-               DEBUG_S((PerlIO_printf(PerlIO_stderr(),
+               DEBUG_S((PerlIO_printf(Perl_debug_log,
                                       "entersub: %p cloning %p:%s\n",
                                       thr, cv, SvPEEK((SV*)cv))));
                /*
@@ -2372,9 +2378,9 @@ try_autoload:
                SvREFCNT_inc(cv);
            }
            DEBUG_S(if (CvDEPTH(cv) != 0)
-                       PerlIO_printf(PerlIO_stderr(), "depth %ld != 0\n",
+                       PerlIO_printf(Perl_debug_log, "depth %ld != 0\n",
                                      CvDEPTH(cv)););
-           SAVEDESTRUCTOR(unset_cvowner, (void*) cv);
+           SAVEDESTRUCTOR_X(unset_cvowner, (void*) cv);
        }
     }
 #endif /* USE_THREADS */
@@ -2487,6 +2493,9 @@ try_autoload:
                            SvPADMY_on(sv);
                        }
                    }
+                   else if (IS_PADGV(oldpad[ix])) {
+                       av_store(newpad, ix, sv = SvREFCNT_inc(oldpad[ix]));
+                   }
                    else {
                        av_store(newpad, ix, sv = NEWSV(0,0));
                        SvPADTMP_on(sv);
@@ -2525,11 +2534,17 @@ try_autoload:
            SV** ary;
 
 #if 0
-           DEBUG_S(PerlIO_printf(PerlIO_stderr(),
+           DEBUG_S(PerlIO_printf(Perl_debug_log,
                                  "%p entersub preparing @_\n", thr));
 #endif
            av = (AV*)PL_curpad[0];
-           assert(!AvREAL(av));
+           if (AvREAL(av)) {
+               /* @_ is normally not REAL--this should only ever
+                * happen when DB::sub() calls things that modify @_ */
+               av_clear(av);
+               AvREAL_off(av);
+               AvREIFY_on(av);
+           }
 #ifndef USE_THREADS
            cx->blk_sub.savearray = GvAV(PL_defgv);
            GvAV(PL_defgv) = (AV*)SvREFCNT_inc(av);
@@ -2567,7 +2582,7 @@ try_autoload:
            && !(PERLDB_SUB && cv == GvCV(PL_DBsub)))
            sub_crush_depth(cv);
 #if 0
-       DEBUG_S(PerlIO_printf(PerlIO_stderr(),
+       DEBUG_S(PerlIO_printf(Perl_debug_log,
                              "%p entersub returning %p\n", thr, CvSTART(cv)));
 #endif
        RETURNOP(CvSTART(cv));
@@ -2763,7 +2778,7 @@ S_method_common(pTHX_ SV* meth, U32* hashp)
                sep = p, leaf = p + 2;
        }
        if (!sep || ((sep - name) == 5 && strnEQ(name, "SUPER", 5))) {
-           packname = HvNAME(sep ? PL_curcop->cop_stash : stash);
+           packname = sep ? CopSTASHPV(PL_curcop) : HvNAME(stash);
            packlen = strlen(packname);
        }
        else {
@@ -2786,11 +2801,11 @@ unset_cvowner(pTHXo_ void *cvarg)
     dTHR;
 #endif /* DEBUGGING */
 
-    DEBUG_S((PerlIO_printf(PerlIO_stderr(), "%p unsetting CvOWNER of %p:%s\n",
+    DEBUG_S((PerlIO_printf(Perl_debug_log, "%p unsetting CvOWNER of %p:%s\n",
                           thr, cv, SvPEEK((SV*)cv))));
     MUTEX_LOCK(CvMUTEXP(cv));
     DEBUG_S(if (CvDEPTH(cv) != 0)
-               PerlIO_printf(PerlIO_stderr(), "depth %ld != 0\n",
+               PerlIO_printf(Perl_debug_log, "depth %ld != 0\n",
                              CvDEPTH(cv)););
     assert(thr == CvOWNER(cv));
     CvOWNER(cv) = 0;