From f5e7f2bb8ffaefaf619861e60a854535cb4fe8f1 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 27 Jun 2017 17:29:13 +1000 Subject: [PATCH 1/2] lwip: Remove port-specific sys_arch_assert(), use libc __assert_func() instead --- components/lwip/include/lwip/port/arch/cc.h | 4 +++- components/lwip/include/lwip/port/arch/sys_arch.h | 1 - components/lwip/port/freertos/sys_arch.c | 13 ------------- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/components/lwip/include/lwip/port/arch/cc.h b/components/lwip/include/lwip/port/arch/cc.h index 3213c66671..2b182d6410 100644 --- a/components/lwip/include/lwip/port/arch/cc.h +++ b/components/lwip/include/lwip/port/arch/cc.h @@ -36,6 +36,7 @@ #include #include +#include #include "arch/sys_arch.h" @@ -67,7 +68,8 @@ typedef int sys_prot_t; #include #define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0) -#define LWIP_PLATFORM_ASSERT(x) do {printf(x); sys_arch_assert(__FILE__, __LINE__);} while(0) +// __assert_func is the assertion failure handler from newlib, defined in assert.h +#define LWIP_PLATFORM_ASSERT(message) __assert_func(__FILE__, __LINE__, __ASSERT_FUNC, message) #ifdef NDEBUG #define LWIP_NOASSERT diff --git a/components/lwip/include/lwip/port/arch/sys_arch.h b/components/lwip/include/lwip/port/arch/sys_arch.h index a863348256..8d30ef171d 100644 --- a/components/lwip/include/lwip/port/arch/sys_arch.h +++ b/components/lwip/include/lwip/port/arch/sys_arch.h @@ -67,7 +67,6 @@ typedef struct sys_mbox_s { #define sys_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE ) #define sys_sem_set_invalid( x ) ( ( *x ) = NULL ) -void sys_arch_assert(const char *file, int line); uint32_t system_get_time(void); void sys_delay_ms(uint32_t ms); sys_sem_t* sys_thread_sem_init(void); diff --git a/components/lwip/port/freertos/sys_arch.c b/components/lwip/port/freertos/sys_arch.c index b03fd6df5d..63d0ccece4 100755 --- a/components/lwip/port/freertos/sys_arch.c +++ b/components/lwip/port/freertos/sys_arch.c @@ -482,19 +482,6 @@ sys_arch_unprotect(sys_prot_t pval) sys_mutex_unlock(&g_lwip_protect_mutex); } -/*-----------------------------------------------------------------------------------*/ -/* - * Prints an assertion messages and aborts execution. - */ -void -sys_arch_assert(const char *file, int line) -{ - ESP_LOGE(TAG, "\nAssertion: %d in %s\n", line, file); - -// vTaskEnterCritical(); - while(1); -} - #define SYS_TLS_INDEX CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX /* * get per thread semphore From 857a7f186e277914038a15ae7b8724580d54cf79 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 27 Jun 2017 18:36:54 +1000 Subject: [PATCH 2/2] lwip: Make LWIP_ERROR behave as if assertions were off, even if they are on --- components/lwip/include/lwip/port/arch/cc.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/components/lwip/include/lwip/port/arch/cc.h b/components/lwip/include/lwip/port/arch/cc.h index 2b182d6410..cba0b365ea 100644 --- a/components/lwip/include/lwip/port/arch/cc.h +++ b/components/lwip/include/lwip/port/arch/cc.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "arch/sys_arch.h" @@ -73,7 +74,21 @@ typedef int sys_prot_t; #ifdef NDEBUG #define LWIP_NOASSERT -#endif -//#define LWIP_ERROR +#else // Assertions enabled + +// If assertions are on, the default LWIP_ERROR handler behaviour is to +// abort w/ an assertion failure. Don't do this, instead just print the error (if LWIP_DEBUG is set) +// and run the handler (same as the LWIP_ERROR behaviour if LWIP_NOASSERT is set). +#ifdef LWIP_DEBUG +#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ + puts(message); handler;}} while(0) +#else +// If LWIP_DEBUG is not set, return the error silently (default LWIP behaviour, also.) +#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ + handler;}} while(0) +#endif // LWIP_DEBUG + +#endif /* NDEBUG */ + #endif /* __ARCH_CC_H__ */