diff options
Diffstat (limited to 'libmisc')
-rw-r--r-- | libmisc/assert.c | 3 | ||||
-rw-r--r-- | libmisc/include/libmisc/_intercept.h | 8 | ||||
-rw-r--r-- | libmisc/intercept.c | 11 | ||||
-rw-r--r-- | libmisc/tests/test_assert.c | 4 |
4 files changed, 21 insertions, 5 deletions
diff --git a/libmisc/assert.c b/libmisc/assert.c index 69c0530..fdd8154 100644 --- a/libmisc/assert.c +++ b/libmisc/assert.c @@ -1,6 +1,6 @@ /* libmisc/assert.c - More assertions * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -12,6 +12,7 @@ #include <libmisc/assert.h> #ifndef NDEBUG +#define __lm_printf __lm_light_printf void __assert_msg_fail(const char *expr, const char *file, unsigned int line, const char *func, const char *msg) { diff --git a/libmisc/include/libmisc/_intercept.h b/libmisc/include/libmisc/_intercept.h index 47e4620..ab76857 100644 --- a/libmisc/include/libmisc/_intercept.h +++ b/libmisc/include/libmisc/_intercept.h @@ -1,6 +1,6 @@ /* libmisc/_intercept.h - Interceptable ("weak") functions * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -18,4 +18,10 @@ int __lm_printf(const char *format, ...); [[noreturn]] void __lm_abort(void); +/* __lm_light_printf is expected to have less stack use than regular + * __lm_printf, if possible. */ + +[[format(printf, 1, 2)]] +int __lm_light_printf(const char *format, ...); + #endif /* _LIBMISC__INTERCEPT_H_ */ diff --git a/libmisc/intercept.c b/libmisc/intercept.c index dda8c09..85a3801 100644 --- a/libmisc/intercept.c +++ b/libmisc/intercept.c @@ -1,6 +1,6 @@ /* libmisc/intercept.c - Interceptable ("weak") functions * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -20,6 +20,15 @@ int __lm_printf(const char *format, ...) { } [[gnu::weak]] +int __lm_light_printf(const char *format, ...) { + va_list va; + va_start(va, format); + int ret = vprintf(format, va); + va_end(va); + return ret; +} + +[[gnu::weak]] void __lm_abort(void) { abort(); } diff --git a/libmisc/tests/test_assert.c b/libmisc/tests/test_assert.c index 3c2d6b6..15f9446 100644 --- a/libmisc/tests/test_assert.c +++ b/libmisc/tests/test_assert.c @@ -1,6 +1,6 @@ /* libmisc/tests/test_assert.c - Tests for <libmisc/assert.h> * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -35,7 +35,7 @@ void __lm_abort(void) { longjmp(global_env, 1); } -int __lm_printf(const char *format, ...) { +int __lm_light_printf(const char *format, ...) { va_list va; va_start(va, format); int ret = vasprintf(&global_log, format, va); |