Simplify return handling for tied handle OPEN/PRINTF/READ/WRITE.
authorNicholas Clark <nick@ccl4.org>
Mon, 27 Dec 2010 19:11:26 +0000 (19:11 +0000)
committerNicholas Clark <nick@ccl4.org>
Mon, 27 Dec 2010 19:11:26 +0000 (19:11 +0000)
Their code used to explicitly move the return value from its current position
on the stack, to the position that was top of top of the stack just before the
call was made. However, the POPBLOCK() in pp_leavesub will restore the stack
pointer, and passing G_SCALAR to call_method() will force exactly one return
value, so all of this is needless defensiveness.

pp_sys.c

index d54b44e..3f43e49 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -527,8 +527,7 @@ PP(pp_open)
            ENTER_with_name("call_OPEN");
            call_method("OPEN", G_SCALAR);
            LEAVE_with_name("call_OPEN");
-           SPAGAIN;
-           RETURN;
+           return NORMAL;
        }
     }
 
@@ -1506,11 +1505,7 @@ PP(pp_prtf)
            ENTER;
            call_method("PRINTF", G_SCALAR);
            LEAVE;
-           SPAGAIN;
-           MARK = ORIGMARK + 1;
-           *MARK = *SP;
-           SP = MARK;
-           RETURN;
+           return NORMAL;
        }
     }
 
@@ -1603,17 +1598,12 @@ PP(pp_sysread)
     {
        const MAGIC * mg = SvTIED_mg((const SV *)io, PERL_MAGIC_tiedscalar);
        if (mg) {
-           SV *sv;
            PUSHMARK(MARK-1);
            *MARK = SvTIED_obj(MUTABLE_SV(io), mg);
            ENTER;
            call_method("READ", G_SCALAR);
            LEAVE;
-           SPAGAIN;
-           sv = POPs;
-           SP = ORIGMARK;
-           PUSHs(sv);
-           RETURN;
+           return NORMAL;
        }
     }
 
@@ -1851,11 +1841,8 @@ PP(pp_send)
        && gv && (io = GvIO(gv))) {
        MAGIC * const mg = SvTIED_mg((const SV *)io, PERL_MAGIC_tiedscalar);
        if (mg) {
-           SV *sv;
-
            if (MARK == SP - 1) {
-               sv = *SP;
-               mXPUSHi(sv_len(sv));
+               mXPUSHi(sv_len(*SP));
                PUTBACK;
            }
 
@@ -1864,11 +1851,7 @@ PP(pp_send)
            ENTER;
            call_method("WRITE", G_SCALAR);
            LEAVE;
-           SPAGAIN;
-           sv = POPs;
-           SP = ORIGMARK;
-           PUSHs(sv);
-           RETURN;
+           return NORMAL;
        }
     }
     if (!gv)