- "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"
--- /dev/null
+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
import time
import types
+import consts_getter
import umarshal
TYPE_CHECKING = False
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}"
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__)))
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')
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,