bh_assert.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "bh_platform.h"
  17. #include "bh_assert.h"
  18. #include <stdarg.h>
  19. #ifdef BH_TEST
  20. #include <setjmp.h>
  21. #endif
  22. #ifdef BH_TEST
  23. /* for exception throwing */
  24. jmp_buf bh_test_jb;
  25. #endif
  26. void bh_assert_internal(int v, const char *file_name, int line_number,
  27. const char *expr_string)
  28. {
  29. if (v)
  30. return;
  31. if (!file_name)
  32. file_name = "NULL FILENAME";
  33. if (!expr_string)
  34. expr_string = "NULL EXPR_STRING";
  35. printf("\nASSERTION FAILED: %s, at FILE=%s, LINE=%d\n", expr_string,
  36. file_name, line_number);
  37. #ifdef BH_TEST
  38. longjmp(bh_test_jb, 1);
  39. #endif
  40. abort();
  41. }
  42. void bh_debug_internal(const char *file_name, int line_number, const char *fmt,
  43. ...)
  44. {
  45. #ifndef JEFF_TEST_VERIFIER
  46. va_list args;
  47. va_start(args, fmt);
  48. bh_assert(file_name);
  49. printf("\nDebug info FILE=%s, LINE=%d: ", file_name, line_number);
  50. vprintf(fmt, args);
  51. va_end(args);
  52. printf("\n");
  53. #endif
  54. }