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

Skip to content

Commit 944fbcc

Browse files
committed
Issue #23571: Enhance _Py_CheckFunctionResult()
Too bad, sometimes Py_FatalError() is unable to write the exception into sys.stderr (on "AMD64 OpenIndiana 3.x" buildbot, the buildbot was probably out of memory). Call Py_FatalError() with a different message for the two cases (result+error, or no result and no error).
1 parent 381a9bc commit 944fbcc

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

Lib/test/test_capi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ def test_return_null_without_error(self):
185185
""")
186186
rc, out, err = assert_python_failure('-c', code)
187187
self.assertRegex(err.replace(b'\r', b''),
188-
br'Fatal Python error: '
189-
br'Function result is invalid\n'
188+
br'Fatal Python error: a function returned NULL '
189+
br'without setting an error\n'
190190
br'SystemError: <built-in function '
191191
br'return_null_without_error> returned NULL '
192192
br'without setting an error\n'
@@ -212,8 +212,8 @@ def test_return_result_with_error(self):
212212
""")
213213
rc, out, err = assert_python_failure('-c', code)
214214
self.assertRegex(err.replace(b'\r', b''),
215-
br'Fatal Python error: '
216-
br'Function result is invalid\n'
215+
br'Fatal Python error: a function returned a '
216+
br'result with an error set\n'
217217
br'ValueError\n'
218218
br'\n'
219219
br'During handling of the above exception, '

Objects/abstract.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,11 @@ _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where)
20902090
PyErr_Format(PyExc_SystemError,
20912091
"%s returned NULL without setting an error",
20922092
where);
2093-
goto error;
2093+
#ifdef Py_DEBUG
2094+
/* Ensure that the bug is catched in debug mode */
2095+
Py_FatalError("a function returned NULL without setting an error");
2096+
#endif
2097+
return NULL;
20942098
}
20952099
}
20962100
else {
@@ -2109,17 +2113,14 @@ _Py_CheckFunctionResult(PyObject *func, PyObject *result, const char *where)
21092113
"%s returned a result with an error set",
21102114
where);
21112115
_PyErr_ChainExceptions(exc, val, tb);
2112-
goto error;
2116+
#ifdef Py_DEBUG
2117+
/* Ensure that the bug is catched in debug mode */
2118+
Py_FatalError("a function returned a result with an error set");
2119+
#endif
2120+
return NULL;
21132121
}
21142122
}
21152123
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;
21232124
}
21242125

21252126
PyObject *

0 commit comments

Comments
 (0)