mirror of
https://github.com/python/cpython.git
synced 2025-07-25 04:04:13 +00:00
GH-90699: Intern statically allocated strings (GH-93597)
This is similar to how strings are interned for deepfreeze.
This commit is contained in:
parent
be862b4e55
commit
9dff9f4814
3 changed files with 628 additions and 4 deletions
|
@ -284,6 +284,15 @@ def generate_runtime_init(identifiers, strings):
|
|||
printer.write('')
|
||||
with printer.block('.tuple_empty =', ','):
|
||||
printer.write('.ob_base = _PyVarObject_IMMORTAL_INIT(&PyTuple_Type, 0)')
|
||||
printer.write('')
|
||||
printer.write("static inline void")
|
||||
with printer.block("_PyUnicode_InitStaticStrings(void)"):
|
||||
printer.write(f'PyObject *string;')
|
||||
for i in sorted(identifiers):
|
||||
# This use of _Py_ID() is ignored by iter_global_strings()
|
||||
# since iter_files() ignores .h files.
|
||||
printer.write(f'string = &_Py_ID({i});')
|
||||
printer.write(f'PyUnicode_InternInPlace(&string);')
|
||||
printer.write(END)
|
||||
printer.write(after)
|
||||
|
||||
|
@ -314,7 +323,4 @@ def main() -> None:
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
args = parser.parse_args()
|
||||
main(**vars(args))
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue