New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build Python with C11 #91731
Comments
Python is now built with "-std=c11" compiler option, rather than "-std=c99".
+1 |
Python is now built with "-std=c11" compiler option, rather than "-std=c99".
Python is now built with "-std=c11" compiler option, rather than "-std=c99".
Python 3.11 now uses C11 standard which adds static_assert() to <assert.h>. * In pytime.c, replace Py_BUILD_ASSERT() with preprocessor checks on SIZEOF_TIME_T with #error. * On macOS, py_mach_timebase_info() now accepts timebase members with the same size than _PyTime_t. * py_get_monotonic_clock() now saturates GetTickCount64() to _PyTime_MAX: GetTickCount64() is unsigned, whereas _PyTime_t is signed.
Python 3.11 now uses C11 standard which adds static_assert() to <assert.h>. * In pytime.c, replace Py_BUILD_ASSERT() with preprocessor checks on SIZEOF_TIME_T with #error. * On macOS, py_mach_timebase_info() now accepts timebase members with the same size than _PyTime_t. * py_get_monotonic_clock() now saturates GetTickCount64() to _PyTime_MAX: GetTickCount64() is unsigned, whereas _PyTime_t is signed.
What about Windows? @zooba are we already building with C11 there? |
Apparently, or CI would have broken. I guess we'll find out when people start using new language features. |
When the PEP 7 change was discussed on python-dev, it was said that MSVC supports C11 without optional features.
My PR got merged and the CI is fine. Do you have remaining concerns about MSVC? The blog post mentions the I only these /std options:
The blog post also mentions the |
My remaining concern is that I tried to use static_assert() in #32387 and it broke on Windows. I've merged the latest main and it still breaks. I'll just assume that that is a different problem so I'll move on. (If you want to look into it, details are in that issue.) |
Yeah, this probably needs to be added (in pyproject.props). I don't think it will matter if it's included twice in the C++ projects, but that would be the biggest issue. |
I reopen the issue. |
It looks like AMD64 FreeBSD Non-Debug 3.x is now failing like this:
|
Is |
Right, I just noticed that: I created #91782 to track this issue. Sadly, this specific FreeBSD buildbot worker failed on the Git step but the CI job was marked as successful on my PR :-( |
|
If you consider that it's worth it, please open a separated issue. I already got enough issues with static_assert(), so I prefer to restrict this issue to that :-) |
Seems that Python 3.11.0 beta 1 doesn't build with gcc 8 in RHEL 6:
|
I'm marking this as release blocker as there may be multiple systems affected |
Seems that the C11 symbol is https://gcc.gnu.org/wiki/C11Status
|
For instance, in RHEL 6 |
Opened #92559 |
Seems that |
|
That's only on glibc 2.16 or newer. GCC itself only provides _Static_assert |
Agreed that the C11 requirement apparently mandates glibc >= 2.16. But |
There is the theory, and the practice. Did you see the FreeBSD issue about the practice? :-) #91782 |
…cs (pythonGH-92559) (cherry picked from commit f0614ca) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
macOS 10.10 and older also don't have static_assert defined even when using a C11 compiler. |
What is your C compiler? What is your error message? Can you try to add this code at the top of pymacro.h? Does it fix your build issue?
|
* Fix typo in pymacro.h * Update Include/pymacro.h Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Victor Stinner <vstinner@python.org>
* Fix typo in pymacro.h * Update Include/pymacro.h Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Victor Stinner <vstinner@python.org> (cherry picked from commit 4e6da50) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* Fix typo in pymacro.h * Update Include/pymacro.h Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Victor Stinner <vstinner@python.org> (cherry picked from commit 4e6da50) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Apple clang-700.1.81 and clang 11 from llvm.org both produce the same error:
Yes, that does fix the build. (Technically I just deleted |
We probably need to add another case. I will prepare a PR. Alternatively, given that this is a macro, we can check if is defined and redefine it ourselves. |
Oh, clang 11 didn't support calling static_assert() in the function scope. It was fixed at 2021-01-29 (only in clang 12): https://bugs.llvm.org/show_bug.cgi?id=48904 |
PEP 7 was recently updated to require a C11 compiler (without optional features) to build Python. I propose to now implement this new requirement:
It's already documented in What's New in Python 3.11:
https://docs.python.org/dev/whatsnew/3.11.html#build-changes
The text was updated successfully, but these errors were encountered: