From 3756c77e536a293fc735726eac0e5f0c3a8b89da Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 21 Dec 2024 23:50:09 -0700 Subject: libmisc: Check that assert.h has no deps --- libmisc/include/libmisc/assert.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libmisc/include') diff --git a/libmisc/include/libmisc/assert.h b/libmisc/include/libmisc/assert.h index da2ba2b..8cf0735 100644 --- a/libmisc/include/libmisc/assert.h +++ b/libmisc/include/libmisc/assert.h @@ -17,7 +17,7 @@ #endif #define assert_msg(expr, msg) __assert_msg(expr, #expr, msg) /* libmisc */ -#define assert(expr) __assert_msg(expr, #expr, NULL) /* C89, POSIX-2001 */ +#define assert(expr) __assert_msg(expr, #expr, 0) /* C89, POSIX-2001 */ #define assert_notreached(msg) do { __assert_msg(0, "notreached", msg); __builtin_unreachable(); } while (0) /* libmisc */ #define static_assert _Static_assert /* C11 */ -- cgit v1.2.3-2-g168b From 79284b25994d90149f4a9a5286ec739770db94ea Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 17 Dec 2024 19:18:21 -0700 Subject: libmisc: Rework how test-intercepts work --- libmisc/include/libmisc/_intercept.h | 21 +++++++++++++++++++++ libmisc/include/libmisc/log.h | 9 ++++----- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 libmisc/include/libmisc/_intercept.h (limited to 'libmisc/include') diff --git a/libmisc/include/libmisc/_intercept.h b/libmisc/include/libmisc/_intercept.h new file mode 100644 index 0000000..47e4620 --- /dev/null +++ b/libmisc/include/libmisc/_intercept.h @@ -0,0 +1,21 @@ +/* libmisc/_intercept.h - Interceptable ("weak") functions + * + * Copyright (C) 2024 Luke T. Shumaker + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _LIBMISC__INTERCEPT_H_ +#define _LIBMISC__INTERCEPT_H_ + +/* pico-sdk/newlib define these 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. + */ + +[[format(printf, 1, 2)]] +int __lm_printf(const char *format, ...); + +[[noreturn]] void __lm_abort(void); + +#endif /* _LIBMISC__INTERCEPT_H_ */ diff --git a/libmisc/include/libmisc/log.h b/libmisc/include/libmisc/log.h index 8c6d6be..121b0e1 100644 --- a/libmisc/include/libmisc/log.h +++ b/libmisc/include/libmisc/log.h @@ -10,6 +10,7 @@ #include /* for uint8_t */ #include +#include #ifndef LOG_NAME #error "each compilation unit that includes must define LOG_NAME" @@ -21,12 +22,10 @@ #define _LOG_NDEBUG 0 #endif -[[format(printf, 1, 2)]] int _log_printf(const char *format, ...); - -#define n_errorf(nam, fmt, ...) do { _log_printf("error: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) -#define n_infof(nam, fmt, ...) do { _log_printf("info : " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define n_errorf(nam, fmt, ...) do { __lm_printf("error: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) +#define n_infof(nam, fmt, ...) do { __lm_printf("info : " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) #define n_debugf(nam, fmt, ...) do { if (LM_CAT3_(CONFIG_, nam, _DEBUG) && !_LOG_NDEBUG) \ - _log_printf("debug: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) + __lm_printf("debug: " LM_STR_(nam) ": " fmt "\n" __VA_OPT__(,) __VA_ARGS__); } while (0) #define errorf(fmt, ...) n_errorf(LOG_NAME, fmt, __VA_ARGS__) #define infof(fmt, ...) n_infof(LOG_NAME, fmt, __VA_ARGS__) -- cgit v1.2.3-2-g168b