develooper Front page | perl.perl5.porters | Postings from September 2012

[perl #24067] IO::Handle::error doesn't report errors

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
September 29, 2012 18:42
Subject:
[perl #24067] IO::Handle::error doesn't report errors
Message ID:
rt-3.6.HEAD-11172-1348969316-1468.24067-15-0@perl.org
On Sat Oct 18 04:58:34 2003, davem wrote:
> On Mon, Sep 29, 2003 at 03:43:41PM -0000, peff-perlbug@peff.net (via
> RT) wrote:
> > -----------------------------------------------------------------
> > The following perl program writes 4096 bytes to a file, checking for
> errors:
> >
> > $ cat foo.pl
> > use IO::File;
> > my $fh = new IO::File($ARGV[0], 'w');
> > $fh->print('a' x 4096) || print "print failed: $!\n";
> > print "errors: " . ($fh->error() ? "yes ($!)" : "no") . "\n";
> >
> > When running it on a regular file, it works as expected:
> > $ perl foo.pl foo.out
> > errors: no
> >
> > However, when an error actually occurs, the print statement returns
> an error
> > but $fh->error does not return true:
> > $ perl foo.pl /dev/full
> > print failed: No space left on device
> > errors: no
> >

Reviewing this older ticket this evening, I could reproduce the OP's
results with Perl 5.12 on Linux/i386:

#########
$ cat 24067.pl
use IO::File;
my $fh = new IO::File($ARGV[0], 'w');
$fh->print('a' x 4096) || print "print failed: $!\n";
print "errors: " . ($fh->error() ? "yes ($!)" : "no") . "\n";

$ /usr/local/bin/perl5.12.0 24067.pl /dev/full
print failed: No space left on device
errors: no
#########

However, on 5.14 and 5.16, I don't get the print failure message, even
though I still get the "errors: no":

#########
$ /usr/local/bin/perl5.14.0 24067.pl /dev/full
errors: no

$ /usr/local/bin/perl5.16.0 24067.pl /dev/full
errors: no
#########

> > IO.xs shows that IO::Handle::error just calls PerlIO_error, which
> typically
> > just calls PerlIOBase_error to check the PERLIO_F_ERROR flag.
> However, if I
> > run gdb on the perl binary, I see that:
> >
> >  - PerlIO_write is called with (in my case) f=0x81a70e4
> >  - PerlIOBuf_flush correctly sets the flag with the same
> f=0x81a70e4, and
> >    sets the PERLIO_F_ERROR flag on f->flags
> >  - PerlIO_error gets called with f=0x81a70e4 (from Perl_do_print),
> and
> >    correctly returns that an error occurred
> >  - PerlIO_error gets called with f=0x81a70e0, whose flags don't have
> an
> >    error; this is *not* for the error message printed to stdout (I
> also saw
> >    that happen, and it has a different address).
> >
> > Whatever the address of the original PerlIO handle is, the final
> call to
> > PerlIO_error always has an address 4 bytes less (the size of a
> pointer on my
> > platform).
> 
> In IO.xs, XS_IO__Handle_error is set up to report errors on the input
> stream only, which is why it's seeing the wrong result.
> That is to say, it effectively calls PerlIO_error(IoIFP(io)) rather
> than
> IoOFP(io).  Anyone have a clue how to handle this, because I dont!
> 
> Dave.
> 

Does anyone know what has changed, for better or worse?

Thank you very much.
Jim Keenan


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=24067

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About