diff options
author | Raymond Hettinger <python@rcn.com> | 2008-12-02 21:33:45 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-12-02 21:33:45 (GMT) |
commit | f5b64116cc85d82df021aa30bbd63f9823b0efeb (patch) | |
tree | 871cdc4c5885d048a1500509ec60552c5725cf9e /Objects | |
parent | 048690410f6ad62327e6cde573d6e8b702ea708b (diff) | |
download | cpython-f5b64116cc85d82df021aa30bbd63f9823b0efeb.zip cpython-f5b64116cc85d82df021aa30bbd63f9823b0efeb.tar.gz cpython-f5b64116cc85d82df021aa30bbd63f9823b0efeb.tar.bz2 |
Issue 3689: list_reverseiterator should support __length_hint__ instead of __len__.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/listobject.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index d5acec1..40077a1 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2736,11 +2736,11 @@ static PyObject *list_reversed(PyListObject *, PyObject *); static void listreviter_dealloc(listreviterobject *); static int listreviter_traverse(listreviterobject *, visitproc, void *); static PyObject *listreviter_next(listreviterobject *); -static Py_ssize_t listreviter_len(listreviterobject *); +static PyObject *listreviter_len(listreviterobject *); -static PySequenceMethods listreviter_as_sequence = { - (lenfunc)listreviter_len, /* sq_length */ - 0, /* sq_concat */ +static PyMethodDef listreviter_methods[] = { + {"__length_hint__", (PyCFunction)listreviter_len, METH_NOARGS, length_hint_doc}, + {NULL, NULL} /* sentinel */ }; PyTypeObject PyListRevIter_Type = { @@ -2756,7 +2756,7 @@ PyTypeObject PyListRevIter_Type = { 0, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ - &listreviter_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -2772,6 +2772,7 @@ PyTypeObject PyListRevIter_Type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)listreviter_next, /* tp_iternext */ + listreviter_methods, /* tp_methods */ 0, }; @@ -2827,12 +2828,12 @@ listreviter_next(listreviterobject *it) return NULL; } -static Py_ssize_t +static PyObject * listreviter_len(listreviterobject *it) { Py_ssize_t len = it->it_index + 1; if (it->it_seq == NULL || PyList_GET_SIZE(it->it_seq) < len) - return 0; - return len; + len = 0; + return PyLong_FromSsize_t(len); } |