summaryrefslogtreecommitdiffstats
path: root/Tools/build/deepfreeze.py
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-11-02 17:42:57 (GMT)
committerGitHub <noreply@github.com>2022-11-02 17:42:57 (GMT)
commit276d77724f2373cc03838448a3e62977aa28bf0d (patch)
treeaeb2f83a896f02a3f38ace9d6ecb65b9620be8e3 /Tools/build/deepfreeze.py
parent18fc232e07c14536d99f07821e338ebddfd8cb63 (diff)
downloadcpython-276d77724f2373cc03838448a3e62977aa28bf0d.zip
cpython-276d77724f2373cc03838448a3e62977aa28bf0d.tar.gz
cpython-276d77724f2373cc03838448a3e62977aa28bf0d.tar.bz2
GH-98686: Quicken everything (GH-98687)
Diffstat (limited to 'Tools/build/deepfreeze.py')
-rw-r--r--Tools/build/deepfreeze.py29
1 files changed, 11 insertions, 18 deletions
diff --git a/Tools/build/deepfreeze.py b/Tools/build/deepfreeze.py
index 28ac2b1..2eef649 100644
--- a/Tools/build/deepfreeze.py
+++ b/Tools/build/deepfreeze.py
@@ -114,9 +114,8 @@ class Printer:
self.file = file
self.cache: Dict[tuple[type, object, str], str] = {}
self.hits, self.misses = 0, 0
- self.patchups: list[str] = []
- self.deallocs: list[str] = []
- self.interns: list[str] = []
+ self.finis: list[str] = []
+ self.inits: list[str] = []
self.write('#include "Python.h"')
self.write('#include "internal/pycore_gc.h"')
self.write('#include "internal/pycore_code.h"')
@@ -257,7 +256,6 @@ class Printer:
self.write(f".co_names = {co_names},")
self.write(f".co_exceptiontable = {co_exceptiontable},")
self.field(code, "co_flags")
- self.write(".co_warmup = QUICKENING_INITIAL_WARMUP_VALUE,")
self.write("._co_linearray_entry_size = 0,")
self.field(code, "co_argcount")
self.field(code, "co_posonlyargcount")
@@ -284,8 +282,8 @@ class Printer:
self.write(f"._co_firsttraceable = {i},")
break
name_as_code = f"(PyCodeObject *)&{name}"
- self.deallocs.append(f"_PyStaticCode_Dealloc({name_as_code});")
- self.interns.append(f"_PyStaticCode_InternStrings({name_as_code})")
+ self.finis.append(f"_PyStaticCode_Fini({name_as_code});")
+ self.inits.append(f"_PyStaticCode_Init({name_as_code})")
return f"& {name}.ob_base.ob_base"
def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:
@@ -373,11 +371,7 @@ class Printer:
def generate_file(self, module: str, code: object)-> None:
module = module.replace(".", "_")
self.generate(f"{module}_toplevel", code)
- with self.block(f"static void {module}_do_patchups(void)"):
- for p in self.patchups:
- self.write(p)
- self.patchups.clear()
- self.write(EPILOGUE.replace("%%NAME%%", module))
+ self.write(EPILOGUE.format(name=module))
def generate(self, name: str, obj: object) -> str:
# Use repr() in the key to distinguish -0.0 from +0.0
@@ -421,11 +415,10 @@ class Printer:
EPILOGUE = """
PyObject *
-_Py_get_%%NAME%%_toplevel(void)
-{
- %%NAME%%_do_patchups();
- return Py_NewRef((PyObject *) &%%NAME%%_toplevel);
-}
+_Py_get_{name}_toplevel(void)
+{{
+ return Py_NewRef((PyObject *) &{name}_toplevel);
+}}
"""
FROZEN_COMMENT_C = "/* Auto-generated by Programs/_freeze_module.c */"
@@ -461,10 +454,10 @@ def generate(args: list[str], output: TextIO) -> None:
code = compile(fd.read(), f"<frozen {modname}>", "exec")
printer.generate_file(modname, code)
with printer.block(f"void\n_Py_Deepfreeze_Fini(void)"):
- for p in printer.deallocs:
+ for p in printer.finis:
printer.write(p)
with printer.block(f"int\n_Py_Deepfreeze_Init(void)"):
- for p in printer.interns:
+ for p in printer.inits:
with printer.block(f"if ({p} < 0)"):
printer.write("return -1;")
printer.write("return 0;")