Fix a stupid little bug: len() of an unsized returns -1 and leaves an

exception waiting to happen next...
This commit is contained in:
Guido van Rossum 1998-06-29 22:26:50 +00:00
parent 16926bd75e
commit 8ea9f4d10a
1 changed files with 5 additions and 1 deletions

View File

@ -1098,10 +1098,14 @@ builtin_len(self, args)
PyObject *args; PyObject *args;
{ {
PyObject *v; PyObject *v;
long res;
if (!PyArg_ParseTuple(args, "O:len", &v)) if (!PyArg_ParseTuple(args, "O:len", &v))
return NULL; return NULL;
return PyInt_FromLong((long)PyObject_Length(v)); res = PyObject_Length(v);
if (res < 0 && PyErr_Occurred())
return NULL;
return PyInt_FromLong(res);
} }
static char len_doc[] = static char len_doc[] =