@@ -6948,8 +6948,12 @@ type_ready_post_checks(PyTypeObject *type)
6948
6948
static int
6949
6949
type_ready (PyTypeObject * type )
6950
6950
{
6951
+ _PyObject_ASSERT ((PyObject * )type ,
6952
+ (type -> tp_flags & Py_TPFLAGS_READYING ) == 0 );
6953
+ type -> tp_flags |= Py_TPFLAGS_READYING ;
6954
+
6951
6955
if (type_ready_pre_checks (type ) < 0 ) {
6952
- return -1 ;
6956
+ goto error ;
6953
6957
}
6954
6958
6955
6959
#ifdef Py_TRACE_REFS
@@ -6963,41 +6967,49 @@ type_ready(PyTypeObject *type)
6963
6967
6964
6968
/* Initialize tp_dict: _PyType_IsReady() tests if tp_dict != NULL */
6965
6969
if (type_ready_set_dict (type ) < 0 ) {
6966
- return -1 ;
6970
+ goto error ;
6967
6971
}
6968
6972
if (type_ready_set_bases (type ) < 0 ) {
6969
- return -1 ;
6973
+ goto error ;
6970
6974
}
6971
6975
if (type_ready_mro (type ) < 0 ) {
6972
- return -1 ;
6976
+ goto error ;
6973
6977
}
6974
6978
if (type_ready_set_new (type ) < 0 ) {
6975
- return -1 ;
6979
+ goto error ;
6976
6980
}
6977
6981
if (type_ready_fill_dict (type ) < 0 ) {
6978
- return -1 ;
6982
+ goto error ;
6979
6983
}
6980
6984
if (type_ready_inherit (type ) < 0 ) {
6981
- return -1 ;
6985
+ goto error ;
6982
6986
}
6983
6987
if (type_ready_preheader (type ) < 0 ) {
6984
- return -1 ;
6988
+ goto error ;
6985
6989
}
6986
6990
if (type_ready_set_hash (type ) < 0 ) {
6987
- return -1 ;
6991
+ goto error ;
6988
6992
}
6989
6993
if (type_ready_add_subclasses (type ) < 0 ) {
6990
- return -1 ;
6994
+ goto error ;
6991
6995
}
6992
6996
if (type_ready_managed_dict (type ) < 0 ) {
6993
- return -1 ;
6997
+ goto error ;
6994
6998
}
6995
6999
if (type_ready_post_checks (type ) < 0 ) {
6996
- return -1 ;
7000
+ goto error ;
6997
7001
}
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 ));
6998
7007
return 0 ;
6999
- }
7000
7008
7009
+ error :
7010
+ type -> tp_flags &= ~Py_TPFLAGS_READYING ;
7011
+ return -1 ;
7012
+ }
7001
7013
7002
7014
int
7003
7015
PyType_Ready (PyTypeObject * type )
@@ -7006,39 +7018,37 @@ PyType_Ready(PyTypeObject *type)
7006
7018
assert (_PyType_CheckConsistency (type ));
7007
7019
return 0 ;
7008
7020
}
7009
- _PyObject_ASSERT ((PyObject * )type ,
7010
- (type -> tp_flags & Py_TPFLAGS_READYING ) == 0 );
7011
-
7012
- type -> tp_flags |= Py_TPFLAGS_READYING ;
7021
+ assert (!(type -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ));
7013
7022
7014
7023
/* Historically, all static types were immutable. See bpo-43908 */
7015
7024
if (!(type -> tp_flags & Py_TPFLAGS_HEAPTYPE )) {
7016
7025
type -> tp_flags |= Py_TPFLAGS_IMMUTABLETYPE ;
7017
7026
}
7018
7027
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 ;
7028
+ return type_ready (type );
7028
7029
}
7029
7030
7030
7031
int
7031
7032
_PyStaticType_InitBuiltin (PyTypeObject * self )
7032
7033
{
7034
+ assert (!(self -> tp_flags & Py_TPFLAGS_HEAPTYPE ));
7035
+
7036
+ if (self -> tp_flags & Py_TPFLAGS_READY ) {
7037
+ assert (self -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN );
7038
+ assert (_PyType_CheckConsistency (self ));
7039
+ return 0 ;
7040
+ }
7041
+
7033
7042
self -> tp_flags |= _Py_TPFLAGS_STATIC_BUILTIN ;
7043
+ self -> tp_flags |= Py_TPFLAGS_IMMUTABLETYPE ;
7034
7044
7035
7045
assert (NEXT_GLOBAL_VERSION_TAG <= _Py_MAX_GLOBAL_TYPE_VERSION_TAG );
7036
7046
self -> tp_version_tag = NEXT_GLOBAL_VERSION_TAG ++ ;
7037
7047
self -> tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG ;
7038
7048
7039
7049
static_builtin_state_init (self );
7040
7050
7041
- int res = PyType_Ready (self );
7051
+ int res = type_ready (self );
7042
7052
if (res < 0 ) {
7043
7053
static_builtin_state_clear (self );
7044
7054
}
0 commit comments