mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
[3.13] gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165) (GH-120403)
gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165)
(cherry picked from commit e16aed63f6
)
Co-authored-by: Ken Jin <kenjin@python.org>
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
39825a7533
commit
91c4444d22
5 changed files with 45 additions and 4 deletions
|
@ -6474,9 +6474,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