-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
Here is a script to find the non-standard macros condition requirement compile in Include:
import os
import subprocess
import re
repo_root = subprocess.check_output(
["git", "rev-parse", "--show-toplevel"],
text=True
).strip()
os.chdir(repo_root)
print(f"Switched to repo root: {repo_root}")
grep_cmd = [
"git", "grep", "-nE", r"^[[:space:]]*#ifn?def[[:space:]]+[A-Za-z_][A-Za-z0-9_]*",
"--", "Include/"
]
result = subprocess.run(grep_cmd, capture_output=True, text=True)
lines = result.stdout.splitlines()
pattern = re.compile(r"#ifn?def\s+([A-Za-z_][A-Za-z0-9_]*)")
filtered = []
for line in lines:
match = pattern.search(line)
if not match:
continue
macro = match.group(1)
if macro.startswith(("Py", "PY", "_Py", "_PY")):
continue
if macro == "__cplusplus":
continue
filtered.append(line)
output_path = os.path.join(repo_root, "non_py_macros.txt")
with open(output_path, "w", encoding="utf-8") as f:
f.write("\n".join(filtered))
print(f"Done. Found {len(filtered)} non-Py macros.")
print(f"Result saved to: {output_path}")Finally I got it :
Detail
Include/Python.h:26:#ifdef HAVE_SYS_TYPES_H
Include/Python.h:63:#ifdef _MSC_VER
Include/Python.h:151:#ifdef _MSC_VER
Include/cpython/initconfig.h:91:#ifdef MS_WINDOWS
Include/cpython/initconfig.h:175:#ifdef MS_WINDOWS
Include/cpython/initconfig.h:184:#ifdef __APPLE__
Include/cpython/object.h:397:#ifdef NDEBUG
Include/cpython/pthread_stubs.h:8:#ifndef _POSIX_THREADS
Include/cpython/pthread_stubs.h:21:#ifdef __wasi__
Include/cpython/pthread_stubs.h:95:#ifndef PTHREAD_KEYS_MAX
Include/cpython/pydebug.h:24:#ifdef MS_WINDOWS
Include/cpython/pyerrors.h:64:#ifdef MS_WINDOWS
Include/cpython/pyerrors.h:88:#ifdef MS_WINDOWS
Include/cpython/pymem.h:22:#ifdef WITH_PYMALLOC
Include/cpython/pymem.h:26:#ifdef WITH_MIMALLOC
Include/cpython/pythread.h:15:#ifdef HAVE_PTHREAD_H
Include/datetime.h:4:#ifndef DATETIME_H
Include/dynamic_annotations.h:56:#ifndef __DYNAMIC_ANNOTATIONS_H__
Include/dynamic_annotations.h:59:#ifndef DYNAMIC_ANNOTATIONS_ENABLED
Include/fileutils.h:8:#ifdef HAVE_SYS_STAT_H
Include/fileutils.h:14:#ifndef S_IFMT
Include/fileutils.h:18:#ifndef S_IFLNK
Include/fileutils.h:23:#ifndef S_ISREG
Include/fileutils.h:26:#ifndef S_ISDIR
Include/fileutils.h:29:#ifndef S_ISCHR
Include/fileutils.h:32:#ifndef S_ISLNK
Include/internal/mimalloc/mimalloc.h:8:#ifndef MIMALLOC_H
Include/internal/mimalloc/mimalloc/atomic.h:8:#ifndef MIMALLOC_ATOMIC_H
Include/internal/mimalloc/mimalloc/atomic.h:139:#ifdef _WIN64
Include/internal/mimalloc/mimalloc/atomic.h:239:#ifdef _WIN64
Include/internal/mimalloc/mimalloc/atomic.h:363:#ifdef __APPLE__
Include/internal/mimalloc/mimalloc/internal.h:8:#ifndef MIMALLOC_INTERNAL_H
Include/internal/mimalloc/mimalloc/internal.h:214:#ifndef __has_builtin
Include/internal/mimalloc/mimalloc/internal.h:226:#ifndef EAGAIN // double free
Include/internal/mimalloc/mimalloc/internal.h:229:#ifndef ENOMEM // out of memory
Include/internal/mimalloc/mimalloc/internal.h:232:#ifndef EFAULT // corrupted free-list or meta-data
Include/internal/mimalloc/mimalloc/internal.h:235:#ifndef EINVAL // trying to free an invalid pointer
Include/internal/mimalloc/mimalloc/internal.h:238:#ifndef EOVERFLOW // count*size overflow
Include/internal/mimalloc/mimalloc/internal.h:636: #ifdef MI_ENCODE_FREELIST
Include/internal/mimalloc/mimalloc/internal.h:648: #ifdef MI_ENCODE_FREELIST
Include/internal/mimalloc/mimalloc/internal.h:658: #ifdef MI_ENCODE_FREELIST
Include/internal/mimalloc/mimalloc/internal.h:674: #ifdef MI_ENCODE_FREELIST
Include/internal/mimalloc/mimalloc/prim.h:8:#ifndef MIMALLOC_PRIM_H
Include/internal/mimalloc/mimalloc/prim.h:134:#ifdef MI_PRIM_THREAD_ID
Include/internal/mimalloc/mimalloc/prim.h:282: #ifdef __GNUC__
Include/internal/mimalloc/mimalloc/track.h:8:#ifndef MIMALLOC_TRACK_H
Include/internal/mimalloc/mimalloc/track.h:108:#ifndef mi_track_resize
Include/internal/mimalloc/mimalloc/track.h:112:#ifndef mi_track_align
Include/internal/mimalloc/mimalloc/track.h:116:#ifndef mi_track_init
Include/internal/mimalloc/mimalloc/track.h:120:#ifndef mi_track_mem_defined
Include/internal/mimalloc/mimalloc/track.h:124:#ifndef mi_track_mem_undefined
Include/internal/mimalloc/mimalloc/track.h:128:#ifndef mi_track_mem_noaccess
Include/internal/mimalloc/mimalloc/types.h:8:#ifndef MIMALLOC_TYPES_H
Include/internal/mimalloc/mimalloc/types.h:26:#ifdef _MSC_VER
Include/internal/mimalloc/mimalloc/types.h:32:#ifndef MI_MAX_ALIGN_SIZE
Include/internal/mimalloc/mimalloc/types.h:634:#ifndef MI_STAT
Include/internal/pycore_bitutils.h:28:#ifdef _MSC_VER
Include/internal/pycore_ceval.h:67:#ifdef HAVE_FORK
Include/internal/pycore_condvar.h:11:#ifdef _POSIX_THREADS
Include/internal/pycore_condvar.h:17:#ifdef HAVE_PTHREAD_H
Include/internal/pycore_condvar.h:34:#ifndef WIN32_LEAN_AND_MEAN
Include/internal/pycore_faulthandler.h:11:#ifdef HAVE_SIGACTION
Include/internal/pycore_faulthandler.h:16:#ifndef MS_WINDOWS
Include/internal/pycore_faulthandler.h:24:#ifdef HAVE_SIGACTION
Include/internal/pycore_faulthandler.h:36:#ifdef FAULTHANDLER_USER
Include/internal/pycore_faulthandler.h:56:#ifdef MS_WINDOWS
Include/internal/pycore_faulthandler.h:79:#ifdef FAULTHANDLER_USER
Include/internal/pycore_faulthandler.h:83:#ifdef FAULTHANDLER_USE_ALT_STACK
Include/internal/pycore_fileutils.h:16:#ifdef _MSC_VER
Include/internal/pycore_fileutils.h:63:#ifdef MS_WINDOWS
Include/internal/pycore_fileutils.h:135:#ifdef HAVE_READLINK
Include/internal/pycore_fileutils.h:144:#ifdef HAVE_REALPATH
Include/internal/pycore_fileutils.h:176:#ifdef MS_WINDOWS
Include/internal/pycore_fileutils.h:240:#ifdef HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION
Include/internal/pycore_fileutils.h:254:#ifdef MS_WINDOWS
Include/internal/pycore_fileutils.h:310:#ifndef MS_WINDOWS
Include/internal/pycore_fileutils_windows.h:11:#ifdef MS_WINDOWS
Include/internal/pycore_gc.h:230:#ifndef NDEBUG
Include/internal/pycore_gc.h:275:#ifndef NDEBUG
Include/internal/pycore_gil.h:55:#ifdef FORCE_SWITCHING
Include/internal/pycore_import.h:35:#ifdef HAVE_DLOPEN
Include/internal/pycore_importdl.h:17:#ifdef HAVE_DYNAMIC_LOADING
Include/internal/pycore_importdl.h:29:#ifdef MS_WINDOWS
Include/internal/pycore_importdl.h:67:#ifndef MS_WINDOWS
Include/internal/pycore_importdl.h:92:#ifdef HAVE_DYNAMIC_LOADING
Include/internal/pycore_importdl.h:128:#ifdef HAVE_DYNAMIC_LOADING
Include/internal/pycore_importdl.h:142:#ifdef MS_WINDOWS
Include/internal/pycore_initconfig.h:16:#ifdef _MSC_VER
Include/internal/pycore_initconfig.h:55:#ifndef NDEBUG
Include/internal/pycore_interp_structs.h:312:#ifdef HAVE_DLOPEN
Include/internal/pycore_interp_structs.h:411:#ifndef PRIVATE_MEM
Include/internal/pycore_interp_structs.h:874:#ifdef HAVE_FORK
Include/internal/pycore_interpframe.h:230:#ifndef NDEBUG
Include/internal/pycore_mimalloc.h:22:#ifdef WITH_MIMALLOC
Include/internal/pycore_object.h:528:#ifdef NDEBUG
Include/internal/pycore_obmalloc.h:175:#ifdef WITH_MEMORY_LIMITS
Include/internal/pycore_obmalloc.h:176:#ifndef SMALL_MEMORY_LIMIT
Include/internal/pycore_obmalloc.h:210:#ifdef USE_LARGE_ARENAS
Include/internal/pycore_obmalloc.h:218:#ifdef WITH_MEMORY_LIMITS
Include/internal/pycore_obmalloc.h:225:#ifdef USE_LARGE_POOLS
Include/internal/pycore_obmalloc.h:579:#ifdef USE_INTERIOR_NODES
Include/internal/pycore_obmalloc.h:632:#ifdef USE_INTERIOR_NODES
Include/internal/pycore_obmalloc.h:647:#ifdef USE_INTERIOR_NODES
Include/internal/pycore_obmalloc.h:693:#ifdef WITH_PYMALLOC
Include/internal/pycore_opcode_metadata.h:36:#ifdef NEED_OPCODE_METADATA
Include/internal/pycore_opcode_metadata.h:519:#ifdef NEED_OPCODE_METADATA
Include/internal/pycore_opcode_metadata.h:1069:#ifdef NEED_OPCODE_METADATA
Include/internal/pycore_opcode_metadata.h:1317:#ifdef NEED_OPCODE_METADATA
Include/internal/pycore_opcode_metadata.h:1506:#ifdef NEED_OPCODE_METADATA
Include/internal/pycore_opcode_metadata.h:1748:#ifdef NEED_OPCODE_METADATA
Include/internal/pycore_opcode_metadata.h:1773:#ifdef NEED_OPCODE_METADATA
Include/internal/pycore_opcode_metadata.h:2073:#ifdef NEED_OPCODE_METADATA
Include/internal/pycore_pyhash.h:74:#ifndef MS_WINDOWS
Include/internal/pycore_pylifecycle.h:21:#ifdef MS_WINDOWS
Include/internal/pycore_pymath.h:86:#ifdef HAVE_GCC_ASM_FOR_X87
Include/internal/pycore_pymath.h:143:#ifdef HAVE_GCC_ASM_FOR_MC68881
Include/internal/pycore_pystate.h:97:#ifndef NDEBUG
Include/internal/pycore_pystate.h:251:#ifdef HAVE_FORK
Include/internal/pycore_pystate.h:296:#ifndef NDEBUG
Include/internal/pycore_pythread.h:62:#ifdef _USE_PTHREADS
Include/internal/pycore_pythread.h:90:#ifdef HAVE_FORK
Include/internal/pycore_runtime.h:24:#ifdef HAVE_FORK
Include/internal/pycore_runtime_structs.h:50:#ifndef MS_WINDOWS
Include/internal/pycore_semaphore.h:12:#ifdef MS_WINDOWS
Include/internal/pycore_signal.h:20:#ifdef _SIG_MAXSIG
Include/internal/pycore_signal.h:47:#ifdef MS_WINDOWS
Include/internal/pycore_signal.h:58:#ifdef MS_WINDOWS
Include/internal/pycore_signal.h:71:#ifdef MS_WINDOWS
Include/internal/pycore_signal.h:82:#ifdef MS_WINDOWS
Include/internal/pycore_signal.h:99:#ifdef MS_WINDOWS
Include/internal/pycore_stackref.h:680:#ifdef _WIN32
Include/internal/pycore_stackref.h:774:#ifdef _WIN32
Include/internal/pycore_stackref.h:808:#ifdef _WIN32
Include/internal/pycore_stackref.h:840:#ifdef _WIN32
Include/internal/pycore_time.h:62:#ifdef __clang__
Include/internal/pycore_time.h:174:#ifdef MS_WINDOWS
Include/internal/pycore_time.h:180:#ifndef MS_WINDOWS
Include/internal/pycore_tracemalloc.h:40:#ifdef __GNUC__
Include/internal/pycore_tracemalloc.h:49:#ifdef _MSC_VER
Include/internal/pycore_uop_metadata.h:21:#ifdef NEED_OPCODE_METADATA
Include/intrcheck.h:9:#ifdef HAVE_FORK
Include/methodobject.h:119:#ifdef STACKLESS
Include/object.h:584:#ifdef STACKLESS
Include/osdefs.h:16:#ifdef MS_WINDOWS
Include/osdefs.h:23:#ifdef __VXWORKS__
Include/osdefs.h:28:#ifndef SEP
Include/osdefs.h:33:#ifdef __hpux
Include/osdefs.h:41:#ifndef MAXPATHLEN
Include/osdefs.h:50:#ifndef DELIM
Include/py_curses.h:5:#ifdef __APPLE__
Include/py_curses.h:10:#ifdef _BSD_WCHAR_T_DEFINED_
Include/py_curses.h:53:#ifdef NCURSES_VERSION
Include/py_curses.h:65:#ifndef MVWDELCH_IS_EXPRESSION
Include/py_curses.h:88:#ifdef CURSES_MODULE
Include/pydtrace.h:9:#ifdef WITH_DTRACE
Include/pyerrors.h:145:#ifdef MS_WINDOWS
Include/pyerrors.h:192:#ifdef MS_WINDOWS
Include/pylifecycle.h:40:#ifdef MS_WINDOWS
Include/pymacconfig.h:8:#ifdef __APPLE__
Include/pymacconfig.h:33:#ifndef __LP64__
Include/pymacconfig.h:38:#ifdef __LP64__
Include/pymacconfig.h:73:#ifdef __BIG_ENDIAN__
Include/pymacro.h:197:#ifdef WITH_DOC_STRINGS
Include/pyport.h:4:#ifndef UCHAR_MAX
Include/pyport.h:16:#ifdef __has_builtin
Include/pyport.h:24:#ifdef __has_attribute
Include/pyport.h:114:#ifndef HAVE_LONG_LONG
Include/pyport.h:153:#ifdef HAVE_PY_SSIZE_T
Include/pyport.h:242:#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
Include/pyport.h:401:#ifndef INT_MAX
Include/pyport.h:405:#ifndef LONG_MAX
Include/pyport.h:415:#ifndef LONG_MIN
Include/pyport.h:419:#ifndef LONG_BIT
Include/pyport.h:458:#ifdef __SUNPRO_C
Include/pyport.h:478:#ifdef WORDS_BIGENDIAN
Include/pyport.h:486:#ifdef __ANDROID__
Include/pyport.h:499:#ifndef WITH_THREAD
Include/pyport.h:511:#ifdef WITH_THREAD
Include/pystrcmp.h:11:#ifdef MS_WINDOWS
Include/pythonrun.h:27:#ifdef USE_STACKCHECK
Include/unicodeobject.h:63:#ifndef SIZEOF_WCHAR_T
Include/unicodeobject.h:86:#ifdef HAVE_USABLE_WCHAR_T
Include/unicodeobject.h:253:#ifdef HAVE_WCHAR_H
Include/unicodeobject.h:613:#ifdef MS_WINDOWS
Some macros are the control of the header file including but dousn't start with "Py" (such as "DATETIME_H"). I think that it need to be renamed.
Some macros which was defined in "pyconfig.h" now have no way to be remaned.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-featureA feature request or enhancementA feature request or enhancement