From 50ca975402b23e12e9782116176f12051e3693d1 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 1 Oct 2019 15:02:59 +0200 Subject: [PATCH] btstack_debug: add support for btstack_assert macro --- src/btstack_debug.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/btstack_debug.h b/src/btstack_debug.h index f65912a26..22b06a6da 100644 --- a/src/btstack_debug.h +++ b/src/btstack_debug.h @@ -54,11 +54,31 @@ #include #endif +#ifdef HAVE_ASSERT +#include +#endif + // fallback to __FILE__ for untagged files #ifndef BTSTACK_FILE__ #define BTSTACK_FILE__ __FILE__ #endif +#ifdef HAVE_ASSERT +// map to libc assert +#define btstack_assert(condition) assert(condition) +#else /* HAVE_ASSERT */ +#ifdef ENABLE_BTSTACK_ASSERT +void btstack_assert_failed(const char * file, uint16_t line_nr); +#ifndef btstack_assert +// use btstack macro that calls btstack_assert_failed() - provided by port +#define btstack_assert(condition) if (condition) {} else { btstack_assert_failed(BTSTACK_FILE__, __LINE__); } +#endif +#else /* btstack_assert */ +// asserts off +#define btstack_assert(condition) {} +#endif +#endif + // Avoid complaints of unused arguments when log levels are disabled. static inline void __log_unused(const char *format, ...) { UNUSED(format);