From 35005c3e85fe17f13e3ae788967936d88844cfed Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 26 Sep 2024 16:54:23 +0200 Subject: [PATCH 1/5] core: add stdio.h to replace stdout functions with stdio_null --- core/include/stdio.h | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 core/include/stdio.h diff --git a/core/include/stdio.h b/core/include/stdio.h new file mode 100644 index 0000000000..cb70c636df --- /dev/null +++ b/core/include/stdio.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2024 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup sys_stdio_null + * + * This module a wrapper for the stdio.h header intended to remove all calls + * to stdout when stdio_null is used. + * + * This needs to reside in `core/` so it gets included early. + * + * @{ + * + * @file + * @brief stdio wrapper to replace the C libs stdio + * + * @author Benjamin Valentin + */ + +#ifndef CORE_STDIO_H +#define CORE_STDIO_H +#include_next "stdio.h" + +#ifdef MODULE_STDIO_NULL + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +static inline int printf_null(const char *__restrict__ format, ...) +{ + (void)format; + return 0; +} + +static inline int vprintf_null(const char *__restrict__ format, va_list ap) +{ + (void)format; + (void)ap; + return 0; +} + +#undef perror +#undef putchar +#undef puts +#undef printf +#undef vprintf + +#define perror(s) (void)s +#define puts(s) (void)s +#define putchar(c) (void)c +#define printf(...) printf_null(__VA_ARGS__) +#define vprintf(format, ap) vprintf_null(format, ap) + +#ifdef __cplusplus +} +#endif + +#endif /* MODULE_STDIO_NULL */ + +#endif /* CORE_STDIO_H */ +/** @} */ From 8c2566626738ccb7c768c2a755205d1043cebd93 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 26 Sep 2024 16:54:51 +0200 Subject: [PATCH 2/5] cpu/native: don't implement stdout functions with stdio_null --- cpu/native/syscalls.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cpu/native/syscalls.c b/cpu/native/syscalls.c index 8e7eb97a18..25828f49c6 100644 --- a/cpu/native/syscalls.c +++ b/cpu/native/syscalls.c @@ -226,18 +226,13 @@ ssize_t _native_writev(int fd, const struct iovec *iov, int iovcnt) #if defined(__FreeBSD__) #undef putchar #endif +#ifndef MODULE_STDIO_NULL int putchar(int c) { char tmp = c; return _native_write(STDOUT_FILENO, &tmp, sizeof(tmp)); } -int putc(int c, FILE *fp) -{ - char tmp = c; - return _native_write(fileno(fp), &tmp, sizeof(tmp)); -} - int puts(const char *s) { int r; @@ -245,6 +240,13 @@ int puts(const char *s) putchar('\n'); return r; } +#endif + +int putc(int c, FILE *fp) +{ + char tmp = c; + return _native_write(fileno(fp), &tmp, sizeof(tmp)); +} int fgetc(FILE *fp) { @@ -308,6 +310,7 @@ char *make_message(const char *format, va_list argp) } } +#ifndef MODULE_STDIO_NULL int printf(const char *format, ...) { int r; @@ -324,6 +327,7 @@ int vprintf(const char *format, va_list argp) { return vfprintf(stdout, format, argp); } +#endif int fprintf(FILE *fp, const char *format, ...) { From 6a08bff2f040ef557eaf40c5297e4934a1015f76 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 2 Oct 2024 19:41:16 +0200 Subject: [PATCH 3/5] pkg/jerryscript: don't be pedantic --- pkg/jerryscript/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/jerryscript/Makefile b/pkg/jerryscript/Makefile index f1b3e0d1bb..eef099eb96 100644 --- a/pkg/jerryscript/Makefile +++ b/pkg/jerryscript/Makefile @@ -13,6 +13,7 @@ JERRY_GC_LIMIT ?= 0 # Use default value, e.g. 1/32 of total heap size JERRY_GC_MARK_LIMIT ?= 8 # maximum recursion depth during GC mark phase EXT_CFLAGS := -D__TARGET_RIOT +EXT_CFLAGS += -Wno-pedantic CFLAGS += -Wno-cast-align # disable warnings when compiling with LLVM for board native From 082a37b17f9bf5c65676741a36fa9598a8092279 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 2 Oct 2024 20:10:06 +0200 Subject: [PATCH 4/5] dist/tools/headerguards: ignore if #include_next is used We can't use the same header guard if we include two files with the same name. --- dist/tools/headerguards/headerguards.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dist/tools/headerguards/headerguards.py b/dist/tools/headerguards/headerguards.py index e650b6c2d4..8f5a220e6d 100755 --- a/dist/tools/headerguards/headerguards.py +++ b/dist/tools/headerguards/headerguards.py @@ -43,6 +43,7 @@ def fix_headerguard(filename): tmp.seek(0) guard_found = 0 + include_next_found = 0 guard_name = "" ifstack = 0 for line in inlines: @@ -66,14 +67,17 @@ def fix_headerguard(filename): else: guard_found += 1 line = "#endif /* %s */\n" % supposed + elif line.startswith("#include_next"): + include_next_found = 1 tmp.write(line) tmp.seek(0) if guard_found == 3: - for line in difflib.unified_diff(inlines, tmp.readlines(), - "%s" % filename, "%s" % filename): - sys.stdout.write(line) + if include_next_found == 0: + for line in difflib.unified_diff(inlines, tmp.readlines(), + "%s" % filename, "%s" % filename): + sys.stdout.write(line) else: print("%s: no / broken header guard" % filename, file=sys.stderr) return False From f840d80473f22d76f41158e771bec5c67f9c9e56 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sun, 22 Dec 2024 16:56:35 +0100 Subject: [PATCH 5/5] cpu/avr8_common: don't implement perror() with stdio_null --- cpu/avr8_common/avr_libc_extra/posix_unistd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpu/avr8_common/avr_libc_extra/posix_unistd.c b/cpu/avr8_common/avr_libc_extra/posix_unistd.c index 55b50f2285..71e6846a74 100644 --- a/cpu/avr8_common/avr_libc_extra/posix_unistd.c +++ b/cpu/avr8_common/avr_libc_extra/posix_unistd.c @@ -177,9 +177,11 @@ ssize_t write(int fd, const void *src, size_t count) #endif } +#ifndef MODULE_STDIO_NULL void perror(const char *s) { printf("%s: %s\n", s, strerror(errno)); } +#endif /** @} */