@@ -98,6 +98,7 @@ static_builtin_index_clear(PyTypeObject *self)
98
98
self -> tp_static_builtin_index = 0 ;
99
99
}
100
100
101
+ /* For static types we store some state in an array on each interpreter. */
101
102
static_builtin_type_state *
102
103
_PyStaticType_GetState (PyTypeObject * self )
103
104
{
@@ -109,6 +110,38 @@ _PyStaticType_GetState(PyTypeObject *self)
109
110
return & (interp -> types .builtins [static_builtin_index_get (self )]);
110
111
}
111
112
113
+ static void
114
+ static_builtin_state_init (PyTypeObject * self )
115
+ {
116
+ /* It should only be called once for each builtin type. */
117
+ assert (!static_builtin_index_is_set (self ));
118
+
119
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
120
+ static_builtin_index_set (self , interp -> types .num_builtins_initialized );
121
+ interp -> types .num_builtins_initialized ++ ;
122
+
123
+ /* Now we initialize the type's per-interpreter state. */
124
+ static_builtin_type_state * state = _PyStaticType_GetState (self );
125
+ assert (state != NULL );
126
+ state -> type = self ;
127
+ }
128
+
129
+ static void
130
+ static_builtin_state_clear (PyTypeObject * self )
131
+ {
132
+ /* Reset the type's per-interpreter state.
133
+ This basically undoes what static_builtin_state_init() did. */
134
+ static_builtin_type_state * state = _PyStaticType_GetState (self );
135
+ assert (state != NULL );
136
+ state -> type = NULL ;
137
+ static_builtin_index_clear (self );
138
+ /* We leave _Py_TPFLAGS_STATIC_BUILTIN set on tp_flags. */
139
+
140
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
141
+ assert (interp -> types .num_builtins_initialized > 0 );
142
+ interp -> types .num_builtins_initialized -- ;
143
+ }
144
+
112
145
// Also see _PyStaticType_InitBuiltin() and _PyStaticType_Dealloc().
113
146
114
147
/* end static builtin helpers */
@@ -4297,7 +4330,6 @@ clear_static_tp_subclasses(PyTypeObject *type)
4297
4330
Py_CLEAR (type -> tp_subclasses );
4298
4331
}
4299
4332
4300
-
4301
4333
void
4302
4334
_PyStaticType_Dealloc (PyTypeObject * type )
4303
4335
{
@@ -4319,17 +4351,7 @@ _PyStaticType_Dealloc(PyTypeObject *type)
4319
4351
type -> tp_flags &= ~Py_TPFLAGS_READY ;
4320
4352
4321
4353
if (type -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
4322
- /* Reset the type's per-interpreter state.
4323
- This basically undoes what _PyStaticType_InitBuiltin() did. */
4324
- static_builtin_type_state * state = _PyStaticType_GetState (type );
4325
- assert (state != NULL );
4326
- state -> type = NULL ;
4327
- static_builtin_index_clear (type );
4328
- /* We leave _Py_TPFLAGS_STATIC_BUILTIN set on tp_flags. */
4329
-
4330
- PyInterpreterState * interp = _PyInterpreterState_GET ();
4331
- assert (interp -> types .num_builtins_initialized > 0 );
4332
- interp -> types .num_builtins_initialized -- ;
4354
+ static_builtin_state_clear (type );
4333
4355
}
4334
4356
}
4335
4357
@@ -6750,18 +6772,7 @@ _PyStaticType_InitBuiltin(PyTypeObject *self)
6750
6772
{
6751
6773
self -> tp_flags = self -> tp_flags | _Py_TPFLAGS_STATIC_BUILTIN ;
6752
6774
6753
- /* It should only be called once for each builtin type. */
6754
- assert (!static_builtin_index_is_set (self ));
6755
-
6756
- /* For static types we store some state in an array on each interpreter. */
6757
- PyInterpreterState * interp = _PyInterpreterState_GET ();
6758
- static_builtin_index_set (self , interp -> types .num_builtins_initialized );
6759
- interp -> types .num_builtins_initialized ++ ;
6760
-
6761
- /* Now we initialize the type's per-interpreter state. */
6762
- static_builtin_type_state * state = _PyStaticType_GetState (self );
6763
- assert (state != NULL );
6764
- state -> type = self ;
6775
+ static_builtin_state_init (self );
6765
6776
6766
6777
return PyType_Ready (self );
6767
6778
}
0 commit comments