This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove the AIX work around code. Instead it should just set it's LOCALTIME_MAX to...
[perl5.git] / pp_sys.c
index 25deca1..74958ac 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1,7 +1,7 @@
 /*    pp_sys.c
  *
- *    Copyright (C) 1995, 1996, 1997, 1998, 1999,
- *    2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others
+ *    Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
+ *    2004, 2005, 2006, 2007 by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -27,6 +27,8 @@
 #include "EXTERN.h"
 #define PERL_IN_PP_SYS_C
 #include "perl.h"
+#include "time64.h"
+#include "time64.c"
 
 #ifdef I_SHADOW
 /* Shadow password support for solaris - pdo@cs.umd.edu
@@ -199,15 +201,6 @@ void endservent(void);
 
 #undef PERL_EFF_ACCESS /* EFFective uid/gid ACCESS */
 
-/* AIX 5.2 and below use mktime for localtime, and defines the edge case
- * for time 0x7fffffff to be valid only in UTC. AIX 5.3 provides localtime64
- * available in the 32bit environment, which could warrant Configure
- * checks in the future.
- */
-#ifdef  _AIX
-#define LOCALTIME_EDGECASE_BROKEN
-#endif
-
 /* F_OK unused: if stat() cannot find it... */
 
 #if !defined(PERL_EFF_ACCESS) && defined(HAS_ACCESS) && defined(EFF_ONLY_OK) && !defined(NO_EFF_ONLY_OK)
@@ -297,22 +290,7 @@ S_emulate_eaccess(pTHX_ const char* path, Mode_t mode)
 
     return res;
 }
-#   define PERL_EFF_ACCESS(p,f) (emulate_eaccess((p), (f)))
-#endif
-
-#if !defined(PERL_EFF_ACCESS)
-/* With it or without it: anyway you get a warning: either that
-   it is unused, or it is declared static and never defined.
- */
-STATIC int
-S_emulate_eaccess(pTHX_ const char* path, Mode_t mode)
-{
-    PERL_UNUSED_ARG(path);
-    PERL_UNUSED_ARG(mode);
-    Perl_croak(aTHX_ "switching effective uid is not implemented");
-    /*NOTREACHED*/
-    return -1;
-}
+#   define PERL_EFF_ACCESS(p,f) (S_emulate_eaccess(aTHX_ (p), (f)))
 #endif
 
 PP(pp_backtick)
@@ -357,7 +335,7 @@ PP(pp_backtick)
                    SvREFCNT_dec(sv);
                    break;
                }
-               XPUSHs(sv_2mortal(sv));
+               mXPUSHs(sv);
                if (SvLEN(sv) - SvCUR(sv) > 20) {
                    SvPV_shrink_to_cur(sv);
                }
@@ -403,7 +381,7 @@ PP(pp_glob)
     PL_last_in_gv = (GV*)*PL_stack_sp--;
 
     SAVESPTR(PL_rs);           /* This is not permanent, either. */
-    PL_rs = sv_2mortal(newSVpvs("\000"));
+    PL_rs = newSVpvs_flags("\000", SVs_TEMP);
 #ifndef DOSISH
 #ifndef CSH
     *SvPVX(PL_rs) = '\n';
@@ -437,6 +415,7 @@ PP(pp_warn)
     else if (SP == MARK) {
        tmpsv = &PL_sv_no;
        EXTEND(SP, 1);
+       SP = MARK + 1;
     }
     else {
        tmpsv = TOPs;
@@ -451,9 +430,9 @@ PP(pp_warn)
        tmps = SvPV_const(tmpsv, len);
     }
     if (!tmps || !len)
-       tmpsv = sv_2mortal(newSVpvs("Warning: something's wrong"));
+       tmpsv = newSVpvs_flags("Warning: something's wrong", SVs_TEMP);
 
-    Perl_warn(aTHX_ "%"SVf, (void*)tmpsv);
+    Perl_warn(aTHX_ "%"SVf, SVfARG(tmpsv));
     RETSETYES;
 }
 
@@ -477,7 +456,7 @@ PP(pp_die)
     }
     else {
        tmpsv = TOPs;
-        tmps = SvROK(tmpsv) ? NULL : SvPV_const(tmpsv, len);
+        tmps = SvROK(tmpsv) ? (const char *)NULL : SvPV_const(tmpsv, len);
     }
     if (!tmps || !len) {
        SV * const error = ERRSV;
@@ -515,9 +494,9 @@ PP(pp_die)
        }
     }
     if (!tmps || !len)
-       tmpsv = sv_2mortal(newSVpvs("Died"));
+       tmpsv = newSVpvs_flags("Died", SVs_TEMP);
 
-    DIE(aTHX_ "%"SVf, (void*)tmpsv);
+    DIE(aTHX_ "%"SVf, SVfARG(tmpsv));
 }
 
 /* I/O. */
@@ -537,10 +516,15 @@ PP(pp_open)
 
     if (!isGV(gv))
        DIE(aTHX_ PL_no_usym, "filehandle");
+
     if ((io = GvIOp(gv))) {
        MAGIC *mg;
        IoFLAGS(GvIOp(gv)) &= ~IOf_UNTAINT;
 
+       if (IoDIRP(io) && ckWARN2(WARN_IO, WARN_DEPRECATED))
+           Perl_warner(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED),
+                   "Opening dirhandle %s also as a file", GvENAME(gv));
+
        mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar);
        if (mg) {
            /* Method's args are same as ours ... */
@@ -616,7 +600,7 @@ PP(pp_pipe_op)
     if (!rgv || !wgv)
        goto badexit;
 
-    if (SvTYPE(rgv) != SVt_PVGV || SvTYPE(wgv) != SVt_PVGV)
+    if (!isGV_with_GP(rgv) || !isGV_with_GP(wgv))
        DIE(aTHX_ PL_no_usym, "filehandle");
     rstio = GvIOn(rgv);
     wstio = GvIOn(wgv);
@@ -707,8 +691,12 @@ PP(pp_umask)
     Mode_t anum;
 
     if (MAXARG < 1) {
-       anum = PerlLIO_umask(0);
-       (void)PerlLIO_umask(anum);
+       anum = PerlLIO_umask(022);
+       /* setting it to 022 between the two calls to umask avoids
+        * to have a window where the umask is set to 0 -- meaning
+        * that another thread could create world-writeable files. */
+       if (anum != 022)
+           (void)PerlLIO_umask(anum);
     }
     else
        anum = PerlLIO_umask(POPi);
@@ -766,22 +754,27 @@ PP(pp_binmode)
     }
 
     PUTBACK;
