diff options
| author | Raymond Hettinger <python@rcn.com> | 2009-11-30 19:44:40 (GMT) |
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2009-11-30 19:44:40 (GMT) |
| commit | e09f45a2e35e741e627f0ef49e94b84a28a4e72a (patch) | |
| tree | 224550aea5ac0aeacda9af044d2b04f1c08bdcb2 /Modules/itertoolsmodule.c | |
| parent | d46430bd8147da24d1e17b5f13064e70acb8ee01 (diff) | |
| download | cpython-e09f45a2e35e741e627f0ef49e94b84a28a4e72a.zip cpython-e09f45a2e35e741e627f0ef49e94b84a28a4e72a.tar.gz cpython-e09f45a2e35e741e627f0ef49e94b84a28a4e72a.tar.bz2 | |
Issue 7410: deepcopy of itertools.count resets the count
Diffstat (limited to 'Modules/itertoolsmodule.c')
| -rw-r--r-- | Modules/itertoolsmodule.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 1a0d44d..6b5c249 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -3375,6 +3375,21 @@ count_repr(countobject *lz) return result; } +static PyObject * +count_reduce(countobject *lz) +{ + if (lz->cnt == PY_SSIZE_T_MAX) + return Py_BuildValue("O(O)", Py_TYPE(lz), lz->long_cnt); + 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}, +}; + PyDoc_STRVAR(count_doc, "count(start=0, step=1]) --> count object\n\ \n\ @@ -3416,7 +3431,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 */ |
