From 3a126a89d6d76a8661929de1584929a20c231f70 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 16 Oct 2024 19:41:13 +0000 Subject: [PATCH 1/2] gh-125610: Fix `STORE_ATTR_INSTANCE_VALUE` specialization check The `STORE_ATTR_INSTANCE_VALUE` opcode doesn't support objects with non-NULL managed dictionaries, so don't specialize to that op in that case. --- Python/specialize.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Python/specialize.c b/Python/specialize.c index 4b33a468733d6b..94b652c5f1d010 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -864,7 +864,10 @@ specialize_dict_access( return 0; } _PyAttrCache *cache = (_PyAttrCache *)(instr + 1); - if (type->tp_flags & Py_TPFLAGS_INLINE_VALUES && _PyObject_InlineValues(owner)->valid) { + if (type->tp_flags & Py_TPFLAGS_INLINE_VALUES && + _PyObject_InlineValues(owner)->valid && + (base_op == LOAD_ATTR || _PyObject_GetManagedDict(owner) == NULL)) + { PyDictKeysObject *keys = ((PyHeapTypeObject *)type)->ht_cached_keys; assert(PyUnicode_CheckExact(name)); Py_ssize_t index = _PyDictKeys_StringLookup(keys, name); From 9aa12bdc159536a91bea062f943795e33156bf8a Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Thu, 24 Oct 2024 09:20:06 -0400 Subject: [PATCH 2/2] Update Python/specialize.c Co-authored-by: Mark Shannon --- Python/specialize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/specialize.c b/Python/specialize.c index 94b652c5f1d010..5d82ab8f45faca 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -866,7 +866,7 @@ specialize_dict_access( _PyAttrCache *cache = (_PyAttrCache *)(instr + 1); if (type->tp_flags & Py_TPFLAGS_INLINE_VALUES && _PyObject_InlineValues(owner)->valid && - (base_op == LOAD_ATTR || _PyObject_GetManagedDict(owner) == NULL)) + !(base_op == STORE_ATTR && _PyObject_GetManagedDict(owner) != NULL)) { PyDictKeysObject *keys = ((PyHeapTypeObject *)type)->ht_cached_keys; assert(PyUnicode_CheckExact(name));