mirror of
https://github.com/python/cpython.git
synced 2025-11-27 05:44:16 +00:00
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.
This commit is contained in:
parent
6ab8b40337
commit
090a3495b3
1 changed files with 13 additions and 1 deletions
|
|
@ -4196,7 +4196,19 @@ slot_nb_nonzero(PyObject *self)
|
||||||
PyObject *temp = PyObject_Call(func, args, NULL);
|
PyObject *temp = PyObject_Call(func, args, NULL);
|
||||||
Py_DECREF(args);
|
Py_DECREF(args);
|
||||||
if (temp != NULL) {
|
if (temp != NULL) {
|
||||||
|
if (PyInt_Check(temp)) {
|
||||||
|
/* XXX need to guard against recursion here */
|
||||||
result = PyObject_IsTrue(temp);
|
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);
|
Py_DECREF(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue