8000 static_builtin_type_state -> static_builtin_state (and factor out sta… · python/cpython@f2f10f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2f10f0

Browse files
static_builtin_type_state -> static_builtin_state (and factor out static_builtin_state_get())
1 parent 6019eba commit f2f10f0

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Include/internal/pycore_typeobject.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ struct type_cache {
4545

4646
typedef struct {
4747
PyTypeObject *type;
48-
} static_builtin_type_state;
48+
} static_builtin_state;
4949

5050
struct types_state {
5151
struct type_cache type_cache;
5252
size_t num_builtins_initialized;
53-
static_builtin_type_state builtins[_Py_MAX_STATIC_BUILTIN_TYPES];
53+
static_builtin_state builtins[_Py_MAX_STATIC_BUILTIN_TYPES];
5454
};
5555

5656

5757
extern PyStatus _PyTypes_InitSlotDefs(void);
5858

5959
extern int _PyStaticType_InitBuiltin(PyTypeObject *type);
60-
extern static_builtin_type_state * _PyStaticType_GetState(PyTypeObject *);
60+
extern static_builtin_state * _PyStaticType_GetState(PyTypeObject *);
6161
extern void _PyStaticType_Dealloc(PyTypeObject *type);
6262

6363

Objects/typeobject.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

113119
static 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

Comments
 (0)
0