Skip to content
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

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

Merged
merged 1 commit into from
Nov 18, 2020
Merged
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 _hashlib extension module to multiphase initialization (:pep:`489`)
38 changes: 2 additions & 36 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -2088,15 +2087,14 @@ static PyModuleDef_Slot hashlib_slots[] = {
{Py_mod_exec, hashlib_md_meth_names},
{0, NULL}
};
#endif

static struct PyModuleDef _hashlibmodule = {
PyModuleDef_HEAD_INIT,
.m_name = "_hashlib",
.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
Expand All @@ -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);
}