This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make -T _ and -B _ always set PL_laststatval
authorFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jan 2012 07:38:57 +0000 (23:38 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jan 2012 07:38:57 +0000 (23:38 -0800)
-T _ and -B _ always do another stat() on the previous file handle or
filename, unless it is a handle that has been closed.

Normally, the internal stat buffer, status, etc., are reset even for
_.  This happens even on a failed fstat().

-T HANDLE and -B HANDLE currently *do* reset the stat status
(PL_laststatval) if there is no IO thingy, so having -T _ and -B _ not
do that makes things needlessly inconsistent.

pp_sys.c
t/op/filetest.t

index 9d5c09c..1a84e10 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -3329,10 +3329,10 @@ PP(pp_fttext)
        }
        else {
            PL_statgv = gv;
        }
        else {
            PL_statgv = gv;
-           PL_laststatval = -1;
            sv_setpvs(PL_statname, "");
            io = GvIO(PL_statgv);
        }
            sv_setpvs(PL_statname, "");
            io = GvIO(PL_statgv);
        }
+       PL_laststatval = -1;
        if (io && IoIFP(io)) {
            if (! PerlIO_has_base(IoIFP(io)))
                DIE(aTHX_ "-T and -B not implemented on filehandles");
        if (io && IoIFP(io)) {
            if (! PerlIO_has_base(IoIFP(io)))
                DIE(aTHX_ "-T and -B not implemented on filehandles");
index cf7a02d..65d9147 100644 (file)
@@ -10,7 +10,7 @@ BEGIN {
 }
 
 use Config;
 }
 
 use Config;
-plan(tests => 42 + 27*14);
+plan(tests => 43 + 27*14);
 
 ok( -d 'op' );
 ok( -f 'TEST' );
 
 ok( -d 'op' );
 ok( -f 'TEST' );
@@ -253,7 +253,7 @@ for my $op (split //, "rwxoRWXOezsfdlpSbctugkTMBAC") {
 my $Perl = which_perl();
 
 SKIP: {
 my $Perl = which_perl();
 
 SKIP: {
-    skip "no -T on filehandles", 5 unless eval { -T STDERR; 1 };
+    skip "no -T on filehandles", 6 unless eval { -T STDERR; 1 };
 
     # Test that -T HANDLE sets the last stat type
     -l "perl.c";   # last stat type is now lstat
 
     # Test that -T HANDLE sets the last stat type
     -l "perl.c";   # last stat type is now lstat
@@ -287,6 +287,12 @@ SKIP: {
     # and after -r $ioref
     -r *$fh{IO};
     ok -T _, '-T _ works after -r $ioref';
     # and after -r $ioref
     -r *$fh{IO};
     ok -T _, '-T _ works after -r $ioref';
+
+    # -T _ on closed filehandle should still reset stat info
+    stat $fh;
+    close $fh;
+    -T _;
+    ok !stat _, '-T _ on closed filehandle resets stat info';
 }
 
 is runperl(prog => '-T _', switches => ['-w'], stderr => 1), "",
 }
 
 is runperl(prog => '-T _', switches => ['-w'], stderr => 1), "",