File tree 1 file changed +11
-15
lines changed
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)
1840
1840
1841
1841
1842
1842
static 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
1844
1849
& PyAsyncGen_Type ,
1845
1850
& PyByteArrayIter_Type ,
1846
1851
& PyByteArray_Type ,
@@ -1955,29 +1960,20 @@ _PyTypes_InitTypes(PyInterpreterState *interp)
1955
1960
return _PyStatus_OK ();
1956
1961
}
1957
1962
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
-
1971
1963
// All other static types (unless initialized elsewhere)
1972
1964
for (size_t i = 0 ; i < Py_ARRAY_LENGTH (static_types ); i ++ ) {
1973
1965
PyTypeObject * type = static_types [i ];
1974
1966
if (PyType_Ready (type ) < 0 ) {
1975
1967
return _PyStatus_ERR ("Can't initialize types" );
1976
1968
}
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
+ }
1977
1974
}
1978
1975
1979
1976
return _PyStatus_OK ();
1980
- #undef INIT_TYPE
1981
1977
}
1982
1978
1983
1979
You can’t perform that action at this time.
0 commit comments