]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-145497: Use same size of static_types array in all builds (GH-149139)
authorPetr Viktorin <encukou@gmail.com>
Fri, 1 May 2026 07:41:28 +0000 (09:41 +0200)
committerGitHub <noreply@github.com>
Fri, 1 May 2026 07:41:28 +0000 (09:41 +0200)
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.

Include/internal/pycore_interp_structs.h
Objects/object.c

index 349044116b9d18fe6f4fc79f40f29167e9ce78df..cccfe3565db6e079a014ca4c2d76e61ba46d6f8a 100644 (file)
@@ -525,8 +525,13 @@ struct _py_func_state {
 /****** type 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). */
-#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 203
+   all the static builtin types will fit (for all builds).
+   If you add a new static type to the standard library, you may have to
+   update one of these numbers.
+   */
+#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)
index e6a764435bc29206eab03fa454cdad42e159098f..e0e26bb50d3653711ceeaa96ffa6695e058a6258 100644 (file)
@@ -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,
@@ -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,
@@ -2668,6 +2671,9 @@ _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 (type == NULL) {
+            continue;
+        }
         if (_PyStaticType_InitBuiltin(interp, type) < 0) {
             return _PyStatus_ERR("Can't initialize builtin type");
         }
@@ -2708,6 +2714,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];
+        if (type == NULL) {
+            continue;
+        }
         _PyStaticType_FiniBuiltin(interp, type);
     }
 }