Skip to content

Commit 9f2c479

Browse files
authored
gh-98831: Fix two bugs in case generator (#101349)
Fix two bugs in case generator - UndefinedLocalError when generating metadata for an 'op' - Accidental newline inserted in test_generator.py
1 parent 409f533 commit 9f2c479

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Tools/cases_generator/generate_cases.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def stack_analysis(
736736

737737
def get_stack_effect_info(
738738
self, thing: parser.InstDef | parser.Super | parser.Macro
739-
) -> tuple[Instruction, str, str]:
739+
) -> tuple[Instruction|None, str, str]:
740740

741741
def effect_str(effect: list[StackEffect]) -> str:
742742
if getattr(thing, 'kind', None) == 'legacy':
@@ -752,6 +752,9 @@ def effect_str(effect: list[StackEffect]) -> str:
752752
instr = self.instrs[thing.name]
753753
popped = effect_str(instr.input_effects)
754754
pushed = effect_str(instr.output_effects)
755+
else:
756+
instr = None
757+
popped = pushed = "", ""
755758
case parser.Super():
756759
instr = self.super_instrs[thing.name]
757760
popped = '+'.join(effect_str(comp.instr.input_effects) for comp in instr.parts)
@@ -770,8 +773,9 @@ def write_stack_effect_functions(self) -> None:
770773
pushed_data = []
771774
for thing in self.everything:
772775
instr, popped, pushed = self.get_stack_effect_info(thing)
773-
popped_data.append( (instr, popped) )
774-
pushed_data.append( (instr, pushed) )
776+
if instr is not None:
777+
popped_data.append( (instr, popped) )
778+
pushed_data.append( (instr, pushed) )
775779

776780
def write_function(direction: str, data: list[tuple[Instruction, str]]) -> None:
777781
self.out.emit("\n#ifndef NDEBUG");

Tools/cases_generator/test_generator.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ def test_macro_instruction():
358358
{
359359
PyObject *arg1 = _tmp_1;
360360
PyObject *interim;
361-
uint16_t counter = re
362-
ad_u16(&next_instr[0].cache);
361+
uint16_t counter = read_u16(&next_instr[0].cache);
363362
interim = op1(arg1);
364363
_tmp_1 = interim;
365364
}

0 commit comments

Comments
 (0)