Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a bug in free-threaded builds where the active exception could be
unexpectedly cleared during subtype deallocation in ``subtype_dealloc()``.
10 changes: 10 additions & 0 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,13 @@ subtype_dealloc(PyObject *self)
}
}

/* Save the current exception: clear_slots() and the dict/base-dealloc
below decref arbitrary attribute values, which may clear
tstate->current_exception (gh-89373). Mirroring slot_tp_finalize(). */
PyThreadState *tstate = _PyThreadState_GET();
PyObject *exc = _PyErr_GetRaisedException(tstate); /* preserve in-flight exception */


/* Clear slots up to the nearest base with a different tp_dealloc */
base = type;
while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
Expand Down Expand Up @@ -2882,6 +2889,9 @@ subtype_dealloc(PyObject *self)
if (type_needs_decref) {
_Py_DECREF_TYPE(type);
}

/* Restore the saved exception (see save above). */
_PyErr_SetRaisedException(tstate, exc);
}

static PyTypeObject *solid_base(PyTypeObject *type);
Expand Down
Loading