Skip to content

Commit b013804

Browse files
authored
pythongh-92932: dis._unpack_opargs should handle EXTENDED_ARG_QUICK (pythongh-92945)
1 parent 941d705 commit b013804

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Lib/dis.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def _unpack_opargs(code):
592592
caches = _inline_cache_entries[deop]
593593
if deop >= HAVE_ARGUMENT:
594594
arg = code[i+1] | extended_arg
595-
extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
595+
extended_arg = (arg << 8) if deop == EXTENDED_ARG else 0
596596
# The oparg is stored as a signed integer
597597
# If the value exceeds its upper limit, it will overflow and wrap
598598
# to a negative integer

Lib/test/test_dis.py

+21
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,22 @@ def loop_test():
620620
loop_test.__code__.co_firstlineno + 2,
621621
loop_test.__code__.co_firstlineno + 1,)
622622

623+
def extended_arg_quick():
624+
*_, _ = ...
625+
626+
dis_extended_arg_quick_code = """\
627+
%3d 0 RESUME 0
628+
629+
%3d 2 LOAD_CONST 1 (Ellipsis)
630+
4 EXTENDED_ARG_QUICK 1
631+
6 UNPACK_EX 256
632+
8 STORE_FAST 0 (_)
633+
10 STORE_FAST 0 (_)
634+
12 LOAD_CONST 0 (None)
635+
14 RETURN_VALUE
636+
"""% (extended_arg_quick.__code__.co_firstlineno,
637+
extended_arg_quick.__code__.co_firstlineno + 1,)
638+
623639
QUICKENING_WARMUP_DELAY = 8
624640

625641
class DisTestBase(unittest.TestCase):
@@ -997,6 +1013,11 @@ def test_loop_quicken(self):
9971013
got = self.get_disassembly(loop_test, adaptive=True)
9981014
self.do_disassembly_compare(got, dis_loop_test_quickened_code)
9991015

1016+
@cpython_only
1017+
def test_extended_arg_quick(self):
1018+
got = self.get_disassembly(extended_arg_quick)
1019+
self.do_disassembly_compare(got, dis_extended_arg_quick_code, True)
1020+
10001021
def get_cached_values(self, quickened, adaptive):
10011022
def f():
10021023
l = []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Now :func:`~dis.dis` and :func:`~dis.get_instructions` handle operand values
2+
for instructions prefixed by ``EXTENDED_ARG_QUICK``.
3+
Patch by Sam Gross and Dong-hee Na.

0 commit comments

Comments
 (0)