[Python-checkins] bpo-1635741: Port _hashlib to multiphase initialization (GH-23358)

tiran webhook-mailer at python.org
Wed Nov 18 10:12:22 EST 2020


https://github.com/python/cpython/commit/46f59ebd01e22cc6a56fd0691217318c1d801a49
commit: 46f59ebd01e22cc6a56fd0691217318c1d801a49
branch: master
author: Christian Heimes <christian at python.org>
committer: tiran <christian at python.org>
date: 2020-11-18T16:12:13+01:00
summary:

bpo-1635741: Port _hashlib to multiphase initialization (GH-23358)

Signed-off-by: Christian Heimes <christian at python.org>

files:
A Misc/NEWS.d/next/C API/2020-11-18-08-45-36.bpo-1635741.VLZfiY.rst
M Modules/_hashopenssl.c

diff --git a/Misc/NEWS.d/next/C API/2020-11-18-08-45-36.bpo-1635741.VLZfiY.rst b/Misc/NEWS.d/next/C API/2020-11-18-08-45-36.bpo-1635741.VLZfiY.rst
new file mode 100644
index 0000000000000..2300170587d7e
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2020-11-18-08-45-36.bpo-1635741.VLZfiY.rst	
@@ -0,0 +1 @@
+Port _hashlib extension module to multiphase initialization (:pep:`489`)
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index adc8653773250..56d2a77049e34 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -2078,7 +2078,6 @@ hashlib_init_hmactype(PyObject *module)
     return 0;
 }
 
-#if 0
 static PyModuleDef_Slot hashlib_slots[] = {
     /* OpenSSL 1.0.2 and LibreSSL */
     {Py_mod_exec, hashlib_openssl_legacy_init},
@@ -2088,7 +2087,6 @@ static PyModuleDef_Slot hashlib_slots[] = {
     {Py_mod_exec, hashlib_md_meth_names},
     {0, NULL}
 };
-#endif
 
 static struct PyModuleDef _hashlibmodule = {
     PyModuleDef_HEAD_INIT,
@@ -2096,7 +2094,7 @@ static struct PyModuleDef _hashlibmodule = {
     .m_doc = "OpenSSL interface for hashlib module",
     .m_size = sizeof(_hashlibstate),
     .m_methods = EVP_functions,
-    .m_slots = NULL,
+    .m_slots = hashlib_slots,
     .m_traverse = hashlib_traverse,
     .m_clear = hashlib_clear,
     .m_free = hashlib_free
@@ -2105,37 +2103,5 @@ static struct PyModuleDef _hashlibmodule = {
 PyMODINIT_FUNC
 PyInit__hashlib(void)
 {
-    PyObject *m = PyState_FindModule(&_hashlibmodule);
-    if (m != NULL) {
-        Py_INCREF(m);
-        return m;
-    }
-
-    m = PyModule_Create(&_hashlibmodule);
-    if (m == NULL) {
-        return NULL;
-    }
-
-    if (hashlib_openssl_legacy_init(m) < 0) {
-        Py_DECREF(m);
-        return NULL;
-    }
-    if (hashlib_init_evptype(m) < 0) {
-        Py_DECREF(m);
-        return NULL;
-    }
-    if (hashlib_init_evpxoftype(m) < 0) {
-        Py_DECREF(m);
-        return NULL;
-    }
-    if (hashlib_init_hmactype(m) < 0) {
-        Py_DECREF(m);
-        return NULL;
-    }
-    if (hashlib_md_meth_names(m) == -1) {
-        Py_DECREF(m);
-        return NULL;
-    }
-
-    return m;
+    return PyModuleDef_Init(&_hashlibmodule);
 }



More information about the Python-checkins mailing list