mirror of
https://github.com/python/cpython.git
synced 2025-09-12 19:57:40 +00:00
gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
This commit is contained in:
parent
ce3879bd45
commit
e16aed63f6
5 changed files with 45 additions and 4 deletions
|
@ -6633,9 +6633,15 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
|
|||
if (newto->tp_flags & Py_TPFLAGS_HEAPTYPE) {
|
||||
Py_INCREF(newto);
|
||||
}
|
||||
Py_BEGIN_CRITICAL_SECTION(self);
|
||||
// The real Py_TYPE(self) (`oldto`) may have changed from
|
||||
// underneath us in another thread, so we re-fetch it here.
|
||||
oldto = Py_TYPE(self);
|
||||
Py_SET_TYPE(self, newto);
|
||||
if (oldto->tp_flags & Py_TPFLAGS_HEAPTYPE)
|
||||
Py_END_CRITICAL_SECTION();
|
||||
if (oldto->tp_flags & Py_TPFLAGS_HEAPTYPE) {
|
||||
Py_DECREF(oldto);
|
||||
}
|
||||
|
||||
RARE_EVENT_INC(set_class);
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue