Skip to content
This repository was archived by the owner on Mar 8, 2018. It is now read-only.

Commit 836ea06

Browse files
author
R. Tyler Ballance
committed
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
1 parent dff262d commit 836ea06

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

encoder.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,13 @@ static yajl_gen_status ProcessObject(_YajlEncoder *self, PyObject *object)
181181
*/
182182
Py_ssize_t size = PyTuple_Size(object);
183183
PyObject *converted = PyList_New(size);
184+
PyObject *item = NULL;
184185
unsigned int i = 0;
185186

186187
for (; i < size; ++i) {
187-
PyList_SET_ITEM(converted, (Py_ssize_t)(i), PyTuple_GetItem(object, i));
188+
item = PyTuple_GetItem(object, i);
189+
Py_INCREF(item);
190+
PyList_SET_ITEM(converted, (Py_ssize_t)(i), item);
188191
}
189192
return ProcessObject(self, converted);
190193
}

test_data/issue_11.gz

82.6 KB
Binary file not shown.

tests/issue_11.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python
2+
3+
import yajl
4+
import sys
5+
6+
for i, l in enumerate(sys.stdin):
7+
l = l.rstrip('\n').split('\t')
8+
d = yajl.dumps(tuple(l))
9+
print i,

0 commit comments

Comments
 (0)