https://github.com/python/cpython/commit/883cb23dd14bcc60921a53cc51c30fda223b9ca6 commit: 883cb23dd14bcc60921a53cc51c30fda223b9ca6 branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: erlend-aasland <[email protected]> date: 2025-01-04T11:09:25Z summary:
[3.13] gh-128152: Argument Clinic: ignore pre-processor directives inside C comments (GH-128464) (#128478) (cherry picked from commit a4e773c540cfd3a9c2bb3b5033d2f79ef50962c8) Co-authored-by: Erlend E. Aasland <[email protected]> files: A Misc/NEWS.d/next/Tools-Demos/2025-01-03-23-51-07.gh-issue-128152.IhzElS.rst M Lib/test/test_clinic.py M Tools/clinic/libclinic/cpp.py diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index a7ba7f3d99860e..e210103a80f399 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -731,6 +731,16 @@ def test_cloned_forced_text_signature_illegal(self): 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 00000000000000..9657e138e9911b --- /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 e115d65a88e1b6..3cfe99b712641d 100644 --- a/Tools/clinic/libclinic/cpp.py +++ b/Tools/clinic/libclinic/cpp.py @@ -132,6 +132,9 @@ def pop_stack() -> TokenAndCondition: if line_comment: line = before.rstrip() + if self.in_comment: + return + if not line.startswith('#'): return _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
