summaryrefslogtreecommitdiff
path: root/libmisc
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-15 00:18:27 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-15 14:58:17 -0600
commit3faaad9fe1f11cfe5699c6720c897bfddc7cf49a (patch)
treef15758869c758eeeb7604afc5c03e8d7601d8315 /libmisc
parent9c0338b1b4495457659157e1e9f47d422dcefc2e (diff)
Begone with the printf variants of the log functions
Diffstat (limited to 'libmisc')
-rw-r--r--libmisc/include/libmisc/_intercept.h14
-rw-r--r--libmisc/include/libmisc/log.h10
-rw-r--r--libmisc/intercept.c12
-rw-r--r--libmisc/tests/test_log.c34
4 files changed, 6 insertions, 64 deletions
diff --git a/libmisc/include/libmisc/_intercept.h b/libmisc/include/libmisc/_intercept.h
index f02244a..fa327d6 100644
--- a/libmisc/include/libmisc/_intercept.h
+++ b/libmisc/include/libmisc/_intercept.h
@@ -7,18 +7,12 @@
#ifndef _LIBMISC__INTERCEPT_H_
#define _LIBMISC__INTERCEPT_H_
-#include <stddef.h> /* for size_t */
-
-/* pico-sdk/newlib define printf() and abort() to be [[gnu::weak]]
- * already, but depending on optimization options glibc might not, and
- * GCC might assume it knows what they do and optimize them out. So
- * define our own `__lm_` wrappers that GCC/glibc won't interfere
- * with.
+/* pico-sdk/newlib defines abort() to be [[gnu::weak]] already, but
+ * depending on optimization options glibc might not, and GCC might
+ * assume it knows what it does and optimize it out. So define our
+ * own `__lm_` wrapper that GCC/glibc won't interfere with.
*/
-[[gnu::format(printf, 1, 2)]]
-size_t __lm_printf(const char *format, ...);
-
[[noreturn]] void __lm_abort(void);
/* While newlib defines putchar() to be [[gnu::weak]], pico_stdio does
diff --git a/libmisc/include/libmisc/log.h b/libmisc/include/libmisc/log.h
index 78ee1e7..e6dfb52 100644
--- a/libmisc/include/libmisc/log.h
+++ b/libmisc/include/libmisc/log.h
@@ -23,11 +23,6 @@ const char *const_byte_str(uint8_t b);
extern lo_interface fmt_dest _log_dest;
-#define log_n_errorf(nam, fmt, ...) do { __lm_printf("error: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0)
-#define log_n_infof(nam, fmt, ...) do { __lm_printf("info : " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0)
-#define log_n_debugf(nam, fmt, ...) do { if (LM_CAT3_(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \
- __lm_printf("debug: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0)
-
#define log_n_errorln(nam, ...) fmt_print(_log_dest, "error: " LM_STR_(nam) ": ", __VA_ARGS__, "\n")
#define log_n_infoln(nam, ...) fmt_print(_log_dest, "info : " LM_STR_(nam) ": ", __VA_ARGS__, "\n")
#define log_n_debugln(nam, ...) do { if (LM_CAT3_(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \
@@ -35,10 +30,7 @@ extern lo_interface fmt_dest _log_dest;
#endif /* _LIBMISC_LOG_H_ */
-#if defined(LOG_NAME) && !defined(log_errorf)
-#define log_errorf(fmt, ...) log_n_errorf(LOG_NAME, fmt, __VA_ARGS__)
-#define log_infof(fmt, ...) log_n_infof(LOG_NAME, fmt, __VA_ARGS__)
-#define log_debugf(fmt, ...) log_n_debugf(LOG_NAME, fmt, __VA_ARGS__)
+#if defined(LOG_NAME) && !defined(log_errorln)
#define log_errorln(...) log_n_errorln(LOG_NAME, __VA_ARGS__)
#define log_infoln(...) log_n_infoln(LOG_NAME, __VA_ARGS__)
#define log_debugln(...) log_n_debugln(LOG_NAME, __VA_ARGS__)
diff --git a/libmisc/intercept.c b/libmisc/intercept.c
index 70671f6..30870bf 100644
--- a/libmisc/intercept.c
+++ b/libmisc/intercept.c
@@ -4,22 +4,12 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-#include <stdarg.h> /* for va_list, va_start(), va_end() */
-#include <stdio.h> /* for vprintf(), putchar() */
+#include <stdio.h> /* for putchar() */
#include <stdlib.h> /* for abort() */
#include <libmisc/_intercept.h>
[[gnu::weak]]
-size_t __lm_printf(const char *format, ...) {
- va_list va;
- va_start(va, format);
- size_t ret = (size_t) vprintf(format, va);
- va_end(va);
- return ret;
-}
-
-[[gnu::weak]]
void __lm_putchar(unsigned char c) {
(void) putchar(c);
}
diff --git a/libmisc/tests/test_log.c b/libmisc/tests/test_log.c
index e5abb61..ee762e2 100644
--- a/libmisc/tests/test_log.c
+++ b/libmisc/tests/test_log.c
@@ -20,23 +20,6 @@
static struct fmt_buf log_output = {};
-size_t __lm_printf(const char *format, ...) {
- restart:
- va_list va;
- va_start(va, format);
- size_t ret = (size_t) vsnprintf(log_output.dat, log_output.cap, format, va);
- va_end(va);
-
- if (ret > log_output.cap) {
- log_output.cap = ret+8;
- log_output.dat = realloc(log_output.dat, log_output.cap);
- memset(log_output.dat, 0, log_output.cap);
- goto restart;
- }
- log_output.len = ret;
- return ret;
-}
-
void __lm_putchar(unsigned char c) {
if (log_output.len+1 >= log_output.cap) {
log_output.cap += 16;
@@ -74,23 +57,6 @@ static void log_output_clear(void) {
} while (0)
int main() {
- /* printf */
- should_print("error: FROBNICATE: val=42\n",
- log_errorf("val=%d", 42));
- should_print("info : FROBNICATE: val=0\n",
- log_infof("val=%d", 0));
-#ifndef NDEBUG
-#define CONFIG_FROBNICATE_DEBUG 1
- should_print("debug: FROBNICATE: val=-2\n",
- log_debugf("val=%d", -2));
-#undef CONFIG_FROBNICATE_DEBUG
-#define CONFIG_FROBNICATE_DEBUG 0
- should_print(NULL,
- log_debugf("val=%d", -2));
-#undef CONFIG_FROBNICATE_DEBUG
-#endif
-
- /* libmisc/fmt.h */
should_print("error: FROBNICATE: val=42\n",
log_errorln("val=", 42));
should_print("info : FROBNICATE: val=0\n",