summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-11-30 21:55:17 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-11-30 21:55:17 (GMT)
commit6c8ee7a33309b79d9f2737616501835349cfcdaf (patch)
tree934ecb458f43c5b729cd95d28d688210244c672a /Modules/itertoolsmodule.c
parent9aeb9df7dae60b570e3a2f64a58fd605ce143d9c (diff)
downloadcpython-6c8ee7a33309b79d9f2737616501835349cfcdaf.zip
cpython-6c8ee7a33309b79d9f2737616501835349cfcdaf.tar.gz
cpython-6c8ee7a33309b79d9f2737616501835349cfcdaf.tar.bz2
Issue #7410: deepcopy of itertools.count was resetting the count.
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 3264d1f..74396b6 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -3049,6 +3049,22 @@ count_repr(countobject *lz)
lz->long_cnt, lz->long_step);
}
+static PyObject *
+count_reduce(countobject *lz)
+{
+ if (lz->cnt == PY_SSIZE_T_MAX)
+ return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->long_cnt, lz->long_step);
+ return Py_BuildValue("O(n)", Py_TYPE(lz), lz->cnt);
+}
+
+PyDoc_STRVAR(count_reduce_doc, "Return state information for pickling.");
+
+static PyMethodDef count_methods[] = {
+ {"__reduce__", (PyCFunction)count_reduce, METH_NOARGS,
+ count_reduce_doc},
+ {NULL, NULL} /* sentinel */
+};
+
PyDoc_STRVAR(count_doc,
"count(start=0, step=1]) --> count object\n\
\n\
@@ -3090,7 +3106,7 @@ static PyTypeObject count_type = {
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)count_next, /* tp_iternext */
- 0, /* tp_methods */
+ count_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */