This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
move CX_LEAVE_SCOPE outside the POPFOO's
authorDavid Mitchell <davem@iabyn.com>
Thu, 15 Oct 2015 12:48:25 +0000 (13:48 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Feb 2016 08:59:43 +0000 (08:59 +0000)
Currently every POPFOO macro has CX_LEAVE_SCOPE(cx) as its first action.
Since this is common code and not specific to a particular POPFOO type,
remove it from each POPFOO macro and make each caller of POPFOO explicitly
call CX_LEAVE_SCOPE() instead.

This should make no functional difference (but will help if you're
single-stepping the code in a debugger :-)

cop.h
pp_ctl.c
pp_hot.c
pp_sort.c
pp_sys.c

diff --git a/cop.h b/cop.h
index c2a1dc0..b4e7cb2 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -649,7 +649,6 @@ struct block_format {
 
 #define POPSUB(cx)                                                     \
     STMT_START {                                                       \
-       CX_LEAVE_SCOPE(cx);                                             \
         if (!(cx->blk_u16 & CxPOPSUB_DONE)) {                           \
         cx->blk_u16 |= CxPOPSUB_DONE;                                   \
        RETURN_PROBE(CvNAMED(cx->blk_sub.cv)                            \
@@ -682,7 +681,6 @@ struct block_format {
 
 #define POPFORMAT(cx)                                                  \
     STMT_START {                                                       \
-       CX_LEAVE_SCOPE(cx);                                             \
         if (!(cx->blk_u16 & CxPOPSUB_DONE)) {                           \
        CV * const cv = cx->blk_format.cv;                              \
        GV * const dfuot = cx->blk_format.dfoutgv;                      \
@@ -729,7 +727,6 @@ struct block_eval {
 
 #define POPEVAL(cx)                                                    \
     STMT_START {                                                       \
-        CX_LEAVE_SCOPE(cx);                                             \
        PL_in_eval = CxOLD_IN_EVAL(cx);                                 \
        optype = CxOLD_OP_TYPE(cx);                                     \
        PL_eval_root = cx->blk_eval.old_eval_root;                      \
@@ -809,7 +806,6 @@ struct block_loop {
         PUSHLOOP_FOR_setpad(cx);
 
 #define POPLOOP(cx)                                                    \
-       CX_LEAVE_SCOPE(cx);                                             \
        if (CxTYPE(cx) == CXt_LOOP_LAZYSV) {                            \
            SvREFCNT_dec_NN(cx->blk_loop.state_u.lazysv.cur);           \
            SvREFCNT_dec_NN(cx->blk_loop.state_u.lazysv.end);           \
@@ -841,10 +837,9 @@ struct block_givwhen {
         cx->blk_givwhen.defsv_save = orig_var;
 
 #define POPWHEN(cx)                                                     \
-       CX_LEAVE_SCOPE(cx);
+       NOOP;
 
 #define POPGIVEN(cx)                                                    \
-       CX_LEAVE_SCOPE(cx);                                             \
         SvREFCNT_dec(GvSV(PL_defgv));                                   \
         GvSV(PL_defgv) = cx->blk_givwhen.defsv_save;
 
@@ -855,7 +850,7 @@ struct block_givwhen {
         cx->cx_u.cx_blk.blku_old_savestack_ix = PL_savestack_ix;
 
 #define POPBASICBLK(cx)                                                 \
-       CX_LEAVE_SCOPE(cx);
+       NOOP;
 
 
 /* context common to subroutines, evals and loops */
@@ -1291,8 +1286,8 @@ See L<perlcall/LIGHTWEIGHT CALLBACKS>.
     STMT_START {                                                       \
        cx = &cxstack[cxstack_ix];                                      \
         CvDEPTH(multicall_cv) = cx->blk_sub.olddepth;                   \
-        /* includes partial unrolled POPSUB(): */                       \
        CX_LEAVE_SCOPE(cx);                                             \
+        /* includes partial unrolled POPSUB(): */                       \
         PL_comppad = cx->blk_sub.prevcomppad;                           \
         PL_curpad = LIKELY(PL_comppad) ? AvARRAY(PL_comppad) : NULL;    \
         SvREFCNT_dec_NN(multicall_cv);                                  \
index 1f91532..d005076 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1515,29 +1515,38 @@ Perl_dounwind(pTHX_ I32 cxix)
            POPSUBST(cx);
            continue;  /* not break */
        case CXt_SUB:
+            CX_LEAVE_SCOPE(cx);
            POPSUB(cx);
            break;
        case CXt_EVAL:
+            CX_LEAVE_SCOPE(cx);
            POPEVAL(cx);
            break;
        case CXt_BLOCK:
+            CX_LEAVE_SCOPE(cx);
             POPBASICBLK(cx);
            break;
        case CXt_LOOP_LAZYIV:
        case CXt_LOOP_LAZYSV:
        case CXt_LOOP_FOR:
        case CXt_LOOP_PLAIN:
+            CX_LEAVE_SCOPE(cx);
            POPLOOP(cx);
            break;
        case CXt_WHEN:
+            CX_LEAVE_SCOPE(cx);
            POPWHEN(cx);
            break;
        case CXt_GIVEN:
+            CX_LEAVE_SCOPE(cx);
            POPGIVEN(cx);
            break;
        case CXt_NULL:
+            /* there isn't a POPNULL ! */
+            CX_LEAVE_SCOPE(cx);
            break;
        case CXt_FORMAT:
+            CX_LEAVE_SCOPE(cx);
            POPFORMAT(cx);
            break;
        }
@@ -1656,6 +1665,7 @@ Perl_die_unwind(pTHX_ SV *msv)
                my_exit(1);
            }
 
+            CX_LEAVE_SCOPE(cx);
            POPEVAL(cx);
            POPBLOCK(cx);
             cxstack_ix--;
@@ -2091,6 +2101,7 @@ PP(pp_leave)
         leave_common(newsp, newsp, gimme, SVs_PADTMP|SVs_TEMP,
                                PL_op->op_private & OPpLVALUE);
 
+    CX_LEAVE_SCOPE(cx);
     POPBASICBLK(cx);
     POPBLOCK(cx);
     cxstack_ix--;
@@ -2267,6 +2278,7 @@ PP(pp_leaveloop)
         leave_common(newsp, MARK, gimme, SVs_PADTMP|SVs_TEMP,
                               PL_op->op_private & OPpLVALUE);
 
+    CX_LEAVE_SCOPE(cx);
     POPLOOP(cx);       /* Stack values are safe: release loop vars ... */
     POPBLOCK(cx);
     cxstack_ix--;
@@ -2326,6 +2338,7 @@ PP(pp_leavesublv)
                what = "undef";
            }
           croak:
+            CX_LEAVE_SCOPE(cx);
            POPSUB(cx);
            cxstack_ix--;
            PL_curpm = cx->blk_oldpm;
@@ -2395,6 +2408,7 @@ PP(pp_leavesublv)
     }
     PUTBACK;
 
+    CX_LEAVE_SCOPE(cx);
     POPSUB(cx);        /* Stack values are safe: release CV and @_ ... */
     POPBLOCK(cx);
     cxstack_ix--;
@@ -2570,6 +2584,7 @@ PP(pp_last)
     TAINT_NOT;
 
     /* Stack values are safe: */
+    CX_LEAVE_SCOPE(cx);
     POPLOOP(cx);       /* release loop vars ... */
     POPBLOCK(cx);
     cxstack_ix--;
@@ -2751,8 +2766,6 @@ PP(pp_goto)
            TOPBLOCK(cx);
            SPAGAIN;
 
-            /* partial unrolled POPSUB(): */
-
             /* protect @_ during save stack unwind. */
             if (arg)
                 SvREFCNT_inc_NN(sv_2mortal(MUTABLE_SV(arg)));
@@ -2760,6 +2773,8 @@ PP(pp_goto)
            assert(PL_scopestack_ix == cx->blk_oldscopesp);
             CX_LEAVE_SCOPE(cx);
 
+            /* partial unrolled POPSUB(): */
+
            if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)) {
                AV* av = MUTABLE_AV(PAD_SVl(0));
                 assert(AvARRAY(MUTABLE_AV(
@@ -3432,6 +3447,7 @@ S_doeval(pTHX_ int gimme, CV* outside, U32 seq, HV *hh)
            }
            SP = PL_stack_base + POPMARK;       /* pop original mark */
             cx = &cxstack[cxstack_ix];
+            CX_LEAVE_SCOPE(cx);
            POPEVAL(cx);
            POPBLOCK(cx);
             cxstack_ix--;
@@ -4278,6 +4294,7 @@ PP(pp_leaveeval)
      * to get the current hints. So restore it early.
      */
     PL_curcop = cx->blk_oldcop;
+    CX_LEAVE_SCOPE(cx);
     POPEVAL(cx);
     POPBLOCK(cx);
     cxstack_ix--;
@@ -4320,6 +4337,7 @@ Perl_delete_eval_scope(pTHX)
     I32 optype;
        
     cx = &cxstack[cxstack_ix];
+    CX_LEAVE_SCOPE(cx);
     POPEVAL(cx);
     POPBLOCK(cx);
     cxstack_ix--;
@@ -4375,6 +4393,7 @@ PP(pp_leavetry)
         PL_stack_sp = newsp;
     else
         leave_common(newsp, newsp, gimme, SVs_PADTMP|SVs_TEMP, FALSE);
+    CX_LEAVE_SCOPE(cx);
     POPEVAL(cx);
     POPBLOCK(cx);
     cxstack_ix--;
@@ -4418,6 +4437,8 @@ PP(pp_leavegiven)
         PL_stack_sp = newsp;
     else
         leave_common(newsp, newsp, gimme, SVs_PADTMP|SVs_TEMP, FALSE);
+
+    CX_LEAVE_SCOPE(cx);
     POPGIVEN(cx);
     POPBLOCK(cx);
     cxstack_ix--;
@@ -5037,6 +5058,7 @@ PP(pp_continue)
     cx = &cxstack[cxstack_ix];
     assert(CxTYPE(cx) == CXt_WHEN);
     PL_stack_sp = PL_stack_base + cx->blk_oldsp;
+    CX_LEAVE_SCOPE(cx);
     POPWHEN(cx);
     POPBLOCK(cx);
     cxstack_ix--;
index 22b9dd4..147f9cb 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -3336,6 +3336,7 @@ PP(pp_leavesub)
     }
     PUTBACK;
 
+    CX_LEAVE_SCOPE(cx);
     POPSUB(cx);        /* Stack values are safe: release CV and @_ ... */
     POPBLOCK(cx);
     cxstack_ix--;
index 1d6f7d6..63214b9 100644 (file)
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1703,14 +1703,14 @@ PP(pp_sort)
 
            PL_stack_sp = PL_stack_base + cx->blk_oldsp;
 
+            CX_LEAVE_SCOPE(cx);
            if (!(flags & OPf_SPECIAL)) {
                 assert(CxTYPE(cx) == CXt_SUB);
                 POPSUB(cx);
            }
-            else {
+            else
                 assert(CxTYPE(cx) == CXt_NULL);
-                CX_LEAVE_SCOPE(cx);
-            }
+                /* there isn't a POPNULL ! */
 
            POPBLOCK(cx);
             cxstack_ix--;
index 6c978eb..be4dec4 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1523,6 +1523,7 @@ PP(pp_leavewrite)
     cx = &cxstack[cxstack_ix];
     assert(CxTYPE(cx) == CXt_FORMAT);
     SP = PL_stack_base + cx->blk_oldsp; /* ignore retval of formline */
+    CX_LEAVE_SCOPE(cx);
     POPFORMAT(cx);
     POPBLOCK(cx);
     retop = cx->blk_sub.retop;