mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-121860: Fix crash when materializing managed dict (#121866)
The object's inline values may be marked invalid if the materialized dict was already initialized and then deleted.
This commit is contained in:
parent
c46d64e0ef
commit
162b41f577
3 changed files with 31 additions and 5 deletions
|
@ -6683,13 +6683,20 @@ _PyObject_MaterializeManagedDict_LockHeld(PyObject *obj)
|
|||
{
|
||||
ASSERT_WORLD_STOPPED_OR_OBJ_LOCKED(obj);
|
||||
|
||||
PyDictValues *values = _PyObject_InlineValues(obj);
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
PyDictKeysObject *keys = CACHED_KEYS(Py_TYPE(obj));
|
||||
OBJECT_STAT_INC(dict_materialized_on_request);
|
||||
PyDictObject *dict = make_dict_from_instance_attributes(interp, keys, values);
|
||||
|
||||
PyDictValues *values = _PyObject_InlineValues(obj);
|
||||
PyDictObject *dict;
|
||||
if (values->valid) {
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
PyDictKeysObject *keys = CACHED_KEYS(Py_TYPE(obj));
|
||||
dict = make_dict_from_instance_attributes(interp, keys, values);
|
||||
}
|
||||
else {
|
||||
dict = (PyDictObject *)PyDict_New();
|
||||
}
|
||||
FT_ATOMIC_STORE_PTR_RELEASE(_PyObject_ManagedDictPointer(obj)->dict,
|
||||
(PyDictObject *)dict);
|
||||
dict);
|
||||
return dict;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue