gh-132993: expose HASHLIB_GIL_MINSIZE to private extension modules (#132999)

This commit is contained in:
Bénédikt Tran 2025-04-28 00:20:15 +02:00 committed by GitHub
parent 019ee49d50
commit 3695ba93d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 119 additions and 28 deletions

View file

@ -20,6 +20,7 @@ import unittest
import warnings
from test import support
from test.support import _4G, bigmemtest
from test.support import hashlib_helper
from test.support.import_helper import import_fresh_module
from test.support import requires_resource
from test.support import threading_helper
@ -911,10 +912,13 @@ class HashLibTestCase(unittest.TestCase):
def test_gil(self):
# Check things work fine with an input larger than the size required
# for multithreaded operation (which is hardwired to 2048).
gil_minsize = 2048
# for multithreaded operation. Currently, all cryptographic modules
# have the same constant value (2048) but in the future it might not
# be the case.
mods = ['_md5', '_sha1', '_sha2', '_sha3', '_blake2', '_hashlib']
gil_minsize = hashlib_helper.find_gil_minsize(mods)
for cons in self.hash_constructors:
# constructors belong to one of the above modules
m = cons(usedforsecurity=False)
m.update(b'1')
m.update(b'#' * gil_minsize)
@ -923,6 +927,8 @@ class HashLibTestCase(unittest.TestCase):
m = cons(b'x' * gil_minsize, usedforsecurity=False)
m.update(b'1')
def test_sha256_gil(self):
gil_minsize = hashlib_helper.find_gil_minsize(['_sha2', '_hashlib'])
m = hashlib.sha256()
m.update(b'1')
m.update(b'#' * gil_minsize)