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 <rep...@bugs.python.org> <http://bugs.python.org/issue23571> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com