From 1b6fa3cc8431558dae822600d377262c611f4872 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Fri, 2 Jan 2026 22:32:59 +0900 Subject: [PATCH 1/4] gh-139757: Fix unintended BINARY_OP_SUBSCR_STR_INT for non-ASCII --- Lib/test/test_opcache.py | 9 +++++++++ Python/specialize.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) 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/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; } From f0372777d9dcb3c72ea0e7af6e3ba63422d1819a Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Fri, 2 Jan 2026 22:35:15 +0900 Subject: [PATCH 2/4] Add NEWS.d --- .../2026-01-02-22-35-12.gh-issue-139757.v5LRew.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-01-02-22-35-12.gh-issue-139757.v5LRew.rst 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..d7d82ebd277b0d --- /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 and Ken Jin. From f4a9ad5abf75c4777b8e3eee35367db6324c6d51 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Fri, 2 Jan 2026 22:36:58 +0900 Subject: [PATCH 3/4] nit --- .../2026-01-02-22-35-12.gh-issue-139757.v5LRew.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index d7d82ebd277b0d..643d40aebf9ac4 100644 --- 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 @@ -1,2 +1,2 @@ -Fix unintended bytecode specialization for non-ascii string. Patch by -Donghee Na and Ken Jin. +Fix unintended bytecode specialization for non-ascii string. +Patch by Donghee Na and Ken Jin. From 03a549c26792be6437510d1bb0306771da08c031 Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Fri, 2 Jan 2026 13:39:32 +0000 Subject: [PATCH 4/4] Update Misc/NEWS.d/next/Core_and_Builtins/2026-01-02-22-35-12.gh-issue-139757.v5LRew.rst --- .../2026-01-02-22-35-12.gh-issue-139757.v5LRew.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 643d40aebf9ac4..ef1a4e4b3af24f 100644 --- 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 @@ -1,2 +1,2 @@ Fix unintended bytecode specialization for non-ascii string. -Patch by Donghee Na and Ken Jin. +Patch by Donghee Na, Ken Jin and Chris Eibl.