From 5415686b41adb8c75a6c1da999aeddd6894b3010 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Wed, 14 May 2025 11:53:11 -0600 Subject: libmisc: _intercept.h: Have __lm_printf return size_t instead of int --- libfmt/libmisc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libfmt/libmisc.c') diff --git a/libfmt/libmisc.c b/libfmt/libmisc.c index 134b9f0..04affb7 100644 --- a/libfmt/libmisc.c +++ b/libfmt/libmisc.c @@ -27,23 +27,23 @@ static void libfmt_libc_fct(char character, void *LM_UNUSED(arg)) { } #endif -int __lm_printf(const char *format, ...) { +size_t __lm_printf(const char *format, ...) { va_list va; va_start(va, format); #if LIB_PICO_STDIO /* pico_stdio has already intercepted vprintf for us, and * their stdio_buffered_printer() is better than our * libfmt_libc_fct() because buffering. */ - int ret = vprintf(format, va); + size_t ret = (size_t) vprintf(format, va); #else - int ret = fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); + size_t ret = (size_t) fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); fflush(stdout); #endif va_end(va); return ret; } -int __lm_light_printf(const char *format, ...) { +size_t __lm_light_printf(const char *format, ...) { va_list va; va_start(va, format); #if LIB_PICO_STDIO @@ -52,10 +52,10 @@ int __lm_light_printf(const char *format, ...) { * stdio.c:__wrap_vprintf(); so that's where you'll see the * numbers be different if you're analyzing it. (Also, being * able to skip the stdio_stack_buffer_flush() call.) */ - int ret = fmt_vfctprintf(libfmt_light_fct, NULL, format, va); + size_t ret = (size_t) fmt_vfctprintf(libfmt_light_fct, NULL, format, va); stdio_flush(); #else - int ret = fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); + size_t ret = (size_t) fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); fflush(stdout); #endif va_end(va); -- cgit v1.2.3-2-g168b From 67cec6d2770aa14a13c89247612f16c628ebd54c Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Wed, 14 May 2025 12:20:02 -0600 Subject: libmisc: Remove uses of printf --- libfmt/libmisc.c | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'libfmt/libmisc.c') diff --git a/libfmt/libmisc.c b/libfmt/libmisc.c index 04affb7..552b916 100644 --- a/libfmt/libmisc.c +++ b/libfmt/libmisc.c @@ -11,17 +11,11 @@ #endif #include /* for LM_UNUSED() */ -#include /* for __lm_printf() and __lm_light_printf() */ +#include /* for __lm_printf() */ #include /* for fmt_vfctprintf() */ -#if LIB_PICO_STDIO -static void libfmt_light_fct(char character, void *LM_UNUSED(arg)) { - if (character == '\n') - stdio_putchar_raw('\r'); - stdio_putchar_raw(character); -} -#else +#if !LIB_PICO_STDIO static void libfmt_libc_fct(char character, void *LM_UNUSED(arg)) { putchar(character); } @@ -43,25 +37,6 @@ size_t __lm_printf(const char *format, ...) { return ret; } -size_t __lm_light_printf(const char *format, ...) { - va_list va; - va_start(va, format); -#if LIB_PICO_STDIO - /* libfmt_light_fct() and stdio_buffered_printer() both use 68 - * bytes of stack; but the buffer lives on the stack of - * stdio.c:__wrap_vprintf(); so that's where you'll see the - * numbers be different if you're analyzing it. (Also, being - * able to skip the stdio_stack_buffer_flush() call.) */ - size_t ret = (size_t) fmt_vfctprintf(libfmt_light_fct, NULL, format, va); - stdio_flush(); -#else - size_t ret = (size_t) fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); - fflush(stdout); -#endif - va_end(va); - return ret; -} - static void libfmt_conv_formatter(struct fmt_state *state) { lo_interface fmt_formatter obj = va_arg(*state->args, lo_interface fmt_formatter); LO_CALL(obj, format, state); -- cgit v1.2.3-2-g168b From 3faaad9fe1f11cfe5699c6720c897bfddc7cf49a Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 15 May 2025 00:18:27 -0600 Subject: Begone with the printf variants of the log functions --- libfmt/libmisc.c | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'libfmt/libmisc.c') diff --git a/libfmt/libmisc.c b/libfmt/libmisc.c index 552b916..4d3724b 100644 --- a/libfmt/libmisc.c +++ b/libfmt/libmisc.c @@ -4,39 +4,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -#include /* for va_list, va_start(), va_end() */ -#include /* for vprintf(), putchar(), fflush() */ -#if LIB_PICO_STDIO -#include /* for stdio_putchar_raw() */ -#endif - -#include /* for LM_UNUSED() */ -#include /* for __lm_printf() */ - #include /* for fmt_vfctprintf() */ -#if !LIB_PICO_STDIO -static void libfmt_libc_fct(char character, void *LM_UNUSED(arg)) { - putchar(character); -} -#endif - -size_t __lm_printf(const char *format, ...) { - va_list va; - va_start(va, format); -#if LIB_PICO_STDIO - /* pico_stdio has already intercepted vprintf for us, and - * their stdio_buffered_printer() is better than our - * libfmt_libc_fct() because buffering. */ - size_t ret = (size_t) vprintf(format, va); -#else - size_t ret = (size_t) fmt_vfctprintf(libfmt_libc_fct, NULL, format, va); - fflush(stdout); -#endif - va_end(va); - return ret; -} - static void libfmt_conv_formatter(struct fmt_state *state) { lo_interface fmt_formatter obj = va_arg(*state->args, lo_interface fmt_formatter); LO_CALL(obj, format, state); -- cgit v1.2.3-2-g168b From e38a2d29292ad3fad64729ef958ff07e3bca02cf Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Thu, 15 May 2025 01:59:17 -0600 Subject: Fully banish printf from the firmware --- libfmt/libmisc.c | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 libfmt/libmisc.c (limited to 'libfmt/libmisc.c') diff --git a/libfmt/libmisc.c b/libfmt/libmisc.c deleted file mode 100644 index 4d3724b..0000000 --- a/libfmt/libmisc.c +++ /dev/null @@ -1,17 +0,0 @@ -/* libfmt/libmisc.c - Integrate pico-fmt with libmisc - * - * Copyright (C) 2024-2025 Luke T. Shumaker - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#include /* for fmt_vfctprintf() */ - -static void libfmt_conv_formatter(struct fmt_state *state) { - lo_interface fmt_formatter obj = va_arg(*state->args, lo_interface fmt_formatter); - LO_CALL(obj, format, state); -} - -[[gnu::constructor]] -static void libfmt_install_formatter(void) { - fmt_install('v', libfmt_conv_formatter); -} -- cgit v1.2.3-2-g168b