[Python-checkins] bpo-46429: tweak deepfreeze output (#32107)
gvanrossum
webhook-mailer at python.org
Sun Mar 27 14:46:37 EDT 2022
https://github.com/python/cpython/commit/785cc6770588de087d09e89a69110af2542be208
commit: 785cc6770588de087d09e89a69110af2542be208
branch: main
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2022年03月27日T11:46:22-07:00
summary:
bpo-46429: tweak deepfreeze output (#32107)
files:
M Tools/scripts/deepfreeze.py
diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py
index 1831c15784af7..dfa4b3a8eeb01 100644
--- a/Tools/scripts/deepfreeze.py
+++ b/Tools/scripts/deepfreeze.py
@@ -170,6 +170,8 @@ def generate_bytes(self, name: str, b: bytes) -> str:
def generate_unicode(self, name: str, s: str) -> str:
if s in identifiers:
return f"&_Py_ID({s})"
+ if re.match(r'\A[A-Za-z0-9_]+\Z', s):
+ name = f"const_str_{s}"
kind, ascii = analyze_character_width(s)
if kind == PyUnicode_1BYTE_KIND:
datatype = "uint8_t"
@@ -326,6 +328,10 @@ def _generate_int_for_bits(self, name: str, i: int, digit: int) -> None:
def generate_int(self, name: str, i: int) -> str:
if -5 <= i <= 256:
return f"(PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + {i}]"
+ if i >= 0:
+ name = f"const_int_{i}"
+ else:
+ name = f"const_int_negative_{abs(i)}"
if abs(i) < 2**15:
self._generate_int_for_bits(name, i, 2**15)
else:
More information about the Python-checkins
mailing list