Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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. Patch by Victor Stinner.
5 changes: 4 additions & 1 deletion 5 Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -8459,7 +8459,10 @@ update_slot(PyTypeObject *type, PyObject *name)
for (p = slotdefs; p->name; p++) {
assert(PyUnicode_CheckExact(p->name_strobj));
assert(PyUnicode_CheckExact(name));
if (p->name_strobj == name) {
// bpo-46006: subinterpreters require to compare strings contents, even
// if both strings are interned. _PyUnicode_EQ() is required to keep
// support for built-in static types in subinterpreters.
if (p->name_strobj == name || _PyUnicode_EQ(p->name_strobj, name)) {
*pp++ = p;
}
}
Expand Down
15 changes: 11 additions & 4 deletions 15 Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -11336,11 +11336,18 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right)
return _PyUnicode_EqualToASCIIString(left, right->string);
}

if (left == right_uni)
if (left == right_uni) {
return 1;

if (PyUnicode_CHECK_INTERNED(left))
return 0;
}
// bpo-46006: The left string cannot be considered as not equal to the
// right string if the left string is interned, because the two string
// objects can belong to two interpreters.
//
// While an interpreter is supposed to only access objects that it created
// (bpo-40533), in practice in Python 3.11, it remains common that a
// subinterpreter access objects of the main interprter. For example,
// access attribute names (strings) of static types created by the main
// interpreter.

assert(_PyUnicode_HASH(right_uni) != -1);
Py_hash_t hash = _PyUnicode_HASH(left);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.