diff options
author | Father Chrysostomos <sprout@cpan.org> | 2010-09-26 11:09:28 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2010-09-26 11:09:28 -0700 |
commit | 13be902cef8b01c085a6b8b1b59fa2754a10cdfb (patch) | |
tree | 36349eb3f2bffa12f01cf0fa38a37036a8b80448 /gv.h | |
parent | 25e68b8bdd34f742e9a4780090bafa60c943ec14 (diff) | |
download | perl-13be902cef8b01c085a6b8b1b59fa2754a10cdfb.tar.gz |
[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
Diffstat (limited to 'gv.h')
-rw-r--r-- | gv.h | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -88,7 +88,17 @@ Return the SV from the GV. #endif #define GvREFCNT(gv) (GvGP(gv)->gp_refcnt) -#define GvIO(gv) ((gv) && SvTYPE((const SV*)gv) == SVt_PVGV && GvGP(gv) ? GvIOp(gv) : NULL) +#define GvIO(gv) \ + ( \ + (gv) \ + && ( \ + SvTYPE((const SV*)(gv)) == SVt_PVGV \ + || SvTYPE((const SV*)(gv)) == SVt_PVLV \ + ) \ + && GvGP(gv) \ + ? GvIOp(gv) \ + : NULL \ + ) #define GvIOp(gv) (GvGP(gv)->gp_io) #define GvIOn(gv) (GvIO(gv) ? GvIOp(gv) : GvIOp(gv_IOadd(gv))) |