-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Improve condition for declaring struct timeval
#14540
Conversation
@mjbogusz, thank you for your changes. |
/* Timeval definition for non GCC_ARM toolchains, | ||
* note: _TIMEVAL_DEFINED is set e.g. in arm-none-eabi/include/sys/_timeval.h | ||
*/ | ||
#if !defined(__GNUC__) && !defined(_TIMEVAL_DEFINED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing __clang__
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it was causing the double-defined errors when using clang-tidy.
AFAIK clang is not supported as a compiler for Mbed anyway, so it shouldn't break anything, but this change allows usage of clang-tidy on a compilation database generated for the GCC toolchain.
I've tried to check for defines used in the headers declaring the struct, but there is no consistency between them, so the alternative solution would be to cover all the known define flags and decide whether do define struct timeval
based on that.
The defines I've found so far are:
- The
libc
and derivatives (e.g. Ubuntu/Debian packagelibc6-dev
) provides#define __timeval_defined 1
, e.g. in/usr/include/<architecture_specific>/bits/types/struct_timeval.h
- The
newlib
(e.g. packagelibnewlib-dev
) provides#define _TIMEVAL_DEFINED
, e.g. in/usr/include/newlib/sys/_timeval.h
I don't have ARM'smicrolib
at hand to inspect what defines it does provide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we define our own, and check if not yet defined (_TIMEVAL_DEFINED
), we should define it.
adding on line 39 #define _TIMEVAL_DEFINED
so anyone getting this header, can check if its defined and it is (by us)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we define gnu flag for compatibility for ARMClang, so __GNUC__
is defined. I assume ARMClang do not have defined _TIMEVAL_DEFINED
(seeing similar implementation https://github.com/cesanta/mjs/blob/master/mjs.c#L1054 for mbed).
I'll fetch this to test with ARMClang, I cant quickly find in the online docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the most compatible solution would be to drop the defined(__GNUC__)
check whatsoever and decide only based on the existance of the _TIMEVAL_DEFINED
(and its variants)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so then. I'll check if we use in tests timeval so our CI tests this with both toolchains we support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a version with checking for the defines - let me know if there are any more conditions we should check.
CI started |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Summary of changes
Improve condition for declaring
struct timeval
- do it only if it wasn't declared before.This fixes usage of
clang-tidy
.Without this fix, I'm hitting errors like this when using clang-tidy (paths slightly redacted):
Impact of changes
Migration actions required
Documentation
Pull request type
Test results
Reviewers