]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92932: dis._unpack_opargs should handle EXTENDED_ARG_QUICK (gh-92945)
authorDong-hee Na <donghee.na@python.org>
Fri, 3 Jun 2022 02:29:27 +0000 (11:29 +0900)
committerGitHub <noreply@github.com>
Fri, 3 Jun 2022 02:29:27 +0000 (11:29 +0900)
Lib/dis.py
Lib/test/test_dis.py
Misc/NEWS.d/next/Library/2022-05-19-17-49-58.gh-issue-92932.o2peTh.rst [new file with mode: 0644]

index 046013120b000de0e58b17e4f4f924fbe777a91a..5a5ee8d848d3a49f230d5520fee3d7b192272f2d 100644 (file)
@@ -592,7 +592,7 @@ def _unpack_opargs(code):
         caches = _inline_cache_entries[deop]
         if deop >= HAVE_ARGUMENT:
             arg = code[i+1] | extended_arg
-            extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
+            extended_arg = (arg << 8) if deop == EXTENDED_ARG else 0
             # The oparg is stored as a signed integer
             # If the value exceeds its upper limit, it will overflow and wrap
             # to a negative integer
index 244a24591b241eb3ce341bb9c6730e80da7a20ff..a4f7f84995bf5f9d9e236decc2150cb759ec5a81 100644 (file)
@@ -620,6 +620,22 @@ dis_loop_test_quickened_code = """\
        loop_test.__code__.co_firstlineno + 2,
        loop_test.__code__.co_firstlineno + 1,)
 
+def extended_arg_quick():
+    *_, _ = ...
+
+dis_extended_arg_quick_code = """\
+%3d           0 RESUME                   0
+
+%3d           2 LOAD_CONST               1 (Ellipsis)
+              4 EXTENDED_ARG_QUICK       1
+              6 UNPACK_EX              256
+              8 STORE_FAST               0 (_)
+             10 STORE_FAST               0 (_)
+             12 LOAD_CONST               0 (None)
+             14 RETURN_VALUE
+"""% (extended_arg_quick.__code__.co_firstlineno,
+      extended_arg_quick.__code__.co_firstlineno + 1,)
+
 QUICKENING_WARMUP_DELAY = 8
 
 class DisTestBase(unittest.TestCase):
@@ -997,6 +1013,11 @@ class DisTests(DisTestBase):
         got = self.get_disassembly(loop_test, adaptive=True)
         self.do_disassembly_compare(got, dis_loop_test_quickened_code)
 
+    @cpython_only
+    def test_extended_arg_quick(self):
+        got = self.get_disassembly(extended_arg_quick)
+        self.do_disassembly_compare(got, dis_extended_arg_quick_code, True)
+
     def get_cached_values(self, quickened, adaptive):
         def f():
             l = []
diff --git a/Misc/NEWS.d/next/Library/2022-05-19-17-49-58.gh-issue-92932.o2peTh.rst b/Misc/NEWS.d/next/Library/2022-05-19-17-49-58.gh-issue-92932.o2peTh.rst
new file mode 100644 (file)
index 0000000..cb76ac5
--- /dev/null
@@ -0,0 +1,3 @@
+Now :func:`~dis.dis` and :func:`~dis.get_instructions` handle operand values
+for instructions prefixed by ``EXTENDED_ARG_QUICK``.
+Patch by Sam Gross and Dong-hee Na.