This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #77362] Assigning glob to lvalue causes stringification
authorFather Chrysostomos <sprout@cpan.org>
Sun, 26 Sep 2010 18:09:28 +0000 (11:09 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 26 Sep 2010 18:09:28 +0000 (11:09 -0700)
commit13be902cef8b01c085a6b8b1b59fa2754a10cdfb
tree36349eb3f2bffa12f01cf0fa38a37036a8b80448
parent25e68b8bdd34f742e9a4780090bafa60c943ec14
[perl #77362] Assigning glob to lvalue causes stringification

This test from t/op/gv.t was added by change 22315/4ce457a6:

{
    # test the assignment of a GLOB to an LVALUE
    my $e = '';
    local $SIG{__DIE__} = sub { $e = $_[0] };
    my $v;
    sub f { $_[0] = 0; $_[0] = "a"; $_[0] = *DATA }
    f($v);
    is ($v, '*main::DATA');
    my $x = <$v>;
    is ($x, "perl\n");
}

That change was the one that made glob-to-lvalue assignment work to
begin with. But this test passes in perl version *prior* to that
change.

This patch fixes the test and adds tests to make sure what is assigned
is actually a glob, and not just a string.

It also happens to fix the stringification bug. In doing so, it essen-
tially ‘enables’ globs-as-PVLVs.

It turns out that many different parts of the perl source don’t fully
take this into account, so this patch also fixes the following to work
with them (I tried to make these into separate patches, but they are
so intertwined it just got too complicated):

• GvIO(gv) to make readline and other I/O ops work.

• Autovivification of glob slots.

• tie *$pvlv

• *$pvlv = undef, *$pvlv = $number, *$pvlv = $ref

• Duplicating a filehandle accessed through a PVLV glob when the
  stringified form of the glob cannot be used to access the file
  handle (!)

• Using a PVLV glob as a subroutine reference

• Coderef assignment when the glob is no longer in the symbol table

• open with a PVLV glob for the filehandle

• -t and -T

• Unopened file handle warnings
gv.c
gv.h
pp_hot.c
pp_sys.c
sv.c
t/op/gv.t
util.c