summaryrefslogtreecommitdiff
path: root/universal.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-05-29 14:21:06 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-05-29 14:46:22 -0700
commit40f11004fb3b5fa1cd207a20090df837d721b736 (patch)
tree6a34379b467f76b48ac57cc85685ec0c104e9848 /universal.c
parent694cf0d2097096aceb05356229e210423cd909c2 (diff)
downloadperl-40f11004fb3b5fa1cd207a20090df837d721b736.tar.gz
[perl #91834] utf8::decode does not respect copy-on-write
utf8::decode was not respecting copy-on-write, but simply modify- ing the PV (the scalar’s string buffer) in place, causing problems with hashes: my $name = "\x{c3}\x{b3}"; my ($k1) = keys %{ { $name=>undef } }; my $k2 = $name; utf8::decode($k1); utf8::decode($k2); print "k1 eq k2 = '", $k1 eq $k2, "'\n"; my $h = { $k1 => 1, $k2 => 2 }; print "{k1} '", $h->{$k1}, "'\n"; print "{k2} '", $h->{$k2}, "'\n"; This example (from the RT ticket) shows that there were two hash ele- ments with the same key. As of this commit, the hash only has one element.
Diffstat (limited to 'universal.c')
-rw-r--r--universal.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/universal.c b/universal.c
index 145d860bc6..d012c0f01d 100644
--- a/universal.c
+++ b/universal.c
@@ -695,6 +695,7 @@ XS(XS_utf8_decode)
croak_xs_usage(cv, "sv");
else {
SV * const sv = ST(0);
+ if (SvIsCOW(sv)) sv_force_normal(sv);
const bool RETVAL = sv_utf8_decode(sv);
ST(0) = boolSV(RETVAL);
sv_2mortal(ST(0));