summaryrefslogtreecommitdiff
path: root/msgpack
diff options
context:
space:
mode:
Diffstat (limited to 'msgpack')
-rw-r--r--msgpack/fallback.py2
-rw-r--r--msgpack/unpack.h3
2 files changed, 5 insertions, 0 deletions
diff --git a/msgpack/fallback.py b/msgpack/fallback.py
index 9e31213..9a48b71 100644
--- a/msgpack/fallback.py
+++ b/msgpack/fallback.py
@@ -644,6 +644,8 @@ class Unpacker(object):
key = self._unpack(EX_CONSTRUCT)
if self._strict_map_key and type(key) not in (unicode, bytes):
raise ValueError("%s is not allowed for map key" % str(type(key)))
+ if not PY2 and type(key) is str:
+ key = sys.intern(key)
ret[key] = self._unpack(EX_CONSTRUCT)
if self._object_hook is not None:
ret = self._object_hook(ret)
diff --git a/msgpack/unpack.h b/msgpack/unpack.h
index 539a991..ead5095 100644
--- a/msgpack/unpack.h
+++ b/msgpack/unpack.h
@@ -192,6 +192,9 @@ static inline int unpack_callback_map_item(unpack_user* u, unsigned int current,
PyErr_Format(PyExc_ValueError, "%.100s is not allowed for map key", Py_TYPE(k)->tp_name);
return -1;
}
+ if (PyUnicode_CheckExact(k)) {
+ PyUnicode_InternInPlace(&k);
+ }
if (u->has_pairs_hook) {
msgpack_unpack_object item = PyTuple_Pack(2, k, v);
if (!item)