@@ -6948,8 +6948,12 @@ type_ready_post_checks(PyTypeObject *type)
69486948static int
69496949type_ready (PyTypeObject * type )
69506950{
6951+ _PyObject_ASSERT ((PyObject * )type ,
6952+ (type -> tp_flags & Py_TPFLAGS_READYING ) == 0 );
6953+ type -> tp_flags |= Py_TPFLAGS_READYING ;
6954+
69516955 if (type_ready_pre_checks (type ) < 0 ) {
6952- return -1 ;
6956+ goto error ;
69536957 }
69546958
69556959#ifdef Py_TRACE_REFS
@@ -6963,82 +6967,89 @@ type_ready(PyTypeObject *type)
69636967
69646968 /* Initialize tp_dict: _PyType_IsReady() tests if tp_dict != NULL */
69656969 if (type_ready_set_dict (type ) < 0 ) {
6966- return -1 ;
6970+ goto error ;
69676971 }
69686972 if (type_ready_set_bases (type ) < 0 ) {
6969- return -1 ;
6973+ goto error ;
69706974 }
69716975 if (type_ready_mro (type ) < 0 ) {
6972- return -1 ;
6976+ goto error ;
69736977 }
69746978 if (type_ready_set_new (type ) < 0 ) {
6975- return -1 ;
6979+ goto error ;
69766980 }
69776981 if (type_ready_fill_dict (type ) < 0 ) {
6978- return -1 ;
6982+ goto error ;
69796983 }
69806984 if (type_ready_inherit (type ) < 0 ) {
6981- return -1 ;
6985+ goto error ;
69826986 }
69836987 if (type_ready_preheader (type ) < 0 ) {
6984- return -1 ;
6988+ goto error ;
69856989 }
69866990 if (type_ready_set_hash (type ) < 0 ) {
6987- return -1 ;
6991+ goto error ;
69886992 }
69896993 if (type_ready_add_subclasses (type ) < 0 ) {
6990- return -1 ;
6994+ goto error ;
69916995 }
69926996 if (type_ready_managed_dict (type ) < 0 ) {
6993- return -1 ;
6997+ goto error ;
69946998 }
69956999 if (type_ready_post_checks (type ) < 0 ) {
6996- return -1 ;
7000+ goto error ;
69977001 }
7002+
7003+ /* All done -- set the ready flag */
7004+ type -> tp_flags = (type -> tp_flags & ~Py_TPFLAGS_READYING ) | Py_TPFLAGS_READY ;
7005+
7006+ assert (_PyType_CheckConsistency (type ));
69987007 return 0 ;
6999- }
70007008
7009+ error :
7010+ type -> tp_flags &= ~Py_TPFLAGS_READYING ;
7011+ return -1 ;
7012+ }
70017013
70027014int
70037015PyType_Ready (PyTypeObject * type )
70047016{
7017+ assert (!(type -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ));
7018+
70057019 if (type -> tp_flags & Py_TPFLAGS_READY ) {
70067020 assert (_PyType_CheckConsistency (type ));
70077021 return 0 ;
70087022 }
7009- _PyObject_ASSERT ((PyObject * )type ,
7010- (type -> tp_flags & Py_TPFLAGS_READYING ) == 0 );
7011-
7012- type -> tp_flags |= Py_TPFLAGS_READYING ;
70137023
70147024 /* Historically, all static types were immutable. See bpo-43908 */
70157025 if (!(type -> tp_flags & Py_TPFLAGS_HEAPTYPE )) {
70167026 type -> tp_flags |= Py_TPFLAGS_IMMUTABLETYPE ;
70177027 }
70187028
7019- if (type_ready (type ) < 0 ) {
7020- type -> tp_flags &= ~Py_TPFLAGS_READYING ;
7021- return -1 ;
7022- }
7023-
7024- /* All done -- set the ready flag */
7025- type -> tp_flags = (type -> tp_flags & ~Py_TPFLAGS_READYING ) | Py_TPFLAGS_READY ;
7026- assert (_PyType_CheckConsistency (type ));
7027- return 0 ;
7029+ return type_ready (type );
70287030}
70297031
70307032int
70317033_PyStaticType_InitBuiltin (PyTypeObject * self )
70327034{
7035+ assert (!(self -> tp_flags & Py_TPFLAGS_HEAPTYPE ));
7036+
7037+ if (self -> tp_flags & Py_TPFLAGS_READY ) {
7038+ assert (self -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN );
7039+ assert (_PyType_CheckConsistency (self ));
7040+ return 0 ;
7041+ }
7042+
70337043 self -> tp_flags |= _Py_TPFLAGS_STATIC_BUILTIN ;
7044+ self -> tp_flags |= Py_TPFLAGS_IMMUTABLETYPE ;
70347045
70357046 assert (NEXT_GLOBAL_VERSION_TAG <= _Py_MAX_GLOBAL_TYPE_VERSION_TAG );
70367047 self -> tp_version_tag = NEXT_GLOBAL_VERSION_TAG ++ ;
70377048 self -> tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG ;
70387049
70397050 static_builtin_state_init (self );
70407051
7041- int res = PyType_Ready (self );
7052+ int res = type_ready (self );
70427053 if (res < 0 ) {
70437054 static_builtin_state_clear (self );
70447055 }
0 commit comments