[Python-checkins] python/dist/src/Objects typeobject.c,2.237,2.238
jhylton@users.sourceforge.net
jhylton@users.sourceforge.net
Fri, 27 Jun 2003 09:46:47 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv15299
Modified Files:
typeobject.c
Log Message:
Check return type of __nonzero__() method.
The language reference says you must return an int or a bool. This
fix limits the scope of SF bug 759227 (infinite recursion) to
subclasses of int.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.237
retrieving revision 2.238
diff -C2 -d -r2.237 -r2.238
*** typeobject.c 13 Jun 2003 20:54:40 -0000 2.237
--- typeobject.c 27 Jun 2003 16:46:45 -0000 2.238
***************
*** 4197,4201 ****
Py_DECREF(args);
if (temp != NULL) {
! result = PyObject_IsTrue(temp);
Py_DECREF(temp);
}
--- 4197,4213 ----
Py_DECREF(args);
if (temp != NULL) {
! if (PyInt_Check(temp)) {
! /* XXX need to guard against recursion here */
! result = PyObject_IsTrue(temp);
! }
! else if (PyBool_Check(temp))
! result = PyObject_IsTrue(temp);
! else {
! PyErr_Format(PyExc_TypeError,
! "__nonzero__ should return "
! "bool or int, returned %s",
! temp->ob_type->tp_name);
! result = NULL;
! }
Py_DECREF(temp);
}