@@ -167,6 +167,49 @@ static_builtin_state_clear(PyInterpreterState *interp, PyTypeObject *self)
167
167
/* end static builtin helpers */
168
168
169
169
170
+ static inline void
171
+ start_readying (PyTypeObject * type )
172
+ {
173
+ if (type -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
174
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
175
+ static_builtin_state * state = static_builtin_state_get (interp , type );
176
+ assert (state != NULL );
177
+ assert (!state -> readying );
178
+ state -> readying = 1 ;
179
+ return ;
180
+ }
181
+ assert ((type -> tp_flags & Py_TPFLAGS_READYING ) == 0 );
182
+ type -> tp_flags |= Py_TPFLAGS_READYING ;
183
+ }
184
+
185
+ static inline void
186
+ stop_readying (PyTypeObject * type )
187
+ {
188
+ if (type -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
189
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
190
+ static_builtin_state * state = static_builtin_state_get (interp , type );
191
+ assert (state != NULL );
192
+ assert (state -> readying );
193
+ state -> readying = 0 ;
194
+ return ;
195
+ }
196
+ assert (type -> tp_flags & Py_TPFLAGS_READYING );
197
+ type -> tp_flags &= ~Py_TPFLAGS_READYING ;
198
+ }
199
+
200
+ static inline int
201
+ is_readying (PyTypeObject * type )
202
+ {
203
+ if (type -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
204
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
205
+ static_builtin_state * state = static_builtin_state_get (interp , type );
206
+ assert (state != NULL );
207
+ return state -> readying ;
208
+ }
209
+ return (type -> tp_flags & Py_TPFLAGS_READYING ) != 0 ;
210
+ }
211
+
212
+
170
213
/* accessors for objects stored on PyTypeObject */
171
214
172
215
static inline PyObject *
@@ -471,7 +514,7 @@ _PyType_CheckConsistency(PyTypeObject *type)
471
514
CHECK (Py_REFCNT (type ) >= 1 );
472
515
CHECK (PyType_Check (type ));
473
516
474
- CHECK (!(type -> tp_flags & Py_TPFLAGS_READYING ));
517
+ CHECK (!is_readying (type ));
475
518
CHECK (lookup_tp_dict (type ) != NULL );
476
519
477
520
if (type -> tp_flags & Py_TPFLAGS_HAVE_GC ) {
@@ -4419,7 +4462,7 @@ find_name_in_mro(PyTypeObject *type, PyObject *name, int *error)
4419
4462
/* Look in tp_dict of types in MRO */
4420
4463
PyObject * mro = lookup_tp_mro (type );
4421
4464
if (mro == NULL ) {
4422
- if ((type -> tp_flags & Py_TPFLAGS_READYING ) == 0 ) {
4465
+ if (! is_readying (type ) ) {
4423
4466
if (PyType_Ready (type ) < 0 ) {
4424
4467
* error = -1 ;
4425
4468
return NULL ;
@@ -7181,9 +7224,8 @@ type_ready_post_checks(PyTypeObject *type)
7181
7224
static int
7182
7225
type_ready (PyTypeObject * type , int rerunbuiltin )
7183
7226
{
7184
- _PyObject_ASSERT ((PyObject * )type ,
7185
- (type -> tp_flags & Py_TPFLAGS_READYING ) == 0 );
7186
- type -> tp_flags |= Py_TPFLAGS_READYING ;
7227
+ _PyObject_ASSERT ((PyObject * )type , !is_readying (type ));
7228
+ start_readying (type );
7187
7229
7188
7230
if (type_ready_pre_checks (type ) < 0 ) {
7189
7231
goto error ;
@@ -7238,13 +7280,14 @@ type_ready(PyTypeObject *type, int rerunbuiltin)
7238
7280
}
7239
7281
7240
7282
/* All done -- set the ready flag */
7241
- type -> tp_flags = (type -> tp_flags & ~Py_TPFLAGS_READYING ) | Py_TPFLAGS_READY ;
7283
+ type -> tp_flags = type -> tp_flags | Py_TPFLAGS_READY ;
7284
+ stop_readying (type );
7242
7285
7243
7286
assert (_PyType_CheckConsistency (type ));
7244
7287
return 0 ;
7245
7288
7246
7289
error :
7247
- type -> tp_flags &= ~ Py_TPFLAGS_READYING ;
7290
+ stop_readying ( type ) ;
7248
7291
return -1 ;
7249
7292
}
7250
7293
0 commit comments