This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
eliminate LEAVESUB() macro
authorDavid Mitchell <davem@iabyn.com>
Sat, 10 Oct 2015 22:22:30 +0000 (23:22 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Feb 2016 08:59:41 +0000 (08:59 +0000)
Many years ago, POPSUB was split into two parts, with a final cleanup
being done by the LEAVESUB() macro. After the previous commit, LEAVESUB
now always immediately follows POPSUB, so roll its action into the
last line of POPSUB and eliminate it.

This also allows us to remove the 'sv' parameter from POPSUB(), which
was needed purely to communicate to LEAVESUB() which var to process

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

diff --git a/cop.h b/cop.h
index fbaa8a0..51782eb 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -651,7 +651,7 @@ struct block_format {
        AvFILLp(ary) = -1;                                              \
     } STMT_END
 
-#define POPSUB(cx,sv)                                                  \
+#define POPSUB(cx)                                                     \
     STMT_START {                                                       \
        CX_LEAVE_SCOPE(cx);                                             \
         if (!(cx->blk_u16 & CxPOPSUB_DONE)) {                           \
@@ -681,13 +681,8 @@ struct block_format {
         PL_tmps_floor = cx->cx_u.cx_blk.blku_old_tmpsfloor;             \
         PL_comppad = cx->blk_sub.prevcomppad;                           \
         PL_curpad = LIKELY(PL_comppad) ? AvARRAY(PL_comppad) : NULL;    \
-       sv = MUTABLE_SV(cx->blk_sub.cv);                                \
-        CvDEPTH((const CV*)sv) = cx->blk_sub.olddepth;                  \
-    } STMT_END
-
-#define LEAVESUB(sv)                                                   \
-    STMT_START {                                                       \
-       SvREFCNT_dec(sv);                                               \
+        CvDEPTH((const CV*)cx->blk_sub.cv) = cx->blk_sub.olddepth;      \
+       SvREFCNT_dec_NN(cx->blk_sub.cv);                                \
     } STMT_END
 
 #define POPFORMAT(cx)                                                  \
@@ -1323,7 +1318,7 @@ See L<perlcall/LIGHTWEIGHT CALLBACKS>.
        CX_LEAVE_SCOPE(cx);                                             \
         PL_comppad = cx->blk_sub.prevcomppad;                           \
         PL_curpad = LIKELY(PL_comppad) ? AvARRAY(PL_comppad) : NULL;    \
-        LEAVESUB(multicall_cv);                                        \
+        SvREFCNT_dec_NN(multicall_cv);                                  \
        POPSTACK;                                                       \
        CATCH_SET(multicall_oldcatch);                                  \
        SPAGAIN;                                                        \
@@ -1340,7 +1335,7 @@ See L<perlcall/LIGHTWEIGHT CALLBACKS>.
        cx = &cxstack[cxstack_ix];                                      \
        assert(cx->cx_type & CXp_MULTICALL);                            \
        CvDEPTH(multicall_cv) = cx->blk_sub.olddepth;                   \
-        LEAVESUB(multicall_cv);                                                \
+        SvREFCNT_dec_NN(multicall_cv);                                  \
        cx->cx_type = (CXt_SUB|CXp_MULTICALL|flags);                    \
         {                                                               \
             /* save a few things that we don't want PUSHSUB to zap */   \
index d30b520..796ee4c 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1507,7 +1507,6 @@ Perl_dounwind(pTHX_ I32 cxix)
        return;
 
     while (cxstack_ix > cxix) {
-       SV *sv;
         PERL_CONTEXT *cx = &cxstack[cxstack_ix];
        DEBUG_CX("UNWIND");                                             \
        /* Note: we don't need to restore the base context info till the end. */
@@ -1516,8 +1515,7 @@ Perl_dounwind(pTHX_ I32 cxix)
            POPSUBST(cx);
            continue;  /* not break */
        case CXt_SUB:
-           POPSUB(cx,sv);
-           LEAVESUB(sv);
+           POPSUB(cx);
            break;
        case CXt_EVAL:
            POPEVAL(cx);
@@ -2303,7 +2301,6 @@ PP(pp_leavesublv)
     PMOP *newpm;
     I32 gimme;
     PERL_CONTEXT *cx;
-    SV *sv;
     bool ref;
     const char *what = NULL;
 
@@ -2326,7 +2323,6 @@ PP(pp_leavesublv)
     ref = !!(CxLVAL(cx) & OPpENTERSUB_INARGS);
     if (gimme == G_SCALAR) {
        if (CxLVAL(cx) && !ref) {     /* Leave it as it is if we can. */
-           SV *sv;
            if (MARK <= SP) {
                if ((SvPADTMP(TOPs) || SvREADONLY(TOPs)) &&
                    !SvSMAGICAL(TOPs)) {
@@ -2341,8 +2337,7 @@ PP(pp_leavesublv)
                what = "undef";
            }
           croak:
-           POPSUB(cx,sv);
-           LEAVESUB(sv);
+           POPSUB(cx);
            cxstack_ix--;
            PL_curpm = cx->blk_oldpm;
            Perl_croak(aTHX_
@@ -2413,8 +2408,7 @@ PP(pp_leavesublv)
 
     POPBLOCK(cx,newpm);
     cxstack_ix++; /* preserve cx entry on stack for use by POPSUB */
-    POPSUB(cx,sv);     /* Stack values are safe: release CV and @_ ... */
-    LEAVESUB(sv);
+    POPSUB(cx);        /* Stack values are safe: release CV and @_ ... */
     cxstack_ix--;
     PL_curpm = newpm;  /* ... and pop $1 et al */
 
index 081c163..b5971f3 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -3274,7 +3274,6 @@ PP(pp_leavesub)
     PMOP *newpm;
     I32 gimme;
     PERL_CONTEXT *cx;
-    SV *sv;
 
     cx = &cxstack[cxstack_ix];
     assert(CxTYPE(cx) == CXt_SUB);
@@ -3308,7 +3307,7 @@ PP(pp_leavesub)
                    sv_2mortal(*MARK);
                }
                else {
-                   sv = SvREFCNT_inc(TOPs);    /* FREETMPS could clobber it */
+                    SV *sv = SvREFCNT_inc(TOPs); /* FREETMPS could clobber it */
                    FREETMPS;
                    *MARK = sv_mortalcopy(sv);
                    SvREFCNT_dec_NN(sv);
@@ -3340,8 +3339,7 @@ PP(pp_leavesub)
 
     POPBLOCK(cx,newpm);
     cxstack_ix++; /* temporarily protect top context */
-    POPSUB(cx,sv);     /* Stack values are safe: release CV and @_ ... */
-    LEAVESUB(sv);
+    POPSUB(cx);        /* Stack values are safe: release CV and @_ ... */
     cxstack_ix--;
     PL_curpm = newpm;  /* ... and pop $1 et al */
 
index fbbf848..1de1ca9 100644 (file)
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1707,12 +1707,10 @@ PP(pp_sort)
                    sort_flags);
 
            if (!(flags & OPf_SPECIAL)) {
-               SV *sv;
                /* Reset cx, in case the context stack has been
                   reallocated. */
                cx = &cxstack[cxstack_ix];
-               POPSUB(cx, sv);
-               LEAVESUB(sv);
+               POPSUB(cx);
            }
             else
                 /* mimic POPSUB */