Skip to content

gh-116915: Make _thread._ThreadHandle support GC #116934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2024
Merged
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
16 changes: 13 additions & 3 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,21 @@ PyThreadHandleObject_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return (PyObject *)PyThreadHandleObject_new(type);
}

static int
PyThreadHandleObject_traverse(PyThreadHandleObject *self, visitproc visit,
void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
}

static void
PyThreadHandleObject_dealloc(PyThreadHandleObject *self)
{
PyObject *tp = (PyObject *) Py_TYPE(self);
PyObject_GC_UnTrack(self);
PyTypeObject *tp = Py_TYPE(self);
ThreadHandle_decref(self->handle);
PyObject_Free(self);
tp->tp_free(self);
Py_DECREF(tp);
}

Expand Down Expand Up @@ -673,6 +682,7 @@ static PyType_Slot ThreadHandle_Type_slots[] = {
{Py_tp_dealloc, (destructor)PyThreadHandleObject_dealloc},
{Py_tp_repr, (reprfunc)PyThreadHandleObject_repr},
{Py_tp_getset, ThreadHandle_getsetlist},
{Py_tp_traverse, PyThreadHandleObject_traverse},
{Py_tp_methods, ThreadHandle_methods},
{Py_tp_new, PyThreadHandleObject_tp_new},
{0, 0}
Expand All @@ -682,7 +692,7 @@ static PyType_Spec ThreadHandle_Type_spec = {
"_thread._ThreadHandle",
sizeof(PyThreadHandleObject),
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC,
ThreadHandle_Type_slots,
};

Expand Down