diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-08-30 09:31:47 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-08-30 12:39:39 -0700 |
commit | 23496c6ea4cd9e3c09a9fe1878f55f241bdc17e5 (patch) | |
tree | 308baee5cf0e50b4fd4b0170aff3f1be4b9b66f2 /t/op/magic.t | |
parent | 38552987f01ba3c9fbea08e94b95b439e5ded364 (diff) | |
download | perl-23496c6ea4cd9e3c09a9fe1878f55f241bdc17e5.tar.gz |
Eliminate is_gv_magical_sv
This resolves perl bug #97978.
Many built-in variables, like $], are actually created on the fly
when first accessed. Perl likes to pretend that these variables have
always existed, so it autovivifies the *] glob even in rvalue context
(e.g., defined *{"]"}, close "]").
The list of variables that were autovivified was maintained separ-
ately (in is_gv_magical_sv) from the code that actually creates
them (gv_fetchpvn_flags). ‘Maintained’ is not actually precise: it
*wasn’t* being maintained, and there were new variables that never
got added to is_gv_magical_sv and one deleted variable that was
never removed.
There are only two pieces of code that call is_gv_magical_sv, both in
pp.c: S_rv2gv (called by *{} and also the implicit *{} that functions
like close() provide) and Perl_softrefxv (called by ${}, @{}, %{}).
In both cases, the glob is immediately autovivified if
is_gv_magical_sv returns true.
So this commit eliminates the extra maintenance burden by extirpat-
ing is_gv_magical_sv altogether, and replacing it with a new flag to
gv_fetchpvn_flags, GvADDMG, which will autovivify a glob *if* it’s a
magical one.
It does make defined(*{"frobbly"}) slightly slower, in that it creates
a temporary glob and then frees it when it sees nothing magical has
been done with it. But this case is rare enough it should not matter.
At least I got rid of the bugginess.
Diffstat (limited to 't/op/magic.t')
-rw-r--r-- | t/op/magic.t | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/t/op/magic.t b/t/op/magic.t index d7c17091d0..3969673742 100644 --- a/t/op/magic.t +++ b/t/op/magic.t @@ -18,8 +18,8 @@ BEGIN { my %non_mini = map { $_ => 1 } qw(+ -); for (qw( SIG ^OPEN ^TAINT ^UNICODE ^UTF8LOCALE ^WARNING_BITS 1 2 3 4 5 6 7 8 - 9 42 & ` ' : ? ! _ - # [ ^ ~ = % . ( ) < > \ / $ | + ; ] ^A ^C ^D - ^E ^F ^H ^I ^L ^N ^O ^P ^S ^T ^V ^W + 9 42 & ` ' : ? ! _ - [ ^ ~ = % . ( ) < > \ / $ | + ; ] ^A ^C ^D + ^E ^F ^H ^I ^L ^N ^O ^P ^S ^T ^V ^W ^UTF8CACHE )) { my $v = $_; # avoid using any global vars here: |