assert_only.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //-------------------------------------------------------------------------------------------------------
  2. // ChakraCore/Pal
  3. // Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
  4. // and edits (c) copyright the ChakraCore Contributors.
  5. // See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
  6. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  7. //-------------------------------------------------------------------------------------------------------
  8. // PAL free Assert definitions
  9. #ifdef DEBUG
  10. #if !defined(CHAKRACORE_STRINGIZE)
  11. #define CHAKRACORE_STRINGIZE_IMPL(x) #x
  12. #define CHAKRACORE_STRINGIZE(x) CHAKRACORE_STRINGIZE_IMPL(x)
  13. #endif
  14. #ifndef __ANDROID__
  15. #define _ERR_OUTPUT_(condition, comment) \
  16. fprintf(stderr, "ASSERTION (%s, line %d) %s %s\n", __FILE__, __LINE__, \
  17. CHAKRACORE_STRINGIZE(condition), comment); \
  18. fflush(stderr);
  19. #else // ANDROID
  20. #include <android/log.h>
  21. #define _ERR_OUTPUT_(condition, comment) \
  22. __android_log_print(ANDROID_LOG_ERROR, "chakracore-log", \
  23. "ASSERTION (%s, line %d) %s %s\n", __FILE__, __LINE__, \
  24. CHAKRACORE_STRINGIZE(condition), comment);
  25. #endif
  26. #define _Assert_(condition, comment) \
  27. do { \
  28. if (!(condition)) \
  29. { \
  30. _ERR_OUTPUT_(condition, comment) \
  31. abort(); \
  32. } \
  33. } while (0)
  34. #define Assert(condition) _Assert_(condition, "")
  35. #define AssertMsg(condition, comment) _Assert_(condition, comment)
  36. #else // ! DEBUG
  37. #define Assert(condition)
  38. #define AssertMsg(condition, comment)
  39. #endif