This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #120535] Add UTF8 flag to B::HV->ARRAY keys
authorTony Cook <tony@develop-help.com>
Mon, 18 Nov 2013 05:44:40 +0000 (16:44 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 18 Nov 2013 05:44:40 +0000 (16:44 +1100)
ext/B/B.xs
ext/B/t/b.t

index 0b097d4..1c44857 100644 (file)
@@ -1952,14 +1952,18 @@ HvARRAY(hv)
        B::HV   hv
     PPCODE:
        if (HvUSEDKEYS(hv) > 0) {
-           SV *sv;
-           char *key;
-           I32 len;
+           HE *he;
            (void)hv_iterinit(hv);
            EXTEND(sp, HvUSEDKEYS(hv) * 2);
-           while ((sv = hv_iternextsv(hv, &key, &len))) {
-               mPUSHp(key, len);
-               PUSHs(make_sv_object(aTHX_ sv));
+           while ((he = hv_iternext(hv))) {
+                if (HeSVKEY(he)) {
+                    mPUSHs(HeSVKEY(he));
+                } else if (HeKUTF8(he)) {
+                    PUSHs(newSVpvn_flags(HeKEY(he), HeKLEN(he), SVf_UTF8|SVs_TEMP));
+                } else {
+                    mPUSHp(HeKEY(he), HeKLEN(he));
+                }
+               PUSHs(make_sv_object(aTHX_ HeVAL(he)));
            }
        }
 
index cbf9e1f..1fee139 100644 (file)
@@ -415,4 +415,11 @@ EOS
     }
 }
 
+{ # [perl #120535]
+    my %h = ( "\x{100}" => 1 );
+    my $b = B::svref_2object(\%h);
+    my ($k, $v) = $b->ARRAY;
+    is($k, "\x{100}", "check utf8 preserved by B::HV::ARRAY");
+}
+
 done_testing();