[Python-checkins] python/dist/src/Modules cStringIO.c,2.39,2.40
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Thu, 24 Apr 2003 08:50:15 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv14170/Modules
Modified Files:
cStringIO.c
Log Message:
SF patch 695710: fix bug 678519: cStringIO self iterator
(requested by GvR. patch contributed by Michael Stone)
Index: cStringIO.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cStringIO.c,v
retrieving revision 2.39
retrieving revision 2.40
diff -C2 -d -r2.39 -r2.40
*** cStringIO.c 3 Jan 2003 08:24:58 -0000 2.39
--- cStringIO.c 24 Apr 2003 15:50:11 -0000 2.40
***************
*** 3,6 ****
--- 3,7 ----
#include "import.h"
#include "cStringIO.h"
+ #include "structmember.h"
PyDoc_STRVAR(cStringIO_module_documentation,
***************
*** 190,194 ****
char *output;
! UNLESS (PyArg_ParseTuple(args, "|i:readline", &m)) return NULL;
if( (n=IO_creadline((PyObject*)self,&output)) < 0) return NULL;
--- 191,196 ----
char *output;
! if (args)
! UNLESS (PyArg_ParseTuple(args, "|i:readline", &m)) return NULL;
if( (n=IO_creadline((PyObject*)self,&output)) < 0) return NULL;
***************
*** 277,280 ****
--- 279,297 ----
}
+ static PyObject *
+ IO_iternext(Iobject *self)
+ {
+ PyObject *next;
+ next = IO_readline((IOobject *)self, NULL);
+ if (!next)
+ return NULL;
+ if (!PyString_GET_SIZE(next)) {
+ Py_DECREF(next);
+ PyErr_SetNone(PyExc_StopIteration);
+ return NULL;
+ }
+ return next;
+ }
+
***************
*** 436,439 ****
--- 453,462 ----
};
+ static PyMemberDef O_memberlist[] = {
+ {"softspace", T_INT, offsetof(Oobject, softspace), 0,
+ "flag indicating that a space needs to be printed; used by print"},
+ {NULL} /* Sentinel */
+ };
+
static void
O_dealloc(Oobject *self) {
***************
*** 443,493 ****
}
- static PyObject *
- O_getattr(Oobject *self, char *name) {
- if (strcmp(name, "softspace") == 0) {
- return PyInt_FromLong(self->softspace);
- }
- return Py_FindMethod(O_methods, (PyObject *)self, name);
- }
-
- static int
- O_setattr(Oobject *self, char *name, PyObject *value) {
- long x;
- if (strcmp(name, "softspace") != 0) {
- PyErr_SetString(PyExc_AttributeError, name);
- return -1;
- }
- x = PyInt_AsLong(value);
- if (x < 0 && PyErr_Occurred())
- return -1;
- self->softspace = x;
- return 0;
- }
-
PyDoc_STRVAR(Otype__doc__, "Simple type for output to strings.");
static PyTypeObject Otype = {
PyObject_HEAD_INIT(NULL)
! 0, /*ob_size*/
! "cStringIO.StringO", /*tp_name*/
sizeof(Oobject), /*tp_basicsize*/
! 0, /*tp_itemsize*/
/* methods */
(destructor)O_dealloc, /*tp_dealloc*/
! (printfunc)0, /*tp_print*/
! (getattrfunc)O_getattr, /*tp_getattr*/
! (setattrfunc)O_setattr, /*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,
! Otype__doc__ /* Documentation string */
};
--- 466,503 ----
}
PyDoc_STRVAR(Otype__doc__, "Simple type for output to strings.");
static PyTypeObject Otype = {
PyObject_HEAD_INIT(NULL)
! 0, /*ob_size*/
! "cStringIO.StringO", /*tp_name*/
sizeof(Oobject), /*tp_basicsize*/
! 0, /*tp_itemsize*/
/* methods */
(destructor)O_dealloc, /*tp_dealloc*/
! (printfunc)0, /*tp_print*/
! 0, /*tp_getattr */
! 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*/
! Otype__doc__, /*tp_doc */
! 0, /*tp_traverse */
! 0, /*tp_clear */
! 0, /*tp_richcompare */
! 0, /*tp_weaklistoffset */
! PyObject_SelfIter, /*tp_iter */
! (iternextfunc)IO_iternext, /*tp_iternext */
! O_methods, /*tp_methods */
! O_memberlist /*tp_members */
};
***************
*** 571,596 ****
}
- static PyObject *
- I_getattr(Iobject *self, char *name) {
- return Py_FindMethod(I_methods, (PyObject *)self, name);
- }
-
- 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;
- }
-
PyDoc_STRVAR(Itype__doc__,
--- 581,584 ----
***************
*** 606,610 ****
(destructor)I_dealloc, /*tp_dealloc*/
(printfunc)0, /*tp_print*/
! (getattrfunc)I_getattr, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
(cmpfunc)0, /*tp_compare*/
--- 594,598 ----
(destructor)I_dealloc, /*tp_dealloc*/
(printfunc)0, /*tp_print*/
! 0, /* tp_getattr */
(setattrfunc)0, /*tp_setattr*/
(cmpfunc)0, /*tp_compare*/
***************
*** 625,630 ****
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! (getiterfunc)I_getiter, /* tp_iter */
! 0, /* tp_iternext */
};
--- 613,619 ----
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
! PyObject_SelfIter, /* tp_iter */
! (iternextfunc)IO_iternext, /* tp_iternext */
! I_methods /* tp_methods */
};
***************
*** 708,711 ****
--- 697,702 ----
Itype.ob_type=&PyType_Type;
Otype.ob_type=&PyType_Type;
+ if (PyType_Ready(&Otype) < 0) return;
+ if (PyType_Ready(&Itype) < 0) return;
PyDict_SetItemString(d,"cStringIO_CAPI",
v = PyCObject_FromVoidPtr(&CAPI,NULL));