aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google
diff options
context:
space:
mode:
authorGravatar Feng Xiao <xfxyjwf@gmail.com>2014-12-05 02:54:43 -0800
committerGravatar Feng Xiao <xfxyjwf@gmail.com>2014-12-05 02:54:43 -0800
commitbe20ae0b6975071563ecc61f8372fd7936f174ed (patch)
treeed4c27622fceb78410c74af287532379f475843e /src/google
parent7c939bcb25bff016ca63669c203e2ebfc0834825 (diff)
Fix compile issues and test failures in VS2008.
Diffstat (limited to 'src/google')
-rw-r--r--src/google/protobuf/arena.cc2
-rw-r--r--src/google/protobuf/arena_unittest.cc12
-rwxr-xr-xsrc/google/protobuf/arenastring.h1
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.cc2
-rw-r--r--src/google/protobuf/map_field_test.cc35
-rw-r--r--src/google/protobuf/map_test_util.cc34
-rw-r--r--src/google/protobuf/preserve_unknown_enum_test.cc2
-rw-r--r--src/google/protobuf/repeated_field.h13
-rw-r--r--src/google/protobuf/repeated_field_reflection_unittest.cc3
-rw-r--r--src/google/protobuf/repeated_field_unittest.cc4
-rw-r--r--src/google/protobuf/stubs/fastmem.h1
-rw-r--r--src/google/protobuf/stubs/type_traits.h7
-rw-r--r--src/google/protobuf/unknown_field_set_unittest.cc2
13 files changed, 44 insertions, 74 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());
}