This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make RC-stack-aware: db/nextstate, unstack
authorDavid Mitchell <davem@iabyn.com>
Sun, 4 Dec 2022 14:44:50 +0000 (14:44 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 16 Aug 2023 16:16:58 +0000 (17:16 +0100)
Update pp_dbstate(), pp_nextstate() and pp_unstack() to handle a
reference-counted stack environment in the presence of PERL_RC_STACK.

But in the presence of PERL_XXX_TMP_NORC, don't actually manipulate
reference counts yet. This will be turned off in a few commits' time.

pp_ctl.c
pp_hot.c

index dad9c5b..7f7c612 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2224,7 +2224,7 @@ PP(pp_dbstate)
 {
     PL_curcop = (COP*)PL_op;
     TAINT_NOT;         /* Each statement is presumed innocent */
-    PL_stack_sp = PL_stack_base + CX_CUR()->blk_oldsp;
+    rpp_popfree_to(PL_stack_base + CX_CUR()->blk_oldsp);
     FREETMPS;
 
     PERL_ASYNC_CHECK();
@@ -2232,7 +2232,6 @@ PP(pp_dbstate)
     if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */
             || PL_DBsingle_iv || PL_DBsignal_iv || PL_DBtrace_iv)
     {
-        dSP;
         PERL_CONTEXT *cx;
         const U8 gimme = G_LIST;
         GV * const gv = PL_DBgv;
@@ -2272,14 +2271,19 @@ PP(pp_dbstate)
             SAVESTACK_POS();
 #endif
             SAVETMPS;
-            PUSHMARK(SP);
-            (void)(*CvXSUB(cv))(aTHX_ cv);
+            PUSHMARK(PL_stack_sp);
+#ifdef PERL_RC_STACK
+            Perl_xs_wrap(aTHX_ CvXSUB(cv), cv);
+#else
+            CvXSUB(cv)(aTHX_ cv);
+#endif
+
             FREETMPS;
             LEAVE;
             return NORMAL;
         }
         else {
-            cx = cx_pushblock(CXt_SUB, gimme, SP, PL_savestack_ix);
+            cx = cx_pushblock(CXt_SUB, gimme, PL_stack_sp, PL_savestack_ix);
             cx_pushsub(cx, cv, PL_op->op_next, 0);
             /* OP_DBSTATE's op_private holds hint bits rather than
              * the lvalue-ish flags seen in OP_ENTERSUB. So cancel
@@ -2296,7 +2300,7 @@ PP(pp_dbstate)
             if (CvDEPTH(cv) >= 2)
                 pad_push(CvPADLIST(cv), CvDEPTH(cv));
             PAD_SET_CUR_NOSAVE(CvPADLIST(cv), CvDEPTH(cv));
-            RETURNOP(CvSTART(cv));
+            return CvSTART(cv);
         }
     }
     else
index d7d8e17..de6a704 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -198,7 +198,7 @@ PP(pp_nextstate)
 {
     PL_curcop = (COP*)PL_op;
     TAINT_NOT;         /* Each statement is presumed innocent */
-    PL_stack_sp = PL_stack_base + CX_CUR()->blk_oldsp;
+    rpp_popfree_to(PL_stack_base + CX_CUR()->blk_oldsp);
     FREETMPS;
     PERL_ASYNC_CHECK();
     return NORMAL;
@@ -490,7 +490,7 @@ PP(pp_unstack)
     PERL_ASYNC_CHECK();
     TAINT_NOT;         /* Each statement is presumed innocent */
     cx  = CX_CUR();
-    PL_stack_sp = PL_stack_base + cx->blk_oldsp;
+    rpp_popfree_to(PL_stack_base + CX_CUR()->blk_oldsp);
     FREETMPS;
     if (!(PL_op->op_flags & OPf_SPECIAL)) {
         assert(CxTYPE(cx) == CXt_BLOCK || CxTYPE_is_LOOP(cx));