Commit 569a0637 authored by Jakub Kulík's avatar Jakub Kulík Committed by Stefan Behnel

Prevent Python call with exception set in __Pyx_AddTraceback() (GH-4723)

Closes https://github.com/cython/cython/issues/4722
parent 94f409ed
...@@ -778,6 +778,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, ...@@ -778,6 +778,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
PyCodeObject *py_code = 0; PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0; PyFrameObject *py_frame = 0;
PyThreadState *tstate = __Pyx_PyThreadState_Current; PyThreadState *tstate = __Pyx_PyThreadState_Current;
PyObject *ptype, *pvalue, *ptraceback;
if (c_line) { if (c_line) {
c_line = __Pyx_CLineForTraceback(tstate, c_line); c_line = __Pyx_CLineForTraceback(tstate, c_line);
...@@ -786,9 +787,18 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, ...@@ -786,9 +787,18 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
// Negate to avoid collisions between py and c lines. // Negate to avoid collisions between py and c lines.
py_code = $global_code_object_cache_find(c_line ? -c_line : py_line); py_code = $global_code_object_cache_find(c_line ? -c_line : py_line);
if (!py_code) { if (!py_code) {
__Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
py_code = __Pyx_CreateCodeObjectForTraceback( py_code = __Pyx_CreateCodeObjectForTraceback(
funcname, c_line, py_line, filename); funcname, c_line, py_line, filename);
if (!py_code) goto bad; if (!py_code) {
/* If the code object creation fails, then we should clear the
fetched exception references and propagate the new exception */
Py_XDECREF(ptype);
Py_XDECREF(pvalue);
Py_XDECREF(ptraceback);
goto bad;
}
__Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
$global_code_object_cache_insert(c_line ? -c_line : py_line, py_code); $global_code_object_cache_insert(c_line ? -c_line : py_line, py_code);
} }
py_frame = PyFrame_New( py_frame = PyFrame_New(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment