-
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
lib: add cbprintf capability #29876
lib: add cbprintf capability #29876
Conversation
174cfd3
to
2e871e4
Compare
34da0c2
to
0238350
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.
LGTM, this is similar to what I was trying to do with just the moving things around :)
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.
this looks great.
I'm assuming stack usage for printk() is roughly like it was before? Passing CI result suggests to me that it does, but I thought I'd ask.
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.
this looks great.
I'm assuming stack usage for printk() is roughly like it was before? Passing CI result suggests to me that it does, but I thought I'd ask.
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.
this looks great.
I'm assuming stack usage for printk() is roughly like it was before? Passing CI result suggests to me that it does, but I thought I'd ask.
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.
this looks great.
I'm assuming stack usage for printk() is roughly like it was before? Passing CI result suggests to me that it does, but I thought I'd ask.
Thanks!
I expect it's a little larger compared to |
```
+/* We can't determine at build-time whether int is 64-bit, so assume
+ * it is. If not the values are truncated at build time, and the str
+ * pointers will be updated during test initialization.
+ */
+static const unsigned int pfx_val = (unsigned int)0x7b6b5b4b3b2b1b0b;
```
In the Zephyr environment, an int is always 32 bits. Only a long will
vary in width, and sizeof(long) is always equal to sizeof(void*). So the
constant above will always be truncated.
|
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: #736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
This commit adds the missing `PRIxMAX` macros for the C99 `intmax_t` and `uintmax_t` types: PRIdMAX, PRIiMAX, PRIoMAX, PRIuMAX, PRIxMAX, PRIXMAX Note that the `PRIxMAX` macros specify the `ll` size modifier because the type of the `intmax_t` for the minimal libc is defined as that of the `int64_t`, which is always overridden to `long long int` by `zephyr_stdint.h`; for more details, refer to the GitHub PR zephyrproject-rtos#29876, which deliberately introduced this scheme. In the future, this scheme will need to be reworked such that the minimal libc `stdint.h` defines `intmax_t` as `__INTMAX_TYPE__`, and the `inttypes.h` resolves the corresponding format specifier. Signed-off-by: Stephanos Ioannidis <[email protected]>
This commit adds the missing `PRIxMAX` macros for the C99 `intmax_t` and `uintmax_t` types: PRIdMAX, PRIiMAX, PRIoMAX, PRIuMAX, PRIxMAX, PRIXMAX Note that the `PRIxMAX` macros specify the `ll` size modifier because the type of the `intmax_t` for the minimal libc is defined as that of the `int64_t`, which is always overridden to `long long int` by `zephyr_stdint.h`; for more details, refer to the GitHub PR #29876, which deliberately introduced this scheme. In the future, this scheme will need to be reworked such that the minimal libc `stdint.h` defines `intmax_t` as `__INTMAX_TYPE__`, and the `inttypes.h` resolves the corresponding format specifier. Signed-off-by: Stephanos Ioannidis <[email protected]>
This commit adds the missing `PRIxMAX` macros for the C99 `intmax_t` and `uintmax_t` types: PRIdMAX, PRIiMAX, PRIoMAX, PRIuMAX, PRIxMAX, PRIXMAX Note that the `PRIxMAX` macros specify the `ll` size modifier because the type of the `intmax_t` for the minimal libc is defined as that of the `int64_t`, which is always overridden to `long long int` by `zephyr_stdint.h`; for more details, refer to the GitHub PR zephyrproject-rtos#29876, which deliberately introduced this scheme. In the future, this scheme will need to be reworked such that the minimal libc `stdint.h` defines `intmax_t` as `__INTMAX_TYPE__`, and the `inttypes.h` resolves the corresponding format specifier. Signed-off-by: Stephanos Ioannidis <[email protected]>
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware/zmk#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware/zmk#736
* new cbprintf formatter causes issues for our use of string formatting. See: zephyrproject-rtos/zephyr#29876 PR: zmkfirmware#736
This PR adds a C99 stdio value formatter capability named
cbprintf()
(plus related variants) where generated text is emitted through a callback. This allows generation of arbitrarily long output without a buffer, functionality that is core to printk, logging, and other system and application needs.The formatter supports most C99 specifications, excluding:
The new solution is derived from
z_prf()
, which had the most complete functionality available. Format parsing has been reimplemented, while floating point conversion has been retained and enhanced.Kconfig options allow disabling features like floating-point conversion if they are not necessary.
Benefits include:
Costs include:
Fixes #29202