From 37df4b65a473ce10843aa94e3fb5867e72d8df73 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Tue, 2 Jun 2015 22:26:00 -0700 Subject: Delete default UnknownFieldSet when shuting down. --- src/google/protobuf/unknown_field_set.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc index 76644900..93f0f206 100644 --- a/src/google/protobuf/unknown_field_set.cc +++ b/src/google/protobuf/unknown_field_set.cc @@ -50,8 +50,13 @@ namespace { // instantiate the UnknownFieldSet dynamically only when required. UnknownFieldSet* default_unknown_field_set_instance_ = NULL; +void DeleteDefaultUnknownFieldSet() { + delete default_unknown_field_set_instance_; +} + void InitDefaultUnknownFieldSet() { default_unknown_field_set_instance_ = new UnknownFieldSet(); + internal::OnShutdown(&DeleteDefaultUnknownFieldSet); } GOOGLE_PROTOBUF_DECLARE_ONCE(default_unknown_field_set_once_init_); -- cgit v1.2.3 From a269a6d397b5bee9df0a73f186400ba2228a68d4 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 15 Jun 2015 16:54:02 -0700 Subject: Implement parsing for proto3 primitive repeated fields. Previously, for proto3 primitive repeated fields, packed data cannot be parsed if definition is unpacked. Neither is the other way. --- src/google/protobuf/compiler/cpp/cpp_message.cc | 10 +- src/google/protobuf/wire_format.h | 2 +- src/google/protobuf/wire_format_unittest.cc | 144 +++++++++++++++--------- 3 files changed, 94 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index af85919a..9802a165 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -2932,7 +2932,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) { "commontag", SimpleItoa(WireFormat::MakeTag(field))); if (need_label || - (field->is_repeated() && !field->options().packed() && !loops)) { + (field->is_repeated() && !field->is_packed() && !loops)) { printer->Print( " parse_$name$:\n", "name", field->name()); @@ -2945,7 +2945,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) { } printer->Indent(); - if (field->options().packed()) { + if (field->is_packed()) { field_generator.GenerateMergeFromCodedStreamWithPacking(printer); } else { field_generator.GenerateMergeFromCodedStream(printer); @@ -2953,7 +2953,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) { printer->Outdent(); // Emit code to parse unexpectedly packed or unpacked values. - if (field->is_packable() && field->options().packed()) { + if (field->is_packed()) { internal::WireFormatLite::WireType wiretype = WireFormat::WireTypeForFieldType(field->type()); printer->Print("} else if (tag == $uncommontag$) {\n", @@ -2963,7 +2963,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) { printer->Indent(); field_generator.GenerateMergeFromCodedStream(printer); printer->Outdent(); - } else if (field->is_packable() && !field->options().packed()) { + } else if (field->is_packable() && !field->is_packed()) { internal::WireFormatLite::WireType wiretype = internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED; printer->Print("} else if (tag == $uncommontag$) {\n", @@ -2988,7 +2988,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) { "if (input->ExpectTag($tag$)) goto parse_loop_$name$;\n", "tag", SimpleItoa(WireFormat::MakeTag(field)), "name", field->name()); - } else if (field->is_repeated() && !field->options().packed()) { + } else if (field->is_repeated() && !field->is_packed()) { printer->Print( "if (input->ExpectTag($tag$)) goto parse_$name$;\n", "tag", SimpleItoa(WireFormat::MakeTag(field)), diff --git a/src/google/protobuf/wire_format.h b/src/google/protobuf/wire_format.h index 8de491a6..84270fee 100644 --- a/src/google/protobuf/wire_format.h +++ b/src/google/protobuf/wire_format.h @@ -290,7 +290,7 @@ class LIBPROTOBUF_EXPORT UnknownFieldSetFieldSkipper : public FieldSkipper { inline WireFormatLite::WireType WireFormat::WireTypeForField( const FieldDescriptor* field) { - if (field->options().packed()) { + if (field->is_packed()) { return WireFormatLite::WIRETYPE_LENGTH_DELIMITED; } else { return WireTypeForFieldType(field->type()); diff --git a/src/google/protobuf/wire_format_unittest.cc b/src/google/protobuf/wire_format_unittest.cc index 4b151f97..aef22b29 100644 --- a/src/google/protobuf/wire_format_unittest.cc +++ b/src/google/protobuf/wire_format_unittest.cc @@ -795,9 +795,73 @@ TEST(WireFormatTest, CompatibleTypes) { ASSERT_EQ(static_cast(data), msg5.data()); } -class Proto3PrimitiveRepeatedWireFormatTest - : public ::testing::TestWithParam { +class Proto3PrimitiveRepeatedWireFormatTest : public ::testing::Test { protected: + Proto3PrimitiveRepeatedWireFormatTest() + : packedTestAllTypes_( + "\xFA\x01\x01\x01" + "\x82\x02\x01\x01" + "\x8A\x02\x01\x01" + "\x92\x02\x01\x01" + "\x9A\x02\x01\x02" + "\xA2\x02\x01\x02" + "\xAA\x02\x04\x01\x00\x00\x00" + "\xB2\x02\x08\x01\x00\x00\x00\x00\x00\x00\x00" + "\xBA\x02\x04\x01\x00\x00\x00" + "\xC2\x02\x08\x01\x00\x00\x00\x00\x00\x00\x00" + "\xCA\x02\x04\x00\x00\x80\x3f" + "\xD2\x02\x08\x00\x00\x00\x00\x00\x00\xf0\x3f" + "\xDA\x02\x01\x01" + "\x9A\x03\x01\x01", + 86), + packedTestUnpackedTypes_( + "\x0A\x01\x01" + "\x12\x01\x01" + "\x1A\x01\x01" + "\x22\x01\x01" + "\x2A\x01\x02" + "\x32\x01\x02" + "\x3A\x04\x01\x00\x00\x00" + "\x42\x08\x01\x00\x00\x00\x00\x00\x00\x00" + "\x4A\x04\x01\x00\x00\x00" + "\x52\x08\x01\x00\x00\x00\x00\x00\x00\x00" + "\x5A\x04\x00\x00\x80\x3f" + "\x62\x08\x00\x00\x00\x00\x00\x00\xf0\x3f" + "\x6A\x01\x01" + "\x72\x01\x01", + 72), + unpackedTestAllTypes_( + "\xF8\x01\x01" + "\x80\x02\x01" + "\x88\x02\x01" + "\x90\x02\x01" + "\x98\x02\x02" + "\xA0\x02\x02" + "\xAD\x02\x01\x00\x00\x00" + "\xB1\x02\x01\x00\x00\x00\x00\x00\x00\x00" + "\xBD\x02\x01\x00\x00\x00" + "\xC1\x02\x01\x00\x00\x00\x00\x00\x00\x00" + "\xCD\x02\x00\x00\x80\x3f" + "\xD1\x02\x00\x00\x00\x00\x00\x00\xf0\x3f" + "\xD8\x02\x01" + "\x98\x03\x01", + 72), + unpackedTestUnpackedTypes_( + "\x08\x01" + "\x10\x01" + "\x18\x01" + "\x20\x01" + "\x28\x02" + "\x30\x02" + "\x3D\x01\x00\x00\x00" + "\x41\x01\x00\x00\x00\x00\x00\x00\x00" + "\x4D\x01\x00\x00\x00" + "\x51\x01\x00\x00\x00\x00\x00\x00\x00" + "\x5D\x00\x00\x80\x3f" + "\x61\x00\x00\x00\x00\x00\x00\xf0\x3f" + "\x68\x01" + "\x70\x01", + 58) {} template void SetProto3PrimitiveRepeatedFields(Proto* message) { message->add_repeated_int32(1); @@ -837,8 +901,7 @@ class Proto3PrimitiveRepeatedWireFormatTest } template - void TestProto3PrimitiveRepeatedFields(Proto* message, - const string& expected) { + void TestSerialization(Proto* message, const string& expected) { SetProto3PrimitiveRepeatedFields(message); int size = message->ByteSize(); @@ -851,13 +914,8 @@ class Proto3PrimitiveRepeatedWireFormatTest message->SerializeWithCachedSizes(&output); ASSERT_FALSE(output.HadError()); } - EXPECT_TRUE(expected == generated_data); - message->Clear(); - message->ParseFromString(generated_data); - ExpectProto3PrimitiveRepeatedFieldsSet(*message); - // Serialize using the dynamic code. string dynamic_data; { @@ -866,64 +924,38 @@ class Proto3PrimitiveRepeatedWireFormatTest WireFormat::SerializeWithCachedSizes(*message, size, &output); ASSERT_FALSE(output.HadError()); } - EXPECT_TRUE(expected == dynamic_data); + } + + template + void TestParsing(Proto* message, const string& compatible_data) { + message->Clear(); + message->ParseFromString(compatible_data); + ExpectProto3PrimitiveRepeatedFieldsSet(*message); message->Clear(); io::CodedInputStream input( - reinterpret_cast(dynamic_data.data()), - dynamic_data.size()); + reinterpret_cast(compatible_data.data()), + compatible_data.size()); WireFormat::ParseAndMergePartial(&input, message); ExpectProto3PrimitiveRepeatedFieldsSet(*message); } + + const string packedTestAllTypes_; + const string packedTestUnpackedTypes_; + const string unpackedTestAllTypes_; + const string unpackedTestUnpackedTypes_; }; -INSTANTIATE_TEST_CASE_P(SetPacked, - Proto3PrimitiveRepeatedWireFormatTest, - ::testing::Values(false, true)); -TEST_P(Proto3PrimitiveRepeatedWireFormatTest, Proto3PrimitiveRepeated) { +TEST_F(Proto3PrimitiveRepeatedWireFormatTest, Proto3PrimitiveRepeated) { proto3_arena_unittest::TestAllTypes packed_message; proto3_arena_unittest::TestUnpackedTypes unpacked_message; - - const string packedExpected( - "\xFA\x01\x01\x01" - "\x82\x02\x01\x01" - "\x8A\x02\x01\x01" - "\x92\x02\x01\x01" - "\x9A\x02\x01\x02" - "\xA2\x02\x01\x02" - "\xAA\x02\x04\x01\x00\x00\x00" - "\xB2\x02\x08\x01\x00\x00\x00\x00\x00\x00\x00" - "\xBA\x02\x04\x01\x00\x00\x00" - "\xC2\x02\x08\x01\x00\x00\x00\x00\x00\x00\x00" - "\xCA\x02\x04\x00\x00\x80\x3f" - "\xD2\x02\x08\x00\x00\x00\x00\x00\x00\xf0\x3f" - "\xDA\x02\x01\x01" - "\x9A\x03\x01\x01", - 86); - - const string unpackedExpected( - "\x08\x01" - "\x10\x01" - "\x18\x01" - "\x20\x01" - "\x28\x02" - "\x30\x02" - "\x3D\x01\x00\x00\x00" - "\x41\x01\x00\x00\x00\x00\x00\x00\x00" - "\x4D\x01\x00\x00\x00" - "\x51\x01\x00\x00\x00\x00\x00\x00\x00" - "\x5D\x00\x00\x80\x3f" - "\x61\x00\x00\x00\x00\x00\x00\xf0\x3f" - "\x68\x01" - "\x70\x01", - 58); - - if (GetParam()) { - TestProto3PrimitiveRepeatedFields(&packed_message, packedExpected); - } else { - TestProto3PrimitiveRepeatedFields(&unpacked_message, unpackedExpected); - } + TestSerialization(&packed_message, packedTestAllTypes_); + TestParsing(&packed_message, packedTestAllTypes_); + TestParsing(&packed_message, unpackedTestAllTypes_); + TestSerialization(&unpacked_message, unpackedTestUnpackedTypes_); + TestParsing(&unpacked_message, packedTestUnpackedTypes_); + TestParsing(&unpacked_message, unpackedTestUnpackedTypes_); } class WireFormatInvalidInputTest : public testing::Test { -- cgit v1.2.3 From 658e72d8fb7599d566e843070ec90f8d0c9141c5 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 24 Jun 2015 14:30:33 -0700 Subject: fix compiler warnings. - control reaches end of non-void function. - remove a deprecated IsMatch. Change-Id: Ifdeb15879bbcf591c48dc7fda1cd8994bdf87bb3 --- src/google/protobuf/util/field_comparator.cc | 1 + src/google/protobuf/util/internal/type_info_test_helper.cc | 3 +++ src/google/protobuf/util/message_differencer.h | 13 ++----------- 3 files changed, 6 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/util/field_comparator.cc b/src/google/protobuf/util/field_comparator.cc index b7676a88..9f613265 100644 --- a/src/google/protobuf/util/field_comparator.cc +++ b/src/google/protobuf/util/field_comparator.cc @@ -106,6 +106,7 @@ FieldComparator::ComparisonResult DefaultFieldComparator::Compare( default: GOOGLE_LOG(FATAL) << "No comparison code for field " << field->full_name() << " of CppType = " << field->cpp_type(); + return DIFFERENT; } } diff --git a/src/google/protobuf/util/internal/type_info_test_helper.cc b/src/google/protobuf/util/internal/type_info_test_helper.cc index f7aea857..177b96e2 100644 --- a/src/google/protobuf/util/internal/type_info_test_helper.cc +++ b/src/google/protobuf/util/internal/type_info_test_helper.cc @@ -97,6 +97,7 @@ ProtoStreamObjectSource* TypeInfoTestHelper::NewProtoSource( } } GOOGLE_LOG(FATAL) << "Can not reach here."; + return NULL; } ProtoStreamObjectWriter* TypeInfoTestHelper::NewProtoWriter( @@ -110,6 +111,7 @@ ProtoStreamObjectWriter* TypeInfoTestHelper::NewProtoWriter( } } GOOGLE_LOG(FATAL) << "Can not reach here."; + return NULL; } DefaultValueObjectWriter* TypeInfoTestHelper::NewDefaultValueWriter( @@ -121,6 +123,7 @@ DefaultValueObjectWriter* TypeInfoTestHelper::NewDefaultValueWriter( } } GOOGLE_LOG(FATAL) << "Can not reach here."; + return NULL; } } // namespace testing diff --git a/src/google/protobuf/util/message_differencer.h b/src/google/protobuf/util/message_differencer.h index 05548897..e002a0f3 100644 --- a/src/google/protobuf/util/message_differencer.h +++ b/src/google/protobuf/util/message_differencer.h @@ -289,20 +289,11 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { MapKeyComparator(); virtual ~MapKeyComparator(); - // The first IsMatch without parent_fields is only for backward - // compatibility. New users should override the second one instead. - // - // Deprecated. - // TODO(ykzhu): remove this function. - virtual bool IsMatch(const Message& message1, - const Message& message2) const { - GOOGLE_CHECK(false) << "This function shouldn't get called"; - return false; - } virtual bool IsMatch(const Message& message1, const Message& message2, const vector& parent_fields) const { - return IsMatch(message1, message2); + GOOGLE_CHECK(false) << "IsMatch() is not implemented."; + return false; } private: -- cgit v1.2.3 From 43dcbbfec7e906ede3d383a0139a05ff8a03481f Mon Sep 17 00:00:00 2001 From: Matt Giuca Date: Tue, 30 Jun 2015 17:23:24 +1000 Subject: Fix "sometimes-uninitialized" warning on Windows Clang. --- src/google/protobuf/compiler/subprocess.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc index 61ae4381..a3cff1f8 100644 --- a/src/google/protobuf/compiler/subprocess.cc +++ b/src/google/protobuf/compiler/subprocess.cc @@ -171,7 +171,7 @@ bool Subprocess::Communicate(const Message& input, Message* output, DWORD wait_result = WaitForMultipleObjects(handle_count, handles, FALSE, INFINITE); - HANDLE signaled_handle; + HANDLE signaled_handle = NULL; if (wait_result >= WAIT_OBJECT_0 && wait_result < WAIT_OBJECT_0 + handle_count) { signaled_handle = handles[wait_result - WAIT_OBJECT_0]; -- cgit v1.2.3 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') 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 From 9f563bd0d8863da35524f7d0a6f87abb2ec228a3 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 6 Jul 2015 16:07:57 -0700 Subject: Internal local modifications. --- python/google/protobuf/internal/test_util.py | 7 + src/Makefile.am | 1 - .../compiler/objectivec/objectivec_helpers.cc | 1 + src/google/protobuf/map.h | 3 +- src/google/protobuf/map_entry_lite.h | 12 ++ .../stubs/atomicops_internals_generic_gcc.h | 4 +- src/google/protobuf/stubs/common.h | 20 ++- src/google/protobuf/stubs/hash.h | 117 ++++++++++++++++- src/google/protobuf/stubs/pbconfig.h | 142 --------------------- src/google/protobuf/testing/zcgunzip.cc | 9 ++ src/google/protobuf/testing/zcgzip.cc | 9 ++ 11 files changed, 167 insertions(+), 158 deletions(-) delete mode 100644 src/google/protobuf/stubs/pbconfig.h (limited to 'src') diff --git a/python/google/protobuf/internal/test_util.py b/python/google/protobuf/internal/test_util.py index 0cbdbad9..fec65382 100755 --- a/python/google/protobuf/internal/test_util.py +++ b/python/google/protobuf/internal/test_util.py @@ -602,6 +602,13 @@ def GoldenFile(filename): return open(full_path, 'rb') path = os.path.join(path, '..') + # Search internally. + path = '.' + full_path = os.path.join(path, 'third_party/py/google/protobuf/testdata', filename) + if os.path.exists(full_path): + # Found it. Load the golden file from the testdata directory. + return open(full_path, 'rb') + raise RuntimeError( 'Could not find golden files. This test must be run from within the ' 'protobuf source package so that it can read test data files from the ' diff --git a/src/Makefile.am b/src/Makefile.am index 5b28579f..effe2a4a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -76,7 +76,6 @@ nobase_include_HEADERS = \ google/protobuf/stubs/fastmem.h \ google/protobuf/stubs/hash.h \ google/protobuf/stubs/once.h \ - google/protobuf/stubs/pbconfig.h \ google/protobuf/stubs/platform_macros.h \ google/protobuf/stubs/shared_ptr.h \ google/protobuf/stubs/singleton.h \ diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 9b645f09..45d122d1 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -28,6 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include #include #include #include diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index 96d2f201..163ce9dc 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -168,7 +168,8 @@ class Map { } } -#if __cplusplus >= 201103L && !defined(GOOGLE_PROTOBUF_OS_APPLE) +#if __cplusplus >= 201103L && !defined(GOOGLE_PROTOBUF_OS_APPLE) && \ + !defined(GOOGLE_PROTOBUF_OS_NACL) && !defined(GOOGLE_PROTOBUF_OS_ANDROID) template void construct(NodeType* p, Args&&... args) { new (p) NodeType(std::forward(args)...); diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index 52746da5..8de11766 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -162,7 +162,19 @@ class MapEntryLite : public MessageLite { if (!KeyWireHandler::Read(input, mutable_key())) return false; set_has_key(); if (!input->ExpectTag(kValueTag)) break; + // BEGIN GOOGLE LOCAL MODIFICATION + // Add __has_cpp_attribute and NaCl and Emscripten checks. +#if defined(__clang__) && defined(__has_cpp_attribute) \ + && !defined(GOOGLE_PROTOBUF_OS_APPLE) +#if defined(GOOGLE_PROTOBUF_OS_NACL) || defined(EMSCRIPTEN) + [[clang::fallthrough]]; +#elif __has_cpp_attribute(clang::fallthrough) + [[clang::fallthrough]]; +#endif +#else GOOGLE_FALLTHROUGH_INTENDED; +#endif + // END GOOGLE LOCAL MODIFICATION case kValueTag: if (!ValueWireHandler::Read(input, mutable_value())) return false; diff --git a/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h b/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h index dd7abf6f..a0116a60 100644 --- a/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h +++ b/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h @@ -61,8 +61,8 @@ inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value) { - __atomic_compare_exchange(ptr, &old_value, &new_value, true, - __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); + __atomic_compare_exchange_n(ptr, &old_value, new_value, true, + __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return old_value; } diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 3eb57a9b..3a081e60 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -203,14 +203,22 @@ typedef unsigned __int16 uint16; typedef unsigned __int32 uint32; typedef unsigned __int64 uint64; #else -typedef int8_t int8; -typedef int16_t int16; -typedef int32_t int32; +typedef signed char int8; +typedef short int16; +typedef int int32; +// NOTE: This should be "long long" for consistency with upstream, but +// something is stacked against this particular type for 64bit hashing. +// Switching it causes an obvious missing hash function (with an unobvious +// cause) when building the tests. typedef int64_t int64; -typedef uint8_t uint8; -typedef uint16_t uint16; -typedef uint32_t uint32; +typedef unsigned char uint8; +typedef unsigned short uint16; +typedef unsigned int uint32; +// NOTE: This should be "unsigned long long" for consistency with upstream, but +// something is stacked against this particular type for 64bit hashing. +// Switching it causes an obvious missing hash function (with an unobvious +// cause) when building the tests. typedef uint64_t uint64; #endif diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h index 4da8a5d8..9a6b217a 100755 --- a/src/google/protobuf/stubs/hash.h +++ b/src/google/protobuf/stubs/hash.h @@ -37,12 +37,117 @@ #include #include -#include + +#define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1 +#define GOOGLE_PROTOBUF_HAVE_HASH_SET 1 + +// Use C++11 unordered_{map|set} if available. Otherwise, libc++ always support +// unordered_{map|set} +#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X) || \ + defined(_LIBCPP_VERSION) +# define GOOGLE_PROTOBUF_HAS_CXX11_HASH + +// For XCode >= 4.6: the compiler is clang with libc++. +// For earlier XCode version: the compiler is gcc-4.2.1 with libstdc++. +// libc++ provides and friends even in non C++11 mode, +// and it does not provide the tr1 library. Therefore the following macro +// checks against this special case. +// Note that we should not test the __APPLE_CC__ version number or the +// __clang__ macro, since the new compiler can still use -stdlib=libstdc++, in +// which case is not compilable without -std=c++11 +#elif defined(__APPLE_CC__) +# if __GNUC__ >= 4 +# define GOOGLE_PROTOBUF_HAS_TR1 +# else +// Not tested for gcc < 4... These setting can compile under 4.2.1 though. +# define GOOGLE_PROTOBUF_HASH_NAMESPACE __gnu_cxx +# include +# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map +# include +# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set +# endif + +// Version checks for gcc. +#elif defined(__GNUC__) +// For GCC 4.x+, use tr1::unordered_map/set; otherwise, follow the +// instructions from: +// https://gcc.gnu.org/onlinedocs/libstdc++/manual/backwards.html +# if __GNUC__ >= 4 +# define GOOGLE_PROTOBUF_HAS_TR1 +# elif __GNUC__ >= 3 +# include +# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map +# include +# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set +# if __GNUC__ == 3 && __GNUC_MINOR__ == 0 +# define GOOGLE_PROTOBUF_HASH_NAMESPACE std // GCC 3.0 +# else +# define GOOGLE_PROTOBUF_HASH_NAMESPACE __gnu_cxx // GCC 3.1 and later +# endif +# else +# define GOOGLE_PROTOBUF_HASH_NAMESPACE +# include +# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map +# include +# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set +# endif + +// Version checks for MSC. +// Apparently Microsoft decided to move hash_map *back* to the std namespace in +// MSVC 2010: +// http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx +// And.. they are moved back to stdext in MSVC 2013 (haven't checked 2012). That +// said, use unordered_map for MSVC 2010 and beyond is our safest bet. +#elif defined(_MSC_VER) +# if _MSC_VER >= 1600 // Since Visual Studio 2010 +# define GOOGLE_PROTOBUF_HAS_CXX11_HASH +# define GOOGLE_PROTOBUF_HASH_COMPARE std::hash_compare +# elif _MSC_VER >= 1500 // Since Visual Studio 2008 +# define GOOGLE_PROTOBUF_HAS_TR1 +# define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare +# elif _MSC_VER >= 1310 +# define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext +# include +# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map +# include +# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set +# define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare +# else +# define GOOGLE_PROTOBUF_HASH_NAMESPACE std +# include +# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map +# include +# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set +# define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare +# endif + +// **ADD NEW COMPILERS SUPPORT HERE.** +// For other compilers, undefine the macro and fallback to use std::map, in +// google/protobuf/stubs/hash.h +#else +# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP +# undef GOOGLE_PROTOBUF_HAVE_HASH_SET +#endif + +#if defined(GOOGLE_PROTOBUF_HAS_CXX11_HASH) +# define GOOGLE_PROTOBUF_HASH_NAMESPACE std +# include +# define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map +# include +# define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set +#elif defined(GOOGLE_PROTOBUF_HAS_TR1) +# define GOOGLE_PROTOBUF_HASH_NAMESPACE std::tr1 +# include +# define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map +# include +# define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set +#endif + +#undef GOOGLE_PROTOBUF_HAS_CXX11_HASH +#undef GOOGLE_PROTOBUF_HAS_TR1 #if defined(GOOGLE_PROTOBUF_HAVE_HASH_MAP) && \ defined(GOOGLE_PROTOBUF_HAVE_HASH_SET) -#include GOOGLE_PROTOBUF_HASH_MAP_H -#include GOOGLE_PROTOBUF_HASH_SET_H #else #define GOOGLE_PROTOBUF_MISSING_HASH #include @@ -92,13 +197,13 @@ template , typename EqualKey = std::equal_to, typename Alloc = std::allocator< std::pair > > -class hash_map : public std::map { - typedef std::map BaseClass; +class hash_map : public std::map { + typedef std::map BaseClass; public: hash_map(int a = 0, const HashFcn& b = HashFcn(), const EqualKey& c = EqualKey(), - const Alloc& d = Alloc()) : BaseClass(a, b, c, d) {} + const Alloc& d = Alloc()) : BaseClass(b, d) {} }; template = 201103L || defined(__GXX_EXPERIMENTAL_CXX0X) -# define GOOGLE_PROTOBUF_HAS_CXX11_HASH - -// For XCode >= 4.6: the compiler is clang with libc++. -// For earlier XCode version: the compiler is gcc-4.2.1 with libstdc++. -// libc++ provides and friends even in non C++11 mode, -// and it does not provide the tr1 library. Therefore the following macro -// checks against this special case. -// Note that we should not test the __APPLE_CC__ version number or the -// __clang__ macro, since the new compiler can still use -stdlib=libstdc++, in -// which case is not compilable without -std=c++11 -#elif defined(__APPLE_CC__) -# if defined(_LIBCPP_VERSION) -# define GOOGLE_PROTOBUF_HAS_CXX11_HASH -# elif __GNUC__ >= 4 -# define GOOGLE_PROTOBUF_HAS_TR1 -# else -// Not tested for gcc < 4... These setting can compile under 4.2.1 though. -# define GOOGLE_PROTOBUF_HASH_NAMESPACE __gnu_cxx -# define GOOGLE_PROTOBUF_HASH_MAP_H -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# define GOOGLE_PROTOBUF_HASH_SET_H -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# endif - -// Version checks for gcc. -#elif defined(__GNUC__) -// For GCC 4.x+, use tr1::unordered_map/set; otherwise, follow the -// instructions from: -// https://gcc.gnu.org/onlinedocs/libstdc++/manual/backwards.html -# if __GNUC__ >= 4 -# define GOOGLE_PROTOBUF_HAS_TR1 -# elif __GNUC__ >= 3 -# define GOOGLE_PROTOBUF_HASH_MAP_H -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# define GOOGLE_PROTOBUF_HASH_SET_H -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# if __GNUC__ == 3 && __GNUC_MINOR__ == 0 -# define GOOGLE_PROTOBUF_HASH_NAMESPACE std // GCC 3.0 -# else -# define GOOGLE_PROTOBUF_HASH_NAMESPACE __gnu_cxx // GCC 3.1 and later -# endif -# else -# define GOOGLE_PROTOBUF_HASH_NAMESPACE -# define GOOGLE_PROTOBUF_HASH_MAP_H -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# define GOOGLE_PROTOBUF_HASH_SET_H -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# endif - -// Version checks for MSC. -// Apparently Microsoft decided to move hash_map *back* to the std namespace in -// MSVC 2010: -// http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx -// And.. they are moved back to stdext in MSVC 2013 (haven't checked 2012). That -// said, use unordered_map for MSVC 2010 and beyond is our safest bet. -#elif defined(_MSC_VER) -# if _MSC_VER >= 1600 // Since Visual Studio 2010 -# define GOOGLE_PROTOBUF_HAS_CXX11_HASH -# define GOOGLE_PROTOBUF_HASH_COMPARE std::hash_compare -# elif _MSC_VER >= 1500 // Since Visual Studio 2008 -# define GOOGLE_PROTOBUF_HAS_TR1 -# define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare -# elif _MSC_VER >= 1310 -# define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext -# define GOOGLE_PROTOBUF_HASH_MAP_H -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# define GOOGLE_PROTOBUF_HASH_SET_H -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare -# else -# define GOOGLE_PROTOBUF_HASH_NAMESPACE std -# define GOOGLE_PROTOBUF_HASH_MAP_H -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# define GOOGLE_PROTOBUF_HASH_SET_H -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare -# endif - -// **ADD NEW COMPILERS SUPPORT HERE.** -// For other compilers, undefine the macro and fallback to use std::map, in -// google/protobuf/stubs/hash.h -#else -# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP -# undef GOOGLE_PROTOBUF_HAVE_HASH_SET -#endif - -#if defined(GOOGLE_PROTOBUF_HAS_CXX11_HASH) -# define GOOGLE_PROTOBUF_HASH_NAMESPACE std -# define GOOGLE_PROTOBUF_HASH_MAP_H -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map -# define GOOGLE_PROTOBUF_HASH_SET_H -# define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set -#elif defined(GOOGLE_PROTOBUF_HAS_TR1) -# define GOOGLE_PROTOBUF_HASH_NAMESPACE std::tr1 -# define GOOGLE_PROTOBUF_HASH_MAP_H -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map -# define GOOGLE_PROTOBUF_HASH_SET_H -# define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set -#endif - -#undef GOOGLE_PROTOBUF_HAS_CXX11_HASH -#undef GOOGLE_PROTOBUF_HAS_TR1 - -#endif // GOOGLE_PROTOBUF_STUBS_PBCONFIG_H__ diff --git a/src/google/protobuf/testing/zcgunzip.cc b/src/google/protobuf/testing/zcgunzip.cc index c9d085c8..76f8cfe1 100644 --- a/src/google/protobuf/testing/zcgunzip.cc +++ b/src/google/protobuf/testing/zcgunzip.cc @@ -43,6 +43,15 @@ #include #include +#ifdef _WIN32 +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#endif +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif +#endif + #include #include diff --git a/src/google/protobuf/testing/zcgzip.cc b/src/google/protobuf/testing/zcgzip.cc index e910f321..992ddc6e 100644 --- a/src/google/protobuf/testing/zcgzip.cc +++ b/src/google/protobuf/testing/zcgzip.cc @@ -42,6 +42,15 @@ #include #include +#ifdef _WIN32 +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#endif +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif +#endif + #include #include -- cgit v1.2.3