]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-1635741: Port _abc extension to multiphase initialization (PEP 489) (GH-18030)
authorHai Shi <shihai1992@gmail.com>
Mon, 17 Feb 2020 13:50:35 +0000 (21:50 +0800)
committerGitHub <noreply@github.com>
Mon, 17 Feb 2020 13:50:35 +0000 (14:50 +0100)
Misc/NEWS.d/next/Core and Builtins/2020-01-16-12-00-04.bpo-1635741.fuqoBG.rst [new file with mode: 0644]
Modules/_abc.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-01-16-12-00-04.bpo-1635741.fuqoBG.rst b/Misc/NEWS.d/next/Core and Builtins/2020-01-16-12-00-04.bpo-1635741.fuqoBG.rst
new file mode 100644 (file)
index 0000000..4dd37a6
--- /dev/null
@@ -0,0 +1 @@
+Port _abc extension module to multiphase initialization (:pep:`489`).
index e21fe782d0a1852c686bafd57fdb6a85f976eccb..c991295d311a17342764bf0b671897d41473e3fa 100644 (file)
@@ -807,26 +807,35 @@ static struct PyMethodDef module_functions[] = {
     {NULL,       NULL}          /* sentinel */
 };
 
+static int
+_abc_exec(PyObject *module)
+{
+    if (PyType_Ready(&_abc_data_type) < 0) {
+        return -1;
+    }
+    _abc_data_type.tp_doc = abc_data_doc;
+    return 0;
+}
+
+static PyModuleDef_Slot _abc_slots[] = {
+    {Py_mod_exec, _abc_exec},
+    {0, NULL}
+};
+
 static struct PyModuleDef _abcmodule = {
     PyModuleDef_HEAD_INIT,
     "_abc",
     _abc__doc__,
-    -1,
+    0,
     module_functions,
-    NULL,
+    _abc_slots,
     NULL,
     NULL,
     NULL
 };
 
-
 PyMODINIT_FUNC
 PyInit__abc(void)
 {
-    if (PyType_Ready(&_abc_data_type) < 0) {
-        return NULL;
-    }
-    _abc_data_type.tp_doc = abc_data_doc;
-
-    return PyModule_Create(&_abcmodule);
+    return PyModuleDef_Init(&_abcmodule);
 }