]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-124642: Dictionaries aren't marking objects as weakref'd (#124643)
authorDino Viehland <dinoviehland@meta.com>
Mon, 30 Sep 2024 17:04:32 +0000 (10:04 -0700)
committerGitHub <noreply@github.com>
Mon, 30 Sep 2024 17:04:32 +0000 (10:04 -0700)
Dictionaries aren't marking objects as weakref'd

Misc/NEWS.d/next/Core_and_Builtins/2024-09-27-17-18-53.gh-issue-124642.OCjhBJ.rst [new file with mode: 0644]
Objects/dictobject.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-09-27-17-18-53.gh-issue-124642.OCjhBJ.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-27-17-18-53.gh-issue-124642.OCjhBJ.rst
new file mode 100644 (file)
index 0000000..2976384
--- /dev/null
@@ -0,0 +1 @@
+Fixed scalability issue in free-threaded builds for lock-free reads from dictionaries in multi-threaded scenarios
index e50cf8bf1787f9190c4696da0c6cfbecf411ce27..ef9d23e62f95de3420f6350dfc9969e5ee139fe9 100644 (file)
@@ -1488,7 +1488,7 @@ read_failed:
     *value_addr = value;
     if (value != NULL) {
         assert(ix >= 0);
-        Py_INCREF(value);
+        _Py_NewRefWithLock(value);
     }
     Py_END_CRITICAL_SECTION();
     return ix;
@@ -7015,7 +7015,7 @@ _PyObject_TryGetInstanceAttribute(PyObject *obj, PyObject *name, PyObject **attr
             // Still no dict, we can read from the values
             assert(values->valid);
             value = values->values[ix];
-            *attr = Py_XNewRef(value);
+            *attr = _Py_XNewRefWithLock(value);
             success = true;
         }
 
@@ -7035,7 +7035,7 @@ _PyObject_TryGetInstanceAttribute(PyObject *obj, PyObject *name, PyObject **attr
 
     if (dict->ma_values == values && FT_ATOMIC_LOAD_UINT8(values->valid)) {
         value = _Py_atomic_load_ptr_relaxed(&values->values[ix]);
-        *attr = Py_XNewRef(value);
+        *attr = _Py_XNewRefWithLock(value);
         success = true;
     } else {
         // Caller needs to lookup from the dictionary