Skip to content

Commit 541834a

Browse files
committed
gh-145497: Use same size of static_types array in all builds
When someone adds a new type but doesn't increment `_Py_MAX_MANAGED_STATIC_BUILTIN_TYPES` or `_Py_MAX_MANAGED_STATIC_EXT_TYPES`, JIT tests fail, because JIT builds define an extra type. But the JIT tests don't necessarily run for the commit that causes the failure. As a workaround, use the same size for the array for all builds, potentially with an empty spot.
1 parent 9633c52 commit 541834a

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

Include/internal/pycore_interp_structs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,9 @@ struct _py_func_state {
528528

529529
/* For now we hard-code this to a value for which we are confident
530530
all the static builtin types will fit (for all builds). */
531-
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 202
531+
#define _Py_NUM_MANAGED_PREINITIALIZED_TYPES 119
532+
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES \
533+
(_Py_NUM_MANAGED_PREINITIALIZED_TYPES + 83)
532534
#define _Py_MAX_MANAGED_STATIC_EXT_TYPES 10
533535
#define _Py_MAX_MANAGED_STATIC_TYPES \
534536
(_Py_MAX_MANAGED_STATIC_BUILTIN_TYPES + _Py_MAX_MANAGED_STATIC_EXT_TYPES)

Objects/object.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,7 +2526,7 @@ extern PyTypeObject _PyMemoryIter_Type;
25262526
extern PyTypeObject _PyPositionsIterator;
25272527
extern PyTypeObject _Py_GenericAliasIterType;
25282528

2529-
static PyTypeObject* static_types[] = {
2529+
static PyTypeObject* static_types[_Py_NUM_MANAGED_PREINITIALIZED_TYPES] = {
25302530
// The two most important base types: must be initialized first and
25312531
// deallocated last.
25322532
&PyBaseObject_Type,
@@ -2643,6 +2643,8 @@ static PyTypeObject* static_types[] = {
26432643
&_PyUnion_Type,
26442644
#ifdef _Py_TIER2
26452645
&_PyUOpExecutor_Type,
2646+
#else
2647+
NULL,
26462648
#endif
26472649
&_PyWeakref_CallableProxyType,
26482650
&_PyWeakref_ProxyType,
@@ -2667,7 +2669,7 @@ _PyTypes_InitTypes(PyInterpreterState *interp)
26672669
// All other static types (unless initialized elsewhere)
26682670
for (size_t i=0; i < Py_ARRAY_LENGTH(static_types); i++) {
26692671
PyTypeObject *type = static_types[i];
2670-
if (_PyStaticType_InitBuiltin(interp, type) < 0) {
2672+
if (type && _PyStaticType_InitBuiltin(interp, type) < 0) {
26712673
return _PyStatus_ERR("Can't initialize builtin type");
26722674
}
26732675
if (type == &PyType_Type) {
@@ -2707,7 +2709,9 @@ _PyTypes_FiniTypes(PyInterpreterState *interp)
27072709
// their base classes.
27082710
for (Py_ssize_t i=Py_ARRAY_LENGTH(static_types)-1; i>=0; i--) {
27092711
PyTypeObject *type = static_types[i];
2710-
_PyStaticType_FiniBuiltin(interp, type);
2712+
if (type) {
2713+
_PyStaticType_FiniBuiltin(interp, type);
2714+
}
27112715
}
27122716
}
27132717

0 commit comments

Comments
 (0)