From ee35402244fc463cedc470baa0f5f1a6080d905d Mon Sep 17 00:00:00 2001 From: Karol Ostrovsky Date: Mon, 29 Jun 2015 16:13:33 +0200 Subject: MinGW64+MSYS2 compilation issues and portable isnan using MathLimits --- src/google/protobuf/compiler/csharp/csharp_field_base.cc | 10 +++------- src/google/protobuf/stubs/common.h | 16 ++++++++-------- src/google/protobuf/stubs/strutil.cc | 10 +++------- src/google/protobuf/text_format_unittest.cc | 10 +++------- src/google/protobuf/util/internal/datapiece.cc | 3 ++- src/google/protobuf/util/internal/utility.cc | 3 ++- 6 files changed, 21 insertions(+), 31 deletions(-) (limited to 'src/google') diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index c3ce426b..4c6a3d72 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -248,11 +249,6 @@ bool FieldGeneratorBase::is_nullable_type() { } } -inline bool IsNaN(double value) { - // NaN is never equal to anything, even itself. - return value != value; -} - bool AllPrintableAscii(const std::string& text) { for(int i = 0; i < text.size(); i++) { if (text[i] < 0x20 || text[i] > 0x7e) { @@ -309,7 +305,7 @@ std::string FieldGeneratorBase::default_value() { return "double.PositiveInfinity"; } else if (value == -numeric_limits::infinity()) { return "double.NegativeInfinity"; - } else if (IsNaN(value)) { + } else if (MathLimits::IsNaN(value)) { return "double.NaN"; } return SimpleDtoa(value) + "D"; @@ -320,7 +316,7 @@ std::string FieldGeneratorBase::default_value() { return "float.PositiveInfinity"; } else if (value == -numeric_limits::infinity()) { return "float.NegativeInfinity"; - } else if (IsNaN(value)) { + } else if (MathLimits::IsNaN(value)) { return "float.NaN"; } return SimpleFtoa(value) + "F"; diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index c3620146..3eb57a9b 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -1459,14 +1459,14 @@ static inline uint32 bswap_32(uint32 x) { } #define bswap_32(x) bswap_32(x) static inline uint64 bswap_64(uint64 x) { - return (((x & GG_ULONGLONG(0xFF)) << 56) | - ((x & GG_ULONGLONG(0xFF00)) << 40) | - ((x & GG_ULONGLONG(0xFF0000)) << 24) | - ((x & GG_ULONGLONG(0xFF000000)) << 8) | - ((x & GG_ULONGLONG(0xFF00000000)) >> 8) | - ((x & GG_ULONGLONG(0xFF0000000000)) >> 24) | - ((x & GG_ULONGLONG(0xFF000000000000)) >> 40) | - ((x & GG_ULONGLONG(0xFF00000000000000)) >> 56)); + return (((x & GOOGLE_ULONGLONG(0xFF)) << 56) | + ((x & GOOGLE_ULONGLONG(0xFF00)) << 40) | + ((x & GOOGLE_ULONGLONG(0xFF0000)) << 24) | + ((x & GOOGLE_ULONGLONG(0xFF000000)) << 8) | + ((x & GOOGLE_ULONGLONG(0xFF00000000)) >> 8) | + ((x & GOOGLE_ULONGLONG(0xFF0000000000)) >> 24) | + ((x & GOOGLE_ULONGLONG(0xFF000000000000)) >> 40) | + ((x & GOOGLE_ULONGLONG(0xFF00000000000000)) >> 56)); } #define bswap_64(x) bswap_64(x) diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc index 99e8bf1d..2ec62b42 100644 --- a/src/google/protobuf/stubs/strutil.cc +++ b/src/google/protobuf/stubs/strutil.cc @@ -31,6 +31,7 @@ // from google3/strings/strutil.cc #include +#include #include #include // FLT_DIG and DBL_DIG @@ -58,11 +59,6 @@ namespace google { namespace protobuf { -inline bool IsNaN(double value) { - // NaN is never equal to anything, even itself. - return value != value; -} - // These are defined as macros on some platforms. #undef them so that we can // redefine them. #undef isxdigit @@ -1210,7 +1206,7 @@ char* DoubleToBuffer(double value, char* buffer) { } else if (value == -numeric_limits::infinity()) { strcpy(buffer, "-inf"); return buffer; - } else if (IsNaN(value)) { + } else if (MathLimits::IsNaN(value)) { strcpy(buffer, "nan"); return buffer; } @@ -1328,7 +1324,7 @@ char* FloatToBuffer(float value, char* buffer) { } else if (value == -numeric_limits::infinity()) { strcpy(buffer, "-inf"); return buffer; - } else if (IsNaN(value)) { + } else if (MathLimits::IsNaN(value)) { strcpy(buffer, "nan"); return buffer; } diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index 1b18c5ed..76ce9875 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -57,11 +58,6 @@ namespace protobuf { // Can't use an anonymous namespace here due to brokenness of Tru64 compiler. namespace text_format_unittest { -inline bool IsNaN(double value) { - // NaN is never equal to anything, even itself. - return value != value; -} - // A basic string with different escapable characters for testing. const string kEscapeTestString = "\"A string with ' characters \n and \r newlines and \t tabs and \001 " @@ -898,8 +894,8 @@ TEST_F(TextFormatTest, ParseExotic) { EXPECT_EQ(message.repeated_double(8), numeric_limits::infinity()); EXPECT_EQ(message.repeated_double(9), -numeric_limits::infinity()); EXPECT_EQ(message.repeated_double(10), -numeric_limits::infinity()); - EXPECT_TRUE(IsNaN(message.repeated_double(11))); - EXPECT_TRUE(IsNaN(message.repeated_double(12))); + EXPECT_TRUE(MathLimits::IsNaN(message.repeated_double(11))); + EXPECT_TRUE(MathLimits::IsNaN(message.repeated_double(12))); // Note: Since these string literals have \0's in them, we must explicitly // pass their sizes to string's constructor. diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc index 72b737e9..944fb2e3 100644 --- a/src/google/protobuf/util/internal/datapiece.cc +++ b/src/google/protobuf/util/internal/datapiece.cc @@ -36,6 +36,7 @@ #include #include #include +#include namespace google { namespace protobuf { @@ -78,7 +79,7 @@ StatusOr NumberConvertAndCheck(From before) { // For conversion between double and float only. template StatusOr FloatingPointConvertAndCheck(From before) { - if (isnan(before)) return std::numeric_limits::quiet_NaN(); + if (MathLimits::IsNaN(before)) return std::numeric_limits::quiet_NaN(); To after = static_cast(before); if (MathUtil::AlmostEquals(after, before)) { diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc index f550f43b..794777d4 100644 --- a/src/google/protobuf/util/internal/utility.cc +++ b/src/google/protobuf/util/internal/utility.cc @@ -41,6 +41,7 @@ #include #include #include +#include namespace google { namespace protobuf { @@ -302,7 +303,7 @@ bool IsMap(const google::protobuf::Field& field, string DoubleAsString(double value) { if (value == std::numeric_limits::infinity()) return "Infinity"; if (value == -std::numeric_limits::infinity()) return "-Infinity"; - if (::isnan(value)) return "NaN"; + if (google::protobuf::MathLimits::IsNaN(value)) return "NaN"; return SimpleDtoa(value); } -- cgit v1.2.3