This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #123503] Bug in POSIX::strerror on 5.21.7
authorKarl Williamson <khw@cpan.org>
Fri, 26 Dec 2014 21:49:17 +0000 (14:49 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 7 Jan 2015 04:41:25 +0000 (21:41 -0700)
There were 3 ideas for a patch: mine, Slaven's, and Father
Chrysostomos'.  I tried out all 3, and all three appear to work, without
breaking #123171.  But I chose FC's as I think it is the best.

I had to create a new .t because it turns out that the test didn't fail
when placed in the obvious test file, wrappers.t.  It appears that the
'use File::Temp' in that file perturbs things to not fail later on.
This is scary, so I created a minimal file.  I thought about using
fresh_perl, but wrappers.t needs functions from Test::More.

MANIFEST
ext/POSIX/lib/POSIX.pm
ext/POSIX/t/strerror_errno.t [new file with mode: 0644]

index 9d2458d..5c434e9 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -3832,6 +3832,7 @@ ext/POSIX/t/math.t                Basic math tests for POSIX
 ext/POSIX/t/posix.t            See if POSIX works
 ext/POSIX/t/sigaction.t                See if POSIX::sigaction works
 ext/POSIX/t/sigset.t           See if POSIX::SigSet works
+ext/POSIX/t/strerror_errno.t   See if POSIX:strerror doesn't trash $!
 ext/POSIX/t/sysconf.t          See if POSIX works
 ext/POSIX/t/taint.t            See if POSIX works with taint
 ext/POSIX/t/termios.t          See if POSIX works
index 5695990..793fdd4 100644 (file)
@@ -151,7 +151,7 @@ my %reimpl = (
     exit      => 'status => CORE::exit($_[0])',
     getenv    => 'name => $ENV{$_[0]}',
     system    => 'command => CORE::system($_[0])',
-    strerror  => 'errno => use locale; local $! = $_[0]; "$!"',
+    strerror  => 'errno => BEGIN { local $!; require locale; locale->import} local $! = $_[0]; "$!"',
     strstr    => 'big, little => CORE::index($_[0], $_[1])',
     chmod     => 'mode, filename => CORE::chmod($_[0], $_[1])',
     fstat     => 'fd => CORE::open my $dup, "<&", $_[0]; CORE::stat($dup)', # Gross.
diff --git a/ext/POSIX/t/strerror_errno.t b/ext/POSIX/t/strerror_errno.t
new file mode 100644 (file)
index 0000000..4807a8d
--- /dev/null
@@ -0,0 +1,17 @@
+use Config;
+use Test::More;
+
+# This is placed in a separate file, as some 'requires' and 'uses' are known
+# to cause it to not fail even with the bug it's testing still being
+# broken.  [perl #123503].
+
+plan(skip_all => "POSIX is unavailable")
+    unless $Config{extensions} =~ /\bPOSIX\b/;
+
+require POSIX;
+
+$! = 1;
+POSIX::strerror(1);
+is (0+$!, 1, 'strerror doesn\'t destroy $!');
+
+done_testing();