Use find_runcv_where for pp_coreargs and pp_runcv
authorFather Chrysostomos <sprout@cpan.org>
Sat, 30 Jun 2012 21:34:42 +0000 (14:34 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 2 Jul 2012 15:44:07 +0000 (08:44 -0700)
pp.c
pp.h
pp_ctl.c

diff --git a/pp.c b/pp.c
index 0324c19..661c055 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -5797,16 +5797,9 @@ PP(pp_coreargs)
        case OA_SCALAR:
          try_defsv:
            if (!numargs && defgv && whicharg == minargs + 1) {
-               PERL_SI * const oldsi = PL_curstackinfo;
-               I32 const oldcxix = oldsi->si_cxix;
-               CV *caller;
-               if (oldcxix) oldsi->si_cxix--;
-               else PL_curstackinfo = oldsi->si_prev;
-               caller = find_runcv(NULL);
-               PL_curstackinfo = oldsi;
-               oldsi->si_cxix = oldcxix;
                PUSHs(find_rundefsv2(
-                   caller,cxstack[cxstack_ix].blk_oldcop->cop_seq
+                   find_runcv_where(FIND_RUNCV_level_eq, (void *)1, NULL),
+                   cxstack[cxstack_ix].blk_oldcop->cop_seq
                ));
            }
            else PUSHs(numargs ? svp && *svp ? *svp : &PL_sv_undef : NULL);
@@ -5894,13 +5887,7 @@ PP(pp_runcv)
     dSP;
     CV *cv;
     if (PL_op->op_private & OPpOFFBYONE) {
-       PERL_SI * const oldsi = PL_curstackinfo;
-       I32 const oldcxix = oldsi->si_cxix;
-       if (oldcxix) oldsi->si_cxix--;
-       else PL_curstackinfo = oldsi->si_prev;
-       cv = find_runcv(NULL);
-       PL_curstackinfo = oldsi;
-       oldsi->si_cxix = oldcxix;
+       cv = find_runcv_where(FIND_RUNCV_level_eq, (void *)1, NULL);
     }
     else cv = find_runcv(NULL);
     XPUSHs(CvEVAL(cv) ? &PL_sv_undef : sv_2mortal(newRV((SV *)cv)));
diff --git a/pp.h b/pp.h
index e684ce9..7f1b770 100644 (file)
--- a/pp.h
+++ b/pp.h
@@ -527,6 +527,7 @@ True if this op will be the return value of an lvalue subroutine
 #  define MAYBE_DEREF_GV_nomg(sv) MAYBE_DEREF_GV_flags(sv,0)
 
 #  define FIND_RUNCV_root_eq   1
+#  define FIND_RUNCV_level_eq  2
 
 #endif
 
index 0fee02a..75204b1 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3254,6 +3254,7 @@ Perl_find_runcv_where(pTHX_ U8 cond, void *arg, U32 *db_seqp)
 {
     dVAR;
     PERL_SI     *si;
+    int                 level = 0;
 
     if (db_seqp)
        *db_seqp = PL_curcop->cop_seq;
@@ -3276,6 +3277,9 @@ Perl_find_runcv_where(pTHX_ U8 cond, void *arg, U32 *db_seqp)
                switch (cond) {
                case FIND_RUNCV_root_eq:
                    if (CvROOT(cv) != (OP *)arg) continue;
+                   return cv;
+               case FIND_RUNCV_level_eq:
+                   if (level++ != (int)arg) continue;
                    /* GERONIMO! */
                default:
                    return cv;