Make some number configure macros public in non-limited capi

Some non-standard macros in pyconfig.h (like SIZEOF_VOID_P or LONG_BIT) are useful (for example, numpy use them). This idea is to make them public:

In pyconfig.h.in, change it to _Py_*
In Python.h add the code like it to avoid the breaking-forward for normal build:

#ifndef Py_LIMITED_API
#ifdef _Py_SIZEOF_VOID_P
#define Py_SIZEOF_VOID_P _Py_SIZEOF_VOID_P
#endif

// and any other number macros
#endif
1 Like

I don’t understand your request. SIZEOF_VOID_P is currently exposed by <Python.h>:

$ cat x.c
#include <Python.h>

int main()
{
    return SIZEOF_VOID_P;
}

$ gcc x.c -o x $(pkg-config python-3.14 --cflags) && ./x; echo $?
8

I don’t understand your example: #define Py_SIZEOF_VOID_P _Py_SIZEOF_VOID_P defines a macro to.. itself? The new name is also private?

I don’t think that it’s a good idea that developers rely on macros generated by Python configure script. These macros may disappear later if Python configure script evolves.

I don’t like the idea of making these macros more visible. I would prefer to discourage their usage. I implemented a check for that in Python 3.16: https://github.com/python/cpython/issues/157695 makes sure that new macros have a name starting with Py (or _Py for private macros): don’t add more HAVE_xxx or SIZEOF_xxx macros. For example, Python 3.16 adds a private _Py_HAVE_ACOSPI macro (name starts with _Py): macro checking if acospi() function is available.

The new name Py_SIZEOF_VOID_P is public (won’t be exposed in limited capi). The _Py_SIZEOF_VOID_P is private (changed from SIZEOF_VOID_P).

A tricky question is why many extensions use them. Perhaps this is to coordinate with specific interpreters.