diff options
Diffstat (limited to 'src')
23 files changed, 275 insertions, 79 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 2ecf6028..33894dc1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -147,6 +147,7 @@ nobase_include_HEADERS = \ google/protobuf/compiler/java/java_names.h \ google/protobuf/compiler/javanano/javanano_generator.h \ google/protobuf/compiler/objectivec/objectivec_generator.h \ + google/protobuf/compiler/objectivec/objectivec_helpers.h \ google/protobuf/compiler/python/python_generator.h \ google/protobuf/compiler/ruby/ruby_generator.h \ google/protobuf/compiler/csharp/csharp_generator.h @@ -449,6 +450,8 @@ EXTRA_DIST = \ google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt \ google/protobuf/package_info.h \ google/protobuf/io/package_info.h \ + google/protobuf/compiler/ruby/ruby_generated_code.proto \ + google/protobuf/compiler/ruby/ruby_generated_code.rb \ google/protobuf/compiler/package_info.h \ google/protobuf/compiler/zip_output_unittest.sh \ google/protobuf/unittest_enormous_descriptor.proto diff --git a/src/google/protobuf/any.h b/src/google/protobuf/any.h index 757b45aa..f681eceb 100644 --- a/src/google/protobuf/any.h +++ b/src/google/protobuf/any.h @@ -43,7 +43,7 @@ namespace protobuf { namespace internal { // Helper class used to implement google::protobuf::Any. -class AnyMetadata { +class LIBPROTOBUF_EXPORT AnyMetadata { typedef ArenaStringPtr UrlType; typedef ArenaStringPtr ValueType; public: diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index 4adcd677..6c3f606e 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -413,12 +413,6 @@ class LIBPROTOBUF_EXPORT Arena { // trivially destructible. template <typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* CreateArray(::google::protobuf::Arena* arena, size_t num_elements) { -#if __cplusplus >= 201103L - static_assert(std::is_trivially_default_constructible<T>::value, - "CreateArray requires a trivially constructible type"); - static_assert(std::is_trivially_destructible<T>::value, - "CreateArray requires a trivially destructible type"); -#endif if (arena == NULL) { return static_cast<T*>(::operator new[](num_elements * sizeof(T))); } else { diff --git a/src/google/protobuf/arena_unittest.cc b/src/google/protobuf/arena_unittest.cc index 873e85ae..6c185695 100644 --- a/src/google/protobuf/arena_unittest.cc +++ b/src/google/protobuf/arena_unittest.cc @@ -30,8 +30,6 @@ #include <google/protobuf/arena.h> -#include <stdint.h> - #include <algorithm> #include <cstring> #include <memory> @@ -1232,8 +1230,11 @@ TEST(ArenaTest, ArenaHooksSanity) { EXPECT_EQ(1, ArenaHooksTestUtil::num_init); EXPECT_EQ(0, ArenaHooksTestUtil::num_allocations); ::google::protobuf::Arena::Create<uint64>(&arena); - EXPECT_EQ(1, ArenaHooksTestUtil::num_allocations); - + if (::google::protobuf::internal::has_trivial_destructor<uint64>::value) { + EXPECT_EQ(1, ArenaHooksTestUtil::num_allocations); + } else { + EXPECT_EQ(2, ArenaHooksTestUtil::num_allocations); + } arena.Reset(); arena.Reset(); EXPECT_EQ(2, ArenaHooksTestUtil::num_reset); diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 23d67e2b..e5b77c33 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -973,6 +973,9 @@ TEST_F(CommandLineInterfaceTest, WriteTransitiveDescriptorSetWithSourceInfo) { EXPECT_TRUE(descriptor_set.file(1).has_source_code_info()); } +#ifdef _WIN32 +// TODO(teboring): Figure out how to write test on windows. +#else TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileGivenTwoInputs) { CreateTempFile("foo.proto", "syntax = \"proto2\";\n" @@ -1042,6 +1045,7 @@ TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileForAbsolutePath) { "$tmpdir/bar.proto.MockCodeGenerator.test_generator: " "$tmpdir/foo.proto\\\n $tmpdir/bar.proto"); } +#endif // !_WIN32 // ------------------------------------------------------------------- diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_field.cc index ee5253a5..c5f05653 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -256,7 +256,7 @@ void FieldGenerator::GenerateFieldDescription( // " .typeSpecific.value* = [something]," GenerateFieldDescriptionTypeSpecific(printer); - const string& field_options(variables_.at("fieldoptions")); + const string& field_options(variables_.find("fieldoptions")->second); if (field_options.empty()) { printer->Print(" .fieldOptions = NULL,\n"); } else { @@ -379,7 +379,7 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration( printer->Print( variables_, "@property(nonatomic, readwrite, $property_storage_attribute$) $property_type$ *$name$$storage_attribute$;\n"); - if (IsInitName(variables_.at("name"))) { + if (IsInitName(variables_.find("name")->second)) { // If property name starts with init we need to annotate it to get past ARC. // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227 printer->Print(variables_, @@ -426,7 +426,7 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration( "$comments$" "$array_comment$" "@property(nonatomic, readwrite, strong) $array_storage_type$ *$name$$storage_attribute$;\n"); - if (IsInitName(variables_.at("name"))) { + if (IsInitName(variables_.find("name")->second)) { // If property name starts with init we need to annotate it to get past ARC. // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227 printer->Print(variables_, diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index 29168937..19317698 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -150,7 +150,7 @@ bool FilterClass(const string& name); // Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform // the input into the the expected output. -class TextFormatDecodeData { +class LIBPROTOC_EXPORT TextFormatDecodeData { public: TextFormatDecodeData() {} diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc index 01e937c3..b091b77a 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc @@ -111,6 +111,8 @@ TEST(ObjCHelper, TextFormatDecodeData_DecodeDataForString_ByteCodes) { EXPECT_EQ(expected, result); } +// Death tests do not work on Windows as of yet. +#ifdef PROTOBUF_HAS_DEATH_TEST TEST(ObjCHelperDeathTest, TextFormatDecodeData_DecodeDataForString_Failures) { // Empty inputs. @@ -136,6 +138,7 @@ TEST(ObjCHelperDeathTest, TextFormatDecodeData_DecodeDataForString_Failures) { ::testing::KilledBySignal(SIGABRT), "error: got a null char in a string for making TextFormat data, input:"); } +#endif // PROTOBUF_HAS_DEATH_TEST TEST(ObjCHelper, TextFormatDecodeData_RawStrings) { TextFormatDecodeData decode_data; @@ -198,6 +201,9 @@ TEST(ObjCHelper, TextFormatDecodeData_ByteCodes) { EXPECT_EQ(expected, decode_data.Data()); } + +// Death tests do not work on Windows as of yet. +#ifdef PROTOBUF_HAS_DEATH_TEST TEST(ObjCHelperDeathTest, TextFormatDecodeData_Failures) { TextFormatDecodeData decode_data; @@ -234,6 +240,7 @@ TEST(ObjCHelperDeathTest, TextFormatDecodeData_Failures) { ::testing::KilledBySignal(SIGABRT), "error: duplicate key \\(2\\) making TextFormat data, input:"); } +#endif // PROTOBUF_HAS_DEATH_TEST } // namespace } // namespace objectivec diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_code.proto b/src/google/protobuf/compiler/ruby/ruby_generated_code.proto new file mode 100644 index 00000000..42d82a6b --- /dev/null +++ b/src/google/protobuf/compiler/ruby/ruby_generated_code.proto @@ -0,0 +1,67 @@ +syntax = "proto3"; + +package A.B.C; + +message TestMessage { + int32 optional_int32 = 1; + int64 optional_int64 = 2; + uint32 optional_uint32 = 3; + uint64 optional_uint64 = 4; + bool optional_bool = 5; + double optional_double = 6; + float optional_float = 7; + string optional_string = 8; + bytes optional_bytes = 9; + TestEnum optional_enum = 10; + TestMessage optional_msg = 11; + + repeated int32 repeated_int32 = 21; + repeated int64 repeated_int64 = 22; + repeated uint32 repeated_uint32 = 23; + repeated uint64 repeated_uint64 = 24; + repeated bool repeated_bool = 25; + repeated double repeated_double = 26; + repeated float repeated_float = 27; + repeated string repeated_string = 28; + repeated bytes repeated_bytes = 29; + repeated TestEnum repeated_enum = 30; + repeated TestMessage repeated_msg = 31; + + oneof my_oneof { + int32 oneof_int32 = 41; + int64 oneof_int64 = 42; + uint32 oneof_uint32 = 43; + uint64 oneof_uint64 = 44; + bool oneof_bool = 45; + double oneof_double = 46; + float oneof_float = 47; + string oneof_string = 48; + bytes oneof_bytes = 49; + TestEnum oneof_enum = 50; + TestMessage oneof_msg = 51; + } + + map<int32, string> map_int32_string = 61; + map<int64, string> map_int64_string = 62; + map<uint32, string> map_uint32_string = 63; + map<uint64, string> map_uint64_string = 64; + map<bool, string> map_bool_string = 65; + map<string, string> map_string_string = 66; + map<string, TestMessage> map_string_msg = 67; + map<string, TestEnum> map_string_enum = 68; + map<string, int32> map_string_int32 = 69; + map<string, bool> map_string_bool = 70; + + message NestedMessage { + int32 foo = 1; + } + + NestedMessage nested_message = 80; +} + +enum TestEnum { + Default = 0; + A = 1; + B = 2; + C = 3; +} diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_code.rb b/src/google/protobuf/compiler/ruby/ruby_generated_code.rb new file mode 100644 index 00000000..100d6fa7 --- /dev/null +++ b/src/google/protobuf/compiler/ruby/ruby_generated_code.rb @@ -0,0 +1,74 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: ruby_generated_code.proto + +require 'google/protobuf' + +Google::Protobuf::DescriptorPool.generated_pool.build do + add_message "A.B.C.TestMessage" do + optional :optional_int32, :int32, 1 + optional :optional_int64, :int64, 2 + optional :optional_uint32, :uint32, 3 + optional :optional_uint64, :uint64, 4 + optional :optional_bool, :bool, 5 + optional :optional_double, :double, 6 + optional :optional_float, :float, 7 + optional :optional_string, :string, 8 + optional :optional_bytes, :string, 9 + optional :optional_enum, :enum, 10, "A.B.C.TestEnum" + optional :optional_msg, :message, 11, "A.B.C.TestMessage" + repeated :repeated_int32, :int32, 21 + repeated :repeated_int64, :int64, 22 + repeated :repeated_uint32, :uint32, 23 + repeated :repeated_uint64, :uint64, 24 + repeated :repeated_bool, :bool, 25 + repeated :repeated_double, :double, 26 + repeated :repeated_float, :float, 27 + repeated :repeated_string, :string, 28 + repeated :repeated_bytes, :string, 29 + repeated :repeated_enum, :enum, 30, "A.B.C.TestEnum" + repeated :repeated_msg, :message, 31, "A.B.C.TestMessage" + map :map_int32_string, :int32, :string, 61 + map :map_int64_string, :int64, :string, 62 + map :map_uint32_string, :uint32, :string, 63 + map :map_uint64_string, :uint64, :string, 64 + map :map_bool_string, :bool, :string, 65 + map :map_string_string, :string, :string, 66 + map :map_string_msg, :string, :message, 67, "A.B.C.TestMessage" + map :map_string_enum, :string, :enum, 68, "A.B.C.TestEnum" + map :map_string_int32, :string, :int32, 69 + map :map_string_bool, :string, :bool, 70 + optional :nested_message, :message, 80, "A.B.C.TestMessage.NestedMessage" + oneof :my_oneof do + optional :oneof_int32, :int32, 41 + optional :oneof_int64, :int64, 42 + optional :oneof_uint32, :uint32, 43 + optional :oneof_uint64, :uint64, 44 + optional :oneof_bool, :bool, 45 + optional :oneof_double, :double, 46 + optional :oneof_float, :float, 47 + optional :oneof_string, :string, 48 + optional :oneof_bytes, :string, 49 + optional :oneof_enum, :enum, 50, "A.B.C.TestEnum" + optional :oneof_msg, :message, 51, "A.B.C.TestMessage" + end + end + add_message "A.B.C.TestMessage.NestedMessage" do + optional :foo, :int32, 1 + end + add_enum "A.B.C.TestEnum" do + value :Default, 0 + value :A, 1 + value :B, 2 + value :C, 3 + end +end + +module A + module B + module C + TestMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("A.B.C.TestMessage").msgclass + TestMessage::NestedMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("A.B.C.TestMessage.NestedMessage").msgclass + TestEnum = Google::Protobuf::DescriptorPool.generated_pool.lookup("A.B.C.TestEnum").enummodule + end + end +end diff --git a/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc b/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc index e35ca695..6c203ab6 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc @@ -45,10 +45,10 @@ namespace compiler { namespace ruby { namespace { -string FindRubyTestDir() { +string FindRubyTestDir(const string& file) { // Inspired by TestSourceDir() in src/google/protobuf/testing/googletest.cc. string prefix = "."; - while (!File::Exists(prefix + "/ruby/tests")) { + while (!File::Exists(prefix + "/src/google/protobuf/compiler/ruby" + file)) { if (!File::Exists(prefix)) { GOOGLE_LOG(FATAL) << "Could not find Ruby test directory. Please run tests from " @@ -56,7 +56,7 @@ string FindRubyTestDir() { } prefix += "/.."; } - return prefix + "/ruby/tests"; + return prefix + "/src/google/protobuf/compiler/ruby"; } // This test is a simple golden-file test over the output of the Ruby code @@ -67,7 +67,7 @@ string FindRubyTestDir() { // extensions to the point where we can do this test in a more automated way. TEST(RubyGeneratorTest, GeneratorTest) { - string ruby_tests = FindRubyTestDir(); + string ruby_tests = FindRubyTestDir("/ruby_generated_code.proto"); google::protobuf::compiler::CommandLineInterface cli; cli.SetInputsAreProtoPathRelative(true); @@ -78,11 +78,11 @@ TEST(RubyGeneratorTest, GeneratorTest) { // Copy generated_code.proto to the temporary test directory. string test_input; GOOGLE_CHECK_OK(File::GetContents( - ruby_tests + "/generated_code.proto", + ruby_tests + "/ruby_generated_code.proto", &test_input, true)); GOOGLE_CHECK_OK(File::SetContents( - TestTempDir() + "/generated_code.proto", + TestTempDir() + "/ruby_generated_code.proto", test_input, true)); @@ -93,7 +93,7 @@ TEST(RubyGeneratorTest, GeneratorTest) { "protoc", ruby_out.c_str(), proto_path.c_str(), - "generated_code.proto", + "ruby_generated_code.proto", }; EXPECT_EQ(0, cli.Run(4, argv)); @@ -101,12 +101,12 @@ TEST(RubyGeneratorTest, GeneratorTest) { // Load the generated output and compare to the expected result. string output; GOOGLE_CHECK_OK(File::GetContents( - TestTempDir() + "/generated_code.rb", + TestTempDir() + "/ruby_generated_code.rb", &output, true)); string expected_output; GOOGLE_CHECK_OK(File::GetContents( - ruby_tests + "/generated_code.rb", + ruby_tests + "/ruby_generated_code.rb", &expected_output, true)); EXPECT_EQ(expected_output, output); diff --git a/src/google/protobuf/lite_unittest.cc b/src/google/protobuf/lite_unittest.cc index 1995cf08..5af8b24d 100644 --- a/src/google/protobuf/lite_unittest.cc +++ b/src/google/protobuf/lite_unittest.cc @@ -700,7 +700,7 @@ int main(int argc, char* argv[]) { // Allocate a large initial block to avoid mallocs during hooked test. std::vector<char> arena_block(128 * 1024); google::protobuf::ArenaOptions options; - options.initial_block = arena_block.data(); + options.initial_block = &arena_block[0]; options.initial_block_size = arena_block.size(); google::protobuf::Arena arena(options); string data; diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index 1858e2f9..c16fbed2 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -33,6 +33,7 @@ #include <iterator> #include <google/protobuf/stubs/hash.h> +#include <limits> // To support Visual Studio 2008 #include <google/protobuf/arena.h> #include <google/protobuf/generated_enum_util.h> @@ -167,11 +168,23 @@ class Map { } } +#if __cplusplus >= 201103L && !defined(GOOGLE_PROTOBUF_OS_APPLE) + template<class NodeType, class... Args> + void construct(NodeType* p, Args&&... args) { + new (p) NodeType(std::forward<Args>(args)...); + } + + template<class NodeType> + void destroy(NodeType* p) { + if (arena_ == NULL) p->~NodeType(); + } +#else void construct(pointer p, const_reference t) { new (p) value_type(t); } void destroy(pointer p) { if (arena_ == NULL) p->~value_type(); } +#endif template <typename X> struct rebind { @@ -188,6 +201,11 @@ class Map { return arena_ != other.arena_; } + // To support Visual Studio 2008 + size_type max_size() const { + return std::numeric_limits<size_type>::max(); + } + private: Arena* arena_; @@ -199,7 +217,7 @@ class Map { typedef MapAllocator<std::pair<const Key, MapPair<Key, T>*> > Allocator; // Iterators - class LIBPROTOBUF_EXPORT const_iterator + class const_iterator : public std::iterator<std::forward_iterator_tag, value_type, ptrdiff_t, const value_type*, const value_type&> { typedef typename hash_map<Key, value_type*, hash<Key>, equal_to<Key>, @@ -229,7 +247,7 @@ class Map { InnerIt it_; }; - class LIBPROTOBUF_EXPORT iterator : public std::iterator<std::forward_iterator_tag, value_type> { + class iterator : public std::iterator<std::forward_iterator_tag, value_type> { typedef typename hash_map<Key, value_type*, hasher, equal_to<Key>, Allocator>::iterator InnerIt; @@ -428,7 +446,7 @@ class Map { internal::WireFormatLite::FieldType key_wire_type, internal::WireFormatLite::FieldType value_wire_type, int default_enum_value> - friend class LIBPROTOBUF_EXPORT internal::MapFieldLite; + friend class internal::MapFieldLite; }; } // namespace protobuf diff --git a/src/google/protobuf/map_entry.h b/src/google/protobuf/map_entry.h index f78a4f40..e93d0348 100644 --- a/src/google/protobuf/map_entry.h +++ b/src/google/protobuf/map_entry.h @@ -97,7 +97,7 @@ template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType, WireFormatLite::FieldType kValueFieldType, int default_enum_value> -class LIBPROTOBUF_EXPORT MapEntry : public MapEntryBase { +class MapEntry : public MapEntryBase { // Handlers for key/value wire type. Provide utilities to parse/serialize // key/value. typedef MapWireFieldTypeHandler<kKeyFieldType> KeyWireHandler; @@ -274,8 +274,8 @@ class LIBPROTOBUF_EXPORT MapEntry : public MapEntryBase { typedef void DestructorSkippable_; template <typename K, typename V, WireFormatLite::FieldType k_wire_type, WireFormatLite::FieldType, int default_enum> - friend class LIBPROTOBUF_EXPORT internal::MapField; - friend class LIBPROTOBUF_EXPORT internal::GeneratedMessageReflection; + friend class internal::MapField; + friend class internal::GeneratedMessageReflection; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry); }; diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index 2d11bea8..52746da5 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -60,7 +60,7 @@ template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType, WireFormatLite::FieldType kValueFieldType, int default_enum_value> -class LIBPROTOBUF_EXPORT MapEntryLite : public MessageLite { +class MapEntryLite : public MessageLite { // Handlers for key/value wire type. Provide utilities to parse/serialize // key/value. typedef MapWireFieldTypeHandler<kKeyFieldType> KeyWireHandler; @@ -302,7 +302,7 @@ class LIBPROTOBUF_EXPORT MapEntryLite : public MessageLite { // only takes references of given key and value. template <typename K, typename V, WireFormatLite::FieldType k_wire_type, WireFormatLite::FieldType v_wire_type, int default_enum> - class LIBPROTOBUF_EXPORT MapEntryWrapper + class MapEntryWrapper : public MapEntryLite<K, V, k_wire_type, v_wire_type, default_enum> { typedef MapEntryLite<K, V, k_wire_type, v_wire_type, default_enum> Base; typedef typename Base::KeyCppType KeyCppType; @@ -336,7 +336,7 @@ class LIBPROTOBUF_EXPORT MapEntryLite : public MessageLite { // the temporary. template <typename K, typename V, WireFormatLite::FieldType k_wire_type, WireFormatLite::FieldType v_wire_type, int default_enum> - class LIBPROTOBUF_EXPORT MapEnumEntryWrapper + class MapEnumEntryWrapper : public MapEntryLite<K, V, k_wire_type, v_wire_type, default_enum> { typedef MapEntryLite<K, V, k_wire_type, v_wire_type, default_enum> Base; typedef typename Base::KeyCppType KeyCppType; @@ -357,7 +357,7 @@ class LIBPROTOBUF_EXPORT MapEntryLite : public MessageLite { const KeyCppType& key_; const ValCppType value_; - friend class LIBPROTOBUF_EXPORT google::protobuf::Arena; + friend class google::protobuf::Arena; typedef void DestructorSkippable_; }; @@ -396,10 +396,10 @@ class LIBPROTOBUF_EXPORT MapEntryLite : public MessageLite { typedef void DestructorSkippable_; template <typename K, typename V, WireFormatLite::FieldType, WireFormatLite::FieldType, int> - friend class LIBPROTOBUF_EXPORT internal::MapEntry; + friend class internal::MapEntry; template <typename K, typename V, WireFormatLite::FieldType, WireFormatLite::FieldType, int> - friend class LIBPROTOBUF_EXPORT internal::MapFieldLite; + friend class internal::MapFieldLite; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryLite); }; diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h index f3504f1b..56d3d0f4 100644 --- a/src/google/protobuf/map_field.h +++ b/src/google/protobuf/map_field.h @@ -68,7 +68,11 @@ class LIBPROTOBUF_EXPORT MapFieldBase { repeated_field_(NULL), entry_descriptor_(NULL), assign_descriptor_callback_(NULL), - state_(STATE_MODIFIED_MAP) {} + state_(STATE_MODIFIED_MAP) { + // Mutex's destructor needs to be called explicitly to release resources + // acquired in its constructor. + arena->OwnDestructor(&mutex_); + } virtual ~MapFieldBase(); // Returns reference to internal repeated field. Data written using @@ -146,7 +150,7 @@ template <typename Key, typename T, WireFormatLite::FieldType kKeyFieldType, WireFormatLite::FieldType kValueFieldType, int default_enum_value = 0> -class LIBPROTOBUF_EXPORT MapField : public MapFieldBase, +class MapField : public MapFieldBase, public MapFieldLite<Key, T, kKeyFieldType, kValueFieldType, default_enum_value> { // Handlers for key/value wire type. Provide utilities to parse/serialize diff --git a/src/google/protobuf/map_field_inl.h b/src/google/protobuf/map_field_inl.h index cbfc0c8f..5b4305f9 100644 --- a/src/google/protobuf/map_field_inl.h +++ b/src/google/protobuf/map_field_inl.h @@ -212,11 +212,11 @@ void MapField<Key, T, kKeyFieldType, kValueFieldType, default_enum_value>::SyncRepeatedFieldWithMapNoLock() const { if (repeated_field_ == NULL) { - if (arena_ == NULL) { + if (MapFieldBase::arena_ == NULL) { repeated_field_ = new RepeatedPtrField<Message>(); } else { - repeated_field_ = - Arena::CreateMessage<RepeatedPtrField<Message> >(arena_); + repeated_field_ = Arena::CreateMessage<RepeatedPtrField<Message> >( + MapFieldBase::arena_); } } const Map<Key, T>& map = GetInternalMap(); @@ -229,7 +229,8 @@ MapField<Key, T, kKeyFieldType, kValueFieldType, it != map.end(); ++it) { InitDefaultEntryOnce(); GOOGLE_CHECK(default_entry_ != NULL); - EntryType* new_entry = down_cast<EntryType*>(default_entry_->New(arena_)); + EntryType* new_entry = + down_cast<EntryType*>(default_entry_->New(MapFieldBase::arena_)); repeated_field->AddAllocated(new_entry); (*new_entry->mutable_key()) = it->first; (*new_entry->mutable_value()) = it->second; diff --git a/src/google/protobuf/map_field_lite.h b/src/google/protobuf/map_field_lite.h index 40322851..860dae55 100644 --- a/src/google/protobuf/map_field_lite.h +++ b/src/google/protobuf/map_field_lite.h @@ -45,7 +45,7 @@ template <typename Key, typename T, WireFormatLite::FieldType key_wire_type, WireFormatLite::FieldType value_wire_type, int default_enum_value = 0> -class LIBPROTOBUF_EXPORT MapFieldLite { +class MapFieldLite { // Define message type for internal repeated field. typedef MapEntryLite<Key, T, key_wire_type, value_wire_type, default_enum_value> EntryType; diff --git a/src/google/protobuf/map_field_test.cc b/src/google/protobuf/map_field_test.cc index f4681866..e3a64079 100644 --- a/src/google/protobuf/map_field_test.cc +++ b/src/google/protobuf/map_field_test.cc @@ -145,7 +145,7 @@ TEST_F(MapFieldBasePrimitiveTest, Arena) { // 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); diff --git a/src/google/protobuf/map_test.cc b/src/google/protobuf/map_test.cc index 447f52d9..d62ec85f 100644 --- a/src/google/protobuf/map_test.cc +++ b/src/google/protobuf/map_test.cc @@ -2285,7 +2285,7 @@ TEST(ArenaTest, ParsingAndSerializingNoHeapAllocation) { // 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); string data; diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h index 2d69fdc1..4da8a5d8 100755 --- a/src/google/protobuf/stubs/hash.h +++ b/src/google/protobuf/stubs/hash.h @@ -93,9 +93,12 @@ template <typename Key, typename Data, typename EqualKey = std::equal_to<Key>, typename Alloc = std::allocator< std::pair<const Key, Data> > > class hash_map : public std::map<Key, Data, HashFcn, EqualKey, Alloc> { + typedef std::map<Key, Data, HashFcn, EqualKey, Alloc> BaseClass; + public: - hash_map(int = 0, const HashFcn& = HashFcn(), const EqualKey& = EqualKey(), - const Alloc& = Alloc()) {} + hash_map(int a = 0, const HashFcn& b = HashFcn(), + const EqualKey& c = EqualKey(), + const Alloc& d = Alloc()) : BaseClass(a, b, c, d) {} }; template <typename Key, @@ -109,7 +112,7 @@ class hash_set : public std::set<Key, HashFcn> { #elif defined(_MSC_VER) && !defined(_STLPORT_VERSION) template <typename Key> -struct hash : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash_compare<Key> { +struct hash : public GOOGLE_PROTOBUF_HASH_COMPARE<Key> { }; // MSVC's hash_compare<const char*> hashes based on the string contents but @@ -123,8 +126,7 @@ class CstringLess { template <> struct hash<const char*> - : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash_compare< - const char*, CstringLess> {}; + : public GOOGLE_PROTOBUF_HASH_COMPARE<const char*, CstringLess> {}; template <typename Key, typename Data, typename HashFcn = hash<Key>, @@ -133,9 +135,13 @@ template <typename Key, typename Data, class hash_map : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< Key, Data, HashFcn, EqualKey, Alloc> { + typedef GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< + Key, Data, HashFcn, EqualKey, Alloc> BaseClass; + public: - hash_map(int = 0, const HashFcn& = HashFcn(), const EqualKey& = EqualKey(), - const Alloc& = Alloc()) {} + hash_map(int a = 0, const HashFcn& b = HashFcn(), + const EqualKey& c = EqualKey(), + const Alloc& d = Alloc()) : BaseClass(a, b, c, d) {} }; template <typename Key, typename HashFcn = hash<Key>, @@ -187,9 +193,13 @@ template <typename Key, typename Data, class hash_map : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< Key, Data, HashFcn, EqualKey, Alloc> { + typedef GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< + Key, Data, HashFcn, EqualKey, Alloc> BaseClass; + public: - hash_map(int = 0, const HashFcn& = HashFcn(), const EqualKey& = EqualKey(), - const Alloc& = Alloc()) {} + hash_map(int a = 0, const HashFcn& b = HashFcn(), + const EqualKey& c = EqualKey(), + const Alloc& d = Alloc()) : BaseClass(a, b, c, d) {} }; template <typename Key, typename HashFcn = hash<Key>, diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h index 5faa81e0..397122ef 100644 --- a/src/google/protobuf/stubs/strutil.h +++ b/src/google/protobuf/stubs/strutil.h @@ -534,7 +534,7 @@ struct Hex { } }; -struct AlphaNum { +struct LIBPROTOBUF_EXPORT AlphaNum { const char *piece_data_; // move these to string_ref eventually size_t piece_size_; // move these to string_ref eventually @@ -610,23 +610,30 @@ using strings::AlphaNum; // be a reference into str. // ---------------------------------------------------------------------- -string StrCat(const AlphaNum &a, const AlphaNum &b); -string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c); -string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d); -string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e); -string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e, const AlphaNum &f); -string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e, const AlphaNum &f, - const AlphaNum &g); -string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e, const AlphaNum &f, - const AlphaNum &g, const AlphaNum &h); -string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, - const AlphaNum &d, const AlphaNum &e, const AlphaNum &f, - const AlphaNum &g, const AlphaNum &h, const AlphaNum &i); +LIBPROTOBUF_EXPORT string StrCat(const AlphaNum& a, const AlphaNum& b); +LIBPROTOBUF_EXPORT string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c); +LIBPROTOBUF_EXPORT string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d); +LIBPROTOBUF_EXPORT string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d, + const AlphaNum& e); +LIBPROTOBUF_EXPORT string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d, + const AlphaNum& e, const AlphaNum& f); +LIBPROTOBUF_EXPORT string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d, + const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g); +LIBPROTOBUF_EXPORT string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d, + const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h); +LIBPROTOBUF_EXPORT string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d, + const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, + const AlphaNum& i); inline string StrCat(const AlphaNum& a) { return string(a.data(), a.size()); } @@ -651,12 +658,14 @@ inline string StrCat(const AlphaNum& a) { return string(a.data(), a.size()); } // worked around as consecutive calls to StrAppend are quite efficient. // ---------------------------------------------------------------------- -void StrAppend(string* dest, const AlphaNum& a); -void StrAppend(string* dest, const AlphaNum& a, const AlphaNum& b); -void StrAppend(string* dest, const AlphaNum& a, const AlphaNum& b, - const AlphaNum& c); -void StrAppend(string* dest, const AlphaNum& a, const AlphaNum& b, - const AlphaNum& c, const AlphaNum& d); +LIBPROTOBUF_EXPORT void StrAppend(string* dest, const AlphaNum& a); +LIBPROTOBUF_EXPORT void StrAppend(string* dest, const AlphaNum& a, + const AlphaNum& b); +LIBPROTOBUF_EXPORT void StrAppend(string* dest, const AlphaNum& a, + const AlphaNum& b, const AlphaNum& c); +LIBPROTOBUF_EXPORT void StrAppend(string* dest, const AlphaNum& a, + const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d); // ---------------------------------------------------------------------- // Join() diff --git a/src/google/protobuf/testing/googletest.cc b/src/google/protobuf/testing/googletest.cc index 5f6a199a..64328063 100644 --- a/src/google/protobuf/testing/googletest.cc +++ b/src/google/protobuf/testing/googletest.cc @@ -108,6 +108,10 @@ string GetTemporaryDirectoryName() { if (HasPrefixString(result, "\\")) { result.erase(0, 1); } + // The Win32 API accepts forward slashes as a path delimiter even though + // backslashes are standard. Let's avoid confusion and use only forward + // slashes. + result = StringReplace(result, "\\", "/", true); #endif // _WIN32 return result; } |