mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
[3.13] GH-133543: Maintain tracking for materialized instance dictionaries (GH-133617)
This commit is contained in:
parent
05ddd06624
commit
50b45c4f45
3 changed files with 17 additions and 0 deletions
|
@ -1006,6 +1006,18 @@ class DictTest(unittest.TestCase):
|
|||
pass
|
||||
self._tracked(MyDict())
|
||||
|
||||
@support.cpython_only
|
||||
def test_track_lazy_instance_dicts(self):
|
||||
class C:
|
||||
pass
|
||||
o = C()
|
||||
d = o.__dict__
|
||||
self._not_tracked(d)
|
||||
o.untracked = 42
|
||||
self._not_tracked(d)
|
||||
o.tracked = []
|
||||
self._tracked(d)
|
||||
|
||||
def make_shared_key_dict(self, n):
|
||||
class C:
|
||||
pass
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Fix a possible memory leak that could occur when directly accessing instance
|
||||
dictionaries (``__dict__``) that later become part of a reference cycle.
|
|
@ -6839,6 +6839,9 @@ store_instance_attr_lock_held(PyObject *obj, PyDictValues *values,
|
|||
value == NULL ? PyDict_EVENT_DELETED :
|
||||
PyDict_EVENT_MODIFIED);
|
||||
_PyDict_NotifyEvent(interp, event, dict, name, value);
|
||||
if (value) {
|
||||
MAINTAIN_TRACKING(dict, name, value);
|
||||
}
|
||||
}
|
||||
|
||||
FT_ATOMIC_STORE_PTR_RELEASE(values->values[ix], Py_XNewRef(value));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue