Skip to content

Commit

Permalink
builtin: fix TARG handling for refaddr, reftype, ceil, floor, trim
Browse files Browse the repository at this point in the history
pp_stringify is a little special in that it is "hot" so I don't fix
it here.

(cherry picked from commit db19dfa)
  • Loading branch information
tonycoz authored and steve-m-hay committed Oct 26, 2024
1 parent 747e164 commit 2c13bf0
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 112 deletions.
66 changes: 63 additions & 3 deletions builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ XS(XS_builtin_trim)
croak_xs_usage(cv, "arg");
}

dTARGET;
dXSTARG;
SV *source = TOPs;
STRLEN len;
const U8 *start;
Expand Down Expand Up @@ -467,8 +467,18 @@ static OP *ck_builtin_func1(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
return newLISTOPn(opcode, wantflags,
argop,
NULL);
else
return newUNOP(opcode, wantflags, argop);
else {
OP * const op = newUNOP(opcode, wantflags, argop);

/* since these pp funcs can be called from XS, and XS may be called
without a normal ENTERSUB, we need to indicate to them that a targ
has been allocated.
*/
if (op->op_targ)
op->op_private |= OPpENTERSUB_HASTARG;

return op;
}
}

XS(XS_builtin_indexed)
Expand Down Expand Up @@ -522,6 +532,56 @@ XS(XS_builtin_load_module)
XSRETURN(1);
}

/* These pp_ funcs all need to use dXSTARG */

PP(pp_refaddr)
{
dXSTARG;
SV *arg = *PL_stack_sp;

SvGETMAGIC(arg);

if(SvROK(arg))
sv_setuv_mg(TARG, PTR2UV(SvRV(arg)));
else
sv_setsv(TARG, &PL_sv_undef);

rpp_replace_1_1_NN(TARG);
return NORMAL;
}

PP(pp_reftype)
{
dXSTARG;
SV *arg = *PL_stack_sp;

SvGETMAGIC(arg);

if(SvROK(arg))
sv_setpv_mg(TARG, sv_reftype(SvRV(arg), FALSE));
else
sv_setsv(TARG, &PL_sv_undef);

rpp_replace_1_1_NN(TARG);
return NORMAL;
}

PP(pp_ceil)
{
dXSTARG;
TARGn(Perl_ceil(SvNVx(*PL_stack_sp)), 1);
rpp_replace_1_1_NN(TARG);
return NORMAL;
}

PP(pp_floor)
{
dXSTARG;
TARGn(Perl_floor(SvNVx(*PL_stack_sp)), 1);
rpp_replace_1_1_NN(TARG);
return NORMAL;
}

static OP *ck_builtin_funcN(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
{
const struct BuiltinFuncDescriptor *builtin = NUM2PTR(const struct BuiltinFuncDescriptor *, SvUV(ckobj));
Expand Down
4 changes: 2 additions & 2 deletions lib/B/Op_private.pm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 61 additions & 59 deletions opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 0 additions & 48 deletions pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7929,54 +7929,6 @@ PP(pp_blessed)
return NORMAL;
}

PP(pp_refaddr)
{
dTARGET;
SV *arg = *PL_stack_sp;

SvGETMAGIC(arg);

if(SvROK(arg))
sv_setuv_mg(TARG, PTR2UV(SvRV(arg)));
else
sv_setsv(TARG, &PL_sv_undef);

rpp_replace_1_1_NN(TARG);
return NORMAL;
}

PP(pp_reftype)
{
dTARGET;
SV *arg = *PL_stack_sp;

SvGETMAGIC(arg);

if(SvROK(arg))
sv_setpv_mg(TARG, sv_reftype(SvRV(arg), FALSE));
else
sv_setsv(TARG, &PL_sv_undef);

rpp_replace_1_1_NN(TARG);
return NORMAL;
}

PP(pp_ceil)
{
dTARGET;
TARGn(Perl_ceil(SvNVx(*PL_stack_sp)), 1);
rpp_replace_1_1_NN(TARG);
return NORMAL;
}

PP(pp_floor)
{
dTARGET;
TARGn(Perl_floor(SvNVx(*PL_stack_sp)), 1);
rpp_replace_1_1_NN(TARG);
return NORMAL;
}

PP(pp_is_tainted)
{
SV *arg = *PL_stack_sp;
Expand Down
Loading

0 comments on commit 2c13bf0

Please sign in to comment.