Skip to content

gh-137199: set associated module for _hashlib heap types #137203

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
60 changes: 27 additions & 33 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2480,7 +2480,19 @@ hashlib_free(void *m)
(void)hashlib_clear((PyObject *)m);
}

/* Py_mod_exec functions */
// --- Py_mod_exec helpers ----------------------------------------------------

static int
hashlib_make_type(PyTypeObject **out,
PyObject *module, PyType_Spec *specs, PyObject *bases)
{
assert(out != NULL);
*out = (PyTypeObject *)PyType_FromModuleAndSpec(module, specs, bases);
return *out == NULL ? -1 : PyModule_AddType(module, *out);
}

// --- Py_mod_exec functions --------------------------------------------------

static int
hashlib_init_hashtable(PyObject *module)
{
Expand All @@ -2498,53 +2510,35 @@ static int
hashlib_init_HASH_type(PyObject *module)
{
_hashlibstate *state = get_hashlib_state(module);

state->HASH_type = (PyTypeObject *)PyType_FromSpec(&HASHobject_type_spec);
if (state->HASH_type == NULL) {
return -1;
}
if (PyModule_AddType(module, state->HASH_type) < 0) {
return -1;
}
return 0;
return hashlib_make_type(
&state->HASH_type,
module, &HASHobject_type_spec, NULL
);
}

static int
hashlib_init_HASHXOF_type(PyObject *module)
{
#ifdef PY_OPENSSL_HAS_SHAKE
_hashlibstate *state = get_hashlib_state(module);

if (state->HASH_type == NULL) {
return -1;
}

state->HASHXOF_type = (PyTypeObject *)PyType_FromSpecWithBases(
&HASHXOFobject_type_spec, (PyObject *)state->HASH_type
assert(state->HASH_type != NULL);
return hashlib_make_type(
&state->HASHXOF_type,
module, &HASHXOFobject_type_spec, (PyObject *)state->HASH_type
);
if (state->HASHXOF_type == NULL) {
return -1;
}
if (PyModule_AddType(module, state->HASHXOF_type) < 0) {
return -1;
}
#endif
#else
return 0;
#endif
}

static int
hashlib_init_hmactype(PyObject *module)
{
_hashlibstate *state = get_hashlib_state(module);

state->HMAC_type = (PyTypeObject *)PyType_FromSpec(&HMACtype_spec);
if (state->HMAC_type == NULL) {
return -1;
}
if (PyModule_AddType(module, state->HMAC_type) < 0) {
return -1;
}
return 0;
return hashlib_make_type(
&state->HMAC_type,
module, &HMACtype_spec, NULL
);
}

static int
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy