File tree Expand file tree Collapse file tree 1 file changed +11
-15
lines changed Expand file tree Collapse file tree 1 file changed +11
-15
lines changed Original file line number Diff line number Diff line change @@ -1840,7 +1840,12 @@ _PyTypes_InitState(PyInterpreterState *interp)
18401840
18411841
18421842static PyTypeObject * static_types [] = {
1843- // base types
1843+ // The two most important base types: must be initialized first and
1844+ // deallocated last.
1845+ & PyBaseObject_Type ,
1846+ & PyType_Type ,
1847+
1848+ // Static types with base=&PyBaseObject_Type
18441849 & PyAsyncGen_Type ,
18451850 & PyByteArrayIter_Type ,
18461851 & PyByteArray_Type ,
@@ -1955,29 +1960,20 @@ _PyTypes_InitTypes(PyInterpreterState *interp)
19551960 return _PyStatus_OK ();
19561961 }
19571962
1958- #define INIT_TYPE (TYPE ) \
1959- do { \
1960- if (PyType_Ready(&(TYPE)) < 0) { \
1961- return _PyStatus_ERR("Can't initialize " #TYPE " type"); \
1962- } \
1963- } while (0)
1964-
1965- // Base types
1966- INIT_TYPE (PyBaseObject_Type );
1967- INIT_TYPE (PyType_Type );
1968- assert (PyBaseObject_Type .tp_base == NULL );
1969- assert (PyType_Type .tp_base == & PyBaseObject_Type );
1970-
19711963 // All other static types (unless initialized elsewhere)
19721964 for (size_t i = 0 ; i < Py_ARRAY_LENGTH (static_types ); i ++ ) {
19731965 PyTypeObject * type = static_types [i ];
19741966 if (PyType_Ready (type ) < 0 ) {
19751967 return _PyStatus_ERR ("Can't initialize types" );
19761968 }
1969+ if (type == & PyType_Type ) {
1970+ // Sanitify checks of the two most important types
1971+ assert (PyBaseObject_Type .tp_base == NULL );
1972+ assert (PyType_Type .tp_base == & PyBaseObject_Type );
1973+ }
19771974 }
19781975
19791976 return _PyStatus_OK ();
1980- #undef INIT_TYPE
19811977}
19821978
19831979
You can’t perform that action at this time.
0 commit comments