File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -525,8 +525,13 @@ struct _py_func_state {
525525/****** type state *********/
526526
527527/* For now we hard-code this to a value for which we are confident
528- all the static builtin types will fit (for all builds). */
529- #define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 203
528+ all the static builtin types will fit (for all builds).
529+ If you add a new static type to the standard library, you may have to
530+ update one of these numbers.
531+ */
532+ #define _Py_NUM_MANAGED_PREINITIALIZED_TYPES 120
533+ #define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES \
534+ (_Py_NUM_MANAGED_PREINITIALIZED_TYPES + 83)
530535#define _Py_MAX_MANAGED_STATIC_EXT_TYPES 10
531536#define _Py_MAX_MANAGED_STATIC_TYPES \
532537 (_Py_MAX_MANAGED_STATIC_BUILTIN_TYPES + _Py_MAX_MANAGED_STATIC_EXT_TYPES)
Original file line number Diff line number Diff line change @@ -2526,7 +2526,7 @@ extern PyTypeObject _PyMemoryIter_Type;
25262526extern PyTypeObject _PyPositionsIterator ;
25272527extern PyTypeObject _Py_GenericAliasIterType ;
25282528
2529- static PyTypeObject * static_types [] = {
2529+ static PyTypeObject * static_types [_Py_NUM_MANAGED_PREINITIALIZED_TYPES ] = {
25302530 // The two most important base types: must be initialized first and
25312531 // deallocated last.
25322532 & PyBaseObject_Type ,
@@ -2644,6 +2644,9 @@ static PyTypeObject* static_types[] = {
26442644 & _PyUnion_Type ,
26452645#ifdef _Py_TIER2
26462646 & _PyUOpExecutor_Type ,
2647+ #else
2648+ // The array should have the same size on all builds; see gh-149139
2649+ NULL ,
26472650#endif
26482651 & _PyWeakref_CallableProxyType ,
26492652 & _PyWeakref_ProxyType ,
@@ -2668,6 +2671,9 @@ _PyTypes_InitTypes(PyInterpreterState *interp)
26682671 // All other static types (unless initialized elsewhere)
26692672 for (size_t i = 0 ; i < Py_ARRAY_LENGTH (static_types ); i ++ ) {
26702673 PyTypeObject * type = static_types [i ];
2674+ if (type == NULL ) {
2675+ continue ;
2676+ }
26712677 if (_PyStaticType_InitBuiltin (interp , type ) < 0 ) {
26722678 return _PyStatus_ERR ("Can't initialize builtin type" );
26732679 }
@@ -2708,6 +2714,9 @@ _PyTypes_FiniTypes(PyInterpreterState *interp)
27082714 // their base classes.
27092715 for (Py_ssize_t i = Py_ARRAY_LENGTH (static_types )- 1 ; i >=0 ; i -- ) {
27102716 PyTypeObject * type = static_types [i ];
2717+ if (type == NULL ) {
2718+ continue ;
2719+ }
27112720 _PyStaticType_FiniBuiltin (interp , type );
27122721 }
27132722}
You can’t perform that action at this time.
0 commit comments