[3.13] GH-122155: Fix cases generator to correctly compute 'peek' offset for error handling (GH-122158) by markshannon · Pull Request #122174 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Lib/test/test_generated_cases.py
6 changes: 5 additions & 1 deletion Tools/cases_generator/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,13 @@ def analyze_stack(op: parser.InstDef, replace_op_arg_1: str | None = None) -> St
convert_stack_item(i, replace_op_arg_1) for i in op.inputs if isinstance(i, parser.StackEffect)
]
outputs: list[StackItem] = [convert_stack_item(i, replace_op_arg_1) for i in op.outputs]
# Mark variables with matching names at the base of the stack as "peek"
modified = False
for input, output in zip(inputs, outputs):
if input.name == output.name:
if input.name == output.name and not modified:
input.peek = output.peek = True
else:
modified = True
return StackEffect(inputs, outputs)


Expand Down
2 changes: 1 addition & 1 deletion Tools/cases_generator/generators_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def replace_error(
next(tkn_iter) # RPAREN
next(tkn_iter) # Semi colon
out.emit(") ")
c_offset = stack.peek_offset.to_c()
c_offset = stack.peek_offset()
try:
offset = -int(c_offset)
close = ";\n"
Expand Down
15 changes: 11 additions & 4 deletions Tools/cases_generator/stack.py