Skip to content

Commit

Permalink
Prevent Python call with exception set in __Pyx_AddTraceback() (cytho…
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikjak authored and scoder committed Apr 7, 2022
1 parent 94f409e commit 569a063
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Cython/Utility/Exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0;
PyThreadState *tstate = __Pyx_PyThreadState_Current;
PyObject *ptype, *pvalue, *ptraceback;

if (c_line) {
c_line = __Pyx_CLineForTraceback(tstate, c_line);
Expand All @@ -786,9 +787,18 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
// Negate to avoid collisions between py and c lines.
py_code = $global_code_object_cache_find(c_line ? -c_line : py_line);
if (!py_code) {
__Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
py_code = __Pyx_CreateCodeObjectForTraceback(
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);
}
py_frame = PyFrame_New(
Expand Down

0 comments on commit 569a063

Please sign in to comment.