Skip to content

Commit

Permalink
only clear the stream error state in readline() for glob()
Browse files Browse the repository at this point in the history
This would previously clear the stream error state in any case
where sv_gets() failed and the error state was set.

This included normal files, which meant that the fact that an error
occurred was no longer reflected in the stream state.

For reads from ARGV this was a no-op, since nextargv() re-opens the
input stream by calling do_open6() which closes the old input stream
silently.

For glob() (and really only for miniperl, since File::Glob is used for
a full perl) leaving the stream in an error state could be confusing
for the error reporting done when do_close() fails, since it would
fail if the stream has an error state, but we report it as the
underlying pclose() failing due to the child process failing in some
way.

Since this now leaves the error state on the stream, the close()
calls in the test updated by this commit would fail, changing its
output.  Since the result of those closes didn't seem related
to the purpose of the test, I changed it not throw an error on
either close() failing.
  • Loading branch information
tonycoz committed Aug 31, 2022
1 parent 02cf5fb commit 80c1f1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

0 comments on commit 80c1f1e

Please sign in to comment.