From 281b4ab57a15c591b236319b19548b59358985ed Mon Sep 17 00:00:00 2001 From: Arseny Smirnov Date: Tue, 12 Feb 2019 18:45:14 +0300 Subject: [PATCH] check.{h,cpp} draft GitOrigin-RevId: b8f5b678208ef35f4753e0f16685381ae41e11b0 --- tdutils/CMakeLists.txt | 2 ++ tdutils/td/utils/check.cpp | 15 +++++++++++++++ tdutils/td/utils/check.h | 17 +++++++++++++++++ tdutils/td/utils/common.h | 1 + tdutils/td/utils/logging.h | 12 ++++++------ 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 tdutils/td/utils/check.cpp create mode 100644 tdutils/td/utils/check.h diff --git a/tdutils/CMakeLists.txt b/tdutils/CMakeLists.txt index a933cd10..ddd8c857 100644 --- a/tdutils/CMakeLists.txt +++ b/tdutils/CMakeLists.txt @@ -69,6 +69,7 @@ set(TDUTILS_SOURCE td/utils/BigNum.cpp td/utils/buffer.cpp td/utils/BufferedUdp.cpp + td/utils/check.cpp td/utils/crypto.cpp td/utils/FileLog.cpp td/utils/filesystem.cpp @@ -144,6 +145,7 @@ set(TDUTILS_SOURCE td/utils/BufferedUdp.h td/utils/ByteFlow.h td/utils/ChangesProcessor.h + td/utils/check.h td/utils/Closure.h td/utils/common.h td/utils/Container.h diff --git a/tdutils/td/utils/check.cpp b/tdutils/td/utils/check.cpp new file mode 100644 index 00000000..bb3933f1 --- /dev/null +++ b/tdutils/td/utils/check.cpp @@ -0,0 +1,15 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#include "td/utils/check.h" +#include "td/utils/logging.h" +namespace td { +namespace detail { +void do_check(const char *message, const char *file, int line) { + LOG(FATAL) << "TODO CHECK"; +} +} // namespace detail +} // namespace td diff --git a/tdutils/td/utils/check.h b/tdutils/td/utils/check.h new file mode 100644 index 00000000..cfbe441d --- /dev/null +++ b/tdutils/td/utils/check.h @@ -0,0 +1,17 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once +#define CHECK(x) \ + if (!(x)) { \ + ::td::detail::do_check(#x, __FILE__, __LINE__); \ + } +#define DCHECK(x) CHECK(x) +namespace td { +namespace detail { +void do_check(const char *message, const char *file, int line); +} +} // namespace td diff --git a/tdutils/td/utils/common.h b/tdutils/td/utils/common.h index 58aa7dc6..90ab2276 100644 --- a/tdutils/td/utils/common.h +++ b/tdutils/td/utils/common.h @@ -42,6 +42,7 @@ #endif // clang-format on +#include "td/utils/check.h" #include "td/utils/int_types.h" #include "td/utils/unique_ptr.h" diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 70d38722..1e4b55f4 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -79,24 +79,24 @@ inline bool no_return_func() { } // clang-format off -#define DUMMY_CHECK(condition) LOG_IF(NEVER, !(condition)) +#define DUMMY_LOG_CHECK(condition) LOG_IF(NEVER, !(condition)) #ifdef TD_DEBUG #if TD_MSVC - #define CHECK(condition) \ + #define LOG_CHECK(condition) \ __analysis_assume(!!(condition)); \ LOG_IMPL(FATAL, FATAL, !(condition), #condition) #else - #define CHECK(condition) LOG_IMPL(FATAL, FATAL, !(condition) && no_return_func(), #condition) + #define LOG_CHECK(condition) LOG_IMPL(FATAL, FATAL, !(condition) && no_return_func(), #condition) #endif #else - #define CHECK DUMMY_CHECK + #define LOG_CHECK DUMMY_LOG_CHECK #endif #if NDEBUG - #define DCHECK DUMMY_CHECK + #define LOG_DCHECK DUMMY_LOG_CHECK #else - #define DCHECK CHECK + #define LOG_DCHECK LOG_CHECK #endif // clang-format on