]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-127316: fix incorrect assertion in setting `__class__` in free-threading...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 29 Nov 2024 16:36:44 +0000 (17:36 +0100)
committerGitHub <noreply@github.com>
Fri, 29 Nov 2024 16:36:44 +0000 (16:36 +0000)
gh-127316: fix incorrect assertion in setting `__class__` in free-threading (GH-127399)
(cherry picked from commit 45c5cba318a19dda3ee6f9fc84781cc7a2fbde80)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Lib/test/test_free_threading/test_type.py
Objects/dictobject.c

index 3e565cb7ea0f7be76cbd1e45f1c45f9e1e13f384..d847acfd6f9edbf444b89e083f5c936517320133 100644 (file)
@@ -125,6 +125,21 @@ class TestType(TestCase):
         for thread in threads:
             thread.join()
 
+    def test_object_class_change(self):
+        class Base:
+            def __init__(self):
+                self.attr = 123
+        class ClassA(Base):
+            pass
+        class ClassB(Base):
+            pass
+
+        obj = ClassA()
+        # keep reference to __dict__
+        d = obj.__dict__
+        obj.__class__ = ClassB
+
+
     def run_one(self, writer_func, reader_func):
         writer = Thread(target=writer_func)
         readers = []
index fccc8e930f51d60f4c2dec81358da675cc9b9177..f1f9110ff73e6d148bf9b95109ce5d8beecf8f1b 100644 (file)
@@ -7190,7 +7190,7 @@ _PyDict_DetachFromObject(PyDictObject *mp, PyObject *obj)
 
     // We could be called with an unlocked dict when the caller knows the
     // values are already detached, so we assert after inline values check.
-    _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(mp);
+    ASSERT_WORLD_STOPPED_OR_OBJ_LOCKED(mp);
     assert(mp->ma_values->embedded == 1);
     assert(mp->ma_values->valid == 1);
     assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_INLINE_VALUES);