Issue 2582: Fix pickling of range objects.

This commit is contained in:
Alexandre Vassalotti 2008-06-10 04:03:04 +00:00
parent 1c9a2d96ec
commit 7505607ae7
2 changed files with 19 additions and 0 deletions

View file

@ -252,6 +252,14 @@ range_repr(rangeobject *r)
r->start, r->stop, r->step);
}
/* Pickling support */
static PyObject *
range_reduce(rangeobject *r, PyObject *args)
{
return Py_BuildValue("(O(OOO))", Py_TYPE(r),
r->start, r->stop, r->step);
}
static PySequenceMethods range_as_sequence = {
(lenfunc)range_length, /* sq_length */
0, /* sq_concat */
@ -269,6 +277,7 @@ PyDoc_STRVAR(reverse_doc,
static PyMethodDef range_methods[] = {
{"__reversed__", (PyCFunction)range_reverse, METH_NOARGS,
reverse_doc},
{"__reduce__", (PyCFunction)range_reduce, METH_VARARGS},
{NULL, NULL} /* sentinel */
};