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)
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

index e270819..e3291a5 100644 (file)
@@ -1,7 +1,7 @@
 package PerlIO::encoding;
 
 use strict;
-our $VERSION = '0.16';
+our $VERSION = '0.17';
 our $DEBUG = 0;
 $DEBUG and warn __PACKAGE__, " called by ", join(", ", caller), "\n";
 
index 2d06d82..a0415d0 100644 (file)
@@ -60,7 +60,6 @@ PerlIOEncode_getarg(pTHX_ PerlIO * f, CLONE_PARAMS * param, int flags)
        dSP;
        /* Not 100% sure stack swap is right thing to do during dup ... */
        PUSHSTACKi(PERLSI_MAGIC);
-       SPAGAIN;
        ENTER;
        SAVETMPS;
        PUSHMARK(sp);
@@ -87,8 +86,6 @@ PerlIOEncode_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg, PerlIO_funcs *
     SV *result = Nullsv;
 
     PUSHSTACKi(PERLSI_MAGIC);
-    SPAGAIN;
-
     ENTER;
     SAVETMPS;
 
@@ -239,7 +236,6 @@ PerlIOEncode_fill(pTHX_ PerlIO * f)
        }
     }
     PUSHSTACKi(PERLSI_MAGIC);
-    SPAGAIN;
     ENTER;
     SAVETMPS;
   retry:
@@ -413,7 +409,6 @@ PerlIOEncode_flush(pTHX_ PerlIO * f)
            if (e->inEncodeCall) return 0;
            /* Write case - encode the buffer and write() to layer below */
            PUSHSTACKi(PERLSI_MAGIC);
-           SPAGAIN;
            ENTER;
            SAVETMPS;
            PUSHMARK(sp);
@@ -476,7 +471,6 @@ PerlIOEncode_flush(pTHX_ PerlIO * f)
                   re-encode and unread() to layer below
                 */
                PUSHSTACKi(PERLSI_MAGIC);
-               SPAGAIN;
                ENTER;
                SAVETMPS;
                str = sv_newmortal();
@@ -650,7 +644,6 @@ BOOT:
      * is invoked without prior "use Encode". -- dankogai
      */
     PUSHSTACKi(PERLSI_MAGIC);
-    SPAGAIN;
     if (!get_cvs(OUR_DEFAULT_FB, 0)) {
 #if 0
        /* This would just be an irritant now loading works */
index 95ccb3a..619174a 100644 (file)
@@ -79,7 +79,6 @@ PerlIOVia_method(pTHX_ PerlIO * f, const char *method, CV ** save, int flags,
        SV *arg;
        PUSHSTACKi(PERLSI_MAGIC);
        ENTER;
-       SPAGAIN;
        PUSHMARK(sp);
        XPUSHs(s->obj);
        while ((arg = va_arg(ap, SV *))) {
diff --git a/gv.c b/gv.c
index 041607b..5a4a80e 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -3187,7 +3187,6 @@ Perl_amagic_call(pTHX_ SV *left, SV *right, int method, int flags)
     PL_op = (OP *) &myop;
     if (PERLDB_SUB && PL_curstash != PL_debstash)
        PL_op->op_private |= OPpENTERSUB_DB;
-    PUTBACK;
     Perl_pp_pushmark(aTHX);
 
     EXTEND(SP, notfound + 5);
diff --git a/perl.c b/perl.c
index e245f39..7652052 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -2957,10 +2957,8 @@ Perl_require_pv(pTHX_ const char *pv)
     PERL_ARGS_ASSERT_REQUIRE_PV;
 
     PUSHSTACKi(PERLSI_REQUIRE);
-    PUTBACK;
     sv = Perl_newSVpvf(aTHX_ "require q%c%s%c", 0, pv, 0);
     eval_sv(sv_2mortal(sv), G_DISCARD);
-    SPAGAIN;
     POPSTACK;
 }