Skip to main content

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

LinesSymbolRole
1-50Version string macrosPY_MAJOR_VERSION, PY_MINOR_VERSION, PY_MICRO_VERSION, PY_VERSION
51-200SIZEOF_*Size of C types on the build platform
201-350HAVE_*Feature detection: HAVE_FORK, HAVE_GETADDRINFO, HAVE_OPENSSL, etc.
351-450WITH_*Feature flags: WITH_THREAD, WITH_DOC_STRINGS
451-500Unicode: Py_UNICODE_SIZE, WORDS_BIGENDIANUnicode storage width and endianness
501-600Py_LIMITED_API, Py_GIL_DISABLEDStable 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:

MacroMeaning
HAVE_FORKfork(2) is available
HAVE_PTHREAD_HPOSIX threads available
HAVE_OPENSSLOpenSSL is linked
HAVE_GETTIMEOFDAYgettimeofday(2) available
HAVE_MREMAPLinux mremap(2) available
HAVE_CLOCK_GETTIMEPOSIX 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".