summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 9349ef8..aee832a 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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 */
};