This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use HEKf
[perl5.git] / doio.c
diff --git a/doio.c b/doio.c
index c23780c..06d9bcd 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -126,8 +126,9 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw,
        if (result == EOF && fd > PL_maxsysfd) {
            /* Why is this not Perl_warn*() call ? */
            PerlIO_printf(Perl_error_log,
-                         "Warning: unable to close filehandle %s properly.\n",
-                         GvENAME(gv));
+               "Warning: unable to close filehandle %"HEKf" properly.\n",
+                HEKfARG(GvENAME_HEK(gv))
+           );
        }
        IoOFP(io) = IoIFP(io) = NULL;
     }
@@ -541,14 +542,16 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw,
        if ((IoTYPE(io) == IoTYPE_RDONLY) &&
            (fp == PerlIO_stdout() || fp == PerlIO_stderr())) {
                Perl_warner(aTHX_ packWARN(WARN_IO),
-                           "Filehandle STD%s reopened as %s only for input",
+                           "Filehandle STD%s reopened as %"HEKf
+                           " only for input",
                            ((fp == PerlIO_stdout()) ? "OUT" : "ERR"),
-                           GvENAME(gv));
+                           HEKfARG(GvENAME_HEK(gv)));
        }
        else if ((IoTYPE(io) == IoTYPE_WRONLY) && fp == PerlIO_stdin()) {
                Perl_warner(aTHX_ packWARN(WARN_IO),
-                           "Filehandle STDIN reopened as %s only for output",
-                           GvENAME(gv));
+                   "Filehandle STDIN reopened as %"HEKf" only for output",
+                    HEKfARG(GvENAME_HEK(gv))
+               );
        }
     }
 
@@ -861,10 +864,7 @@ Perl_nextargv(pTHX_ register GV *gv)
 #ifdef HAS_FCHMOD
                (void)fchmod(PL_lastfd,PL_filemode);
 #else
-#  if !(defined(WIN32) && defined(__BORLANDC__))
-               /* Borland runtime creates a readonly file! */
                (void)PerlLIO_chmod(PL_oldname,PL_filemode);
-#  endif
 #endif
                if (fileuid != PL_statbuf.st_uid || filegid != PL_statbuf.st_gid) {
 #ifdef HAS_FCHOWN
@@ -1224,6 +1224,9 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp)
                tmpbuf = bytes_to_utf8((const U8*) tmps, &len);
                tmps = (char *) tmpbuf;
            }
+           else if (ckWARN_d(WARN_UTF8)) {
+               (void) check_utf8_print((const U8*) tmps, len);
+           }
        }
        else if (DO_UTF8(sv)) {
            STRLEN tmplen = len;
@@ -1240,6 +1243,9 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp)
                                 "Wide character in %s",
                                   PL_op ? OP_DESC(PL_op) : "print"
                                );
