Skip to content
Browse files

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
  • Loading branch information...
1 parent dff262d commit 836ea060ac8075ffdc6754c3ef9d643db45ed36b @rtyler committed Apr 6, 2010
Showing with 13 additions and 1 deletion.
  1. +4 −1 encoder.c
  2. BIN test_data/issue_11.gz
  3. +9 −0 tests/issue_11.py
View
5 encoder.c
@@ -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);
}
View
BIN test_data/issue_11.gz
Binary file not shown.
View
9 tests/issue_11.py
@@ -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,

0 comments on commit 836ea06

Please sign in to comment.
Something went wrong with that request. Please try again.