8000 bpo-46417: _PyTypes_FiniTypes() clears object and type by vstinner · Pull Request #30798 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46417: _PyTypes_FiniTypes() clears object and type #30798

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

Merged
merged 1 commit into from
Jan 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,12 @@ _PyTypes_InitState(PyInterpreterState *interp)


static PyTypeObject* static_types[] = {
// base types
// The two most important base types: must be initialized first and
// deallocated last.
&PyBaseObject_Type,
&PyType_Type,

// Static types with base=&PyBaseObject_Type
&PyAsyncGen_Type,
&PyByteArrayIter_Type,
&PyByteArray_Type,
Expand Down Expand Up @@ -1955,29 +1960,20 @@ _PyTypes_InitTypes(PyInterpreterState *interp)
return _PyStatus_OK();
}

#define INIT_TYPE(TYPE) \
do { \
if (PyType_Ready(&(TYPE)) < 0) { \
return _PyStatus_ERR("Can't initialize " #TYPE " type"); \
} \
} while (0)

// Base types
INIT_TYPE(PyBaseObject_Type);
INIT_TYPE(PyType_Type);
assert(PyBaseObject_Type.tp_base == NULL);
assert(PyType_Type.tp_base == &PyBaseObject_Type);

// All other static types (unless initialized elsewhere)
for (size_t i=0; i < Py_ARRAY_LENGTH(static_types); i++) {
PyTypeObject *type = static_types[i];
if (PyType_Ready(type) < 0) {
return _PyStatus_ERR("Can't initialize types");
}
if (type == &PyType_Type) {
// Sanitify checks of the two most important types
assert(PyBaseObject_Type.tp_base == NULL);
assert(PyType_Type.tp_base == &PyBaseObject_Type);
}
}

return _PyStatus_OK();
#undef INIT_TYPE
}


Expand Down
0