]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-45757: Fix bug where dis produced an incorrect oparg on EXTENDED_ARG befor...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Tue, 9 Nov 2021 22:05:30 +0000 (22:05 +0000)
committerGitHub <noreply@github.com>
Tue, 9 Nov 2021 22:05:30 +0000 (22:05 +0000)
Lib/dis.py
Lib/test/test_dis.py
Misc/NEWS.d/next/Library/2021-11-08-23-22-14.bpo-45757.MHZHt3.rst [new file with mode: 0644]

index 3fee1ce27725cda243fd3dce26f83d8591d8b6e2..fe5d24e88058f745b7df7ddab4c5efc23e7bb27e 100644 (file)
@@ -428,6 +428,7 @@ def _unpack_opargs(code):
             extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
         else:
             arg = None
+            extended_arg = 0
         yield (i, op, arg)
 
 def findlabels(code):
index 2cb2eff9a6c3f1e49bc9b3df056d2b3d083b50ee..000549f5b6f1143df81a077b0eed02f6a97defe8 100644 (file)
@@ -180,6 +180,23 @@ dis_bug42562 = """\
           2 RETURN_VALUE
 """
 
+# Extended arg followed by NOP
+code_bug_45757 = bytes([
+        0x90, 0x01,  # EXTENDED_ARG 0x01
+        0x09, 0xFF,  # NOP 0xFF
+        0x90, 0x01,  # EXTENDED_ARG 0x01
+        0x64, 0x29,  # LOAD_CONST 0x29
+        0x53, 0x00,  # RETURN_VALUE 0x00
+    ])
+
+dis_bug_45757 = """\
+          0 EXTENDED_ARG             1
+          2 NOP
+          4 EXTENDED_ARG             1
+          6 LOAD_CONST             297 (297)
+          8 RETURN_VALUE
+"""
+
 _BIG_LINENO_FORMAT = """\
 %3d           0 LOAD_GLOBAL              0 (spam)
               2 POP_TOP
@@ -534,6 +551,10 @@ class DisTests(unittest.TestCase):
     def test_bug_42562(self):
         self.do_disassembly_test(bug42562, dis_bug42562)
 
+    def test_bug_45757(self):
+        # Extended arg followed by NOP
+        self.do_disassembly_test(code_bug_45757, dis_bug_45757)
+
     def test_big_linenos(self):
         def func(count):
             namespace = {}
diff --git a/Misc/NEWS.d/next/Library/2021-11-08-23-22-14.bpo-45757.MHZHt3.rst b/Misc/NEWS.d/next/Library/2021-11-08-23-22-14.bpo-45757.MHZHt3.rst
new file mode 100644 (file)
index 0000000..f25638c
--- /dev/null
@@ -0,0 +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.
\ No newline at end of file