From 830dd1322871770077497889bd6efce81f2944cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nenad=20=C4=8Caklovi=C4=87?= Date: Thu, 4 Jan 2024 23:42:54 +0100 Subject: [PATCH] COMPARE_OP operand changes in 3.12 --- ASTree.cpp | 5 ++++- bytecode.cpp | 13 +++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ASTree.cpp b/ASTree.cpp index 108e4e4a7..87762654c 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -638,7 +638,10 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) stack.pop(); PycRef left = stack.top(); stack.pop(); - stack.push(new ASTCompare(left, right, operand)); + auto arg = operand; + if (mod->verCompare(3, 12) >= 0) + arg >>= 4; // changed under GH-100923 + stack.push(new ASTCompare(left, right, arg)); } break; case Pyc::CONTAINS_OP_A: diff --git a/bytecode.cpp b/bytecode.cpp index 1dc9dc0d9..33c1abcbf 100644 --- a/bytecode.cpp +++ b/bytecode.cpp @@ -489,10 +489,15 @@ void bc_disasm(std::ostream& pyc_output, PycRef code, PycModule* mod, } break; case Pyc::COMPARE_OP_A: - if (static_cast(operand) < cmp_strings_len) - formatted_print(pyc_output, "%d (%s)", operand, cmp_strings[operand]); - else - formatted_print(pyc_output, "%d (UNKNOWN)", operand); + { + auto arg = operand; + if (mod->verCompare(3, 12) >= 0) + arg >>= 4; // changed under GH-100923 + if (static_cast(arg) < cmp_strings_len) + formatted_print(pyc_output, "%d (%s)", operand, cmp_strings[arg]); + else + formatted_print(pyc_output, "%d (UNKNOWN)", operand); + } break; case Pyc::BINARY_OP_A: if (static_cast(operand) < binop_strings_len)