|
|
7e86df |
From fc5f3468dcbee38eb202cfd552a5b8dbff990c7b Mon Sep 17 00:00:00 2001
|
|
|
7e86df |
From: Tony Cook <tony@develop-help.com>
|
|
|
7e86df |
Date: Tue, 12 May 2020 10:59:08 +1000
|
|
|
7e86df |
Subject: [PATCH 2/2] IO::Handle: clear the error on both input and output
|
|
|
7e86df |
streams
|
|
|
7e86df |
MIME-Version: 1.0
|
|
|
7e86df |
Content-Type: text/plain; charset=UTF-8
|
|
|
7e86df |
Content-Transfer-Encoding: 8bit
|
|
|
7e86df |
|
|
|
7e86df |
Similarly to GH #6799 clearerr() only cleared the error status
|
|
|
7e86df |
of the input stream, so clear both.
|
|
|
7e86df |
|
|
|
7e86df |
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
7e86df |
---
|
|
|
7e86df |
dist/IO/IO.xs | 14 +++++++++++---
|
|
|
7e86df |
dist/IO/t/io_xs.t | 8 +++++---
|
|
|
7e86df |
2 files changed, 16 insertions(+), 6 deletions(-)
|
|
|
7e86df |
|
|
|
7e86df |
diff --git a/dist/IO/IO.xs b/dist/IO/IO.xs
|
|
|
7e86df |
index 99d523d2c1..9158106416 100644
|
|
|
7e86df |
--- a/dist/IO/IO.xs
|
|
|
7e86df |
+++ b/dist/IO/IO.xs
|
|
|
7e86df |
@@ -410,13 +410,21 @@ ferror(handle)
|
|
|
7e86df |
|
|
|
7e86df |
int
|
|
|
7e86df |
clearerr(handle)
|
|
|
7e86df |
- InputStream handle
|
|
|
7e86df |
+ SV * handle
|
|
|
7e86df |
+ PREINIT:
|
|
|
7e86df |
+ IO *io = sv_2io(handle);
|
|
|
7e86df |
+ InputStream in = IoIFP(io);
|
|
|
7e86df |
+ OutputStream out = IoOFP(io);
|
|
|
7e86df |
CODE:
|
|
|
7e86df |
if (handle) {
|
|
|
7e86df |
#ifdef PerlIO
|
|
|
7e86df |
- PerlIO_clearerr(handle);
|
|
|
7e86df |
+ PerlIO_clearerr(in);
|
|
|
7e86df |
+ if (in != out)
|
|
|
7e86df |
+ PerlIO_clearerr(out);
|
|
|
7e86df |
#else
|
|
|
7e86df |
- clearerr(handle);
|
|
|
7e86df |
+ clearerr(in);
|
|
|
7e86df |
+ if (in != out)
|
|
|
7e86df |
+ clearerr(out);
|
|
|
7e86df |
#endif
|
|
|
7e86df |
RETVAL = 0;
|
|
|
7e86df |
}
|
|
|
7e86df |
diff --git a/dist/IO/t/io_xs.t b/dist/IO/t/io_xs.t
|
|
|
7e86df |
index f890e92558..a8833b0651 100644
|
|
|
7e86df |
--- a/dist/IO/t/io_xs.t
|
|
|
7e86df |
+++ b/dist/IO/t/io_xs.t
|
|
|
7e86df |
@@ -11,7 +11,7 @@ BEGIN {
|
|
|
7e86df |
}
|
|
|
7e86df |
}
|
|
|
7e86df |
|
|
|
7e86df |
-use Test::More tests => 7;
|
|
|
7e86df |
+use Test::More tests => 8;
|
|
|
7e86df |
use IO::File;
|
|
|
7e86df |
use IO::Seekable;
|
|
|
7e86df |
|
|
|
7e86df |
@@ -58,12 +58,14 @@ SKIP: {
|
|
|
7e86df |
# This isn't really a Linux/BSD specific test, but /dev/full is (I
|
|
|
7e86df |
# hope) reasonably well defined on these. Patches welcome if your platform
|
|
|
7e86df |
# also supports it (or something like it)
|
|
|
7e86df |
- skip "no /dev/full or not a /dev/full platform", 2
|
|
|
7e86df |
+ skip "no /dev/full or not a /dev/full platform", 3
|
|
|
7e86df |
unless $^O =~ /^(linux|netbsd|freebsd)$/ && -c "/dev/full";
|
|
|
7e86df |
open my $fh, ">", "/dev/full"
|
|
|
7e86df |
- or skip "Could not open /dev/full: $!", 2;
|
|
|
7e86df |
+ or skip "Could not open /dev/full: $!", 3;
|
|
|
7e86df |
$fh->print("a" x 1024);
|
|
|
7e86df |
ok(!$fh->flush, "should fail to flush");
|
|
|
7e86df |
ok($fh->error, "stream should be in error");
|
|
|
7e86df |
+ $fh->clearerr;
|
|
|
7e86df |
+ ok(!$fh->error, "check clearerr removed the error");
|
|
|
7e86df |
close $fh; # silently ignore the error
|
|
|
7e86df |
}
|
|
|
7e86df |
--
|
|
|
7e86df |
2.25.4
|
|
|
7e86df |
|