2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Replace t_assert() with Assert().

Also use this assertions for Expects(), Ensures() and Unexpected().
This commit is contained in:
John Preston
2017-08-17 12:06:26 +03:00
parent b3da99c302
commit 25ffaaaa2d
107 changed files with 492 additions and 435 deletions

View File

@@ -181,22 +181,22 @@ namespace {
int _ffmpegLockManager(void **mutex, AVLockOp op) {
switch (op) {
case AV_LOCK_CREATE: {
t_assert(*mutex == 0);
Assert(*mutex == 0);
*mutex = reinterpret_cast<void*>(new QMutex());
} break;
case AV_LOCK_OBTAIN: {
t_assert(*mutex != 0);
Assert(*mutex != 0);
reinterpret_cast<QMutex*>(*mutex)->lock();
} break;
case AV_LOCK_RELEASE: {
t_assert(*mutex != 0);
Assert(*mutex != 0);
reinterpret_cast<QMutex*>(*mutex)->unlock();
}; break;
case AV_LOCK_DESTROY: {
t_assert(*mutex != 0);
Assert(*mutex != 0);
delete reinterpret_cast<QMutex*>(*mutex);
*mutex = 0;
} break;
@@ -662,7 +662,7 @@ char *hashMd5Hex(const int32 *hashmd5, void *dest) {
}
void memset_rand(void *data, uint32 len) {
t_assert(_sslInited);
Assert(_sslInited);
RAND_bytes((uchar*)data, len);
}

View File

@@ -22,42 +22,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "core/basic_types.h"
// Release build assertions.
inline void t_noop() {
}
[[noreturn]] inline void t_assert_fail(const char *message, const char *file, int32 line) {
auto info = qsl("%1 %2:%3").arg(message).arg(file).arg(line);
LOG(("Assertion Failed! ") + info);
SignalHandlers::setCrashAnnotation("Assertion", info);
// Crash with access violation and generate crash report.
volatile int *t_assert_nullptr = nullptr;
*t_assert_nullptr = 0;
// Silent the possible failure to comply noreturn warning.
std::abort();
}
#define t_assert_full(condition, message, file, line) ((GSL_UNLIKELY(!(condition))) ? t_assert_fail(message, file, line) : t_noop())
#define t_assert_c(condition, comment) t_assert_full(condition, "\"" #condition "\" (" comment ")", __FILE__, __LINE__)
#define t_assert(condition) t_assert_full(condition, "\"" #condition "\"", __FILE__, __LINE__)
// Declare our own versions of Expects() and Ensures().
// Let them crash with reports and logging.
#ifdef Expects
#undef Expects
#endif // Expects
#define Expects(condition) t_assert_full(condition, "\"" #condition "\"", __FILE__, __LINE__)
#ifdef Ensures
#undef Ensures
#endif // Ensures
#define Ensures(condition) t_assert_full(condition, "\"" #condition "\"", __FILE__, __LINE__)
#ifdef Unexpected
#undef Unexpected
#endif // Unexpected
#define Unexpected(message) t_assert_fail("Unexpected: " message, __FILE__, __LINE__)
// Define specializations for QByteArray for Qt 5.3.2, because
// QByteArray in Qt 5.3.2 doesn't declare "pointer" subtype.
#ifdef OS_MAC_OLD
@@ -667,7 +631,7 @@ public:
return data();
}
T &operator*() const {
t_assert(!isNull());
Assert(!isNull());
return *data();
}
explicit operator bool() const {
@@ -710,7 +674,7 @@ public:
return data();
}
T &operator*() const {
t_assert(!isNull());
Assert(!isNull());
return *data();
}
explicit operator bool() const {