summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-09-03 06:43:08 (GMT)
committerGitHub <noreply@github.com>2022-09-03 06:43:08 (GMT)
commit6dab8c95bd8db18e09619d804a938ab3e46042fc (patch)
tree5e4ade21c974782385aa48f945a66701b895e3c3 /Tools/scripts
parent16c6759b3748f9b787b2fa4d5e652a8e08a17dee (diff)
downloadcpython-6dab8c95bd8db18e09619d804a938ab3e46042fc.zip
cpython-6dab8c95bd8db18e09619d804a938ab3e46042fc.tar.gz
cpython-6dab8c95bd8db18e09619d804a938ab3e46042fc.tar.bz2
GH-96458: Statically initialize utf8 representation of static strings (#96481)
Diffstat (limited to 'Tools/scripts')
-rw-r--r--Tools/scripts/deepfreeze.py4
-rw-r--r--Tools/scripts/generate_global_objects.py6
2 files changed, 8 insertions, 2 deletions
diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py
index 62eeafa..d9c6030 100644
--- a/Tools/scripts/deepfreeze.py
+++ b/Tools/scripts/deepfreeze.py
@@ -195,7 +195,6 @@ class Printer:
else:
self.write("PyCompactUnicodeObject _compact;")
self.write(f"{datatype} _data[{len(s)+1}];")
- self.deallocs.append(f"_PyStaticUnicode_Dealloc((PyObject *)&{name});")
with self.block(f"{name} =", ";"):
if ascii:
with self.block("._ascii =", ","):
@@ -218,6 +217,9 @@ class Printer:
self.write(f".kind = {kind},")
self.write(".compact = 1,")
self.write(".ascii = 0,")
+ utf8 = s.encode('utf-8')
+ self.write(f'.utf8 = {make_string_literal(utf8)},')
+ self.write(f'.utf8_length = {len(utf8)},')
with self.block(f"._data =", ","):
for i in range(0, len(s), 16):
data = s[i:i+16]
diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py
index f3a11f5..a50f3ba 100644
--- a/Tools/scripts/generate_global_objects.py
+++ b/Tools/scripts/generate_global_objects.py
@@ -287,7 +287,11 @@ def generate_runtime_init(identifiers, strings):
immortal_objects.append(f'(PyObject *)&_Py_SINGLETON(strings).ascii[{i}]')
with printer.block('.latin1 =', ','):
for i in range(128, 256):
- printer.write(f'_PyUnicode_LATIN1_INIT("\\x{i:02x}"),')
+ utf8 = ['"']
+ for c in chr(i).encode('utf-8'):
+ utf8.append(f"\\x{c:02x}")
+ utf8.append('"')
+ printer.write(f'_PyUnicode_LATIN1_INIT("\\x{i:02x}", {"".join(utf8)}),')
immortal_objects.append(f'(PyObject *)&_Py_SINGLETON(strings).latin1[{i} - 128]')
printer.write('')
with printer.block('.tuple_empty =', ','):