This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_sort: add missing CX_LEAVE_SCOPE()
authorDavid Mitchell <davem@iabyn.com>
Thu, 15 Oct 2015 07:52:18 +0000 (08:52 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Feb 2016 08:59:42 +0000 (08:59 +0000)
The branch that does POPSUB has an implicit CX_LEAVE_SCOPE; the
other branch didn't; do add one for consistency. It's fairly harmless,
as pp_sort shortly afterwards does a LEAVE() anyway.

Also add an assertion to POPBLOCK that the save stack has been popped;
this is how I discovered the sort issue in the first place.

cop.h
pp_sort.c

diff --git a/cop.h b/cop.h
index 5cce43f..806f72c 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -942,6 +942,11 @@ struct block {
        PL_curcop        = cx->blk_oldcop,                              \
        PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp,            \
        PL_scopestack_ix = cx->blk_oldscopesp,                          \
+        /* LEAVE_SCOPE() should have made this true. /(?{})/ cheats
+         * and leaves a CX entry lying around for repeated use, so
+         * skip for multicall */                  \
+        assert(CxMULTICALL(cx) ||                                       \
+            PL_savestack_ix == cx->cx_u.cx_blk.blku_old_savestack_ix);  \
        PL_curpm         = cx->blk_oldpm;
 
 /* Continue a block elsewhere (NEXT and REDO). */
index 47d4a06..5cab129 100644 (file)
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1718,6 +1718,7 @@ PP(pp_sort)
             else
                 assert(CxTYPE(cx) == CXt_NULL);
                 /* mimic POPSUB */
+                CX_LEAVE_SCOPE(cx);
                 PL_tmps_floor = cx->cx_u.cx_blk.blku_old_tmpsfloor;
 
            POPBLOCK(cx);