This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add CX_LEAVE_SCOPE(cx) macro
authorDavid Mitchell <davem@iabyn.com>
Sat, 10 Oct 2015 21:49:46 +0000 (22:49 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Feb 2016 08:59:40 +0000 (08:59 +0000)
which is shorthand for

    LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix)

This is the start of a new breed of macros designed to manipulate the
conetect stack, that have a CX_ prefix, that will eventually superede
the (PUSH/POP)(BLOCK/SUB/ETC) system.

cop.h
pp_ctl.c
pp_hot.c

diff --git a/cop.h b/cop.h
index d637a6d..f7e6f68 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -570,6 +570,11 @@ struct block_format {
     GV *       dfoutgv;
 };
 
+/* free all savestack items back to the watermark of the specified context */
+
+#define CX_LEAVE_SCOPE(cx) \
+    LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix)
+
 /* base for the next two macros. Don't use directly.
  * The context frame holds a reference to the CV so that it can't be
  * freed while we're executing it */
@@ -648,7 +653,7 @@ struct block_format {
 
 #define POPSUB(cx,sv)                                                  \
     STMT_START {                                                       \
-       LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);             \
+       CX_LEAVE_SCOPE(cx);                                             \
         if (!(cx->blk_u16 & CxPOPSUB_DONE)) {                           \
         cx->blk_u16 |= CxPOPSUB_DONE;                                   \
        RETURN_PROBE(CvNAMED(cx->blk_sub.cv)                            \
@@ -687,7 +692,7 @@ struct block_format {
 
 #define POPFORMAT(cx)                                                  \
     STMT_START {                                                       \
-       LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);             \
+       CX_LEAVE_SCOPE(cx);                                             \
         if (!(cx->blk_u16 & CxPOPSUB_DONE)) {                           \
        CV * const cv = cx->blk_format.cv;                              \
        GV * const dfuot = cx->blk_format.dfoutgv;                      \
@@ -820,7 +825,7 @@ struct block_loop {
         PUSHLOOP_FOR_setpad(cx);
 
 #define POPLOOP(cx)                                                    \
-       LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);             \
+       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);           \
@@ -855,11 +860,11 @@ struct block_givwhen {
         cx->blk_givwhen.defsv_save = orig_var;
 
 #define POPWHEN(cx)                                                     \
-        LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);             \
+       CX_LEAVE_SCOPE(cx);                                             \
         PL_tmps_floor = cx->cx_u.cx_blk.blku_old_tmpsfloor;
 
 #define POPGIVEN(cx)                                                    \
-        LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);             \
+       CX_LEAVE_SCOPE(cx);                                             \
         SvREFCNT_dec(GvSV(PL_defgv));                                   \
         GvSV(PL_defgv) = cx->blk_givwhen.defsv_save;                    \
         PL_tmps_floor = cx->cx_u.cx_blk.blku_old_tmpsfloor;
@@ -867,13 +872,13 @@ struct block_givwhen {
 
 /* basic block, i.e. pp_enter/leave */
 
-#define PUSHBASICBLK(cx)                                                     \
+#define PUSHBASICBLK(cx)                                                \
         cx->cx_u.cx_blk.blku_old_savestack_ix = PL_savestack_ix;        \
         cx->cx_u.cx_blk.blku_old_tmpsfloor = PL_tmps_floor;             \
         PL_tmps_floor = PL_tmps_ix;
 
-#define POPBASICBLK(cx)                                                      \
-        LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);             \
+#define POPBASICBLK(cx)                                                 \
+       CX_LEAVE_SCOPE(cx);                                             \
         PL_tmps_floor = cx->cx_u.cx_blk.blku_old_tmpsfloor;
 
 
@@ -1315,7 +1320,7 @@ See L<perlcall/LIGHTWEIGHT CALLBACKS>.
         newsp = PL_stack_base + cx->blk_oldsp;                          \
         gimme = cx->blk_gimme;                                          \
         /* includes partial unrolled POPSUB(): */                       \
-       LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);             \
+       CX_LEAVE_SCOPE(cx);                                             \
         PL_comppad = cx->blk_sub.prevcomppad;                           \
         PL_curpad = LIKELY(PL_comppad) ? AvARRAY(PL_comppad) : NULL;    \
        POPSTACK;                                                       \
index 9f32a24..47b61b9 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1659,7 +1659,7 @@ Perl_die_unwind(pTHX_ SV *msv)
            }
 
            POPBLOCK(cx,PL_curpm);
-            LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);
+            CX_LEAVE_SCOPE(cx);
            POPEVAL(cx);
            namesv = cx->blk_eval.old_namesv;
 #ifdef DEBUGGING
@@ -2615,7 +2615,7 @@ PP(pp_redo)
     }
 
     TOPBLOCK(cx);
-    LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);
+    CX_LEAVE_SCOPE(cx);
     FREETMPS;
     PL_curcop = cx->blk_oldcop;
     PERL_ASYNC_CHECK();
@@ -2770,7 +2770,7 @@ PP(pp_goto)
                 SvREFCNT_inc_NN(sv_2mortal(MUTABLE_SV(arg)));
 
            assert(PL_scopestack_ix == cx->blk_oldscopesp);
-            LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);
+            CX_LEAVE_SCOPE(cx);
 
            if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)) {
                AV* av = MUTABLE_AV(PAD_SVl(0));
@@ -3444,7 +3444,7 @@ S_doeval(pTHX_ int gimme, CV* outside, U32 seq, HV *hh)
            }
            SP = PL_stack_base + POPMARK;       /* pop original mark */
            POPBLOCK(cx,PL_curpm);
-            LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);
+            CX_LEAVE_SCOPE(cx);
            POPEVAL(cx);
            namesv = cx->blk_eval.old_namesv;
            /* POPBLOCK has rendered LEAVE_with_name("evalcomp") unnecessary */
@@ -4283,7 +4283,7 @@ PP(pp_leaveeval)
     if (gimme != G_VOID)
         SP = leave_common(newsp, SP, newsp, gimme, SVs_TEMP, FALSE);
     POPBLOCK(cx,newpm);
-    LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);
+    CX_LEAVE_SCOPE(cx);
     POPEVAL(cx);
     namesv = cx->blk_eval.old_namesv;
     retop = cx->blk_eval.retop;
@@ -4328,7 +4328,7 @@ Perl_delete_eval_scope(pTHX)
     I32 optype;
        
     POPBLOCK(cx,newpm);
-    LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);
+    CX_LEAVE_SCOPE(cx);
     POPEVAL(cx);
     PL_curpm = newpm;
     PL_tmps_floor = cx->cx_u.cx_blk.blku_old_tmpsfloor;
@@ -4388,7 +4388,7 @@ PP(pp_leavetry)
                               SVs_PADTMP|SVs_TEMP, FALSE);
     POPBLOCK(cx,newpm);
     retop = cx->blk_eval.retop;
-    LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);
+    CX_LEAVE_SCOPE(cx);
     POPEVAL(cx);
     PERL_UNUSED_VAR(optype);
 
index 0762217..8f2298b 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -254,7 +254,7 @@ PP(pp_unstack)
             || CxTYPE(cx) == CXt_LOOP_LAZYSV
             || CxTYPE(cx) == CXt_LOOP_LAZYIV
         );
-        LEAVE_SCOPE(cx->cx_u.cx_blk.blku_old_savestack_ix);
+       CX_LEAVE_SCOPE(cx);
     }
     return NORMAL;
 }