From 0f41abc83ea69a8abeae6a1cd31055d8b17839e9 Mon Sep 17 00:00:00 2001 From: Matt Page Date: Fri, 13 Dec 2024 10:49:34 -0800 Subject: [PATCH] Use _PyDictKeys_StringLookup and lock around it, rather than wasting out param --- Python/specialize.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Python/specialize.c b/Python/specialize.c index 00a0d52f40cef1..0af189e71e22b1 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -976,8 +976,13 @@ specialize_inline_values_access_lock_held( _PyAttrCache *cache = (_PyAttrCache *)(instr + 1); assert(PyUnicode_CheckExact(name)); _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(owner); - uint32_t version; - Py_ssize_t index = _PyDictKeys_StringLookupAndVersion(keys, name, &version); + #ifdef Py_GIL_DISABLED + PyMutex_LockFlags(&keys->dk_mutex, _Py_LOCK_DONT_DETACH); + #endif + Py_ssize_t index = _PyDictKeys_StringLookup(keys, name); + #ifdef Py_GIL_DISABLED + PyMutex_Unlock(&keys->dk_mutex); + #endif assert (index != DKIX_ERROR); if (index == DKIX_EMPTY) { SPECIALIZATION_FAIL(base_op, SPEC_FAIL_ATTR_NOT_IN_KEYS);