-    if (PerlIO_binmode(aTHX_ fp,IoTYPE(io),mode_from_discipline(discp),
-                       (discp) ? SvPV_nolen_const(discp) : NULL)) {
-       if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
-            if (!PerlIO_binmode(aTHX_ IoOFP(io),IoTYPE(io),
-                       mode_from_discipline(discp),
-                       (discp) ? SvPV_nolen_const(discp) : NULL)) {
-               SPAGAIN;
-               RETPUSHUNDEF;
-            }
+    {
+       STRLEN len = 0;
+       const char *d = NULL;
+       int mode;
+       if (discp)
+           d = SvPV_const(discp, len);
+       mode = mode_from_discipline(d, len);
+       if (PerlIO_binmode(aTHX_ fp, IoTYPE(io), mode, d)) {
+           if (IoOFP(io) && IoOFP(io) != IoIFP(io)) {
+               if (!PerlIO_binmode(aTHX_ IoOFP(io), IoTYPE(io), mode, d)) {
+                   SPAGAIN;
+                   RETPUSHUNDEF;
+               }
+           }
+           SPAGAIN;
+           RETPUSHYES;
+       }
+       else {
+           SPAGAIN;
+           RETPUSHUNDEF;
        }
-       SPAGAIN;
-       RETPUSHYES;
-    }
-    else {
-       SPAGAIN;
-       RETPUSHUNDEF;
     }
 }
 
@@ -806,26 +799,29 @@ PP(pp_tie)
            methname = "TIEARRAY";
            break;
        case SVt_PVGV:
+           if (isGV_with_GP(varsv)) {
 #ifdef GV_UNIQUE_CHECK
-           if (GvUNIQUE((GV*)varsv)) {
-                Perl_croak(aTHX_ "Attempt to tie unique GV");
-           }
+               if (GvUNIQUE((GV*)varsv)) {
+                   Perl_croak(aTHX_ "Attempt to tie unique GV");
+               }
 #endif
-           methname = "TIEHANDLE";
-           how = PERL_MAGIC_tiedscalar;
-           /* For tied filehandles, we apply tiedscalar magic to the IO
-              slot of the GP rather than the GV itself. AMS 20010812 */
-           if (!GvIOp(varsv))
-               GvIOp(varsv) = newIO();
-           varsv = (SV *)GvIOp(varsv);
-           break;
+               methname = "TIEHANDLE";
+               how = PERL_MAGIC_tiedscalar;
+               /* For tied filehandles, we apply tiedscalar magic to the IO
+                  slot of the GP rather than the GV itself. AMS 20010812 */
+               if (!GvIOp(varsv))
+                   GvIOp(varsv) = newIO();
+               varsv = (SV *)GvIOp(varsv);
+               break;
+           }
+           /* FALL THROUGH */
        default:
            methname = "TIESCALAR";
            how = PERL_MAGIC_tiedscalar;
            break;
     }
     items = SP - MARK++;
