From c432fdd987b727f6a427b5609fc9714ecf9c8533 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 12 Feb 2022 13:20:15 +0200 Subject: [PATCH] Bump fmt to version 8.1.1 and run clang-format --- example/example.cpp | 13 +- include/spdlog/async.h | 6 +- include/spdlog/common.h | 2 +- include/spdlog/details/file_helper-inl.h | 2 +- include/spdlog/details/thread_pool-inl.h | 6 +- include/spdlog/fmt/bin_to_hex.h | 9 +- include/spdlog/pattern_formatter.h | 4 +- include/spdlog/sinks/rotating_file_sink-inl.h | 4 +- src/fmt.cpp | 137 ++++++++---------- tests/test_file_helper.cpp | 17 +-- tests/test_macros.cpp | 3 +- 11 files changed, 94 insertions(+), 109 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index c1251b1b..f8ad03c1 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -199,8 +199,8 @@ void vector_example() spdlog::info("Vector example: {}", vec); } -#else -void vector_example() {} +#else +void vector_example() {} #endif // ! DSPDLOG_USE_STD_FORMAT @@ -258,7 +258,8 @@ void multi_sink_example() struct my_type { int i = 0; - explicit my_type(int i): i(i){}; + explicit my_type(int i) + : i(i){}; }; namespace fmt_lib = spdlog::fmt_lib; @@ -266,7 +267,7 @@ template<> struct fmt_lib::formatter : fmt_lib::formatter { auto format(my_type my, format_context &ctx) -> decltype(ctx.out()) - { + { return fmt_lib::format_to(ctx.out(), "[my_type i={}]", my.i); } }; @@ -359,9 +360,9 @@ void replace_default_logger_example() auto new_logger = spdlog::basic_logger_mt("new_default_logger", "logs/new-default-log.txt", true); spdlog::set_default_logger(new_logger); - spdlog::set_level(spdlog::level::info); + spdlog::set_level(spdlog::level::info); spdlog::debug("This message should not be displayed!"); - spdlog::set_level(spdlog::level::trace); + spdlog::set_level(spdlog::level::trace); spdlog::debug("This message should be displayed.."); spdlog::set_default_logger(old_logger); diff --git a/include/spdlog/async.h b/include/spdlog/async.h index 281af697..d6e21349 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -73,7 +73,8 @@ inline std::shared_ptr create_async_nb(std::string logger_name, } // set global thread pool. -inline void init_thread_pool(size_t q_size, size_t thread_count, std::function on_thread_start, std::function on_thread_stop) +inline void init_thread_pool( + size_t q_size, size_t thread_count, std::function on_thread_start, std::function on_thread_stop) { auto tp = std::make_shared(q_size, thread_count, on_thread_start, on_thread_stop); details::registry::instance().set_tp(std::move(tp)); @@ -86,7 +87,8 @@ inline void init_thread_pool(size_t q_size, size_t thread_count, std::function using enable_if_t = typename std::enable_if::type; template -std::unique_ptr make_unique(Args &&...args) +std::unique_ptr make_unique(Args &&... args) { static_assert(!std::is_array::value, "arrays not supported"); return std::unique_ptr(new T(std::forward(args)...)); diff --git a/include/spdlog/details/file_helper-inl.h b/include/spdlog/details/file_helper-inl.h index fa082253..d4528711 100644 --- a/include/spdlog/details/file_helper-inl.h +++ b/include/spdlog/details/file_helper-inl.h @@ -84,7 +84,7 @@ SPDLOG_INLINE void file_helper::reopen(bool truncate) SPDLOG_INLINE void file_helper::flush() { - if(std::fflush(fd_) != 0) + if (std::fflush(fd_) != 0) { throw_spdlog_ex("Failed flush to file " + os::filename_to_str(filename_), errno); } diff --git a/include/spdlog/details/thread_pool-inl.h b/include/spdlog/details/thread_pool-inl.h index c99af52d..e4b3e1c4 100644 --- a/include/spdlog/details/thread_pool-inl.h +++ b/include/spdlog/details/thread_pool-inl.h @@ -13,7 +13,8 @@ namespace spdlog { namespace details { -SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std::function on_thread_start, std::function on_thread_stop) +SPDLOG_INLINE thread_pool::thread_pool( + size_t q_max_items, size_t threads_n, std::function on_thread_start, std::function on_thread_stop) : q_(q_max_items) { if (threads_n == 0 || threads_n > 1000) @@ -36,7 +37,8 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std {} SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n) - : thread_pool(q_max_items, threads_n, [] {}, [] {}) + : thread_pool( + q_max_items, threads_n, [] {}, [] {}) {} // message all threads to terminate gracefully join them diff --git a/include/spdlog/fmt/bin_to_hex.h b/include/spdlog/fmt/bin_to_hex.h index 76dcb836..93e5c28b 100644 --- a/include/spdlog/fmt/bin_to_hex.h +++ b/include/spdlog/fmt/bin_to_hex.h @@ -9,11 +9,11 @@ #include #if defined(__has_include) && __has_include() -#include +# include #endif #if __cpp_lib_span >= 202002L -#include +# include #endif // @@ -78,8 +78,9 @@ inline details::dump_info to_hex(const Conta #if __cpp_lib_span >= 202002L -template -inline details::dump_info::iterator> to_hex(const std::span &container, size_t size_per_line = 32) +template +inline details::dump_info::iterator> to_hex( + const std::span &container, size_t size_per_line = 32) { using Container = std::span; static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1"); diff --git a/include/spdlog/pattern_formatter.h b/include/spdlog/pattern_formatter.h index df046f67..8bcf8e2a 100644 --- a/include/spdlog/pattern_formatter.h +++ b/include/spdlog/pattern_formatter.h @@ -68,7 +68,7 @@ class SPDLOG_API custom_flag_formatter : public details::flag_formatter public: virtual std::unique_ptr clone() const = 0; - void set_padding_info(const details::padding_info& padding) + void set_padding_info(const details::padding_info &padding) { flag_formatter::padinfo_ = padding; } @@ -80,7 +80,7 @@ public: using custom_flags = std::unordered_map>; explicit pattern_formatter(std::string pattern, pattern_time_type time_type = pattern_time_type::local, - std::string eol = spdlog::details::os::default_eol, custom_flags custom_user_flags = custom_flags()); + std::string eol = spdlog::details::os::default_eol, custom_flags custom_user_flags = custom_flags()); // use default pattern is not given explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol); diff --git a/include/spdlog/sinks/rotating_file_sink-inl.h b/include/spdlog/sinks/rotating_file_sink-inl.h index 050a3e6c..4cb5f9fa 100644 --- a/include/spdlog/sinks/rotating_file_sink-inl.h +++ b/include/spdlog/sinks/rotating_file_sink-inl.h @@ -31,7 +31,7 @@ SPDLOG_INLINE rotating_file_sink::rotating_file_sink( , max_files_(max_files) , file_helper_{event_handlers} { - if(max_size == 0) + if (max_size == 0) { throw_spdlog_ex("rotating sink constructor: max_size arg cannot be zero"); } @@ -79,7 +79,7 @@ SPDLOG_INLINE void rotating_file_sink::sink_it_(const details::log_msg &m if (new_size > max_size_) { file_helper_.flush(); - if(file_helper_.size() > 0) + if (file_helper_.size() > 0) { rotate_(); new_size = formatted.size(); diff --git a/src/fmt.cpp b/src/fmt.cpp index 647189ba..8caa18d9 100644 --- a/src/fmt.cpp +++ b/src/fmt.cpp @@ -13,117 +13,98 @@ FMT_BEGIN_NAMESPACE namespace detail { // DEPRECATED! -template struct basic_data { - FMT_API static constexpr const char digits[100][2] = { - {'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'}, {'0', '5'}, - {'0', '6'}, {'0', '7'}, {'0', '8'}, {'0', '9'}, {'1', '0'}, {'1', '1'}, - {'1', '2'}, {'1', '3'}, {'1', '4'}, {'1', '5'}, {'1', '6'}, {'1', '7'}, - {'1', '8'}, {'1', '9'}, {'2', '0'}, {'2', '1'}, {'2', '2'}, {'2', '3'}, - {'2', '4'}, {'2', '5'}, {'2', '6'}, {'2', '7'}, {'2', '8'}, {'2', '9'}, - {'3', '0'}, {'3', '1'}, {'3', '2'}, {'3', '3'}, {'3', '4'}, {'3', '5'}, - {'3', '6'}, {'3', '7'}, {'3', '8'}, {'3', '9'}, {'4', '0'}, {'4', '1'}, - {'4', '2'}, {'4', '3'}, {'4', '4'}, {'4', '5'}, {'4', '6'}, {'4', '7'}, - {'4', '8'}, {'4', '9'}, {'5', '0'}, {'5', '1'}, {'5', '2'}, {'5', '3'}, - {'5', '4'}, {'5', '5'}, {'5', '6'}, {'5', '7'}, {'5', '8'}, {'5', '9'}, - {'6', '0'}, {'6', '1'}, {'6', '2'}, {'6', '3'}, {'6', '4'}, {'6', '5'}, - {'6', '6'}, {'6', '7'}, {'6', '8'}, {'6', '9'}, {'7', '0'}, {'7', '1'}, - {'7', '2'}, {'7', '3'}, {'7', '4'}, {'7', '5'}, {'7', '6'}, {'7', '7'}, - {'7', '8'}, {'7', '9'}, {'8', '0'}, {'8', '1'}, {'8', '2'}, {'8', '3'}, - {'8', '4'}, {'8', '5'}, {'8', '6'}, {'8', '7'}, {'8', '8'}, {'8', '9'}, - {'9', '0'}, {'9', '1'}, {'9', '2'}, {'9', '3'}, {'9', '4'}, {'9', '5'}, - {'9', '6'}, {'9', '7'}, {'9', '8'}, {'9', '9'}}; - FMT_API static constexpr const char hex_digits[] = "0123456789abcdef"; - FMT_API static constexpr const char signs[4] = {0, '-', '+', ' '}; - FMT_API static constexpr const char left_padding_shifts[5] = {31, 31, 0, 1, - 0}; - FMT_API static constexpr const char right_padding_shifts[5] = {0, 31, 0, 1, - 0}; - FMT_API static constexpr const unsigned prefixes[4] = {0, 0, 0x1000000u | '+', - 0x1000000u | ' '}; +template +struct basic_data +{ + FMT_API static constexpr const char digits[100][2] = {{'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'}, {'0', '5'}, + {'0', '6'}, {'0', '7'}, {'0', '8'}, {'0', '9'}, {'1', '0'}, {'1', '1'}, {'1', '2'}, {'1', '3'}, {'1', '4'}, {'1', '5'}, {'1', '6'}, + {'1', '7'}, {'1', '8'}, {'1', '9'}, {'2', '0'}, {'2', '1'}, {'2', '2'}, {'2', '3'}, {'2', '4'}, {'2', '5'}, {'2', '6'}, {'2', '7'}, + {'2', '8'}, {'2', '9'}, {'3', '0'}, {'3', '1'}, {'3', '2'}, {'3', '3'}, {'3', '4'}, {'3', '5'}, {'3', '6'}, {'3', '7'}, {'3', '8'}, + {'3', '9'}, {'4', '0'}, {'4', '1'}, {'4', '2'}, {'4', '3'}, {'4', '4'}, {'4', '5'}, {'4', '6'}, {'4', '7'}, {'4', '8'}, {'4', '9'}, + {'5', '0'}, {'5', '1'}, {'5', '2'}, {'5', '3'}, {'5', '4'}, {'5', '5'}, {'5', '6'}, {'5', '7'}, {'5', '8'}, {'5', '9'}, {'6', '0'}, + {'6', '1'}, {'6', '2'}, {'6', '3'}, {'6', '4'}, {'6', '5'}, {'6', '6'}, {'6', '7'}, {'6', '8'}, {'6', '9'}, {'7', '0'}, {'7', '1'}, + {'7', '2'}, {'7', '3'}, {'7', '4'}, {'7', '5'}, {'7', '6'}, {'7', '7'}, {'7', '8'}, {'7', '9'}, {'8', '0'}, {'8', '1'}, {'8', '2'}, + {'8', '3'}, {'8', '4'}, {'8', '5'}, {'8', '6'}, {'8', '7'}, {'8', '8'}, {'8', '9'}, {'9', '0'}, {'9', '1'}, {'9', '2'}, {'9', '3'}, + {'9', '4'}, {'9', '5'}, {'9', '6'}, {'9', '7'}, {'9', '8'}, {'9', '9'}}; + FMT_API static constexpr const char hex_digits[] = "0123456789abcdef"; + FMT_API static constexpr const char signs[4] = {0, '-', '+', ' '}; + FMT_API static constexpr const char left_padding_shifts[5] = {31, 31, 0, 1, 0}; + FMT_API static constexpr const char right_padding_shifts[5] = {0, 31, 0, 1, 0}; + FMT_API static constexpr const unsigned prefixes[4] = {0, 0, 0x1000000u | '+', 0x1000000u | ' '}; }; -#ifdef FMT_SHARED +# ifdef FMT_SHARED // Required for -flto, -fivisibility=hidden and -shared to work extern template struct basic_data; -#endif +# endif -#if __cplusplus < 201703L +# if __cplusplus < 201703L // DEPRECATED! These are here only for ABI compatiblity. -template constexpr const char basic_data::digits[][2]; -template constexpr const char basic_data::hex_digits[]; -template constexpr const char basic_data::signs[]; -template constexpr const char basic_data::left_padding_shifts[]; -template +template +constexpr const char basic_data::digits[][2]; +template +constexpr const char basic_data::hex_digits[]; +template +constexpr const char basic_data::signs[]; +template +constexpr const char basic_data::left_padding_shifts[]; +template constexpr const char basic_data::right_padding_shifts[]; -template constexpr const unsigned basic_data::prefixes[]; -#endif +template +constexpr const unsigned basic_data::prefixes[]; +# endif -template -int format_float(char* buf, std::size_t size, const char* format, int precision, - T value) { -#ifdef FMT_FUZZ - if (precision > 100000) - throw std::runtime_error( - "fuzz mode - avoid large allocation inside snprintf"); -#endif - // Suppress the warning about nonliteral format string. - int (*snprintf_ptr)(char*, size_t, const char*, ...) = FMT_SNPRINTF; - return precision < 0 ? snprintf_ptr(buf, size, format, value) - : snprintf_ptr(buf, size, format, precision, value); +template +int format_float(char *buf, std::size_t size, const char *format, int precision, T value) +{ +# ifdef FMT_FUZZ + if (precision > 100000) + throw std::runtime_error("fuzz mode - avoid large allocation inside snprintf"); +# endif + // Suppress the warning about nonliteral format string. + int (*snprintf_ptr)(char *, size_t, const char *, ...) = FMT_SNPRINTF; + return precision < 0 ? snprintf_ptr(buf, size, format, value) : snprintf_ptr(buf, size, format, precision, value); } -template FMT_API dragonbox::decimal_fp dragonbox::to_decimal(float x) - FMT_NOEXCEPT; -template FMT_API dragonbox::decimal_fp dragonbox::to_decimal(double x) - FMT_NOEXCEPT; -} // namespace detail +template FMT_API dragonbox::decimal_fp dragonbox::to_decimal(float x) FMT_NOEXCEPT; +template FMT_API dragonbox::decimal_fp dragonbox::to_decimal(double x) FMT_NOEXCEPT; +} // namespace detail // Workaround a bug in MSVC2013 that prevents instantiation of format_float. -int (*instantiate_format_float)(double, int, detail::float_specs, - detail::buffer&) = detail::format_float; +int (*instantiate_format_float)(double, int, detail::float_specs, detail::buffer &) = detail::format_float; -#ifndef FMT_STATIC_THOUSANDS_SEPARATOR -template FMT_API detail::locale_ref::locale_ref(const std::locale& loc); +# ifndef FMT_STATIC_THOUSANDS_SEPARATOR +template FMT_API detail::locale_ref::locale_ref(const std::locale &loc); template FMT_API std::locale detail::locale_ref::get() const; -#endif +# endif // Explicit instantiations for char. -template FMT_API auto detail::thousands_sep_impl(locale_ref) - -> thousands_sep_result; +template FMT_API auto detail::thousands_sep_impl(locale_ref) -> thousands_sep_result; template FMT_API char detail::decimal_point_impl(locale_ref); -template FMT_API void detail::buffer::append(const char*, const char*); +template FMT_API void detail::buffer::append(const char *, const char *); // DEPRECATED! // There is no correspondent extern template in format.h because of // incompatibility between clang and gcc (#2377). template FMT_API void detail::vformat_to( - detail::buffer&, string_view, - basic_format_args, detail::locale_ref); + detail::buffer &, string_view, basic_format_args, detail::locale_ref); -template FMT_API int detail::snprintf_float(double, int, detail::float_specs, - detail::buffer&); -template FMT_API int detail::snprintf_float(long double, int, - detail::float_specs, - detail::buffer&); -template FMT_API int detail::format_float(double, int, detail::float_specs, - detail::buffer&); -template FMT_API int detail::format_float(long double, int, detail::float_specs, - detail::buffer&); +template FMT_API int detail::snprintf_float(double, int, detail::float_specs, detail::buffer &); +template FMT_API int detail::snprintf_float(long double, int, detail::float_specs, detail::buffer &); +template FMT_API int detail::format_float(double, int, detail::float_specs, detail::buffer &); +template FMT_API int detail::format_float(long double, int, detail::float_specs, detail::buffer &); // Explicit instantiations for wchar_t. -template FMT_API auto detail::thousands_sep_impl(locale_ref) - -> thousands_sep_result; +template FMT_API auto detail::thousands_sep_impl(locale_ref) -> thousands_sep_result; template FMT_API wchar_t detail::decimal_point_impl(locale_ref); -template FMT_API void detail::buffer::append(const wchar_t*, - const wchar_t*); +template FMT_API void detail::buffer::append(const wchar_t *, const wchar_t *); template struct detail::basic_data; FMT_END_NAMESPACE - #endif // !SPDLOG_FMT_EXTERNAL diff --git a/tests/test_file_helper.cpp b/tests/test_file_helper.cpp index 01fa48ef..9d459277 100644 --- a/tests/test_file_helper.cpp +++ b/tests/test_file_helper.cpp @@ -110,7 +110,7 @@ TEST_CASE("file_event_handlers", "[file_helper]") after_close }; prepare_logdir(); - + spdlog::filename_t test_filename = SPDLOG_FILENAME_T(TEST_FILENAME); // define event handles that update vector of flags when called std::vector events; @@ -119,13 +119,13 @@ TEST_CASE("file_event_handlers", "[file_helper]") REQUIRE(filename == test_filename); events.push_back(flags::before_open); }; - handlers.after_open = [&](spdlog::filename_t filename, std::FILE* fstream) { + handlers.after_open = [&](spdlog::filename_t filename, std::FILE *fstream) { REQUIRE(filename == test_filename); REQUIRE(fstream); fputs("after_open\n", fstream); events.push_back(flags::after_open); }; - handlers.before_close = [&](spdlog::filename_t filename, std::FILE* fstream) { + handlers.before_close = [&](spdlog::filename_t filename, std::FILE *fstream) { REQUIRE(filename == test_filename); REQUIRE(fstream); fputs("before_close\n", fstream); @@ -141,17 +141,16 @@ TEST_CASE("file_event_handlers", "[file_helper]") helper.open(test_filename); REQUIRE(events == std::vector{flags::before_open, flags::after_open}); - - events.clear(); - helper.close(); + + events.clear(); + helper.close(); REQUIRE(events == std::vector{flags::before_close, flags::after_close}); REQUIRE(file_contents(TEST_FILENAME) == "after_open\nbefore_close\n"); helper.reopen(true); - events.clear(); + events.clear(); } - // make sure that the file_helper destrcutor calls the close callbacks if needed + // make sure that the file_helper destrcutor calls the close callbacks if needed REQUIRE(events == std::vector{flags::before_close, flags::after_close}); REQUIRE(file_contents(TEST_FILENAME) == "after_open\nbefore_close\n"); - } diff --git a/tests/test_macros.cpp b/tests/test_macros.cpp index c9af60f3..2aeeecff 100644 --- a/tests/test_macros.cpp +++ b/tests/test_macros.cpp @@ -27,7 +27,7 @@ TEST_CASE("debug and trace w/o format string", "[macros]]") using spdlog::details::os::default_eol; REQUIRE(ends_with(file_contents(TEST_FILENAME), spdlog::fmt_lib::format("Test message 2{}", default_eol))); REQUIRE(count_lines(TEST_FILENAME) == 1); - + auto orig_default_logger = spdlog::default_logger(); spdlog::set_default_logger(logger); @@ -52,4 +52,3 @@ TEST_CASE("pass logger pointer", "[macros]") SPDLOG_LOGGER_TRACE(&ref, "Test message 1"); SPDLOG_LOGGER_DEBUG(&ref, "Test message 2"); } -