aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/assert/assert.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/yt/assert/assert.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/yt/assert/assert.h')
-rw-r--r--library/cpp/yt/assert/assert.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/library/cpp/yt/assert/assert.h b/library/cpp/yt/assert/assert.h
new file mode 100644
index 0000000000..7a9e761a3a
--- /dev/null
+++ b/library/cpp/yt/assert/assert.h
@@ -0,0 +1,76 @@
+#pragma once
+
+#include <util/system/compiler.h>
+#include <util/system/src_root.h>
+
+#include <util/generic/strbuf.h>
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+namespace NDetail {
+
+[[noreturn]]
+void AssertTrapImpl(
+ TStringBuf trapType,
+ TStringBuf expr,
+ TStringBuf file,
+ int line,
+ TStringBuf function);
+
+} // namespace NDetail
+
+#ifdef __GNUC__
+ #define YT_BUILTIN_TRAP() __builtin_trap()
+#else
+ #define YT_BUILTIN_TRAP() std::terminate()
+#endif
+
+#define YT_ASSERT_TRAP(trapType, expr) \
+ ::NYT::NDetail::AssertTrapImpl(TStringBuf(trapType), TStringBuf(expr), __SOURCE_FILE_IMPL__.As<TStringBuf>(), __LINE__, TStringBuf(__FUNCTION__)); \
+ Y_UNREACHABLE() \
+
+#ifdef NDEBUG
+ #define YT_ASSERT(expr) \
+ do { \
+ if (false) { \
+ (void) (expr); \
+ } \
+ } while (false)
+#else
+ #define YT_ASSERT(expr) \
+ do { \
+ if (Y_UNLIKELY(!(expr))) { \
+ YT_ASSERT_TRAP("YT_ASSERT", #expr); \
+ } \
+ } while (false)
+#endif
+
+//! Same as |YT_ASSERT| but evaluates and checks the expression in both release and debug mode.
+#define YT_VERIFY(expr) \
+ do { \
+ if (Y_UNLIKELY(!(expr))) { \
+ YT_ASSERT_TRAP("YT_VERIFY", #expr); \
+ } \
+ } while (false)
+
+//! Fatal error code marker. Abnormally terminates the current process.
+#ifdef YT_COMPILING_UDF
+ #define YT_ABORT() __YT_BUILTIN_ABORT()
+#else
+ #define YT_ABORT() \
+ do { \
+ YT_ASSERT_TRAP("YT_ABORT", ""); \
+ } while (false)
+#endif
+
+//! Unimplemented code marker. Abnormally terminates the current process.
+#define YT_UNIMPLEMENTED() \
+ do { \
+ YT_ASSERT_TRAP("YT_UNIMPLEMENTED", ""); \
+ } while (false)
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT