From ea3407d1ec6a2800353896fac481023dbc3f4854 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 4 Sep 2018 17:19:44 +0300 Subject: [PATCH] Explicit check that only little endian architectures are supported. --- coding/endianness.hpp | 11 +++++++++++ generator/generator_tool/generator_tool.cpp | 3 +++ map/framework.cpp | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/coding/endianness.hpp b/coding/endianness.hpp index 103f6fa04b..2f0329d594 100644 --- a/coding/endianness.hpp +++ b/coding/endianness.hpp @@ -8,6 +8,10 @@ // #define ENDIAN_IS_BIG +// @TODO(bykoianko) This method returns false since 05.12.2010. That means only little endian +// architecture is supported. Now checks are added to generator and to app that only +// little endian architecture is supported. All the usage of IsBigEndian(), ReverseByteOrder() +// and SwapIfBigEndian() should be removed. inline bool IsBigEndian() { #ifdef ENDIAN_IS_BIG @@ -37,3 +41,10 @@ template inline T SwapIfBigEndian(T t) return t; #endif } + +inline bool IsLittleEndian() +{ + uint16_t const word = 0x0001; + char const * const b = reinterpret_cast(&word); + return b[0] == 0x1; +} diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index b2cc1a56c5..3ee4b2642b 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -43,6 +43,7 @@ #include "platform/platform.hpp" +#include "coding/endianness.hpp" #include "coding/file_name_utils.hpp" #include "coding/transliteration.hpp" @@ -167,6 +168,8 @@ using namespace generator; int main(int argc, char ** argv) { + CHECK(IsLittleEndian(), ("Only little endian architecture is supported.")); + google::SetUsageMessage( "Takes OSM XML data from stdin and creates data and index files in several passes."); diff --git a/map/framework.cpp b/map/framework.cpp index f91091f029..7e2bf8345f 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -72,6 +72,7 @@ #include "platform/settings.hpp" #include "platform/socket.hpp" +#include "coding/endianness.hpp" #include "coding/file_name_utils.hpp" #include "coding/multilang_utf8_string.hpp" #include "coding/transliteration.hpp" @@ -391,6 +392,10 @@ Framework::Framework(FrameworkParams const & params) , m_purchase(std::make_unique()) , m_tipsApi(static_cast(*this)) { + CHECK(IsLittleEndian(), ("Only little endian architecture is supported.")); + + m_startBackgroundTime = my::Timer::LocalTime(); + // Editor should be initialized from the main thread to set its ThreadChecker. // However, search calls editor upon initialization thus setting the lazy editor's ThreadChecker // to a wrong thread. So editor should be initialiazed before serach.