btstack_debug: allow to provide custom btstack_assert

This commit is contained in:
Matthias Ringwald 2022-02-28 15:04:46 +01:00
parent a0e500cff7
commit 4b246621d1

View File

@ -54,8 +54,10 @@
#endif #endif
#ifdef HAVE_ASSERT #ifdef HAVE_ASSERT
#ifndef btstack_assert
#include <assert.h> #include <assert.h>
#endif #endif
#endif
// fallback to __FILE__ for untagged files // fallback to __FILE__ for untagged files
#ifndef BTSTACK_FILE__ #ifndef BTSTACK_FILE__
@ -63,8 +65,11 @@
#endif #endif
#ifdef HAVE_ASSERT #ifdef HAVE_ASSERT
// allow to override btstack_assert in btstack_config.h
#ifndef btstack_assert
// map to libc assert // map to libc assert
#define btstack_assert(condition) assert(condition) #define btstack_assert(condition) assert(condition)
#endif /* btstack_assert */
#else /* HAVE_ASSERT */ #else /* HAVE_ASSERT */
#ifdef ENABLE_BTSTACK_ASSERT #ifdef ENABLE_BTSTACK_ASSERT
void btstack_assert_failed(const char * file, uint16_t line_nr); void btstack_assert_failed(const char * file, uint16_t line_nr);
@ -72,11 +77,11 @@ void btstack_assert_failed(const char * file, uint16_t line_nr);
// use btstack macro that calls btstack_assert_failed() - provided by port // use btstack macro that calls btstack_assert_failed() - provided by port
#define btstack_assert(condition) if (condition) {} else { btstack_assert_failed(BTSTACK_FILE__, __LINE__); } #define btstack_assert(condition) if (condition) {} else { btstack_assert_failed(BTSTACK_FILE__, __LINE__); }
#endif #endif
#else /* btstack_assert */ #else /* ENABLE_BTSTACK_ASSERT */
// asserts off // asserts off
#define btstack_assert(condition) {} #define btstack_assert(condition) {}
#endif #endif /* btstack_assert */
#endif #endif /* HAVE_ASSERT */
// mark code that should not be reached. Similar to assert, but mapped to NOP for coverage // mark code that should not be reached. Similar to assert, but mapped to NOP for coverage
#ifdef UNIT_TEST #ifdef UNIT_TEST