forked from organicmaps/organicmaps
[base] Fix CHECK in fabric crashlytics
This commit is contained in:
parent
285c7f2c33
commit
059d0126fa
7 changed files with 67 additions and 37 deletions
|
@ -53,11 +53,6 @@ void AndroidLogMessage(LogLevel level, SrcPoint const & src, std::string const &
|
|||
void AndroidAssertMessage(SrcPoint const & src, std::string const & s)
|
||||
{
|
||||
AndroidMessage(LCRITICAL, src, s);
|
||||
#ifdef DEBUG
|
||||
assert(false);
|
||||
#else
|
||||
std::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
void InitSystemLog()
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "base/internal/message.hpp"
|
||||
#include "base/src_point.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
@ -14,39 +16,53 @@ namespace my
|
|||
|
||||
/// @return Pointer to previous message function.
|
||||
AssertFailedFn SetAssertFunction(AssertFailedFn fn);
|
||||
|
||||
bool AssertAbortIsEnabled();
|
||||
void SwitchAssertAbort(bool enable);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#define ABORT_ON_ASSERT() assert(false)
|
||||
#else
|
||||
#define ABORT_ON_ASSERT() std::abort()
|
||||
#endif
|
||||
|
||||
#define ON_ASSERT_FAILED(msg) \
|
||||
::my::OnAssertFailed(SRC(), msg); \
|
||||
if (::my::AssertAbortIsEnabled()) \
|
||||
ABORT_ON_ASSERT();
|
||||
|
||||
// TODO: Evaluate X only once in CHECK().
|
||||
#define CHECK(X, msg) do { if (X) {} else { \
|
||||
::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X")", ::my::impl::Message msg));} } while(false)
|
||||
ON_ASSERT_FAILED(::my::impl::Message("CHECK("#X")", ::my::impl::Message msg));} } while(false)
|
||||
#define CHECK_EQUAL(X, Y, msg) do { if ((X) == (Y)) {} else { \
|
||||
::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" == "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
ON_ASSERT_FAILED(::my::impl::Message("CHECK("#X" == "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
#define CHECK_NOT_EQUAL(X, Y, msg) do { if ((X) != (Y)) {} else { \
|
||||
::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" != "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
ON_ASSERT_FAILED(::my::impl::Message("CHECK("#X" != "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
#define CHECK_LESS(X, Y, msg) do { if ((X) < (Y)) {} else { \
|
||||
::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" < "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
ON_ASSERT_FAILED(::my::impl::Message("CHECK("#X" < "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
#define CHECK_LESS_OR_EQUAL(X, Y, msg) do { if ((X) <= (Y)) {} else { \
|
||||
::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" <= "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
ON_ASSERT_FAILED(::my::impl::Message("CHECK("#X" <= "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
#define CHECK_GREATER(X, Y, msg) do { if ((X) > (Y)) {} else { \
|
||||
::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" > "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
ON_ASSERT_FAILED(::my::impl::Message("CHECK("#X" > "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
#define CHECK_GREATER_OR_EQUAL(X, Y, msg) do { if ((X) >= (Y)) {} else { \
|
||||
::my::OnAssertFailed(SRC(), ::my::impl::Message("CHECK("#X" >= "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
ON_ASSERT_FAILED(::my::impl::Message("CHECK("#X" >= "#Y")", \
|
||||
::my::impl::Message(X, Y), \
|
||||
::my::impl::Message msg));} } while (false)
|
||||
#define CHECK_OR_CALL(fail, call, X, msg) do { if (X) {} else { \
|
||||
if (fail) {\
|
||||
::my::OnAssertFailed(SRC(), ::my::impl::Message(::my::impl::Message("CHECK("#X")"), \
|
||||
::my::impl::Message msg)); \
|
||||
ON_ASSERT_FAILED(::my::impl::Message(::my::impl::Message("CHECK("#X")"), \
|
||||
::my::impl::Message msg)); \
|
||||
} else { \
|
||||
call(); \
|
||||
} } } while (false)
|
||||
|
|
|
@ -4,10 +4,13 @@
|
|||
|
||||
#include "std/target_os.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool g_assertAbortIsEnabled = true;
|
||||
}
|
||||
|
||||
namespace my
|
||||
{
|
||||
void OnAssertFailedDefault(SrcPoint const & srcPoint, std::string const & msg)
|
||||
|
@ -15,12 +18,6 @@ namespace my
|
|||
std::cerr << "ASSERT FAILED" << std::endl
|
||||
<< srcPoint.FileName() << ":" << srcPoint.Line() << std::endl
|
||||
<< msg << std::endl;
|
||||
|
||||
#ifdef DEBUG
|
||||
assert(false);
|
||||
#else
|
||||
std::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
AssertFailedFn OnAssertFailed = &OnAssertFailedDefault;
|
||||
|
@ -30,4 +27,7 @@ namespace my
|
|||
std::swap(OnAssertFailed, fn);
|
||||
return fn;
|
||||
}
|
||||
|
||||
bool AssertAbortIsEnabled() { return g_assertAbortIsEnabled; }
|
||||
void SwitchAssertAbort(bool enable) { g_assertAbortIsEnabled = enable; }
|
||||
}
|
||||
|
|
|
@ -82,7 +82,9 @@ UNIT_TEST(RefPointerExpiringTest)
|
|||
#if defined(TRACK_POINTERS)
|
||||
|
||||
g_assertRaised = false;
|
||||
bool const assertAbortWasEnabled = my::AssertAbortIsEnabled();
|
||||
my::AssertFailedFn prevFn = my::SetAssertFunction(OnAssertRaised);
|
||||
my::SwitchAssertAbort(false);
|
||||
|
||||
drape_ptr<Tester> ptr = make_unique_dp<Tester>();
|
||||
ref_ptr<Tester> refPtr1 = make_ref(ptr);
|
||||
|
@ -90,6 +92,7 @@ UNIT_TEST(RefPointerExpiringTest)
|
|||
ptr.reset();
|
||||
|
||||
my::SetAssertFunction(prevFn);
|
||||
my::SwitchAssertAbort(assertAbortWasEnabled);
|
||||
|
||||
TEST(g_assertRaised, ());
|
||||
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
|
||||
namespace platform
|
||||
{
|
||||
void LogMessageFabric(my::LogLevel level, my::SrcPoint const & srcPoint, std::string const & msg);
|
||||
void IosLogMessage(my::LogLevel level, my::SrcPoint const & srcPoint, std::string const & msg);
|
||||
void IosAssertMessage(my::SrcPoint const & srcPoint, std::string const & msg);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
|
||||
#include "base/assert.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace platform
|
||||
{
|
||||
void LogMessageFabric(my::LogLevel level, my::SrcPoint const & srcPoint, std::string const & msg)
|
||||
void LogMessageFabric(my::LogLevel level, my::SrcPoint const & srcPoint, std::string const & msg)
|
||||
{
|
||||
std::string recordType;
|
||||
switch (level)
|
||||
|
@ -22,7 +24,19 @@ namespace platform
|
|||
std::string const srcString = recordType + DebugPrint(srcPoint) + " " + msg + "\n";
|
||||
|
||||
CLSLog(@"%@", @(srcString.c_str()));
|
||||
}
|
||||
|
||||
void IosLogMessage(my::LogLevel level, my::SrcPoint const & srcPoint, std::string const & msg)
|
||||
{
|
||||
LogMessageFabric(level, srcPoint, msg);
|
||||
my::LogMessageDefault(level, srcPoint, msg);
|
||||
}
|
||||
|
||||
void IosAssertMessage(my::SrcPoint const & srcPoint, std::string const & msg)
|
||||
{
|
||||
LogMessageFabric(my::LCRITICAL, srcPoint, msg);
|
||||
std::cerr << "ASSERT FAILED" << std::endl
|
||||
<< srcPoint.FileName() << ":" << srcPoint.Line() << std::endl
|
||||
<< msg << std::endl;
|
||||
}
|
||||
} // namespace platform
|
||||
|
|
|
@ -56,7 +56,8 @@ int main(int argc, char * argv[])
|
|||
#ifdef MWM_LOG_TO_FILE
|
||||
my::SetLogMessageFn(LogMessageFile);
|
||||
#elif OMIM_PRODUCTION
|
||||
my::SetLogMessageFn(platform::LogMessageFabric);
|
||||
my::SetLogMessageFn(platform::IosLogMessage);
|
||||
my::SetAssertFunction(platform::IosAssertMessage);
|
||||
#endif
|
||||
auto & p = GetPlatform();
|
||||
LOG(LINFO, ("maps.me started, detected CPU cores:", p.CpuCores()));
|
||||
|
|
Loading…
Add table
Reference in a new issue