Issue #23571: In debug mode, _Py_CheckFunctionResult() now calls
Py_FatalError() instead of using an assertion in debug mode. Py_FatalError() displays the current exception and the traceback which contain more information than just the assertion error.
This commit is contained in:
parent
de821befd4
commit
3b06dfb9d1
|
@ -2080,16 +2080,6 @@ _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where)
|
||||||
|
|
||||||
assert((func != NULL) ^ (where != NULL));
|
assert((func != NULL) ^ (where != NULL));
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
/* In debug mode: abort() with an assertion error. Use two different
|
|
||||||
assertions, so if an assertion fails, it's possible to know
|
|
||||||
if result was set or not and if an exception was raised or not. */
|
|
||||||
if (result != NULL)
|
|
||||||
assert(!err_occurred);
|
|
||||||
else
|
|
||||||
assert(err_occurred);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
if (!err_occurred) {
|
if (!err_occurred) {
|
||||||
if (func)
|
if (func)
|
||||||
|
@ -2100,7 +2090,7 @@ _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where)
|
||||||
PyErr_Format(PyExc_SystemError,
|
PyErr_Format(PyExc_SystemError,
|
||||||
"%s returned NULL without setting an error",
|
"%s returned NULL without setting an error",
|
||||||
where);
|
where);
|
||||||
return NULL;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2119,10 +2109,17 @@ _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where)
|
||||||
"%s returned a result with an error set",
|
"%s returned a result with an error set",
|
||||||
where);
|
where);
|
||||||
_PyErr_ChainExceptions(exc, val, tb);
|
_PyErr_ChainExceptions(exc, val, tb);
|
||||||
return NULL;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
error:
|
||||||
|
#ifdef Py_DEBUG
|
||||||
|
/* Ensure that the bug is catched in debug mode */
|
||||||
|
Py_FatalError("Function result is invalid");
|
||||||
|
#endif
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
|
|
Loading…
Reference in New Issue