@@ -172,6 +172,12 @@ static_builtin_state_clear(PyInterpreterState *interp, PyTypeObject *self)
172
172
static inline PyObject *
173
173
lookup_tp_dict (PyTypeObject * self )
174
174
{
175
+ if (self -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
176
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
177
+ static_builtin_state * state = _PyStaticType_GetState (interp , self );
178
+ assert (state != NULL );
179
+ return state -> tp_dict ;
180
+ }
175
181
return self -> tp_dict ;
176
182
}
177
183
@@ -184,12 +190,26 @@ _PyType_GetDict(PyTypeObject *self)
184
190
static inline void
185
191
set_tp_dict (PyTypeObject * self , PyObject * dict )
186
192
{
193
+ if (self -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
194
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
195
+ static_builtin_state * state = _PyStaticType_GetState (interp , self );
196
+ assert (state != NULL );
197
+ state -> tp_dict = dict ;
198
+ return ;
199
+ }
187
200
self -> tp_dict = dict ;
188
201
}
189
202
190
203
static inline void
191
204
clear_tp_dict (PyTypeObject * self )
192
205
{
206
+ if (self -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
207
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
208
+ static_builtin_state * state = _PyStaticType_GetState (interp , self );
209
+ assert (state != NULL );
210
+ Py_CLEAR (state -> tp_dict );
211
+ return ;
212
+ }
193
213
Py_CLEAR (self -> tp_dict );
194
214
}
195
215
@@ -4738,13 +4758,11 @@ static void
4738
4758
clear_static_type_objects (PyInterpreterState * interp , PyTypeObject * type )
4739
4759
{
4740
4760
if (_Py_IsMainInterpreter (interp )) {
4741
- clear_tp_dict (type );
4742
4761
Py_CLEAR (type -> tp_cache );
4743
4762
}
4744
- else {
4745
- clear_tp_bases (type );
4746
- clear_tp_mro (type );
4747
- }
4763
+ clear_tp_dict (type );
4764
+ clear_tp_bases (type );
4765
+ clear_tp_mro (type );
4748
4766
clear_static_tp_subclasses (type );
4749
4767
}
4750
4768
0 commit comments