]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-128152: Argument Clinic: ignore pre-processor directives inside C comments (#128464)
authorErlend E. Aasland <erlend@python.org>
Sat, 4 Jan 2025 10:46:04 +0000 (11:46 +0100)
committerGitHub <noreply@github.com>
Sat, 4 Jan 2025 10:46:04 +0000 (11:46 +0100)
Lib/test/test_clinic.py
Misc/NEWS.d/next/Tools-Demos/2025-01-03-23-51-07.gh-issue-128152.IhzElS.rst [new file with mode: 0644]
Tools/clinic/libclinic/cpp.py

index 11054963b6ff0371e28f35ee205804db7b43faa4..b45b9ee89ee3de92f09f782e29748dbc2af29e8c 100644 (file)
@@ -740,6 +740,16 @@ class ClinicWholeFileTest(TestCase):
         err = "Cannot use @text_signature when cloning a function"
         self.expect_failure(block, err, lineno=11)
 
+    def test_ignore_preprocessor_in_comments(self):
+        for dsl in "clinic", "python":
+            raw = dedent(f"""\
+                /*[{dsl} input]
+                # CPP directives, valid or not, should be ignored in C comments.
+                #
+                [{dsl} start generated code]*/
+            """)
+            self.clinic.parse(raw)
+
 
 class ParseFileUnitTest(TestCase):
     def expect_parsing_failure(
diff --git a/Misc/NEWS.d/next/Tools-Demos/2025-01-03-23-51-07.gh-issue-128152.IhzElS.rst b/Misc/NEWS.d/next/Tools-Demos/2025-01-03-23-51-07.gh-issue-128152.IhzElS.rst
new file mode 100644 (file)
index 0000000..9657e13
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a bug where Argument Clinic's C pre-processor parser tried to parse
+pre-processor directives inside C comments. Patch by Erlend Aasland.
index e115d65a88e1b6022c05207a45346f096f755b75..3cfe99b712641dfd8adcd2ff6fd9b44995cd84f7 100644 (file)
@@ -132,6 +132,9 @@ class Monitor:
         if line_comment:
             line = before.rstrip()
 
+        if self.in_comment:
+            return
+
         if not line.startswith('#'):
             return