mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
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:
parent
56c7176d1d
commit
d2e2e53f73
21 changed files with 89 additions and 169 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue