2022-06-17 10:59:56 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2017-07-12 00:57:44 -04:00
|
|
|
|
|
|
|
/* This header file wraps newlib's own unmodified assert.h and adds
|
|
|
|
support for silent assertion failure.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <sdkconfig.h>
|
|
|
|
#include <stdlib.h>
|
2021-05-26 09:18:57 -04:00
|
|
|
#include <stdint.h>
|
2017-07-12 00:57:44 -04:00
|
|
|
|
|
|
|
#include_next <assert.h>
|
|
|
|
|
2021-02-11 23:14:03 -05:00
|
|
|
/* moved part of libc provided assert to here allows
|
|
|
|
* tweaking the assert macro to use __builtin_expect()
|
|
|
|
* and reduce jumps in the "asserts OK" code path
|
|
|
|
*
|
|
|
|
* Note: using __builtin_expect() not likely() to avoid defining the likely
|
|
|
|
* macro in namespace of non-IDF code that may include this standard header.
|
|
|
|
*/
|
|
|
|
#undef assert
|
|
|
|
|
2021-05-26 09:18:57 -04:00
|
|
|
/* __FILENAME__ points to the file name instead of path + filename
|
|
|
|
* e.g __FILE__ points to "/apps/test.c" where as __FILENAME__ points to "test.c"
|
|
|
|
*/
|
|
|
|
#define __FILENAME__ (__builtin_strrchr( "/" __FILE__, '/') + 1)
|
|
|
|
|
2021-02-11 23:14:03 -05:00
|
|
|
#if defined(NDEBUG)
|
|
|
|
|
2021-05-26 09:18:57 -04:00
|
|
|
#define assert(__e) ((void)(__e))
|
2021-02-11 23:14:03 -05:00
|
|
|
|
|
|
|
#elif CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT
|
|
|
|
|
2021-05-26 09:18:57 -04:00
|
|
|
#define assert(__e) (__builtin_expect(!!(__e), 1) ? (void)0 : __assert_func(NULL, 0, NULL, NULL))
|
2021-02-11 23:14:03 -05:00
|
|
|
|
|
|
|
#else // !CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT
|
|
|
|
|
2021-05-26 09:18:57 -04:00
|
|
|
#define assert(__e) (__builtin_expect(!!(__e), 1) ? (void)0 : __assert_func (__FILENAME__, __LINE__, \
|
2021-02-11 23:14:03 -05:00
|
|
|
__ASSERT_FUNC, #__e))
|
2017-07-12 00:57:44 -04:00
|
|
|
#endif
|