bpo-46712: Share global string identifiers in deepfreeze (GH-31261)

Where appropriate, deepfreeze.c now uses `&_Py_ID(blah)` references instead of locally defining constants. This saves some space.
This commit is contained in:
Kumar Aditya 2022-02-25 23:35:24 +05:30 committed by GitHub
parent ea9612a17b
commit eb002dbe0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View file

@ -15,9 +15,10 @@ import types
from typing import Dict, FrozenSet, TextIO, Tuple
import umarshal
from generate_global_objects import get_identifiers_and_strings
verbose = False
identifiers = get_identifiers_and_strings()[0]
def isprintable(b: bytes) -> bool:
return all(0x20 <= c < 0x7f for c in b)
@ -167,6 +168,8 @@ class Printer:
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"