Skip to content

[3.13] gh-133441: Fix STORE_ATTR_WITH_HINT bytecode #133446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,24 @@ def make_pairs():
self.assertEqual(d.get(key3_3), 44)
self.assertGreaterEqual(eq_count, 1)

def test_store_attr_with_hint(self):
# gh-133441: Regression test for STORE_ATTR_WITH_HINT bytecode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in test_opcache not test_dict IMO.

class Node:
def __init__(self):
self.parents = {}

def __setstate__(self, data_dict):
self.__dict__ = data_dict
self.parents = {}

class Dict(dict):
pass

obj = Node()
obj.__setstate__({'parents': {}})
obj.__setstate__({'parents': {}})
obj.__setstate__(Dict({'parents': {}}))


class CAPITest(unittest.TestCase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``STORE_ATTR_WITH_HINT`` bytecode: deoptimize if the dictionary is a
dict subclass. Patch by Victor Stinner.
3 changes: 2 additions & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,8 @@ dummy_func(
assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
PyDictObject *dict = _PyObject_GetManagedDict(owner);
DEOPT_IF(dict == NULL);
assert(PyDict_CheckExact((PyObject *)dict));
DEOPT_IF(!PyDict_CheckExact((PyObject *)dict));

PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries);
PyObject *old_value;
Expand Down
2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading