Commit ee354022 authored by Karol Ostrovsky's avatar Karol Ostrovsky

MinGW64+MSYS2 compilation issues and portable isnan using MathLimits

parent d40a0db2
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <google/protobuf/io/printer.h> #include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/mathlimits.h>
#include <google/protobuf/compiler/csharp/csharp_field_base.h> #include <google/protobuf/compiler/csharp/csharp_field_base.h>
#include <google/protobuf/compiler/csharp/csharp_helpers.h> #include <google/protobuf/compiler/csharp/csharp_helpers.h>
...@@ -248,11 +249,6 @@ bool FieldGeneratorBase::is_nullable_type() { ...@@ -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) { bool AllPrintableAscii(const std::string& text) {
for(int i = 0; i < text.size(); i++) { for(int i = 0; i < text.size(); i++) {
if (text[i] < 0x20 || text[i] > 0x7e) { if (text[i] < 0x20 || text[i] > 0x7e) {
...@@ -309,7 +305,7 @@ std::string FieldGeneratorBase::default_value() { ...@@ -309,7 +305,7 @@ std::string FieldGeneratorBase::default_value() {
return "double.PositiveInfinity"; return "double.PositiveInfinity";
} else if (value == -numeric_limits<double>::infinity()) { } else if (value == -numeric_limits<double>::infinity()) {
return "double.NegativeInfinity"; return "double.NegativeInfinity";
} else if (IsNaN(value)) { } else if (MathLimits<double>::IsNaN(value)) {
return "double.NaN"; return "double.NaN";
} }
return SimpleDtoa(value) + "D"; return SimpleDtoa(value) + "D";
...@@ -320,7 +316,7 @@ std::string FieldGeneratorBase::default_value() { ...@@ -320,7 +316,7 @@ std::string FieldGeneratorBase::default_value() {
return "float.PositiveInfinity"; return "float.PositiveInfinity";
} else if (value == -numeric_limits<float>::infinity()) { } else if (value == -numeric_limits<float>::infinity()) {
return "float.NegativeInfinity"; return "float.NegativeInfinity";
} else if (IsNaN(value)) { } else if (MathLimits<float>::IsNaN(value)) {
return "float.NaN"; return "float.NaN";
} }
return SimpleFtoa(value) + "F"; return SimpleFtoa(value) + "F";
......
...@@ -1459,14 +1459,14 @@ static inline uint32 bswap_32(uint32 x) { ...@@ -1459,14 +1459,14 @@ static inline uint32 bswap_32(uint32 x) {
} }
#define bswap_32(x) bswap_32(x) #define bswap_32(x) bswap_32(x)
static inline uint64 bswap_64(uint64 x) { static inline uint64 bswap_64(uint64 x) {
return (((x & GG_ULONGLONG(0xFF)) << 56) | return (((x & GOOGLE_ULONGLONG(0xFF)) << 56) |
((x & GG_ULONGLONG(0xFF00)) << 40) | ((x & GOOGLE_ULONGLONG(0xFF00)) << 40) |
((x & GG_ULONGLONG(0xFF0000)) << 24) | ((x & GOOGLE_ULONGLONG(0xFF0000)) << 24) |
((x & GG_ULONGLONG(0xFF000000)) << 8) | ((x & GOOGLE_ULONGLONG(0xFF000000)) << 8) |
((x & GG_ULONGLONG(0xFF00000000)) >> 8) | ((x & GOOGLE_ULONGLONG(0xFF00000000)) >> 8) |
((x & GG_ULONGLONG(0xFF0000000000)) >> 24) | ((x & GOOGLE_ULONGLONG(0xFF0000000000)) >> 24) |
((x & GG_ULONGLONG(0xFF000000000000)) >> 40) | ((x & GOOGLE_ULONGLONG(0xFF000000000000)) >> 40) |
((x & GG_ULONGLONG(0xFF00000000000000)) >> 56)); ((x & GOOGLE_ULONGLONG(0xFF00000000000000)) >> 56));
} }
#define bswap_64(x) bswap_64(x) #define bswap_64(x) bswap_64(x)
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
// from google3/strings/strutil.cc // from google3/strings/strutil.cc
#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/mathlimits.h>
#include <errno.h> #include <errno.h>
#include <float.h> // FLT_DIG and DBL_DIG #include <float.h> // FLT_DIG and DBL_DIG
...@@ -58,11 +59,6 @@ ...@@ -58,11 +59,6 @@
namespace google { namespace google {
namespace protobuf { 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 // These are defined as macros on some platforms. #undef them so that we can
// redefine them. // redefine them.
#undef isxdigit #undef isxdigit
...@@ -1210,7 +1206,7 @@ char* DoubleToBuffer(double value, char* buffer) { ...@@ -1210,7 +1206,7 @@ char* DoubleToBuffer(double value, char* buffer) {
} else if (value == -numeric_limits<double>::infinity()) { } else if (value == -numeric_limits<double>::infinity()) {
strcpy(buffer, "-inf"); strcpy(buffer, "-inf");
return buffer; return buffer;
} else if (IsNaN(value)) { } else if (MathLimits<double>::IsNaN(value)) {
strcpy(buffer, "nan"); strcpy(buffer, "nan");
return buffer; return buffer;
} }
...@@ -1328,7 +1324,7 @@ char* FloatToBuffer(float value, char* buffer) { ...@@ -1328,7 +1324,7 @@ char* FloatToBuffer(float value, char* buffer) {
} else if (value == -numeric_limits<double>::infinity()) { } else if (value == -numeric_limits<double>::infinity()) {
strcpy(buffer, "-inf"); strcpy(buffer, "-inf");
return buffer; return buffer;
} else if (IsNaN(value)) { } else if (MathLimits<float>::IsNaN(value)) {
strcpy(buffer, "nan"); strcpy(buffer, "nan");
return buffer; return buffer;
} }
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <google/protobuf/io/tokenizer.h> #include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/mathlimits.h>
#include <google/protobuf/stubs/substitute.h> #include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/testing/googletest.h> #include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
...@@ -57,11 +58,6 @@ namespace protobuf { ...@@ -57,11 +58,6 @@ namespace protobuf {
// Can't use an anonymous namespace here due to brokenness of Tru64 compiler. // Can't use an anonymous namespace here due to brokenness of Tru64 compiler.
namespace text_format_unittest { 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. // A basic string with different escapable characters for testing.
const string kEscapeTestString = const string kEscapeTestString =
"\"A string with ' characters \n and \r newlines and \t tabs and \001 " "\"A string with ' characters \n and \r newlines and \t tabs and \001 "
...@@ -898,8 +894,8 @@ TEST_F(TextFormatTest, ParseExotic) { ...@@ -898,8 +894,8 @@ TEST_F(TextFormatTest, ParseExotic) {
EXPECT_EQ(message.repeated_double(8), numeric_limits<double>::infinity()); EXPECT_EQ(message.repeated_double(8), numeric_limits<double>::infinity());
EXPECT_EQ(message.repeated_double(9), -numeric_limits<double>::infinity()); EXPECT_EQ(message.repeated_double(9), -numeric_limits<double>::infinity());
EXPECT_EQ(message.repeated_double(10), -numeric_limits<double>::infinity()); EXPECT_EQ(message.repeated_double(10), -numeric_limits<double>::infinity());
EXPECT_TRUE(IsNaN(message.repeated_double(11))); EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(11)));
EXPECT_TRUE(IsNaN(message.repeated_double(12))); EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(12)));
// Note: Since these string literals have \0's in them, we must explicitly // Note: Since these string literals have \0's in them, we must explicitly
// pass their sizes to string's constructor. // pass their sizes to string's constructor.
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <google/protobuf/util/internal/utility.h> #include <google/protobuf/util/internal/utility.h>
#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/mathutil.h> #include <google/protobuf/stubs/mathutil.h>
#include <google/protobuf/stubs/mathlimits.h>
namespace google { namespace google {
namespace protobuf { namespace protobuf {
...@@ -78,7 +79,7 @@ StatusOr<To> NumberConvertAndCheck(From before) { ...@@ -78,7 +79,7 @@ StatusOr<To> NumberConvertAndCheck(From before) {
// For conversion between double and float only. // For conversion between double and float only.
template <typename To, typename From> template <typename To, typename From>
StatusOr<To> FloatingPointConvertAndCheck(From before) { StatusOr<To> FloatingPointConvertAndCheck(From before) {
if (isnan(before)) return std::numeric_limits<To>::quiet_NaN(); if (MathLimits<From>::IsNaN(before)) return std::numeric_limits<To>::quiet_NaN();
To after = static_cast<To>(before); To after = static_cast<To>(before);
if (MathUtil::AlmostEquals<To>(after, before)) { if (MathUtil::AlmostEquals<To>(after, before)) {
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <google/protobuf/util/internal/constants.h> #include <google/protobuf/util/internal/constants.h>
#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/map_util.h> #include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/mathlimits.h>
namespace google { namespace google {
namespace protobuf { namespace protobuf {
...@@ -302,7 +303,7 @@ bool IsMap(const google::protobuf::Field& field, ...@@ -302,7 +303,7 @@ bool IsMap(const google::protobuf::Field& field,
string DoubleAsString(double value) { string DoubleAsString(double value) {
if (value == std::numeric_limits<double>::infinity()) return "Infinity"; if (value == std::numeric_limits<double>::infinity()) return "Infinity";
if (value == -std::numeric_limits<double>::infinity()) return "-Infinity"; if (value == -std::numeric_limits<double>::infinity()) return "-Infinity";
if (::isnan(value)) return "NaN"; if (google::protobuf::MathLimits<double>::IsNaN(value)) return "NaN";
return SimpleDtoa(value); return SimpleDtoa(value);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment