mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-133467: fix data race in type_set_name (GH-137302) (#137303)
gh-133467: fix data race in `type_set_name` (GH-137302)
Fix data race in `type_set_name` by assigning name under stop the world pause making it thread safe in free-threading.
(cherry picked from commit e99bc7fd44)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
070993b8ad
commit
bf397e272c
3 changed files with 22 additions and 4 deletions
|
|
@ -1434,9 +1434,13 @@ type_set_name(PyObject *tp, PyObject *value, void *Py_UNUSED(closure))
|
|||
return -1;
|
||||
}
|
||||
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
_PyEval_StopTheWorld(interp);
|
||||
type->tp_name = tp_name;
|
||||
Py_SETREF(((PyHeapTypeObject*)type)->ht_name, Py_NewRef(value));
|
||||
|
||||
PyObject *old_name = ((PyHeapTypeObject*)type)->ht_name;
|
||||
((PyHeapTypeObject*)type)->ht_name = Py_NewRef(value);
|
||||
_PyEval_StartTheWorld(interp);
|
||||
Py_DECREF(old_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -10406,9 +10410,11 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
|
|||
|
||||
get = _PyType_LookupRef(tp, &_Py_ID(__get__));
|
||||
if (get == NULL) {
|
||||
#ifndef Py_GIL_DISABLED
|
||||
/* Avoid further slowdowns */
|
||||
if (tp->tp_descr_get == slot_tp_descr_get)
|
||||
tp->tp_descr_get = NULL;
|
||||
#endif
|
||||
return Py_NewRef(self);
|
||||
}
|
||||
if (obj == NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue