This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove redundant SPAGAIN & PUTBACK after PUSHSTACKi().
authorNicholas Clark <nick@ccl4.org>
Fri, 4 Oct 2013 11:28:58 +0000 (13:28 +0200)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 23 Nov 2013 05:20:37 +0000 (21:20 -0800)
commitea35f80112fbe2dfbe7bc30c9804d106145e5241
treeab80c56e3208406fd9a36945eabc1bd4196c324c
parent865e3ae09bd2dde9953a008963d3c5a0ad14e32d
Remove redundant SPAGAIN & PUTBACK after PUSHSTACKi().

PUSHSTACKi() calls SWITCHSTACK(), which sets PL_stack_sp and sp like this:

    sp = PL_stack_sp = PL_stack_base + AvFILLp(t)

Hence after PUSHSTACKi() both are identical, so use of SPAGAIN or PUTBACK
to assign one to the other is redundant.

The use of SPAGAIN in encoding.xs and via.xs was added with commit
24f59afc531955e5 (April 2002) which added the use of PUSHSTACKi(). It feels
like cargo-cult.

The use of PUTBACK in Perl_amagic_call() predates the introduction of nested
stacks and PUSHSTACKi() in commit e336de0d01f30cc4 (April 1998). It dates from
perl 5.000, but it's not clear that it was ever needed, as the code in
question looked like this, and nothing could have moved the stack between
the dSP and PUTBACK:

    dSP;
    BINOP myop;
    SV* res;

    Zero(&myop, 1, BINOP);
    myop.op_last = (OP *) &myop;
    myop.op_next = Nullop;
    myop.op_flags = OPf_KNOW|OPf_STACKED;

    ENTER;
    SAVESPTR(op);
    op = (OP *) &myop;
    PUTBACK;

The PUTBACK and SPAGAIN in Perl_require_pv() were added by commit
d3acc0f7e5197310 (June 1998) which also added the PUSHSTACKi(). They have
both been redundant since they were added.
ext/PerlIO-encoding/encoding.pm
ext/PerlIO-encoding/encoding.xs
ext/PerlIO-via/via.xs
gv.c
perl.c