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
[perl5.git] / ext / B / B.xs
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)));
            }
        }