diff --git a/Lib/test/test_interpreters/test_api.py b/Lib/test/test_interpreters/test_api.py index 01856d9bf67657..9c02efe71683f6 100644 --- a/Lib/test/test_interpreters/test_api.py +++ b/Lib/test/test_interpreters/test_api.py @@ -703,6 +703,7 @@ def test_not_shareable(self): with self.assertRaises(ExecutionFailed): interp.exec('print(spam)') + @support.skip_if_sanitizer('gh-129824: file descriptor race', thread=True) def test_running(self): interp = interpreters.create() interp.prepare_main({'spam': True}) @@ -1530,6 +1531,7 @@ def test_whence(self): whence = eval(text) self.assertEqual(whence, _interpreters.WHENCE_LEGACY_CAPI) + @support.skip_if_sanitizer('gh-129824: file descriptor race', thread=True) def test_is_running(self): def check(interpid, expected): with self.assertRaisesRegex(InterpreterError, 'unrecognized'): diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 154cde9316866e..30dc4685d8a813 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -4231,7 +4231,8 @@ _PyExc_InitTypes(PyInterpreterState *interp) return -1; } if (exc->tp_new == BaseException_new - && exc->tp_init == (initproc)BaseException_init) + && exc->tp_init == (initproc)BaseException_init + && _Py_IsMainInterpreter(interp)) { exc->tp_vectorcall = BaseException_vectorcall; } diff --git a/Objects/typeobject.c b/Objects/typeobject.c index f3238da8a642e4..f94c773a427e85 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -234,10 +234,10 @@ managed_static_type_state_init(PyInterpreterState *interp, PyTypeObject *self, ? index : index + _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES; - assert((initial == 1) == - (_PyRuntime.types.managed_static.types[full_index].interp_count == 0)); - (void)_Py_atomic_add_int64( + int64_t prev_interp_count = _Py_atomic_add_int64( &_PyRuntime.types.managed_static.types[full_index].interp_count, 1); + assert((initial == 1) == (prev_interp_count == 0)); + (void)prev_interp_count; if (initial) { assert(_PyRuntime.types.managed_static.types[full_index].type == NULL); @@ -8506,7 +8506,12 @@ type_ready_set_new(PyTypeObject *type, int initial) && base == &PyBaseObject_Type && !(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { - type->tp_flags |= Py_TPFLAGS_DISALLOW_INSTANTIATION; + if (initial) { + type->tp_flags |= Py_TPFLAGS_DISALLOW_INSTANTIATION; + } + else { + assert(_PyType_HasFeature(type, Py_TPFLAGS_DISALLOW_INSTANTIATION)); + } } if (!(type->tp_flags & Py_TPFLAGS_DISALLOW_INSTANTIATION)) { @@ -8521,12 +8526,22 @@ type_ready_set_new(PyTypeObject *type, int initial) } else { // tp_new is NULL: inherit tp_new from base - type->tp_new = base->tp_new; + if (initial) { + type->tp_new = base->tp_new; + } + else { + assert(type->tp_new == base->tp_new); + } } } else { // Py_TPFLAGS_DISALLOW_INSTANTIATION sets tp_new to NULL - type->tp_new = NULL; + if (initial) { + type->tp_new = NULL; + } + else { + assert(type->tp_new == NULL); + } } return 0; } @@ -8659,7 +8674,12 @@ type_ready(PyTypeObject *type, int initial) } /* All done -- set the ready flag */ - type->tp_flags |= Py_TPFLAGS_READY; + if (initial) { + type->tp_flags |= Py_TPFLAGS_READY; + } + else { + assert(_PyType_HasFeature(type, Py_TPFLAGS_READY)); + } stop_readying(type); assert(_PyType_CheckConsistency(type));