]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-138143: Allow anonymous unions in public headers, using `_Py_ANONYMOUS` (GH-137283)
authorPetr Viktorin <encukou@gmail.com>
Tue, 26 Aug 2025 09:14:35 +0000 (11:14 +0200)
committerGitHub <noreply@github.com>
Tue, 26 Aug 2025 09:14:35 +0000 (11:14 +0200)
commitce1a877a3882acf50f1162e4a823ce0abf2d8525
tree58bc8e8d0cb048d5cde15664b8cf81a4ea5a7080
parent73fb155ba7920268238d01047555e1b9ad77b35b
gh-138143: Allow anonymous unions in public headers, using `_Py_ANONYMOUS` (GH-137283)

We already use an anonymous union for PyObject. This makes the workarounds available in all public headers:

- MSVC: `__pragma(warning(disable: 4201))` (with push/pop). Warning 4201 is specifically for anonymous unions, so let's disable for all of `<Python.h>`
- GCC/clang, pedantic old C standards: define `_Py_ANONYMOUS` as `__extension__`
- otherwise, define `_Py_ANONYMOUS` as nothing

(Note that this is only for public headers -- CPython internals use C11, which has anonymous structs/unions.)

C API WG vote: https://github.com/capi-workgroup/decisions/issues/74
Include/Python.h
Include/object.h
Include/pymacro.h