]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44145: Release the GIL around HMAC_Update. (GH-26157)
authorGregory P. Smith <greg@krypto.org>
Mon, 17 May 2021 07:35:16 +0000 (00:35 -0700)
committerGitHub <noreply@github.com>
Mon, 17 May 2021 07:35:16 +0000 (00:35 -0700)
It was always meant to be released for parallelization.
This now matches the other similar code in the module.

Thanks michaelforney for noticing!

Misc/NEWS.d/next/Library/2021-05-16-00-00-38.bpo-44145.ko5SJ7.rst [new file with mode: 0644]
Modules/_hashopenssl.c

diff --git a/Misc/NEWS.d/next/Library/2021-05-16-00-00-38.bpo-44145.ko5SJ7.rst b/Misc/NEWS.d/next/Library/2021-05-16-00-00-38.bpo-44145.ko5SJ7.rst
new file mode 100644 (file)
index 0000000..4022218
--- /dev/null
@@ -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.
index e4a28853775672f8b1da0f1c182b7177ce5af6bb..b9e68c05c3edbeec2d1d75f1f19333a2ffcf4f54 100644 (file)
@@ -1496,9 +1496,11 @@ _hmac_update(HMACobject *self, PyObject *obj)
     }
 
     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);
-        LEAVE_HASHLIB(self);
+        PyThread_release_lock(self->lock);
+        Py_END_ALLOW_THREADS
     } else {
         r = HMAC_Update(self->ctx, (const unsigned char*)view.buf, view.len);
     }