← 返回首页
bpo-1635741: Port sha256 module to multiphase init (PEP 489) by koubaa · Pull Request #21189 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .rst  (1) All 2 file types selected Viewed files
Conversations
Failed to load comments. Retry
Loading
Jump to
Jump to file
Failed to load files. Retry
Loading
Diff view
Unified
Split
Hide whitespace
Apply and reload
Show whitespace
Diff view
Unified
Split
Hide whitespace
Apply and reload
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port :mod:`sha256` to multiphase initialization
58 changes: 30 additions & 28 deletions Modules/sha256module.c
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Comment thread
koubaa marked this conversation as resolved.
Show resolved Hide resolved
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);
}
Toggle all file notes Toggle all file annotations

Footer

© 2026 GitHub, Inc.