Merge pull request #551 from ostrovsky/master

MinGW64+MSYS2 compilation issues
This commit is contained in:
Feng Xiao 2015-07-01 10:36:30 -07:00
commit ec7bbc76be
6 changed files with 21 additions and 31 deletions

View File

@ -38,6 +38,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.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_helpers.h>
@ -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<double>::infinity()) {
return "double.NegativeInfinity";
} else if (IsNaN(value)) {
} else if (MathLimits<double>::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<float>::infinity()) {
return "float.NegativeInfinity";
} else if (IsNaN(value)) {
} else if (MathLimits<float>::IsNaN(value)) {
return "float.NaN";
}
return SimpleFtoa(value) + "F";

View File

@ -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)

View File

@ -31,6 +31,7 @@
// from google3/strings/strutil.cc
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/mathlimits.h>
#include <errno.h>
#include <float.h> // 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<double>::infinity()) {
strcpy(buffer, "-inf");
return buffer;
} else if (IsNaN(value)) {
} else if (MathLimits<double>::IsNaN(value)) {
strcpy(buffer, "nan");
return buffer;
}
@ -1328,7 +1324,7 @@ char* FloatToBuffer(float value, char* buffer) {
} else if (value == -numeric_limits<double>::infinity()) {
strcpy(buffer, "-inf");
return buffer;
} else if (IsNaN(value)) {
} else if (MathLimits<float>::IsNaN(value)) {
strcpy(buffer, "nan");
return buffer;
}

View File

@ -46,6 +46,7 @@
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/mathlimits.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
@ -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<double>::infinity());
EXPECT_EQ(message.repeated_double(9), -numeric_limits<double>::infinity());
EXPECT_EQ(message.repeated_double(10), -numeric_limits<double>::infinity());
EXPECT_TRUE(IsNaN(message.repeated_double(11)));
EXPECT_TRUE(IsNaN(message.repeated_double(12)));
EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(11)));
EXPECT_TRUE(MathLimits<double>::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.

View File

@ -36,6 +36,7 @@
#include <google/protobuf/util/internal/utility.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/mathutil.h>
#include <google/protobuf/stubs/mathlimits.h>
namespace google {
namespace protobuf {
@ -78,7 +79,7 @@ StatusOr<To> NumberConvertAndCheck(From before) {
// For conversion between double and float only.
template <typename To, typename From>
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);
if (MathUtil::AlmostEquals<To>(after, before)) {

View File

@ -41,6 +41,7 @@
#include <google/protobuf/util/internal/constants.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/mathlimits.h>
namespace google {
namespace protobuf {
@ -302,7 +303,7 @@ bool IsMap(const google::protobuf::Field& field,
string DoubleAsString(double value) {
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);
}