From 9ad0c7b0f14c5fcda6bfae6692c88abb95502d38 Mon Sep 17 00:00:00 2001 From: Peter Hawkins Date: Tue, 13 May 2025 13:38:57 -0400 Subject: gh-132641: fix race in `lru_cache` under free-threading (#133787) Fix race in `lru_cache` by acquiring critical section on the cache object itself and call the lock held variant of dict functions to modify the underlying dict. --- Objects/dictobject.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Objects/dictobject.c') diff --git a/Objects/dictobject.c b/Objects/dictobject.c index ce27e47dabf..fd8ccf56324 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2915,6 +2915,11 @@ clear_lock_held(PyObject *op) ASSERT_CONSISTENT(mp); } +void +_PyDict_Clear_LockHeld(PyObject *op) { + clear_lock_held(op); +} + void PyDict_Clear(PyObject *op) { -- cgit v1.2.3