Skip to content

Commit 2f56c68

Browse files
[3.13] gh-127316: fix incorrect assertion in setting __class__ in free-threading (GH-127399) (#127422)
gh-127316: fix incorrect assertion in setting `__class__` in free-threading (GH-127399) (cherry picked from commit 45c5cba) Co-authored-by: Kumar Aditya <[email protected]>
1 parent ee57221 commit 2f56c68

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Lib/test/test_free_threading/test_type.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ def work():
125125
for thread in threads:
126126
thread.join()
127127

128+
def test_object_class_change(self):
129+
class Base:
130+
def __init__(self):
131+
self.attr = 123
132+
class ClassA(Base):
133+
pass
134+
class ClassB(Base):
135+
pass
136+
137+
obj = ClassA()
138+
# keep reference to __dict__
139+
d = obj.__dict__
140+
obj.__class__ = ClassB
141+
142+
128143
def run_one(self, writer_func, reader_func):
129144
writer = Thread(target=writer_func)
130145
readers = []

Objects/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7190,7 +7190,7 @@ _PyDict_DetachFromObject(PyDictObject *mp, PyObject *obj)
71907190

71917191
// We could be called with an unlocked dict when the caller knows the
71927192
// values are already detached, so we assert after inline values check.
7193-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(mp);
7193+
ASSERT_WORLD_STOPPED_OR_OBJ_LOCKED(mp);
71947194
assert(mp->ma_values->embedded == 1);
71957195
assert(mp->ma_values->valid == 1);
71967196
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_INLINE_VALUES);

0 commit comments

Comments
 (0)