Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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
Changes from 1 commit
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
Next Next commit
Port _asyncio extension module to multiphase initialization(PEP 489)
  • Loading branch information
shihai1991 committed Jan 16, 2020
commit 46759bea9610750280c16d570777bc496f677a07
88 changes: 46 additions & 42 deletions 88 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);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.