mirror of
https://github.com/python/cpython
synced 2024-09-05 16:38:56 +00:00
GH-104787: use managed weakrefs in _asyncio
(#106516)
This commit is contained in:
parent
51ea664d18
commit
8fb6edf479
|
@ -120,7 +120,6 @@ typedef enum {
|
|||
PyObject *prefix##_result; \
|
||||
PyObject *prefix##_source_tb; \
|
||||
PyObject *prefix##_cancel_msg; \
|
||||
PyObject *prefix##_weakreflist; \
|
||||
PyObject *prefix##_cancelled_exc; \
|
||||
fut_state prefix##_state; \
|
||||
/* These bitfields need to be at the end of the struct
|
||||
|
@ -1502,11 +1501,6 @@ static PyMethodDef FutureType_methods[] = {
|
|||
{NULL, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyMemberDef FutureType_members[] = {
|
||||
{"__weaklistoffset__", T_PYSSIZET, offsetof(FutureObj, fut_weakreflist), READONLY},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
#define FUTURE_COMMON_GETSETLIST \
|
||||
{"_state", (getter)FutureObj_get_state, NULL, NULL}, \
|
||||
{"_asyncio_future_blocking", (getter)FutureObj_get_blocking, \
|
||||
|
@ -1537,7 +1531,6 @@ static PyType_Slot Future_slots[] = {
|
|||
{Py_tp_clear, (inquiry)FutureObj_clear},
|
||||
{Py_tp_iter, (getiterfunc)future_new_iter},
|
||||
{Py_tp_methods, FutureType_methods},
|
||||
{Py_tp_members, FutureType_members},
|
||||
{Py_tp_getset, FutureType_getsetlist},
|
||||
{Py_tp_init, (initproc)_asyncio_Future___init__},
|
||||
{Py_tp_new, PyType_GenericNew},
|
||||
|
@ -1552,7 +1545,8 @@ static PyType_Spec Future_spec = {
|
|||
.name = "_asyncio.Future",
|
||||
.basicsize = sizeof(FutureObj),
|
||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
|
||||
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_MANAGED_DICT),
|
||||
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_MANAGED_DICT |
|
||||
Py_TPFLAGS_MANAGED_WEAKREF),
|
||||
.slots = Future_slots,
|
||||
};
|
||||
|
||||
|
@ -1569,9 +1563,7 @@ FutureObj_dealloc(PyObject *self)
|
|||
PyTypeObject *tp = Py_TYPE(fut);
|
||||
PyObject_GC_UnTrack(self);
|
||||
|
||||
if (fut->fut_weakreflist != NULL) {
|
||||
PyObject_ClearWeakRefs(self);
|
||||
}
|
||||
PyObject_ClearWeakRefs(self);
|
||||
|
||||
(void)FutureObj_clear(fut);
|
||||
tp->tp_free(fut);
|
||||
|
@ -2642,11 +2634,6 @@ static PyMethodDef TaskType_methods[] = {
|
|||
{NULL, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyMemberDef TaskType_members[] = {
|
||||
{"__weaklistoffset__", T_PYSSIZET, offsetof(TaskObj, task_weakreflist), READONLY},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
static PyGetSetDef TaskType_getsetlist[] = {
|
||||
FUTURE_COMMON_GETSETLIST
|
||||
{"_log_destroy_pending", (getter)TaskObj_get_log_destroy_pending,
|
||||
|
@ -2665,7 +2652,6 @@ static PyType_Slot Task_slots[] = {
|
|||
{Py_tp_clear, (inquiry)TaskObj_clear},
|
||||
{Py_tp_iter, (getiterfunc)future_new_iter},
|
||||
{Py_tp_methods, TaskType_methods},
|
||||
{Py_tp_members, TaskType_members},
|
||||
{Py_tp_getset, TaskType_getsetlist},
|
||||
{Py_tp_init, (initproc)_asyncio_Task___init__},
|
||||
{Py_tp_new, PyType_GenericNew},
|
||||
|
@ -2680,7 +2666,8 @@ static PyType_Spec Task_spec = {
|
|||
.name = "_asyncio.Task",
|
||||
.basicsize = sizeof(TaskObj),
|
||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
|
||||
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_MANAGED_DICT),
|
||||
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_MANAGED_DICT |
|
||||
Py_TPFLAGS_MANAGED_WEAKREF),
|
||||
.slots = Task_slots,
|
||||
};
|
||||
|
||||
|
@ -2697,9 +2684,7 @@ TaskObj_dealloc(PyObject *self)
|
|||
PyTypeObject *tp = Py_TYPE(task);
|
||||
PyObject_GC_UnTrack(self);
|
||||
|
||||
if (task->task_weakreflist != NULL) {
|
||||
PyObject_ClearWeakRefs(self);
|
||||
}
|
||||
PyObject_ClearWeakRefs(self);
|
||||
|
||||
(void)TaskObj_clear(task);
|
||||
tp->tp_free(task);
|
||||
|
|
Loading…
Reference in a new issue