diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2014-12-05 02:54:43 -0800 |
---|---|---|
committer | Feng Xiao <xfxyjwf@gmail.com> | 2014-12-05 02:54:43 -0800 |
commit | be20ae0b6975071563ecc61f8372fd7936f174ed (patch) | |
tree | ed4c27622fceb78410c74af287532379f475843e | |
parent | 7c939bcb25bff016ca63669c203e2ebfc0834825 (diff) |
Fix compile issues and test failures in VS2008.
-rw-r--r-- | src/google/protobuf/arena.cc | 2 | ||||
-rw-r--r-- | src/google/protobuf/arena_unittest.cc | 12 | ||||
-rwxr-xr-x | src/google/protobuf/arenastring.h | 1 | ||||
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_message.cc | 2 | ||||
-rw-r--r-- | src/google/protobuf/map_field_test.cc | 35 | ||||
-rw-r--r-- | src/google/protobuf/map_test_util.cc | 34 | ||||
-rw-r--r-- | src/google/protobuf/preserve_unknown_enum_test.cc | 2 | ||||
-rw-r--r-- | src/google/protobuf/repeated_field.h | 13 | ||||
-rw-r--r-- | src/google/protobuf/repeated_field_reflection_unittest.cc | 3 | ||||
-rw-r--r-- | src/google/protobuf/repeated_field_unittest.cc | 4 | ||||
-rw-r--r-- | src/google/protobuf/stubs/fastmem.h | 1 | ||||
-rw-r--r-- | src/google/protobuf/stubs/type_traits.h | 7 | ||||
-rw-r--r-- | src/google/protobuf/unknown_field_set_unittest.cc | 2 | ||||
-rw-r--r-- | vsprojects/libprotoc.vcproj | 84 |
14 files changed, 112 insertions, 90 deletions
diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc index 1cb6441e..2ce987cb 100644 --- a/src/google/protobuf/arena.cc +++ b/src/google/protobuf/arena.cc @@ -38,7 +38,7 @@ namespace google { namespace protobuf { google::protobuf::internal::SequenceNumber Arena::lifecycle_id_generator_; -__thread Arena::ThreadCache Arena::thread_cache_ = { -1, NULL }; +GOOGLE_THREAD_LOCAL Arena::ThreadCache Arena::thread_cache_ = { -1, NULL }; void Arena::Init(const ArenaOptions& options) { lifecycle_id_ = lifecycle_id_generator_.GetNext(); diff --git a/src/google/protobuf/arena_unittest.cc b/src/google/protobuf/arena_unittest.cc index 76a4274f..9d3d3e3e 100644 --- a/src/google/protobuf/arena_unittest.cc +++ b/src/google/protobuf/arena_unittest.cc @@ -128,7 +128,7 @@ TEST(ArenaTest, InitialBlockTooSmall) { // initial block. std::vector<char> arena_block(64); ArenaOptions options; - options.initial_block = arena_block.data(); + options.initial_block = &arena_block[0]; options.initial_block_size = arena_block.size(); Arena arena(options); @@ -137,7 +137,7 @@ TEST(ArenaTest, InitialBlockTooSmall) { // Ensure that the arena allocator did not return memory pointing into the // initial block of memory. - uintptr_t arena_start = reinterpret_cast<uintptr_t>(arena_block.data()); + uintptr_t arena_start = reinterpret_cast<uintptr_t>(&arena_block[0]); uintptr_t arena_end = arena_start + arena_block.size(); EXPECT_FALSE(allocation >= arena_start && allocation < arena_end); @@ -771,7 +771,7 @@ TEST(ArenaTest, RepeatedFieldOnArena) { // Preallocate an initial arena block to avoid mallocs during hooked region. std::vector<char> arena_block(1024 * 1024); ArenaOptions options; - options.initial_block = arena_block.data(); + options.initial_block = &arena_block[0]; options.initial_block_size = arena_block.size(); Arena arena(options); @@ -898,7 +898,7 @@ TEST(ArenaTest, NoHeapAllocationsTest) { // Allocate a large initial block to avoid mallocs during hooked test. std::vector<char> arena_block(128 * 1024); ArenaOptions options; - options.initial_block = arena_block.data(); + options.initial_block = &arena_block[0]; options.initial_block_size = arena_block.size(); Arena arena(options); @@ -918,7 +918,7 @@ TEST(ArenaTest, NoHeapAllocationsTest) { TEST(ArenaTest, MessageLiteOnArena) { std::vector<char> arena_block(128 * 1024); ArenaOptions options; - options.initial_block = arena_block.data(); + options.initial_block = &arena_block[0]; options.initial_block_size = arena_block.size(); Arena arena(options); const google::protobuf::MessageLite* prototype = dynamic_cast< @@ -977,7 +977,7 @@ TEST(ArenaTest, SpaceUsed) { // Test with initial block. std::vector<char> arena_block(1024); - options.initial_block = arena_block.data(); + options.initial_block = &arena_block[0]; options.initial_block_size = arena_block.size(); Arena arena_2(options); EXPECT_EQ(1024, arena_2.SpaceUsed()); diff --git a/src/google/protobuf/arenastring.h b/src/google/protobuf/arenastring.h index 50f13837..2adad16a 100755 --- a/src/google/protobuf/arenastring.h +++ b/src/google/protobuf/arenastring.h @@ -31,7 +31,6 @@ #ifndef GOOGLE_PROTOBUF_ARENASTRING_H__ #define GOOGLE_PROTOBUF_ARENASTRING_H__ -#include <stdint.h> #include <string> #include <google/protobuf/stubs/common.h> diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 212bc3e9..e71d35fa 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -1226,7 +1226,7 @@ GenerateDescriptorDeclarations(io::Printer* printer) { for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j); printer->Print(" "); - if (IsStringOrMessage(field)) { + if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { printer->Print("const "); } field_generators_.get(field).GeneratePrivateMembers(printer); diff --git a/src/google/protobuf/map_field_test.cc b/src/google/protobuf/map_field_test.cc index 98551839..045f8f2c 100644 --- a/src/google/protobuf/map_field_test.cc +++ b/src/google/protobuf/map_field_test.cc @@ -430,41 +430,6 @@ TEST_P(MapFieldStateTest, MutableMapField) { } } -class MapFieldBaseStateStub : public MapFieldBaseStub { - public: - MapFieldBaseStateStub(Mutex* mutex, int* clean_counter, - int* completed_counter) - : mutex_(mutex), - clean_counter_(clean_counter), - completed_counter_(completed_counter) {} - ~MapFieldBaseStateStub() {} - - protected: - void SyncRepeatedFieldWithMapNoLock() const { Clean(); } - void SyncMapWithRepeatedFieldNoLock() const { Clean(); } - - private: - void Clean() const { - { - MutexLock lock(mutex_); - ++(*clean_counter_); - } - struct timespec tm; - tm.tv_sec = 0; - tm.tv_nsec = 100000000; // 100ms - nanosleep(&tm, NULL); - { - MutexLock lock(mutex_); - // No other thread should have completed while this one was initializing. - EXPECT_EQ(0, *completed_counter_); - } - } - Mutex* mutex_; - int* clean_counter_; - int* completed_counter_; -}; - - } // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/map_test_util.cc b/src/google/protobuf/map_test_util.cc index b27c8f19..eb7ea511 100644 --- a/src/google/protobuf/map_test_util.cc +++ b/src/google/protobuf/map_test_util.cc @@ -1020,7 +1020,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_int32_int32_key_); int32 val = sub_message->GetReflection()->GetInt32( *sub_message, map_int32_int32_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1034,7 +1034,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_int64_int64_key_); int64 val = sub_message->GetReflection()->GetInt64( *sub_message, map_int64_int64_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1048,7 +1048,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_uint32_uint32_key_); uint32 val = sub_message->GetReflection()->GetUInt32( *sub_message, map_uint32_uint32_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1062,7 +1062,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_uint64_uint64_key_); uint64 val = sub_message->GetReflection()->GetUInt64( *sub_message, map_uint64_uint64_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1076,7 +1076,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_sint32_sint32_key_); int32 val = sub_message->GetReflection()->GetInt32( *sub_message, map_sint32_sint32_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1090,7 +1090,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_sint64_sint64_key_); int64 val = sub_message->GetReflection()->GetInt64( *sub_message, map_sint64_sint64_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1104,7 +1104,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_fixed32_fixed32_key_); uint32 val = sub_message->GetReflection()->GetUInt32( *sub_message, map_fixed32_fixed32_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1118,7 +1118,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_fixed64_fixed64_key_); uint64 val = sub_message->GetReflection()->GetUInt64( *sub_message, map_fixed64_fixed64_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1132,7 +1132,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_sfixed32_sfixed32_key_); int32 val = sub_message->GetReflection()->GetInt32( *sub_message, map_sfixed32_sfixed32_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1146,7 +1146,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_sfixed64_sfixed64_key_); int64 val = sub_message->GetReflection()->GetInt64( *sub_message, map_sfixed64_sfixed64_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1160,7 +1160,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_int32_float_key_); float val = sub_message->GetReflection()->GetFloat( *sub_message, map_int32_float_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1174,7 +1174,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_int32_double_key_); double val = sub_message->GetReflection()->GetDouble( *sub_message, map_int32_double_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1188,7 +1188,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_bool_bool_key_); bool val = sub_message->GetReflection()->GetBool( *sub_message, map_bool_bool_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1202,7 +1202,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_string_string_key_); string val = sub_message->GetReflection()->GetString( *sub_message, map_string_string_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1216,7 +1216,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_int32_bytes_key_); string val = sub_message->GetReflection()->GetString( *sub_message, map_int32_bytes_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1230,7 +1230,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_int32_enum_key_); const EnumValueDescriptor* val = sub_message->GetReflection()->GetEnum( *sub_message, map_int32_enum_val_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } { @@ -1246,7 +1246,7 @@ void MapTestUtil::MapReflectionTester::ExpectMapFieldsSetViaReflection( *sub_message, map_int32_foreign_message_val_); int32 val = foreign_message.GetReflection()->GetInt32( foreign_message, foreign_c_); - EXPECT_EQ(map.at(key), val); + EXPECT_EQ(map[key], val); } } } diff --git a/src/google/protobuf/preserve_unknown_enum_test.cc b/src/google/protobuf/preserve_unknown_enum_test.cc index 33e9ea10..816e52ca 100644 --- a/src/google/protobuf/preserve_unknown_enum_test.cc +++ b/src/google/protobuf/preserve_unknown_enum_test.cc @@ -200,6 +200,7 @@ TEST(PreserveUnknownEnumTest, Proto2CatchesUnknownValues) { EXPECT_TRUE(enum_value != NULL); r->AddEnum(&message, repeated_field, enum_value); +#ifdef PROTOBUF_HAS_DEATH_TEST // Enum-field integer-based setters GOOGLE_DCHECK-fail on invalid values, in order to // remain consistent with proto2 generated code. EXPECT_DEBUG_DEATH({ @@ -214,6 +215,7 @@ TEST(PreserveUnknownEnumTest, Proto2CatchesUnknownValues) { r->AddEnumValue(&message, repeated_field, 4242); r->GetRepeatedEnum(message, repeated_field, 1); }, "AddEnumValue accepts only valid integer values"); +#endif // PROTOBUF_HAS_DEATH_TEST } TEST(PreserveUnknownEnumTest, SupportsUnknownEnumValuesAPI) { diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index e14dcc62..4798eeda 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -236,10 +236,11 @@ class RepeatedField { Arena* arena; Element elements[1]; }; - // Why not sizeof(Rep) - sizeof(Element)? Because this is not accurate w.r.t. - // trailing padding on the struct -- e.g. if Element is int, this would yield - // 12 on x86-64, not 8 as we want. - static const size_t kRepHeaderSize = sizeof(Arena*); + // We can not use sizeof(Rep) - sizeof(Element) due to the trailing padding on + // the struct. We can not use sizeof(Arena*) as well because there might be + // a "gap" after the field arena and before the field elements (e.g., when + // Element is double and pointer is 32bit). + static const size_t kRepHeaderSize; // Contains arena ptr and the elements array. We also keep the invariant that // if rep_ is NULL, then arena is NULL. Rep* rep_; @@ -263,6 +264,10 @@ class RepeatedField { } }; +template<typename Element> +const size_t RepeatedField<Element>::kRepHeaderSize = + reinterpret_cast<size_t>(&reinterpret_cast<Rep*>(16)->elements[0]) - 16; + namespace internal { template <typename It> class RepeatedPtrIterator; template <typename It, typename VoidPtr> class RepeatedPtrOverPtrsIterator; diff --git a/src/google/protobuf/repeated_field_reflection_unittest.cc b/src/google/protobuf/repeated_field_reflection_unittest.cc index 00252674..8b821806 100644 --- a/src/google/protobuf/repeated_field_reflection_unittest.cc +++ b/src/google/protobuf/repeated_field_reflection_unittest.cc @@ -196,8 +196,7 @@ void TestRepeatedFieldRefIterator( int index = 0; for (typename Ref::const_iterator it = handle.begin(); it != handle.end(); ++it) { - ValueType value = static_cast<ValueType>(*it); - EXPECT_EQ((message.*GetFunc)(index), value); + EXPECT_EQ((message.*GetFunc)(index), *it); ++index; } EXPECT_EQ(handle.size(), index); diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index 9942af50..15c0c93e 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -92,8 +92,8 @@ TEST(RepeatedField, Small) { EXPECT_TRUE(field.empty()); EXPECT_EQ(field.size(), 0); - // Additional 8 bytes are for 'struct Rep' header. - int expected_usage = 4 * sizeof(int) + 8; + // Additional bytes are for 'struct Rep' header. + int expected_usage = 4 * sizeof(int) + sizeof(Arena*); EXPECT_EQ(field.SpaceUsedExcludingSelf(), expected_usage); } diff --git a/src/google/protobuf/stubs/fastmem.h b/src/google/protobuf/stubs/fastmem.h index e553f142..763a6e60 100644 --- a/src/google/protobuf/stubs/fastmem.h +++ b/src/google/protobuf/stubs/fastmem.h @@ -46,7 +46,6 @@ #define GOOGLE_PROTOBUF_STUBS_FASTMEM_H_ #include <stddef.h> -#include <stdint.h> #include <stdio.h> #include <string.h> diff --git a/src/google/protobuf/stubs/type_traits.h b/src/google/protobuf/stubs/type_traits.h index 0c294677..b58cae3f 100644 --- a/src/google/protobuf/stubs/type_traits.h +++ b/src/google/protobuf/stubs/type_traits.h @@ -339,6 +339,9 @@ struct ConvertHelper { static small_ Test(To); static big_ Test(...); static From Create(); + enum { + value = sizeof(Test(Create())) == sizeof(small_) + }; }; } // namespace type_traits_internal @@ -346,9 +349,7 @@ struct ConvertHelper { template <typename From, typename To> struct is_convertible : integral_constant<bool, - sizeof(type_traits_internal::ConvertHelper<From, To>::Test( - type_traits_internal::ConvertHelper<From, To>::Create())) - == sizeof(small_)> { + type_traits_internal::ConvertHelper<From, To>::value> { }; #endif diff --git a/src/google/protobuf/unknown_field_set_unittest.cc b/src/google/protobuf/unknown_field_set_unittest.cc index 6bba8fc7..9b02f0b0 100644 --- a/src/google/protobuf/unknown_field_set_unittest.cc +++ b/src/google/protobuf/unknown_field_set_unittest.cc @@ -485,7 +485,7 @@ TEST_F(UnknownFieldSetTest, UnknownEnumValue) { TEST_F(UnknownFieldSetTest, SpaceUsedExcludingSelf) { UnknownFieldSet empty; empty.AddVarint(1, 0); - EXPECT_EQ(/* vector<UnknownField> */ 24 + /* sizeof(UnknownField) */ 16, + EXPECT_EQ(sizeof(vector<UnknownField>) + sizeof(UnknownField), empty.SpaceUsedExcludingSelf()); } diff --git a/vsprojects/libprotoc.vcproj b/vsprojects/libprotoc.vcproj index ccbc0b36..1feac924 100644 --- a/vsprojects/libprotoc.vcproj +++ b/vsprojects/libprotoc.vcproj @@ -324,22 +324,6 @@ > </File> <File - RelativePath="..\src\google\protobuf\compiler\subprocess.cc" - > - </File> - <File - RelativePath="..\src\google\protobuf\compiler\zip_writer.cc" - > - </File> - <File - RelativePath="..\src\google\protobuf\compiler\plugin.cc" - > - </File> - <File - RelativePath="..\src\google\protobuf\compiler\plugin.pb.cc" - > - </File> - <File RelativePath="..\src\google\protobuf\compiler\cpp\cpp_enum.cc" > </File> @@ -368,6 +352,10 @@ > </File> <File + RelativePath="..\src\google\protobuf\compiler\cpp\cpp_map_field.cc" + > + </File> + <File RelativePath="..\src\google\protobuf\compiler\cpp\cpp_message.cc" > </File> @@ -392,6 +380,10 @@ > </File> <File + RelativePath="..\src\google\protobuf\compiler\java\java_doc_comment.cc" + > + </File> + <File RelativePath="..\src\google\protobuf\compiler\java\java_enum.cc" > </File> @@ -428,6 +420,10 @@ > </File> <File + RelativePath="..\src\google\protobuf\compiler\java\java_map_field.cc" + > + </File> + <File RelativePath="..\src\google\protobuf\compiler\java\java_message.cc" > </File> @@ -456,9 +452,65 @@ > </File> <File + RelativePath="..\src\google\protobuf\compiler\javanano\javanano_enum.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\javanano\javanano_enum_field.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\javanano\javanano_extension.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\javanano\javanano_field.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\javanano\javanano_file.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\javanano\javanano_generator.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\javanano\javanano_helpers.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\javanano\javanano_message.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\javanano\javanano_message_field.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\javanano\javanano_primitive_field.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\plugin.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\plugin.pb.cc" + > + </File> + <File RelativePath="..\src\google\protobuf\compiler\python\python_generator.cc" > </File> + <File + RelativePath="..\src\google\protobuf\compiler\subprocess.cc" + > + </File> + <File + RelativePath="..\src\google\protobuf\compiler\zip_writer.cc" + > + </File> </Filter> </Files> <Globals> |