summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-10-30 20:58:42 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-10-30 20:58:42 (GMT)
commitf43ee81ef211d9c79f8bbaa3ab369d387c2dfeb6 (patch)
treec8b3b606b8b14db6d8e10d9ef76751703b58ae87 /Modules/_collectionsmodule.c
parent73b90a8d61898ccde2c083a6e51af6624ec52fc3 (diff)
downloadcpython-f43ee81ef211d9c79f8bbaa3ab369d387c2dfeb6.zip
cpython-f43ee81ef211d9c79f8bbaa3ab369d387c2dfeb6.tar.gz
cpython-f43ee81ef211d9c79f8bbaa3ab369d387c2dfeb6.tar.bz2
#4170: Fix segfault when pickling a defauldict object.
The 2.x dict.iteritems() returns an iterator, whereas the 3.0 dict.items() returns a "view", which is iterable, but not an iterator with its __next__ method. Patch by Hirokazu Yamamoto.
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 8e51420..d7a6042 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1155,6 +1155,7 @@ defdict_reduce(defdictobject *dd)
*/
PyObject *args;
PyObject *items;
+ PyObject *iter;
PyObject *result;
if (dd->default_factory == NULL || dd->default_factory == Py_None)
args = PyTuple_New(0);
@@ -1167,8 +1168,15 @@ defdict_reduce(defdictobject *dd)
Py_DECREF(args);
return NULL;
}
+ iter = PyObject_GetIter(items);
+ if (iter == NULL) {
+ Py_DECREF(items);
+ Py_DECREF(args);
+ return NULL;
+ }
result = PyTuple_Pack(5, Py_TYPE(dd), args,
- Py_None, Py_None, items);
+ Py_None, Py_None, iter);
+ Py_DECREF(iter);
Py_DECREF(items);
Py_DECREF(args);
return result;