This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #97088] Prevent double get-magic in various cases
authorGerard Goossen <gerard@ggoossen.net>
Wed, 24 Aug 2011 21:26:51 +0000 (14:26 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 24 Aug 2011 21:26:51 +0000 (14:26 -0700)
commit9026059dcee814a1dd826752b902416a3eff6eb2
tree1cb3e4b0b071f4e9f6d8d2d0b05618d382cf525b
parent835c0338f857876193eb10d8e9d5a6efe142b2a9
[perl #97088] Prevent double get-magic in various cases

This patch prevents get-magic from executing twice during autovivifi-
cation when the op doing the autovivification is not directly nested
inside the dereferencing op.

This can happen in cases like this:

    ${ (), $a } = 1;

Previously (as of 5.13.something), the outer op was marked with the
OPpDEREFed flag, which indicated that get-magic had already been
called by the vivifying op (calling get-magic during vivification is
inevitable):

$ perl5.14.0 -MO=Concise -e '${ $a } = 1'
8  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 2 -e:1) v:{ ->3
7     <2> sassign vKS/2 ->8
3        <$> const[IV 1] s ->4
6        <1> rv2sv sKRM*/DREFed,1 ->7          <-- right here
-           <@> scope sK ->6
-              <0> ex-nextstate v ->4
5              <1> rv2sv sKM/DREFSV,1 ->6
4                 <#> gv[*a] s ->5
-e syntax OK

But in the ${()...} example above, there is a list op in the way that
prevents the flag from being set inside the peephole optimizer.  It’s
not even possible to set it correctly in all cases, as in this exam-
ple, which would need it both set and not set depending on which
branch of the ternary operator is executed:

    ${ $x ? delete $a[0] : $a[0] } = 1

Instead of setting the OPpDEREFed flag, we now make a non-magic copy
of the SV in vivify_ref (the first time get-magic is executed).
dump.c
embed.fnc
ext/B/t/f_sort.t
lib/overload.t
op.c
op.h
pp.c
pp_ctl.c
pp_hot.c
proto.h