summaryrefslogtreecommitdiff
path: root/libmisc/include
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-26 20:09:17 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-12-26 20:09:17 -0700
commite7e0cff1960fca598e0ba01be2bb56b65cbb9e2b (patch)
tree1e2c607ae9980b47917effe4203b4448a1dd4c5f /libmisc/include
parentd0e9e9c4a178fe396f3ba255bc440a15b107a097 (diff)
parent1aecc70750ee6ce9c96ebf3e6b4a7fb322ff8ca3 (diff)
Merge branch 'lukeshu/check-build'
Diffstat (limited to 'libmisc/include')
-rw-r--r--libmisc/include/libmisc/_intercept.h21
-rw-r--r--libmisc/include/libmisc/assert.h2
-rw-r--r--libmisc/include/libmisc/log.h9
3 files changed, 26 insertions, 6 deletions
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 <lukeshu@lukeshu.com>
+ * 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/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 */
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 <stdint.h> /* for uint8_t */
#include <libmisc/macro.h>
+#include <libmisc/_intercept.h>
#ifndef LOG_NAME
#error "each compilation unit that includes <libmisc/log.h> 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__)