From 688b0935e29bd485aaf147881a8d814126d2c46a Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Tue, 23 Oct 2018 08:00:37 +0200 Subject: [PATCH] Try to catch missing std includes on travis By defining LWIP_PLATFORM_ASSERT to a function, we can prevent arch.h from including stdio.h and stdlib.h Signed-off-by: Simon Goldschmidt --- contrib/examples/example_app/lwipopts.h | 6 ++++++ contrib/examples/example_app/test.c | 10 ++++++++++ contrib/ports/win32/include/arch/cc.h | 10 +++++----- src/apps/http/makefsdata/makefsdata.c | 4 ++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/contrib/examples/example_app/lwipopts.h b/contrib/examples/example_app/lwipopts.h index d076d61a..5acbe98a 100644 --- a/contrib/examples/example_app/lwipopts.h +++ b/contrib/examples/example_app/lwipopts.h @@ -326,4 +326,10 @@ void sys_unlock_tcpip_core(void); #endif #endif +#ifndef LWIP_PLATFORM_ASSERT +/* Define LWIP_PLATFORM_ASSERT to something to catch missing stdio.h includes */ +void lwip_example_app_platform_assert(const char *msg, int line, const char *file); +#define LWIP_PLATFORM_ASSERT(x) lwip_example_app_platform_assert(x, __LINE__, __FILE__) +#endif + #endif /* LWIP_LWIPOPTS_H */ diff --git a/contrib/examples/example_app/test.c b/contrib/examples/example_app/test.c index 0002bac7..510fd3ae 100644 --- a/contrib/examples/example_app/test.c +++ b/contrib/examples/example_app/test.c @@ -760,3 +760,13 @@ int main(void) return 0; } + +/* This function is only required to prevent arch.h including stdio.h + * (which it does if LWIP_PLATFORM_ASSERT is undefined) + */ +void lwip_example_app_platform_assert(const char *msg, int line, const char *file) +{ + printf("Assertion \"%s\" failed at line %d in %s\n", msg, line, file); + fflush(NULL); + abort(); +} diff --git a/contrib/ports/win32/include/arch/cc.h b/contrib/ports/win32/include/arch/cc.h index 0ec5483c..3ee051da 100644 --- a/contrib/ports/win32/include/arch/cc.h +++ b/contrib/ports/win32/include/arch/cc.h @@ -82,8 +82,8 @@ typedef int sys_prot_t; #define PACK_STRUCT_USE_INCLUDES #define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ - printf("Assertion \"%s\" failed at line %d in %s\n", message, __LINE__, __FILE__); \ - fflush(NULL);handler;} } while(0) + LWIP_PLATFORM_DIAG(("Assertion \"%s\" failed at line %d in %s\n", message, __LINE__, __FILE__)); \ + handler;} } while(0) #ifdef _MSC_VER /* C runtime functions redefined */ @@ -94,9 +94,9 @@ typedef int sys_prot_t; #endif /* Define an example for LWIP_PLATFORM_DIAG: since this uses varargs and the old - * C standard lwIP targets does not support this in macros, we have extra brackets - * around the arguments, which are left out in the following macro definition: - */ +* C standard lwIP targets does not support this in macros, we have extra brackets +* around the arguments, which are left out in the following macro definition: +*/ #if !defined(LWIP_TESTMODE) || !LWIP_TESTMODE void lwip_win32_platform_diag(const char *format, ...); #define LWIP_PLATFORM_DIAG(x) lwip_win32_platform_diag x diff --git a/src/apps/http/makefsdata/makefsdata.c b/src/apps/http/makefsdata/makefsdata.c index 695e94f5..31c15a63 100644 --- a/src/apps/http/makefsdata/makefsdata.c +++ b/src/apps/http/makefsdata/makefsdata.c @@ -81,6 +81,10 @@ int deflate_level = 10; /* default compression level, can be changed via command #define NEWLINE "\r\n" #define NEWLINE_LEN 2 +/* Define this here since we don't include any external C files and ports might override it */ +#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \ + x, __LINE__, __FILE__); fflush(NULL); abort();} while(0) + /* define this to get the header variables we use to build HTTP headers */ #define LWIP_HTTPD_DYNAMIC_HEADERS 1 #define LWIP_HTTPD_SSI 1