From e959ed63056b79bd4a26507dc8c2d942d6ecfd69 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 24 Feb 2022 07:50:06 +0000 Subject: [PATCH] use global strings --- Tools/scripts/deepfreeze.py | 6 ++++-- Tools/scripts/generate_global_objects.py | 14 +++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py index 0edf3af71d9934..e8aada3ea40235 100644 --- a/Tools/scripts/deepfreeze.py +++ b/Tools/scripts/deepfreeze.py @@ -13,11 +13,11 @@ import time import types from typing import Dict, FrozenSet, TextIO, Tuple - +from generate_global_objects import get_identifiers_and_strings import umarshal verbose = False - +identifiers = get_identifiers_and_strings()[0] def isprintable(b: bytes) -> bool: return all(0x20 <= c < 0x7f for c in b) @@ -166,6 +166,8 @@ def generate_bytes(self, name: str, b: bytes) -> str: return f"& {name}.ob_base.ob_base" def generate_unicode(self, name: str, s: str) -> str: + if s in identifiers: + return f"&_Py_ID({s})" kind, ascii = analyze_character_width(s) if kind == PyUnicode_1BYTE_KIND: datatype = "uint8_t" diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index bad7865f1ff83b..506aa86575c4e8 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -256,13 +256,10 @@ def generate_runtime_init(identifiers, strings): printer.write(after) -####################################### -# the script - -def main() -> None: +def get_identifiers_and_strings() -> tuple[set[str], dict[str, str]]: identifiers = set(IDENTIFIERS) strings = dict(STRING_LITERALS) - for name, string, filename, lno, _ in iter_global_strings(): + for name, string, *_ in iter_global_strings(): if string is None: if name not in IGNORED: identifiers.add(name) @@ -271,6 +268,13 @@ def main() -> None: strings[name] = string elif string != strings[name]: raise ValueError(f'string mismatch for {name!r} ({string!r} != {strings[name]!r}') + return identifiers, strings + +####################################### +# the script + +def main() -> None: + identifiers, strings = get_identifiers_and_strings() generate_global_strings(identifiers, strings) generate_runtime_init(identifiers, strings)