1 /* 2 * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 8 /* This header file wraps newlib's own unmodified assert.h and adds 9 support for silent assertion failure. 10 */ 11 #pragma once 12 #include <sdkconfig.h> 13 #include <stdlib.h> 14 #include <stdint.h> 15 16 #include_next <assert.h> 17 18 /* moved part of libc provided assert to here allows 19 * tweaking the assert macro to use __builtin_expect() 20 * and reduce jumps in the "asserts OK" code path 21 * 22 * Note: using __builtin_expect() not likely() to avoid defining the likely 23 * macro in namespace of non-IDF code that may include this standard header. 24 */ 25 #undef assert 26 27 /* __FILENAME__ points to the file name instead of path + filename 28 * e.g __FILE__ points to "/apps/test.c" where as __FILENAME__ points to "test.c" 29 */ 30 #define __FILENAME__ (__builtin_strrchr( "/" __FILE__, '/') + 1) 31 32 #if defined(NDEBUG) 33 34 #define assert(__e) ((void)(__e)) 35 36 #elif CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT 37 38 #define assert(__e) (__builtin_expect(!!(__e), 1) ? (void)0 : __assert_func(NULL, 0, NULL, NULL)) 39 40 #else // !CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT 41 42 #define assert(__e) (__builtin_expect(!!(__e), 1) ? (void)0 : __assert_func (__FILENAME__, __LINE__, \ 43 __ASSERT_FUNC, #__e)) 44 #endif 45