Skip to content

Commit 2283010

Browse files
authored
gh-131173: Improve exception handling during take_ownership processing (#132620)
Save and restore exceptions during take_ownership processing to preserve exceptions currently being raised. Co-authored-by: alperyoney <[email protected]>
1 parent 1d529cb commit 2283010

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Python/frame.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
6969
_PyInterpreterFrame *prev = _PyFrame_GetFirstComplete(frame->previous);
7070
if (prev) {
7171
assert(prev->owner < FRAME_OWNED_BY_INTERPRETER);
72+
PyObject *exc = PyErr_GetRaisedException();
7273
/* Link PyFrameObjects.f_back and remove link through _PyInterpreterFrame.previous */
7374
PyFrameObject *back = _PyFrame_GetFrameObject(prev);
7475
if (back == NULL) {
@@ -80,6 +81,7 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
8081
else {
8182
f->f_back = (PyFrameObject *)Py_NewRef(back);
8283
}
84+
PyErr_SetRaisedException(exc);
8385
}
8486
if (!_PyObject_GC_IS_TRACKED((PyObject *)f)) {
8587
_PyObject_GC_TRACK((PyObject *)f);

0 commit comments

Comments
 (0)