File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -353,6 +353,7 @@ type_to_impl(PyTypeObject *type)
353353
354354typedef struct {
355355 PyObject_HEAD
356+ HASHLIB_MUTEX_API
356357 union {
357358 Hacl_Hash_Blake2s_state_t * blake2s_state ;
358359 Hacl_Hash_Blake2b_state_t * blake2b_state ;
@@ -364,8 +365,6 @@ typedef struct {
364365#endif
365366 };
366367 blake2_impl impl ;
367- bool use_mutex ;
368- PyMutex mutex ;
369368} Blake2Object ;
370369
371370#define _Blake2Object_CAST (op ) ((Blake2Object *)(op))
Original file line number Diff line number Diff line change 22
33#include "pycore_lock.h" // PyMutex
44
5+ #define HASHLIB_MUTEX_API \
6+ /*
7+ * Attributes to prevent undefined behaviors
8+ * via multiple threads entering the C API.
9+ */ \
10+ bool use_mutex; \
11+ PyMutex mutex;
12+
513/*
614 * Given a PyObject* obj, fill in the Py_buffer* viewp with the result
715 * of PyObject_GetBuffer. Sets an exception and issues the erraction
Original file line number Diff line number Diff line change @@ -383,9 +383,7 @@ typedef Hacl_Streaming_HMAC_agile_state HACL_HMAC_state;
383383
384384typedef struct HMACObject {
385385 PyObject_HEAD
386-
387- bool use_mutex ;
388- PyMutex mutex ;
386+ HASHLIB_MUTEX_API
389387
390388 // Hash function information
391389 PyObject * name ; // rendered name (exact unicode object)
Original file line number Diff line number Diff line change @@ -39,9 +39,7 @@ class MD5Type "MD5object *" "&PyType_Type"
3939
4040typedef struct {
4141 PyObject_HEAD
42- // Prevents undefined behavior via multiple threads entering the C API.
43- bool use_mutex ;
44- PyMutex mutex ;
42+ HASHLIB_MUTEX_API
4543 Hacl_Hash_MD5_state_t * hash_state ;
4644} MD5object ;
4745
Original file line number Diff line number Diff line change @@ -39,10 +39,7 @@ class SHA1Type "SHA1object *" "&PyType_Type"
3939
4040typedef struct {
4141 PyObject_HEAD
42- // Prevents undefined behavior via multiple threads entering the C API.
43- bool use_mutex ;
44- PyMutex mutex ;
45- PyThread_type_lock lock ;
42+ HASHLIB_MUTEX_API
4643 Hacl_Hash_SHA1_state_t * hash_state ;
4744} SHA1object ;
4845
Original file line number Diff line number Diff line change @@ -52,18 +52,14 @@ class SHA512Type "SHA512object *" "&PyType_Type"
5252typedef struct {
5353 PyObject_HEAD
5454 int digestsize ;
55- // Prevents undefined behavior via multiple threads entering the C API.
56- bool use_mutex ;
57- PyMutex mutex ;
55+ HASHLIB_MUTEX_API
5856 Hacl_Hash_SHA2_state_t_256 * state ;
5957} SHA256object ;
6058
6159typedef struct {
6260 PyObject_HEAD
6361 int digestsize ;
64- // Prevents undefined behavior via multiple threads entering the C API.
65- bool use_mutex ;
66- PyMutex mutex ;
62+ HASHLIB_MUTEX_API
6763 Hacl_Hash_SHA2_state_t_512 * state ;
6864} SHA512object ;
6965
Original file line number Diff line number Diff line change @@ -60,9 +60,7 @@ class _sha3.shake_256 "SHA3object *" "&SHAKE256type"
6060
6161typedef struct {
6262 PyObject_HEAD
63- // Prevents undefined behavior via multiple threads entering the C API.
64- bool use_mutex ;
65- PyMutex mutex ;
63+ HASHLIB_MUTEX_API
6664 Hacl_Hash_SHA3_state_t * hash_state ;
6765} SHA3object ;
6866
You can’t perform that action at this time.
0 commit comments