Skip to content

Commit 540a506

Browse files
committed
Merge branch 'bugfix/lwip_assert' into 'master'
lwip: Remove port-specific sys_arch_assert(), use libc __assert_func() instead See merge request !926
2 parents bd09f18 + 857a7f1 commit 540a506

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

components/lwip/include/lwip/port/arch/cc.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#include <stdint.h>
3838
#include <errno.h>
39+
#include <assert.h>
40+
#include <stdio.h>
3941

4042
#include "arch/sys_arch.h"
4143

@@ -67,11 +69,26 @@ typedef int sys_prot_t;
6769
#include <stdio.h>
6870

6971
#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
70-
#define LWIP_PLATFORM_ASSERT(x) do {printf(x); sys_arch_assert(__FILE__, __LINE__);} while(0)
72+
// __assert_func is the assertion failure handler from newlib, defined in assert.h
73+
#define LWIP_PLATFORM_ASSERT(message) __assert_func(__FILE__, __LINE__, __ASSERT_FUNC, message)
7174

7275
#ifdef NDEBUG
7376
#define LWIP_NOASSERT
74-
#endif
75-
//#define LWIP_ERROR
77+
#else // Assertions enabled
78+
79+
// If assertions are on, the default LWIP_ERROR handler behaviour is to
80+
// abort w/ an assertion failure. Don't do this, instead just print the error (if LWIP_DEBUG is set)
81+
// and run the handler (same as the LWIP_ERROR behaviour if LWIP_NOASSERT is set).
82+
#ifdef LWIP_DEBUG
83+
#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
84+
puts(message); handler;}} while(0)
85+
#else
86+
// If LWIP_DEBUG is not set, return the error silently (default LWIP behaviour, also.)
87+
#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
88+
handler;}} while(0)
89+
#endif // LWIP_DEBUG
90+
91+
#endif /* NDEBUG */
92+
7693

7794
#endif /* __ARCH_CC_H__ */

components/lwip/include/lwip/port/arch/sys_arch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ typedef struct sys_mbox_s {
6767
#define sys_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
6868
#define sys_sem_set_invalid( x ) ( ( *x ) = NULL )
6969

70-
void sys_arch_assert(const char *file, int line);
7170
uint32_t system_get_time(void);
7271
void sys_delay_ms(uint32_t ms);
7372
sys_sem_t* sys_thread_sem_init(void);

components/lwip/port/freertos/sys_arch.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -482,19 +482,6 @@ sys_arch_unprotect(sys_prot_t pval)
482482
sys_mutex_unlock(&g_lwip_protect_mutex);
483483
}
484484

485-
/*-----------------------------------------------------------------------------------*/
486-
/*
487-
* Prints an assertion messages and aborts execution.
488-
*/
489-
void
490-
sys_arch_assert(const char *file, int line)
491-
{
492-
ESP_LOGE(TAG, "\nAssertion: %d in %s\n", line, file);
493-
494-
// vTaskEnterCritical();
495-
while(1);
496-
}
497-
498485
#define SYS_TLS_INDEX CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX
499486
/*
500487
* get per thread semphore

0 commit comments

Comments
 (0)