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 /Modules/collectionsmodule.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 'Modules/collectionsmodule.c')
-rw-r--r-- | Modules/collectionsmodule.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Modules/collectionsmodule.c b/Modules/collectionsmodule.c index ffe1a96..1a8258e 100644 --- a/Modules/collectionsmodule.c +++ b/Modules/collectionsmodule.c @@ -935,15 +935,17 @@ dequeiter_next(dequeiterobject *it) return item; } -static int +static PyObject * dequeiter_len(dequeiterobject *it) { - return it->counter; + return PyInt_FromLong(it->counter); } -static PySequenceMethods dequeiter_as_sequence = { - (inquiry)dequeiter_len, /* sq_length */ - 0, /* sq_concat */ +PyDoc_STRVAR(length_cue_doc, "Private method returning an estimate of len(list(it))."); + +static PyMethodDef dequeiter_methods[] = { + {"_length_cue", (PyCFunction)dequeiter_len, METH_NOARGS, length_cue_doc}, + {NULL, NULL} /* sentinel */ }; PyTypeObject dequeiter_type = { @@ -960,7 +962,7 @@ PyTypeObject dequeiter_type = { 0, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ - &dequeiter_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -976,6 +978,7 @@ PyTypeObject dequeiter_type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)dequeiter_next, /* tp_iternext */ + dequeiter_methods, /* tp_methods */ 0, }; @@ -1042,7 +1045,7 @@ PyTypeObject dequereviter_type = { 0, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ - &dequeiter_as_sequence, /* tp_as_sequence */ + 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -1058,6 +1061,7 @@ PyTypeObject dequereviter_type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)dequereviter_next, /* tp_iternext */ + dequeiter_methods, /* tp_methods */ 0, }; |