]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-132013: use relaxed atomics in hash of frozenset (#132014)
authorKumar Aditya <kumaraditya@python.org>
Wed, 2 Apr 2025 14:31:05 +0000 (20:01 +0530)
committerGitHub <noreply@github.com>
Wed, 2 Apr 2025 14:31:05 +0000 (20:01 +0530)
Use relaxed atomics in hash of `frozenset` to fix TSAN warning.

Objects/setobject.c

index 5ad83c3f1633b9ad43b8b22ef88db95025c6e0c7..f65d458f7924c3b346043ca2452007162fd93542 100644 (file)
@@ -793,12 +793,12 @@ frozenset_hash(PyObject *self)
     PySetObject *so = _PySet_CAST(self);
     Py_uhash_t hash;
 
-    if (so->hash != -1) {
-        return so->hash;
+    if (FT_ATOMIC_LOAD_SSIZE_RELAXED(so->hash) != -1) {
+        return FT_ATOMIC_LOAD_SSIZE_RELAXED(so->hash);
     }
 
     hash = frozenset_hash_impl(self);
-    so->hash = hash;
+    FT_ATOMIC_STORE_SSIZE_RELAXED(so->hash, hash);
     return hash;
 }