summaryrefslogtreecommitdiffstats
path: root/Objects/enumobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-09-24 21:23:05 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-09-24 21:23:05 (GMT)
commit6b27cda64386195cd07dfb686e9486f1c4bc3159 (patch)
tree277a5c96e9683c63b573b508f8c4bd2d1374aed8 /Objects/enumobject.c
parent9ceebd544516908e67c0f0d92c7a5f484e12beeb (diff)
downloadcpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.zip
cpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.tar.gz
cpython-6b27cda64386195cd07dfb686e9486f1c4bc3159.tar.bz2
Convert iterator __len__() methods to a private API.
Diffstat (limited to 'Objects/enumobject.c')
-rw-r--r--Objects/enumobject.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index aac88db..f74acdc 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -239,23 +239,25 @@ PyDoc_STRVAR(reversed_doc,
"\n"
"Return a reverse iterator");
-static int
+static PyObject *
reversed_len(reversedobject *ro)
{
int position, seqsize;
if (ro->seq == NULL)
- return 0;
+ return PyInt_FromLong(0);
seqsize = PySequence_Size(ro->seq);
if (seqsize == -1)
- return -1;
+ return NULL;
position = ro->index + 1;
- return (seqsize < position) ? 0 : position;
+ return PyInt_FromLong((seqsize < position) ? 0 : position);
}
-static PySequenceMethods reversed_as_sequence = {
- (inquiry)reversed_len, /* sq_length */
- 0, /* sq_concat */
+PyDoc_STRVAR(length_cue_doc, "Private method returning an estimate of len(list(it)).");
+
+static PyMethodDef reversediter_methods[] = {
+ {"_length_cue", (PyCFunction)reversed_len, METH_NOARGS, length_cue_doc},
+ {NULL, NULL} /* sentinel */
};
PyTypeObject PyReversed_Type = {
@@ -272,7 +274,7 @@ PyTypeObject PyReversed_Type = {
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
- &reversed_as_sequence, /* tp_as_sequence */
+ 0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
@@ -289,7 +291,7 @@ PyTypeObject PyReversed_Type = {
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)reversed_next, /* tp_iternext */
- 0, /* tp_methods */
+ reversediter_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */