summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1998-08-02 04:21:48 +0000
committerGurusamy Sarathy <gsar@cpan.org>1998-08-02 04:21:48 +0000
commitdf0bd2f4ab5af7b0babaa8c3c84969f29fcac3c7 (patch)
tree914b0cdb127888696c000090152efbaaa4029187
parent502a173a8c3e53b1538fe058ed5270cb83ccfb93 (diff)
downloadperl-df0bd2f4ab5af7b0babaa8c3c84969f29fcac3c7.tar.gz
ensure implicit close on local(*FH) doesn't affect $! and thence $?
p4raw-id: //depot/maint-5.005/perl@1687
-rw-r--r--sv.c3
-rwxr-xr-xt/op/die_exit.t9
2 files changed, 8 insertions, 4 deletions
diff --git a/sv.c b/sv.c
index 3652b9d83d..72007b13cb 100644
--- a/sv.c
+++ b/sv.c
@@ -2885,7 +2885,8 @@ sv_clear(register SV *sv)
stash = NULL;
switch (SvTYPE(sv)) {
case SVt_PVIO:
- if (IoIFP(sv) != PerlIO_stdin() &&
+ if (IoIFP(sv) &&
+ IoIFP(sv) != PerlIO_stdin() &&
IoIFP(sv) != PerlIO_stdout() &&
IoIFP(sv) != PerlIO_stderr())
io_close((IO*)sv);
diff --git a/t/op/die_exit.t b/t/op/die_exit.t
index b5760d6fa0..ffbb1e015e 100755
--- a/t/op/die_exit.t
+++ b/t/op/die_exit.t
@@ -30,6 +30,8 @@ my %tests = (
14 => [ 255, 0],
15 => [ 255, 1],
16 => [ 255, 256],
+ # see if implicit close preserves $?
+ 17 => [ 42, 42, '{ local *F; open F, q[TEST]; close F } die;'],
);
my $max = keys %tests;
@@ -37,11 +39,12 @@ my $max = keys %tests;
print "1..$max\n";
foreach my $test (1 .. $max) {
- my($bang, $query) = @{$tests{$test}};
+ my($bang, $query, $code) = @{$tests{$test}};
+ $code ||= 'die;';
my $exit =
($^O eq 'MSWin32'
- ? system qq($perl -e "\$! = $bang; \$? = $query; die;" 2> nul)
- : system qq($perl -e '\$! = $bang; \$? = $query; die;' 2> /dev/null));
+ ? system qq($perl -e "\$! = $bang; \$? = $query; $code" 2> nul)
+ : system qq($perl -e '\$! = $bang; \$? = $query; $code' 2> /dev/null));
printf "# 0x%04x 0x%04x 0x%04x\nnot ", $exit, $bang, $query
unless $exit == (($bang || ($query >> 8) || 255) << 8);