Skip to content

Commit 44ba11a

Browse files
[3.13] pythongh-124642: Dictionaries aren't marking objects as weakref'd (pythonGH-124643) (python#124798)
pythongh-124642: Dictionaries aren't marking objects as weakref'd (pythonGH-124643) Dictionaries aren't marking objects as weakref'd (cherry picked from commit 077e7ef) Co-authored-by: Dino Viehland <dinoviehland@meta.com>
1 parent fe58596 commit 44ba11a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed scalability issue in free-threaded builds for lock-free reads from dictionaries in multi-threaded scenarios

Objects/dictobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyOb
15491549
*value_addr = value;
15501550
if (value != NULL) {
15511551
assert(ix >= 0);
1552-
Py_INCREF(value);
1552+
_Py_NewRefWithLock(value);
15531553
}
15541554
Py_END_CRITICAL_SECTION();
15551555
return ix;
@@ -6988,7 +6988,7 @@ _PyObject_TryGetInstanceAttribute(PyObject *obj, PyObject *name, PyObject **attr
69886988
// Still no dict, we can read from the values
69896989
assert(values->valid);
69906990
value = values->values[ix];
6991-
*attr = Py_XNewRef(value);
6991+
*attr = _Py_XNewRefWithLock(value);
69926992
success = true;
69936993
}
69946994

@@ -7008,7 +7008,7 @@ _PyObject_TryGetInstanceAttribute(PyObject *obj, PyObject *name, PyObject **attr
70087008

70097009
if (dict->ma_values == values && FT_ATOMIC_LOAD_UINT8(values->valid)) {
70107010
value = _Py_atomic_load_ptr_relaxed(&values->values[ix]);
7011-
*attr = Py_XNewRef(value);
7011+
*attr = _Py_XNewRefWithLock(value);
70127012
success = true;
70137013
} else {
70147014
// Caller needs to lookup from the dictionary

0 commit comments

Comments
 (0)