summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-03-06 12:02:26 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-03-06 12:02:26 (GMT)
commit5608411a964f7fd5a35eda04b297e0d77de9958d (patch)
treeb7dd9121e58f5660b8684477ee78377b6dc986cc /Modules/itertoolsmodule.c
parentb6bfce6c0b4721700241b550e31ae3aeabcb6f41 (diff)
parentd55162517da38138fed130607b311ed4cc62ec77 (diff)
downloadcpython-5608411a964f7fd5a35eda04b297e0d77de9958d.zip
cpython-5608411a964f7fd5a35eda04b297e0d77de9958d.tar.gz
cpython-5608411a964f7fd5a35eda04b297e0d77de9958d.tar.bz2
Issue #25718: Fixed pickling and copying the accumulate() iterator with total is None.
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 57eb4ec..9fb9d74 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -3464,6 +3464,23 @@ accumulate_next(accumulateobject *lz)
static PyObject *
accumulate_reduce(accumulateobject *lz)
{
+ if (lz->total == Py_None) {
+ PyObject *it;
+
+ if (PyType_Ready(&chain_type) < 0)
+ return NULL;
+ if (PyType_Ready(&islice_type) < 0)
+ return NULL;
+ it = PyObject_CallFunction((PyObject *)&chain_type, "(O)O",
+ lz->total, lz->it);
+ if (it == NULL)
+ return NULL;
+ it = PyObject_CallFunction((PyObject *)Py_TYPE(lz), "NO",
+ it, lz->binop ? lz->binop : Py_None);
+ if (it == NULL)
+ return NULL;
+ return Py_BuildValue("O(NiO)", &islice_type, it, 1, Py_None);
+ }
return Py_BuildValue("O(OO)O", Py_TYPE(lz),
lz->it, lz->binop?lz->binop:Py_None,
lz->total?lz->total:Py_None);