mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
[3.13] gh-117657: Fix data races reported by TSAN in some set methods (GH-120914) (#121240)
Refactor the fast Unicode hash check into `_PyObject_HashFast` and use relaxed
atomic loads in the free-threaded build.
After this change, the TSAN doesn't report data races for this method.
(cherry picked from commit 294e724964
)
Co-authored-by: AN Long <aisk@users.noreply.github.com>
This commit is contained in:
parent
fc0b1cbdfe
commit
06fd745dd9
6 changed files with 81 additions and 121 deletions
|
@ -628,6 +628,20 @@ _PyObject_IS_GC(PyObject *obj)
|
|||
&& (type->tp_is_gc == NULL || type->tp_is_gc(obj)));
|
||||
}
|
||||
|
||||
// Fast inlined version of PyObject_Hash()
|
||||
static inline Py_hash_t
|
||||
_PyObject_HashFast(PyObject *op)
|
||||
{
|
||||
if (PyUnicode_CheckExact(op)) {
|
||||
Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED(
|
||||
_PyASCIIObject_CAST(op)->hash);
|
||||
if (hash != -1) {
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
return PyObject_Hash(op);
|
||||
}
|
||||
|
||||
// Fast inlined version of PyType_IS_GC()
|
||||
#define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue