gh-120198: Fix race condition when editing __class__ with an audit hook active (GH-120195)

Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
This commit is contained in:
Ken Jin 2024-06-12 21:06:24 +08:00 committed by GitHub
parent 0315fdc24d
commit e8a9f0c9e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 2 deletions

View file

@ -5709,7 +5709,6 @@ differs:
static int
object_set_class(PyObject *self, PyObject *value, void *closure)
{
PyTypeObject *oldto = Py_TYPE(self);
if (value == NULL) {
PyErr_SetString(PyExc_TypeError,
@ -5729,6 +5728,8 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
return -1;
}
PyTypeObject *oldto = Py_TYPE(self);
/* In versions of CPython prior to 3.5, the code in
compatible_for_assignment was not set up to correctly check for memory
layout / slot / etc. compatibility for non-HEAPTYPE classes, so we just