From 4499db7385adf05fc8c5f6e28aa920d268b63435 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 27 Jul 2012 23:46:07 -0700 Subject: Flatten vstrings modified in place MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- embed.fnc | 1 - 1 file changed, 1 deletion(-) (limited to 'embed.fnc') diff --git a/embed.fnc b/embed.fnc index dd4daefe61..b3f757c1bf 100644 --- a/embed.fnc +++ b/embed.fnc @@ -775,7 +775,6 @@ p |int |magic_settaint |NN SV* sv|NN MAGIC* mg p |int |magic_setuvar |NN SV* sv|NN MAGIC* mg p |int |magic_setvec |NN SV* sv|NN MAGIC* mg p |int |magic_setutf8 |NN SV* sv|NN MAGIC* mg -p |int |magic_setvstring|NN SV* sv|NN MAGIC* mg p |int |magic_set_all_env|NN SV* sv|NN MAGIC* mg p |U32 |magic_sizepack |NN SV* sv|NN MAGIC* mg p |int |magic_wipepack |NN SV* sv|NN MAGIC* mg -- cgit v1.2.1