Commit 3d783859 authored by Mark Dickinson's avatar Mark Dickinson

Issue #16060: Fix a double DECREF in int() implementation. Thanks Serhiy Storchaka.

parent 0beb4d28
......@@ -12,6 +12,9 @@ Core and Builtins
- Issue #16046: Fix loading sourceless legacy .pyo files.
- Issue #16060: Fix refcounting bug when __trunc__ returns an object
whose __int__ gives a non-integer. Patch by Serhiy Storchaka.
Library
-------
......
......@@ -1228,11 +1228,10 @@ convert_integral_to_int(PyObject *integral, const char *error_format)
nb = Py_TYPE(integral)->tp_as_number;
if (nb->nb_int) {
PyObject *as_int = nb->nb_int(integral);
Py_DECREF(integral);
if (!as_int)
return NULL;
if (PyLong_Check(as_int))
if (!as_int || PyLong_Check(as_int)) {
Py_DECREF(integral);
return as_int;
}
Py_DECREF(as_int);
}
PyErr_Format(PyExc_TypeError, error_format, Py_TYPE(integral)->tp_name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment