@@ -98,16 +98,22 @@ static_builtin_index_clear(PyTypeObject *self)
9898 self -> tp_static_builtin_index = 0 ;
9999}
100100
101+ static inline static_builtin_state *
102+ static_builtin_state_get (PyInterpreterState * interp , size_t index )
103+ {
104+ return & (interp -> types .builtins [index ]);
105+ }
106+
101107/* For static types we store some state in an array on each interpreter. */
102- static_builtin_type_state *
108+ static_builtin_state *
103109_PyStaticType_GetState (PyTypeObject * self )
104110{
105111 assert (self -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN );
106112 if (!static_builtin_index_is_set (self )) {
107113 return NULL ;
108114 }
109115 PyInterpreterState * interp = _PyInterpreterState_GET ();
110- return & (interp -> types . builtins [ static_builtin_index_get (self )] );
116+ return static_builtin_state_get (interp , static_builtin_index_get (self ));
111117}
112118
113119static void
@@ -117,11 +123,12 @@ static_builtin_state_init(PyTypeObject *self)
117123 assert (!static_builtin_index_is_set (self ));
118124
119125 PyInterpreterState * interp = _PyInterpreterState_GET ();
120- static_builtin_index_set ( self , interp -> types .num_builtins_initialized ) ;
126+ size_t index = interp -> types .num_builtins_initialized ;
121127 interp -> types .num_builtins_initialized ++ ;
128+ static_builtin_index_set (self , index );
122129
123130 /* Now we initialize the type's per-interpreter state. */
124- static_builtin_type_state * state = _PyStaticType_GetState ( self );
131+ static_builtin_state * state = static_builtin_state_get ( interp , index );
125132 assert (state != NULL );
126133 state -> type = self ;
127134}
@@ -131,12 +138,14 @@ static_builtin_state_clear(PyTypeObject *self)
131138{
132139 /* Reset the type's per-interpreter state.
133140 This basically undoes what static_builtin_state_init() did. */
134- static_builtin_type_state * state = _PyStaticType_GetState (self );
141+ PyInterpreterState * interp = _PyInterpreterState_GET ();
142+
143+ size_t index = static_builtin_index_get (self );
144+ static_builtin_state * state = static_builtin_state_get (interp , index );
135145 assert (state != NULL );
136146 state -> type = NULL ;
137147 static_builtin_index_clear (self );
138148
139- PyInterpreterState * interp = _PyInterpreterState_GET ();
140149 assert (interp -> types .num_builtins_initialized > 0 );
141150 interp -> types .num_builtins_initialized -- ;
142151}
0 commit comments