gh-100227: Move the Dict of Interned Strings to PyInterpreterState (gh-102339)

We can revisit the options for keeping it global later, if desired.  For now the approach seems quite complex, so we've gone with the simpler isolation solution in the meantime.

https://github.com/python/cpython/issues/100227
This commit is contained in:
Eric Snow 2023-03-28 12:52:28 -06:00 committed by GitHub
parent 7703def37e
commit ba65a065cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 727 additions and 718 deletions

View file

@ -354,14 +354,14 @@ def generate_static_strings_initializer(identifiers, strings):
printer.write(before)
printer.write(START)
printer.write("static inline void")
with printer.block("_PyUnicode_InitStaticStrings(void)"):
with printer.block("_PyUnicode_InitStaticStrings(PyInterpreterState *interp)"):
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'assert(_PyUnicode_CheckConsistency(string, 1));')
printer.write(f'PyUnicode_InternInPlace(&string);')
printer.write(f'_PyUnicode_InternInPlace(interp, &string);')
# XXX What about "strings"?
printer.write(END)
printer.write(after)