diff options
author | Vladimir Matveev <vladima@fb.com> | 2020-10-22 00:49:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-22 00:49:10 (GMT) |
commit | c8ba47b5518f83b5766fefe6f68557b5033e1d70 (patch) | |
tree | 9d2bdae20029425a53cb973774462c946e64088a /Modules/_asynciomodule.c | |
parent | 3c69f0c933d4790855929f1fcd74e4a0fefb5d52 (diff) | |
download | cpython-c8ba47b5518f83b5766fefe6f68557b5033e1d70.zip cpython-c8ba47b5518f83b5766fefe6f68557b5033e1d70.tar.gz cpython-c8ba47b5518f83b5766fefe6f68557b5033e1d70.tar.bz2 |
Delete TaskWakeupMethWrapper_Type and use PyCFunction instead (#22875)
Diffstat (limited to 'Modules/_asynciomodule.c')
-rw-r--r-- | Modules/_asynciomodule.c | 102 |
1 files changed, 8 insertions, 94 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index f01e588..90d288f 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -95,11 +95,6 @@ typedef struct { typedef struct { PyObject_HEAD - TaskObj *ww_task; -} TaskWakeupMethWrapper; - -typedef struct { - PyObject_HEAD PyObject *rl_loop; #if defined(HAVE_GETPID) && !defined(MS_WINDOWS) pid_t rl_pid; @@ -1870,93 +1865,15 @@ TaskStepMethWrapper_new(TaskObj *task, PyObject *arg) return (PyObject*) o; } -/* ----- Task._wakeup wrapper */ - -static PyObject * -TaskWakeupMethWrapper_call(TaskWakeupMethWrapper *o, - PyObject *args, PyObject *kwds) -{ - PyObject *fut; - - 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; -} +/* ----- Task._wakeup implementation */ -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 PyMethodDef TaskWakeupDef = { + "task_wakeup", + (PyCFunction)task_wakeup, + METH_O, + NULL }; -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 */ static int @@ -2803,7 +2720,7 @@ task_step_impl(TaskObj *task, PyObject *exc) fut->fut_blocking = 0; /* result.add_done_callback(task._wakeup) */ - wrapper = TaskWakeupMethWrapper_new(task); + wrapper = PyCFunction_New(&TaskWakeupDef, (PyObject *)task); if (wrapper == NULL) { goto fail; } @@ -2884,7 +2801,7 @@ task_step_impl(TaskObj *task, PyObject *exc) goto fail; } - wrapper = TaskWakeupMethWrapper_new(task); + wrapper = PyCFunction_New(&TaskWakeupDef, (PyObject *)task); if (wrapper == NULL) { goto fail; } @@ -3458,9 +3375,6 @@ PyInit__asyncio(void) if (PyType_Ready(&TaskStepMethWrapper_Type) < 0) { return NULL; } - if (PyType_Ready(&TaskWakeupMethWrapper_Type) < 0) { - return NULL; - } if (PyType_Ready(&PyRunningLoopHolder_Type) < 0) { return NULL; } |