-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
sys/fmt: use fflush(); stdio_write()
instead of fwrite()
#19250
Conversation
9e06684
to
bfcf2e5
Compare
I think the failed test is just a fluke, what do you think? |
Unfortunately not. Somehow the if condition caused printf to be used, which fails with the small stacks in those tests. I've changed |
7e8be4c
to
2fb98a9
Compare
I've also added a bit more commentary. |
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.
Please squash
ba8a886
to
c77b104
Compare
bors merge |
Build succeeded: |
Thanks for the review! |
/* native gets special treatment as native's stdio code is ... special. | ||
* And when not building for RIOT, there's no `stdio_write()`. | ||
* In those cases, just defer to `printf()`. | ||
*/ | ||
#if IS_USED(MODULE_STDIO_NATIVE) || !defined(RIOT_VERSION) |
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.
Could you explain to me why this is needed? I fail to understand the reason on my own. E.g. if I remove the guarded code, the unit test still pass for native. What am I misunderstanding?
Contribution description
Currently, fmt's
print()
is using libc'sfwrite()
in order to mitigate bothlibc and fmt output clashing wrt. libc stdio buffers. That causes
print()
touse quite a bit more stack, we had to remove the lower stack case in
print_stack_usage_metrics()
.This PR changes
print()
to usefflush()
;stdio_write()
instead, bypassinga lot of libc's FILE machinery.
A quick test on nrf52840dk shows that
print_stack_usage_metrics()
on anotherwise empty thread uses 124b stack without the
fflush()
, 160b with thefflush()
(this PR's state). So another commit re-adds theMIN_SIZE
fmtcase.
Testing procedure
Issues/PRs references