From 417e7105d33e1bc66cd4c48a04fee504a8cca019 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Mon, 11 Jul 2016 19:30:21 +0100 Subject: [PATCH] Import Sprout. This is to fix the build on clang. Sprout is needed because pow, log2 and log10 are constexpr on gcc, but that's nonstandard. Sprout provides the constexpr version of those functions. Also fix warnings. I still get plenty of warnings about some suggested paretheses, but it seems to be a bug from clang. See https://llvm.org/bugs/show_bug.cgi?id=21629 for the bug report. --- .gitmodules | 3 +++ CMakeLists.txt | 1 + include/helpers/lexical_cast.hpp | 12 +++++++----- lib/sprout | 1 + src/backends/redis/async_connection.cpp | 11 ++++++++--- 5 files changed, 20 insertions(+), 8 deletions(-) create mode 160000 lib/sprout diff --git a/.gitmodules b/.gitmodules index 94e1d37..1984ae6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "lib/better-enums"] path = lib/better-enums url = https://github.com/aantron/better-enums +[submodule "lib/sprout"] + path = lib/sprout + url = https://github.com/bolero-MURAKAMI/Sprout.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ef6463..2a0e6d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ target_compile_features(${PROJECT_NAME} target_include_directories(${bare_name}-inc INTERFACE ${PROJECT_BINARY_DIR} INTERFACE ${CMAKE_SOURCE_DIR}/include + INTERFACE ${CMAKE_SOURCE_DIR}/lib/sprout ) diff --git a/include/helpers/lexical_cast.hpp b/include/helpers/lexical_cast.hpp index 7417892..f5bced8 100644 --- a/include/helpers/lexical_cast.hpp +++ b/include/helpers/lexical_cast.hpp @@ -21,10 +21,12 @@ #include "compatibility.h" #include "helpers/sequence_bt.hpp" #include "helpers/MaxSizedArray.hpp" +#include "sprout/math/log10.hpp" +#include "sprout/math/log2.hpp" +#include "sprout/math/pow.hpp" #include #include #include -#include #include #include #include @@ -112,7 +114,7 @@ namespace dinhelp { static std::size_t count_digits ( T parValue ) a_pure; static typename std::make_unsigned::type make_unsigned ( T parValue ) a_pure; static constexpr std::size_t count_digits_bt (std::size_t parNum) { - return (parNum == 0 ? 0 : static_cast(std::log10(static_cast(parNum)) / std::log10(static_cast(base)))) + 1; + return (parNum == 0 ? 0 : static_cast(sprout::log10(static_cast(parNum)) / sprout::log10(static_cast(base)))) + 1; } }; } //namespace implem @@ -133,7 +135,7 @@ namespace dinhelp { static typename std::make_unsigned::type make_unsigned ( T parValue ) a_pure; static constexpr std::size_t count_digits_bt (std::size_t parNum) { - return (parNum == 0 ? 0 : static_cast(std::log10(static_cast(parNum)))) + 1 + (std::numeric_limits::is_signed ? 1 : 0); + return (parNum == 0 ? 0 : static_cast(sprout::log10(static_cast(parNum)))) + 1 + (std::numeric_limits::is_signed ? 1 : 0); } }; @@ -153,7 +155,7 @@ namespace dinhelp { static std::size_t count_digits ( T parValue ) a_pure; static typename std::make_unsigned::type make_unsigned ( T parValue ) a_pure; static constexpr std::size_t count_digits_bt (std::size_t parNum) { - return (parNum == 0 ? 0 : static_cast(std::log2(static_cast(parNum)))) + 1; + return (parNum == 0 ? 0 : static_cast(sprout::log2(static_cast(parNum)))) + 1; } }; @@ -163,7 +165,7 @@ namespace dinhelp { std::size_t dec::count_digits_implem (T parValue, dinhelp::bt::index_seq, dinhelp::bt::index_seq) { typedef typename std::make_unsigned::type UT; static constexpr UT powers[] = { 0, static_cast(dinhelp::implem::power<10, Powers + 1>::value)... }; - static constexpr std::size_t maxdigits[] = { count_digits_bt(static_cast(::pow(2.0, Digits))) - (std::numeric_limits::is_signed ? 1 : 0)... }; + static constexpr std::size_t maxdigits[] = { count_digits_bt(static_cast(sprout::pow(2.0, Digits))) - (std::numeric_limits::is_signed ? 1 : 0)... }; const auto bits = sizeof(parValue) * CHAR_BIT - dinhelp::implem::count_leading_zeroes(dinhelp::implem::abs(parValue)); static_assert(std::is_same::value, "Unexpected type"); return (dinhelp::implem::abs(parValue) < powers[maxdigits[bits] - 1] ? maxdigits[bits] - 1 : maxdigits[bits]) + dinhelp::implem::is_negative::check(parValue); diff --git a/lib/sprout b/lib/sprout new file mode 160000 index 0000000..fea5e75 --- /dev/null +++ b/lib/sprout @@ -0,0 +1 @@ +Subproject commit fea5e752bda763c27ecd6f84531cdd0b4f82399d diff --git a/src/backends/redis/async_connection.cpp b/src/backends/redis/async_connection.cpp index cf48a01..483bc3c 100644 --- a/src/backends/redis/async_connection.cpp +++ b/src/backends/redis/async_connection.cpp @@ -36,13 +36,18 @@ namespace redis { ev_break(parLoop, EVBREAK_ALL); } - void lock_mutex_libev (ev_loop* parLoop) { + void lock_mutex_libev (ev_loop* parLoop) noexcept { std::mutex* mtx = static_cast(ev_userdata(parLoop)); assert(mtx); - mtx->lock(); + try { + mtx->lock(); + } + catch (const std::system_error&) { + assert(false); + } } - void unlock_mutex_libev (ev_loop* parLoop) { + void unlock_mutex_libev (ev_loop* parLoop) noexcept { std::mutex* mtx = static_cast(ev_userdata(parLoop)); assert(mtx); mtx->unlock();