https://github.com/python/cpython/commit/61f2ad9a3a78597bb1983c3392a758ed02709574
commit: 61f2ad9a3a78597bb1983c3392a758ed02709574
branch: main
author: Donghee Na <[email protected]>
committer: corona10 <[email protected]>
date: 2026-01-02T14:05:08Z
summary:
gh-139757: Fix unintended bytecode specialization for non-ascii string
(gh-143352)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2026-01-02-22-35-12.gh-issue-139757.v5LRew.rst
M Lib/test/test_opcache.py
M Python/specialize.c
diff --git a/Lib/test/test_opcache.py b/Lib/test/test_opcache.py
index 4113b79ef5c80b..4df88d0f16885f 100644
--- a/Lib/test/test_opcache.py
+++ b/Lib/test/test_opcache.py
@@ -1785,6 +1785,15 @@ def binary_subscr_str_int():
self.assert_specialized(binary_subscr_str_int,
"BINARY_OP_SUBSCR_STR_INT")
self.assert_no_opcode(binary_subscr_str_int, "BINARY_OP")
+ def binary_subscr_str_int_non_compact():
+ for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
+ a = "바이트코드_특수화"
+ for idx, expected in enumerate(a):
+ self.assertEqual(a[idx], expected)
+
+ binary_subscr_str_int_non_compact()
+ self.assert_no_opcode(binary_subscr_str_int_non_compact,
"BINARY_OP_SUBSCR_STR_INT")
+
def binary_subscr_getitems():
class C:
def __init__(self, val):
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2026-01-02-22-35-12.gh-issue-139757.v5LRew.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2026-01-02-22-35-12.gh-issue-139757.v5LRew.rst
new file mode 100644
index 00000000000000..ef1a4e4b3af24f
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2026-01-02-22-35-12.gh-issue-139757.v5LRew.rst
@@ -0,0 +1,2 @@
+Fix unintended bytecode specialization for non-ascii string.
+Patch by Donghee Na, Ken Jin and Chris Eibl.
diff --git a/Python/specialize.c b/Python/specialize.c
index e67078afdd9df3..e9302157e7782a 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -2240,7 +2240,7 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef
rhs_st, _Py_CODEUNIT *in
specialize(instr, BINARY_OP_SUBSCR_TUPLE_INT);
return;
}
- if (PyUnicode_CheckExact(lhs)) {
+ if (PyUnicode_CheckExact(lhs) &&
PyUnicode_IS_COMPACT_ASCII(lhs)) {
specialize(instr, BINARY_OP_SUBSCR_STR_INT);
return;
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]