Skip to content

Commit

Permalink
make RC-stack-aware: unwrap nullary pp() fns
Browse files Browse the repository at this point in the history
Remove the temporary wrappers from most of the pp() functions which
take zero arguments from the stack (but which may well return
arguments).

Only the simple nullary OPs have been unwrapped in this commit; more
complex ones will have their own commit.
  • Loading branch information
iabyn committed Sep 4, 2023
1 parent e78b109 commit da2d8d0
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 113 deletions.
44 changes: 22 additions & 22 deletions pp.c
Expand Up @@ -34,24 +34,23 @@

/* variations on pp_null */

PP_wrapped(pp_stub, 0, 0)
PP(pp_stub)
{
dSP;
if (GIMME_V == G_SCALAR)
XPUSHs(&PL_sv_undef);
RETURN;
rpp_xpush_1(&PL_sv_undef);
return NORMAL;
}

/* Pushy stuff. */



PP_wrapped(pp_padcv, 0, 0)
PP(pp_padcv)
{
dSP; dTARGET;
dTARGET;
assert(SvTYPE(TARG) == SVt_PVCV);
XPUSHs(TARG);
RETURN;
rpp_xpush_1(TARG);
return NORMAL;
}

PP(pp_introcv)
Expand Down Expand Up @@ -398,23 +397,20 @@ PP_wrapped(pp_prototype, 1, 0)
RETURN;
}

PP_wrapped(pp_anoncode, 0, 0)
PP(pp_anoncode)
{
dSP;
CV *cv = MUTABLE_CV(PAD_SV(PL_op->op_targ));
if (CvCLONE(cv))
cv = MUTABLE_CV(sv_2mortal(MUTABLE_SV(cv_clone(cv))));
EXTEND(SP,1);

SV* sv = MUTABLE_SV(cv);

if (LIKELY(PL_op->op_flags & OPf_REF)) {
sv = refto(sv);
}

PUSHs(sv);

RETURN;
rpp_xpush_1(sv);
return NORMAL;
}

PP_wrapped(pp_srefgen, 1, 0)
Expand Down Expand Up @@ -6893,16 +6889,21 @@ PP(pp_avhvswitch)
](aTHX);
}

PP_wrapped(pp_runcv, 0, 0)
PP(pp_runcv)
{
dSP;
CV *cv;
if (PL_op->op_private & OPpOFFBYONE) {
cv = find_runcv_where(FIND_RUNCV_level_eq, 1, NULL);
}
else cv = find_runcv(NULL);
XPUSHs(CvEVAL(cv) ? &PL_sv_undef : sv_2mortal(newRV((SV *)cv)));
RETURN;

rpp_extend(1);
if (CvEVAL(cv))
rpp_push_1(&PL_sv_undef);
else
rpp_push_1_norc(newRV((SV *)cv));

return NORMAL;
}

static void
Expand Down Expand Up @@ -7317,7 +7318,7 @@ PP_wrapped(pp_argelem,
* into PL_curpad.
*/

PP_wrapped(pp_argdefelem, 0, 0)
PP(pp_argdefelem)
{
OP * const o = PL_op;
AV *defav = GvAV(PL_defgv); /* @_ */
Expand All @@ -7339,9 +7340,8 @@ PP_wrapped(pp_argdefelem, 0, 0)
if ((PL_op->op_private & OPpARG_IF_FALSE) && !SvTRUE(val))
return cLOGOPo->op_other;

dSP;
XPUSHs(val);
RETURN;
rpp_xpush_1(val);
return NORMAL;
}


Expand Down
37 changes: 24 additions & 13 deletions pp_ctl.c
Expand Up @@ -42,31 +42,42 @@

#define dopoptosub(plop) dopoptosub_at(cxstack, (plop))

PP_wrapped(pp_wantarray, 0, 0)
PP(pp_wantarray)
{
dSP;
I32 cxix;
const PERL_CONTEXT *cx;
EXTEND(SP, 1);
SV *sv;

if (PL_op->op_private & OPpOFFBYONE) {
if (!(cx = caller_cx(1,NULL))) RETPUSHUNDEF;
if (!(cx = caller_cx(1,NULL))) {
sv = &PL_sv_undef;
goto ret;
}
}
else {
cxix = dopopto_cursub();
if (cxix < 0)
RETPUSHUNDEF;
if (cxix < 0) {
sv = &PL_sv_undef;
goto ret;
}
cx = &cxstack[cxix];
}

switch (cx->blk_gimme) {
case G_LIST:
RETPUSHYES;
sv = &PL_sv_yes;
break;
case G_SCALAR:
RETPUSHNO;
sv = &PL_sv_no;
break;
default:
RETPUSHUNDEF;
sv = &PL_sv_undef;
break;
}

ret:
rpp_xpush_1(sv);
return NORMAL;
}

PP(pp_regcreset)
Expand Down Expand Up @@ -5226,11 +5237,11 @@ PP(pp_require)
pp_entereval. The hash can be modified by the code
being eval'ed, so we return a copy instead. */

PP_wrapped(pp_hintseval, 0, 0)
PP(pp_hintseval)
{
dSP;
mXPUSHs(MUTABLE_SV(hv_copy_hints_hv(MUTABLE_HV(cSVOP_sv))));
RETURN;
rpp_extend(1);
rpp_push_1_norc(MUTABLE_SV(hv_copy_hints_hv(MUTABLE_HV(cSVOP_sv))));
return NORMAL;
}


Expand Down

0 comments on commit da2d8d0

Please sign in to comment.