]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126211: Exclude preprocessor directives from statements containing escaping calls...
authormpage <mpage@cs.stanford.edu>
Fri, 1 Nov 2024 15:53:03 +0000 (08:53 -0700)
committerGitHub <noreply@github.com>
Fri, 1 Nov 2024 15:53:03 +0000 (08:53 -0700)
The cases generator inserts code to save and restore the stack pointer around
statements that contain escaping calls. To find the beginning of such statements,
we would walk backwards from the escaping call until we encountered a token that
was treated as a statement terminator. This set of terminators should include
preprocessor directives.

Lib/test/test_generated_cases.py
Tools/cases_generator/analyzer.py

index 173e405b785ddc2bc4d896149295853556f3b2f4..ff9a52b7adac8a54e85a4c7ad616d93f3197f7a7 100644 (file)
@@ -1429,6 +1429,39 @@ class TestGeneratedCases(unittest.TestCase):
         with self.assertRaisesRegex(SyntaxError, "All instructions containing a uop"):
             self.run_cases_test(input, output)
 
+    def test_escaping_call_next_to_cmacro(self):
+        input = """
+        inst(OP, (--)) {
+            #ifdef Py_GIL_DISABLED
+            escaping_call();
+            #else
+            another_escaping_call();
+            #endif
+            yet_another_escaping_call();
+        }
+        """
+        output = """
+        TARGET(OP) {
+            frame->instr_ptr = next_instr;
+            next_instr += 1;
+            INSTRUCTION_STATS(OP);
+            #ifdef Py_GIL_DISABLED
+            _PyFrame_SetStackPointer(frame, stack_pointer);
+            escaping_call();
+            stack_pointer = _PyFrame_GetStackPointer(frame);
+            #else
+            _PyFrame_SetStackPointer(frame, stack_pointer);
+            another_escaping_call();
+            stack_pointer = _PyFrame_GetStackPointer(frame);
+            #endif
+            _PyFrame_SetStackPointer(frame, stack_pointer);
+            yet_another_escaping_call();
+            stack_pointer = _PyFrame_GetStackPointer(frame);
+            DISPATCH();
+        }
+        """
+        self.run_cases_test(input, output)
+
 
 class TestGeneratedAbstractCases(unittest.TestCase):
     def setUp(self) -> None:
index 66ead741b87a2bbf6284d33d196b2d368eacf40d..a725ec10d4e52ad2e53cca0e723dad0962f5d24d 100644 (file)
@@ -637,7 +637,7 @@ def find_stmt_start(node: parser.InstDef, idx: int) -> lexer.Token:
     assert idx < len(node.block.tokens)
     while True:
         tkn = node.block.tokens[idx-1]
-        if tkn.kind in {"SEMI", "LBRACE", "RBRACE"}:
+        if tkn.kind in {"SEMI", "LBRACE", "RBRACE", "CMACRO"}:
             break
         idx -= 1
         assert idx > 0