diff options
author | Raymond Hettinger <python@rcn.com> | 2005-09-24 21:23:05 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-09-24 21:23:05 (GMT) |
commit | 6b27cda64386195cd07dfb686e9486f1c4bc3159 (patch) | |
tree | 277a5c96e9683c63b573b508f8c4bd2d1374aed8 /Objects/rangeobject.c | |
parent | 9ceebd544516908e67c0f0d92c7a5f484e12beeb (diff) | |
download | cpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.zip cpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.tar.gz cpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.tar.bz2 |
Convert iterator __len__() methods to a private API.
Diffstat (limited to 'Objects/rangeobject.c')
-rw-r--r-- | Objects/rangeobject.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 8b5650a..3cc5504 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -262,17 +262,18 @@ rangeiter_next(rangeiterobject *r) return NULL; } -static int +static PyObject * rangeiter_len(rangeiterobject *r) { - return r->len - r->index; + return PyInt_FromLong(r->len - r->index); } -static PySequenceMethods rangeiter_as_sequence = { - (inquiry)rangeiter_len, /* sq_length */ - 0, /* sq_concat */ -}; +PyDoc_STRVAR(length_cue_doc, "Private method returning an estimate of len(list(it))."); +static PyMethodDef rangeiter_methods[] = { + {"_length_cue", (PyCFunction)rangeiter_len, METH_NOARGS, length_cue_doc}, + {NULL, NULL} /* sentinel */ +}; static PyTypeObject Pyrangeiter_Type = { PyObject_HEAD_INIT(&PyType_Type) @@ -288,7 +289,7 @@ static PyTypeObject Pyrangeiter_Type = { 0, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ - &rangeiter_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -304,5 +305,6 @@ static PyTypeObject Pyrangeiter_Type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)rangeiter_next, /* tp_iternext */ - 0, /* tp_methods */ + rangeiter_methods, /* tp_methods */ + 0, }; |