Don’t emit unopened warning for other stat(HANDLE) error
authorFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jan 2012 08:33:15 +0000 (00:33 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jan 2012 08:51:58 +0000 (00:51 -0800)
-r or -T on a GV with no IO or on an IO with no fp (or dirp for -r)
will produce an ‘unopened’ warning.  stat() on a filehandle will warn
about an unopened filehandle not only if there is no fp, but also if
the fstat call fails (with errno containing EBADP, EFAULT or EIO, at
least on Darwin).

I don’t know if there is a way to test this.

(But pp_stat and my_stat_flags are getting closer, so this must be
correct. :-)

pp_sys.c

index 7767764..88e2f4e 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2759,6 +2759,7 @@ PP(pp_stat)
 
     if (PL_op->op_flags & OPf_REF ? (gv = cGVOP_gv, 1)
                                   : !!(sv=POPs, gv = MAYBE_DEREF_GV(sv))) {
+       bool havefp = FALSE;
        if (PL_op->op_type == OP_LSTAT) {
            if (gv != PL_defgv) {
            do_fstat_warning_check:
@@ -2784,9 +2785,11 @@ PP(pp_stat)
                     if (IoIFP(io)) {
                         PL_laststatval = 
                             PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache);   
+                        havefp = TRUE;
                     } else if (IoDIRP(io)) {
                         PL_laststatval =
                             PerlLIO_fstat(my_dirfd(IoDIRP(io)), &PL_statcache);
+                        havefp = TRUE;
                     } else {
                         PL_laststatval = -1;
                     }
@@ -2795,7 +2798,7 @@ PP(pp_stat)
         }
 
        if (PL_laststatval < 0) {
-           report_evil_fh(gv);
+           if (!havefp) report_evil_fh(gv);
            max = 0;
        }
     }