@@ -44,10 +44,12 @@ struct type_cache {
4444
4545/* For now we hard-code this to a value for which we are confident
4646 all the static builtin types will fit (for all builds). */
47- #define _Py_MAX_STATIC_BUILTIN_TYPES 200
47+ #define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 200
48+ #define _Py_MAX_MANAGED_STATIC_EXT_TYPES 10
4849
4950typedef struct {
5051 PyTypeObject * type ;
52+ int isbuiltin ;
5153 int readying ;
5254 int ready ;
5355 // XXX tp_dict can probably be statically allocated,
@@ -59,7 +61,7 @@ typedef struct {
5961 are also some diagnostic uses for the list of weakrefs,
6062 so we still keep it. */
6163 PyObject * tp_weaklist ;
62- } static_builtin_state ;
64+ } managed_static_type_state ;
6365
6466struct types_state {
6567 /* Used to set PyTypeObject.tp_version_tag.
@@ -105,8 +107,16 @@ struct types_state {
105107 num_builtins_initialized is incremented once for each static
106108 builtin type. Once initialization is over for a subinterpreter,
107109 the value will be the same as for all other interpreters. */
108- size_t num_builtins_initialized ;
109- static_builtin_state builtins [_Py_MAX_STATIC_BUILTIN_TYPES ];
110+ struct {
111+ size_t num_initialized ;
112+ managed_static_type_state initialized [_Py_MAX_MANAGED_STATIC_BUILTIN_TYPES ];
113+ } builtins ;
114+ /* We apply a similar strategy for managed extension modules. */
115+ struct {
116+ size_t num_initialized ;
117+ size_t next_index ;
118+ managed_static_type_state initialized [_Py_MAX_MANAGED_STATIC_EXT_TYPES ];
119+ } for_extensions ;
110120 PyMutex mutex ;
111121};
112122
@@ -130,12 +140,35 @@ typedef struct wrapperbase pytype_slotdef;
130140
131141
132142static inline PyObject * *
133- _PyStaticType_GET_WEAKREFS_LISTPTR (static_builtin_state * state )
143+ _PyStaticType_GET_WEAKREFS_LISTPTR (managed_static_type_state * state )
134144{
135145 assert (state != NULL );
136146 return & state -> tp_weaklist ;
137147}
138148
149+ extern int _PyStaticType_InitBuiltin (
150+ PyInterpreterState * interp ,
151+ PyTypeObject * type );
152+ extern void _PyStaticType_FiniBuiltin (
153+ PyInterpreterState * interp ,
154+ PyTypeObject * type );
155+ extern void _PyStaticType_ClearWeakRefs (
156+ PyInterpreterState * interp ,
157+ PyTypeObject * type );
158+ extern managed_static_type_state * _PyStaticType_GetState (
159+ PyInterpreterState * interp ,
160+ PyTypeObject * type );
161+
162+ // Export for '_datetime' shared extension.
163+ PyAPI_FUNC (int ) _PyStaticType_InitForExtension (
164+ PyInterpreterState * interp ,
165+ PyTypeObject * self );
166+ PyAPI_FUNC (void ) _PyStaticType_FiniForExtension (
167+ PyInterpreterState * interp ,
168+ PyTypeObject * self ,
169+ int final );
170+
171+
139172/* Like PyType_GetModuleState, but skips verification
140173 * that type is a heap type with an associated module */
141174static inline void *
@@ -151,11 +184,6 @@ _PyType_GetModuleState(PyTypeObject *type)
151184}
152185
153186
154- extern int _PyStaticType_InitBuiltin (PyInterpreterState * , PyTypeObject * type );
155- extern static_builtin_state * _PyStaticType_GetState (PyInterpreterState * , PyTypeObject * );
156- extern void _PyStaticType_ClearWeakRefs (PyInterpreterState * , PyTypeObject * type );
157- extern void _PyStaticType_Dealloc (PyInterpreterState * , PyTypeObject * );
158-
159187// Export for 'math' shared extension, used via _PyType_IsReady() static inline
160188// function
161189PyAPI_FUNC (PyObject * ) _PyType_GetDict (PyTypeObject * );
0 commit comments