Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion Include/internal/pycore_interp_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,9 @@ struct _py_func_state {

/* For now we hard-code this to a value for which we are confident
all the static builtin types will fit (for all builds). */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 83 still needs to be bumped if you add some categories of new types, right?

Would be useful to rewrite the comment to something like "If you add a new type, you may have to update some of these numbers".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.
(I don't think it will be that helpful though -- if you're reading this piece of code, you probably already know. But it's nice to get a confirmation.)

#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 203
#define _Py_NUM_MANAGED_PREINITIALIZED_TYPES 120
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES \
(_Py_NUM_MANAGED_PREINITIALIZED_TYPES + 83)
#define _Py_MAX_MANAGED_STATIC_EXT_TYPES 10
#define _Py_MAX_MANAGED_STATIC_TYPES \
(_Py_MAX_MANAGED_STATIC_BUILTIN_TYPES + _Py_MAX_MANAGED_STATIC_EXT_TYPES)
Expand Down
11 changes: 8 additions & 3 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2526,7 +2526,7 @@ extern PyTypeObject _PyMemoryIter_Type;
extern PyTypeObject _PyPositionsIterator;
extern PyTypeObject _Py_GenericAliasIterType;

static PyTypeObject* static_types[] = {
static PyTypeObject* static_types[_Py_NUM_MANAGED_PREINITIALIZED_TYPES] = {
// The two most important base types: must be initialized first and
// deallocated last.
&PyBaseObject_Type,
Expand Down Expand Up @@ -2644,6 +2644,9 @@ static PyTypeObject* static_types[] = {
&_PyUnion_Type,
#ifdef _Py_TIER2
&_PyUOpExecutor_Type,
#else
// The array should have the same size on all builds; see gh-149139
NULL,
#endif
&_PyWeakref_CallableProxyType,
&_PyWeakref_ProxyType,
Expand All @@ -2668,7 +2671,7 @@ _PyTypes_InitTypes(PyInterpreterState *interp)
// 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 (_PyStaticType_InitBuiltin(interp, type) < 0) {
if (type && _PyStaticType_InitBuiltin(interp, type) < 0) {
Comment thread
vstinner marked this conversation as resolved.
Outdated
return _PyStatus_ERR("Can't initialize builtin type");
}
if (type == &PyType_Type) {
Expand Down Expand Up @@ -2708,7 +2711,9 @@ _PyTypes_FiniTypes(PyInterpreterState *interp)
// their base classes.
for (Py_ssize_t i=Py_ARRAY_LENGTH(static_types)-1; i>=0; i--) {
PyTypeObject *type = static_types[i];
_PyStaticType_FiniBuiltin(interp, type);
if (type) {
Comment thread
vstinner marked this conversation as resolved.
Outdated
_PyStaticType_FiniBuiltin(interp, type);
}
}
}

Expand Down
Loading