summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-03-06 12:00:45 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-03-06 12:00:45 (GMT)
commitd55162517da38138fed130607b311ed4cc62ec77 (patch)
tree71604a96a8a112d4636da05f16e990704db51dd2 /Modules/itertoolsmodule.c
parenta01a144aab05b18b7f4d0e84d04b36b1677338ff (diff)
downloadcpython-d55162517da38138fed130607b311ed4cc62ec77.zip
cpython-d55162517da38138fed130607b311ed4cc62ec77.tar.gz
cpython-d55162517da38138fed130607b311ed4cc62ec77.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 cac02ad..11ce5ea 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -3460,6 +3460,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);