[New-bugs-announce] [issue23571] Raise SystemError if a function returns a result with an exception set
STINNER Victor
report at bugs.python.org
Tue Mar 3 12:58:41 CET 2015
New submission from STINNER Victor:
Attached patch changes PyObject_Call() and PyCFunction_Call() to raise a SystemError and destroy the result (Py_DECREF) if a function returns a result with an exception set.
I also refactored PyCFunction_Call() and added "assert(!PyErr_Occurred());" at the beginning of PyCFunction_Call().
I removed duplicate checks in ceval.c.
--
I didn't check the impact on performances.
If the patch has a significant overhead: _Py_CheckFunctionResult() may be marked to be inlined, and PyCFunction_Call() and PyObject_Call() checks may be marked as unlikely using GCC __builtin_expect(), something like:
#ifdef __GNUC__
# define Py_likely(x) __builtin_expect((x),1)
# define Py_unlikely(x) __builtin_expect((x),0)
#else
# define Py_likely(x) x
# define Py_unlikely(x) x
#endif
Be careful of __builtin_expect(), misused it can make the code slower! (benchmark, benchmark, benchmark!)
----------
components: Interpreter Core
messages: 237123
nosy: haypo, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Raise SystemError if a function returns a result with an exception set
versions: Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23571>
_______________________________________
More information about the New-bugs-announce
mailing list