Skip to content
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
bpo-42972: Fully support GC protocol for _queue.SimpleQueue (GH-26372)
(cherry picked from commit 4d7f8f9)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
  • Loading branch information
Erlend Egeberg Aasland authored and miss-islington committed May 27, 2021
commit 52b8cfef398840a892adfa652dcaf8436814851c
11 changes: 10 additions & 1 deletion Modules/_queuemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class _queue.SimpleQueue "simplequeueobject *" "simplequeue_get_state_by_type(ty
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=0a4023fe4d198c8d]*/

static int
simplequeue_clear(simplequeueobject *self)
{
Py_CLEAR(self->lst);
return 0;
}

static void
simplequeue_dealloc(simplequeueobject *self)
{
Expand All @@ -46,7 +53,7 @@ simplequeue_dealloc(simplequeueobject *self)
PyThread_release_lock(self->lock);
PyThread_free_lock(self->lock);
}
Py_XDECREF(self->lst);
(void)simplequeue_clear(self);
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) self);
Py_TYPE(self)->tp_free(self);
Expand All @@ -57,6 +64,7 @@ static int
simplequeue_traverse(simplequeueobject *self, visitproc visit, void *arg)
{
Py_VISIT(self->lst);
Py_VISIT(Py_TYPE(self));
return 0;
}

Expand Down Expand Up @@ -362,6 +370,7 @@ static PyType_Slot simplequeue_slots[] = {
{Py_tp_dealloc, simplequeue_dealloc},
{Py_tp_doc, (void *)simplequeue_new__doc__},
{Py_tp_traverse, simplequeue_traverse},
{Py_tp_clear, simplequeue_clear},
{Py_tp_members, simplequeue_members},
{Py_tp_methods, simplequeue_methods},
{Py_tp_new, simplequeue_new},
Expand Down