Skip to content

clang-format: Use MacroBlock for Py_*_ALLOW_THREADS formatting#2733

Open
Avasam wants to merge 2 commits intomhammond:mainfrom
Avasam:clang-format-MacroBlock
Open

clang-format: Use MacroBlock for Py_*_ALLOW_THREADS formatting#2733
Avasam wants to merge 2 commits intomhammond:mainfrom
Avasam:clang-format-MacroBlock

Conversation

@Avasam
Copy link
Copy Markdown
Collaborator

@Avasam Avasam commented Apr 20, 2026

Do not squash merge, to preserve the commit hash in .git-blame-ignore-revs

The first commit is applied formatting using the second commit's configs, and is 100% automated by just running clang-format.

Alternatively there's also Macros https://clang.llvm.org/docs/ClangFormatStyleOptions.html#macros which gets clang-format to try and expand specific macros, but that makes the formatter non-portable (I ran this PR on my Linux machine, and Macros makes clang-format crash because I don't have llvm-symbolizer on my PATH)


I prefer doing this over adding ; everywhere because then clang-format will also correctly increase indentation inside the macro block. Adding visual clarity that it is, indeed, a block.

Py_*_ALLOW_THREADS is standard to Python, so I don't feel like this is "special-casing" the formatter configs to pywin32.

PY_INTERFACE_PRECALL/PY_INTERFACE_POSTCALL, GUI_BGN_SAVE/GUI_END_SAVE and PyW32_BEGIN_ALLOW_THREADS/PyW32_END_ALLOW_THREADS (which are all the same thing), differ in that they're not block-scoped.

@Avasam Avasam changed the title clang-format: Use MacroBlock for Py_*_ALLOW_THREADS formattin clang-format: Use MacroBlock for Py_*_ALLOW_THREADS formatting Apr 20, 2026
@Avasam Avasam mentioned this pull request May 3, 2026
@Avasam Avasam force-pushed the clang-format-MacroBlock branch from e3de5d5 to c8f58b2 Compare May 4, 2026 18:02
@Avasam Avasam changed the title clang-format: Use MacroBlock for Py_*_ALLOW_THREADS formatting clang-format: Use MacroBlock for Py_*_ALLOW_THREADS formatting May 4, 2026
@mhammond
Copy link
Copy Markdown
Owner

mhammond commented May 5, 2026

If we are touching (almost) every Py_*_ALLOW_THREADS use, wouldn't it be better to add a trailing ; and not indent the code in between?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants