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
>
> 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.
--
"Strange women lying in ponds distributing swords is no basis for a system
of government. Supreme executive power derives from a mandate from the
masses, not from some farcical aquatic ceremony."
Dennis - Monty Python and the Holy Grail.
Thread Previous
|
Thread Next