Skip to content

Commit 8fb6edf

Browse files
GH-104787: use managed weakrefs in _asyncio (#106516)
1 parent 51ea664 commit 8fb6edf

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

Modules/_asynciomodule.c

+6-21
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ typedef enum {
120120
PyObject *prefix##_result; \
121121
PyObject *prefix##_source_tb; \
122122
PyObject *prefix##_cancel_msg; \
123-
PyObject *prefix##_weakreflist; \
124123
PyObject *prefix##_cancelled_exc; \
125124
fut_state prefix##_state; \
126125
/* These bitfields need to be at the end of the struct
@@ -1502,11 +1501,6 @@ static PyMethodDef FutureType_methods[] = {
15021501
{NULL, NULL} /* Sentinel */
15031502
};
15041503

1505-
static PyMemberDef FutureType_members[] = {
1506-
{"__weaklistoffset__", T_PYSSIZET, offsetof(FutureObj, fut_weakreflist), READONLY},
1507-
{NULL},
1508-
};
1509-
15101504
#define FUTURE_COMMON_GETSETLIST \
15111505
{"_state", (getter)FutureObj_get_state, NULL, NULL}, \
15121506
{"_asyncio_future_blocking", (getter)FutureObj_get_blocking, \
@@ -1537,7 +1531,6 @@ static PyType_Slot Future_slots[] = {
15371531
{Py_tp_clear, (inquiry)FutureObj_clear},
15381532
{Py_tp_iter, (getiterfunc)future_new_iter},
15391533
{Py_tp_methods, FutureType_methods},
1540-
{Py_tp_members, FutureType_members},
15411534
{Py_tp_getset, FutureType_getsetlist},
15421535
{Py_tp_init, (initproc)_asyncio_Future___init__},
15431536
{Py_tp_new, PyType_GenericNew},
@@ -1552,7 +1545,8 @@ static PyType_Spec Future_spec = {
15521545
.name = "_asyncio.Future",
15531546
.basicsize = sizeof(FutureObj),
15541547
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
1555-
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_MANAGED_DICT),
1548+
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_MANAGED_DICT |
1549+
Py_TPFLAGS_MANAGED_WEAKREF),
15561550
.slots = Future_slots,
15571551
};
15581552

@@ -1569,9 +1563,7 @@ FutureObj_dealloc(PyObject *self)
15691563
PyTypeObject *tp = Py_TYPE(fut);
15701564
PyObject_GC_UnTrack(self);
15711565

1572-
if (fut->fut_weakreflist != NULL) {
1573-
PyObject_ClearWeakRefs(self);
1574-
}
1566+
PyObject_ClearWeakRefs(self);
15751567

15761568
(void)FutureObj_clear(fut);
15771569
tp->tp_free(fut);
@@ -2642,11 +2634,6 @@ static PyMethodDef TaskType_methods[] = {
26422634
{NULL, NULL} /* Sentinel */
26432635
};
26442636

2645-
static PyMemberDef TaskType_members[] = {
2646-
{"__weaklistoffset__", T_PYSSIZET, offsetof(TaskObj, task_weakreflist), READONLY},
2647-
{NULL},
2648-
};
2649-
26502637
static PyGetSetDef TaskType_getsetlist[] = {
26512638
FUTURE_COMMON_GETSETLIST
26522639
{"_log_destroy_pending", (getter)TaskObj_get_log_destroy_pending,
@@ -2665,7 +2652,6 @@ static PyType_Slot Task_slots[] = {
26652652
{Py_tp_clear, (inquiry)TaskObj_clear},
26662653
{Py_tp_iter, (getiterfunc)future_new_iter},
26672654
{Py_tp_methods, TaskType_methods},
2668-
{Py_tp_members, TaskType_members},
26692655
{Py_tp_getset, TaskType_getsetlist},
26702656
{Py_tp_init, (initproc)_asyncio_Task___init__},
26712657
{Py_tp_new, PyType_GenericNew},
@@ -2680,7 +2666,8 @@ static PyType_Spec Task_spec = {
26802666
.name = "_asyncio.Task",
26812667
.basicsize = sizeof(TaskObj),
26822668
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
2683-
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_MANAGED_DICT),
2669+
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_MANAGED_DICT |
2670+
Py_TPFLAGS_MANAGED_WEAKREF),
26842671
.slots = Task_slots,
26852672
};
26862673

@@ -2697,9 +2684,7 @@ TaskObj_dealloc(PyObject *self)
26972684
PyTypeObject *tp = Py_TYPE(task);
26982685
PyObject_GC_UnTrack(self);
26992686

2700-
if (task->task_weakreflist != NULL) {
2701-
PyObject_ClearWeakRefs(self);
2702-
}
2687+
PyObject_ClearWeakRefs(self);
27032688

27042689
(void)TaskObj_clear(task);
27052690
tp->tp_free(task);

0 commit comments

Comments
 (0)