-
Notifications
You must be signed in to change notification settings - Fork 2k
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
sys/byteorder: clean up implementation #20313
sys/byteorder: clean up implementation #20313
Conversation
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.
🧼 🧽 Clean! ✨
43f844d
to
4a7097a
Compare
0384d19
to
83a0c79
Compare
This has revealed some bugs in |
83a0c79
to
1e8337e
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.
I think this can stay in one PR. Just a whitespace nit left.
8fdc667
to
16ebc02
Compare
The script to fix the vendor header files has been renamed to `fix_headers.sh` and now does two things: 1. Strip bogus type qualifiers in front of padding (as before) 2. Strip bogus `LITTLE_ENDIAN` defines.
Ran the `fix_headers.sh` to fix the vendor header files and removed the no longer needed work around for them.
The constants BIG_ENDIAN etc. were not consistently defined. This bug was not caught by the unit tests, as the preprocessor would treat undefined macros as being `0` in numeric comparisons, hence the following test did select the correct implementation: ```C #if BYTE_ORDER == LITTLE_ENDIAN /* correct implementation for all currently supported boards */ #endif ``` This adds now an explicit test to the unit tests to ensure that the magic numbers are consistently the correct values. Hence, this bug should no longer be able to sneak in. Co-authored-by: Teufelchen <9516484+Teufelchen1@users.noreply.github.com>
There is no need to use `__uint16_t` instead of `uint16_t` etc., so let's just go with `uint16_t` and have AVR GCC happy.
16ebc02
to
2328a32
Compare
Older versions of newlib already provide the magic endian numbers via `machine/endian.h`, which may be indirectly included. This changes the header to only provide the macros if the are not provided otherwise. For sanity, it checks if the values are indeed the expected magic numbers, even if provided from other sources.
2328a32
to
ad67d24
Compare
@benpicco Could you take a look at the first two commits of this PR? I dropped the work around for the |
Move the <endian.h> header from `sys/libc/include` to `sys/include`.
a307f15
to
944ce26
Compare
OK, this has been quite a journey, but everything is green now. I reorganized the commits into a logically sensible order. Everything should be ready for another round of review. |
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, did not run any tests, I assume the CI is enough.
(the timing of your request makes it look like I speed-ed through it in less than 3 minutes, not the case)
This changes the implementation to be solely build upon `endian.h` and `unaligned.h`. This turns `byteorder.h` basically in syntactic sugar on top of the `<endian.h>` API, reducing the complexity of the implementation and, hence, the maintenance effort. Note that yields a small ROM reduction as well *yeah!* ``` make BOARD=nrf52840dk RIOT_CI_BUILD=1 BUILD_IN_DOCKER=1 -C tests/unittests ``` Yields before this commit: ``` text data bss dec hex filename 417788 2200 28640 448628 6d874 /data/riotbuild/riotbase/tests/unittests/bin/nrf52840dk/tests_unittests.elf ``` And with this commit: ``` text data bss dec hex filename 417756 2200 28640 448596 6d854 /data/riotbuild/riotbase/tests/unittests/bin/nrf52840dk/tests_unittests.elf ```
944ce26
to
ebfaa36
Compare
This time it was just a CI glitch... |
Woohooo! 🎉 Thanks for the review! :) |
Contribution description
This changes the implementation to be solely build upon
endian.h
andunaligned.h
.This turns
byteorder.h
basically in syntactic sugar on top of the<endian.h>
API, reducing the complexity of the implementation and, hence, the maintenance effort.Note that yields a small ROM reduction as well yeah!
Yields before this commit:
And with this commit:
Update
This uncovered some bugs in
<endian.h>
that were not detected by the unit tests, as the unit test did not cover the magic constants but only that the right implementation was chosen. Due to the preprocessor handling undifined macros as0
in#if
directives, the correct implementation on little endian system was chosen anyway.In addition to fixing the bug, the unit test was extended, so that the same bug would be detected now.
Testing procedure
The unit tests in core cover
sys/byteorder
(historically,byteorder.h
was once incore
):make BOARD=nrf52840dk BUILD_IN_DOCKER=1 -C tests/unittests tests-core flash test -j
tl;dr
Issues/PRs references
None