Skip to content

Commit 1ec6596

Browse files
gh-150858: fix data race while changing __qualname__ of a type object(#150859)
1 parent 937d89c commit 1ec6596

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a data race while changing ``__qualname__`` of a type concurrently on free-threaded builds.

Objects/typeobject.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,12 @@ type_set_qualname(PyObject *tp, PyObject *value, void *context)
15941594
}
15951595

15961596
et = (PyHeapTypeObject*)type;
1597-
Py_SETREF(et->ht_qualname, Py_NewRef(value));
1597+
PyInterpreterState *interp = _PyInterpreterState_GET();
1598+
_PyEval_StopTheWorld(interp);
1599+
PyObject *old_qualname = et->ht_qualname;
1600+
et->ht_qualname = Py_NewRef(value);
1601+
_PyEval_StartTheWorld(interp);
1602+
Py_DECREF(old_qualname);
15981603
return 0;
15991604
}
16001605

0 commit comments

Comments
 (0)