-
Couldn't load subscription status.
- Fork 8.1k
sys: util: Prevent ARRAY_SIZE being defined if already defined #49831
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
Prevents ARRAY_SIZE being defined by util.h if it is already defined, prevents possible future include file ordering issues that have plagued CI tests in the past. Signed-off-by: Jamie McCrae <[email protected]>
|
Where is the other definition? If it's in the Zephyr tree, we should fix that. If it's not, then we have an API collision between modules and we need to think about a better solution (e.g. fix it in the foreign code, or rename it to "SYS_ARRAY_SIZE()" or whatever to be part of a known Zephyr namespace). |
|
@andyross There is the same macro in zcbor, the zcbor code only defines it if it is not already defined |
@nordicjm I do not think that Zephyr provided macro definition should be conditional, as it would allow to override macro behaviour in out of tree code - making it behave differently in Zephyr and external code. I am -1 on this change. Sorry.
@andyross It might be good idea to make some of Zephyr macros, by for example SYS_ prefixing, more unique to decrease chance of collision. I am quite sure there has been discussion on that some time ago... I may be wrong. |
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.
While this may be a bit beyond the scope of this PR, as @andyross noted, it would be preferable to rename these macros so as to minimise the chance of name conflicts.
|
FWIW: for this specific macro, there is a long history of its use in Linux, where it's defined globally and used pervasively. I think that at least makes a reasonable precedent that it's a standard "OS kernel" API and thus something we should feel free to define ourselves. I don't know zcbor at all, but if it's colliding here maybe the solution is to put its definition inside an |
zcbor has #ifndef protection around it, it's when you have includes including includes including includes, etc. whereby util.h gets included in one specific source file after the zcbor header has been included |
|
Right, what I'm saying is that zcbor should have something like this instead, in whatever header it's defining ARRAY_SIZE(): #ifdef __ZEPHYR__
#include <zephyr/sys/util.h>
#else
#define ARRAY_SIZE(a) ...
#endif |
You can always do something like: #ifndef ZCBOR_USE_EXTERNAL_ARRAY_SIZE_DEFINITION //bad name
#undef ARRAY_SIZE(a) ...
#define ARRAY_SIZE(a) ...
#endifwhere It then forces explicit decision whether the |
Prevents ARRAY_SIZE being defined by util.h if it is already defined,
prevents possible future include file ordering issues that have
plagued CI tests in the past.