When converting a tuple to a list, the count needs to be incremented on the borrowed reference

http://github.com/rtyler/py-yajl/issues#issue/11

Change-Id: I54adeaf992d041f43b8d1c9c8eb3fbe957b85826
This commit is contained in:
R. Tyler Ballance 2010-04-06 20:54:53 -07:00
parent dff262de24
commit 836ea060ac
3 changed files with 13 additions and 1 deletions

View File

@ -181,10 +181,13 @@ static yajl_gen_status ProcessObject(_YajlEncoder *self, PyObject *object)
*/
Py_ssize_t size = PyTuple_Size(object);
PyObject *converted = PyList_New(size);
PyObject *item = NULL;
unsigned int i = 0;
for (; i < size; ++i) {
PyList_SET_ITEM(converted, (Py_ssize_t)(i), PyTuple_GetItem(object, i));
item = PyTuple_GetItem(object, i);
Py_INCREF(item);
PyList_SET_ITEM(converted, (Py_ssize_t)(i), item);
}
return ProcessObject(self, converted);
}

BIN
test_data/issue_11.gz Normal file

Binary file not shown.

9
tests/issue_11.py Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env python
import yajl
import sys
for i, l in enumerate(sys.stdin):
l = l.rstrip('\n').split('\t')
d = yajl.dumps(tuple(l))
print i,