gh-103571: Add runtime-global strings to the initial per-interpreter interned_dict#103572
Closed
Christopher-Chianelli wants to merge 2 commits intopython:mainfrom
Closed
gh-103571: Add runtime-global strings to the initial per-interpreter interned_dict#103572Christopher-Chianelli wants to merge 2 commits intopython:mainfrom
Christopher-Chianelli wants to merge 2 commits intopython:mainfrom
Conversation
…reter interned_dict bpo-46430 caused an interesting side effect; the code `x = 'a'; x[0] is x` no longer returned True. This in turn is because there are two different cached versions of 'a': - One that was cached when code in frozen modules was compiled (and is stored in the interned_dict) - One that is stored as a runtime-global object that is used during function calls (and is stored in _Py_SINGLETON(strings)) However, some characters do not have this behaviour (for example, 'g', 'u', and 'z'). I suspect it because these characters are not used in co_consts of frozen modules. The interned_dict is per interpreter, and is initialized by `init_interned_dict(PyInterpreterState *)`. The prior implementation initialize it to an empty dict, which allows code in frozen modules to use their (different and per interpreter) singleton strings instead of the runtime-global one. The new implementation add all runtime-global singleton strings to the interned_dict when it initialized, causing the frozen modules to use the same immortal singleton string and for `x = 'a'; x[0] is x` to return True.
Using it in the intern dict seems to causes decrementation of its reference count elsewhere that cannot be solved with Py_INCREF. However, updating the tuple inside intern_string_constants does not cause the extra decrementation.
Contributor
|
See my comment on issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bpo-46430 caused an interesting side effect; the code
x = 'a'; x[0] is xno longer returned True. This in turn is because there are two different cached versions of 'a':However, some characters do not have this behaviour (for example, 'g', 'u', and 'z'). I suspect it because these characters are not used in co_consts of frozen modules.
The interned_dict is per interpreter, and is initialized by
init_interned_dict(PyInterpreterState *). The prior implementation initialize it to an empty dict, which allows code in frozen modules to use their (different and per interpreter) singleton strings instead of the runtime-global one.The new implementation add all runtime-global singleton strings to the interned_dict when it initialized, causing the frozen modules to use the same immortal singleton string and for
x = 'a'; x[0] is xto return True.