PUTBACK; /* hv_iternext and hv_iterval might clobber stack_sp */
while ((entry = hv_iternext(keys))) {
SPAGAIN;
- if (dokeys)
+ if (dokeys) {
XPUSHs(hv_iterkeysv(entry)); /* won't clobber stack_sp */
+ if (SvUTF8((SV*)keys))
+ SvUTF8_on(TOPs); /* Yuck */
+ }
if (dovalues) {
PUTBACK;
tmpstr = realhv ?
if (!hv)
return 0;
+ if (SvUTF8((SV*)hv) && !SvUTF8(keysv))
+ sv_utf8_upgrade(keysv);
+
if (SvRMAGICAL(hv)) {
if (mg_find((SV*)hv,'P')) {
dTHR;
return 0;
xhv = (XPVHV*)SvANY(hv);
+
+ if (SvUTF8((SV*)hv) && !SvUTF8(keysv))
+ sv_utf8_upgrade(keysv);
+ else if (SvUTF8(keysv) && !SvUTF8((SV*)hv)) { /* Upgrade hash */
+ SvUTF8_on((SV*)hv);
+ /* XXX Need to save iterator to prevent weird things during "each" */
+ (void)hv_iterinit(hv);
+ while (entry = hv_iternext(hv)) {
+ if (HeKLEN(entry) != HEf_SVKEY) /* Upgrade to SV key */
+ HeSVKEY_set(entry, newSVpvn(HeKEY(entry), HeKLEN(entry)));
+ sv_utf8_upgrade(HeKEY_sv(entry));
+ }
+ }
+
if (SvMAGICAL(hv)) {
dTHR;
bool needs_copy;
#define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
-#define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
+#define SVphv_SHAREKEYS 0x80000000 /* keys live on shared string table */
#define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
#define SVprv_WEAKREF 0x80000000 /* Weak reference */