]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-98831: Fix two bugs in case generator (#101349)
authorGuido van Rossum <guido@python.org>
Thu, 26 Jan 2023 17:15:05 +0000 (09:15 -0800)
committerGitHub <noreply@github.com>
Thu, 26 Jan 2023 17:15:05 +0000 (09:15 -0800)
Fix two bugs in case generator

- UndefinedLocalError when generating metadata for an 'op'
- Accidental newline inserted in test_generator.py

Tools/cases_generator/generate_cases.py
Tools/cases_generator/test_generator.py

index b7942410c82fc3c826892902e94e0d76e27106dd..9d894d2ff5745550e2efb1b36e8e3adaebe5e043 100644 (file)
@@ -736,7 +736,7 @@ class Analyzer:
 
     def get_stack_effect_info(
         self, thing: parser.InstDef | parser.Super | parser.Macro
-    ) -> tuple[Instruction, str, str]:
+    ) -> tuple[Instruction|None, str, str]:
 
         def effect_str(effect: list[StackEffect]) -> str:
             if getattr(thing, 'kind', None) == 'legacy':
@@ -752,6 +752,9 @@ class Analyzer:
                     instr = self.instrs[thing.name]
                     popped = effect_str(instr.input_effects)
                     pushed = effect_str(instr.output_effects)
+                else:
+                    instr = None
+                    popped = pushed = "", ""
             case parser.Super():
                 instr = self.super_instrs[thing.name]
                 popped = '+'.join(effect_str(comp.instr.input_effects) for comp in instr.parts)
@@ -770,8 +773,9 @@ class Analyzer:
         pushed_data = []
         for thing in self.everything:
             instr, popped, pushed = self.get_stack_effect_info(thing)
-            popped_data.append( (instr, popped) )
-            pushed_data.append( (instr, pushed) )
+            if instr is not None:
+                popped_data.append( (instr, popped) )
+                pushed_data.append( (instr, pushed) )
 
         def write_function(direction: str, data: list[tuple[Instruction, str]]) -> None:
             self.out.emit("\n#ifndef NDEBUG");
index cf58e6aaf2b37c9159274f22856ce8005ac05108..bd1b974399abdd4a12a75bd27d0a27fbbf1fef9e 100644 (file)
@@ -358,8 +358,7 @@ def test_macro_instruction():
             {
                 PyObject *arg1 = _tmp_1;
                 PyObject *interim;
-                uint16_t counter = re
-                ad_u16(&next_instr[0].cache);
+                uint16_t counter = read_u16(&next_instr[0].cache);
                 interim = op1(arg1);
                 _tmp_1 = interim;
             }