aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorilnurkh <ilnurkh@yandex-team.com>2023-10-06 10:08:36 +0300
committerilnurkh <ilnurkh@yandex-team.com>2023-10-06 10:28:01 +0300
commite6552744f49f722981ec4ba533d430744410c1f1 (patch)
tree739d61f3ece0ea4e7493a8cfd15e1267444e4f7d
parent26ca74bbdccfa2d88aa97bf24cb05b9ee8ee3200 (diff)
downloadydb-e6552744f49f722981ec4ba533d430744410c1f1.tar.gz
aliases for checking macroses
https://clubs.at.yandex-team.ru/arcadia/29404
-rw-r--r--util/generic/string_ut.cpp4
-rw-r--r--util/generic/yexception.h14
-rw-r--r--util/system/yassert.h72
3 files changed, 40 insertions, 50 deletions
diff --git a/util/generic/string_ut.cpp b/util/generic/string_ut.cpp
index ca7b673fdb..b49e5ddb6b 100644
--- a/util/generic/string_ut.cpp
+++ b/util/generic/string_ut.cpp
@@ -279,7 +279,9 @@ protected:
void null_char_of_empty() {
const TStringType s;
- UNIT_ASSERT(s[s.size()] == 0);
+ //NOTE: https://a.yandex-team.ru/arcadia/junk/grechnik/test_string?rev=r12602052
+ i64 i = s[s.size()];
+ UNIT_ASSERT_VALUES_EQUAL(i, 0);
}
void null_char() {
diff --git a/util/generic/yexception.h b/util/generic/yexception.h
index f4a1bd6205..ee6c4ae51d 100644
--- a/util/generic/yexception.h
+++ b/util/generic/yexception.h
@@ -187,12 +187,13 @@ std::string CurrentExceptionTypeName();
TString FormatExc(const std::exception& exception);
-#define Y_ENSURE_EX(CONDITION, THROW_EXPRESSION) \
- do { \
- if (Y_UNLIKELY(!(CONDITION))) { \
- ythrow THROW_EXPRESSION; \
- } \
+#define Y_THROW_UNLESS_EX(CONDITION, THROW_EXPRESSION) \
+ do { \
+ if (Y_UNLIKELY(!(CONDITION))) { \
+ ythrow THROW_EXPRESSION; \
+ } \
} while (false)
+#define Y_ENSURE_EX Y_THROW_UNLESS_EX
/// @def Y_ENSURE_SIMPLE
/// This macro works like the Y_ENSURE, but requires the second argument to be a constant string view.
@@ -225,7 +226,8 @@ TString FormatExc(const std::exception& exception);
* }
* @endcode
*/
-#define Y_ENSURE(...) Y_PASS_VA_ARGS(Y_MACRO_IMPL_DISPATCHER_2(__VA_ARGS__, Y_ENSURE_IMPL_2, Y_ENSURE_IMPL_1)(__VA_ARGS__))
+#define Y_THROW_UNLESS(...) Y_PASS_VA_ARGS(Y_MACRO_IMPL_DISPATCHER_2(__VA_ARGS__, Y_ENSURE_IMPL_2, Y_ENSURE_IMPL_1)(__VA_ARGS__))
+#define Y_ENSURE Y_THROW_UNLESS
/**
* @def Y_ENSURE_BT
diff --git a/util/system/yassert.h b/util/system/yassert.h
index c6c8b8349b..c4510e7550 100644
--- a/util/system/yassert.h
+++ b/util/system/yassert.h
@@ -61,35 +61,15 @@ inline void YaDebugBreak() {
#undef Y_ASSERT
#if !defined(NDEBUG) && !defined(__GCCXML__)
- #define Y_ASSERT(a) \
- do { \
- try { \
- if (Y_UNLIKELY(!(a))) { \
- if (YaIsDebuggerPresent()) \
- __debugbreak(); \
- else { \
- PrintBackTrace(); \
- /* NOLINTNEXTLINE */ \
- assert(false && (a)); \
- } \
- } \
- } catch (...) { \
- if (YaIsDebuggerPresent()) \
- __debugbreak(); \
- else { \
- PrintBackTrace(); \
- /* NOLINTNEXTLINE */ \
- assert(false && "Exception during assert"); \
- } \
- } \
+ #define Y_HIT_DEBUGGER() \
+ do { \
+ if (YaIsDebuggerPresent()) { \
+ __debugbreak(); \
+ } \
} while (false)
#else
- #define Y_ASSERT(a) \
- do { \
- if (false) { \
- auto __xxx = static_cast<bool>(a); \
- Y_UNUSED(__xxx); \
- } \
+ #define Y_HIT_DEBUGGER(a) \
+ do { \
} while (false)
#endif
@@ -99,28 +79,32 @@ namespace NPrivate {
}
/// Assert that does not depend on NDEBUG macro and outputs message like printf
-#define Y_VERIFY(expr, ...) \
- do { \
- if (Y_UNLIKELY(!(expr))) { \
- ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, #expr, " " __VA_ARGS__); \
- } \
+#define Y_ABORT_UNLESS(expr, ...) \
+ do { \
+ try { \
+ if (Y_UNLIKELY(!(expr))) { \
+ Y_HIT_DEBUGGER(); \
+ ::PrintBackTrace(); \
+ /* NOLINTNEXTLINE */ \
+ ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, #expr, " " __VA_ARGS__); \
+ } \
+ } catch (...) { \
+ Y_HIT_DEBUGGER(); \
+ /* NOLINTNEXTLINE */ \
+ ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, #expr, "Exception during assert" \
+ " " __VA_ARGS__); \
+ } \
} while (false)
+#define Y_VERIFY(...) Y_ABORT_UNLESS(__VA_ARGS__)
-#define Y_FAIL(...) \
- do { \
- ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, nullptr, " " __VA_ARGS__); \
- } while (false)
+#define Y_ABORT(...) Y_ABORT_UNLESS(false, __VA_ARGS__)
+#define Y_FAIL Y_ABORT
#ifndef NDEBUG
/// Assert that depend on NDEBUG macro and outputs message like printf
- #define Y_VERIFY_DEBUG(expr, ...) \
- do { \
- if (Y_UNLIKELY(!(expr))) { \
- ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, #expr, " " __VA_ARGS__); \
- } \
- } while (false)
+ #define Y_DEBUG_ABORT_UNLESS Y_ABORT_UNLESS
#else
- #define Y_VERIFY_DEBUG(expr, ...) \
+ #define Y_DEBUG_ABORT_UNLESS(expr, ...) \
do { \
if (false) { \
bool __xxx = static_cast<bool>(expr); \
@@ -128,3 +112,5 @@ namespace NPrivate {
} \
} while (false)
#endif
+#define Y_VERIFY_DEBUG Y_DEBUG_ABORT_UNLESS
+#define Y_ASSERT(a) Y_DEBUG_ABORT_UNLESS(a)