Skip to content

f_lasti points to CACHE opcode during inlined CALL#96970

@15r10nk

Description

@15r10nk

The instruction pointer f_lasti points under some conditions to a CACHE opcode.
This is not completely wrong, because this cache opcode comes after the expected CALL opcode, but the documetation says that CACHE opcodes should be skipped. Which it is not in this case.

script:

importinspectimportdisframe=inspect.currentframe() classTester: def__call__(self, f): deco(f) tester=Tester() defdeco(f): assertf.__name__=="foo"instructions=list(dis.get_instructions(frame.f_code, show_caches=True)) opname=instructions[frame.f_lasti//2].opnameprint(f"{frame.f_lasti=}\n{opname=}") assertopname=="CALL", opnameprint("correct") @testerdeffoo(): passprint() print("incorrect") @decodeffoo(): pass

output (Python 3.11.0rc2+):

correctframe.f_lasti=132opname='CALL'incorrectframe.f_lasti=204opname='CACHE'Traceback (mostrecentcalllast): File"/home/frank/projects/executing/example.py", line35, in<module> @deco^^^^File"/home/frank/projects/executing/example.py", line20, indecoassertopname=="CALL", opnameAssertionError: CACHE

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions