From: Sergey B Kirpichev Date: Thu, 30 Jul 2026 15:02:59 +0000 (+0300) Subject: gh-154037: Fix race in the hash(Decimal) (#154045) X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=2f381f5a90474d9dad12e1e4946f348dd4b513bc;p=thirdparty%2FPython%2Fcpython.git gh-154037: Fix race in the hash(Decimal) (#154045) --- diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 6fbce0ed85e6..ac3ffb23248f 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -5935,11 +5935,13 @@ static Py_hash_t dec_hash(PyObject *op) { PyDecObject *self = _PyDecObject_CAST(op); - if (self->hash == -1) { - self->hash = _dec_hash(self); - } + Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED(self->hash); - return self->hash; + if (hash == -1) { + hash = _dec_hash(self); + FT_ATOMIC_STORE_SSIZE_RELAXED(self->hash, hash); + } + return hash; } /*[clinic input]