-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Includes/internal/pycore_code.h
uses static_assert()
but does not inlcude pymacro.h
#123747
Comments
In general, I would suggest to only include |
Sure, the compilation error is unrelated (Cython requires only C99 which does not have |
Do you get the error if you include |
Yes. But the error is unrelated to what I am trying to say. |
They are not independent. <Python.h> must always be included first. |
Thanks. There is nothing wrong then. |
It turns out that this is an issue, even after Since Cython code is not commonly compiled with C11 (we currently require C99), there are platforms where the resulting code does not compile |
Since it is really just an assertion that gets in the way here, I propose to comment it out for the final release. |
I don't understand how to reproduce the issue. Can somone provide a reproducer? Does the issue only affect macOS? With which C compiler and which compiler options? |
FTR, here's the comment concerning // gh-91782: On FreeBSD 12, if the _POSIX_C_SOURCE and _XOPEN_SOURCE macros are
// defined, <sys/cdefs.h> disables C11 support and <assert.h> does not define
// the static_assert() macro.
// https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255290
//
// macOS <= 10.10 doesn't define static_assert in assert.h at all despite
// having C11 compiler support.
//
// static_assert is defined in glibc from version 2.16. Compiler support for
// the C11 _Static_assert keyword is in gcc >= 4.6.
//
// MSVC makes static_assert a keyword in C11-17, contrary to the standards.
//
// In C++11 and C2x, static_assert is a keyword, redefining is undefined
// behaviour. So only define if building as C, not C++ (if __cplusplus is
// not defined), and only for C11-17. |
I can reproduce the issue compiling the most simple Cython extension module: def foo():
return 42 with Cython 3.0.11 with clang from Xtools: $ cc --version
Apple clang version 14.0.0 (clang-1400.0.29.202) using an explicit A more synthetic reproducer is trying to compile something like: #include "Python.h"
#include "internal/pycore_frame.h"
int main() { } In this way: $ cc foo.c -o foo.o -DPy_BUILD_CORE=1 $(python3.13-config --cflags) -std=c99 Omitting the As pointed out before, the issue is that For some reason that I have not investigated, |
I cannot reproduce the issue on Linux (Fedora 40) with clang 18.1.6. See also discussion capi-workgroup/decisions#30 |
I wrote PR gh-123779 to avoid static_assert() in the internal header files. |
Could Cython re- |
…on#123779) (cherry picked from commit ef4b69d)
Fixed by ef4b69d. |
Thanks for your bug report @dnicolodi! |
Thanks @vstinner |
Bug report
Bug description:
Includes/internal/pycore_code.h
usesstatic_assert()
but does not inlcudepymacro.h
, should it?AFAIU
pymacro.h
makes sure thatstatic_assert()
is correctly defined for all supported compilers and platforms. Not including it inIncludes/internal/pycore_code.h
implicitly relies onpymacro.h
being included before or via transitive includes.I've found this while investigating a Cython extension module build failure. Cython includes the private header and thus requires
static_macro()
to be defined.CPython versions tested on:
3.13, CPython main branch
Operating systems tested on:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: