mirror of
https://github.com/python/cpython.git
synced 2025-12-03 08:04:34 +00:00
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
This commit is contained in:
parent
73fb155ba7
commit
ce1a877a38
3 changed files with 36 additions and 15 deletions
|
|
@ -60,6 +60,15 @@
|
|||
# endif
|
||||
#endif // Py_GIL_DISABLED
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Ignore MSC warning C4201: "nonstandard extension used: nameless
|
||||
// struct/union". (Only generated for C standard versions less than C11, which
|
||||
// we don't *officially* support.)
|
||||
__pragma(warning(push))
|
||||
__pragma(warning(disable: 4201))
|
||||
#endif
|
||||
|
||||
|
||||
// Include Python header files
|
||||
#include "pyport.h"
|
||||
#include "pymacro.h"
|
||||
|
|
@ -139,4 +148,8 @@
|
|||
#include "cpython/pyfpe.h"
|
||||
#include "cpython/tracemalloc.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
__pragma(warning(pop)) // warning(disable: 4201)
|
||||
#endif
|
||||
|
||||
#endif /* !Py_PYTHON_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue