Skip to content

Commit 4563481

Browse files
committed
ifdef Py_GIL_DISABLED, change news
1 parent 2767d89 commit 4563481

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix a possible data and PY_EVP_MD refcount race in _hashopenssl.c py_digest_by_name() under free-threading.
1+
Fix possible extra reference when using objects returned by :func:`hashlib.sha256` under :term:`free threading`.

Modules/_hashopenssl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,16 +384,24 @@ py_digest_by_name(PyObject *module, const char *name, enum Py_hash_type py_ht)
384384
digest = FT_ATOMIC_LOAD_PTR_RELAXED(entry->evp);
385385
if (digest == NULL) {
386386
digest = PY_EVP_MD_fetch(entry->ossl_name, NULL);
387+
#ifdef Py_GIL_DISABLED
387388
// exchange just in case another thread did same thing at same time
388389
other_digest = _Py_atomic_exchange_ptr(&entry->evp, digest);
390+
#else
391+
entry->evp = digest;
392+
#endif
389393
}
390394
break;
391395
case Py_ht_evp_nosecurity:
392396
digest = FT_ATOMIC_LOAD_PTR_RELAXED(entry->evp_nosecurity);
393397
if (digest == NULL) {
394398
digest = PY_EVP_MD_fetch(entry->ossl_name, "-fips");
399+
#ifdef Py_GIL_DISABLED
395400
// exchange just in case another thread did same thing at same time
396401
other_digest = _Py_atomic_exchange_ptr(&entry->evp_nosecurity, digest);
402+
#else
403+
entry->evp_nosecurity = digest;
404+
#endif
397405
}
398406
break;
399407
}

0 commit comments

Comments
 (0)