summaryrefslogtreecommitdiffstats
path: root/Modules/sha256module.c
diff options
context:
space:
mode:
authorMohamed Koubaa <koubaa.m@gmail.com>2020-07-03 08:59:47 (GMT)
committerGitHub <noreply@github.com>2020-07-03 08:59:47 (GMT)
commit9d006977d7ff5a45d6e7d696c1713fdf2dd308b7 (patch)
treec4bab2710d32ca07a4fec33c1e09c60aa395d972 /Modules/sha256module.c
parent148f32913573c29250dfb3f0d079eb8847633621 (diff)
downloadcpython-9d006977d7ff5a45d6e7d696c1713fdf2dd308b7.zip
cpython-9d006977d7ff5a45d6e7d696c1713fdf2dd308b7.tar.gz
cpython-9d006977d7ff5a45d6e7d696c1713fdf2dd308b7.tar.bz2
bpo-1635741: Port sha256 module to multiphase init (PEP 489) (GH-21189)
Diffstat (limited to 'Modules/sha256module.c')
-rw-r--r--Modules/sha256module.c58
1 files changed, 30 insertions, 28 deletions
diff --git a/Modules/sha256module.c b/Modules/sha256module.c
index 261f9da..06e4430 100644
--- a/Modules/sha256module.c
+++ b/Modules/sha256module.c
@@ -681,43 +681,45 @@ static struct PyMethodDef SHA_functions[] = {
{NULL, NULL} /* Sentinel */
};
-
-/* Initialize this module. */
-
-static struct PyModuleDef _sha256module = {
- PyModuleDef_HEAD_INIT,
- "_sha256",
- NULL,
- -1,
- SHA_functions,
- NULL,
- NULL,
- NULL,
- NULL
-};
-
-PyMODINIT_FUNC
-PyInit__sha256(void)
+static int sha256_exec(PyObject *module)
{
- PyObject *m;
-
Py_SET_TYPE(&SHA224type, &PyType_Type);
if (PyType_Ready(&SHA224type) < 0) {
- return NULL;
+ return -1;
}
Py_SET_TYPE(&SHA256type, &PyType_Type);
if (PyType_Ready(&SHA256type) < 0) {
- return NULL;
+ return -1;
}
- m = PyModule_Create(&_sha256module);
- if (m == NULL)
- return NULL;
-
Py_INCREF((PyObject *)&SHA224type);
- PyModule_AddObject(m, "SHA224Type", (PyObject *)&SHA224type);
+ if (PyModule_AddObject(module, "SHA224Type", (PyObject *)&SHA224type) < 0) {
+ Py_DECREF((PyObject *)&SHA224type);
+ return -1;
+ }
Py_INCREF((PyObject *)&SHA256type);
- PyModule_AddObject(m, "SHA256Type", (PyObject *)&SHA256type);
- return m;
+ if (PyModule_AddObject(module, "SHA256Type", (PyObject *)&SHA256type) < 0) {
+ Py_DECREF((PyObject *)&SHA256type);
+ return -1;
+ }
+ return 0;
+}
+
+static PyModuleDef_Slot _sha256_slots[] = {
+ {Py_mod_exec, sha256_exec},
+ {0, NULL}
+};
+
+static struct PyModuleDef _sha256module = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "_sha256",
+ .m_methods = SHA_functions,
+ .m_slots = _sha256_slots,
+};
+/* Initialize this module. */
+PyMODINIT_FUNC
+PyInit__sha256(void)
+{
+ return PyModuleDef_Init(&_sha256module);
}