diff options
author | Haibo Huang <hhb@google.com> | 2020-11-25 12:23:40 -0800 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2020-11-25 12:23:40 -0800 |
commit | f44020815afba5b4eaca3ee70364f21780b92923 (patch) | |
tree | 5a3e3db7e0c4a3db4e3d42d44ac7a7498a6b0aef | |
parent | d6904de0e78c94cc01ca5697193819bf2cb17d6d (diff) | |
parent | 7bdf0628b1276379886c7f6dda2cef2b3b374f0b (diff) | |
download | fmtlib-f44020815afba5b4eaca3ee70364f21780b92923.tar.gz |
Upgrade fmtlib to 7.1.3
Test: make
Change-Id: I1a6309cd0a0b85ff61b59cc7d60152169e886578
-rw-r--r-- | .github/workflows/windows.yml | 44 | ||||
-rw-r--r-- | ChangeLog.rst | 22 | ||||
-rw-r--r-- | METADATA | 4 | ||||
-rwxr-xr-x | doc/build.py | 2 | ||||
-rw-r--r-- | include/fmt/core.h | 6 | ||||
-rw-r--r-- | include/fmt/format-inl.h | 2 | ||||
-rw-r--r-- | include/fmt/format.h | 16 | ||||
-rw-r--r-- | include/fmt/os.h | 2 | ||||
-rw-r--r-- | include/fmt/ranges.h | 5 | ||||
-rw-r--r-- | src/format.cc | 4 | ||||
-rw-r--r-- | src/os.cc | 2 | ||||
-rw-r--r-- | test/format-test.cc | 19 | ||||
-rw-r--r-- | test/ostream-test.cc | 7 |
13 files changed, 109 insertions, 26 deletions
diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000..f66e2bc9 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,44 @@ +name: windows + +on: [push, pull_request] + +jobs: + build: + runs-on: ${{matrix.os}} + strategy: + matrix: + # windows-2016 and windows-2019 have MSVC 2017 and 2019 installed + # respectively: https://github.com/actions/virtual-environments. + os: [windows-2016, windows-2019] + platform: [Win32, x64] + build_type: [Debug, Release] + include: + - os: windows-2016 + platform: Win32 + build_type: Debug + shared: -DBUILD_SHARED_LIBS=ON + exclude: + - os: windows-2016 + platform: Win32 + + steps: + - uses: actions/checkout@v2 + + - name: Create Build Environment + run: cmake -E make_directory ${{runner.workspace}}/build + + - name: Configure + # Use a bash shell for $GITHUB_WORKSPACE. + shell: bash + working-directory: ${{runner.workspace}}/build + run: | + cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} ${{matrix.shared}} \ + -A ${{matrix.platform}} $GITHUB_WORKSPACE + + - name: Build + working-directory: ${{runner.workspace}}/build + run: cmake --build . --config ${{matrix.build_type}} + + - name: Test + working-directory: ${{runner.workspace}}/build + run: ctest -C ${{matrix.build_type}} diff --git a/ChangeLog.rst b/ChangeLog.rst index a5b776cf..9c171af0 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -1,3 +1,25 @@ +7.1.3 - 2020-11-24 +------------------ + +* Fixed handling of buffer boundaries in ``format_to_n`` + (`#1996 <https://github.com/fmtlib/fmt/issues/1996>`_, + `#2029 <https://github.com/fmtlib/fmt/issues/2029>`_). + +* Fixed linkage errors when linking with a shared library + (`#2011 <https://github.com/fmtlib/fmt/issues/2011>`_). + +* Reintroduced ostream support to range formatters + (`#2014 <https://github.com/fmtlib/fmt/issues/2014>`_). + +* Worked around an issue with mixing std versions in gcc + (`#2017 <https://github.com/fmtlib/fmt/issues/2017>`_). + +7.1.2 - 2020-11-04 +------------------ + +* Fixed floating point formatting with large precision + (`#1976 <https://github.com/fmtlib/fmt/issues/1976>`_). + 7.1.1 - 2020-11-01 ------------------ @@ -9,11 +9,11 @@ third_party { type: GIT value: "https://github.com/fmtlib/fmt.git" } - version: "7.1.1" + version: "7.1.3" license_type: NOTICE last_upgrade_date { year: 2020 month: 11 - day: 2 + day: 25 } } diff --git a/doc/build.py b/doc/build.py index 85eaaa81..4651756e 100755 --- a/doc/build.py +++ b/doc/build.py @@ -6,7 +6,7 @@ import errno, os, shutil, sys, tempfile from subprocess import check_call, check_output, CalledProcessError, Popen, PIPE from distutils.version import LooseVersion -versions = ['1.0.0', '1.1.0', '2.0.0', '3.0.2', '4.0.0', '4.1.0', '5.0.0', '5.1.0', '5.2.0', '5.2.1', '5.3.0', '6.0.0', '6.1.0', '6.1.1', '6.1.2', '6.2.0', '6.2.1', '7.0.0', '7.0.1', '7.0.2', '7.0.3', '7.1.0', '7.1.1'] +versions = ['1.0.0', '1.1.0', '2.0.0', '3.0.2', '4.0.0', '4.1.0', '5.0.0', '5.1.0', '5.2.0', '5.2.1', '5.3.0', '6.0.0', '6.1.0', '6.1.1', '6.1.2', '6.2.0', '6.2.1', '7.0.0', '7.0.1', '7.0.2', '7.0.3', '7.1.0', '7.1.1', '7.1.2', '7.1.3'] def pip_install(package, commit=None, **kwargs): "Install package using pip." diff --git a/include/fmt/core.h b/include/fmt/core.h index 60e49425..0a81e0cc 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -18,7 +18,7 @@ #include <vector> // The fmt library version in the form major * 10000 + minor * 100 + patch. -#define FMT_VERSION 70101 +#define FMT_VERSION 70103 #ifdef __clang__ # define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) @@ -761,7 +761,7 @@ class fixed_buffer_traits { explicit fixed_buffer_traits(size_t limit) : limit_(limit) {} size_t count() const { return count_; } size_t limit(size_t size) { - size_t n = limit_ - count_; + size_t n = limit_ > count_ ? limit_ - count_ : 0; count_ += size; return size < n ? size : n; } @@ -784,7 +784,7 @@ class iterator_buffer final : public Traits, public buffer<T> { public: explicit iterator_buffer(OutputIt out, size_t n = buffer_size) : Traits(n), - buffer<T>(data_, 0, n < size_t(buffer_size) ? n : size_t(buffer_size)), + buffer<T>(data_, 0, buffer_size), out_(out) {} ~iterator_buffer() { flush(); } diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 5d466eeb..8f2fe735 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -2337,7 +2337,7 @@ void fallback_format(Double d, int num_digits, bool binary32, buffer<char>& buf, upper = &upper_store; } denominator.assign_pow10(exp10); - denominator <<= 1; + denominator <<= shift; } else if (exp10 < 0) { numerator.assign_pow10(-exp10); lower.assign(numerator); diff --git a/include/fmt/format.h b/include/fmt/format.h index 13b8da30..1a037b02 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1145,8 +1145,8 @@ template <typename T = void> struct null {}; template <typename Char> struct fill_t { private: enum { max_size = 4 }; - Char data_[max_size]; - unsigned char size_; + Char data_[max_size] = {Char(' '), Char(0), Char(0), Char(0)}; + unsigned char size_ = 1; public: FMT_CONSTEXPR void operator=(basic_string_view<Char> s) { @@ -1166,13 +1166,6 @@ template <typename Char> struct fill_t { FMT_CONSTEXPR const Char& operator[](size_t index) const { return data_[index]; } - - static FMT_CONSTEXPR fill_t<Char> make() { - auto fill = fill_t<Char>(); - fill[0] = Char(' '); - fill.size_ = 1; - return fill; - } }; } // namespace detail @@ -1204,8 +1197,7 @@ template <typename Char> struct basic_format_specs { type(0), align(align::none), sign(sign::none), - alt(false), - fill(detail::fill_t<Char>::make()) {} + alt(false) {} }; using format_specs = basic_format_specs<char>; @@ -1274,7 +1266,7 @@ template <typename T> struct decimal_fp { int exponent; }; -template <typename T> decimal_fp<T> to_decimal(T x) FMT_NOEXCEPT; +template <typename T> FMT_API decimal_fp<T> to_decimal(T x) FMT_NOEXCEPT; } // namespace dragonbox template <typename T> diff --git a/include/fmt/os.h b/include/fmt/os.h index 88151006..d44ea0c9 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -388,7 +388,7 @@ class ostream final : private detail::buffer<char> { clear(); } - void grow(size_t) final; + FMT_API void grow(size_t) override final; ostream(cstring_view path, const detail::ostream_params& params) : file_(path, params.oflag) { diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index b603d637..632f0494 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -254,7 +254,10 @@ struct formatter< enable_if_t<fmt::is_range<T, Char>::value // Workaround a bug in MSVC 2017 and earlier. #if !FMT_MSC_VER || FMT_MSC_VER >= 1927 - && has_formatter<detail::value_type<T>, format_context>::value + && + (has_formatter<detail::value_type<T>, format_context>::value || + detail::has_fallback_formatter<detail::value_type<T>, + format_context>::value) #endif >> { formatting_range<Char> formatting; diff --git a/src/format.cc b/src/format.cc index bca87b03..6141d964 100644 --- a/src/format.cc +++ b/src/format.cc @@ -24,9 +24,9 @@ int format_float(char* buf, std::size_t size, const char* format, int precision, : snprintf_ptr(buf, size, format, precision, value); } -template dragonbox::decimal_fp<float> dragonbox::to_decimal(float x) +template FMT_API dragonbox::decimal_fp<float> dragonbox::to_decimal(float x) FMT_NOEXCEPT; -template dragonbox::decimal_fp<double> dragonbox::to_decimal(double x) +template FMT_API dragonbox::decimal_fp<double> dragonbox::to_decimal(double x) FMT_NOEXCEPT; // DEPRECATED! This function exists for ABI compatibility. @@ -315,7 +315,7 @@ long getpagesize() { # endif } -void ostream::grow(size_t) { +FMT_API void ostream::grow(size_t) { if (this->size() == this->capacity()) flush(); } #endif // FMT_USE_FCNTL diff --git a/test/format-test.cc b/test/format-test.cc index 128b57a2..8ed524cc 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1270,6 +1270,8 @@ TEST(FormatterTest, FormatDouble) { EXPECT_EQ(buffer, format("{:a}", -42.0)); safe_sprintf(buffer, "%A", -42.0); EXPECT_EQ(buffer, format("{:A}", -42.0)); + EXPECT_EQ("9223372036854775808.000000", + format("{:f}", 9223372036854775807.0)); } TEST(FormatterTest, PrecisionRounding) { @@ -1943,10 +1945,12 @@ TEST(FormatTest, FormatToN) { EXPECT_EQ(5u, result.size); EXPECT_EQ(buffer + 3, result.out); EXPECT_EQ("123x", fmt::string_view(buffer, 4)); + result = fmt::format_to_n(buffer, 3, "{:s}", "foobar"); EXPECT_EQ(6u, result.size); EXPECT_EQ(buffer + 3, result.out); EXPECT_EQ("foox", fmt::string_view(buffer, 4)); + buffer[0] = 'x'; buffer[1] = 'x'; buffer[2] = 'x'; @@ -1954,10 +1958,20 @@ TEST(FormatTest, FormatToN) { EXPECT_EQ(1u, result.size); EXPECT_EQ(buffer + 1, result.out); EXPECT_EQ("Axxx", fmt::string_view(buffer, 4)); + result = fmt::format_to_n(buffer, 3, "{}{} ", 'B', 'C'); EXPECT_EQ(3u, result.size); EXPECT_EQ(buffer + 3, result.out); EXPECT_EQ("BC x", fmt::string_view(buffer, 4)); + + result = fmt::format_to_n(buffer, 4, "{}", "ABCDE"); + EXPECT_EQ(5u, result.size); + EXPECT_EQ("ABCD", fmt::string_view(buffer, 4)); + + buffer[3] = 'x'; + result = fmt::format_to_n(buffer, 3, "{}", std::string(1000, '*')); + EXPECT_EQ(1000u, result.size); + EXPECT_EQ("***x", fmt::string_view(buffer, 4)); } TEST(FormatTest, WideFormatToN) { @@ -2414,11 +2428,13 @@ TEST(FormatTest, CharTraitsIsNotAmbiguous) { #endif } +#if __cplusplus > 201103L struct custom_char { int value; custom_char() = default; - template <typename T> custom_char(T val) : value(static_cast<int>(val)) {} + template <typename T> + constexpr custom_char(T val) : value(static_cast<int>(val)) {} operator int() const { return value; } }; @@ -2435,6 +2451,7 @@ TEST(FormatTest, FormatCustomChar) { EXPECT_EQ(result.size(), 1); EXPECT_EQ(result[0], custom_char('x')); } +#endif // Convert a char8_t string to std::string. Otherwise GTest will insist on // inserting `char8_t` NTBS into a `char` stream which is disabled by P1423. diff --git a/test/ostream-test.cc b/test/ostream-test.cc index ebf14210..4f432fb9 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -5,7 +5,6 @@ // // For the license information refer to format.h. -#define FMT_STRING_ALIAS 1 #include "fmt/format.h" struct test {}; @@ -24,6 +23,7 @@ template <> struct formatter<test> : formatter<int> { #include <sstream> #include "fmt/ostream.h" +#include "fmt/ranges.h" #include "gmock.h" #include "gtest-extra.h" #include "util.h" @@ -323,3 +323,8 @@ TEST(OStreamTest, CompileTimeString) { TEST(OStreamTest, ToString) { EXPECT_EQ("ABC", fmt::to_string(fmt_test::ABC())); } + +TEST(OStreamTest, Range) { + auto strs = std::vector<TestString>{TestString("foo"), TestString("bar")}; + EXPECT_EQ("{foo, bar}", format("{}", strs)); +}
\ No newline at end of file |