diff Python/bltinmodule.c @ 8589:97dc6aa532e7 legacy-trunk

Fix a stupid little bug: len() of an unsized returns -1 and leaves an exception waiting to happen next...
author Guido van Rossum <guido@python.org>
date Mon, 29 Jun 1998 22:26:50 +0000
parents 221667f89064
children 30fbf18af29e
line wrap: on
line diff
--- a/Python/bltinmodule.c	Mon Jun 29 20:34:46 1998 +0000
+++ b/Python/bltinmodule.c	Mon Jun 29 22:26:50 1998 +0000
@@ -1098,10 +1098,14 @@
 	PyObject *args;
 {
 	PyObject *v;
+	long res;
 
 	if (!PyArg_ParseTuple(args, "O:len", &v))
 		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[] =