-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-94673: Clarify About Runtime State Related to Static Builtin Types #117761
gh-94673: Clarify About Runtime State Related to Static Builtin Types #117761
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. With suitable explanation we may not need the runtime counter -- we can just explain that the index is assigned by the main thread based upon its counter.
Include/internal/pycore_typeobject.h
Outdated
Those objects are stored in the PyInterpreterState.types.builtins | ||
array, at the index corresponding to each specific static builtin | ||
type. That index (a size_t value) is stored in the tp_subclasses | ||
field (defined as PyObject*). We re-purposed the now-unused |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it's void *
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Objects/typeobject.c
Outdated
@@ -163,7 +163,17 @@ static void | |||
static_builtin_state_init(PyInterpreterState *interp, PyTypeObject *self) | |||
{ | |||
if (!static_builtin_index_is_set(self)) { | |||
static_builtin_index_set(self, interp->types.num_builtins_initialized); | |||
assert(_Py_IsMainInterpreter(interp)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In static_builtin_state_clear()
there's a check for this rather than an assert. Maybe it should be an if
here too, for symmetry? (Maybe the assert should be !static_builtin_index_is_set()
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll flip it around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Objects/typeobject.c
Outdated
@@ -163,7 +163,17 @@ static void | |||
static_builtin_state_init(PyInterpreterState *interp, PyTypeObject *self) | |||
{ | |||
if (!static_builtin_index_is_set(self)) { | |||
static_builtin_index_set(self, interp->types.num_builtins_initialized); | |||
assert(_Py_IsMainInterpreter(interp)); | |||
assert(interp->types.num_builtins_initialized == \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's C. :-)
assert(interp->types.num_builtins_initialized == \ | |
assert(interp->types.num_builtins_initialized == |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropped
Objects/typeobject.c
Outdated
} | ||
else { | ||
assert(!_Py_IsMainInterpreter(interp)); | ||
assert(static_builtin_index_get(self) == \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert(static_builtin_index_get(self) == \ | |
assert(static_builtin_index_get(self) == |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
This reverts commit b8d622e.
Good point. I've dropped the extra counter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect!
… Types (pythongh-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
After this PR,
|
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:
_PyRuntimeState.types.next_builtin_index
Regarding
next_builtin_index
, it replaces our use of the main interpreter'sinterp->types.num_builtins_initialized
as the next index. Even though it's technically redundant, the distinct global runtime field helps clarify explicitly that each index is from global state.