[Python-Dev] Is it safe to call PyEval_EvalFrameEx() with an exception set?
Victor Stinner
victor.stinner at gmail.com
Wed Jul 17 01:08:31 CEST 2013
2013/7/16 Victor Stinner <victor.stinner at gmail.com>:
> I would like to add assertions in Python/ceval.c to detect such bugs
> earlier. The problem is that some functions rely on the ability to
> call PyEval_EvalFrameEx() with an exception set. Is it expected?
> Should it be avoided? The current exception can be replaced with a new
> exception.
Another example. Py_ReprLeave() function can be called while an
exception is set. I'm not sure that it is "safe" to call new code
while an exception is set.
The function can raise a new exception. For example, PyList_SetSlice()
can fail because of a MemoryError.
I modified Py_ReprLeave() to save and then restore the current exception:
http://hg.python.org/cpython/rev/28ff7ac91477
If Py_ReprLeave() raises a new exception, it is clears (replaced by
the previous exception context).
Victor
More information about the Python-Dev
mailing list