-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IO::Handle::error doesn't report errors #6799
Comments
From peff-perlbug@peff.netThis is a bug report for perl from peff-perlbug@peff.net, The following perl program writes 4096 bytes to a file, checking for errors: $ cat foo.pl When running it on a regular file, it works as expected: However, when an error actually occurs, the print statement returns an error IO.xs shows that IO::Handle::error just calls PerlIO_error, which typically - PerlIO_write is called with (in my case) f=0x81a70e4 Whatever the address of the original PerlIO handle is, the final call to I haven't been able to follow it past here since I'm unclear on exactly where Flags: Site configuration information for perl v5.8.0: Configured by Debian Project at Thu Sep 11 20:57:21 EST 2003. Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration: Locally applied patches: @INC for perl v5.8.0: Environment for perl v5.8.0: |
From @iabynOn Mon, Sep 29, 2003 at 03:43:41PM -0000, peff-perlbug@peff.net (via RT) wrote:
In IO.xs, XS_IO__Handle_error is set up to report errors on the input Dave. -- |
From @jkeenanOn Sat Oct 18 04:58:34 2003, davem wrote:
Reviewing this older ticket this evening, I could reproduce the OP's ######### $ /usr/local/bin/perl5.12.0 24067.pl /dev/full However, on 5.14 and 5.16, I don't get the print failure message, even ######### $ /usr/local/bin/perl5.16.0 24067.pl /dev/full
Does anyone know what has changed, for better or worse? Thank you very much. |
From @arcJames E Keenan via RT <perlbug-followup@perl.org> wrote:
I can reproduce the OP's results under 5.16 by increasing the constant commit b83080d Increase PERLIOBUF_DEFAULT_BUFSIZ to larger of 8192 and BUFSIZ. The previous default size of a PerlIO buffer (4096 bytes) was The only situation without a noticeable performance benefit so BUFSIZ will be chosen in the unlikely event that it's larger If the new size causes problems, or to try an even bigger size, ./Configure -Accflags=-DPERLIOBUF_DEFAULT_BUFSIZ=N where N is the desired size in bytes; it should probably be a That is, when the amount of data written is less than the buffer size, But it does look like a bug to me that $fh->error returns false after -- |
From @peffOn Sun, Sep 30, 2012 at 06:14:05AM -0700, Aaron Crane via RT wrote:
I think my original test was flaky; it should flush explicitly rather use IO::File;
Right, that's the main thing I was trying to report with the test. -Peff |
From @jkeenanOn Sat Oct 18 04:58:34 2003, davem wrote:
This is the source code you're referring to -- correct? dist/IO/IO.xs 345 int |
Perl's I/O objects (that is the IO SV , not PerlIO) can have both an input (PerlIO) file handle and an output file handle. For files that output handle is the same as the input handle, and if you try the error method on a file:
For a character device (like /dev/full) or a socket, perl creates a second PerlIO object on the same fd to use as the output handle, and that causes the behaviour this ticket documents.
The separate handle allows sockets and character devices to have separate input and output buffers, but it does make this method less useful. |
@tonycoz Yeah, that makes sense. Since the fact that one It's possible that some existing callers using sockets could be relying on ignoring output errors, but it seems unlikely (and I think it could be argued they're in the wrong). |
I'm working on such a PR now, I also want to check clearerr() works here. |
For character devices and sockets perl uses separate PerlIO objects for input and output so they can be buffered separately. The IO::Handle::error() method only checked the input stream, so if a write error occurs error() would still returned false. Change this so both the input and output streams are checked. fixes Perl#6799
Similarly to GH Perl#6799 clearerr() only cleared the error status of the input stream, so clear both.
Similarly to GH #6799 clearerr() only cleared the error status of the input stream, so clear both.
89341f8 fix for GH Perl#6799 introduced a regression when calling error() on an IO::Handle object that was opened for reading a regular file: $ perl -e 'open my $f, q{<}, q{/etc/hosts} or die; print qq{error\n} if $f->error' error In case of a regular file opened for reading, IoOFP() returns NULL and PerlIO_error(NULL) reports -1. Compare to the case of a file opened for writing when both IoIFP() and IoOFP() return non-NULL, equaled pointer. This patch fixes handling the case of the NULL output stream. GH Perl#18019
89341f8 fix for GH #6799 introduced a regression when calling error() on an IO::Handle object that was opened for reading a regular file: $ perl -e 'open my $f, q{<}, q{/etc/hosts} or die; print qq{error\n} if $f->error' error In case of a regular file opened for reading, IoOFP() returns NULL and PerlIO_error(NULL) reports -1. Compare to the case of a file opened for writing when both IoIFP() and IoOFP() return non-NULL, equaled pointer. This patch fixes handling the case of the NULL output stream. GH #18019
Migrated from rt.perl.org#24067 (status was 'open')
Searchable as RT24067$
The text was updated successfully, but these errors were encountered: