This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
375ed12a broke Config::IniFiles
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 3 Jun 2014 12:41:34 +0000 (08:41 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Tue, 3 Jun 2014 16:32:43 +0000 (12:32 -0400)
... among other things: https://rt.perl.org/Ticket/Display.html?id=122021

PerlIO::scalar (aka opening scalars for IO) has fileno of -1.

This (and probably other exotic PerlIO objects which have funny fds)
requires special care.

doio.c

diff --git a/doio.c b/doio.c
index 3a09927..cb4d007 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -1392,10 +1392,13 @@ Perl_my_stat_flags(pTHX_ const U32 flags)
         PL_laststype = OP_STAT;
         PL_statgv = gv ? gv : (GV *)io;
         sv_setpvs(PL_statname, "");
         PL_laststype = OP_STAT;
         PL_statgv = gv ? gv : (GV *)io;
         sv_setpvs(PL_statname, "");
-        if(io) {
+        if (io) {
            if (IoIFP(io)) {
                 int fd = PerlIO_fileno(IoIFP(io));
            if (IoIFP(io)) {
                 int fd = PerlIO_fileno(IoIFP(io));
-                if (fd >= 0) {
+                if (fd < 0) {
+                    /* E.g. PerlIO::scalar has no real fd. */
+                    return (PL_laststatval = -1);
+                } else {
                     return (PL_laststatval = PerlLIO_fstat(fd, &PL_statcache));
                 }
             } else if (IoDIRP(io)) {
                     return (PL_laststatval = PerlLIO_fstat(fd, &PL_statcache));
                 }
             } else if (IoDIRP(io)) {