From 00fc1d567b0fefdc90e659aae2c44c33cbeed7b6 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Thu, 19 Jan 2023 14:06:10 +0000 Subject: [PATCH] make RC-stack-aware: eval_sv() Similar to the previous commit which fixed up call_sv() and similar, the commit updates eval_sv() to handle a reference-counted stack environment. Note that these functions are slightly unusual in that they can be called from either a reference-counted or non-RC stack environment, so must be able to handle either case. This is done mostly by relying on CALLRUNOPS() to fix things up, but for anything pushed/pulled around that, by checking rpp_stack_is_rc(): which currently always returns false, but once ref-counting is enabled in a few commits' time, may start returning true. --- perl.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/perl.c b/perl.c index 5d2c1cc239..3bd05b4f83 100644 --- a/perl.c +++ b/perl.c @@ -3258,13 +3258,13 @@ Perl_eval_sv(pTHX_ SV *sv, I32 flags) myop.op_ppaddr = PL_ppaddr[OP_ENTEREVAL]; myop.op_type = OP_ENTEREVAL; - { - dSP; - oldmark = SP - PL_stack_base; - EXTEND(SP, 1); - PUSHs(sv); - PUTBACK; - } + oldmark = PL_stack_sp - PL_stack_base; + rpp_extend(1); + *++PL_stack_sp = sv; +#if defined PERL_RC_STACK && !defined PERL_XXX_TMP_NORC + if (rpp_stack_is_rc()) + SvREFCNT_inc_simple_void_NN(sv); +#endif if (!(flags & G_NOARGS)) myop.op_flags = OPf_STACKED; @@ -3345,7 +3345,12 @@ Perl_eval_sv(pTHX_ SV *sv, I32 flags) JMPENV_POP; if (flags & G_DISCARD) { - PL_stack_sp = PL_stack_base + oldmark; +#if defined PERL_RC_STACK && !defined PERL_XXX_TMP_NORC + if (rpp_stack_is_rc()) + rpp_popfree_to(PL_stack_base + oldmark); + else +#endif + PL_stack_sp = PL_stack_base + oldmark; retval = 0; FREETMPS; LEAVE;