-    if (sv_isobject(*MARK)) {
+    if (sv_isobject(*MARK)) { /* Calls GET magic. */
        ENTER;
        PUSHSTACKi(PERLSI_MAGIC);
        PUSHMARK(SP);
@@ -839,10 +835,12 @@ PP(pp_tie)
        /* Not clear why we don't call call_method here too.
         * perhaps to get different error message ?
         */
-       stash = gv_stashsv(*MARK, FALSE);
+       STRLEN len;
+       const char *name = SvPV_nomg_const(*MARK, len);
+       stash = gv_stashpvn(name, len, 0);
        if (!stash || !(gv = gv_fetchmethod(stash, methname))) {
            DIE(aTHX_ "Can't locate object method \"%s\" via package \"%"SVf"\"",
-                methname, (void*)*MARK);
+                methname, SVfARG(SvOK(*MARK) ? *MARK : &PL_sv_no));
        }
        ENTER;
        PUSHSTACKi(PERLSI_MAGIC);
@@ -881,7 +879,7 @@ PP(pp_untie)
     const char how = (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV)
                ? PERL_MAGIC_tied : PERL_MAGIC_tiedscalar;
 
-    if (SvTYPE(sv) == SVt_PVGV && !(sv = (SV *)GvIOp(sv)))
+    if (isGV_with_GP(sv) && !(sv = (SV *)GvIOp(sv)))
        RETPUSHYES;
 
     if ((mg = SvTIED_mg(sv, how))) {
@@ -892,7 +890,7 @@ PP(pp_untie)
            if (gv && isGV(gv) && (cv = GvCV(gv))) {
               PUSHMARK(SP);
               XPUSHs(SvTIED_obj((SV*)gv, mg));
-              XPUSHs(sv_2mortal(newSViv(SvREFCNT(obj)-1)));
+              mXPUSHi(SvREFCNT(obj) - 1);
               PUTBACK;
               ENTER;
               call_sv((SV *)cv, G_VOID);
@@ -919,7 +917,7 @@ PP(pp_tied)
     const char how = (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV)
                ? PERL_MAGIC_tied : PERL_MAGIC_tiedscalar;
 
-    if (SvTYPE(sv) == SVt_PVGV && !(sv = (SV *)GvIOp(sv)))
+    if (isGV_with_GP(sv) && !(sv = (SV *)GvIOp(sv)))
        RETPUSHUNDEF;
 
     if ((mg = SvTIED_mg(sv, how))) {
@@ -940,13 +938,13 @@ PP(pp_dbmopen)
     GV *gv;
 
     HV * const hv = (HV*)POPs;
-    SV * const sv = sv_2mortal(newSVpvs("AnyDBM_File"));
-    stash = gv_stashsv(sv, FALSE);
+    SV * const sv = newSVpvs_flags("AnyDBM_File", SVs_TEMP);
+    stash = gv_stashsv(sv, 0);
     if (!stash || !(gv = gv_fetchmethod(stash, "TIEHASH"))) {
        PUTBACK;
        require_pv("AnyDBM_File.pm");
        SPAGAIN;
-       if (!(gv = gv_fetchmethod(stash, "TIEHASH")))
+       if (!stash || !(gv = gv_fetchmethod(stash, "TIEHASH")))
            DIE(aTHX_ "No dbm on this machine");
     }
 
@@ -957,9 +955,9 @@ PP(pp_dbmopen)
     PUSHs(sv);
     PUSHs(left);
     if (SvIV(right))
-       PUSHs(sv_2mortal(newSVuv(O_RDWR|O_CREAT)));
+       mPUSHu(O_RDWR|O_CREAT);
     else
-       PUSHs(sv_2mortal(newSVuv(O_RDWR)));
+       mPUSHu(O_RDWR);
     PUSHs(right);
     PUTBACK;
     call_sv((SV*)GvCV(gv), G_SCALAR);
@@ -970,7 +968,7 @@ PP(pp_dbmopen)
        PUSHMARK(SP);
        PUSHs(sv);
        PUSHs(left);
-       PUSHs(sv_2mortal(newSVuv(O_RDONLY)));
+       mPUSHu(O_RDONLY);
        PUSHs(right);
        PUTBACK;
        call_sv((SV*)GvCV(gv), G_SCALAR);
@@ -1141,7 +1139,7 @@ PP(pp_sselect)
     if (GIMME == G_ARRAY && tbuf) {
        value = (NV)(timebuf.tv_sec) +
                (NV)(timebuf.tv_usec) / 1000000.0;
-       PUSHs(sv_2mortal(newSVnv(value)));
+       mPUSHn(value);
     }
     RETURN;
 #else
@@ -1178,7 +1176,7 @@ PP(pp_select)
            XPUSHTARG;
        }
        else {
-           XPUSHs(sv_2mortal(newRV((SV*)egv)));
+           mXPUSHs(newRV((SV*)egv));
        }
     }
 
@@ -1244,12 +1242,13 @@ S_doform(pTHX_ CV *cv, GV *gv, OP *retop)
     register PERL_CONTEXT *cx;
     const I32 gimme = GIMME_V;
 
+    PERL_ARGS_ASSERT_DOFORM;
+
     ENTER;
     SAVETMPS;
 
     PUSHBLOCK(cx, CXt_FORMAT, PL_stack_sp);
-    PUSHFORMAT(cx);
-    cx->blk_sub.retop = retop;
+    PUSHFORMAT(cx, retop);
     SAVECOMPPAD();
     PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1);
 
@@ -1265,6 +1264,7 @@ PP(pp_enterwrite)
     register IO *io;
     GV *fgv;
     CV *cv;
+    SV * tmpsv = NULL;
 
     if (MAXARG == 0)
        gv = PL_defoutgv;
@@ -1288,8 +1288,8 @@ PP(pp_enterwrite)
 
     cv = GvFORM(fgv);
     if (!cv) {
-       SV * const tmpsv = sv_newmortal();
        const char *name;
+       tmpsv = sv_newmortal();
        gv_efullname4(tmpsv, fgv, NULL, FALSE);
        name = SvPV_nolen_const(tmpsv);
        if (name && *name)
@@ -1308,7 +1308,7 @@ PP(pp_enterwrite)
 PP(pp_leavewrite)
 {
     dVAR; dSP;
-    GV * const gv = cxstack[cxstack_ix].blk_sub.gv;
+    GV * const gv = cxstack[cxstack_ix].blk_format.gv;
     register IO * const io = GvIOp(gv);
     PerlIO *ofp;
     PerlIO *fp;
@@ -1483,6 +1483,8 @@ PP(pp_prtf)
        goto just_say_no;
     }
     else {
+       if (SvTAINTED(MARK[1]))
+           TAINT_PROPER("printf");
        do_sprintf(sv, SP - MARK, MARK + 1);
        if (!do_print(sv, fp))
            goto just_say_no;
@@ -1617,7 +1619,7 @@ PP(pp_sysread)
        buffer = SvGROW(bufsv, (STRLEN)(length+1));
        /* 'offset' means 'flags' here */
        count = PerlSock_recvfrom(PerlIO_fileno(IoIFP(io)), buffer, length, offset,
-                         (struct sockaddr *)namebuf, &bufsize);
+                                 (struct sockaddr *)namebuf, &bufsize);
        if (count < 0)
            RETPUSHUNDEF;
 #ifdef EPOC
@@ -1825,10 +1827,14 @@ PP(pp_send)
 
     SETERRNO(0,0);
     io = GvIO(gv);
-    if (!io || !IoIFP(io)) {
+    if (!io || !IoIFP(io) || IoTYPE(io) == IoTYPE_RDONLY) {
        retval = -1;
-       if (ckWARN(WARN_CLOSED))
-           report_evil_fh(gv, io, PL_op->op_type);
+       if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) {
+           if (io && IoIFP(io))
+               report_evil_fh(gv, io, OP_phoney_INPUT_ONLY);
+           else
+               report_evil_fh(gv, io, PL_op->op_type);
+       }
        SETERRNO(EBADF,RMS_IFI);
        goto say_undef;
     }
@@ -2009,7 +2015,12 @@ PP(pp_eof)
                    IoLINES(io) = 0;
                    IoFLAGS(io) &= ~IOf_START;
                    do_open(gv, "-", 1, FALSE, O_RDONLY, 0, NULL);
-                   sv_setpvn(GvSV(gv), "-", 1);
+                   if ( GvSV(gv) ) {
+                       sv_setpvn(GvSV(gv), "-", 1);
+                   }
+                   else {
+                       GvSV(gv) = newSVpvn("-", 1);
+                   }
                    SvSETMAGIC(GvSV(gv));
                }
                else if (!nextargv(gv))
@@ -2092,11 +2103,11 @@ PP(pp_sysseek)
            PUSHMARK(SP);
            XPUSHs(SvTIED_obj((SV*)io, mg));
 #if LSEEKSIZE > IVSIZE
-           XPUSHs(sv_2mortal(newSVnv((NV) offset)));
+           mXPUSHn((NV) offset);
 #else
-           XPUSHs(sv_2mortal(newSViv(offset)));
+           mXPUSHi(offset);
 #endif
-           XPUSHs(sv_2mortal(newSViv(whence)));
+           mXPUSHi(whence);
            PUTBACK;
            ENTER;
            call_method("SEEK", G_SCALAR);
@@ -2120,7 +2131,7 @@ PP(pp_sysseek)
                 newSViv(sought)
 #endif
                 : newSVpvn(zero_but_true, ZBTLEN);
-            PUSHs(sv_2mortal(sv));
+            mPUSHs(sv);
         }
     }
     RETURN;
@@ -2180,11 +2191,11 @@ PP(pp_truncate)
            SV * const sv = POPs;
            const char *name;
 
