-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Forward declare timespec struct #22621
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
Conversation
The Python headers use this as, e.g.: PyAPI_FUNC(int) _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts); When GCC sees this, it complains that the definition of `timespec` will not be visible outside of the function declaration. However, `timespec` is defined in `time.h`. Forward definition is the fix pipewire applied (https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/230).
|
Seems a bit weird that this is necessary, found this (closed) Python issue python/cpython#70040. But if that is needed for the warning 🤷 (maybe a comment that it is just to silence a warning on some setups?)... |
|
On which platforms/compilations are you seeing the warning? |
|
This is on Linux (Fedora) compiling the meson branch. |
|
That function is defined in Perhaps in Fedora the upstream code is modified? |
|
Looking at the Fedora sources for Python 3.10, I see the same. Here is the section of #ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else /* !TIME_WITH_SYS_TIME */
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else /* !HAVE_SYS_TIME_H */
#include <time.h>
#endif /* !HAVE_SYS_TIME_H */
#endif /* !TIME_WITH_SYS_TIME */However, I can't find a good reference on when |
|
|
|
Here is the current HEAD CPython version of the code you pointed to: This was simplified from the code you pointed to in CPython PR python/cpython#29441 without a comment, seemingly to adapt to a change in autoconf. Edit: the change was applied to CPython3.11+ but was not backported. |
|
This also appears on CI with Python 3.11. |
|
OK, I think I figured it out. #if defined __USE_POSIX199309 || defined __USE_ISOC11
# include <bits/types/struct_timespec.h>
#endifThe following patches would make the warning go away, but I'm not sure if we're willing to jump to C11: diff --git a/meson.build b/meson.build
index 775d59688..3784fe7b0 100644
--- a/meson.build
+++ b/meson.build
@@ -9,7 +9,7 @@ project(
meson_version: '>= 0.64.0',
default_options: [
'buildtype=debugoptimized',
- 'c_std=c99',
+ 'c_std=c11',
'cpp_std=c++11',
'blas=openblas',
'lapack=openblas',Alternatively, setting # define _XOPEN_SOURCE 700
# define _POSIX_C_SOURCE 200809L
#if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199309L
# define __USE_POSIX199309 1
#endifWhile investigating, I came upon this S/O answer that explains it all nicely. |
|
Thanks @stefanv! Defining Jumping to C11 should be relatively safe by now, but it's hard to be sure on niche platforms. This would be less of a problem if we left |
|
Nice digging. I wonder why setup.py doesn't run into this. Is it because setup.py and meson use different |
It's because there |
|
Do you understand why |
|
Yes, it asks for strict C99 mode, not C99 + POSIX or "whatever the compiler can do". |
|
For future reference, looks like all this magic happens inside of Here is the diff between preprocessing directives with and without -#define linux 1
-#define unix 1
-#define __STDC_VERSION__ 201710L
+#define __STDC_VERSION__ 201112L
+#define __STRICT_ANSI__ 1It's the I can confirm that setting @rgommers I've pushed a commit to your branch; not sure if a global flag is the right solution or not, so feel free to drop/replace the patch. |
I had a look, this silences the warning but isn't quite the right thing to do. The problem was that some files included standard library headers before they included I'll also note that you always want to use I suggest we close this PR. |
|
Closed by 82fd2b8 For completeness, note that compilation now defaults to c99 and c++14. |
The Python headers use this as, e.g.:
When GCC sees this, it complains that the definition of
timespecwill not be visible outside of the function declaration. However,timespecis defined intime.h.Forward definition is the fix pipewire applied
(https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/230).
Perhaps there is a better way?