summaryrefslogtreecommitdiffstats
path: root/Modules/cStringIO.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-04-12 22:04:01 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-04-12 22:04:01 (GMT)
commit127b2ef2d568a929d08f07219a45283cb546ab00 (patch)
tree635ef6280ccd134e8d6bc22a777fcb47f1b2a6ae /Modules/cStringIO.c
parent394b54d01a42fe235b3e6ec55f0ce38fe1a03f50 (diff)
downloadcpython-127b2ef2d568a929d08f07219a45283cb546ab00.zip
cpython-127b2ef2d568a929d08f07219a45283cb546ab00.tar.gz
cpython-127b2ef2d568a929d08f07219a45283cb546ab00.tar.bz2
raise TypeError when bad argument passed to cStringIO.StringIO
Diffstat (limited to 'Modules/cStringIO.c')
-rw-r--r--Modules/cStringIO.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index 6a5efd6..e816178 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -578,9 +578,14 @@ newIobject(PyObject *s) {
Iobject *self;
char *buf;
int size;
-
- UNLESS(buf=PyString_AsString(s)) return NULL;
- UNLESS(-1 != (size=PyString_Size(s))) return NULL;
+
+ if (!PyString_Check(s)) {
+ PyErr_Format(PyExc_TypeError, "expected string, %.200s found",
+ s->ob_type->tp_name);
+ return NULL;
+ }
+ buf = PyString_AS_STRING(s);
+ size = PyString_GET_SIZE(s);
UNLESS(self = PyObject_NEW(Iobject, &Itype)) return NULL;
Py_INCREF(s);
self->buf=buf;
@@ -603,7 +608,8 @@ static PyObject *
IO_StringIO(PyObject *self, PyObject *args) {
PyObject *s=0;
- UNLESS(PyArg_ParseTuple(args, "|O:StringIO", &s)) return NULL;
+ if (!PyArg_ParseTuple(args, "|O:StringIO", &s))
+ return NULL;
if(s) return newIobject(s);
return newOobject(128);
}