-           if (SvTYPE(sv) == SVt_PVGV) {
+           if (isGV_with_GP(sv)) {
                tmpgv = (GV*)sv;                /* *main::FRED for example */
                goto do_ftruncate_gv;
            }
-           else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVGV) {
+           else if (SvROK(sv) && isGV_with_GP(SvRV(sv))) {
                tmpgv = (GV*) SvRV(sv); /* \*main::FRED for example */
                goto do_ftruncate_gv;
            }
@@ -2557,6 +2568,17 @@ PP(pp_accept)
 
     nstio = GvIOn(ngv);
     fd = PerlSock_accept(PerlIO_fileno(IoIFP(gstio)), (struct sockaddr *) namebuf, &len);
+#if defined(OEMVS)
+    if (len == 0) {
+       /* Some platforms indicate zero length when an AF_UNIX client is
+        * not bound. Simulate a non-zero-length sockaddr structure in
+        * this case. */
+       namebuf[0] = 0;        /* sun_len */
+       namebuf[1] = AF_UNIX;  /* sun_family */
+       len = 2;
+    }
+#endif
+
     if (fd < 0)
        goto badexit;
     if (IoIFP(nstio))
@@ -2769,7 +2791,8 @@ PP(pp_stat)
 {
     dVAR;
     dSP;
-    GV *gv;
+    GV *gv = NULL;
+    IO *io;
     I32 gimme;
     I32 max = 13;
 
@@ -2780,7 +2803,7 @@ PP(pp_stat)
            do_fstat_warning_check:
                if (ckWARN(WARN_IO))
                    Perl_warner(aTHX_ packWARN(WARN_IO),
-                       "lstat() on filehandle %s", GvENAME(gv));
+                       "lstat() on filehandle %s", gv ? GvENAME(gv) : "");
            } else if (PL_laststype != OP_LSTAT)
                Perl_croak(aTHX_ "The stat preceding lstat() wasn't an lstat");
        }
@@ -2791,18 +2814,15 @@ PP(pp_stat)
            PL_statgv = gv;
            sv_setpvn(PL_statname, "", 0);
             if(gv) {
-                IO* const io = GvIO(gv);
+                io = GvIO(gv);
+                do_fstat_have_io:
                 if (io) {
                     if (IoIFP(io)) {
                         PL_laststatval = 
                             PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache);   
                     } else if (IoDIRP(io)) {
-#ifdef HAS_DIRFD
                         PL_laststatval =
-                            PerlLIO_fstat(dirfd(IoDIRP(io)), &PL_statcache);
-#else
-                        DIE(aTHX_ PL_no_func, "dirfd");
-#endif
+                            PerlLIO_fstat(my_dirfd(IoDIRP(io)), &PL_statcache);
                     } else {
                         PL_laststatval = -1;
                     }
@@ -2818,16 +2838,21 @@ PP(pp_stat)
     }
     else {
        SV* const sv = POPs;
-       if (SvTYPE(sv) == SVt_PVGV) {
+       if (isGV_with_GP(sv)) {
            gv = (GV*)sv;
            goto do_fstat;
-       }
-       else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVGV) {
-           gv = (GV*)SvRV(sv);
-           if (PL_op->op_type == OP_LSTAT)
-               goto do_fstat_warning_check;
-           goto do_fstat;
-       }
+       } else if(SvROK(sv) && isGV_with_GP(SvRV(sv))) {
+            gv = (GV*)SvRV(sv);
+            if (PL_op->op_type == OP_LSTAT)
+                goto do_fstat_warning_check;
+            goto do_fstat;
+        } else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVIO) { 
+            io = (IO*)SvRV(sv);
+            if (PL_op->op_type == OP_LSTAT)
+                goto do_fstat_warning_check;
+            goto do_fstat_have_io; 
+        }
+        
        sv_setpv(PL_statname, SvPV_nolen_const(sv));
        PL_statgv = NULL;
        PL_laststype = PL_op->op_type;
@@ -2851,53 +2876,53 @@ PP(pp_stat)
     if (max) {
        EXTEND(SP, max);
        EXTEND_MORTAL(max);
-       PUSHs(sv_2mortal(newSViv(PL_statcache.st_dev)));
-       PUSHs(sv_2mortal(newSViv(PL_statcache.st_ino)));
-       PUSHs(sv_2mortal(newSVuv(PL_statcache.st_mode)));
-       PUSHs(sv_2mortal(newSVuv(PL_statcache.st_nlink)));
+       mPUSHi(PL_statcache.st_dev);
+       mPUSHi(PL_statcache.st_ino);
+       mPUSHu(PL_statcache.st_mode);
+       mPUSHu(PL_statcache.st_nlink);
 #if Uid_t_size > IVSIZE
-       PUSHs(sv_2mortal(newSVnv(PL_statcache.st_uid)));
+       mPUSHn(PL_statcache.st_uid);
 #else
 #   if Uid_t_sign <= 0
-       PUSHs(sv_2mortal(newSViv(PL_statcache.st_uid)));
+       mPUSHi(PL_statcache.st_uid);
 #   else
-       PUSHs(sv_2mortal(newSVuv(PL_statcache.st_uid)));
+       mPUSHu(PL_statcache.st_uid);
 #   endif
 #endif
 #if Gid_t_size > IVSIZE
-       PUSHs(sv_2mortal(newSVnv(PL_statcache.st_gid)));
+       mPUSHn(PL_statcache.st_gid);
 #else
 #   if Gid_t_sign <= 0
-       PUSHs(sv_2mortal(newSViv(PL_statcache.st_gid)));
+       mPUSHi(PL_statcache.st_gid);
 #   else
-       PUSHs(sv_2mortal(newSVuv(PL_statcache.st_gid)));
+       mPUSHu(PL_statcache.st_gid);
 #   endif
 #endif
 #ifdef USE_STAT_RDEV
-       PUSHs(sv_2mortal(newSViv(PL_statcache.st_rdev)));
+       mPUSHi(PL_statcache.st_rdev);
 #else
-       PUSHs(sv_2mortal(newSVpvs("")));
+       PUSHs(newSVpvs_flags("", SVs_TEMP));
 #endif
 #if Off_t_size > IVSIZE
-       PUSHs(sv_2mortal(newSVnv((NV)PL_statcache.st_size)));
+       mPUSHn(PL_statcache.st_size);
 #else
-       PUSHs(sv_2mortal(newSViv(PL_statcache.st_size)));
+       mPUSHi(PL_statcache.st_size);
 #endif
 #ifdef BIG_TIME
-       PUSHs(sv_2mortal(newSVnv(PL_statcache.st_atime)));
-       PUSHs(sv_2mortal(newSVnv(PL_statcache.st_mtime)));
-       PUSHs(sv_2mortal(newSVnv(PL_statcache.st_ctime)));
+       mPUSHn(PL_statcache.st_atime);
+       mPUSHn(PL_statcache.st_mtime);
+       mPUSHn(PL_statcache.st_ctime);
 #else
-       PUSHs(sv_2mortal(newSViv(PL_statcache.st_atime)));
-       PUSHs(sv_2mortal(newSViv(PL_statcache.st_mtime)));
-       PUSHs(sv_2mortal(newSViv(PL_statcache.st_ctime)));
+       mPUSHi(PL_statcache.st_atime);
+       mPUSHi(PL_statcache.st_mtime);
+       mPUSHi(PL_statcache.st_ctime);
 #endif
 #ifdef USE_STAT_BLOCKS
-       PUSHs(sv_2mortal(newSVuv(PL_statcache.st_blksize)));
-       PUSHs(sv_2mortal(newSVuv(PL_statcache.st_blocks)));
+       mPUSHu(PL_statcache.st_blksize);
+       mPUSHu(PL_statcache.st_blocks);
 #else
-       PUSHs(sv_2mortal(newSVpvs("")));
-       PUSHs(sv_2mortal(newSVpvs("")));
+       PUSHs(newSVpvs_flags("", SVs_TEMP));
+       PUSHs(newSVpvs_flags("", SVs_TEMP));
 #endif
     }
     RETURN;
