mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
Issue #14288: Serialization support for builtin iterators.
This commit is contained in:
parent
283b96b6bd
commit
31668b8f7a
28 changed files with 2190 additions and 104 deletions
|
@ -14382,9 +14382,43 @@ unicodeiter_len(unicodeiterobject *it)
|
|||
|
||||
PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");
|
||||
|
||||
static PyObject *
|
||||
unicodeiter_reduce(unicodeiterobject *it)
|
||||
{
|
||||
if (it->it_seq != NULL) {
|
||||
return Py_BuildValue("N(O)n", _PyIter_GetBuiltin("iter"),
|
||||
it->it_seq, it->it_index);
|
||||
} else {
|
||||
PyObject *u = PyUnicode_FromUnicode(NULL, 0);
|
||||
if (u == NULL)
|
||||
return NULL;
|
||||
return Py_BuildValue("N(N)", _PyIter_GetBuiltin("iter"), u);
|
||||
}
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
|
||||
|
||||
static PyObject *
|
||||
unicodeiter_setstate(unicodeiterobject *it, PyObject *state)
|
||||
{
|
||||
Py_ssize_t index = PyLong_AsSsize_t(state);
|
||||
if (index == -1 && PyErr_Occurred())
|
||||
return NULL;
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
it->it_index = index;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(setstate_doc, "Set state information for unpickling.");
|
||||
|
||||
static PyMethodDef unicodeiter_methods[] = {
|
||||
{"__length_hint__", (PyCFunction)unicodeiter_len, METH_NOARGS,
|
||||
length_hint_doc},
|
||||
{"__reduce__", (PyCFunction)unicodeiter_reduce, METH_NOARGS,
|
||||
reduce_doc},
|
||||
{"__setstate__", (PyCFunction)unicodeiter_setstate, METH_O,
|
||||
setstate_doc},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue