gh-150858: fix data race while changing `__qualname__` of a type object(GH-150859)
(cherry picked from commit
1ec6596828b0db4317d85afa85e1f68a3551a07e)
Co-authored-by: Thomas Kowalski <thom.kowa@gmail.com>
--- /dev/null
+Fix a data race while changing ``__qualname__`` of a type concurrently on free-threaded builds.
}
et = (PyHeapTypeObject*)type;
- Py_SETREF(et->ht_qualname, Py_NewRef(value));
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ _PyEval_StopTheWorld(interp);
+ PyObject *old_qualname = et->ht_qualname;
+ et->ht_qualname = Py_NewRef(value);
+ _PyEval_StartTheWorld(interp);
+ Py_DECREF(old_qualname);
return 0;
}