Skip to content

only clear the stream error state in readline() for a good nextargv() #20103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pp_hot.c
Original file line number Diff line number Diff line change
Expand Up @@ -3334,14 +3334,19 @@ Perl_do_readline(pTHX)
|| SNARF_EOF(gimme, PL_rs, io, sv)
|| PerlIO_error(fp)))
{
PerlIO_clearerr(fp);
if (IoFLAGS(io) & IOf_ARGV) {
fp = nextargv(PL_last_in_gv, PL_op->op_flags & OPf_SPECIAL);
if (fp)
if (fp) {
continue;
}
(void)do_close(PL_last_in_gv, FALSE);
}
else if (type == OP_GLOB) {
/* clear any errors here so we only fail on the pclose()
failing, which should only happen on the child
failing
*/
PerlIO_clearerr(fp);
if (!do_close(PL_last_in_gv, FALSE)) {
Perl_ck_warner(aTHX_ packWARN(WARN_GLOB),
"glob failed (child exited with status %d%s)",
Expand Down
4 changes: 2 additions & 2 deletions t/lib/warnings/pp_hot
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ $a = <FOO> ;
use warnings 'io' ;
$a = <FOO> ;
$a = <FH> ;
close (FH) or die $! ;
close (FOO) or die $! ;
close (FH);
close (FOO);
unlink $file ;
EXPECT
Filehandle FH opened only for output at - line 5.
Expand Down
14 changes: 13 additions & 1 deletion t/op/readline.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BEGIN {
set_up_inc('../lib');
}

plan tests => 32;
plan tests => 36;

# [perl #19566]: sv_gets writes directly to its argument via
# TARG. Test that we respect SvREADONLY.
Expand Down Expand Up @@ -289,6 +289,18 @@ is ${^LAST_FH}, undef, '${^LAST_FH} after readline undef';
'[perl #123790] *x=<y> used to fail an assertion';
}

SKIP:
{
skip_without_dynamic_extension("IO", 4);
my $tmpfile = tempfile();
open my $fh, ">", $tmpfile
or die "Cannot open $tmpfile: $!";
ok(!$fh->error, "no error before we try to read");
ok(!<$fh>, "fail to readline file opened for write");
ok($fh->error, "error after trying to readline file opened for write");
ok(!close($fh), "closing the file should fail");
}

__DATA__
moo
moo
Expand Down