Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b06dfb

Browse files
committed
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.
1 parent de821be commit 3b06dfb

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

Objects/abstract.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,16 +2080,6 @@ _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where)
20802080

20812081
assert((func != NULL) ^ (where != NULL));
20822082

2083-
#ifndef NDEBUG
2084-
/* In debug mode: abort() with an assertion error. Use two different
2085-
assertions, so if an assertion fails, it's possible to know
2086-
if result was set or not and if an exception was raised or not. */
2087-
if (result != NULL)
2088-
assert(!err_occurred);
2089-
else
2090-
assert(err_occurred);
2091-
#endif
2092-
20932083
if (result == NULL) {
20942084
if (!err_occurred) {
20952085
if (func)
@@ -2100,7 +2090,7 @@ _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where)
21002090
PyErr_Format(PyExc_SystemError,
21012091
"%s returned NULL without setting an error",
21022092
where);
2103-
return NULL;
2093+
goto error;
21042094
}
21052095
}
21062096
else {
@@ -2119,10 +2109,17 @@ _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where)
21192109
"%s returned a result with an error set",
21202110
where);
21212111
_PyErr_ChainExceptions(exc, val, tb);
2122-
return NULL;
2112+
goto error;
21232113
}
21242114
}
21252115
return result;
2116+
2117+
error:
2118+
#ifdef Py_DEBUG
2119+
/* Ensure that the bug is catched in debug mode */
2120+
Py_FatalError("Function result is invalid");
2121+
#endif
2122+
return NULL;
21262123
}
21272124

21282125
PyObject *

0 commit comments

Comments
 (0)