From 47c794f7589bf9c5f2a0906400cbe3f8fa2a0fe3 Mon Sep 17 00:00:00 2001 From: Matt Page Date: Thu, 19 Dec 2024 22:59:49 -0800 Subject: [PATCH] Add test for LOAD_ATTR_CLASS_WITH_METACLASS_CHECK --- Lib/test/test_opcache.py | 44 ++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_opcache.py b/Lib/test/test_opcache.py index 5b42995e6a0bb8..d7c034365357b7 100644 --- a/Lib/test/test_opcache.py +++ b/Lib/test/test_opcache.py @@ -717,13 +717,10 @@ def write(items): @requires_specialization_ft def test_load_attr_class(self): def get_items(): - class B: - pass - class C: # a must be set to an instance that uses deferred reference - # counting - a = B + # counting in free-threaded builds + a = type("Foo", (object,), {}) items = [] for _ in range(self.ITEMS): @@ -744,11 +741,46 @@ def write(items): del item.a except AttributeError: pass - item.a = object() + item.a = type("Foo", (object,), {}) opname = "LOAD_ATTR_CLASS" self.assert_races_do_not_crash(opname, get_items, read, write) + @requires_specialization_ft + def test_load_attr_class_with_metaclass_check(self): + def get_items(): + class Meta(type): + pass + + class C(metaclass=Meta): + # a must be set to an instance that uses deferred reference + # counting in free-threaded builds + a = type("Foo", (object,), {}) + + items = [] + for _ in range(self.ITEMS): + item = C + items.append(item) + return items + + def read(items): + for item in items: + try: + item.a + except AttributeError: + pass + + def write(items): + for item in items: + try: + del item.a + except AttributeError: + pass + item.a = type("Foo", (object,), {}) + + opname = "LOAD_ATTR_CLASS_WITH_METACLASS_CHECK" + self.assert_races_do_not_crash(opname, get_items, read, write) + @requires_specialization_ft def test_load_attr_getattribute_overridden(self): def get_items():