From 46759bea9610750280c16d570777bc496f677a07 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Fri, 17 Jan 2020 00:21:16 +0800 Subject: [PATCH 1/2] Port _asyncio extension module to multiphase initialization(PEP 489) --- Modules/_asynciomodule.c | 88 +++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 70da40a8a3b863..5d1c5a07ea5288 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -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); } From 4f070d9c17d8c756ee84fa646e3f64f3c492fd58 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2020 16:30:22 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2020-01-16-16-30-18.bpo-1635741.bLqfQb.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-01-16-16-30-18.bpo-1635741.bLqfQb.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-01-16-16-30-18.bpo-1635741.bLqfQb.rst b/Misc/NEWS.d/next/Core and Builtins/2020-01-16-16-30-18.bpo-1635741.bLqfQb.rst new file mode 100644 index 00000000000000..c994066546f8ee --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-01-16-16-30-18.bpo-1635741.bLqfQb.rst @@ -0,0 +1 @@ +Port _asyncio extension module to multiphase initialization (:pep:`489`). \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy