-
Notifications
You must be signed in to change notification settings - Fork 6.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
Several fixes around POSIX_SOURCE, remove global definitions of POSIX_SOURCE #67052
Conversation
b8c9623
to
efaaef3
Compare
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.
The ssize_t -> int changes are unrelated and also seem wrong? I'd also remove the #undef
bits; they shouldn't be necessary once we get rid of the global definitions
@@ -7,6 +7,20 @@ | |||
|
|||
#define DT_DRV_COMPAT zephyr_sim_eeprom | |||
|
|||
#ifdef CONFIG_ARCH_POSIX | |||
#undef _POSIX_C_SOURCE |
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 the undef here?
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.
As a harmless safety.
A user may define this globally, another library may due to legacy or by mistake.
It is safe to undef macros even if they were never defined.
Given that we are here due to conflicts in this area, and that some feel strongly about defining this kind of macro globally, and that Zephyr as an OS is built quite monotonically with the app it seemed reasonable to play safe.
Wouldn't you want to add them on your PR? :)
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 agree with the changes :)
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.
Temporary nak until the issue described in #67181 can be brought to the AWG.
3ee105f
to
5eb2b29
Compare
The following west manifest projects have been modified in this Pull Request:
Note: This message is automatically posted and updated by the Manifest GitHub Action. |
5eb2b29
to
c6a5377
Compare
strnlen() and strtok_r() are tested in this files which are extensions to the the std C library. Let's explicity select one of the extensions also when building with the host C library, instead of relaying on somebody having set it for this file somewhere else. Also, let's be nice and undefine them first in case they had been defined somewhere else in the build scripts. Signed-off-by: Alberto Escolar Piedras <[email protected]>
This test uses functions which are extensions to the C library. Let's explicity select one of the extensions which includes it instead of relaying on somebody having set it for this file somewhere else. (Note this test is exclusive to native targets) Signed-off-by: Alberto Escolar Piedras <[email protected]>
strnlen is not a C standard API, but an extension. Instead of relaying that the SOURCE macro was set somewhere else of that the C library provides a prototype anyhow let's explicitly define it for this library. Signed-off-by: Alberto Escolar Piedras <[email protected]>
strnlen is not a C standard API, but an extension. Instead of relaying that the SOURCE macro was set somewhere else of that the C library provides a prototype anyhow let's explicitly define it for this library. Signed-off-by: Alberto Escolar Piedras <[email protected]>
This test uses functions and types which are extensions to the C library. Let's explicity select one of the extensions which includes it instead of relaying on somebody having set it for this file somewhere else. Signed-off-by: Alberto Escolar Piedras <[email protected]>
Instead of relaying on those macros having been defined somewhere else let's define them for this file. Signed-off-by: Alberto Escolar Piedras <[email protected]>
This was necessary to get Picolibc to expose the whole Zephyr C library API, but current versions of the SDK use a version of Picolibc with built-in Zephyr support. Signed-off-by: Keith Packard <[email protected]>
Instead of relaying on those macros having been defined somewhere else let's define them for this library. Signed-off-by: Alberto Escolar Piedras <[email protected]>
07fa0b4
to
0bc1883
Compare
The compliance check failures are false positives. |
The srandom function is not available unless _XOPEN_SOURCE is set > 500 or an equivalent declaration is done. Let's set it. Signed-off-by: Alberto Escolar Piedras <[email protected]>
Do not define these macros globally, but instead define them only for this library and when needed. Signed-off-by: Alberto Escolar Piedras <[email protected]>
Both zcbor_encode.c & zcbor_decode.c use strnlen() In general these 2 functions are only exposed by the C library if _POSIX_C_SOURCE is set 200809L. But neither of these files (or their build scripts), are setting this macro, causing build warnings Implicit declaration of function ‘strnlen’ which turn into failures in CI with some libCs. Let's set this macro to avoid this issue. Signed-off-by: Alberto Escolar Piedras <[email protected]>
36b70b7
to
d4b85c6
Compare
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.
Looks OK. Thanks!
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.
Net part looks ok
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.
LGTM - thanks @aescolar 👍
Some cleanup around the selection of the API provided by the C library.
The main idea is to limit where the SOURCE selection is applied to much fewer files than before.
This PR includes some commits from #67040 so as to provide a complete solution. But it only includes those commits that are inline with the overall direction of this PR of removing all global definitions of these macros.
Background on the PR strategy differences:
Currently #67040 cleans up only the global definitions done by picolibc, but sets newlibc to define those globally.
The current assumption in 67040 is that all functions listed in the coding guidelines rules A.4 and A.5 should be globally available, without needing to set any macro by the user file, even that some of those functions are not part of the C std library API but extensions. Unfortunately, this sets a requirement on the libC integration to ensure they are exposed. See #67040 (comment).
Instead, this PR solves the global use of POSIX_SOURCE issue, while postponing deciding on and solving the libC integration topic ( #67040 (comment) )
Notes about the checkpatch warnings:
Sidenote: We can avoid all those check-patch warnings by defining these macros in cmake, but it does not feel nice to do so, just because of checkpatch.
Fixes #66921