gh-94673: Clarify About Runtime State Related to Static Builtin Types (gh-117761)

Guido pointed out to me that some details about the per-interpreter state for the builtin types aren't especially clear.  I'm addressing that by:

* adding a comment explaining that state
* adding some asserts to point out the relationship between each index and the interp/global runtime state
This commit is contained in:
Eric Snow 2024-04-12 16:39:27 -06:00 committed by GitHub
parent 30f0643e36
commit eca53620e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 1 deletions

View file

@ -162,9 +162,14 @@ _PyStaticType_GetState(PyInterpreterState *interp, PyTypeObject *self)
static void
static_builtin_state_init(PyInterpreterState *interp, PyTypeObject *self)
{
if (!static_builtin_index_is_set(self)) {
if (_Py_IsMainInterpreter(interp)) {
assert(!static_builtin_index_is_set(self));
static_builtin_index_set(self, interp->types.num_builtins_initialized);
}
else {
assert(static_builtin_index_get(self) ==
interp->types.num_builtins_initialized);
}
static_builtin_state *state = static_builtin_state_get(interp, self);
/* It should only be called once for each builtin type. */