From: Father Chrysostomos Date: Sat, 14 Jan 2012 21:12:07 +0000 (-0800) Subject: Make lstat($ioref) and lstat($gv) consistent X-Git-Tag: v5.15.7~126 X-Git-Url: https://perl5.git.perl.org/perl5.git/commitdiff_plain/0d5064f119150c3a17481d5c2ece0ae5d24ae9d9 Make lstat($ioref) and lstat($gv) consistent 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(_). --- diff --git a/pp_sys.c b/pp_sys.c index 3611f51..d22c578 100644 --- 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; } diff --git a/t/op/stat.t b/t/op/stat.t index 3e99865..59c7398 100644 --- a/t/op/stat.t +++ b/t/op/stat.t @@ -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};