1
0
Fork 0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-05-28 18:16:02 +02:00

Fixes for sort_keys bug and a typo.

- Fixed segfault when using sort_keys=True on dict with unorderable keys (GH247)

    - Fixed refcount becoming negative when using sort_keys=True (GH243)

    - Fixed compile error when defining JSON_NO_EXTRA_WHITESPACE
      caused by a wrongly named variable. (GH245)
This commit is contained in:
Joakim Hamren 2017-02-04 01:07:52 +01:00
parent ab6b6f88cd
commit 870ee48fe1
2 changed files with 12 additions and 4 deletions

View File

@ -717,7 +717,7 @@ static void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t c
{
const char *value;
char *objName;
int count;
int count, res;
JSOBJ iterObj;
size_t szlen;
JSONTypeContext tc;
@ -796,7 +796,7 @@ static void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t c
{
Buffer_AppendCharUnchecked (enc, ',');
#ifndef JSON_NO_EXTRA_WHITESPACE
Buffer_AppendCharUnchecked (buffer, ' ');
Buffer_AppendCharUnchecked (enc, ' ');
#endif
Buffer_AppendIndentNewlineUnchecked (enc);
}
@ -823,8 +823,16 @@ static void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t c
Buffer_AppendCharUnchecked (enc, '{');
Buffer_AppendIndentNewlineUnchecked (enc);
while (enc->iterNext(obj, &tc))
while ((res = enc->iterNext(obj, &tc)))
{
if(res < 0)
{
enc->iterEnd(obj, &tc);
enc->endTypeContext(obj, &tc);
enc->level--;
return;
}
if (count > 0)
{
Buffer_AppendCharUnchecked (enc, ',');

View File

@ -537,6 +537,7 @@ static int SortedDict_iterNext(JSOBJ obj, JSONTypeContext *tc)
// Sort the list.
if (PyList_Sort(items) < 0)
{
PyErr_SetString(PyExc_ValueError, "unorderable keys");
goto error;
}
@ -607,7 +608,6 @@ static void SortedDict_iterEnd(JSOBJ obj, JSONTypeContext *tc)
{
GET_TC(tc)->itemName = NULL;
GET_TC(tc)->itemValue = NULL;
Py_DECREF(GET_TC(tc)->newObj);
Py_DECREF(GET_TC(tc)->dictObj);
PRINTMARK();
}