Skip to content

Commit 2f381f5

Browse files
authored
gh-154037: Fix race in the hash(Decimal) (#154045)
1 parent 405daf5 commit 2f381f5

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Modules/_decimal/_decimal.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5935,11 +5935,13 @@ static Py_hash_t
59355935
dec_hash(PyObject *op)
59365936
{
59375937
PyDecObject *self = _PyDecObject_CAST(op);
5938-
if (self->hash == -1) {
5939-
self->hash = _dec_hash(self);
5940-
}
5938+
Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED(self->hash);
59415939

5942-
return self->hash;
5940+
if (hash == -1) {
5941+
hash = _dec_hash(self);
5942+
FT_ATOMIC_STORE_SSIZE_RELAXED(self->hash, hash);
5943+
}
5944+
return hash;
59435945
}
59445946

59455947
/*[clinic input]

0 commit comments

Comments
 (0)