Skip to content

bpo-42972: Fully implement GC protocol for arraymodule types #26114

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
May 25, 2021
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
13 changes: 11 additions & 2 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,18 @@ ins1(arrayobject *self, Py_ssize_t where, PyObject *v)

/* Methods */

static int
array_tp_traverse(arrayobject *op, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(op));
return 0;
}

static void
array_dealloc(arrayobject *op)
{
PyTypeObject *tp = Py_TYPE(op);
PyObject_GC_UnTrack(op);

if (op->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) op);
Expand Down Expand Up @@ -2820,7 +2828,7 @@ static PyType_Slot array_slots[] = {
{Py_tp_getset, array_getsets},
{Py_tp_alloc, PyType_GenericAlloc},
{Py_tp_new, array_new},
{Py_tp_free, PyObject_Del},
{Py_tp_traverse, array_tp_traverse},

/* as sequence */
{Py_sq_length, array_length},
Expand Down Expand Up @@ -2848,7 +2856,7 @@ static PyType_Spec array_spec = {
.name = "array.array",
.basicsize = sizeof(arrayobject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE |
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_SEQUENCE),
.slots = array_slots,
};
Expand Down Expand Up @@ -2922,6 +2930,7 @@ arrayiter_dealloc(arrayiterobject *it)
static int
arrayiter_traverse(arrayiterobject *it, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(it));
Py_VISIT(it->ao);
return 0;
}
Expand Down