mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
[3.13] gh-128152: Argument Clinic: ignore pre-processor directives inside C comments (GH-128464) (#128478)
(cherry picked from commit a4e773c540
)
Co-authored-by: Erlend E. Aasland <erlend@python.org>
This commit is contained in:
parent
855af3bbc6
commit
883cb23dd1
3 changed files with 15 additions and 0 deletions
|
@ -731,6 +731,16 @@ class ClinicWholeFileTest(TestCase):
|
||||||
err = "Cannot use @text_signature when cloning a function"
|
err = "Cannot use @text_signature when cloning a function"
|
||||||
self.expect_failure(block, err, lineno=11)
|
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):
|
class ParseFileUnitTest(TestCase):
|
||||||
def expect_parsing_failure(
|
def expect_parsing_failure(
|
||||||
|
|
|
@ -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.
|
|
@ -132,6 +132,9 @@ class Monitor:
|
||||||
if line_comment:
|
if line_comment:
|
||||||
line = before.rstrip()
|
line = before.rstrip()
|
||||||
|
|
||||||
|
if self.in_comment:
|
||||||
|
return
|
||||||
|
|
||||||
if not line.startswith('#'):
|
if not line.startswith('#'):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue