You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

log.h 5.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * Copyright 2021 Huawei Technologies Co., Ltd
  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. #ifndef MINDSPORE_LITE_MICRO_CODER_LOG_H_
  17. #define MINDSPORE_LITE_MICRO_CODER_LOG_H_
  18. #include "src/common/log_adapter.h"
  19. #include "include/errorcode.h"
  20. #define MS_CHECK_PTR(ptr) \
  21. do { \
  22. if ((ptr) == nullptr) { \
  23. MS_LOG(ERROR) << ": The pointer[" << #ptr << "] is null."; \
  24. return mindspore::lite::RET_ERROR; \
  25. } \
  26. } while (0)
  27. #define MS_CHECK_PTR_WITH_EXE(ptr, FUNC) \
  28. do { \
  29. if ((ptr) == nullptr) { \
  30. MS_LOG(ERROR) << ": The pointer[" << #ptr << "] is null."; \
  31. FUNC; \
  32. return mindspore::lite::RET_ERROR; \
  33. } \
  34. } while (0)
  35. #define MS_CHECK_PTR_RET_NULL(ptr) \
  36. do { \
  37. if ((ptr) == nullptr) { \
  38. MS_LOG(ERROR) << ": The pointer[" << #ptr << "] is null."; \
  39. return nullptr; \
  40. } \
  41. } while (0)
  42. #define MS_CHECK_PTR_IF_NULL(ptr) \
  43. do { \
  44. if ((ptr) == nullptr) { \
  45. MS_LOG(ERROR) << ": The pointer[" << #ptr << "] is null."; \
  46. return; \
  47. } \
  48. } while (0)
  49. #define MS_CHECK_RET_CODE(code, msg) \
  50. do { \
  51. if ((code) != RET_OK) { \
  52. MS_LOG(ERROR) << msg; \
  53. return mindspore::lite::RET_ERROR; \
  54. } \
  55. } while (0)
  56. #define MS_CHECK_RET_CODE_WITH_EXE(code, msg, FUNC) \
  57. do { \
  58. if ((code) != RET_OK) { \
  59. MS_LOG(ERROR) << msg; \
  60. FUNC; \
  61. return mindspore::lite::RET_ERROR; \
  62. } \
  63. } while (0)
  64. #define MS_CHECK_RET_CODE_RET_NULL(code, msg) \
  65. do { \
  66. if ((code) != RET_OK) { \
  67. MS_LOG(ERROR) << msg; \
  68. return nullptr; \
  69. } \
  70. } while (0)
  71. #define MS_CHECK_TRUE(code, msg) \
  72. do { \
  73. if (!(code)) { \
  74. MS_LOG(ERROR) << msg; \
  75. return mindspore::lite::RET_ERROR; \
  76. } \
  77. } while (0)
  78. #define MS_CHECK_TRUE_WITH_EXE(code, msg, FUNC) \
  79. do { \
  80. if (!(code)) { \
  81. MS_LOG(ERROR) << msg; \
  82. FUNC; \
  83. return mindspore::lite::RET_ERROR; \
  84. } \
  85. } while (0)
  86. #define MS_CHECK_TRUE_WITHOUT_RET(code, msg) \
  87. do { \
  88. if (!(code)) { \
  89. MS_LOG(ERROR) << msg; \
  90. return; \
  91. } \
  92. } while (0)
  93. #define MS_CHECK_TRUE_RET_NULL(code, msg) \
  94. do { \
  95. if (!(code)) { \
  96. MS_LOG(ERROR) << msg; \
  97. return nullptr; \
  98. } \
  99. } while (0)
  100. #define MS_CHECK_TRUE_RET_BOOL(code, msg) \
  101. do { \
  102. if (!(code)) { \
  103. MS_LOG(ERROR) << msg; \
  104. return false; \
  105. } \
  106. } while (0)
  107. #endif // MINDSPORE_LITE_MICRO_CODER_LOG_H_