8000 bpo-46429: tweak deepfreeze output (#32107) · python/cpython@785cc67 · GitHub
[go: up one dir, main page]

Skip to content

Commit 785cc67

Browse files
bpo-46429: tweak deepfreeze output (#32107)
1 parent c12ba6b commit 785cc67

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Tools/scripts/deepfreeze.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ def generate_bytes(self, name: str, b: bytes) -> str:
170170
def generate_unicode(self, name: str, s: str) -> str:
171171
if s in identifiers:
172172
return f"&_Py_ID({s})"
173+
if re.match(r'\A[A-Za-z0-9_]+\Z', s):
174+
name = f"const_str_{s}"
173175
kind, ascii = analyze_character_width(s)
174176
if kind == PyUnicode_1BYTE_KIND:
175177
datatype = "uint8_t"
@@ -326,6 +328,10 @@ def _generate_int_for_bits(self, name: str, i: int, digit: int) -> None:
326328
def generate_int(self, name: str, i: int) -> str:
327329
if -5 <= i <= 256:
328330
return f"(PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + {i}]"
331+
if i >= 0:
332+
name = f"const_int_{i}"
333+
else:
334+
name = f"const_int_negative_{abs(i)}"
329335
if abs(i) < 2**15:
330336
self._generate_int_for_bits(name, i, 2**15)
331337
else:

0 commit comments

Comments
 (0)
0