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