Browse Source

Fix compile issues and test failures in VS2008.

Feng Xiao 11 years ago
parent
commit
be20ae0b69

+ 1 - 1
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();

+ 6 - 6
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());

+ 0 - 1
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>

+ 1 - 1
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);

+ 0 - 35
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

+ 17 - 17
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);
     }
   }
 }

+ 2 - 0
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) {

+ 9 - 4
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;

+ 1 - 2
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);

+ 2 - 2
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);
 }
 

+ 0 - 1
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>
 

+ 4 - 3
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
 

+ 1 - 1
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());
 }
 

+ 68 - 16
vsprojects/libprotoc.vcproj

@@ -323,22 +323,6 @@
 				RelativePath="..\src\google\protobuf\compiler\command_line_interface.cc"
 				>
 			</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"
 				>
@@ -367,6 +351,10 @@
 				RelativePath="..\src\google\protobuf\compiler\cpp\cpp_helpers.cc"
 				>
 			</File>
+			<File
+				RelativePath="..\src\google\protobuf\compiler\cpp\cpp_map_field.cc"
+				>
+			</File>
 			<File
 				RelativePath="..\src\google\protobuf\compiler\cpp\cpp_message.cc"
 				>
@@ -391,6 +379,10 @@
 				RelativePath="..\src\google\protobuf\compiler\java\java_context.cc"
 				>
 			</File>
+			<File
+				RelativePath="..\src\google\protobuf\compiler\java\java_doc_comment.cc"
+				>
+			</File>
 			<File
 				RelativePath="..\src\google\protobuf\compiler\java\java_enum.cc"
 				>
@@ -427,6 +419,10 @@
 				RelativePath="..\src\google\protobuf\compiler\java\java_lazy_message_field.cc"
 				>
 			</File>
+			<File
+				RelativePath="..\src\google\protobuf\compiler\java\java_map_field.cc"
+				>
+			</File>
 			<File
 				RelativePath="..\src\google\protobuf\compiler\java\java_message.cc"
 				>
@@ -455,10 +451,66 @@
 				RelativePath="..\src\google\protobuf\compiler\java\java_string_field.cc"
 				>
 			</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>