diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 8a92d6ba29e..fbd1466c788 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -185,8 +185,8 @@ class CAPITest(unittest.TestCase): """) rc, out, err = assert_python_failure('-c', code) self.assertRegex(err.replace(b'\r', b''), - br'Fatal Python error: ' - br'Function result is invalid\n' + br'Fatal Python error: a function returned NULL ' + br'without setting an error\n' br'SystemError: returned NULL ' br'without setting an error\n' @@ -212,8 +212,8 @@ class CAPITest(unittest.TestCase): """) rc, out, err = assert_python_failure('-c', code) self.assertRegex(err.replace(b'\r', b''), - br'Fatal Python error: ' - br'Function result is invalid\n' + br'Fatal Python error: a function returned a ' + br'result with an error set\n' br'ValueError\n' br'\n' br'During handling of the above exception, ' diff --git a/Objects/abstract.c b/Objects/abstract.c index 6f8432efefd..dc8fb3749d3 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2090,7 +2090,11 @@ _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where) PyErr_Format(PyExc_SystemError, "%s returned NULL without setting an error", where); - goto error; +#ifdef Py_DEBUG + /* Ensure that the bug is catched in debug mode */ + Py_FatalError("a function returned NULL without setting an error"); +#endif + return NULL; } } else { @@ -2109,17 +2113,14 @@ _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where) "%s returned a result with an error set", where); _PyErr_ChainExceptions(exc, val, tb); - goto error; +#ifdef Py_DEBUG + /* Ensure that the bug is catched in debug mode */ + Py_FatalError("a function returned a result with an error set"); +#endif + return NULL; } } 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 *