summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-03-17 08:24:35 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-03-17 08:24:35 (GMT)
commit01538269643175877f516d09f429a2ae28136da6 (patch)
tree3b6bdbf815394deaf883b1409de3520de88959b4 /Objects
parent08801db123077407ae7ec7af2fe2d65a24a46063 (diff)
downloadcpython-01538269643175877f516d09f429a2ae28136da6.zip
cpython-01538269643175877f516d09f429a2ae28136da6.tar.gz
cpython-01538269643175877f516d09f429a2ae28136da6.tar.bz2
Created PyObject_GenericGetIter().
Factors out the common case of returning self.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c9
-rw-r--r--Objects/enumobject.c9
-rw-r--r--Objects/iterobject.c11
-rw-r--r--Objects/listobject.c10
-rw-r--r--Objects/object.c7
-rw-r--r--Objects/rangeobject.c9
-rw-r--r--Objects/tupleobject.c10
7 files changed, 14 insertions, 51 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 633f2ce..52e516f 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2013,13 +2013,6 @@ dictiter_dealloc(dictiterobject *di)
PyObject_Del(di);
}
-static PyObject *
-dictiter_getiter(PyObject *it)
-{
- Py_INCREF(it);
- return it;
-}
-
static PyObject *dictiter_iternext(dictiterobject *di)
{
PyObject *key, *value;
@@ -2069,7 +2062,7 @@ PyTypeObject PyDictIter_Type = {
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
- (getiterfunc)dictiter_getiter, /* tp_iter */
+ PyObject_GenericGetIter, /* tp_iter */
(iternextfunc)dictiter_iternext, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index f69a002..cd6ca67 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -78,13 +78,6 @@ enum_next(enumobject *en)
return result;
}
-static PyObject *
-enum_getiter(PyObject *en)
-{
- Py_INCREF(en);
- return en;
-}
-
PyDoc_STRVAR(enum_doc,
"enumerate(iterable) -> create an enumerating-iterator");
@@ -117,7 +110,7 @@ PyTypeObject PyEnum_Type = {
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
- (getiterfunc)enum_getiter, /* tp_iter */
+ PyObject_GenericGetIter, /* tp_iter */
(iternextfunc)enum_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
diff --git a/Objects/iterobject.c b/Objects/iterobject.c
index 2e1caae..7970fa6 100644
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -44,13 +44,6 @@ iter_traverse(seqiterobject *it, visitproc visit, void *arg)
}
static PyObject *
-iter_getiter(PyObject *it)
-{
- Py_INCREF(it);
- return it;
-}
-
-static PyObject *
iter_iternext(PyObject *iterator)
{
seqiterobject *it;
@@ -106,7 +99,7 @@ PyTypeObject PySeqIter_Type = {
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
- (getiterfunc)iter_getiter, /* tp_iter */
+ PyObject_GenericGetIter, /* tp_iter */
(iternextfunc)iter_iternext, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
@@ -223,7 +216,7 @@ PyTypeObject PyCallIter_Type = {
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
- (getiterfunc)iter_getiter, /* tp_iter */
+ PyObject_GenericGetIter, /* tp_iter */
(iternextfunc)calliter_iternext, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 79403cc..75ad235 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2398,14 +2398,6 @@ listiter_traverse(listiterobject *it, visitproc visit, void *arg)
return visit((PyObject *)it->it_seq, arg);
}
-
-static PyObject *
-listiter_getiter(PyObject *it)
-{
- Py_INCREF(it);
- return it;
-}
-
static PyObject *
listiter_next(listiterobject *it)
{
@@ -2458,7 +2450,7 @@ PyTypeObject PyListIter_Type = {
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
- (getiterfunc)listiter_getiter, /* tp_iter */
+ PyObject_GenericGetIter, /* tp_iter */
(iternextfunc)listiter_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
diff --git a/Objects/object.c b/Objects/object.c
index bf8056c..eb4d8f7 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1301,6 +1301,13 @@ _PyObject_GetDictPtr(PyObject *obj)
/* Generic GetAttr functions - put these in your tp_[gs]etattro slot */
PyObject *
+PyObject_GenericGetIter(PyObject *obj)
+{
+ Py_INCREF(obj);
+ return obj;
+}
+
+PyObject *
PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
{
PyTypeObject *tp = obj->ob_type;
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index 9c7b74e..5dbbf13 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -246,13 +246,6 @@ range_iter(PyObject *seq)
}
static PyObject *
-rangeiter_getiter(PyObject *it)
-{
- Py_INCREF(it);
- return it;
-}
-
-static PyObject *
rangeiter_next(rangeiterobject *r)
{
if (r->index < r->len)
@@ -288,7 +281,7 @@ static PyTypeObject Pyrangeiter_Type = {
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
- (getiterfunc)rangeiter_getiter, /* tp_iter */
+ PyObject_GenericGetIter, /* tp_iter */
(iternextfunc)rangeiter_next, /* tp_iternext */
0, /* tp_methods */
};
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index d6d0aaa..ede18e0 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -779,14 +779,6 @@ tupleiter_traverse(tupleiterobject *it, visitproc visit, void *arg)
return visit((PyObject *)it->it_seq, arg);
}
-
-static PyObject *
-tupleiter_getiter(PyObject *it)
-{
- Py_INCREF(it);
- return it;
-}
-
static PyObject *
tupleiter_next(tupleiterobject *it)
{
@@ -839,6 +831,6 @@ PyTypeObject PyTupleIter_Type = {
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
- (getiterfunc)tupleiter_getiter, /* tp_iter */
+ PyObject_GenericGetIter, /* tp_iter */
(iternextfunc)tupleiter_next, /* tp_iternext */
};