Files
cpython/Python/makeopcodetargets.py
T
Łukasz LangaandClaude Fable 5.1 0fc01831b6 [3.11] Fix Windows build regen with Python 3.15 as the host Python (#160621)
The windows-2022 GitHub runner image no longer ships Python 3.10, so
PCbuild/find_python.bat fell through to NuGet and installed the latest
pythonx86 package, which is now 3.15.1. Python 3.15 removed
Loader.load_module(), which Python/makeopcodetargets.py used to import
Lib/opcode.py, so the _RegenOpcodes target failed and broke every
Windows CI build on this branch.

Load Lib/opcode.py through importlib.util instead, and extend the py.exe
search list in find_python.bat up to 3.14 so the build picks up the
runner's preinstalled Python rather than whatever NuGet considers latest.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-24 15:30:40 -07:00

54 lines
1.5 KiB
Python
Executable File

#! /usr/bin/env python
"""Generate C code for the jump table of the threaded code interpreter
(for compilers supporting computed gotos or "labels-as-values", such as gcc).
"""
import importlib.util
import os
import sys
def find_module(modname):
"""Finds and returns a module in the local dist/checkout.
"""
modpath = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "Lib", modname + ".py")
spec = importlib.util.spec_from_file_location(modname, modpath)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def write_contents(f):
"""Write C code contents to the target file object.
"""
opcode = find_module('opcode')
targets = ['_unknown_opcode'] * 256
targets[255] = "TARGET_DO_TRACING"
for opname, op in opcode.opmap.items():
targets[op] = "TARGET_%s" % opname
next_op = 1
for opname in opcode._specialized_instructions:
while targets[next_op] != '_unknown_opcode':
next_op += 1
targets[next_op] = "TARGET_%s" % opname
f.write("static void *opcode_targets[256] = {\n")
f.write(",\n".join([" &&%s" % s for s in targets]))
f.write("\n};\n")
def main():
if len(sys.argv) >= 3:
sys.exit("Too many arguments")
if len(sys.argv) == 2:
target = sys.argv[1]
else:
target = "Python/opcode_targets.h"
with open(target, "w") as f:
write_contents(f)
print("Jump table written into %s" % target)
if __name__ == "__main__":
main()