Skip to content

Commit c5bfb88

Browse files
authored
[3.10] bpo-45757: Fix bug where dis produced an incorrect oparg on EXTENDED_ARG before a no-arg opcode (GH-29480) (GH-29506)
1 parent d29f591 commit c5bfb88

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

Lib/dis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ def _unpack_opargs(code):
428428
extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
429429
else:
430430
arg = None
431+
extended_arg = 0
431432
yield (i, op, arg)
432433

433434
def findlabels(code):

Lib/test/test_dis.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ def bug42562():
180180
2 RETURN_VALUE
181181
"""
182182

183+
# Extended arg followed by NOP
184+
code_bug_45757 = bytes([
185+
0x90, 0x01, # EXTENDED_ARG 0x01
186+
0x09, 0xFF, # NOP 0xFF
187+
0x90, 0x01, # EXTENDED_ARG 0x01
188+
0x64, 0x29, # LOAD_CONST 0x29
189+
0x53, 0x00, # RETURN_VALUE 0x00
190+
])
191+
192+
dis_bug_45757 = """\
193+
0 EXTENDED_ARG 1
194+
2 NOP
195+
4 EXTENDED_ARG 1
196+
6 LOAD_CONST 297 (297)
197+
8 RETURN_VALUE
198+
"""
199+
183200
_BIG_LINENO_FORMAT = """\
184201
%3d 0 LOAD_GLOBAL 0 (spam)
185202
2 POP_TOP
@@ -534,6 +551,10 @@ def test_bug_1333982(self):
534551
def test_bug_42562(self):
535552
self.do_disassembly_test(bug42562, dis_bug42562)
536553

554+
def test_bug_45757(self):
555+
# Extended arg followed by NOP
556+
self.do_disassembly_test(code_bug_45757, dis_bug_45757)
557+
537558
def test_big_linenos(self):
538559
def func(count):
539560
namespace = {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where :mod:`dis` produced an incorrect oparg when :opcode:`EXTENDED_ARG` is followed by an opcode that does not use its argument.

0 commit comments

Comments
 (0)