Skip to content

Commit e5dfcea

Browse files
[3.13] gh-117657: Fix data races report by TSAN unicode-hash (gh-119907) (gh-119963)
gh-117657: Fix data races report by TSAN unicode-hash (gh-119907) (cherry picked from commit 0594a27) Co-authored-by: Donghee Na <donghee.na@python.org>
1 parent 3709e1b commit e5dfcea

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Objects/unicodeobject.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ unicode_modifiable(PyObject *unicode)
16251625
assert(_PyUnicode_CHECK(unicode));
16261626
if (Py_REFCNT(unicode) != 1)
16271627
return 0;
1628-
if (_PyUnicode_HASH(unicode) != -1)
1628+
if (FT_ATOMIC_LOAD_SSIZE_RELAXED(_PyUnicode_HASH(unicode)) != -1)
16291629
return 0;
16301630
if (PyUnicode_CHECK_INTERNED(unicode))
16311631
return 0;
@@ -10819,9 +10819,10 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right)
1081910819
if (PyUnicode_CHECK_INTERNED(left))
1082010820
return 0;
1082110821

10822-
assert(_PyUnicode_HASH(right_uni) != -1);
10823-
Py_hash_t hash = _PyUnicode_HASH(left);
10824-
if (hash != -1 && hash != _PyUnicode_HASH(right_uni)) {
10822+
Py_hash_t right_hash = FT_ATOMIC_LOAD_SSIZE_RELAXED(_PyUnicode_HASH(right_uni));
10823+
assert(right_hash != -1);
10824+
Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED(_PyUnicode_HASH(left));
10825+
if (hash != -1 && hash != right_hash) {
1082510826
return 0;
1082610827
}
1082710828

@@ -11306,12 +11307,14 @@ unicode_hash(PyObject *self)
1130611307
#ifdef Py_DEBUG
1130711308
assert(_Py_HashSecret_Initialized);
1130811309
#endif
11309-
if (_PyUnicode_HASH(self) != -1)
11310-
return _PyUnicode_HASH(self);
11311-
11310+
Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED(_PyUnicode_HASH(self));
11311+
if (hash != -1) {
11312+
return hash;
11313+
}
1131211314
x = _Py_HashBytes(PyUnicode_DATA(self),
1131311315
PyUnicode_GET_LENGTH(self) * PyUnicode_KIND(self));
11314-
_PyUnicode_HASH(self) = x;
11316+
11317+
FT_ATOMIC_STORE_SSIZE_RELAXED(_PyUnicode_HASH(self), x);
1131511318
return x;
1131611319
}
1131711320

Tools/tsan/suppressions_free_threading.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ race_top:set_discard_entry
4949
race_top:set_inheritable
5050
race_top:start_the_world
5151
race_top:tstate_set_detached
52-
race_top:unicode_hash
5352
race_top:Py_SET_TYPE
5453
race_top:_PyDict_CheckConsistency
5554
race_top:_PyImport_AcquireLock

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy