[Python-checkins] CVS: python/dist/src/Modules cStringIO.c,2.28,2.29
Barry Warsaw
bwarsaw@users.sourceforge.net
Fri, 21 Sep 2001 21:37:02 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv28966/Modules
Modified Files:
cStringIO.c
Log Message:
I_getiter(): Function for the tp_iter slot of Itype so that
cStringIO's can participate in the iterator protocol.
Fill the Itype.tp_iter slot with I_getiter()
Index: cStringIO.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cStringIO.c,v
retrieving revision 2.28
retrieving revision 2.29
diff -C2 -d -r2.28 -r2.29
*** cStringIO.c 2001/02/09 23:44:22 2.28
--- cStringIO.c 2001/09/22 04:36:49 2.29
***************
*** 654,657 ****
--- 654,675 ----
}
+ static PyObject *
+ I_getiter(Iobject *self)
+ {
+ PyObject *myreadline = PyObject_GetAttrString((PyObject*)self,
+ "readline");
+ PyObject *emptystring = PyString_FromString("");
+ PyObject *iter = NULL;
+ if (!myreadline || !emptystring)
+ goto finally;
+
+ iter = PyCallIter_New(myreadline, emptystring);
+ finally:
+ Py_XDECREF(myreadline);
+ Py_XDECREF(emptystring);
+ return iter;
+ }
+
+
static char Itype__doc__[] =
"Simple type for treating strings as input file streams"
***************
*** 660,684 ****
static PyTypeObject Itype = {
PyObject_HEAD_INIT(NULL)
! 0, /*ob_size*/
! "StringI", /*tp_name*/
! sizeof(Iobject), /*tp_basicsize*/
! 0, /*tp_itemsize*/
/* methods */
! (destructor)I_dealloc, /*tp_dealloc*/
! (printfunc)0, /*tp_print*/
! (getattrfunc)I_getattr, /*tp_getattr*/
! (setattrfunc)0, /*tp_setattr*/
! (cmpfunc)0, /*tp_compare*/
! (reprfunc)0, /*tp_repr*/
! 0, /*tp_as_number*/
! 0, /*tp_as_sequence*/
! 0, /*tp_as_mapping*/
! (hashfunc)0, /*tp_hash*/
! (ternaryfunc)0, /*tp_call*/
! (reprfunc)0, /*tp_str*/
!
! /* Space for future expansion */
! 0L,0L,0L,0L,
! Itype__doc__ /* Documentation string */
};
--- 678,709 ----
static PyTypeObject Itype = {
PyObject_HEAD_INIT(NULL)
! 0, /*ob_size*/
! "StringI", /*tp_name*/
! sizeof(Iobject), /*tp_basicsize*/
! 0, /*tp_itemsize*/
/* methods */
! (destructor)I_dealloc, /*tp_dealloc*/
! (printfunc)0, /*tp_print*/
! (getattrfunc)I_getattr, /*tp_getattr*/
! (setattrfunc)0, /*tp_setattr*/
! (cmpfunc)0, /*tp_compare*/
! (reprfunc)0, /*tp_repr*/
! 0, /*tp_as_number*/
! 0, /*tp_as_sequence*/
! 0, /*tp_as_mapping*/
! (hashfunc)0, /*tp_hash*/
! (ternaryfunc)0, /*tp_call*/
! (reprfunc)0, /*tp_str*/
! 0, /* tp_getattro */
! 0, /* tp_setattro */
! 0, /* tp_as_buffer */
! Py_TPFLAGS_DEFAULT, /* tp_flags */
! Itype__doc__, /* tp_doc */
! 0, /* tp_traverse */
! 0, /* tp_clear */
! 0, /* tp_richcompare */
! 0, /* tp_weaklistoffset */
! (getiterfunc)I_getiter, /* tp_iter */
! 0, /* tp_iternext */
};