gh-94673: More Per-Interpreter Fields for Builtin Static Types (gh-103912)

his involves moving tp_dict, tp_bases, and tp_mro to PyInterpreterState, in the same way we did for tp_subclasses.  Those three fields are effectively const for builtin static types (unlike tp_subclasses).  In theory we only need to make their values immortal, along with their contents.  However, that isn't such a simple proposition.  (See gh-103823.)  In the meantime the simplest solution is to move the fields into the interpreter.

One alternative is to statically allocate the values, but that's its own can of worms.
This commit is contained in:
Eric Snow 2023-05-02 21:30:03 -06:00 committed by GitHub
parent 872cbc6132
commit de64e75616
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 185 additions and 86 deletions

View file

@ -511,7 +511,6 @@ _PyStructSequence_InitBuiltinWithFlags(PyInterpreterState *interp,
Py_ssize_t n_members = count_members(desc, &n_unnamed_members);
PyMemberDef *members = NULL;
int initialized = 1;
if ((type->tp_flags & Py_TPFLAGS_READY) == 0) {
assert(type->tp_name == NULL);
assert(type->tp_members == NULL);
@ -524,7 +523,6 @@ _PyStructSequence_InitBuiltinWithFlags(PyInterpreterState *interp,
initialize_static_fields(type, desc, members, tp_flags);
_Py_SetImmortal(type);
initialized = 0;
}
#ifndef NDEBUG
else {
@ -543,13 +541,10 @@ _PyStructSequence_InitBuiltinWithFlags(PyInterpreterState *interp,
desc->name);
goto error;
}
// This should be dropped if tp_dict is made per-interpreter.
if (initialized) {
return 0;
}
if (initialize_structseq_dict(
desc, _PyType_GetDict(type), n_members, n_unnamed_members) < 0) {
desc, _PyType_GetDict(type), n_members, n_unnamed_members) < 0)
{
goto error;
}