mirror of https://github.com/python/cpython
Issue #28003: Make WrappedVal, ASend and AThrow GC types
This commit is contained in:
parent
49ffdf6bb2
commit
29310c47a7
|
@ -1503,14 +1503,14 @@ PyAsyncGen_ClearFreeLists(void)
|
||||||
_PyAsyncGenWrappedValue *o;
|
_PyAsyncGenWrappedValue *o;
|
||||||
o = ag_value_freelist[--ag_value_freelist_free];
|
o = ag_value_freelist[--ag_value_freelist_free];
|
||||||
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
||||||
PyObject_Del(o);
|
PyObject_GC_Del(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ag_asend_freelist_free) {
|
while (ag_asend_freelist_free) {
|
||||||
PyAsyncGenASend *o;
|
PyAsyncGenASend *o;
|
||||||
o = ag_asend_freelist[--ag_asend_freelist_free];
|
o = ag_asend_freelist[--ag_asend_freelist_free];
|
||||||
assert(Py_TYPE(o) == &_PyAsyncGenASend_Type);
|
assert(Py_TYPE(o) == &_PyAsyncGenASend_Type);
|
||||||
PyObject_Del(o);
|
PyObject_GC_Del(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1557,16 +1557,25 @@ async_gen_unwrap_value(PyAsyncGenObject *gen, PyObject *result)
|
||||||
static void
|
static void
|
||||||
async_gen_asend_dealloc(PyAsyncGenASend *o)
|
async_gen_asend_dealloc(PyAsyncGenASend *o)
|
||||||
{
|
{
|
||||||
|
_PyObject_GC_UNTRACK((PyObject *)o);
|
||||||
Py_CLEAR(o->ags_gen);
|
Py_CLEAR(o->ags_gen);
|
||||||
Py_CLEAR(o->ags_sendval);
|
Py_CLEAR(o->ags_sendval);
|
||||||
if (ag_asend_freelist_free < _PyAsyncGen_MAXFREELIST) {
|
if (ag_asend_freelist_free < _PyAsyncGen_MAXFREELIST) {
|
||||||
assert(PyAsyncGenASend_CheckExact(o));
|
assert(PyAsyncGenASend_CheckExact(o));
|
||||||
ag_asend_freelist[ag_asend_freelist_free++] = o;
|
ag_asend_freelist[ag_asend_freelist_free++] = o;
|
||||||
} else {
|
} else {
|
||||||
PyObject_Del(o);
|
PyObject_GC_Del(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
async_gen_asend_traverse(PyAsyncGenASend *o, visitproc visit, void *arg)
|
||||||
|
{
|
||||||
|
Py_VISIT(o->ags_gen);
|
||||||
|
Py_VISIT(o->ags_sendval);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
async_gen_asend_send(PyAsyncGenASend *o, PyObject *arg)
|
async_gen_asend_send(PyAsyncGenASend *o, PyObject *arg)
|
||||||
|
@ -1668,9 +1677,9 @@ PyTypeObject _PyAsyncGenASend_Type = {
|
||||||
PyObject_GenericGetAttr, /* tp_getattro */
|
PyObject_GenericGetAttr, /* tp_getattro */
|
||||||
0, /* tp_setattro */
|
0, /* tp_setattro */
|
||||||
0, /* tp_as_buffer */
|
0, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
|
||||||
0, /* tp_doc */
|
0, /* tp_doc */
|
||||||
0, /* tp_traverse */
|
(traverseproc)async_gen_asend_traverse, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
0, /* tp_richcompare */
|
0, /* tp_richcompare */
|
||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
|
@ -1699,7 +1708,7 @@ async_gen_asend_new(PyAsyncGenObject *gen, PyObject *sendval)
|
||||||
o = ag_asend_freelist[ag_asend_freelist_free];
|
o = ag_asend_freelist[ag_asend_freelist_free];
|
||||||
_Py_NewReference((PyObject *)o);
|
_Py_NewReference((PyObject *)o);
|
||||||
} else {
|
} else {
|
||||||
o = PyObject_New(PyAsyncGenASend, &_PyAsyncGenASend_Type);
|
o = PyObject_GC_New(PyAsyncGenASend, &_PyAsyncGenASend_Type);
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1712,6 +1721,8 @@ async_gen_asend_new(PyAsyncGenObject *gen, PyObject *sendval)
|
||||||
o->ags_sendval = sendval;
|
o->ags_sendval = sendval;
|
||||||
|
|
||||||
o->ags_state = AWAITABLE_STATE_INIT;
|
o->ags_state = AWAITABLE_STATE_INIT;
|
||||||
|
|
||||||
|
_PyObject_GC_TRACK((PyObject*)o);
|
||||||
return (PyObject*)o;
|
return (PyObject*)o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1722,16 +1733,26 @@ async_gen_asend_new(PyAsyncGenObject *gen, PyObject *sendval)
|
||||||
static void
|
static void
|
||||||
async_gen_wrapped_val_dealloc(_PyAsyncGenWrappedValue *o)
|
async_gen_wrapped_val_dealloc(_PyAsyncGenWrappedValue *o)
|
||||||
{
|
{
|
||||||
|
_PyObject_GC_UNTRACK((PyObject *)o);
|
||||||
Py_CLEAR(o->agw_val);
|
Py_CLEAR(o->agw_val);
|
||||||
if (ag_value_freelist_free < _PyAsyncGen_MAXFREELIST) {
|
if (ag_value_freelist_free < _PyAsyncGen_MAXFREELIST) {
|
||||||
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
||||||
ag_value_freelist[ag_value_freelist_free++] = o;
|
ag_value_freelist[ag_value_freelist_free++] = o;
|
||||||
} else {
|
} else {
|
||||||
PyObject_Del(o);
|
PyObject_GC_Del(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
async_gen_wrapped_val_traverse(_PyAsyncGenWrappedValue *o,
|
||||||
|
visitproc visit, void *arg)
|
||||||
|
{
|
||||||
|
Py_VISIT(o->agw_val);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PyTypeObject _PyAsyncGenWrappedValue_Type = {
|
PyTypeObject _PyAsyncGenWrappedValue_Type = {
|
||||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||||
"async_generator_wrapped_value", /* tp_name */
|
"async_generator_wrapped_value", /* tp_name */
|
||||||
|
@ -1753,9 +1774,9 @@ PyTypeObject _PyAsyncGenWrappedValue_Type = {
|
||||||
PyObject_GenericGetAttr, /* tp_getattro */
|
PyObject_GenericGetAttr, /* tp_getattro */
|
||||||
0, /* tp_setattro */
|
0, /* tp_setattro */
|
||||||
0, /* tp_as_buffer */
|
0, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
|
||||||
0, /* tp_doc */
|
0, /* tp_doc */
|
||||||
0, /* tp_traverse */
|
(traverseproc)async_gen_wrapped_val_traverse, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
0, /* tp_richcompare */
|
0, /* tp_richcompare */
|
||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
|
@ -1787,13 +1808,15 @@ _PyAsyncGenValueWrapperNew(PyObject *val)
|
||||||
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
||||||
_Py_NewReference((PyObject*)o);
|
_Py_NewReference((PyObject*)o);
|
||||||
} else {
|
} else {
|
||||||
o = PyObject_New(_PyAsyncGenWrappedValue, &_PyAsyncGenWrappedValue_Type);
|
o = PyObject_GC_New(_PyAsyncGenWrappedValue,
|
||||||
|
&_PyAsyncGenWrappedValue_Type);
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
o->agw_val = val;
|
o->agw_val = val;
|
||||||
Py_INCREF(val);
|
Py_INCREF(val);
|
||||||
|
_PyObject_GC_TRACK((PyObject*)o);
|
||||||
return (PyObject*)o;
|
return (PyObject*)o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1804,9 +1827,19 @@ _PyAsyncGenValueWrapperNew(PyObject *val)
|
||||||
static void
|
static void
|
||||||
async_gen_athrow_dealloc(PyAsyncGenAThrow *o)
|
async_gen_athrow_dealloc(PyAsyncGenAThrow *o)
|
||||||
{
|
{
|
||||||
|
_PyObject_GC_UNTRACK((PyObject *)o);
|
||||||
Py_CLEAR(o->agt_gen);
|
Py_CLEAR(o->agt_gen);
|
||||||
Py_CLEAR(o->agt_args);
|
Py_CLEAR(o->agt_args);
|
||||||
PyObject_Del(o);
|
PyObject_GC_Del(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
async_gen_athrow_traverse(PyAsyncGenAThrow *o, visitproc visit, void *arg)
|
||||||
|
{
|
||||||
|
Py_VISIT(o->agt_gen);
|
||||||
|
Py_VISIT(o->agt_args);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1990,9 +2023,9 @@ PyTypeObject _PyAsyncGenAThrow_Type = {
|
||||||
PyObject_GenericGetAttr, /* tp_getattro */
|
PyObject_GenericGetAttr, /* tp_getattro */
|
||||||
0, /* tp_setattro */
|
0, /* tp_setattro */
|
||||||
0, /* tp_as_buffer */
|
0, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
|
||||||
0, /* tp_doc */
|
0, /* tp_doc */
|
||||||
0, /* tp_traverse */
|
(traverseproc)async_gen_athrow_traverse, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
0, /* tp_clear */
|
||||||
0, /* tp_richcompare */
|
0, /* tp_richcompare */
|
||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
|
@ -2016,7 +2049,7 @@ static PyObject *
|
||||||
async_gen_athrow_new(PyAsyncGenObject *gen, PyObject *args)
|
async_gen_athrow_new(PyAsyncGenObject *gen, PyObject *args)
|
||||||
{
|
{
|
||||||
PyAsyncGenAThrow *o;
|
PyAsyncGenAThrow *o;
|
||||||
o = PyObject_New(PyAsyncGenAThrow, &_PyAsyncGenAThrow_Type);
|
o = PyObject_GC_New(PyAsyncGenAThrow, &_PyAsyncGenAThrow_Type);
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2025,5 +2058,6 @@ async_gen_athrow_new(PyAsyncGenObject *gen, PyObject *args)
|
||||||
o->agt_state = AWAITABLE_STATE_INIT;
|
o->agt_state = AWAITABLE_STATE_INIT;
|
||||||
Py_INCREF(gen);
|
Py_INCREF(gen);
|
||||||
Py_XINCREF(args);
|
Py_XINCREF(args);
|
||||||
|
_PyObject_GC_TRACK((PyObject*)o);
|
||||||
return (PyObject*)o;
|
return (PyObject*)o;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue