]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133059: Fix `Tools/build/deepfreeze.py` for new nsmallposints (#139906)
authorAlbert N <anamaev263@gmail.com>
Fri, 17 Oct 2025 08:48:53 +0000 (11:48 +0300)
committerGitHub <noreply@github.com>
Fri, 17 Oct 2025 08:48:53 +0000 (11:48 +0300)
.github/workflows/mypy.yml
Tools/build/consts_getter.py [new file with mode: 0644]
Tools/build/deepfreeze.py
Tools/build/generate_global_objects.py
Tools/build/mypy.ini

index 5d5d77f29f6eb1ebbf6518aad1ea439795699689..fac0fa8aba3050473beea4240920f26d56267a9d 100644 (file)
@@ -16,6 +16,7 @@ on:
       - "Tools/build/check_extension_modules.py"
       - "Tools/build/check_warnings.py"
       - "Tools/build/compute-changes.py"
+      - "Tools/build/consts_getter.py"
       - "Tools/build/deepfreeze.py"
       - "Tools/build/generate-build-details.py"
       - "Tools/build/generate_sbom.py"
diff --git a/Tools/build/consts_getter.py b/Tools/build/consts_getter.py
new file mode 100644 (file)
index 0000000..4cd4544
--- /dev/null
@@ -0,0 +1,20 @@
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[2]
+INTERNAL = ROOT / "Include" / "internal"
+
+def get_nsmallnegints_and_nsmallposints() -> tuple[int, int]:
+    nsmallposints = None
+    nsmallnegints = None
+    with open(INTERNAL / "pycore_runtime_structs.h") as infile:
+        for line in infile:
+            if line.startswith("#define _PY_NSMALLPOSINTS"):
+                nsmallposints = int(line.split()[-1])
+            elif line.startswith("#define _PY_NSMALLNEGINTS"):
+                nsmallnegints = int(line.split()[-1])
+                break
+        else:
+            raise NotImplementedError
+    assert nsmallposints
+    assert nsmallnegints
+    return nsmallnegints, nsmallposints
index 2b9f03aebb6d7e8ca6b05bf93b81392472829ab2..477c3d0f5b30d51155a8c8bd9b10aef864d3bcb6 100644 (file)
@@ -17,6 +17,7 @@ import re
 import time
 import types
 
+import consts_getter
 import umarshal
 
 TYPE_CHECKING = False
@@ -362,7 +363,9 @@ class Printer:
                 self.write(f".ob_digit = {{ {ds} }},")
 
     def generate_int(self, name: str, i: int) -> str:
-        if -5 <= i <= 256:
+        nsmallnegints, nsmallposints = consts_getter.get_nsmallnegints_and_nsmallposints()
+
+        if -nsmallnegints <= i <= nsmallposints:
             return f"(PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + {i}]"
         if i >= 0:
             name = f"const_int_{i}"
index 94905b3756d0d8775d4a0d8406b7f7f35e779038..5b188e338bab360c6e12513afc714ddf9236230d 100644 (file)
@@ -3,6 +3,8 @@ import io
 import os.path
 import re
 
+import consts_getter
+
 SCRIPT_NAME = 'Tools/build/generate_global_objects.py'
 __file__ = os.path.abspath(__file__)
 ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
@@ -274,20 +276,7 @@ def generate_global_strings(identifiers, strings):
 
 
 def generate_runtime_init(identifiers, strings):
-    # First get some info from the declarations.
-    nsmallposints = None
-    nsmallnegints = None
-    with open(os.path.join(INTERNAL, 'pycore_runtime_structs.h')) as infile:
-        for line in infile:
-            if line.startswith('#define _PY_NSMALLPOSINTS'):
-                nsmallposints = int(line.split()[-1])
-            elif line.startswith('#define _PY_NSMALLNEGINTS'):
-                nsmallnegints = int(line.split()[-1])
-                break
-        else:
-            raise NotImplementedError
-    assert nsmallposints
-    assert nsmallnegints
+    nsmallnegints, nsmallposints = consts_getter.get_nsmallnegints_and_nsmallposints()
 
     # Then target the runtime initializer.
     filename = os.path.join(INTERNAL, 'pycore_runtime_init_generated.h')
index 331bada6f47d2e1a940563e18a63cabdcb084b91..7d341afd1cd48b48867e935625e82fc49d19e79e 100644 (file)
@@ -6,6 +6,7 @@ files =
     Tools/build/check_extension_modules.py,
     Tools/build/check_warnings.py,
     Tools/build/compute-changes.py,
+    Tools/build/consts_getter.py,
     Tools/build/deepfreeze.py,
     Tools/build/generate-build-details.py,
     Tools/build/generate_sbom.py,