Uh oh!
There was an error while loading. Please reload this page.
gh-99069: Consolidate checks for static_assert - #94766
Conversation
Uh oh!
There was an error while loading. Please reload this page.
jmroot
commented
Nov 7, 2022
@vstinner Is there something that is defined iff Python itself is being built? Other users of the headers don't necessarily need |
vstinner
commented
Nov 7, 2022
Sadly, static_assert() is now part of the Python 3.11 C API. Removing it from its public C API in a 3.11.x bugfix release would be worse IMO. |
vstinner
commented
Nov 7, 2022
In practice, which platform/libc/compiler is impacted by this change? It would be nice to add a NEWS entry to discuss which platforms are affected. |
vstinner
commented
Nov 7, 2022
cc @pablogsal who modified this macro recently. cc @ambv who may have an opinion on the macOS 10.10 support (issue #99069), purpose of this PR if I got it correctly |
Uh oh!
There was an error while loading. Please reload this page.
jmroot
commented
Nov 7, 2022
I only know of the ones mentioned in the comment, i.e. FreeBSD <= 12, macOS <= 10.10, and glibc < 2.16. |
vstinner
commented
Nov 7, 2022
I was very excited to be able to get rid of Maybe we should give up with Maybe Py_BUILD_ASSERT() is just better since it's battle tested (in Python) and it "just works" :-) I didn't expect that it would be so complicated to get static_assert() on all compilers on all platforms in 2022 :-( A tradeoff might be to only use static_assert() inside Python and remove it from the public Python C API. Then the funny part is that depending if the proper (hypothetical) Python internal header file is included or not, using static_assert() might work or not. The problem is that some Python macros use assert(), so Python.h includes "Well defined": people are now discussing static_assert() with a single argument. I'm curious when it will be standard and when all compilers on all platforms will support it :-) |
jmroot
commented
Nov 20, 2022
@vstinner@pablogsal Is there a consensus for how you want to proceed here? |
vstinner
commented
Nov 21, 2022
@pablogsal asked to add |
jmroot
commented
Nov 21, 2022
@vstinner Sorry if I misinterpreted your comments above; it looked to me like you were disagreeing with @pablogsal's proposal. My own view is that a clang-specific check is not necessary, because the existence of |
Several platforms don't define the static_assert macro despite having compiler support for the _Static_assert keyword. The macro needs to be defined since it is used unconditionally in the Python code. So it should always be safe to define it if undefined and not in C++11 (or later) mode. Hence, remove the checks for particular platforms or libc versions, and just define static_assert anytime it needs to be defined but isn't. That way, all platforms that need the fix will get it, regardless of whether someone specifically thought of them. Also document that certain macOS versions are among the platforms that need this.
jmroot
commented
Nov 29, 2022
@pablogsal Is this acceptable now? |
pablogsal
commented
Nov 29, 2022
Yup, this looks good to me. Thanks for working on this! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
left a comment
There was a problem hiding this comment.
For me, it's strange to check for GNUC with clang. The first code was added for FreeBSD which uses clang.
Uh oh!
There was an error while loading. Please reload this page.
jmroot
commented
Jan 1, 2023
@vstinner What is still needed for this to be ready to merge? |
The C2x draft (currently expected to become C23) makes static_assert a keyword to match C++. So only define the macro for up to C17.
miss-islington
commented
Apr 5, 2023
Several platforms don't define the static_assert macro despite having compiler support for the _Static_assert keyword. The macro needs to be defined since it is used unconditionally in the Python code. So it should always be safe to define it if undefined and not in C++11 (or later) mode. Hence, remove the checks for particular platforms or libc versions, and just define static_assert anytime it needs to be defined but isn't. That way, all platforms that need the fix will get it, regardless of whether someone specifically thought of them. Also document that certain macOS versions are among the platforms that need this. The C2x draft (currently expected to become C23) makes static_assert a keyword to match C++. So only define the macro for up to C17. (cherry picked from commit 96e1901) Co-authored-by: Joshua Root <jmr@macports.org> Co-authored-by: Victor Stinner <vstinner@python.org>
bedevere-bot
commented
Apr 5, 2023
GH-103282 is a backport of this pull request to the 3.11 branch. |
vstinner
commented
Apr 5, 2023
Merged, thanks. |
Several platforms don't define the static_assert macro despite having compiler support for the _Static_assert keyword. The macro needs to be defined since it is used unconditionally in the Python code. So it should always be safe to define it if undefined and not in C++11 (or later) mode. Hence, remove the checks for particular platforms or libc versions, and just define static_assert anytime it needs to be defined but isn't. That way, all platforms that need the fix will get it, regardless of whether someone specifically thought of them. Also document that certain macOS versions are among the platforms that need this. The C2x draft (currently expected to become C23) makes static_assert a keyword to match C++. So only define the macro for up to C17. (cherry picked from commit 96e1901) Co-authored-by: Joshua Root <jmr@macports.org> Co-authored-by: Victor Stinner <vstinner@python.org>
Several platforms don't define the static_assert macro despite having compiler support for the _Static_assert keyword. The macro needs to be defined since it is used unconditionally in the Python code. So it should always be safe to define it if undefined and not in C++11 (or later) mode. Hence, remove the checks for particular platforms or libc versions, and just define static_assert anytime it needs to be defined but isn't. That way, all platforms that need the fix will get it, regardless of whether someone specifically thought of them. Also document that certain macOS versions are among the platforms that need this. The C2x draft (currently expected to become C23) makes static_assert a keyword to match C++. So only define the macro for up to C17. Co-authored-by: Victor Stinner <vstinner@python.org>
Several platforms don't define the static_assert macro despite having compiler support for the _Static_assert keyword. The macro needs to be defined since it is used unconditionally in the Python code. So it should always be safe to define it if undefined and not in C++11 (or later) mode. Hence, remove the checks for particular platforms or libc versions, and just define static_assert anytime it needs to be defined but isn't. That way, all platforms that need the fix will get it, regardless of whether someone specifically thought of them. Also document that certain macOS versions are among the platforms that need this. The C2x draft (currently expected to become C23) makes static_assert a keyword to match C++. So only define the macro for up to C17. Co-authored-by: Victor Stinner <vstinner@python.org>
Several platforms don't define the static_assert macro despite having
compiler support for the _Static_assert keyword. The macro needs to be
defined since it is used unconditionally in the Python code. So it
should always be safe to define it if undefined and not in C++11 (or
later) mode.
Hence, remove the checks for particular platforms or libc versions,
and just define static_assert anytime it needs to be defined but isn't.
That way, all platforms that need the fix will get it, regardless of
whether someone specifically thought of them.
Also document that certain macOS versions are among the platforms that
need this.