Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7843524
Add PyInterpreterState.types.
ericsnowcurrently Jul 8, 2022
09fd0be
Add PyInterpreterState.types.num_builtins_initialized.
ericsnowcurrently Jul 9, 2022
afbde1a
Hard-code _Py_NUM_STATIC_BUILTIN_TYPES.
ericsnowcurrently Jul 18, 2022
f3aa649
Store per-interpreter state for static builtin types.
ericsnowcurrently Jul 19, 2022
9a1cc36
Export _PyStaticType_GetState().
ericsnowcurrently Jul 19, 2022
375b2d9
Move _PyStaticType_GetState() down next to _PyStaticType_InitBuiltin().
ericsnowcurrently Jul 19, 2022
b0b32a6
make it compile
kumaraditya303 Jul 19, 2022
eb05d9b
fix test_sys
kumaraditya303 Jul 19, 2022
f5ebd23
Reset tp_static_builtin_index only if a static builtin type.
ericsnowcurrently Jul 20, 2022
d94818b
Factor out get_static_builtin_index() and set_static_builtin_index().
ericsnowcurrently Jul 20, 2022
06799d5
Reset state->type later on.
ericsnowcurrently Jul 21, 2022
d78f10d
Add some asserts.
ericsnowcurrently Jul 21, 2022
44edc49
Decrement num_builtins_initialized.
ericsnowcurrently Jul 21, 2022
bc7fa26
Verify the per-interpreter type state has been cleared.
ericsnowcurrently Jul 22, 2022
3f20f4a
Add tp_static_builtin_index to the docs.
ericsnowcurrently Jul 25, 2022
9f7775d
Revert "Add tp_static_builtin_index to the docs."
ericsnowcurrently Jul 25, 2022
cf04c2c
Update tp_flags sooner in _PyStaticType_InitBuiltin().
ericsnowcurrently Jul 25, 2022
38427a0
Move the state/index-related helpers to the top.
ericsnowcurrently Jul 26, 2022
d313dbd
Add static_builtin_index_is_set() and static_builtin_index_clear().
ericsnowcurrently Jul 26, 2022
b4bbfcb
Hide the 1-based indexing behind the helper functions.
ericsnowcurrently Jul 26, 2022
1bd26c4
Move and edit a comment.
ericsnowcurrently Jul 26, 2022
652fcc6
Factor out static_builtin_state_init() and static_builtin_state_clear().
ericsnowcurrently Jul 26, 2022
d558a46
Un-initialize the type if PyType_Ready() fails.
ericsnowcurrently Jul 26, 2022
39a8fc7
Drop an empty line.
ericsnowcurrently Jul 26, 2022
6019eba
Move a comment.
ericsnowcurrently Jul 26, 2022
f2f10f0
static_builtin_type_state -> static_builtin_state (and factor out sta…
ericsnowcurrently Jul 26, 2022
cea5d34
Pass the type to static_builtin_state_get().
ericsnowcurrently Jul 26, 2022
4348e3f
Handle non-builtin and non-static types in _PyStaticType_GetState().
ericsnowcurrently Jul 26, 2022
1c8b0c3
Use static_builtin_index_is_set() in static_builtin_index_get().
ericsnowcurrently Jul 26, 2022
ae2d440
Restrict _PyStaticType_GetState() to static builtin types.
ericsnowcurrently Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pass the type to static_builtin_state_get().
  • Loading branch information
ericsnowcurrently committed Jul 26, 2022
commit cea5d3438a30827dfbd53aaa6ceed6567298a0c6
21 changes: 9 additions & 12 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ static_builtin_index_clear(PyTypeObject *self)
}

static inline static_builtin_state *
static_builtin_state_get(PyInterpreterState *interp, size_t index)
static_builtin_state_get(PyInterpreterState *interp, PyTypeObject *self)
{
return &(interp->types.builtins[index]);
return &(interp->types.builtins[static_builtin_index_get(self)]);
}

/* For static types we store some state in an array on each interpreter. */
Expand All @@ -113,23 +113,22 @@ _PyStaticType_GetState(PyTypeObject *self)
return NULL;
}
PyInterpreterState *interp = _PyInterpreterState_GET();
return static_builtin_state_get(interp, static_builtin_index_get(self));
return static_builtin_state_get(interp, self);
}

static void
static_builtin_state_init(PyTypeObject *self)
{
/* Set the type's per-interpreter state. */
PyInterpreterState *interp = _PyInterpreterState_GET();

/* It should only be called once for each builtin type. */
assert(!static_builtin_index_is_set(self));

PyInterpreterState *interp = _PyInterpreterState_GET();
size_t index = interp->types.num_builtins_initialized;
static_builtin_index_set(self, interp->types.num_builtins_initialized);
interp->types.num_builtins_initialized++;
static_builtin_index_set(self, index);

/* Now we initialize the type's per-interpreter state. */
static_builtin_state *state = static_builtin_state_get(interp, index);
assert(state != NULL);
static_builtin_state *state = static_builtin_state_get(interp, self);
state->type = self;
}

Expand All @@ -140,9 +139,7 @@ static_builtin_state_clear(PyTypeObject *self)
This basically undoes what static_builtin_state_init() did. */
PyInterpreterState *interp = _PyInterpreterState_GET();

size_t index = static_builtin_index_get(self);
static_builtin_state *state = static_builtin_state_get(interp, index);
assert(state != NULL);
static_builtin_state *state = static_builtin_state_get(interp, self);
state->type = NULL;
static_builtin_index_clear(self);

Expand Down