summaryrefslogtreecommitdiffstats
path: root/Objects/setobject.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/setobject.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/setobject.c')
-rw-r--r--Objects/setobject.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index c4cd562..29a9184 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -749,17 +749,20 @@ setiter_dealloc(setiterobject *si)
PyObject_Del(si);
}
-static int
+static PyObject *
setiter_len(setiterobject *si)
{
+ int len = 0;
if (si->si_set != NULL && si->si_used == si->si_set->used)
- return si->len;
- return 0;
+ len = si->len;
+ return PyInt_FromLong(len);
}
-static PySequenceMethods setiter_as_sequence = {
- (inquiry)setiter_len, /* sq_length */
- 0, /* sq_concat */
+PyDoc_STRVAR(length_cue_doc, "Private method returning an estimate of len(list(it)).");
+
+static PyMethodDef setiter_methods[] = {
+ {"_length_cue", (PyCFunction)setiter_len, METH_NOARGS, length_cue_doc},
+ {NULL, NULL} /* sentinel */
};
static PyObject *setiter_iternext(setiterobject *si)
@@ -814,7 +817,7 @@ static PyTypeObject PySetIter_Type = {
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
- &setiter_as_sequence, /* tp_as_sequence */
+ 0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
@@ -830,6 +833,8 @@ static PyTypeObject PySetIter_Type = {
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)setiter_iternext, /* tp_iternext */
+ setiter_methods, /* tp_methods */
+ 0,
};
static int