Skip to content

Commit 883cb23

Browse files
[3.13] gh-128152: Argument Clinic: ignore pre-processor directives inside C comments (GH-128464) (#128478)
(cherry picked from commit a4e773c) Co-authored-by: Erlend E. Aasland <erlend@python.org>
1 parent 855af3b commit 883cb23

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Lib/test/test_clinic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,16 @@ def test_cloned_forced_text_signature_illegal(self):
731731
err = "Cannot use @text_signature when cloning a function"
732732
self.expect_failure(block, err, lineno=11)
733733

734+
def test_ignore_preprocessor_in_comments(self):
735+
for dsl in "clinic", "python":
736+
raw = dedent(f"""\
737+
/*[{dsl} input]
738+
# CPP directives, valid or not, should be ignored in C comments.
739+
#
740+
[{dsl} start generated code]*/
741+
""")
742+
self.clinic.parse(raw)
743+
734744

735745
class ParseFileUnitTest(TestCase):
736746
def expect_parsing_failure(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug where Argument Clinic's C pre-processor parser tried to parse
2+
pre-processor directives inside C comments. Patch by Erlend Aasland.

Tools/clinic/libclinic/cpp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ def pop_stack() -> TokenAndCondition:
132132
if line_comment:
133133
line = before.rstrip()
134134

135+
if self.in_comment:
136+
return
137+
135138
if not line.startswith('#'):
136139
return
137140

0 commit comments

Comments
 (0)