Stop readline($foo) from autovivifying
authorFather Chrysostomos <sprout@cpan.org>
Tue, 23 Aug 2011 21:54:34 +0000 (14:54 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 23 Aug 2011 21:54:34 +0000 (14:54 -0700)
Currently <$foo> does not autovivify, but readline($foo) does, due to
the way pp_readline calls pp_rv2gv directly, with PL_op still holding
a pp_readline op, whose flags may have completely different meanings.

readline uses the OPf_SPECIAL flag to distinguish <$foo> from readline
($foo).  rv2gv uses it to determine whether to autovivify; hence the
discrepancy.

pp.c
t/op/readline.t

diff --git a/pp.c b/pp.c
index 865001b..dbe2647 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -197,8 +197,9 @@ PP(pp_rv2gv)
                    report_uninit(sv);
                RETSETUNDEF;
            }
-           if ((PL_op->op_flags & OPf_SPECIAL) &&
-               !(PL_op->op_flags & OPf_MOD))
+           if (  ((PL_op->op_flags & OPf_SPECIAL) &&
+                  !(PL_op->op_flags & OPf_MOD))
+               || PL_op->op_type == OP_READLINE  )
            {
                STRLEN len;
                const char * const nambeg = SvPV_nomg_const(sv, len);
index 81ac9e0..17567cd 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan tests => 25;
+plan tests => 27;
 
 # [perl #19566]: sv_gets writes directly to its argument via
 # TARG. Test that we respect SvREADONLY.
@@ -245,6 +245,17 @@ $two .= <DATA>;
 is( $one, "A: One\n", "rcatline works with tied scalars" );
 is( $two, "B: Two\n", "rcatline works with tied scalars" );
 
+# mentioned in bug #97482
+# <$foo> versus readline($foo) should not affect vivification.
+my $yunk = "brumbo";
+if (exists $::{$yunk}) {
+     die "Name $yunk already used. Please adjust this test."
+}
+<$yunk>;
+ok !defined *$yunk, '<> does not autovivify';
+readline($yunk);
+ok !defined *$yunk, "readline does not autovivify";
+
 __DATA__
 moo
 moo