Skip to content

Commit e798f69

Browse files
gh-92932: dis._unpack_opargs should handle EXTENDED_ARG_QUICK (gh-92945)
(cherry picked from commit b013804) Co-authored-by: Dong-hee Na <donghee.na@python.org>
1 parent 376d537 commit e798f69

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
@@ -633,6 +633,22 @@ def loop_test():
633633
loop_test.__code__.co_firstlineno + 2,
634634
loop_test.__code__.co_firstlineno + 1,)
635635

636+
def extended_arg_quick():
637+
*_, _ = ...
638+
639+
dis_extended_arg_quick_code = """\
640+
%3d 0 RESUME 0
641+
642+
%3d 2 LOAD_CONST 1 (Ellipsis)
643+
4 EXTENDED_ARG_QUICK 1
644+
6 UNPACK_EX 256
645+
8 STORE_FAST 0 (_)
646+
10 STORE_FAST 0 (_)
647+
12 LOAD_CONST 0 (None)
648+
14 RETURN_VALUE
649+
"""% (extended_arg_quick.__code__.co_firstlineno,
650+
extended_arg_quick.__code__.co_firstlineno + 1,)
651+
636652
QUICKENING_WARMUP_DELAY = 8
637653

638654
class DisTestBase(unittest.TestCase):
@@ -1011,6 +1027,11 @@ def test_loop_quicken(self):
10111027
got = self.get_disassembly(loop_test, adaptive=True)
10121028
self.do_disassembly_compare(got, dis_loop_test_quickened_code, True)
10131029

1030+
@cpython_only
1031+
def test_extended_arg_quick(self):
1032+
got = self.get_disassembly(extended_arg_quick)
1033+
self.do_disassembly_compare(got, dis_extended_arg_quick_code, True)
1034+
10141035
def get_cached_values(self, quickened, adaptive):
10151036
def f():
10161037
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)