standard type hierarchy in :ref:`types`.
- .. function:: str([object[, encoding[, errors]]])
+.. _func-str:
+ .. function:: str(object='')
+ str(object[, encoding[, errors]])
Return a string version of an object, using one of the following modes:
PyDoc_STRVAR(length_hint_doc,
"Private method returning an estimate of len(list(it)).");
-
+static PyObject *
+rangeiter_reduce(rangeiterobject *r)
+{
+ PyObject *start=NULL, *stop=NULL, *step=NULL;
+ PyObject *range;
++
+ /* create a range object for pickling */
+ start = PyLong_FromLong(r->start);
+ if (start == NULL)
+ goto err;
+ stop = PyLong_FromLong(r->start + r->len * r->step);
+ if (stop == NULL)
+ goto err;
+ step = PyLong_FromLong(r->step);
+ if (step == NULL)
+ goto err;
+ range = (PyObject*)make_range_object(&PyRange_Type,
+ start, stop, step);
+ if (range == NULL)
+ goto err;
+ /* return the result */
+ return Py_BuildValue("N(N)i", _PyObject_GetBuiltin("iter"), range, r->index);
+err:
+ Py_XDECREF(start);
+ Py_XDECREF(stop);
+ Py_XDECREF(step);
+ return NULL;
+}
+
+static PyObject *
+rangeiter_setstate(rangeiterobject *r, PyObject *state)
+{
+ long index = PyLong_AsLong(state);
+ if (index == -1 && PyErr_Occurred())
+ return NULL;
+ if (index < 0 || index >= r->len) {
+ PyErr_SetString(PyExc_ValueError, "index out of range");
+ return NULL;
+ }
+ r->index = index;
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
+PyDoc_STRVAR(setstate_doc, "Set state information for unpickling.");
+
static PyMethodDef rangeiter_methods[] = {
{"__length_hint__", (PyCFunction)rangeiter_len, METH_NOARGS,
length_hint_doc},