Skip to content

PyUnicode_InternFromString does not immortalize the string as the document claims #133260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yuyichao opened this issue May 1, 2025 · 2 comments
Labels
docs Documentation in the Doc dir interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-C-API type-bug An unexpected behavior, bug, or error

Comments

@yuyichao
Copy link

yuyichao commented May 1, 2025

Documentation

The document for PyUnicode_InternFromString currently claimed that

CPython implementation detail: Strings interned this way are made immortal.

However, testing with simple code like,

        auto v = PyUnicode_InternFromString("abcdefg_aaaaa");
        // PyUnicode_InternImmortal(&v);
        printf("immortalized? %d\n", _Py_IsImmortal(v));

suggests that the returned value is not, which is expected based on the code since it calls _PyUnicode_InternMortal rather than _PyUnicode_InternImmortal. If a call to the internal API PyUnicode_InternImmortal was 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_InternFromString never immortalize the string ever since it was added in #120520.

The only public API that ever immortalized the input string appears to be PyUnicode_InternInPlace and 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.

@yuyichao yuyichao added the docs Documentation in the Doc dir label May 1, 2025
@picnixz picnixz added topic-C-API type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) and removed docs Documentation in the Doc dir labels May 1, 2025
@picnixz
Copy link
Member

picnixz commented May 4, 2025

Either it's a doc issue or it's an implementation issue. So I'll let both tags.

@picnixz picnixz added the docs Documentation in the Doc dir label May 4, 2025
@neonene
Copy link
Contributor

neonene commented May 5, 2025

cc @encukou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-C-API type-bug An unexpected behavior, bug, or error
Projects
Status: Todo
Development

No branches or pull requests

3 participants