Skip to content

Commit

Permalink
pp_readline: Don’t set PL_last_in_gv to &PL_sv_undef
Browse files Browse the repository at this point in the history
Code elsewhere assumes it is always a GV or NULL:

readline "foo";
my $lastfh = "${^LAST_FH}";
  • Loading branch information
Father Chrysostomos committed Dec 15, 2014
1 parent 0824f74 commit 84ee769
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pp_hot.c
Expand Up @@ -449,6 +449,10 @@ PP(pp_readline)
PUTBACK;
Perl_pp_rv2gv(aTHX);
PL_last_in_gv = MUTABLE_GV(*PL_stack_sp--);
if (PL_last_in_gv == (GV *)&PL_sv_undef)
PL_last_in_gv = NULL;
else
assert(isGV_with_GP(PL_last_in_gv));
}
}
return do_readline();
Expand Down
7 changes: 6 additions & 1 deletion t/op/readline.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
set_up_inc('../lib');
}

plan tests => 30;
plan tests => 31;

# [perl #19566]: sv_gets writes directly to its argument via
# TARG. Test that we respect SvREADONLY.
Expand Down Expand Up @@ -270,6 +270,11 @@ is tell, -1, 'unglobbery of last gv nullifies PL_last_in_gv';
readline *{$f{g}};
is tell, tell *foom, 'readline *$glob_copy sets PL_last_in_gv';

# PL_last_in_gv should not point to &PL_sv_undef, either.
# This used to fail an assertion or return a scalar ref.
readline undef;
is ${^LAST_FH}, undef, '${^LAST_FH} after readline undef';

__DATA__
moo
moo
Expand Down

0 comments on commit 84ee769

Please sign in to comment.