Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Parse also pyconfig.h.in
  • Loading branch information
vstinner committed Sep 18, 2026
commit c6af62b70df1c48673c400122880ea681ae33a5c
23 changes: 23 additions & 0 deletions Tools/build/check_capi_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Check that all macros defined by the Python C API have a name starting with
"Py". Ignore names listed by check_capi_macros_ignored.txt: macros with an
invalid name, added before this script was created.

Python C API:

* Include/*.h
* Include/cpython/*.h
* pyconfig.h.in
"""

import glob
Expand All @@ -15,6 +21,7 @@
DEFINE_REGEX = re.compile(r'^\s*# *define\s+(.*)')
PYTHON_PREFIX = re.compile(r'^(Py|PY|_Py|_PY)')
DEFINE_NAME_REGEX = re.compile(r'^([A-Za-z_][A-Za-z0-9_]*)\b')
UNDEF_REGEX = re.compile(r'#undef (.*)$')
Comment thread
vstinner marked this conversation as resolved.
Outdated


def parse_file(filename, names, ignored):
Expand All @@ -39,6 +46,18 @@ def parse_file(filename, names, ignored):
names.append((name, filename))


def parse_pyconfig_in(filename, names, ignored):
with open(filename, encoding='utf8') as fp:
for line in fp:
match = UNDEF_REGEX.match(line)
if not match:
continue
name = match.group(1)
if name in ignored:
continue
names.append((name, filename))


def get_ignored_names():
filename = os.path.join(TOOLS_BUILD_DIR, 'check_capi_macros_ignored.txt')
ignored = set()
Expand All @@ -62,6 +81,10 @@ def main():
names = []
for filename in files:
parse_file(filename, names, ignored)

filename = os.path.join(SRC_DIR, 'pyconfig.h.in')
parse_file(filename, names, ignored)
parse_pyconfig_in(filename, names, ignored)
names.sort()

if not names:
Expand Down
Loading
Loading