Repository navigation
PyUnicode_InternFromString does not immortalize the string as the document claims #133260
Copy link
Copy link
Closed
Closed
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errorinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)and removeddocsDocumentation in the Doc dirDocumentation in the Doc dir
on May 1, 2025 Either it's a doc issue or it's an implementation issue. So I'll let both tags.
cc @encukou
Oh, good catch! Thanks! I did miss that in #121364 :/
Given that 3.13 is in bugfix-only mode, I'll remove the docs note and backport that.@colesbury:
PyUnicode_InternFromStringcan start immortalizing the string inmainand possibly 3.14. Will it help free-threading?- added a commit that references this issue
on May 29, 2025 The docs now allow either behaviour. Closing.
Later we can makePyUnicode_InternFromStringimmortalize, if it's helpful.Thank you for the report, @yuyichao!
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsTodo
Documentation
The document for
PyUnicode_InternFromStringcurrently claimed thatHowever, testing with simple code like,
suggests that the returned value is not, which is expected based on the code since it calls
_PyUnicode_InternMortalrather than_PyUnicode_InternImmortal. If a call to the internal APIPyUnicode_InternImmortalwas added (as in the commented out code above), then the string is indeed immortalized.This document was added in #121364 but that PR did not change the behavior of this function. AFAICT,
PyUnicode_InternFromStringnever immortalize the string ever since it was added in #120520.The only public API that ever immortalized the input string appears to be
PyUnicode_InternInPlaceand that was changed in #121364 (the one that added the wrong doc) and there doesn't seem to be any public API that immortalize the string anymore. Although this is technically a document issue, I think it might be better to change the behavior of the function instead to match the document.Linked PRs