[Python-checkins] python/dist/src/Modules collectionsmodule.c, 1.39, 1.40 itertoolsmodule.c, 1.41, 1.42
rhettinger@users.sourceforge.net
rhettinger at users.sourceforge.net
Sat Sep 24 23:23:08 CEST 2005
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7585/Modules
Modified Files:
collectionsmodule.c itertoolsmodule.c
Log Message:
Convert iterator __len__() methods to a private API.
Index: collectionsmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/collectionsmodule.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- collectionsmodule.c 26 Aug 2005 06:42:30 -0000 1.39
+++ collectionsmodule.c 24 Sep 2005 21:23:05 -0000 1.40
@@ -935,15 +935,17 @@
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 @@
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 @@
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)dequeiter_next, /* tp_iternext */
+ dequeiter_methods, /* tp_methods */
0,
};
@@ -1042,7 +1045,7 @@
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 @@
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)dequereviter_next, /* tp_iternext */
+ dequeiter_methods, /* tp_methods */
0,
};
Index: itertoolsmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/itertoolsmodule.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- itertoolsmodule.c 26 Aug 2005 06:42:30 -0000 1.41
+++ itertoolsmodule.c 24 Sep 2005 21:23:05 -0000 1.42
@@ -2336,17 +2336,21 @@
return result;
}
-static int
+static PyObject *
repeat_len(repeatobject *ro)
{
- if (ro->cnt == -1)
+ if (ro->cnt == -1) {
PyErr_SetString(PyExc_TypeError, "len() of unsized object");
- return (int)(ro->cnt);
+ return NULL;
+ }
+ return PyInt_FromLong(ro->cnt);
}
-static PySequenceMethods repeat_as_sequence = {
- (inquiry)repeat_len, /* sq_length */
- 0, /* sq_concat */
+PyDoc_STRVAR(length_cue_doc, "Private method returning an estimate of len(list(it)).");
+
+static PyMethodDef repeat_methods[] = {
+ {"_length_cue", (PyCFunction)repeat_len, METH_NOARGS, length_cue_doc},
+ {NULL, NULL} /* sentinel */
};
PyDoc_STRVAR(repeat_doc,
@@ -2368,7 +2372,7 @@
0, /* tp_compare */
(reprfunc)repeat_repr, /* tp_repr */
0, /* tp_as_number */
- &repeat_as_sequence, /* tp_as_sequence */
+ 0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
@@ -2385,7 +2389,7 @@
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
(iternextfunc)repeat_next, /* tp_iternext */
- 0, /* tp_methods */
+ repeat_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
More information about the Python-checkins
mailing list