]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-90699: Intern statically allocated strings (GH-93597)
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Fri, 8 Jul 2022 17:47:37 +0000 (23:17 +0530)
committerGitHub <noreply@github.com>
Fri, 8 Jul 2022 17:47:37 +0000 (10:47 -0700)
This is similar to how strings are interned for deepfreeze.

Include/internal/pycore_runtime_init_generated.h
Objects/unicodeobject.c
Tools/scripts/generate_global_objects.py

index 7b217c3e29d23d644a9bb37107a3641cb71e0b94..ddaab07727b81ebed8ff46e6561917bbf397978f 100644 (file)
@@ -1131,6 +1131,615 @@ extern "C" {
         }, \
     }, \
 }
+
+static inline void
+_PyUnicode_InitStaticStrings(void) {
+    PyObject *string;
+    string = &_Py_ID(False);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(Py_Repr);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(TextIOWrapper);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(True);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(WarningMessage);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__IOBase_closed);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__abc_tpflags__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__abs__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__abstractmethods__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__add__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__aenter__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__aexit__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__aiter__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__all__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__and__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__anext__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__annotations__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__args__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__await__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__bases__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__bool__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__build_class__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__builtins__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__bytes__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__call__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__cantrace__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__class__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__class_getitem__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__classcell__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__complex__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__contains__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__copy__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__del__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__delattr__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__delete__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__delitem__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__dict__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__dictoffset__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__dir__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__divmod__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__doc__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__enter__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__eq__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__exit__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__file__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__float__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__floordiv__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__format__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__fspath__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__ge__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__get__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__getattr__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__getattribute__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__getinitargs__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__getitem__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__getnewargs__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__getnewargs_ex__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__getstate__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__gt__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__hash__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__iadd__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__iand__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__ifloordiv__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__ilshift__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__imatmul__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__imod__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__import__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__imul__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__index__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__init__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__init_subclass__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__instancecheck__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__int__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__invert__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__ior__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__ipow__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__irshift__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__isabstractmethod__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__isub__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__iter__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__itruediv__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__ixor__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__le__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__len__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__length_hint__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__lltrace__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__loader__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__lshift__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__lt__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__main__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__matmul__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__missing__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__mod__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__module__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__mro_entries__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__mul__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__name__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__ne__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__neg__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__new__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__newobj__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__newobj_ex__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__next__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__notes__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__or__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__orig_class__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__origin__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__package__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__parameters__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__path__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__pos__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__pow__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__prepare__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__qualname__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__radd__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rand__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rdivmod__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__reduce__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__reduce_ex__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__repr__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__reversed__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rfloordiv__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rlshift__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rmatmul__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rmod__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rmul__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__ror__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__round__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rpow__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rrshift__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rshift__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rsub__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rtruediv__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__rxor__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__set__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__set_name__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__setattr__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__setitem__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__setstate__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__sizeof__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__slotnames__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__slots__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__spec__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__str__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__sub__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__subclasscheck__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__subclasshook__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__truediv__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__trunc__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__typing_is_unpacked_typevartuple__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__typing_prepare_subst__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__typing_subst__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__typing_unpacked_tuple_args__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__warningregistry__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__weaklistoffset__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__weakref__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(__xor__);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_abc_impl);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_annotation);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_blksize);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_bootstrap);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_dealloc_warn);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_finalizing);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_find_and_load);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_fix_up_module);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_get_sourcefile);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_handle_fromlist);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_initializing);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_is_text_encoding);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_lock_unlock_module);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_showwarnmsg);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_shutdown);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_slotnames);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_uninitialized_submodules);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_warn_unawaited_coroutine);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(_xoptions);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(add);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(append);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(big);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(buffer);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(builtins);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(c_call);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(c_exception);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(c_return);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(call);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(clear);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(close);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(closed);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(code);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(copy);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(copyreg);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(decode);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(default);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(defaultaction);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(dictcomp);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(difference_update);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(dispatch_table);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(displayhook);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(encode);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(encoding);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(end_lineno);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(end_offset);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(errors);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(excepthook);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(exception);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(extend);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(filename);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(fileno);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(fillvalue);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(filters);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(find_class);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(flush);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(genexpr);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(get);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(get_source);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(getattr);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(getstate);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(ignore);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(importlib);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(inf);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(intersection);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(isatty);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(isinstance);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(items);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(iter);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(join);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(keys);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(lambda);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(last_traceback);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(last_type);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(last_value);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(latin1);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(len);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(line);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(lineno);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(listcomp);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(little);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(locale);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(match);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(metaclass);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(mode);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(modules);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(mro);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(msg);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(n_fields);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(n_sequence_fields);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(n_unnamed_fields);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(name);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(newlines);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(next);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(obj);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(offset);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(onceregistry);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(opcode);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(open);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(parent);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(path);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(peek);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(persistent_id);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(persistent_load);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(print_file_and_line);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(ps1);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(ps2);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(raw);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(read);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(read1);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(readable);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(readall);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(readinto);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(readinto1);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(readline);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(reducer_override);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(reload);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(replace);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(reset);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(return);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(reversed);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(seek);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(seekable);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(send);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(setcomp);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(setstate);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(sort);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(stderr);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(stdin);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(stdout);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(strict);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(symmetric_difference_update);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(tell);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(text);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(threading);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(throw);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(top);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(truncate);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(unraisablehook);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(values);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(version);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(warnings);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(warnoptions);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(writable);
+    PyUnicode_InternInPlace(&string);
+    string = &_Py_ID(write);
+    PyUnicode_InternInPlace(&string);
+}
 /* End auto-generated code */
 #ifdef __cplusplus
 }
index d0e4bcd920e40149b28ef6926cacaf28327d7a45..669ffe70727468ce3c60c1f82d393c9a43cc816b 100644 (file)
@@ -52,6 +52,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "pycore_pathconfig.h"    // _Py_DumpPathConfig()
 #include "pycore_pylifecycle.h"   // _Py_SetFileSystemEncoding()
 #include "pycore_pystate.h"       // _PyInterpreterState_GET()
+#include "pycore_runtime_init.h"  // _PyUnicode_InitStaticStrings()
 #include "pycore_ucnhash.h"       // _PyUnicode_Name_CAPI
 #include "pycore_unicodeobject.h" // struct _Py_unicode_state
 #include "stringlib/eq.h"         // unicode_eq()
@@ -14576,6 +14577,14 @@ _PyUnicode_InitGlobalObjects(PyInterpreterState *interp)
         return _PyStatus_OK();
     }
 
+    /* Intern statically allocated string identifiers and deepfreeze strings.
+     * This must be done before any module initialization so that statically
+     * allocated string identifiers are used instead of heap allocated strings.
+     * Deepfreeze uses the interned identifiers if present to save space
+     * else generates them and they are interned to speed up dict lookups.
+    */
+    _PyUnicode_InitStaticStrings();
+
 #ifdef Py_DEBUG
     assert(_PyUnicode_CheckConsistency(&_Py_STR(empty), 1));
 
index c26491b1d083a04d672709666daae3750ed8b3a6..27e3530f38574da354b980b959b8195ebc299776 100644 (file)
@@ -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()