@@ -2977,10 +3002,9 @@ PP(pp_ftrread)
        effective = TRUE;
        break;
 
-
     case OP_FTEEXEC:
 #ifdef PERL_EFF_ACCESS
-       access_mode = W_OK;
+       access_mode = X_OK;
 #else
        use_access = 0;
 #endif
@@ -2991,7 +3015,7 @@ PP(pp_ftrread)
 
     if (use_access) {
 #if defined(HAS_ACCESS) || defined (PERL_EFF_ACCESS)
-       const char *const name = POPpx;
+       const char *name = POPpx;
        if (effective) {
 #  ifdef PERL_EFF_ACCESS
            result = PERL_EFF_ACCESS(name, access_mode);
@@ -3311,7 +3335,7 @@ PP(pp_fttext)
 
 #if defined(DOSISH) || defined(USEMYBINMODE)
     /* ignore trailing ^Z on short files */
-    if (len && len < sizeof(tbuf) && tbuf[len-1] == 26)
+    if (len && len < (I32)sizeof(tbuf) && tbuf[len-1] == 26)
        --len;
 #endif
 
@@ -3373,14 +3397,14 @@ PP(pp_chdir)
        if (PL_op->op_flags & OPf_SPECIAL) {
            gv = gv_fetchsv(sv, 0, SVt_PVIO);
        }
-        else if (SvTYPE(sv) == SVt_PVGV) {
+        else if (isGV_with_GP(sv)) {
            gv = (GV*)sv;
         }
-       else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVGV) {
+       else if (SvROK(sv) && isGV_with_GP(SvRV(sv))) {
             gv = (GV*)SvRV(sv);
         }
         else {
-           tmps = SvPVx_nolen_const(sv);
+           tmps = SvPV_nolen_const(sv);
        }
     }
 
@@ -3411,15 +3435,10 @@ PP(pp_chdir)
 #ifdef HAS_FCHDIR
        IO* const io = GvIO(gv);
        if (io) {
-           if (IoIFP(io)) {
-               PUSHi(fchdir(PerlIO_fileno(IoIFP(io))) >= 0);
-           }
-           else if (IoDIRP(io)) {
-#ifdef HAS_DIRFD
-               PUSHi(fchdir(dirfd(IoDIRP(io))) >= 0);
-#else
-               DIE(aTHX_ PL_no_func, "dirfd");
-#endif
+           if (IoDIRP(io)) {
+               PUSHi(fchdir(my_dirfd(IoDIRP(io))) >= 0);
+           } else if (IoIFP(io)) {
+                PUSHi(fchdir(PerlIO_fileno(IoIFP(io))) >= 0);
            }
            else {
                if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
@@ -3580,15 +3599,19 @@ S_dooneliner(pTHX_ const char *cmd, const char *filename)
     char *s;
     PerlIO *myfp;
     int anum = 1;
+    Size_t size = strlen(cmd) + (strlen(filename) * 2) + 10;
 
-    Newx(cmdline, strlen(cmd) + (strlen(filename) * 2) + 10, char);
-    strcpy(cmdline, cmd);
-    strcat(cmdline, " ");
+    PERL_ARGS_ASSERT_DOONELINER;
+
+    Newx(cmdline, size, char);
+    my_strlcpy(cmdline, cmd, size);
+    my_strlcat(cmdline, " ", size);
     for (s = cmdline + strlen(cmdline); *filename; ) {
        *s++ = '\\';
        *s++ = *filename++;
     }
-    strcpy(s, " 2>&1");
+    if (s - cmdline < size)
+       my_strlcpy(s, " 2>&1", size - (s - cmdline));
     myfp = PerlProc_popen(cmdline, "r");
     Safefree(cmdline);
 
@@ -3737,6 +3760,9 @@ PP(pp_open_dir)
     if (!io)
        goto nope;
 
+    if ((IoIFP(io) || IoOFP(io)) && ckWARN2(WARN_IO, WARN_DEPRECATED))
+       Perl_warner(aTHX_ packWARN2(WARN_IO, WARN_DEPRECATED),
+               "Opening filehandle %s also as a directory", GvENAME(gv));
     if (IoDIRP(io))
        PerlDir_close(IoDIRP(io));
     if (!(IoDIRP(io) = PerlDir_open(dirname)))
@@ -3790,7 +3816,7 @@ PP(pp_readdir)
         if (!(IoFLAGS(io) & IOf_UNTAINT))
             SvTAINTED_on(sv);
 #endif
-        XPUSHs(sv_2mortal(sv));
+        mXPUSHs(sv);
     } while (gimme == G_ARRAY);
 
     if (!dp && gimme != G_ARRAY)
@@ -3976,7 +4002,7 @@ PP(pp_fork)
 
 PP(pp_wait)
 {
-#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL)
+#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) && !defined(__LIBCATAMOUNT__)
     dVAR; dSP; dTARGET;
     Pid_t childpid;
     int argflags;
@@ -4004,7 +4030,7 @@ PP(pp_wait)
 
 PP(pp_waitpid)
 {
-#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL)
+#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) && !defined(__LIBCATAMOUNT__)
     dVAR; dSP; dTARGET;
     const int optype = POPi;
     const Pid_t pid = TOPi;
@@ -4035,6 +4061,11 @@ PP(pp_waitpid)
 PP(pp_system)
 {
     dVAR; dSP; dMARK; dORIGMARK; dTARGET;
+#if defined(__LIBCATAMOUNT__)
+    PL_statusvalue = -1;
+    SP = ORIGMARK;
+    XPUSHi(-1);
+#else
     I32 value;
     int result;
 
@@ -4136,14 +4167,14 @@ PP(pp_system)
     result = 0;
     if (PL_op->op_flags & OPf_STACKED) {
        SV * const really = *++MARK;
-#  if defined(WIN32) || defined(OS2) || defined(__SYMBIAN32__)
+#  if defined(WIN32) || defined(OS2) || defined(__SYMBIAN32__) || defined(__VMS)
        value = (I32)do_aspawn(really, MARK, SP);
 #  else
        value = (I32)do_aspawn(really, (void **)MARK, (void **)SP);
 #  endif
     }
     else if (SP - MARK != 1) {
-#  if defined(WIN32) || defined(OS2) || defined(__SYMBIAN32__)
+#  if defined(WIN32) || defined(OS2) || defined(__SYMBIAN32__) || defined(__VMS)
        value = (I32)do_aspawn(NULL, MARK, SP);
 #  else
        value = (I32)do_aspawn(NULL, (void **)MARK, (void **)SP);
@@ -4158,7 +4189,8 @@ PP(pp_system)
     do_execfree();
     SP = ORIGMARK;
     XPUSHi(result ? value : STATUS_CURRENT);
-#endif /* !FORK or VMS */
+#endif /* !FORK or VMS or OS/2 */
+#endif
     RETURN;
 }
 
@@ -4339,22 +4371,22 @@ PP(pp_tms)
                                                    /* is returned.                   */
 #endif
 
-    PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_utime)/(NV)PL_clocktick)));
+    mPUSHn(((NV)PL_timesbuf.tms_utime)/(NV)PL_clocktick);
     if (GIMME == G_ARRAY) {
-       PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_stime)/(NV)PL_clocktick)));
-       PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_cutime)/(NV)PL_clocktick)));
-       PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_cstime)/(NV)PL_clocktick)));
+       mPUSHn(((NV)PL_timesbuf.tms_stime)/(NV)PL_clocktick);
+       mPUSHn(((NV)PL_timesbuf.tms_cutime)/(NV)PL_clocktick);
+       mPUSHn(((NV)PL_timesbuf.tms_cstime)/(NV)PL_clocktick);
     }
     RETURN;
 #else
 #   ifdef PERL_MICRO
     dSP;
