diff options
author | Victor Stinner <vstinner@python.org> | 2022-01-22 18:31:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-22 18:31:24 (GMT) |
commit | 6cacdb42454264ae75cab5e32bb62876da43bf6f (patch) | |
tree | dc4fc3780b863565bc28c5e707c40aa6e498902f /Objects/object.c | |
parent | ce7d66771ec64488134a1dd114015aa056eef696 (diff) | |
download | cpython-6cacdb42454264ae75cab5e32bb62876da43bf6f.zip cpython-6cacdb42454264ae75cab5e32bb62876da43bf6f.tar.gz cpython-6cacdb42454264ae75cab5e32bb62876da43bf6f.tar.bz2 |
bpo-46417: _PyTypes_FiniTypes() clears object and type (GH-30798)
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/Objects/object.c b/Objects/object.c index a1663c0..27f89e8 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1840,7 +1840,12 @@ _PyTypes_InitState(PyInterpreterState *interp) static PyTypeObject* static_types[] = { - // base types + // The two most important base types: must be initialized first and + // deallocated last. + &PyBaseObject_Type, + &PyType_Type, + + // Static types with base=&PyBaseObject_Type &PyAsyncGen_Type, &PyByteArrayIter_Type, &PyByteArray_Type, @@ -1955,29 +1960,20 @@ _PyTypes_InitTypes(PyInterpreterState *interp) return _PyStatus_OK(); } -#define INIT_TYPE(TYPE) \ - do { \ - if (PyType_Ready(&(TYPE)) < 0) { \ - return _PyStatus_ERR("Can't initialize " #TYPE " type"); \ - } \ - } while (0) - - // Base types - INIT_TYPE(PyBaseObject_Type); - INIT_TYPE(PyType_Type); - assert(PyBaseObject_Type.tp_base == NULL); - assert(PyType_Type.tp_base == &PyBaseObject_Type); - // All other static types (unless initialized elsewhere) for (size_t i=0; i < Py_ARRAY_LENGTH(static_types); i++) { PyTypeObject *type = static_types[i]; if (PyType_Ready(type) < 0) { return _PyStatus_ERR("Can't initialize types"); } + if (type == &PyType_Type) { + // Sanitify checks of the two most important types + assert(PyBaseObject_Type.tp_base == NULL); + assert(PyType_Type.tp_base == &PyBaseObject_Type); + } } return _PyStatus_OK(); -#undef INIT_TYPE } |