Include/pyconfig.h
Source:
cpython 3.14 @ ab2d84fe1023/Include/pyconfig.h
pyconfig.h is generated by configure (on POSIX) or PC/pyconfig.h (on Windows). It encodes platform-specific constants that all of CPython's C code relies on. Every C file includes Python.h, which includes pyconfig.h as its first dependency.
Map
| Lines | Symbol | Role |
|---|---|---|
| 1-50 | Version string macros | PY_MAJOR_VERSION, PY_MINOR_VERSION, PY_MICRO_VERSION, PY_VERSION |
| 51-200 | SIZEOF_* | Size of C types on the build platform |
| 201-350 | HAVE_* | Feature detection: HAVE_FORK, HAVE_GETADDRINFO, HAVE_OPENSSL, etc. |
| 351-450 | WITH_* | Feature flags: WITH_THREAD, WITH_DOC_STRINGS |
| 451-500 | Unicode: Py_UNICODE_SIZE, WORDS_BIGENDIAN | Unicode storage width and endianness |
| 501-600 | Py_LIMITED_API, Py_GIL_DISABLED | Stable ABI and free-threaded build flags |
Reading
Version macros
// CPython: Include/patchlevel.h (included via pyconfig.h)
#define PY_MAJOR_VERSION 3
#define PY_MINOR_VERSION 14
#define PY_MICRO_VERSION 0
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA
#define PY_VERSION "3.14.0a7"
These macros are used by C extension modules to conditionally compile for specific Python versions.
SIZEOF_* constants
// CPython: Include/pyconfig.h (generated)
#define SIZEOF_INT 4
#define SIZEOF_LONG 8 /* on 64-bit Linux */
#define SIZEOF_LONG_LONG 8
#define SIZEOF_VOID_P 8 /* pointer size */
#define SIZEOF_SIZE_T 8
#define SIZEOF_PY_HASH_T 8
Py_ssize_t is defined as ssize_t when SIZEOF_SIZE_T == SIZEOF_VOID_P, otherwise as long.
HAVE_* feature flags
Selected examples:
| Macro | Meaning |
|---|---|
HAVE_FORK | fork(2) is available |
HAVE_PTHREAD_H | POSIX threads available |
HAVE_OPENSSL | OpenSSL is linked |
HAVE_GETTIMEOFDAY | gettimeofday(2) available |
HAVE_MREMAP | Linux mremap(2) available |
HAVE_CLOCK_GETTIME | POSIX high-res clock |
Py_GIL_DISABLED
Defined in the free-threaded build (PEP 703). When set, the GIL is absent and the ref counting is replaced by biased reference counting with thread-local caches.
gopy notes
pyconfig.h has no direct gopy equivalent since Go's runtime package handles platform detection. The gopy analogue of SIZEOF_VOID_P is unsafe.Sizeof(uintptr(0)). HAVE_FORK maps to a build tag. PY_VERSION is set to the CPython version gopy is compatible with, currently "3.14".