[Python-checkins] python/dist/src/Objects enumobject.c,1.2,1.3
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Tue, 16 Jul 2002 14:02:44 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv15850
Modified Files:
enumobject.c
Log Message:
Remove the next() method -- one is supplied automatically by
PyType_Ready() because the tp_iternext slot is set (fortunately,
because using the tp_iternext implementation for the the next()
implementation is buggy). Also changed the allocation order in
enum_next() so that the underlying iterator is only moved ahead when
we have successfully allocated the result tuple and index.
Index: enumobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/enumobject.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** enumobject.c 13 Jun 2002 20:32:59 -0000 1.2
--- enumobject.c 16 Jul 2002 21:02:42 -0000 1.3
***************
*** 55,77 ****
PyObject *result;
PyObject *next_index;
! PyObject *next_item = PyIter_Next(en->en_sit);
! if (next_item == NULL)
return NULL;
! result = PyTuple_New(2);
! if (result == NULL) {
! Py_DECREF(next_item);
return NULL;
}
! next_index = PyInt_FromLong(en->en_index++);
! if (next_index == NULL) {
! Py_DECREF(next_item);
Py_DECREF(result);
return NULL;
}
! PyTuple_SET_ITEM(result, 0, next_index);
PyTuple_SET_ITEM(result, 1, next_item);
return result;
--- 55,78 ----
PyObject *result;
PyObject *next_index;
+ PyObject *next_item;
! result = PyTuple_New(2);
! if (result == NULL)
return NULL;
! next_index = PyInt_FromLong(en->en_index);
! if (next_index == NULL) {
! Py_DECREF(result);
return NULL;
}
+ PyTuple_SET_ITEM(result, 0, next_index);
! next_item = PyIter_Next(en->en_sit);
! if (next_item == NULL) {
Py_DECREF(result);
return NULL;
}
! en->en_index++;
PyTuple_SET_ITEM(result, 1, next_item);
return result;
***************
*** 85,94 ****
}
- static PyMethodDef enum_methods[] = {
- {"next", (PyCFunction)enum_next, METH_NOARGS,
- "return the next (index, value) pair, or raise StopIteration"},
- {NULL, NULL} /* sentinel */
- };
-
PyDoc_STRVAR(enum_doc,
"enumerate(iterable) -> create an enumerating-iterator");
--- 86,89 ----
***************
*** 125,129 ****
(getiterfunc)enum_getiter, /* tp_iter */
(iternextfunc)enum_next, /* tp_iternext */
! enum_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
--- 120,124 ----
(getiterfunc)enum_getiter, /* tp_iter */
(iternextfunc)enum_next, /* tp_iternext */
! 0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */