Make lstat($ioref) and lstat($gv) consistent
authorFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jan 2012 21:12:07 +0000 (13:12 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jan 2012 22:16:26 +0000 (14:16 -0800)
As documented in perldiag, lstat($gv) warns and does an fstat.

lstat($ioref) wasn’t doing what was documented, but after warning
would do the same as stat(_).

pp_sys.c
t/op/stat.t

index 3611f51..d22c578 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2776,13 +2776,14 @@ PP(pp_stat)
 
        havefp = FALSE;
        if (gv != PL_defgv) {
+          do_fstat_have_io:
            PL_laststype = OP_STAT;
-           PL_statgv = gv;
+           PL_statgv = gv ? gv : (GV *)io;
            sv_setpvs(PL_statname, "");
             if(gv) {
                 io = GvIO(gv);
-                do_fstat_have_io:
-                if (io) {
+           }
+            if (io) {
                     if (IoIFP(io)) {
                         PL_laststatval = 
                             PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache);   
@@ -2794,7 +2795,6 @@ PP(pp_stat)
                     } else {
                         PL_laststatval = -1;
                     }
-               }
             }
         }
 
@@ -2808,9 +2808,6 @@ PP(pp_stat)
             io = MUTABLE_IO(SvRV(sv));
             if (PL_op->op_type == OP_LSTAT)
                 goto do_fstat_warning_check;
-           PL_laststype = OP_STAT;
-           PL_statgv = (GV *)io;
-           sv_setpvs(PL_statname, "");
             goto do_fstat_have_io; 
         }
         
index 3e99865..59c7398 100644 (file)
@@ -20,7 +20,7 @@ if(eval {require File::Spec; 1}) {
 }
 
 
-plan tests => 111;
+plan tests => 112;
 
 my $Perl = which_perl();
 
@@ -465,6 +465,13 @@ lstat "test.pl";
 }
 like $@, qr/^The stat preceding lstat\(\) wasn't an lstat at /,
 'stat $ioref resets stat type';
+
+{
+    my @statbuf = stat STDOUT;
+    stat "test.pl";
+    my @lstatbuf = lstat *STDOUT{IO};
+    is "@lstatbuf", "@statbuf", 'lstat $ioref reverts to regular fstat';
+}
   
 SKIP: {
     skip "No lstat", 2 unless $Config{d_lstat};