8000 gh-128152: Argument Clinic: ignore pre-processor directives inside C … · python/cpython@a4e773c · GitHub
[go: up one dir, main page]

Skip to content

Commit a4e773c

Browse files
gh-128152: Argument Clinic: ignore pre-processor directives inside C comments (#128464)
1 parent 03ede5a commit a4e773c

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
@@ -740,6 +740,16 @@ def test_cloned_forced_text_signature_illegal(self):
740740
err = "Cannot use @text_signature when cloning a function"
741741
self.expect_failure(block, err, lineno=11)
742742

743+
def test_ignore_preprocessor_in_comments(self):
744+
for dsl in "clinic", "python":
745+
raw = dedent(f"""\
746+
/*[{dsl} input]
747+
# CPP directives, valid or not, should be ignored in C comments.
748+
#
749+
[{dsl} start generated code]*/
750+
""")
751+
self.clinic.parse(raw)
752+
743753

744754
class ParseFileUnitTest(TestCase):
745755
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)
0