Skip to content
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

bpo-46006: Fix _PyUnicode_EqualToASCIIId() for interned strings #30123

Closed
wants to merge 1 commit into from
Closed

bpo-46006: Fix _PyUnicode_EqualToASCIIId() for interned strings #30123

wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Dec 15, 2021

Fix string comparisons for subinterpreters: no longer make the assumption
that two interned strings are not equal if they have different different
memory addresses. This assumption is no longer true since interned
strings have been made per interpreter in Python 3.10.

Fix _PyUnicode_EqualToASCIIId() and type update_slot() functions.

The change makes update_slot() a little bit less efficient:
update_slot() now compares the strings contents, rather than
comparing strings memory addresses.

https://bugs.python.org/issue46006

Fix string comparisons for subinterpreters: no longer make the assumption
that two interned strings are not equal if they have different different
memory addresses. This assumption is no longer true since interned
strings have been made per interpreter in Python 3.10.

Fix _PyUnicode_EqualToASCIIId() and type update_slot() functions.

The change makes update_slot() a little bit less efficient:
update_slot() now compares the strings contents, rather than
comparing strings memory addresses.
@vstinner
Copy link
Member Author

cc @methane @serhiy-storchaka @corona10

We will be able to add again this micro-optimization once Python C extensions and third-party C extensions will no longer define and use static types and will stop sharing objects between two interpreters. Sadly, this long term goal may take a few years...

@markshannon
Copy link
Member

It is meaningless to compare strings from one fully isolated interpreter with those in another.
So the assumption that id(o1) != id(o2) implies o1 != o2 is still true for a valid comparison of interned strings.

Feel free to add an assert, but please avoid this sort of pessimization for a hypothetical future which may well not happen.

@hroncok
Copy link
Contributor

hroncok commented Dec 15, 2021

Suggestion: add the reproducer from https://bugs.python.org/issue46034 as a test?

@vstinner
Copy link
Member Author

Feel free to add an assert, but please avoid this sort of pessimization for a hypothetical future which may well not happen.

@markshannon: I'm not sure what you are talking about. https://bugs.python.org/issue46006 is affecting multiple Python 3.10 users right now. It's not an hypothetical bug. At least, jep and mod_wsgi projects are known to be affected by the bug:

The bug may also explain https://bugs.python.org/issue46070 which affects more projects.

@vstinner
Copy link
Member Author

It is meaningless to compare strings from one fully isolated interpreter with those in another.

@markshannon: I added long comments as part of the change to explain the issue. Did you see my comments? It's about interned strings of static types which are shared by all interpreters.

@markshannon
Copy link
Member

I'll comment on the issue.

@markshannon
Copy link
Member

I agree that a fix is needed. But this is not the needed fix.

@vstinner
Copy link
Member Author

vstinner commented Jan 6, 2022

I merged GH-20085 instead.

@vstinner vstinner closed this Jan 6, 2022
@vstinner vstinner deleted the interned branch January 6, 2022 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants