bpo-44145: Release the GIL around HMAC_Update. (GH-26157)

It was always meant to be released for parallelization.
This now matches the other similar code in the module.

Thanks michaelforney for noticing!
This commit is contained in:
Gregory P. Smith 2021-05-17 00:35:16 -07:00 committed by GitHub
parent b102dd598d
commit c10392e7dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -0,0 +1,3 @@
:mod:`hmac` computations were not releasing the GIL while calling the
OpenSSL ``HMAC_Update`` C API (a new feature in 3.9). This unintentionally
prevented parallel computation as other :mod:`hashlib` algorithms support.

View File

@ -1496,9 +1496,11 @@ _hmac_update(HMACobject *self, PyObject *obj)
} }
if (self->lock != NULL) { if (self->lock != NULL) {
ENTER_HASHLIB(self); Py_BEGIN_ALLOW_THREADS
PyThread_acquire_lock(self->lock, 1);
r = HMAC_Update(self->ctx, (const unsigned char*)view.buf, view.len); r = HMAC_Update(self->ctx, (const unsigned char*)view.buf, view.len);
LEAVE_HASHLIB(self); PyThread_release_lock(self->lock);
Py_END_ALLOW_THREADS
} else { } else {
r = HMAC_Update(self->ctx, (const unsigned char*)view.buf, view.len); r = HMAC_Update(self->ctx, (const unsigned char*)view.buf, view.len);
} }