@@ -80,14 +80,16 @@ static inline size_t
80
80
static_builtin_index_get (PyTypeObject * self )
81
81
{
82
82
assert (self -> tp_static_builtin_index > 0 );
83
- return self -> tp_static_builtin_index ;
83
+ /* We store a 1-based index so 0 can mean "not initialized". */
84
+ return self -> tp_static_builtin_index - 1 ;
84
85
}
85
86
86
87
static inline void
87
88
static_builtin_index_set (PyTypeObject * self , size_t index )
88
89
{
89
90
assert (index < _Py_MAX_STATIC_BUILTIN_TYPES );
90
- self -> tp_static_builtin_index = index ;
91
+ /* We store a 1-based index so 0 can mean "not initialized". */
92
+ self -> tp_static_builtin_index = index + 1 ;
91
93
}
92
94
93
95
static inline void
@@ -104,7 +106,7 @@ _PyStaticType_GetState(PyTypeObject *self)
104
106
return NULL ;
105
107
}
106
108
PyInterpreterState * interp = _PyInterpreterState_GET ();
107
- return & (interp -> types .builtins [static_builtin_index_get (self ) - 1 ]);
109
+ return & (interp -> types .builtins [static_builtin_index_get (self )]);
108
110
}
109
111
110
112
// Also see _PyStaticType_InitBuiltin() and _PyStaticType_Dealloc().
@@ -6754,11 +6756,8 @@ _PyStaticType_InitBuiltin(PyTypeObject *self)
6754
6756
6755
6757
/* For static types we store some state in an array on each interpreter. */
6756
6758
PyInterpreterState * interp = _PyInterpreterState_GET ();
6757
- interp -> types .num_builtins_initialized ++ ;
6758
- assert (interp -> types .num_builtins_initialized < _Py_MAX_STATIC_BUILTIN_TYPES );
6759
-
6760
- /* We use 1-based indexing so 0 can mean "not initialized". */
6761
6759
static_builtin_index_set (self , interp -> types .num_builtins_initialized );
6760
+ interp -> types .num_builtins_initialized ++ ;
6762
6761
6763
6762
/* Now we initialize the type's per-interpreter state. */
6764
6763
static_builtin_type_state * state = _PyStaticType_GetState (self );
0 commit comments