From 5f225caf526f3dc47399e2a79ca58703079fca47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nenad=20=C4=8Caklovi=C4=87?= Date: Fri, 5 Jan 2024 21:32:53 +0100 Subject: [PATCH 1/3] LOAD_ATTR operand changes in 3.12 --- ASTree.cpp | 5 ++++- bytecode.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ASTree.cpp b/ASTree.cpp index 87762654c..4a33bffeb 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -1473,8 +1473,11 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) { PycRef name = stack.top(); if (name.type() != ASTNode::NODE_IMPORT) { + auto arg = operand; + if (mod->verCompare(3, 12) >= 0 && (arg & 1)) + arg >>= 1; stack.pop(); - stack.push(new ASTBinary(name, new ASTName(code->getName(operand)), ASTBinary::BIN_ATTR)); + stack.push(new ASTBinary(name, new ASTName(code->getName(arg)), ASTBinary::BIN_ATTR)); } } break; diff --git a/bytecode.cpp b/bytecode.cpp index 33c1abcbf..20969a993 100644 --- a/bytecode.cpp +++ b/bytecode.cpp @@ -390,7 +390,10 @@ void bc_disasm(std::ostream& pyc_output, PycRef code, PycModule* mod, case Pyc::LOAD_METHOD_A: case Pyc::LOAD_FROM_DICT_OR_GLOBALS_A: try { - formatted_print(pyc_output, "%d: %s", operand, code->getName(operand)->value()); + auto arg = operand; + if (opcode == Pyc::LOAD_ATTR_A && mod->verCompare(3, 12) >= 0 && (arg & 1)) + arg >>= 1; + formatted_print(pyc_output, "%d: %s", operand, code->getName(arg)->value()); } catch (const std::out_of_range &) { formatted_print(pyc_output, "%d ", operand); } From 28b62b6534213ee68270b3d8990f5833b488057e Mon Sep 17 00:00:00 2001 From: ncaklovic Date: Wed, 28 Feb 2024 12:34:15 +0100 Subject: [PATCH 2/3] Update bytecode.cpp Co-authored-by: Michael Hansen --- bytecode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bytecode.cpp b/bytecode.cpp index 20969a993..0d780fb76 100644 --- a/bytecode.cpp +++ b/bytecode.cpp @@ -391,7 +391,7 @@ void bc_disasm(std::ostream& pyc_output, PycRef code, PycModule* mod, case Pyc::LOAD_FROM_DICT_OR_GLOBALS_A: try { auto arg = operand; - if (opcode == Pyc::LOAD_ATTR_A && mod->verCompare(3, 12) >= 0 && (arg & 1)) + if (opcode == Pyc::LOAD_ATTR_A && mod->verCompare(3, 12) >= 0) arg >>= 1; formatted_print(pyc_output, "%d: %s", operand, code->getName(arg)->value()); } catch (const std::out_of_range &) { From 32c1ca10bbd95a3d860dba875a4737691544a3ca Mon Sep 17 00:00:00 2001 From: ncaklovic Date: Wed, 28 Feb 2024 12:34:32 +0100 Subject: [PATCH 3/3] Update ASTree.cpp Co-authored-by: Michael Hansen --- ASTree.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ASTree.cpp b/ASTree.cpp index 4a33bffeb..840d55799 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -1473,9 +1473,7 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) { PycRef name = stack.top(); if (name.type() != ASTNode::NODE_IMPORT) { - auto arg = operand; - if (mod->verCompare(3, 12) >= 0 && (arg & 1)) - arg >>= 1; + auto arg = (mod->verCompare(3, 12) >= 0) ? operand >> 1 : operand; stack.pop(); stack.push(new ASTBinary(name, new ASTName(code->getName(arg)), ASTBinary::BIN_ATTR)); }