@@ -98,16 +98,22 @@ static_builtin_index_clear(PyTypeObject *self)
98
98
self -> tp_static_builtin_index = 0 ;
99
99
}
100
100
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
+
101
107
/* For static types we store some state in an array on each interpreter. */
102
- static_builtin_type_state *
108
+ static_builtin_state *
103
109
_PyStaticType_GetState (PyTypeObject * self )
104
110
{
105
111
assert (self -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN );
106
112
if (!static_builtin_index_is_set (self )) {
107
113
return NULL ;
108
114
}
109
115
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 ));
111
117
}
112
118
113
119
static void
@@ -117,11 +123,12 @@ static_builtin_state_init(PyTypeObject *self)
117
123
assert (!static_builtin_index_is_set (self ));
118
124
119
125
PyInterpreterState * interp = _PyInterpreterState_GET ();
120
- static_builtin_index_set ( self , interp -> types .num_builtins_initialized ) ;
126
+ size_t index = interp -> types .num_builtins_initialized ;
121
127
interp -> types .num_builtins_initialized ++ ;
128
+ static_builtin_index_set (self , index );
122
129
123
130
/* 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 );
125
132
assert (state != NULL );
126
133
state -> type = self ;
127
134
}
@@ -131,12 +138,14 @@ static_builtin_state_clear(PyTypeObject *self)
131
138
{
132
139
/* Reset the type's per-interpreter state.
133
140
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 );
135
145
assert (state != NULL );
136
146
state -> type = NULL ;
137
147
static_builtin_index_clear (self );
138
148
139
- PyInterpreterState * interp = _PyInterpreterState_GET ();
140
149
assert (interp -> types .num_builtins_initialized > 0 );
141
150
interp -> types .num_builtins_initialized -- ;
142
151
}
0 commit comments