Skip to content
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
Empty file added .jit-stamp
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note: this file is still there for some reason 🤔
Should it be ignored in #149311 ?

Empty file.
2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_metadata.h

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

40 changes: 40 additions & 0 deletions Lib/test/test_opcache.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import enum
import copy
import pickle
import dis
Expand Down Expand Up @@ -2114,6 +2115,45 @@ def load_enum_member():
self.assert_specialized(load_enum_member,
"LOAD_ATTR_CLASS_WITH_METACLASS_CHECK")

@cpython_only
@requires_specialization
def test_load_attr_class_with_metaclass_check_149239(self):
# LOAD_ATTR_CLASS_WITH_METACLASS_CHECK must check
# for `__class__` writes, see gh-149239
class ColorMeta(enum.EnumType):
pass

class Color(enum.IntEnum, metaclass=ColorMeta):
RED = 1

red = Color.RED

def f1():
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
assert Color.RED == 1

f1()
self.assert_specialized(f1,
"LOAD_ATTR_CLASS_WITH_METACLASS_CHECK")

# Reassign the `__class__` attr to deopt:
class Descriptor(enum.IntEnum):
RED = 1

def __get__(self, obj, owner):
return "descr"

red.__class__ = Descriptor

def f2():
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
assert Color.RED == 'descr'

f2()
self.assert_no_opcode(f2,
"LOAD_ATTR_CLASS_WITH_METACLASS_CHECK")



if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Deopt ``LOAD_ATTR_CLASS_WITH_METACLASS_CHECK`` opcode on ``__class__``
reassigning.
16 changes: 16 additions & 0 deletions Modules/_testinternalcapi/test_cases.c.h

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

5 changes: 5 additions & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2976,6 +2976,11 @@ dummy_func(
}

op(_LOAD_ATTR_CLASS, (descr/4, owner -- attr)) {
PyTypeObject *descr_type = Py_TYPE(descr);
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
EXIT_IF((descr_type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) == 0
&& descr_type != (PyTypeObject *)owner_o);

STAT_INC(LOAD_ATTR, hit);
assert(descr != NULL);
attr = PyStackRef_FromPyObjectNew(descr);
Expand Down
9 changes: 9 additions & 0 deletions Python/executor_cases.c.h

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

16 changes: 16 additions & 0 deletions Python/generated_cases.c.h

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

Loading