check.{h,cpp} draft

GitOrigin-RevId: b8f5b678208ef35f4753e0f16685381ae41e11b0
This commit is contained in:
Arseny Smirnov 2019-02-12 18:45:14 +03:00
parent 911d326dba
commit 281b4ab57a
5 changed files with 41 additions and 6 deletions

View File

@ -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

View File

@ -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

17
tdutils/td/utils/check.h Normal file
View File

@ -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

View File

@ -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"

View File

@ -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