gh-94673: Ensure Builtin Static Types are Readied Properly (gh-103940)

There were cases where we do unnecessary work for builtin static types. This also simplifies some work necessary for a per-interpreter GIL.
This commit is contained in:
Eric Snow 2023-04-27 16:19:43 -06:00 committed by GitHub
parent 56c7176d1d
commit d2e2e53f73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 89 additions and 169 deletions

View file

@ -509,6 +509,13 @@ _PyStructSequence_InitBuiltinWithFlags(PyTypeObject *type,
PyStructSequence_Desc *desc,
unsigned long tp_flags)
{
if (type->tp_flags & Py_TPFLAGS_READY) {
if (_PyStaticType_InitBuiltin(type) < 0) {
goto failed_init_builtin;
}
return 0;
}
PyMemberDef *members;
Py_ssize_t n_members, n_unnamed_members;
@ -517,18 +524,25 @@ _PyStructSequence_InitBuiltinWithFlags(PyTypeObject *type,
return -1;
}
initialize_static_fields(type, desc, members, tp_flags);
Py_INCREF(type); // XXX It should be immortal.
if (_PyStaticType_InitBuiltin(type) < 0) {
PyMem_Free(members);
PyErr_Format(PyExc_RuntimeError,
"Can't initialize builtin type %s",
desc->name);
return -1;
goto failed_init_builtin;
}
if (initialize_static_type(type, desc, n_members, n_unnamed_members) < 0) {
if (initialize_structseq_dict(
desc, type->tp_dict, n_members, n_unnamed_members) < 0) {
PyMem_Free(members);
return -1;
}
return 0;
failed_init_builtin:
PyErr_Format(PyExc_RuntimeError,
"Can't initialize builtin type %s",
desc->name);
return -1;
}
int