1
0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-11-24 05:12:02 +01:00

Merge pull request #16 from mbra/master

Fix segfault when encoding python unicode dict-keys
This commit is contained in:
Jonas Tärnström 2011-06-16 00:55:26 -07:00
commit 7a9b93266b

@ -368,11 +368,24 @@ int Dict_iterNext(JSOBJ obj, JSONTypeContext *tc)
PRINTMARK();
return 0;
}
if (!PyString_Check(GET_TC(tc)->itemName))
GET_TC(tc)->itemName = PyObject_Str(GET_TC(tc)->itemName);
if (PyUnicode_Check(GET_TC(tc)->itemName))
{
GET_TC(tc)->itemName = PyUnicode_EncodeUTF8 (
PyUnicode_AS_UNICODE(GET_TC(tc)->itemName),
PyUnicode_GET_SIZE(GET_TC(tc)->itemName),
NULL
);
}
else
if (!PyString_Check(GET_TC(tc)->itemName))
{
GET_TC(tc)->itemName = PyObject_Str(GET_TC(tc)->itemName);
}
else
{
Py_INCREF(GET_TC(tc)->itemName);
}
PRINTMARK();
return 1;
}