Skip to content

Commit e959ed6

Browse files
use global strings
1 parent 7fce106 commit e959ed6

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Tools/scripts/deepfreeze.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import time
1414
import types
1515
from typing import Dict, FrozenSet, TextIO, Tuple
16-
16+
from generate_global_objects import get_identifiers_and_strings
1717
import umarshal
1818

1919
verbose = False
20-
20+
identifiers = get_identifiers_and_strings()[0]
2121

2222
def isprintable(b: bytes) -> bool:
2323
return all(0x20 <= c < 0x7f for c in b)
@@ -166,6 +166,8 @@ def generate_bytes(self, name: str, b: bytes) -> str:
166166
return f"& {name}.ob_base.ob_base"
167167

168168
def generate_unicode(self, name: str, s: str) -> str:
169+
if s in identifiers:
170+
return f"&_Py_ID({s})"
169171
kind, ascii = analyze_character_width(s)
170172
if kind == PyUnicode_1BYTE_KIND:
171173
datatype = "uint8_t"

Tools/scripts/generate_global_objects.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,10 @@ def generate_runtime_init(identifiers, strings):
256256
printer.write(after)
257257

258258

259-
#######################################
260-
# the script
261-
262-
def main() -> None:
259+
def get_identifiers_and_strings() -> tuple[set[str], dict[str, str]]:
263260
identifiers = set(IDENTIFIERS)
264261
strings = dict(STRING_LITERALS)
265-
for name, string, filename, lno, _ in iter_global_strings():
262+
for name, string, *_ in iter_global_strings():
266263
if string is None:
267264
if name not in IGNORED:
268265
identifiers.add(name)
@@ -271,6 +268,13 @@ def main() -> None:
271268
strings[name] = string
272269
elif string != strings[name]:
273270
raise ValueError(f'string mismatch for {name!r} ({string!r} != {strings[name]!r}')
271+
return identifiers, strings
272+
273+
#######################################
274+
# the script
275+
276+
def main() -> None:
277+
identifiers, strings = get_identifiers_and_strings()
274278

275279
generate_global_strings(identifiers, strings)
276280
generate_runtime_init(identifiers, strings)

0 commit comments

Comments
 (0)