This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Eliminate is_gv_magical_sv
authorFather Chrysostomos <sprout@cpan.org>
Tue, 30 Aug 2011 16:31:47 +0000 (09:31 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 30 Aug 2011 19:39:39 +0000 (12:39 -0700)
commit23496c6ea4cd9e3c09a9fe1878f55f241bdc17e5
tree308baee5cf0e50b4fd4b0170aff3f1be4b9b66f2
parent38552987f01ba3c9fbea08e94b95b439e5ded364
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.
embed.fnc
embed.h
gv.c
gv.h
pod/perldelta.pod
pp.c
proto.h
t/op/magic.t