summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2025-01-04 10:46:04 (GMT)
committerGitHub <noreply@github.com>2025-01-04 10:46:04 (GMT)
commita4e773c540cfd3a9c2bb3b5033d2f79ef50962c8 (patch)
tree3b54e1c9369a7d25e190fe06eb194e77b7958707
parent03ede5afe2d10c04e05f159fd353ee5869ae2cdb (diff)
downloadcpython-a4e773c540cfd3a9c2bb3b5033d2f79ef50962c8.zip
cpython-a4e773c540cfd3a9c2bb3b5033d2f79ef50962c8.tar.gz
cpython-a4e773c540cfd3a9c2bb3b5033d2f79ef50962c8.tar.bz2
gh-128152: Argument Clinic: ignore pre-processor directives inside C comments (#128464)
-rw-r--r--Lib/test/test_clinic.py10
-rw-r--r--Misc/NEWS.d/next/Tools-Demos/2025-01-03-23-51-07.gh-issue-128152.IhzElS.rst2
-rw-r--r--Tools/clinic/libclinic/cpp.py3
3 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py
index 1105496..b45b9ee 100644
--- a/Lib/test/test_clinic.py
+++ b/Lib/test/test_clinic.py
@@ -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
index 0000000..9657e13
--- /dev/null
+++ b/Misc/NEWS.d/next/Tools-Demos/2025-01-03-23-51-07.gh-issue-128152.IhzElS.rst
@@ -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.
diff --git a/Tools/clinic/libclinic/cpp.py b/Tools/clinic/libclinic/cpp.py
index e115d65..3cfe99b 100644
--- a/Tools/clinic/libclinic/cpp.py
+++ b/Tools/clinic/libclinic/cpp.py
@@ -132,6 +132,9 @@ class Monitor:
if line_comment:
line = before.rstrip()
+ if self.in_comment:
+ return
+
if not line.startswith('#'):
return