Skip to content

bpo-1635741: Port _asyncio extension module to multiphase initialization(PEP 489) #18032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port _asyncio extension module to multiphase initialization (:pep:`489`).
88 changes: 46 additions & 42 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3372,76 +3372,80 @@ static PyMethodDef asyncio_methods[] = {
{NULL, NULL}
};

static struct PyModuleDef _asynciomodule = {
PyModuleDef_HEAD_INIT, /* m_base */
"_asyncio", /* m_name */
module_doc, /* m_doc */
-1, /* m_size */
asyncio_methods, /* m_methods */
NULL, /* m_slots */
NULL, /* m_traverse */
NULL, /* m_clear */
(freefunc)module_free /* m_free */
};


PyMODINIT_FUNC
PyInit__asyncio(void)
static int
_asyncio_exec(PyObject *module)
{
if (module_init() < 0) {
return NULL;
}
if (PyType_Ready(&FutureType) < 0) {
return NULL;
return -1;
}
if (PyType_Ready(&FutureIterType) < 0) {
return NULL;
return -1;
}
if (PyType_Ready(&TaskStepMethWrapper_Type) < 0) {
return NULL;
return -1;
}
if (PyType_Ready(&TaskWakeupMethWrapper_Type) < 0) {
return NULL;
return -1;
}
if (PyType_Ready(&TaskType) < 0) {
return NULL;
return -1;
}
if (PyType_Ready(&PyRunningLoopHolder_Type) < 0) {
return NULL;
}

PyObject *m = PyModule_Create(&_asynciomodule);
if (m == NULL) {
return NULL;
return -1;
}

Py_INCREF(&FutureType);
if (PyModule_AddObject(m, "Future", (PyObject *)&FutureType) < 0) {
if (PyModule_AddObject(module, "Future", (PyObject *)&FutureType) < 0) {
Py_DECREF(&FutureType);
Py_DECREF(m);
return NULL;
Py_DECREF(module);
return -1;
}

Py_INCREF(&TaskType);
if (PyModule_AddObject(m, "Task", (PyObject *)&TaskType) < 0) {
if (PyModule_AddObject(module, "Task", (PyObject *)&TaskType) < 0) {
Py_DECREF(&TaskType);
Py_DECREF(m);
return NULL;
Py_DECREF(module);
return -1;
}

Py_INCREF(all_tasks);
if (PyModule_AddObject(m, "_all_tasks", all_tasks) < 0) {
if (PyModule_AddObject(module, "_all_tasks", all_tasks) < 0) {
Py_DECREF(all_tasks);
Py_DECREF(m);
return NULL;
Py_DECREF(module);
return -1;
}

Py_INCREF(current_tasks);
if (PyModule_AddObject(m, "_current_tasks", current_tasks) < 0) {
if (PyModule_AddObject(module, "_current_tasks", current_tasks) < 0) {
Py_DECREF(current_tasks);
Py_DECREF(m);
return NULL;
Py_DECREF(module);
return -1;
}
return 0;
}

static PyModuleDef_Slot _asyncio_slots[] = {
{Py_mod_exec, _asyncio_exec},
{0, NULL}
};

static struct PyModuleDef _asynciomodule = {
PyModuleDef_HEAD_INIT, /* m_base */
"_asyncio", /* m_name */
module_doc, /* m_doc */
0, /* m_size */
asyncio_methods, /* m_methods */
_asyncio_slots, /* m_slots */
NULL, /* m_traverse */
NULL, /* m_clear */
(freefunc)module_free /* m_free */
};

return m;
PyMODINIT_FUNC
PyInit__asyncio(void)
{
if (module_init() < 0) {
return NULL;
}
return PyModuleDef_Init(&_asynciomodule);
}