From 327dd732ce2b7df001b0a052e3464c85f0c85128 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 22 Oct 2013 15:05:23 +0200 Subject: [PATCH] Issue #18742: Expose the internal hash type object for ABCs. --- Modules/_hashopenssl.c | 4 +--- Modules/_sha3/sha3module.c | 10 +++++++++- Modules/md5module.c | 11 ++++++++++- Modules/sha1module.c | 11 ++++++++++- Modules/sha256module.c | 14 +++++++++++++- Modules/sha512module.c | 13 ++++++++++++- 6 files changed, 55 insertions(+), 8 deletions(-) diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 222e5efe5e0..423b3b3a476 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -872,10 +872,8 @@ PyInit__hashlib(void) return NULL; } -#if HASH_OBJ_CONSTRUCTOR - Py_INCREF(&EVPtype); + Py_INCREF((PyObject *)&EVPtype); PyModule_AddObject(m, "HASH", (PyObject *)&EVPtype); -#endif /* these constants are used by the convenience constructors */ INIT_CONSTRUCTOR_CONSTANTS(md5); diff --git a/Modules/_sha3/sha3module.c b/Modules/_sha3/sha3module.c index 4e6352b7baf..71127d0b76c 100644 --- a/Modules/_sha3/sha3module.c +++ b/Modules/_sha3/sha3module.c @@ -576,10 +576,18 @@ static struct PyModuleDef _SHA3module = { PyMODINIT_FUNC PyInit__sha3(void) { + PyObject *m; + Py_TYPE(&SHA3type) = &PyType_Type; if (PyType_Ready(&SHA3type) < 0) { return NULL; } - return PyModule_Create(&_SHA3module); + m = PyModule_Create(&_SHA3module); + if (m == NULL) + return NULL; + + Py_INCREF((PyObject *)&SHA3type); + PyModule_AddObject(m, "SHA3Type", (PyObject *)&SHA3type); + return m; } diff --git a/Modules/md5module.c b/Modules/md5module.c index bb91b6c3698..5cb3d36c9b0 100644 --- a/Modules/md5module.c +++ b/Modules/md5module.c @@ -572,8 +572,17 @@ static struct PyModuleDef _md5module = { PyMODINIT_FUNC PyInit__md5(void) { + PyObject *m; + Py_TYPE(&MD5type) = &PyType_Type; if (PyType_Ready(&MD5type) < 0) return NULL; - return PyModule_Create(&_md5module); + + m = PyModule_Create(&_md5module); + if (m == NULL) + return NULL; + + Py_INCREF((PyObject *)&MD5type); + PyModule_AddObject(m, "MD5Type", (PyObject *)&MD5type); + return m; } diff --git a/Modules/sha1module.c b/Modules/sha1module.c index 403194c06be..b44fe189d26 100644 --- a/Modules/sha1module.c +++ b/Modules/sha1module.c @@ -544,8 +544,17 @@ static struct PyModuleDef _sha1module = { PyMODINIT_FUNC PyInit__sha1(void) { + PyObject *m; + Py_TYPE(&SHA1type) = &PyType_Type; if (PyType_Ready(&SHA1type) < 0) return NULL; - return PyModule_Create(&_sha1module); + + m = PyModule_Create(&_sha1module); + if (m == NULL) + return NULL; + + Py_INCREF((PyObject *)&SHA1type); + PyModule_AddObject(m, "SHA1Type", (PyObject *)&SHA1type); + return m; } diff --git a/Modules/sha256module.c b/Modules/sha256module.c index e60111ad02d..b05bfc172f5 100644 --- a/Modules/sha256module.c +++ b/Modules/sha256module.c @@ -706,11 +706,23 @@ static struct PyModuleDef _sha256module = { PyMODINIT_FUNC PyInit__sha256(void) { + PyObject *m; + Py_TYPE(&SHA224type) = &PyType_Type; if (PyType_Ready(&SHA224type) < 0) return NULL; Py_TYPE(&SHA256type) = &PyType_Type; if (PyType_Ready(&SHA256type) < 0) return NULL; - return PyModule_Create(&_sha256module); + + m = PyModule_Create(&_sha256module); + if (m == NULL) + return NULL; + + Py_INCREF((PyObject *)&SHA224type); + PyModule_AddObject(m, "SHA224Type", (PyObject *)&SHA224type); + Py_INCREF((PyObject *)&SHA256type); + PyModule_AddObject(m, "SHA256Type", (PyObject *)&SHA256type); + return m; + } diff --git a/Modules/sha512module.c b/Modules/sha512module.c index 2841eabb2bf..47c57e5c428 100644 --- a/Modules/sha512module.c +++ b/Modules/sha512module.c @@ -772,13 +772,24 @@ static struct PyModuleDef _sha512module = { PyMODINIT_FUNC PyInit__sha512(void) { + PyObject *m; + Py_TYPE(&SHA384type) = &PyType_Type; if (PyType_Ready(&SHA384type) < 0) return NULL; Py_TYPE(&SHA512type) = &PyType_Type; if (PyType_Ready(&SHA512type) < 0) return NULL; - return PyModule_Create(&_sha512module); + + m = PyModule_Create(&_sha512module); + if (m == NULL) + return NULL; + + Py_INCREF((PyObject *)&SHA384type); + PyModule_AddObject(m, "SHA384Type", (PyObject *)&SHA384type); + Py_INCREF((PyObject *)&SHA512type); + PyModule_AddObject(m, "SHA512Type", (PyObject *)&SHA512type); + return m; } #endif