absl_check.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright 2022 The Abseil Authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // -----------------------------------------------------------------------------
  16. // File: log/absl_check.h
  17. // -----------------------------------------------------------------------------
  18. //
  19. // This header declares a family of `ABSL_CHECK` macros as alternative spellings
  20. // for `CHECK` macros in `check.h`.
  21. //
  22. // Except for those whose names begin with `ABSL_DCHECK`, these macros are not
  23. // controlled by `NDEBUG` (cf. `assert`), so the check will be executed
  24. // regardless of compilation mode. `ABSL_CHECK` and friends are thus useful for
  25. // confirming invariants in situations where continuing to run would be worse
  26. // than terminating, e.g., due to risk of data corruption or security
  27. // compromise. It is also more robust and portable to deliberately terminate
  28. // at a particular place with a useful message and backtrace than to assume some
  29. // ultimately unspecified and unreliable crashing behavior (such as a
  30. // "segmentation fault").
  31. //
  32. // For full documentation of each macro, see comments in `check.h`, which has an
  33. // identical set of macros without the ABSL_* prefix.
  34. #ifndef ABSL_LOG_ABSL_CHECK_H_
  35. #define ABSL_LOG_ABSL_CHECK_H_
  36. #include "absl/log/internal/check_impl.h"
  37. #define ABSL_CHECK(condition) \
  38. ABSL_LOG_INTERNAL_CHECK_IMPL((condition), #condition)
  39. #define ABSL_QCHECK(condition) \
  40. ABSL_LOG_INTERNAL_QCHECK_IMPL((condition), #condition)
  41. #define ABSL_PCHECK(condition) \
  42. ABSL_LOG_INTERNAL_PCHECK_IMPL((condition), #condition)
  43. #define ABSL_DCHECK(condition) \
  44. ABSL_LOG_INTERNAL_DCHECK_IMPL((condition), #condition)
  45. #define ABSL_CHECK_EQ(val1, val2) \
  46. ABSL_LOG_INTERNAL_CHECK_EQ_IMPL((val1), #val1, (val2), #val2)
  47. #define ABSL_CHECK_NE(val1, val2) \
  48. ABSL_LOG_INTERNAL_CHECK_NE_IMPL((val1), #val1, (val2), #val2)
  49. #define ABSL_CHECK_LE(val1, val2) \
  50. ABSL_LOG_INTERNAL_CHECK_LE_IMPL((val1), #val1, (val2), #val2)
  51. #define ABSL_CHECK_LT(val1, val2) \
  52. ABSL_LOG_INTERNAL_CHECK_LT_IMPL((val1), #val1, (val2), #val2)
  53. #define ABSL_CHECK_GE(val1, val2) \
  54. ABSL_LOG_INTERNAL_CHECK_GE_IMPL((val1), #val1, (val2), #val2)
  55. #define ABSL_CHECK_GT(val1, val2) \
  56. ABSL_LOG_INTERNAL_CHECK_GT_IMPL((val1), #val1, (val2), #val2)
  57. #define ABSL_QCHECK_EQ(val1, val2) \
  58. ABSL_LOG_INTERNAL_QCHECK_EQ_IMPL((val1), #val1, (val2), #val2)
  59. #define ABSL_QCHECK_NE(val1, val2) \
  60. ABSL_LOG_INTERNAL_QCHECK_NE_IMPL((val1), #val1, (val2), #val2)
  61. #define ABSL_QCHECK_LE(val1, val2) \
  62. ABSL_LOG_INTERNAL_QCHECK_LE_IMPL((val1), #val1, (val2), #val2)
  63. #define ABSL_QCHECK_LT(val1, val2) \
  64. ABSL_LOG_INTERNAL_QCHECK_LT_IMPL((val1), #val1, (val2), #val2)
  65. #define ABSL_QCHECK_GE(val1, val2) \
  66. ABSL_LOG_INTERNAL_QCHECK_GE_IMPL((val1), #val1, (val2), #val2)
  67. #define ABSL_QCHECK_GT(val1, val2) \
  68. ABSL_LOG_INTERNAL_QCHECK_GT_IMPL((val1), #val1, (val2), #val2)
  69. #define ABSL_DCHECK_EQ(val1, val2) \
  70. ABSL_LOG_INTERNAL_DCHECK_EQ_IMPL((val1), #val1, (val2), #val2)
  71. #define ABSL_DCHECK_NE(val1, val2) \
  72. ABSL_LOG_INTERNAL_DCHECK_NE_IMPL((val1), #val1, (val2), #val2)
  73. #define ABSL_DCHECK_LE(val1, val2) \
  74. ABSL_LOG_INTERNAL_DCHECK_LE_IMPL((val1), #val1, (val2), #val2)
  75. #define ABSL_DCHECK_LT(val1, val2) \
  76. ABSL_LOG_INTERNAL_DCHECK_LT_IMPL((val1), #val1, (val2), #val2)
  77. #define ABSL_DCHECK_GE(val1, val2) \
  78. ABSL_LOG_INTERNAL_DCHECK_GE_IMPL((val1), #val1, (val2), #val2)
  79. #define ABSL_DCHECK_GT(val1, val2) \
  80. ABSL_LOG_INTERNAL_DCHECK_GT_IMPL((val1), #val1, (val2), #val2)
  81. #define ABSL_CHECK_OK(status) ABSL_LOG_INTERNAL_CHECK_OK_IMPL((status), #status)
  82. #define ABSL_QCHECK_OK(status) \
  83. ABSL_LOG_INTERNAL_QCHECK_OK_IMPL((status), #status)
  84. #define ABSL_DCHECK_OK(status) \
  85. ABSL_LOG_INTERNAL_DCHECK_OK_IMPL((status), #status)
  86. #define ABSL_CHECK_STREQ(s1, s2) \
  87. ABSL_LOG_INTERNAL_CHECK_STREQ_IMPL((s1), #s1, (s2), #s2)
  88. #define ABSL_CHECK_STRNE(s1, s2) \
  89. ABSL_LOG_INTERNAL_CHECK_STRNE_IMPL((s1), #s1, (s2), #s2)
  90. #define ABSL_CHECK_STRCASEEQ(s1, s2) \
  91. ABSL_LOG_INTERNAL_CHECK_STRCASEEQ_IMPL((s1), #s1, (s2), #s2)
  92. #define ABSL_CHECK_STRCASENE(s1, s2) \
  93. ABSL_LOG_INTERNAL_CHECK_STRCASENE_IMPL((s1), #s1, (s2), #s2)
  94. #define ABSL_QCHECK_STREQ(s1, s2) \
  95. ABSL_LOG_INTERNAL_QCHECK_STREQ_IMPL((s1), #s1, (s2), #s2)
  96. #define ABSL_QCHECK_STRNE(s1, s2) \
  97. ABSL_LOG_INTERNAL_QCHECK_STRNE_IMPL((s1), #s1, (s2), #s2)
  98. #define ABSL_QCHECK_STRCASEEQ(s1, s2) \
  99. ABSL_LOG_INTERNAL_QCHECK_STRCASEEQ_IMPL((s1), #s1, (s2), #s2)
  100. #define ABSL_QCHECK_STRCASENE(s1, s2) \
  101. ABSL_LOG_INTERNAL_QCHECK_STRCASENE_IMPL((s1), #s1, (s2), #s2)
  102. #define ABSL_DCHECK_STREQ(s1, s2) \
  103. ABSL_LOG_INTERNAL_DCHECK_STREQ_IMPL((s1), #s1, (s2), #s2)
  104. #define ABSL_DCHECK_STRNE(s1, s2) \
  105. ABSL_LOG_INTERNAL_DCHECK_STRNE_IMPL((s1), #s1, (s2), #s2)
  106. #define ABSL_DCHECK_STRCASEEQ(s1, s2) \
  107. ABSL_LOG_INTERNAL_DCHECK_STRCASEEQ_IMPL((s1), #s1, (s2), #s2)
  108. #define ABSL_DCHECK_STRCASENE(s1, s2) \
  109. ABSL_LOG_INTERNAL_DCHECK_STRCASENE_IMPL((s1), #s1, (s2), #s2)
  110. #endif // ABSL_LOG_ABSL_CHECK_H_