Visitar URL original
gh-106931: Intern Statically Allocated Strings Globally by ericsnowcurrently · Pull Request #107272 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle statically allocated strings explicitly when interning.
  • Loading branch information
ericsnowcurrently committed Jul 25, 2023
commit 76f198862093682a12950ee81e61fc977332e6e7
12 changes: 11 additions & 1 deletion Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -14744,10 +14744,20 @@ _PyUnicode_InternInPlace(PyInterpreterState *interp, PyObject **p)
return;
}

if (_PyUnicode_STATE(s).statically_allocated) {
if (!_Py_IsImmortal(s)) {
printf("\"%s\"\n", PyUnicode_AsUTF8(s));
}
assert(_Py_IsImmortal(s));
_PyUnicode_STATE(*p).interned = SSTATE_INTERNED_IMMORTAL_STATIC;
return;
}
if (_Py_IsImmortal(s)) {
// XXX Restrict this to the main interpreter?
_PyUnicode_STATE(*p).interned = SSTATE_INTERNED_IMMORTAL_STATIC;
return;
return;
}

#ifdef Py_REF_DEBUG
/* The reference count value excluding the 2 references from the
interned dictionary should be excluded from the RefTotal. The
Expand Down