[Python-checkins] cpython: Issue #23571: Enhance _Py_CheckFunctionResult()

victor.stinner python-checkins at python.org
Tue Mar 24 16:29:07 CET 2015


https://hg.python.org/cpython/rev/2a18b958f1e1
changeset: 95163:2a18b958f1e1
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Mar 24 16:28:52 2015 +0100
summary:
 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).
files:
 Lib/test/test_capi.py | 8 ++++----
 Objects/abstract.c | 19 ++++++++++---------
 2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -185,8 +185,8 @@
 """)
 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: <built-in function '
 br'return_null_without_error> returned NULL '
 br'without setting an error\n'
@@ -212,8 +212,8 @@
 """)
 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
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2090,7 +2090,11 @@
 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 @@
 "%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 *
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /