Skip to content

Commit 8f73b52

Browse files
committed
expose HASHLIB_GIL_MINSIZE
1 parent ca12a74 commit 8f73b52

File tree

7 files changed

+69
-20
lines changed

7 files changed

+69
-20
lines changed

Modules/_hashopenssl.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,16 @@ hashlib_exception(PyObject *module)
23582358
return 0;
23592359
}
23602360

2361+
static int
2362+
hashlib_constants(PyObject *module)
2363+
{
2364+
if (PyModule_AddIntConstant(module, "GIL_MINSIZE",
2365+
HASHLIB_GIL_MINSIZE) < 0)
2366+
{
2367+
return -1;
2368+
}
2369+
return 0;
2370+
}
23612371

23622372
static PyModuleDef_Slot hashlib_slots[] = {
23632373
{Py_mod_exec, hashlib_init_hashtable},
@@ -2367,6 +2377,7 @@ static PyModuleDef_Slot hashlib_slots[] = {
23672377
{Py_mod_exec, hashlib_md_meth_names},
23682378
{Py_mod_exec, hashlib_init_constructors},
23692379
{Py_mod_exec, hashlib_exception},
2380+
{Py_mod_exec, hashlib_constants},
23702381
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
23712382
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
23722383
{0, NULL}

Modules/blake2module.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ blake2_exec(PyObject *m)
229229
// good a place as any to probe the CPU flags.
230230
detect_cpu_features(&st->flags);
231231

232+
ADD_INT_CONST("GIL_MINSIZE", HASHLIB_GIL_MINSIZE);
233+
232234
st->blake2b_type = (PyTypeObject *)PyType_FromModuleAndSpec(
233235
m, &blake2b_type_spec, NULL);
234236

Modules/hmacmodule.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,20 @@ hmacmodule_init_strings(hmacmodule_state *state)
16791679
return 0;
16801680
}
16811681

1682+
static int
1683+
hmacmodule_init_globals(PyObject *module, hmacmodule_state *state)
1684+
{
1685+
#define ADD_INT_CONST(NAME, VALUE) \
1686+
do { \
1687+
if (PyModule_AddIntConstant(module, (NAME), (VALUE)) < 0) { \
1688+
return -1; \
1689+
} \
1690+
} while (0)
1691+
ADD_INT_CONST("GIL_MINSIZE", HASHLIB_GIL_MINSIZE);
1692+
#undef ADD_INT_CONST
1693+
return 0;
1694+
}
1695+
16821696
static void
16831697
hmacmodule_init_cpu_features(hmacmodule_state *state)
16841698
{
@@ -1769,6 +1783,9 @@ hmacmodule_exec(PyObject *module)
17691783
if (hmacmodule_init_strings(state) < 0) {
17701784
return -1;
17711785
}
1786+
if (hmacmodule_init_globals(module, state) < 0) {
1787+
return -1;
1788+
}
17721789
hmacmodule_init_cpu_features(state);
17731790
return 0;
17741791
}

Modules/md5module.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ md5_exec(PyObject *m)
370370
if (PyModule_AddObjectRef(m, "MD5Type", (PyObject *)st->md5_type) < 0) {
371371
return -1;
372372
}
373+
if (PyModule_AddIntConstant(m, "GIL_MINSIZE", HASHLIB_GIL_MINSIZE) < 0) {
374+
return -1;
375+
}
373376

374377
return 0;
375378
}
@@ -383,14 +386,14 @@ static PyModuleDef_Slot _md5_slots[] = {
383386

384387

385388
static struct PyModuleDef _md5module = {
386-
PyModuleDef_HEAD_INIT,
387-
.m_name = "_md5",
388-
.m_size = sizeof(MD5State),
389-
.m_methods = MD5_functions,
390-
.m_slots = _md5_slots,
391-
.m_traverse = _md5_traverse,
392-
.m_clear = _md5_clear,
393-
.m_free = _md5_free,
389+
PyModuleDef_HEAD_INIT,
390+
.m_name = "_md5",
391+
.m_size = sizeof(MD5State),
392+
.m_methods = MD5_functions,
393+
.m_slots = _md5_slots,
394+
.m_traverse = _md5_traverse,
395+
.m_clear = _md5_clear,
396+
.m_free = _md5_free,
394397
};
395398

396399
PyMODINIT_FUNC

Modules/sha1module.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,15 @@ _sha1_exec(PyObject *module)
362362
st->sha1_type = (PyTypeObject *)PyType_FromModuleAndSpec(
363363
module, &sha1_type_spec, NULL);
364364
if (PyModule_AddObjectRef(module,
365-
"SHA1Type",
366-
(PyObject *)st->sha1_type) < 0) {
365+
"SHA1Type",
366+
(PyObject *)st->sha1_type) < 0)
367+
{
368+
return -1;
369+
}
370+
if (PyModule_AddIntConstant(module,
371+
"GIL_MINSIZE",
372+
HASHLIB_GIL_MINSIZE) < 0)
373+
{
367374
return -1;
368375
}
369376

@@ -381,14 +388,14 @@ static PyModuleDef_Slot _sha1_slots[] = {
381388
};
382389

383390
static struct PyModuleDef _sha1module = {
384-
PyModuleDef_HEAD_INIT,
385-
.m_name = "_sha1",
386-
.m_size = sizeof(SHA1State),
387-
.m_methods = SHA1_functions,
388-
.m_slots = _sha1_slots,
389-
.m_traverse = _sha1_traverse,
390-
.m_clear = _sha1_clear,
391-
.m_free = _sha1_free
391+
PyModuleDef_HEAD_INIT,
392+
.m_name = "_sha1",
393+
.m_size = sizeof(SHA1State),
394+
.m_methods = SHA1_functions,
395+
.m_slots = _sha1_slots,
396+
.m_traverse = _sha1_traverse,
397+
.m_clear = _sha1_clear,
398+
.m_free = _sha1_free
392399
};
393400

394401
PyMODINIT_FUNC

Modules/sha2module.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,13 @@ static int sha2_exec(PyObject *module)
894894
return -1;
895895
}
896896

897+
if (PyModule_AddIntConstant(module,
898+
"GIL_MINSIZE",
899+
HASHLIB_GIL_MINSIZE) < 0)
900+
{
901+
return -1;
902+
}
903+
897904
return 0;
898905
}
899906

Modules/sha3module.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,10 @@ _sha3_exec(PyObject *m)
639639
init_sha3type(shake_256_type, SHAKE256_spec);
640640
#undef init_sha3type
641641

642-
if (PyModule_AddStringConstant(m, "implementation",
643-
"HACL") < 0) {
642+
if (PyModule_AddStringConstant(m, "implementation", "HACL") < 0) {
643+
return -1;
644+
}
645+
if (PyModule_AddIntConstant(m, "GIL_MINSIZE", HASHLIB_GIL_MINSIZE) < 0) {
644646
return -1;
645647
}
646648

0 commit comments

Comments
 (0)