Skip to content

Commit fcd53b6

Browse files
authored
gh-145497: Use same size of static_types array in all builds (GH-149139)
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 8066db5 commit fcd53b6

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

Include/internal/pycore_interp_structs.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,13 @@ struct _py_func_state {
525525
/****** type state *********/
526526

527527
/* For now we hard-code this to a value for which we are confident
528-
all the static builtin types will fit (for all builds). */
529-
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 203
528+
all the static builtin types will fit (for all builds).
529+
If you add a new static type to the standard library, you may have to
530+
update one of these numbers.
531+
*/
532+
#define _Py_NUM_MANAGED_PREINITIALIZED_TYPES 120
533+
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES \
534+
(_Py_NUM_MANAGED_PREINITIALIZED_TYPES + 83)
530535
#define _Py_MAX_MANAGED_STATIC_EXT_TYPES 10
531536
#define _Py_MAX_MANAGED_STATIC_TYPES \
532537
(_Py_MAX_MANAGED_STATIC_BUILTIN_TYPES + _Py_MAX_MANAGED_STATIC_EXT_TYPES)

Objects/object.c

Lines changed: 10 additions & 1 deletion
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,
@@ -2644,6 +2644,9 @@ static PyTypeObject* static_types[] = {
26442644
&_PyUnion_Type,
26452645
#ifdef _Py_TIER2
26462646
&_PyUOpExecutor_Type,
2647+
#else
2648+
// The array should have the same size on all builds; see gh-149139
2649+
NULL,
26472650
#endif
26482651
&_PyWeakref_CallableProxyType,
26492652
&_PyWeakref_ProxyType,
@@ -2668,6 +2671,9 @@ _PyTypes_InitTypes(PyInterpreterState *interp)
26682671
// All other static types (unless initialized elsewhere)
26692672
for (size_t i=0; i < Py_ARRAY_LENGTH(static_types); i++) {
26702673
PyTypeObject *type = static_types[i];
2674+
if (type == NULL) {
2675+
continue;
2676+
}
26712677
if (_PyStaticType_InitBuiltin(interp, type) < 0) {
26722678
return _PyStatus_ERR("Can't initialize builtin type");
26732679
}
@@ -2708,6 +2714,9 @@ _PyTypes_FiniTypes(PyInterpreterState *interp)
27082714
// their base classes.
27092715
for (Py_ssize_t i=Py_ARRAY_LENGTH(static_types)-1; i>=0; i--) {
27102716
PyTypeObject *type = static_types[i];
2717+
if (type == NULL) {
2718+
continue;
2719+
}
27112720
_PyStaticType_FiniBuiltin(interp, type);
27122721
}
27132722
}

0 commit comments

Comments
 (0)