diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-07-27 23:46:07 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-07-27 23:46:33 -0700 |
commit | 4499db7385adf05fc8c5f6e28aa920d268b63435 (patch) | |
tree | d44c8f9c0a2a84ccf98f701d09be2a67955ed1a9 /regen/mg_vtable.pl | |
parent | 5bbe7184a7198d6334733fd9eb3ca7db21bf04f2 (diff) | |
download | perl-4499db7385adf05fc8c5f6e28aa920d268b63435.tar.gz |
Flatten vstrings modified in place
A substitution forces its target to a string upon successful substitu-
tion, even if the substitution did nothing:
$ ./perl -Ilib -le '$a = *f; $a =~ s/f/f/; print ref \$a'
SCALAR
Notice that $a is no longer a glob after s///.
But vstrings are different:
$ ./perl -Ilib -le '$a = v102; $a =~ s/f/f/; print ref \$a'
VSTRING
I fixed this in 5.16 (1e6bda93) for those cases where the vstring ends
up with a value that doesn’t correspond to the actual string:
$ ./perl -Ilib -le '$a = v102; $a =~ s/f/o/; print ref \$a'
SCALAR
It works through vstring set-magic, that does the check and removes
the magic if it doesn’t match.
I did it that way because I couldn’t think of any other way to fix
bug #29070, and I didn’t realise at the time that I hadn’t fixed
all the bugs.
By making SvTHINKFIRST true on a vstring, we force it through
sv_force_normal before any in-place string operations. We can also
make sv_force_normal handle vstrings as well. This fixes all the lin-
gering-vstring-magic bugs in just two lines, making the vstring set-
magic (which is also slow) redundant. It also allows the special case
in sv_setsv_flags to be removed.
Or at least that was what I had hoped.
It turns out that pp_subst, twists and turns in tortuous ways, and
needs special treatment for things like this.
And do_trans functions wasn’t checking SvTHINKFIRST when arguably it
should have.
I tweaked sv_2pv{utf8,byte} to avoid copying magic variables that do
not need copying.
Diffstat (limited to 'regen/mg_vtable.pl')
-rw-r--r-- | regen/mg_vtable.pl | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/regen/mg_vtable.pl b/regen/mg_vtable.pl index f96c7a0fa5..5fcdc4c78f 100644 --- a/regen/mg_vtable.pl +++ b/regen/mg_vtable.pl @@ -84,7 +84,7 @@ my %mg = unknown_to_sv_magic => 1 }, vec => { char => 'v', vtable => 'vec', value_magic => 1, desc => 'vec() lvalue' }, - vstring => { char => 'V', value_magic => 1, vtable => 'vstring', + vstring => { char => 'V', value_magic => 1, desc => 'SV was vstring literal' }, utf8 => { char => 'w', vtable => 'utf8', value_magic => 1, desc => 'Cached UTF-8 information' }, @@ -142,7 +142,6 @@ my %sig = cond => '#ifdef USE_LOCALE_COLLATE'}, 'hintselem' => {set => 'sethint', clear => 'clearhint'}, 'hints' => {clear => 'clearhints'}, - 'vstring' => {set => 'setvstring'}, 'checkcall' => {copy => 'copycallchecker'}, ); |