check.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include "flipper.h"
  3. // Find how to how get function's pretty name
  4. #ifndef __FURI_CHECK_FUNC
  5. // Use g++'s demangled names in C++
  6. #if defined __cplusplus && defined __GNUC__
  7. #define __FURI_CHECK_FUNC __PRETTY_FUNCTION__
  8. // C99 requires the use of __func__
  9. #elif __STDC_VERSION__ >= 199901L
  10. #define __FURI_CHECK_FUNC __func__
  11. // Older versions of gcc don't have __func__ but can use __FUNCTION__
  12. #elif __GNUC__ >= 2
  13. #define __FURI_CHECK_FUNC __FUNCTION__
  14. // failed to detect __func__ support
  15. #else
  16. #define __FURI_CHECK_FUNC ((char*)0)
  17. #endif
  18. #endif
  19. // !__FURI_CHECK_FUNC
  20. // We have two levels of assertion
  21. // One - furi_check, which always runs, the only difference is in the level of debug information
  22. // The second is furi_assert, which doesn't compile in release mode
  23. #ifdef NDEBUG
  24. #define furi_check(__e) ((__e) ? (void)0 : __furi_check())
  25. #define furi_assert(__e) ((void)0)
  26. #else
  27. #define furi_check(__e) \
  28. ((__e) ? (void)0 : __furi_check_debug(__FILE__, __LINE__, __FURI_CHECK_FUNC, #__e))
  29. #define furi_assert(__e) \
  30. ((__e) ? (void)0 : __furi_check_debug(__FILE__, __LINE__, __FURI_CHECK_FUNC, #__e))
  31. #endif
  32. // !NDEBUG
  33. void __furi_check(void);
  34. void __furi_check_debug(const char* file, int line, const char* function, const char* condition);