This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
move and rename cx_old_savestack_ix
[perl5.git] / pp_sort.c
index f4664f9..a95796d 100644 (file)
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1640,8 +1640,8 @@ PP(pp_sort)
        SV **start;
        if (PL_sortcop) {
            PERL_CONTEXT *cx;
-           SV** newsp;
            const bool oldcatch = CATCH_GET;
+            I32 old_savestack_ix = PL_savestack_ix;
 
            SAVEOP();
 
@@ -1670,7 +1670,7 @@ PP(pp_sort)
             gimme = G_SCALAR;
            PUSHBLOCK(cx, CXt_NULL, PL_stack_base);
            if (!(flags & OPf_SPECIAL)) {
-               cx->cx_type = CXt_SUB;
+               cx->cx_type = CXt_SUB|CXp_MULTICALL;
                PUSHSUB(cx);
                if (!is_xsub) {
                    PADLIST * const padlist = CvPADLIST(cv);
@@ -1691,34 +1691,29 @@ PP(pp_sort)
 
                }
            }
-            else {
-                /* mimic PUSHSUB. Note that we're cheating and using a
-                 * CXt_NULL block as a CXt_SUB block */
-                cx->blk_sub.old_tmpsfloor = PL_tmps_floor;
-                PL_tmps_floor = PL_tmps_ix;
-            }
+            cx->blk_oldsaveix = old_savestack_ix;
 
-           cx->cx_type |= CXp_MULTICALL;
-           
            start = p1 - max;
            sortsvp(aTHX_ start, max,
                    (is_xsub ? S_sortcv_xsub : hasargs ? S_sortcv_stacked : S_sortcv),
                    sort_flags);
 
+            /* Reset cx, in case the context stack has been reallocated. */
+            cx = &cxstack[cxstack_ix];
+
+           PL_stack_sp = PL_stack_base + cx->blk_oldsp;
+
+            CX_LEAVE_SCOPE(cx);
            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);
+                assert(CxTYPE(cx) == CXt_SUB);
+                POPSUB(cx);
            }
             else
-                /* mimic POPSUB */
-                PL_tmps_floor = cx->blk_sub.old_tmpsfloor;
+                assert(CxTYPE(cx) == CXt_NULL);
+                /* there isn't a POPNULL ! */
 
-           POPBLOCK(cx,PL_curpm);
-           PL_stack_sp = newsp;
+           POPBLOCK(cx);
+            CX_POP(cx);
            POPSTACK;
            CATCH_SET(oldcatch);
        }