mirror of https://github.com/python/cpython
bpo-42972: Fully implement GC protocol for arraymodule types (GH-26114)
This commit is contained in:
parent
d3c277a59c
commit
bd404ccac0
|
@ -661,10 +661,18 @@ ins1(arrayobject *self, Py_ssize_t where, PyObject *v)
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
|
||||||
|
static int
|
||||||
|
array_tp_traverse(arrayobject *op, visitproc visit, void *arg)
|
||||||
|
{
|
||||||
|
Py_VISIT(Py_TYPE(op));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
array_dealloc(arrayobject *op)
|
array_dealloc(arrayobject *op)
|
||||||
{
|
{
|
||||||
PyTypeObject *tp = Py_TYPE(op);
|
PyTypeObject *tp = Py_TYPE(op);
|
||||||
|
PyObject_GC_UnTrack(op);
|
||||||
|
|
||||||
if (op->weakreflist != NULL)
|
if (op->weakreflist != NULL)
|
||||||
PyObject_ClearWeakRefs((PyObject *) op);
|
PyObject_ClearWeakRefs((PyObject *) op);
|
||||||
|
@ -2820,7 +2828,7 @@ static PyType_Slot array_slots[] = {
|
||||||
{Py_tp_getset, array_getsets},
|
{Py_tp_getset, array_getsets},
|
||||||
{Py_tp_alloc, PyType_GenericAlloc},
|
{Py_tp_alloc, PyType_GenericAlloc},
|
||||||
{Py_tp_new, array_new},
|
{Py_tp_new, array_new},
|
||||||
{Py_tp_free, PyObject_Del},
|
{Py_tp_traverse, array_tp_traverse},
|
||||||
|
|
||||||
/* as sequence */
|
/* as sequence */
|
||||||
{Py_sq_length, array_length},
|
{Py_sq_length, array_length},
|
||||||
|
@ -2848,7 +2856,7 @@ static PyType_Spec array_spec = {
|
||||||
.name = "array.array",
|
.name = "array.array",
|
||||||
.basicsize = sizeof(arrayobject),
|
.basicsize = sizeof(arrayobject),
|
||||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
|
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
|
||||||
Py_TPFLAGS_IMMUTABLETYPE |
|
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC |
|
||||||
Py_TPFLAGS_SEQUENCE),
|
Py_TPFLAGS_SEQUENCE),
|
||||||
.slots = array_slots,
|
.slots = array_slots,
|
||||||
};
|
};
|
||||||
|
@ -2922,6 +2930,7 @@ arrayiter_dealloc(arrayiterobject *it)
|
||||||
static int
|
static int
|
||||||
arrayiter_traverse(arrayiterobject *it, visitproc visit, void *arg)
|
arrayiter_traverse(arrayiterobject *it, visitproc visit, void *arg)
|
||||||
{
|
{
|
||||||
|
Py_VISIT(Py_TYPE(it));
|
||||||
Py_VISIT(it->ao);
|
Py_VISIT(it->ao);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue