From: Nicholas Clark Date: Thu, 30 Mar 2006 20:37:03 +0000 (+0000) Subject: Fix bug #38815 (localising keys which are UTF-8 encoded didn't delete X-Git-Tag: accepted/trunk/20130322.191538~18112 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7d654f43b92f51303a8d5388d3c3bfb7ebbceb22;p=platform%2Fupstream%2Fperl.git Fix bug #38815 (localising keys which are UTF-8 encoded didn't delete them correctly on scope exit) p4raw-id: //depot/perl@27637 --- diff --git a/pp_hot.c b/pp_hot.c index 3b4d8ed..91940ad 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1828,7 +1828,8 @@ PP(pp_helem) if (!preeminent) { STRLEN keylen; const char * const key = SvPV_const(keysv, keylen); - SAVEDELETE(hv, savepvn(key,keylen), keylen); + SAVEDELETE(hv, savepvn(key,keylen), + SvUTF8(keysv) ? -(I32)keylen : keylen); } else save_helem(hv, keysv, svp); } diff --git a/scope.c b/scope.c index a49a82a..7b76823 100644 --- a/scope.c +++ b/scope.c @@ -826,7 +826,7 @@ Perl_leave_scope(pTHX_ I32 base) ptr = SSPOPPTR; hv = (HV*)ptr; ptr = SSPOPPTR; - (void)hv_delete(hv, (char*)ptr, (U32)SSPOPINT, G_DISCARD); + (void)hv_delete(hv, (char*)ptr, (I32)SSPOPINT, G_DISCARD); SvREFCNT_dec(hv); Safefree(ptr); break; diff --git a/t/op/local.t b/t/op/local.t index 561e395..bc24657 100755 --- a/t/op/local.t +++ b/t/op/local.t @@ -4,7 +4,7 @@ BEGIN { chdir 't' if -d 't'; require './test.pl'; } -plan tests => 95; +plan tests => 104; my $list_assignment_supported = 1; @@ -368,3 +368,27 @@ sub f { ok(0 == $[); } ::ok(f1() eq "f1", "localised sub restored"); ::ok(f2() eq "f2", "localised sub restored"); } + +# Localising unicode keys (bug #38815) +{ + my %h; + $h{"\243"} = "pound"; + $h{"\302\240"} = "octects"; + is(scalar keys %h, 2); + { + my $unicode = chr 256; + my $ambigous = "\240" . $unicode; + chop $ambigous; + local $h{$unicode} = 256; + local $h{$ambigous} = 160; + + is(scalar keys %h, 4); + is($h{"\243"}, "pound"); + is($h{$unicode}, 256); + is($h{$ambigous}, 160); + is($h{"\302\240"}, "octects"); + } + is(scalar keys %h, 2); + is($h{"\243"}, "pound"); + is($h{"\302\240"}, "octects"); +}