]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-131173: Improve exception handling during take_ownership processing (#132620)
authorAlper <alper_yoney@hotmail.com>
Thu, 17 Apr 2025 20:38:34 +0000 (13:38 -0700)
committerGitHub <noreply@github.com>
Thu, 17 Apr 2025 20:38:34 +0000 (13:38 -0700)
Save and restore exceptions during take_ownership processing to preserve
exceptions currently being raised.

Co-authored-by: alperyoney <alperyoney@fb.com>
Python/frame.c

index 558f92055bbfc1a8e428b0b0e47c6cf862788268..ce216797e47cda6a5c8d29c0d7d3721461a9df78 100644 (file)
@@ -69,6 +69,7 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
     _PyInterpreterFrame *prev = _PyFrame_GetFirstComplete(frame->previous);
     if (prev) {
         assert(prev->owner < FRAME_OWNED_BY_INTERPRETER);
+        PyObject *exc = PyErr_GetRaisedException();
         /* Link PyFrameObjects.f_back and remove link through _PyInterpreterFrame.previous */
         PyFrameObject *back = _PyFrame_GetFrameObject(prev);
         if (back == NULL) {
@@ -80,6 +81,7 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
         else {
             f->f_back = (PyFrameObject *)Py_NewRef(back);
         }
+        PyErr_SetRaisedException(exc);
     }
     if (!_PyObject_GC_IS_TRACKED((PyObject *)f)) {
         _PyObject_GC_TRACK((PyObject *)f);