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