Skip to content

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commented May 14, 2020

Make the Unicode dictionary of interned strings per-interpreter to
make it compatible with subinterpreters.

https://bugs.python.org/issue40521

@vstinner
Copy link
MemberAuthor

This change requires https://bugs.python.org/issue39465 to be fixed, and also to make the type method cache compatible with subinterpreters.

@vstinner
Copy link
MemberAuthor

This change requires https://bugs.python.org/issue39465 to be fixed, and also to make the type method cache compatible with subinterpreters.

With this PR, tests using subinterpreters like test_ast.test_subinterpreter() does crash since the method cache is built by default, whereas it shares interned strings between multiple interpreters. MCACHE must not be defined to test this PR, or the method cache must be fixed for subinterpreters.

@vstinner
Copy link
MemberAuthor

I rebased my PR on master. It is still a draft: PR #20058 must be merged first, and then the method cache must be fixed for subinterpreter, before we can consider to merge this PR.

@vstinnervstinner marked this pull request as ready for review December 26, 2020 00:48
@vstinnervstinner changed the title [WIP] bpo-40521: Per-interpreter interned stringsbpo-40521: Per-interpreter interned stringsDec 26, 2020
@vstinner
Copy link
MemberAuthor

And I pushed a second fix for test_repl:

_PyUnicode_ClearInterned() now uses PyDict_Next() to no longer allocate memory, to ensure that the interned dictionary is cleared.

It's more an enhancement than a fix. Previously, the code also failed. It's just that previously, we didn't check if interned is NULL at exit, whereas my PR adds such assertion.

Make the Unicode dictionary of interned strings compatible with subinterpreters. Remove the INTERN_NAME_STRINGS macro in typeobject.c: names are always now interned (even if EXPERIMENTAL_ISOLATED_SUBINTERPRETERS macro is defined). _PyUnicode_ClearInterned() now uses PyDict_Next() to no longer allocate memory, to ensure that the interned dictionary is cleared.
@vstinnervstinner merged commit ea25180 into python:masterDec 26, 2020
@vstinnervstinner deleted the unicode_interned_subinterp branch December 26, 2020 01:58
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
Make the Unicode dictionary of interned strings compatible with subinterpreters. Remove the INTERN_NAME_STRINGS macro in typeobject.c: names are always now interned (even if EXPERIMENTAL_ISOLATED_SUBINTERPRETERS macro is defined). _PyUnicode_ClearInterned() now uses PyDict_Next() to no longer allocate memory, to ensure that the interned dictionary is cleared.
vstinner added a commit that referenced this pull request Jan 6, 2022
)" (GH-30422) This reverts commit ea25180. Keep "assert(interned == NULL);" in _PyUnicode_Fini(), but only for the main interpreter. Keep _PyUnicode_ClearInterned() changes avoiding the creation of a temporary Python list object.
vstinner added a commit that referenced this pull request Jan 6, 2022
…GH-20085)" (GH-30422) (GH-30425) This reverts commit ea25180. Keep "assert(interned == NULL);" in _PyUnicode_Fini(), but only for the main interpreter. Keep _PyUnicode_ClearInterned() changes avoiding the creation of a temporary Python list object. Leave the PyInterpreterState structure unchanged to keep the ABI backward compatibility with Python 3.10.0: rename the "interned" member to "unused_interned". (cherry picked from commit 35d6540)
ericsnowcurrently added a commit to ericsnowcurrently/cpython that referenced this pull request Jan 13, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@vstinner@the-knights-who-say-ni@bedevere-bot