assert_only.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // PAL free Assert definitions
  6. #ifdef DEBUG
  7. #define _QUOTE_(s) #s
  8. #define _STRINGIZE_(s) _QUOTE_(s)
  9. #ifndef __ANDROID__
  10. #define _ERR_OUTPUT_(condition, comment) \
  11. fprintf(stderr, "ASSERTION (%s, line %d) %s %s\n", __FILE__, __LINE__, \
  12. _STRINGIZE_(condition), comment); \
  13. fflush(stderr);
  14. #else // ANDROID
  15. #include <android/log.h>
  16. #define _ERR_OUTPUT_(condition, comment) \
  17. __android_log_print(ANDROID_LOG_ERROR, "chakracore-log", \
  18. "ASSERTION (%s, line %d) %s %s\n", __FILE__, __LINE__, \
  19. _STRINGIZE_(condition), comment);
  20. #endif
  21. #define _Assert_(condition, comment) \
  22. do { \
  23. if (!(condition)) \
  24. { \
  25. _ERR_OUTPUT_(condition, comment) \
  26. abort(); \
  27. } \
  28. } while (0)
  29. #define Assert(condition) _Assert_(condition, "")
  30. #define AssertMsg(condition, comment) _Assert_(condition, comment)
  31. #else // ! DEBUG
  32. #define Assert(condition)
  33. #define AssertMsg(condition, comment)
  34. #endif