diff Modules/cStringIO.c @ 12385:627226df9f01 legacy-trunk

raise TypeError when bad argument passed to cStringIO.StringIO
author Jeremy Hylton <jeremy@alum.mit.edu>
date Wed, 12 Apr 2000 22:04:01 +0000
parents dc65c5f6ad7c
children 1c7c2dd1beb1
line wrap: on
line diff
--- a/Modules/cStringIO.c	Wed Apr 12 21:19:47 2000 +0000
+++ b/Modules/cStringIO.c	Wed Apr 12 22:04:01 2000 +0000
@@ -578,9 +578,14 @@
   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 @@
 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);
 }