+                   /* Could also check that isn't one of the things to avoid
+                    * in utf8 by using check_utf8_print(), but not doing so,
+                    * since the stream isn't a UTF8 stream */
            }
        }
        /* To detect whether the process is about to overstep its
@@ -1296,12 +1302,7 @@ Perl_my_stat_flags(pTHX_ const U32 flags)
        const char *s;
        STRLEN len;
        PUTBACK;
-       if (isGV_with_GP(sv)) {
-           gv = MUTABLE_GV(sv);
-           goto do_fstat;
-       }
-       else if (SvROK(sv) && isGV_with_GP(SvRV(sv))) {
-           gv = MUTABLE_GV(SvRV(sv));
+       if ((gv = MAYBE_DEREF_GV_flags(sv,flags))) {
            goto do_fstat;
        }
         else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVIO) {
@@ -1339,24 +1340,22 @@ Perl_my_lstat_flags(pTHX_ const U32 flags)
            return PL_laststatval;
        }
        if (ckWARN(WARN_IO)) {
-           Perl_warner(aTHX_ packWARN(WARN_IO), "Use of -l on filehandle %s",
-                   GvENAME(cGVOP_gv));
-           return (PL_laststatval = -1);
+           Perl_warner(aTHX_ packWARN(WARN_IO),
+                            "Use of -l on filehandle %"HEKf,
+                             HEKfARG(GvENAME_HEK(cGVOP_gv)));
        }
+       return (PL_laststatval = -1);
     }
-    else if (PL_laststype != OP_LSTAT
-           && (PL_op->op_private & OPpFT_STACKED) && ckWARN(WARN_IO))
+    else if (PL_op->op_private & OPpFT_STACKED) {
+      if (PL_laststype != OP_LSTAT)
        Perl_croak(aTHX_ no_prev_lstat);
+      return PL_laststatval;
+    } 
 
     PL_laststype = OP_LSTAT;
     PL_statgv = NULL;
     sv = POPs;
     PUTBACK;
-    if (SvROK(sv) && isGV_with_GP(SvRV(sv)) && ckWARN(WARN_IO)) {
-       Perl_warner(aTHX_ packWARN(WARN_IO), "Use of -l on filehandle %s",
-               GvENAME((const GV *)SvRV(sv)));
-       return (PL_laststatval = -1);
-    }
     file = SvPV_flags_const_nolen(sv, flags);
     sv_setpv(PL_statname,file);
     PL_laststatval = PerlLIO_lstat(file,&PL_statcache);
@@ -1572,6 +1571,7 @@ Perl_apply(pTHX_ I32 type, register SV **mark, register SV **sp)
     register I32 tot = 0;
     const char *const what = PL_op_name[type];
     const char *s;
+    STRLEN len;
     SV ** const oldmark = mark;
 
     PERL_ARGS_ASSERT_APPLY;
@@ -1613,9 +1613,7 @@ Perl_apply(pTHX_ I32 type, register SV **mark, register SV **sp)
            tot = sp - mark;
            while (++mark <= sp) {
                 GV* gv;
-                if (isGV_with_GP(*mark)) {
-                    gv = MUTABLE_GV(*mark);
-               do_fchmod:
+                if ((gv = MAYBE_DEREF_GV(*mark))) {
                    if (GvIO(gv) && IoIFP(GvIOp(gv))) {
 #ifdef HAS_FCHMOD
                        APPLY_TAINT_PROPER();
@@ -1629,12 +1627,8 @@ Perl_apply(pTHX_ I32 type, register SV **mark, register SV **sp)
                        tot--;
                    }
                }
-               else if (SvROK(*mark) && isGV_with_GP(SvRV(*mark))) {
-                   gv = MUTABLE_GV(SvRV(*mark));
-                   goto do_fchmod;
-               }
                else {
-                   const char *name = SvPV_nolen_const(*mark);
+                   const char *name = SvPV_nomg_const_nolen(*mark);
                    APPLY_TAINT_PROPER();
                    if (PerlLIO_chmod(name, val))
                        tot--;
@@ -1653,9 +1647,7 @@ Perl_apply(pTHX_ I32 type, register SV **mark, register SV **sp)
            tot = sp - mark;
            while (++mark <= sp) {
                 GV* gv;
-                if (isGV_with_GP(*mark)) {
-                    gv = MUTABLE_GV(*mark);
-               do_fchown:
+               if ((gv = MAYBE_DEREF_GV(*mark))) {
                    if (GvIO(gv) && IoIFP(GvIOp(gv))) {
 #ifdef HAS_FCHOWN
                        APPLY_TAINT_PROPER();
@@ -1669,12 +1661,8 @@ Perl_apply(pTHX_ I32 type, register SV **mark, register SV **sp)
                        tot--;
                    }
                }
-               else if (SvROK(*mark) && isGV_with_GP(SvRV(*mark))) {
-                   gv = MUTABLE_GV(SvRV(*mark));
-                   goto do_fchown;
-               }
                else {
-                   const char *name = SvPV_nolen_const(*mark);
+                   const char *name = SvPV_nomg_const_nolen(*mark);
                    APPLY_TAINT_PROPER();
                    if (PerlLIO_chown(name, val, val2))
                        tot--;
@@ -1694,12 +1682,14 @@ nothing in the core.
        APPLY_TAINT_PROPER();
        if (mark == sp)
            break;
-       s = SvPVx_nolen_const(*++mark);
+       s = SvPVx_const(*++mark, len);
        if (isALPHA(*s)) {
-           if (*s == 'S' && s[1] == 'I' && s[2] == 'G')
+           if (*s == 'S' && s[1] == 'I' && s[2] == 'G') {
                s += 3;
-           if ((val = whichsig(s)) < 0)
-               Perl_croak(aTHX_ "Unrecognized signal name \"%s\"",s);
+                len -= 3;
+            }
+           if ((val = whichsig_pvn(s, len)) < 0)
+               Perl_croak(aTHX_ "Unrecognized signal name \"%"SVf"\"", SVfARG(*mark));
        }
        else
            val = SvIV(*mark);
@@ -1839,9 +1829,7 @@ nothing in the core.
            tot = sp - mark;
            while (++mark <= sp) {
                 GV* gv;
-                if (isGV_with_GP(*mark)) {
-                    gv = MUTABLE_GV(*mark);
-               do_futimes:
+                if ((gv = MAYBE_DEREF_GV(*mark))) {
                    if (GvIO(gv) && IoIFP(GvIOp(gv))) {
 #ifdef HAS_FUTIMES
                        APPLY_TAINT_PROPER();
@@ -1856,12 +1844,8 @@ nothing in the core.
                        tot--;
                    }
                }
-               else if (SvROK(*mark) && isGV_with_GP(SvRV(*mark))) {
-                   gv = MUTABLE_GV(SvRV(*mark));
-                   goto do_futimes;
-               }
                else {
-                   const char * const name = SvPV_nolen_const(*mark);
+                   const char * const name = SvPV_nomg_const_nolen(*mark);
                    APPLY_TAINT_PROPER();
 #ifdef HAS_FUTIMES
                    if (utimes(name, (struct timeval *)utbufp))
@@ -2298,7 +2282,8 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp)
        /* suppress warning when reading into undef var (tchrist 3/Mar/00) */
        if (! SvOK(mstr))
            sv_setpvs(mstr, "");
-       SvPV_force_nolen(mstr);
+       SvUPGRADE(mstr, SVt_PV);
+       SvPOK_only(mstr);
        mbuf = SvGROW(mstr, (STRLEN)msize+1);
 
        Copy(shm + mpos, mbuf, msize, char);
@@ -2394,6 +2379,7 @@ Perl_vms_start_glob
 #endif
 #endif /* !CSH */
 #endif /* !DOSISH */
+    save_hash(gv_fetchpvs("ENV", 0, SVt_PVHV));
     (void)do_open(PL_last_in_gv, (char*)SvPVX_const(tmpcmd), SvCUR(tmpcmd),
                  FALSE, O_RDONLY, 0, NULL);
     fp = IoIFP(io);