Skip to content

Commit 80c1f1e

Browse files
committed
only clear the stream error state in readline() for glob()
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.
1 parent 02cf5fb commit 80c1f1e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pp_hot.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,14 +3334,19 @@ Perl_do_readline(pTHX)
33343334
|| SNARF_EOF(gimme, PL_rs, io, sv)
33353335
|| PerlIO_error(fp)))
33363336
{
3337-
PerlIO_clearerr(fp);
33383337
if (IoFLAGS(io) & IOf_ARGV) {
33393338
fp = nextargv(PL_last_in_gv, PL_op->op_flags & OPf_SPECIAL);
3340-
if (fp)
3339+
if (fp) {
33413340
continue;
3341+
}
33423342
(void)do_close(PL_last_in_gv, FALSE);
33433343
}
33443344
else if (type == OP_GLOB) {
3345+
/* clear any errors here so we only fail on the pclose()
3346+
failing, which should only happen on the child
3347+
failing
3348+
*/
3349+
PerlIO_clearerr(fp);
33453350
if (!do_close(PL_last_in_gv, FALSE)) {
33463351
Perl_ck_warner(aTHX_ packWARN(WARN_GLOB),
33473352
"glob failed (child exited with status %d%s)",

t/lib/warnings/pp_hot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ $a = <FOO> ;
237237
use warnings 'io' ;
238238
$a = <FOO> ;
239239
$a = <FH> ;
240-
close (FH) or die $! ;
241-
close (FOO) or die $! ;
240+
close (FH);
241+
close (FOO);
242242
unlink $file ;
243243
EXPECT
244244
Filehandle FH opened only for output at - line 5.

0 commit comments

Comments
 (0)