Delete TaskWakeupMethWrapper_Type and use PyCFunction instead (#22875)

This commit is contained in:
Vladimir Matveev 2020-10-21 17:49:10 -07:00 committed by GitHub
parent 3c69f0c933
commit c8ba47b551
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 94 deletions

View File

@ -93,11 +93,6 @@ typedef struct {
PyObject *sw_arg; PyObject *sw_arg;
} TaskStepMethWrapper; } TaskStepMethWrapper;
typedef struct {
PyObject_HEAD
TaskObj *ww_task;
} TaskWakeupMethWrapper;
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
PyObject *rl_loop; PyObject *rl_loop;
@ -1870,93 +1865,15 @@ TaskStepMethWrapper_new(TaskObj *task, PyObject *arg)
return (PyObject*) o; return (PyObject*) o;
} }
/* ----- Task._wakeup wrapper */ /* ----- Task._wakeup implementation */
static PyObject * static PyMethodDef TaskWakeupDef = {
TaskWakeupMethWrapper_call(TaskWakeupMethWrapper *o, "task_wakeup",
PyObject *args, PyObject *kwds) (PyCFunction)task_wakeup,
{ METH_O,
PyObject *fut; NULL
if (kwds != NULL && PyDict_GET_SIZE(kwds) != 0) {
PyErr_SetString(PyExc_TypeError, "function takes no keyword arguments");
return NULL;
}
if (!PyArg_ParseTuple(args, "O", &fut)) {
return NULL;
}
return task_wakeup(o->ww_task, fut);
}
static int
TaskWakeupMethWrapper_clear(TaskWakeupMethWrapper *o)
{
Py_CLEAR(o->ww_task);
return 0;
}
static int
TaskWakeupMethWrapper_traverse(TaskWakeupMethWrapper *o,
visitproc visit, void *arg)
{
Py_VISIT(o->ww_task);
return 0;
}
static void
TaskWakeupMethWrapper_dealloc(TaskWakeupMethWrapper *o)
{
PyObject_GC_UnTrack(o);
(void)TaskWakeupMethWrapper_clear(o);
Py_TYPE(o)->tp_free(o);
}
static PyObject *
TaskWakeupMethWrapper_get___self__(TaskWakeupMethWrapper *o, void *Py_UNUSED(ignored))
{
if (o->ww_task) {
Py_INCREF(o->ww_task);
return (PyObject*)o->ww_task;
}
Py_RETURN_NONE;
}
static PyGetSetDef TaskWakeupMethWrapper_getsetlist[] = {
{"__self__", (getter)TaskWakeupMethWrapper_get___self__, NULL, NULL},
{NULL} /* Sentinel */
}; };
static PyTypeObject TaskWakeupMethWrapper_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"TaskWakeupMethWrapper",
.tp_basicsize = sizeof(TaskWakeupMethWrapper),
.tp_itemsize = 0,
.tp_dealloc = (destructor)TaskWakeupMethWrapper_dealloc,
.tp_call = (ternaryfunc)TaskWakeupMethWrapper_call,
.tp_getattro = PyObject_GenericGetAttr,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.tp_traverse = (traverseproc)TaskWakeupMethWrapper_traverse,
.tp_clear = (inquiry)TaskWakeupMethWrapper_clear,
.tp_getset = TaskWakeupMethWrapper_getsetlist,
};
static PyObject *
TaskWakeupMethWrapper_new(TaskObj *task)
{
TaskWakeupMethWrapper *o;
o = PyObject_GC_New(TaskWakeupMethWrapper, &TaskWakeupMethWrapper_Type);
if (o == NULL) {
return NULL;
}
Py_INCREF(task);
o->ww_task = task;
PyObject_GC_Track(o);
return (PyObject*) o;
}
/* ----- Task introspection helpers */ /* ----- Task introspection helpers */
static int static int
@ -2803,7 +2720,7 @@ task_step_impl(TaskObj *task, PyObject *exc)
fut->fut_blocking = 0; fut->fut_blocking = 0;
/* result.add_done_callback(task._wakeup) */ /* result.add_done_callback(task._wakeup) */
wrapper = TaskWakeupMethWrapper_new(task); wrapper = PyCFunction_New(&TaskWakeupDef, (PyObject *)task);
if (wrapper == NULL) { if (wrapper == NULL) {
goto fail; goto fail;
} }
@ -2884,7 +2801,7 @@ task_step_impl(TaskObj *task, PyObject *exc)
goto fail; goto fail;
} }
wrapper = TaskWakeupMethWrapper_new(task); wrapper = PyCFunction_New(&TaskWakeupDef, (PyObject *)task);
if (wrapper == NULL) { if (wrapper == NULL) {
goto fail; goto fail;
} }
@ -3458,9 +3375,6 @@ PyInit__asyncio(void)
if (PyType_Ready(&TaskStepMethWrapper_Type) < 0) { if (PyType_Ready(&TaskStepMethWrapper_Type) < 0) {
return NULL; return NULL;
} }
if (PyType_Ready(&TaskWakeupMethWrapper_Type) < 0) {
return NULL;
}
if (PyType_Ready(&PyRunningLoopHolder_Type) < 0) { if (PyType_Ready(&PyRunningLoopHolder_Type) < 0) {
return NULL; return NULL;
} }