Support jumps in Python 3.10+
Svenskithesource opened this issue · 0 comments
Svenskithesource commented
In Python 3.10+ the arguments for all jump opcodes were divided by 2. We need to handle that in the unpacker.
See the example below:
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import dis
>>> def demo(num):
... if num == 1:
... print("equal")
... else:
... print("not equal")
...
>>> dis.dis(demo.__code__)
2 0 LOAD_FAST 0 (num)
2 LOAD_CONST 1 (1)
4 COMPARE_OP 2 (==)
6 POP_JUMP_IF_FALSE 10 (to 20)
3 8 LOAD_GLOBAL 0 (print)
10 LOAD_CONST 2 ('equal')
12 CALL_FUNCTION 1
14 POP_TOP
16 LOAD_CONST 0 (None)
18 RETURN_VALUE
5 >> 20 LOAD_GLOBAL 0 (print)
22 LOAD_CONST 3 ('not equal')
24 CALL_FUNCTION 1
26 POP_TOP
28 LOAD_CONST 0 (None)
30 RETURN_VALUE
>>>
We can see that the argument for instruction at index 6 (POP_JUMP_IF_FALSE
) has argument 10
. dis
shows us it's actually pointing to index 20.