-    PUSHs(sv_2mortal(newSVnv((NV)0.0)));
+    mPUSHn(0.0);
     EXTEND(SP, 4);
     if (GIMME == G_ARRAY) {
-        PUSHs(sv_2mortal(newSVnv((NV)0.0)));
-        PUSHs(sv_2mortal(newSVnv((NV)0.0)));
-        PUSHs(sv_2mortal(newSVnv((NV)0.0)));
+        mPUSHn(0.0);
+        mPUSHn(0.0);
+        mPUSHn(0.0);
     }
     RETURN;
 #   else
@@ -4363,104 +4395,70 @@ PP(pp_tms)
 #endif /* HAS_TIMES */
 }
 
-#ifdef LOCALTIME_EDGECASE_BROKEN
-static struct tm *S_my_localtime (pTHX_ Time_t *tp)
-{
-    auto time_t     T;
-    auto struct tm *P;
-
-    /* No workarounds in the valid range */
-    if (!tp || *tp < 0x7fff573f || *tp >= 0x80000000)
-       return (localtime (tp));
-
-    /* This edge case is to workaround the undefined behaviour, where the
-     * TIMEZONE makes the time go beyond the defined range.
-     * gmtime (0x7fffffff) => 2038-01-19 03:14:07
-     * If there is a negative offset in TZ, like MET-1METDST, some broken
-     * implementations of localtime () (like AIX 5.2) barf with bogus
-     * return values:
-     * 0x7fffffff gmtime               2038-01-19 03:14:07
-     * 0x7fffffff localtime            1901-12-13 21:45:51
-     * 0x7fffffff mylocaltime          2038-01-19 04:14:07
-     * 0x3c19137f gmtime               2001-12-13 20:45:51
-     * 0x3c19137f localtime            2001-12-13 21:45:51
-     * 0x3c19137f mylocaltime          2001-12-13 21:45:51
-     * Given that legal timezones are typically between GMT-12 and GMT+12
-     * we turn back the clock 23 hours before calling the localtime
-     * function, and add those to the return value. This will never cause
-     * day wrapping problems, since the edge case is Tue Jan *19*
-     */
-    T = *tp - 82800; /* 23 hour. allows up to GMT-23 */
-    P = localtime (&T);
-    P->tm_hour += 23;
-    if (P->tm_hour >= 24) {
-       P->tm_hour -= 24;
-       P->tm_mday++;   /* 18  -> 19  */
-       P->tm_wday++;   /* Mon -> Tue */
-       P->tm_yday++;   /* 18  -> 19  */
-    }
-    return (P);
-} /* S_my_localtime */
-#endif
-
 PP(pp_gmtime)
 {
     dVAR;
     dSP;
-    Time_t when;
-    const struct tm *tmbuf;
+    Time64_T when;
+    struct TM tmbuf;
+    struct TM *err;
     static const char * const dayname[] =
        {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
     static const char * const monname[] =
        {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
 
-    if (MAXARG < 1)
-       (void)time(&when);
+    if (MAXARG < 1) {
+       time_t now;
+       (void)time(&now);
+       when = (Time64_T)now;
+    }
     else
-#ifdef BIG_TIME
-       when = (Time_t)SvNVx(POPs);
-#else
-       when = (Time_t)SvIVx(POPs);
-#endif
+       when = (Time64_T)SvNVx(POPs);
 
     if (PL_op->op_type == OP_LOCALTIME)
-#ifdef LOCALTIME_EDGECASE_BROKEN
-       tmbuf = S_my_localtime(aTHX_ &when);
-#else
-       tmbuf = localtime(&when);
-#endif
+        err = localtime64_r(&when, &tmbuf);
     else
-       tmbuf = gmtime(&when);
+       err = gmtime64_r(&when, &tmbuf);
 
-    if (GIMME != G_ARRAY) {
+    if( err == NULL ) {
+       char *opname = PL_op->op_type == OP_LOCALTIME ? "localtime" : "gmtime";
+       Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
+                   "%s under/overflowed the year", opname);
+    }
+
+    if (GIMME != G_ARRAY) {    /* scalar context */
        SV *tsv;
         EXTEND(SP, 1);
         EXTEND_MORTAL(1);
-       if (!tmbuf)
+       if (err == NULL)
            RETPUSHUNDEF;
-       tsv = Perl_newSVpvf(aTHX_ "%s %s %2d %02d:%02d:%02d %d",
-                           dayname[tmbuf->tm_wday],
-                           monname[tmbuf->tm_mon],
-                           tmbuf->tm_mday,
-                           tmbuf->tm_hour,
-                           tmbuf->tm_min,
-                           tmbuf->tm_sec,
-                           tmbuf->tm_year + 1900);
-       PUSHs(sv_2mortal(tsv));
-    }
-    else if (tmbuf) {
+
+       tsv = Perl_newSVpvf(aTHX_ "%s %s %2d %02d:%02d:%02d %lld",
+                           dayname[tmbuf.tm_wday],
+                           monname[tmbuf.tm_mon],
+                           tmbuf.tm_mday,
+                           tmbuf.tm_hour,
+                           tmbuf.tm_min,
+                           tmbuf.tm_sec,
+                           tmbuf.tm_year + 1900);
+       mPUSHs(tsv);
+    }
+    else {                     /* list context */
+       if ( err == NULL )
+           RETURN;
+
         EXTEND(SP, 9);
         EXTEND_MORTAL(9);
-        PUSHs(sv_2mortal(newSViv(tmbuf->tm_sec)));
-       PUSHs(sv_2mortal(newSViv(tmbuf->tm_min)));
-       PUSHs(sv_2mortal(newSViv(tmbuf->tm_hour)));
-       PUSHs(sv_2mortal(newSViv(tmbuf->tm_mday)));
-       PUSHs(sv_2mortal(newSViv(tmbuf->tm_mon)));
-       PUSHs(sv_2mortal(newSViv(tmbuf->tm_year)));
-       PUSHs(sv_2mortal(newSViv(tmbuf->tm_wday)));
-       PUSHs(sv_2mortal(newSViv(tmbuf->tm_yday)));
-       PUSHs(sv_2mortal(newSViv(tmbuf->tm_isdst)));
+        mPUSHi(tmbuf.tm_sec);
+       mPUSHi(tmbuf.tm_min);
+       mPUSHi(tmbuf.tm_hour);
+       mPUSHi(tmbuf.tm_mday);
+       mPUSHi(tmbuf.tm_mon);
+       mPUSHi(tmbuf.tm_year);
+       mPUSHi(tmbuf.tm_wday);
+       mPUSHi(tmbuf.tm_yday);
+       mPUSHi(tmbuf.tm_isdst);
     }
     RETURN;
 }
@@ -4578,8 +4576,10 @@ S_space_join_names_mortal(pTHX_ char *const *array)
 {
     SV *target;
 
+    PERL_ARGS_ASSERT_SPACE_JOIN_NAMES_MORTAL;
+
     if (array && *array) {
-       target = sv_2mortal(newSVpvs(""));
+       target = newSVpvs_flags("", SVs_TEMP);
        while (1) {
            sv_catpv(target, *array);
            if (!*++array)
@@ -4623,7 +4623,7 @@ PP(pp_ghostent)
        const int addrtype = POPi;
        SV * const addrsv = POPs;
        STRLEN addrlen;
-       Netdb_host_t addr = (Netdb_host_t) SvPVbyte(addrsv, addrlen);
+       const char *addr = (char *)SvPVbyte(addrsv, addrlen);
 
        hent = PerlSock_gethostbyaddr(addr, (Netdb_hlen_t) addrlen, addrtype);
 #else
@@ -4662,18 +4662,18 @@ PP(pp_ghostent)
     }
 
     if (hent) {
-       PUSHs(sv_2mortal(newSVpv((char*)hent->h_name, 0)));
+       mPUSHs(newSVpv((char*)hent->h_name, 0));
        PUSHs(space_join_names_mortal(hent->h_aliases));
-       PUSHs(sv_2mortal(newSViv((IV)hent->h_addrtype)));
+       mPUSHi(hent->h_addrtype);
        len = hent->h_length;
-       PUSHs(sv_2mortal(newSViv((IV)len)));
+       mPUSHi(len);
 #ifdef h_addr
        for (elem = hent->h_addr_list; elem && *elem; elem++) {
-           XPUSHs(sv_2mortal(newSVpvn(*elem, len)));
+           mXPUSHp(*elem, len);
        }
 #else
        if (hent->h_addr)
-           PUSHs(newSVpvn(hent->h_addr, len));
+           mPUSHp(hent->h_addr, len);
        else
            PUSHs(sv_mortalcopy(&PL_sv_no));
 #endif /* h_addr */
@@ -4745,10 +4745,10 @@ PP(pp_gnetent)
     }
 
     if (nent) {
-       PUSHs(sv_2mortal(newSVpv(nent->n_name, 0)));
+       mPUSHs(newSVpv(nent->n_name, 0));
        PUSHs(space_join_names_mortal(nent->n_aliases));
-       PUSHs(sv_2mortal(newSViv((IV)nent->n_addrtype)));
-       PUSHs(sv_2mortal(newSViv((IV)nent->n_net)));
+       mPUSHi(nent->n_addrtype);
+       mPUSHi(nent->n_net);
     }
 
     RETURN;
@@ -4806,9 +4806,9 @@ PP(pp_gprotoent)
     }
 
     if (pent) {
-       PUSHs(sv_2mortal(newSVpv(pent->p_name, 0)));
+       mPUSHs(newSVpv(pent->p_name, 0));
        PUSHs(space_join_names_mortal(pent->p_aliases));
-       PUSHs(sv_2mortal(newSViv((IV)pent->p_proto)));
+       mPUSHi(pent->p_proto);
     }
 
     RETURN;
@@ -4876,14 +4876,14 @@ PP(pp_gservent)
     }
 
     if (sent) {
-       PUSHs(sv_2mortal(newSVpv(sent->s_name, 0)));
+       mPUSHs(newSVpv(sent->s_name, 0));
        PUSHs(space_join_names_mortal(sent->s_aliases));
 #ifdef HAS_NTOHS
-       PUSHs(sv_2mortal(newSViv((IV)PerlSock_ntohs(sent->s_port))));
+       mPUSHi(PerlSock_ntohs(sent->s_port));
 #else
-       PUSHs(sv_2mortal(newSViv((IV)(sent->s_port))));
+       mPUSHi(sent->s_port);
 #endif
-       PUSHs(sv_2mortal(newSVpv(sent->s_proto, 0)));
+       mPUSHs(newSVpv(sent->s_proto, 0));
     }
 
     RETURN;
@@ -4907,7 +4907,7 @@ PP(pp_snetent)
 {
 #ifdef HAS_SETNETENT
     dVAR; dSP;
-    PerlSock_setnetent(TOPi);
+    (void)PerlSock_setnetent(TOPi);
     RETSETYES;
 #else
     DIE(aTHX_ PL_no_sock_func, "setnetent");
@@ -4918,7 +4918,7 @@ PP(pp_sprotoent)
 {
 #ifdef HAS_SETPROTOENT
     dVAR; dSP;
-    PerlSock_setprotoent(TOPi);
+    (void)PerlSock_setprotoent(TOPi);
     RETSETYES;
 #else
     DIE(aTHX_ PL_no_sock_func, "setprotoent");
@@ -4929,7 +4929,7 @@ PP(pp_sservent)
 {
 #ifdef HAS_SETSERVENT
     dVAR; dSP;
-    PerlSock_setservent(TOPi);
+    (void)PerlSock_setservent(TOPi);
     RETSETYES;
 #else
     DIE(aTHX_ PL_no_sock_func, "setservent");
@@ -5099,9 +5099,10 @@ PP(pp_gpwent)
     }
 
     if (pwent) {
-       PUSHs(sv_2mortal(newSVpv(pwent->pw_name, 0)));
+       mPUSHs(newSVpv(pwent->pw_name, 0));
 
-       PUSHs(sv = sv_2mortal(newSViv(0)));
+       sv = newSViv(0);
+       mPUSHs(sv);
        /* If we have getspnam(), we try to dig up the shadow
         * password.  If we are underprivileged, the shadow
         * interface will set the errno to EACCES or similar,
@@ -5145,15 +5146,15 @@ PP(pp_gpwent)
 #   endif
 
 #   if Uid_t_sign <= 0
-       PUSHs(sv_2mortal(newSViv((IV)pwent->pw_uid)));
+       mPUSHi(pwent->pw_uid);
 #   else
-       PUSHs(sv_2mortal(newSVuv((UV)pwent->pw_uid)));
+       mPUSHu(pwent->pw_uid);
 #   endif
 
 #   if Uid_t_sign <= 0
-       PUSHs(sv_2mortal(newSViv((IV)pwent->pw_gid)));
+       mPUSHi(pwent->pw_gid);
 #   else
-       PUSHs(sv_2mortal(newSVuv((UV)pwent->pw_gid)));
+       mPUSHu(pwent->pw_gid);
 #   endif
        /* pw_change, pw_quota, and pw_age are mutually exclusive--
         * because of the poor interface of the Perl getpw*(),
@@ -5161,13 +5162,13 @@ PP(pp_gpwent)
         * A better interface would have been to return a hash,
         * but we are accursed by our history, alas. --jhi.  */
 #   ifdef PWCHANGE
-       PUSHs(sv_2mortal(newSViv((IV)pwent->pw_change)));
+       mPUSHi(pwent->pw_change);
 #   else
 #       ifdef PWQUOTA
-       PUSHs(sv_2mortal(newSViv((IV)pwent->pw_quota)));
+       mPUSHi(pwent->pw_quota);
 #       else
 #           ifdef PWAGE
-       PUSHs(sv_2mortal(newSVpv(pwent->pw_age, 0)));
+       mPUSHs(newSVpv(pwent->pw_age, 0));
 #          else
        /* I think that you can never get this compiled, but just in case.  */
        PUSHs(sv_mortalcopy(&PL_sv_no));
@@ -5178,10 +5179,10 @@ PP(pp_gpwent)
        /* pw_class and pw_comment are mutually exclusive--.
         * see the above note for pw_change, pw_quota, and pw_age. */
 #   ifdef PWCLASS
-       PUSHs(sv_2mortal(newSVpv(pwent->pw_class, 0)));
+       mPUSHs(newSVpv(pwent->pw_class, 0));
 #   else
 #       ifdef PWCOMMENT
-       PUSHs(sv_2mortal(newSVpv(pwent->pw_comment, 0)));
+       mPUSHs(newSVpv(pwent->pw_comment, 0));
 #      else
        /* I think that you can never get this compiled, but just in case.  */
        PUSHs(sv_mortalcopy(&PL_sv_no));
@@ -5191,14 +5192,14 @@ PP(pp_gpwent)
 #   ifdef PWGECOS
        PUSHs(sv = sv_2mortal(newSVpv(pwent->pw_gecos, 0)));
 #   else
-       PUSHs(sv_mortalcopy(&PL_sv_no));
+       PUSHs(sv = sv_mortalcopy(&PL_sv_no));
 #   endif
 #   ifndef INCOMPLETE_TAINTS
        /* pw_gecos is tainted because user himself can diddle with it. */
        SvTAINTED_on(sv);
 #   endif
 
-       PUSHs(sv_2mortal(newSVpv(pwent->pw_dir, 0)));
+       mPUSHs(newSVpv(pwent->pw_dir, 0));
 
        PUSHs(sv = sv_2mortal(newSVpv(pwent->pw_shell, 0)));
 #   ifndef INCOMPLETE_TAINTS
@@ -5207,7 +5208,7 @@ PP(pp_gpwent)
 #   endif
 
 #   ifdef PWEXPIRE
-       PUSHs(sv_2mortal(newSViv((IV)pwent->pw_expire)));
+       mPUSHi(pwent->pw_expire);
 #   endif
     }
     RETURN;
@@ -5275,15 +5276,15 @@ PP(pp_ggrent)
     }
 
     if (grent) {
-       PUSHs(sv_2mortal(newSVpv(grent->gr_name, 0)));
+       mPUSHs(newSVpv(grent->gr_name, 0));
 
 #ifdef GRPASSWD
-       PUSHs(sv_2mortal(newSVpv(grent->gr_passwd, 0)));
+       mPUSHs(newSVpv(grent->gr_passwd, 0));
 #else
        PUSHs(sv_mortalcopy(&PL_sv_no));
 #endif
 
-       PUSHs(sv_2mortal(newSViv((IV)grent->gr_gid)));
+       mPUSHi(grent->gr_gid);
 
 #if !(defined(_CRAYMPP) && defined(USE_REENTRANT_API))
        /* In UNICOS/mk (_CRAYMPP) the multithreading