From ed934b50fbe0b2729670f42d19cb5fc745cd177e Mon Sep 17 00:00:00 2001 From: Odysseas Georgoudis Date: Mon, 20 Nov 2023 01:42:52 +0000 Subject: [PATCH] fix macos build when exceptions disabled --- CHANGELOG.md | 1 + benchmarks/hot_path_latency/hot_path_bench.h | 2 ++ quill/include/quill/QuillError.h | 14 +++++++++++++- quill/include/quill/detail/misc/Common.h | 20 ++++---------------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 133f525b..cf8b110a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ - Reduce backend worker unnecessary allocation. ([#368](https://github.com/odygrd/quill/issues/368)) - Adjusted handling for empty `std::string_view` instances, addressing an issue where logging empty strings triggered an unintended `memcpy` with zero size and a nullptr, leading to address sanitizer warnings. +- Fix build error on macOS when using '-DQUILL_NO_EXCEPTIONS:BOOL=ON'. ([#357](https://github.com/odygrd/quill/issues/357)) ## v3.4.0 diff --git a/benchmarks/hot_path_latency/hot_path_bench.h b/benchmarks/hot_path_latency/hot_path_bench.h index 730a08de..cc3b1de1 100644 --- a/benchmarks/hot_path_latency/hot_path_bench.h +++ b/benchmarks/hot_path_latency/hot_path_bench.h @@ -18,6 +18,8 @@ #include #include +#include + // Instead of sleep inline void wait(std::chrono::nanoseconds min, std::chrono::nanoseconds max) { diff --git a/quill/include/quill/QuillError.h b/quill/include/quill/QuillError.h index be6c3a17..6e7d8a7f 100644 --- a/quill/include/quill/QuillError.h +++ b/quill/include/quill/QuillError.h @@ -8,10 +8,22 @@ #include "quill/TweakMe.h" #include "quill/detail/misc/Attributes.h" -#include "quill/detail/misc/Common.h" #include #include +/** + * Require check + */ +#define QUILL_REQUIRE(expression, error) \ + do \ + { \ + if (QUILL_UNLIKELY(!(expression))) \ + { \ + printf("Quill fatal error: %s (%s:%d)\n", error, __FILE__, __LINE__); \ + std::abort(); \ + } \ + } while (0) + #if defined(QUILL_NO_EXCEPTIONS) #define QUILL_TRY if (true) #define QUILL_THROW(ex) QUILL_REQUIRE(false, ex.what()) diff --git a/quill/include/quill/detail/misc/Common.h b/quill/include/quill/detail/misc/Common.h index 676073df..001fe1d7 100644 --- a/quill/include/quill/detail/misc/Common.h +++ b/quill/include/quill/detail/misc/Common.h @@ -7,8 +7,9 @@ #include "quill/TweakMe.h" -#include "quill/detail/misc/Attributes.h" #include "quill/Fmt.h" +#include "quill/QuillError.h" +#include "quill/detail/misc/Attributes.h" #include #include #include @@ -76,19 +77,6 @@ enum class QueueType #define QUILL_UNLIKELY(x) (x) #endif -/** - * Require check - */ -#define QUILL_REQUIRE(expression, error) \ - do \ - { \ - if (QUILL_UNLIKELY(!(expression))) \ - { \ - printf("Quill fatal error: %s (%s:%d)\n", error, __FILE__, __LINE__); \ - std::abort(); \ - } \ - } while (0) - namespace quill { namespace detail @@ -191,8 +179,8 @@ constexpr bool check_printf_format_string(S format_str) if (num_specifiers > sizeof...(Args)) { - throw std::runtime_error{ - "Invalid printf format: format string does not match number of arguments"}; + QUILL_THROW( + QuillError{"Invalid printf format: format string does not match number of arguments"}); } return true;