This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add UTF8 flag to keys returned by B::HV->ARRAY
authorReini Urban <rurban@x-ray.at>
Wed, 13 Nov 2013 19:18:09 +0000 (13:18 -0600)
committerTony Cook <tony@develop-help.com>
Mon, 18 Nov 2013 04:18:43 +0000 (15:18 +1100)
hv_iternextsv() ignores the HEK flags, but we do care about the UTF8 flag
at least when returning hash keys from B::HV->ARRAY

ext/B/B.xs

index 0b097d4..1c44857 100644 (file)
@@ -1952,14 +1952,18 @@ HvARRAY(hv)
        B::HV   hv
     PPCODE:
        if (HvUSEDKEYS(hv) > 0) {
        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);
            (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)));
            }
        }
 
            }
        }