Skip to content

Commit 077e7ef

Browse files
authored
pythongh-124642: Dictionaries aren't marking objects as weakref'd (python#124643)
Dictionaries aren't marking objects as weakref'd
1 parent cce1125 commit 077e7ef

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
@@ -1488,7 +1488,7 @@ _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyOb
14881488
*value_addr = value;
14891489
if (value != NULL) {
14901490
assert(ix >= 0);
1491-
Py_INCREF(value);
1491+
_Py_NewRefWithLock(value);
14921492
}
14931493
Py_END_CRITICAL_SECTION();
14941494
return ix;
@@ -7015,7 +7015,7 @@ _PyObject_TryGetInstanceAttribute(PyObject *obj, PyObject *name, PyObject **attr
70157015
// Still no dict, we can read from the values
70167016
assert(values->valid);
70177017
value = values->values[ix];
7018-
*attr = Py_XNewRef(value);
7018+
*attr = _Py_XNewRefWithLock(value);
70197019
success = true;
70207020
}
70217021

@@ -7035,7 +7035,7 @@ _PyObject_TryGetInstanceAttribute(PyObject *obj, PyObject *name, PyObject **attr
70357035

70367036
if (dict->ma_values == values && FT_ATOMIC_LOAD_UINT8(values->valid)) {
70377037
value = _Py_atomic_load_ptr_relaxed(&values->values[ix]);
7038-
*attr = Py_XNewRef(value);
7038+
*attr = _Py_XNewRefWithLock(value);
70397039
success = true;
70407040
} else {
70417041
// Caller needs to lookup from the dictionary

0 commit comments

Comments
 (0)