From 6aace693db9141788ab9311b7b6e8eb3cf3a85b7 Mon Sep 17 00:00:00 2001 From: Constantine Tarasenkov Date: Wed, 11 Jun 2014 02:38:57 +0400 Subject: [PATCH 1/4] Changes for MinGW compiler --- format.cc | 7 +++++++ posix.cc | 4 ++++ test/format-test.cc | 2 +- test/gtest-extra-test.cc | 4 ++-- test/util-test.cc | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/format.cc b/format.cc index b7138985..8ddd0235 100644 --- a/format.cc +++ b/format.cc @@ -42,6 +42,9 @@ #ifdef _WIN32 # define WIN32_LEAN_AND_MEAN +# ifdef __MINGW32__ +# include +# endif # include # undef ERROR #endif @@ -228,7 +231,11 @@ int fmt::internal::StrError( result = ERANGE; buffer = message; #elif _WIN32 +# ifdef __MINGW32__ + strerror(result); +# else result = strerror_s(buffer, buffer_size, error_code); +# endif // If the buffer is full then the message is probably truncated. if (result == 0 && std::strlen(buffer) == buffer_size - 1) result = ERANGE; diff --git a/posix.cc b/posix.cc index 9c3cc2ca..2d3a85d3 100644 --- a/posix.cc +++ b/posix.cc @@ -41,6 +41,10 @@ # define S_IRUSR _S_IREAD # define S_IWUSR _S_IWRITE +# ifdef __MINGW32__ +# define _SH_DENYNO 0x40 +# endif + #endif // _WIN32 namespace { diff --git a/test/format-test.cc b/test/format-test.cc index 14ff1b52..be092b49 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -35,7 +35,7 @@ #include #include -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) // Fix MSVC warning about "unsafe" fopen. FILE *FOpen(const char *filename, const char *mode) { FILE *f = 0; diff --git a/test/gtest-extra-test.cc b/test/gtest-extra-test.cc index 5d5c678b..af2682f4 100644 --- a/test/gtest-extra-test.cc +++ b/test/gtest-extra-test.cc @@ -32,13 +32,13 @@ #include #include -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) # include // for _CrtSetReportMode #endif // _WIN32 namespace { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) // Suppresses Windows assertions on invalid file descriptors, making // POSIX functions return proper error codes instead of crashing on Windows. diff --git a/test/util-test.cc b/test/util-test.cc index 35a5e410..66ee4727 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -43,7 +43,7 @@ using fmt::StringRef; namespace { std::string GetSystemErrorMessage(int error_code) { -#ifndef _WIN32 +#if defined(__MINGW32__) || !defined(_WIN32) return strerror(error_code); #else enum { BUFFER_SIZE = 200 }; From 08d4e5040f6a0c3fa169d258527dd82a17d3fdae Mon Sep 17 00:00:00 2001 From: Alexey Morozov Date: Wed, 11 Jun 2014 15:30:57 +0700 Subject: [PATCH 2/4] GCC may have support for __has_feature but doesn't support __has_builtin So perform these checks separately --- format.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/format.h b/format.h index 42b0e65f..b184bde4 100644 --- a/format.h +++ b/format.h @@ -61,9 +61,13 @@ // Compatibility with compilers other than clang. #ifdef __has_feature # define FMT_HAS_FEATURE(x) __has_feature(x) -# define FMT_HAS_BUILTIN(x) __has_builtin(x) #else # define FMT_HAS_FEATURE(x) 0 +#endif + +# ifdef __has_builtin +# define FMT_HAS_BUILTIN(x) __has_builtin(x) +#else # define FMT_HAS_BUILTIN(x) 0 #endif From 1aeac1b25a2d4b72c31e574f5ed69c13495cb703 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 11 Jun 2014 05:52:02 -0700 Subject: [PATCH 3/4] Unindent --- format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format.h b/format.h index b184bde4..c94aa8f0 100644 --- a/format.h +++ b/format.h @@ -65,7 +65,7 @@ # define FMT_HAS_FEATURE(x) 0 #endif -# ifdef __has_builtin +#ifdef __has_builtin # define FMT_HAS_BUILTIN(x) __has_builtin(x) #else # define FMT_HAS_BUILTIN(x) 0 From f4d47d7140d7a738c0b793acf14c12ca53dc1c42 Mon Sep 17 00:00:00 2001 From: Johan 't Hart Date: Mon, 16 Jun 2014 11:38:16 +0200 Subject: [PATCH 4/4] Fix grow size during Array<>::append When the resulting array must grow during append, one must make sure that the new elements _plus_ the current elements fit the new array size. --- format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format.h b/format.h index c94aa8f0..761132ff 100644 --- a/format.h +++ b/format.h @@ -315,7 +315,7 @@ template void Array::append(const T *begin, const T *end) { std::ptrdiff_t num_elements = end - begin; if (size_ + num_elements > capacity_) - Grow(num_elements); + Grow(size_ + num_elements); std::copy(begin, end, CheckPtr(ptr_, capacity_) + size_); size_ += num_elements; }