From df184fba00acc7d4aa7b9d64693c53c815a64eda Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 25 Feb 2015 15:28:44 -0800 Subject: Make maps fields work on installed C++ protobufs. Change-Id: Id937e25bbb35968ee76c92bd4a8ce6247408c443 --- Makefile.am | 2 ++ config.h.include | 7 +++++ src/Makefile.am | 25 +++++++++++++--- src/google/protobuf/stubs/hash.h | 44 +++++++++++++++-------------- vsprojects/extract_includes.bat | 2 ++ vsprojects/google/protobuf/stubs/pbconfig.h | 29 +++++++++++++++++++ vsprojects/libprotobuf-lite.vcproj | 4 +++ vsprojects/libprotobuf.vcproj | 4 +++ 8 files changed, 92 insertions(+), 25 deletions(-) create mode 100644 config.h.include create mode 100644 vsprojects/google/protobuf/stubs/pbconfig.h diff --git a/Makefile.am b/Makefile.am index 1c64b710..18b3fe85 100644 --- a/Makefile.am +++ b/Makefile.am @@ -310,10 +310,12 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ LICENSE \ CONTRIBUTORS.txt \ CHANGES.txt \ + config.h.include \ editors/README.txt \ editors/proto.vim \ editors/protobuf-mode.el \ vsprojects/config.h \ + vsprojects/google/protobuf/stubs/pbconfig.h \ vsprojects/extract_includes.bat \ vsprojects/libprotobuf.vcproj \ vsprojects/libprotobuf-lite.vcproj \ diff --git a/config.h.include b/config.h.include new file mode 100644 index 00000000..0c557fbe --- /dev/null +++ b/config.h.include @@ -0,0 +1,7 @@ +HASH_MAP_CLASS +HASH_MAP_H +HASH_NAMESPACE +HASH_SET_CLASS +HASH_SET_H +HAVE_HASH_MAP +HAVE_HASH_SET diff --git a/src/Makefile.am b/src/Makefile.am index 0f0bd089..5179846c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,12 +31,24 @@ nobase_dist_proto_DATA = google/protobuf/descriptor.proto \ clean-local: rm -f *.loT -CLEANFILES = $(protoc_outputs) unittest_proto_middleman \ +public_config = google/protobuf/stubs/pbconfig.h + +CLEANFILES = $(protoc_outputs) $(public_config) unittest_proto_middleman \ testzip.jar testzip.list testzip.proto testzip.zip MAINTAINERCLEANFILES = \ Makefile.in +# Generate and distribute a minimum config.h file to make hash_map work. +# The autoheader config has too much info, which might conflict with other +# macros applications might include. Thus, we create a stubs/pbconfig.h, that +# only #defines what we really need, and prefix it with GOOGLE_PROTOBUF_ to +# avoid conflicts. +$(public_config): $(top_builddir)/config.h $(top_srcdir)/config.h.include + echo "// Note: Google Protobuf internal only. Do NOT include." > $@ + cat $(top_builddir)/config.h | grep -f $(top_srcdir)/config.h.include | \ + sed 's,#define , #define GOOGLE_PROTOBUF_,' >> $@ + nobase_include_HEADERS = \ google/protobuf/stubs/atomic_sequence_num.h \ google/protobuf/stubs/atomicops.h \ @@ -54,11 +66,12 @@ nobase_include_HEADERS = \ google/protobuf/stubs/atomicops_internals_x86_gcc.h \ google/protobuf/stubs/atomicops_internals_x86_msvc.h \ google/protobuf/stubs/casts.h \ - google/protobuf/stubs/singleton.h \ google/protobuf/stubs/common.h \ google/protobuf/stubs/fastmem.h \ + google/protobuf/stubs/hash.h \ google/protobuf/stubs/once.h \ google/protobuf/stubs/platform_macros.h \ + google/protobuf/stubs/singleton.h \ google/protobuf/stubs/stl_util.h \ google/protobuf/stubs/template_util.h \ google/protobuf/stubs/type_traits.h \ @@ -111,6 +124,9 @@ nobase_include_HEADERS = \ google/protobuf/compiler/python/python_generator.h \ google/protobuf/compiler/ruby/ruby_generator.h +nobase_nodist_include_HEADERS = \ + $(public_config) + lib_LTLIBRARIES = libprotobuf-lite.la libprotobuf.la libprotoc.la libprotobuf_lite_la_LIBADD = $(PTHREAD_LIBS) @@ -135,7 +151,8 @@ libprotobuf_lite_la_SOURCES = \ google/protobuf/io/coded_stream.cc \ google/protobuf/io/coded_stream_inl.h \ google/protobuf/io/zero_copy_stream.cc \ - google/protobuf/io/zero_copy_stream_impl_lite.cc + google/protobuf/io/zero_copy_stream_impl_lite.cc \ + $(public_config) libprotobuf_la_LIBADD = $(PTHREAD_LIBS) libprotobuf_la_LDFLAGS = -version-info 10:0:0 -export-dynamic -no-undefined @@ -374,7 +391,7 @@ protoc_outputs = \ google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.cc \ google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h -BUILT_SOURCES = $(protoc_outputs) +BUILT_SOURCES = $(protoc_outputs) $(public_config) if USE_EXTERNAL_PROTOC diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h index 5b6a073d..badcb6a5 100644 --- a/src/google/protobuf/stubs/hash.h +++ b/src/google/protobuf/stubs/hash.h @@ -37,13 +37,14 @@ #include #include -#include "config.h" +#include -#if defined(HAVE_HASH_MAP) && defined(HAVE_HASH_SET) -#include HASH_MAP_H -#include HASH_SET_H +#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 MISSING_HASH +#define GOOGLE_PROTOBUF_MISSING_HASH #include #include #endif @@ -51,7 +52,7 @@ namespace google { namespace protobuf { -#ifdef MISSING_HASH +#ifdef GOOGLE_PROTOBUF_MISSING_HASH // This system doesn't have hash_map or hash_set. Emulate them using map and // set. @@ -105,7 +106,7 @@ class hash_set : public std::set { #elif defined(_MSC_VER) && !defined(_STLPORT_VERSION) template -struct hash : public HASH_NAMESPACE::hash_compare { +struct hash : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash_compare { }; // MSVC's hash_compare hashes based on the string contents but @@ -119,13 +120,13 @@ class CstringLess { template <> struct hash - : public HASH_NAMESPACE::hash_compare { -}; + : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash_compare< + const char*, CstringLess> {}; template , typename EqualKey = int > -class hash_map : public HASH_NAMESPACE::hash_map< +class hash_map : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash_map< Key, Data, HashFcn> { public: hash_map(int = 0) {} @@ -134,7 +135,7 @@ class hash_map : public HASH_NAMESPACE::hash_map< template , typename EqualKey = int > -class hash_set : public HASH_NAMESPACE::hash_set< +class hash_set : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash_set< Key, HashFcn> { public: hash_set(int = 0) {} @@ -143,7 +144,7 @@ class hash_set : public HASH_NAMESPACE::hash_set< #else template -struct hash : public HASH_NAMESPACE::hash { +struct hash : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash { }; template @@ -166,25 +167,26 @@ struct hash { } }; -template , +template , typename EqualKey = std::equal_to > -class hash_map : public HASH_NAMESPACE::HASH_MAP_CLASS< - Key, Data, HashFcn, EqualKey> { +class hash_map + : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< + Key, Data, HashFcn, EqualKey> { public: hash_map(int = 0) {} }; -template , +template , typename EqualKey = std::equal_to > -class hash_set : public HASH_NAMESPACE::HASH_SET_CLASS< - Key, HashFcn, EqualKey> { +class hash_set + : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_SET_CLASS< + Key, HashFcn, EqualKey> { public: hash_set(int = 0) {} }; -#endif +#undef GOOGLE_PROTOBUF_MISSING_HASH +#endif // !GOOGLE_PROTOBUF_MISSING_HASH template <> struct hash { diff --git a/vsprojects/extract_includes.bat b/vsprojects/extract_includes.bat index 3f902e8e..e9d762c6 100755 --- a/vsprojects/extract_includes.bat +++ b/vsprojects/extract_includes.bat @@ -72,6 +72,7 @@ copy ..\src\google\protobuf\stubs\fastmem.h include\google\protobuf\stubs\fastme copy ..\src\google\protobuf\stubs\once.h include\google\protobuf\stubs\once.h copy ..\src\google\protobuf\stubs\platform_macros.h include\google\protobuf\stubs\platform_macros.h copy ..\src\google\protobuf\stubs\singleton.h include\google\protobuf\stubs\singleton.h +copy ..\src\google\protobuf\stubs\hash.h include\google\protobuf\stubs\hash.h copy ..\src\google\protobuf\stubs\stl_util.h include\google\protobuf\stubs\stl_util.h copy ..\src\google\protobuf\stubs\template_util.h include\google\protobuf\stubs\template_util.h copy ..\src\google\protobuf\stubs\type_traits.h include\google\protobuf\stubs\type_traits.h @@ -80,3 +81,4 @@ copy ..\src\google\protobuf\unknown_field_set.h include\google\protobuf\unknown_ copy ..\src\google\protobuf\wire_format.h include\google\protobuf\wire_format.h copy ..\src\google\protobuf\wire_format_lite.h include\google\protobuf\wire_format_lite.h copy ..\src\google\protobuf\wire_format_lite_inl.h include\google\protobuf\wire_format_lite_inl.h +copy google\protobuf\stubs\pbconfig.h include\google\protobuf\stubs\pbconfig.h diff --git a/vsprojects/google/protobuf/stubs/pbconfig.h b/vsprojects/google/protobuf/stubs/pbconfig.h new file mode 100644 index 00000000..c49d26b0 --- /dev/null +++ b/vsprojects/google/protobuf/stubs/pbconfig.h @@ -0,0 +1,29 @@ +/* protobuf config.h for MSVC. On other platforms, this is generated + * automatically by autoheader / autoconf / configure. */ + +/* the location of */ +#define GOOGLE_PROTOBUF_HASH_MAP_H + +/* the namespace of hash_map/hash_set */ +// 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 +// TODO(kenton): Use unordered_map instead, which is available in MSVC 2010. +#if _MSC_VER < 1310 || _MSC_VER >= 1600 +#define GOOGLE_PROTOBUF_HASH_NAMESPACE std +#else +#define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext +#endif + +/* the location of */ +#define GOOGLE_PROTOBUF_HASH_SET_H + +/* define if the compiler has hash_map */ +#define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1 + +/* define if the compiler has hash_set */ +#define GOOGLE_PROTOBUF_HAVE_HASH_SET 1 + +/* define if you want to use zlib. See readme.txt for additional + * requirements. */ +// #define HAVE_ZLIB 1 diff --git a/vsprojects/libprotobuf-lite.vcproj b/vsprojects/libprotobuf-lite.vcproj index 09eca4d8..339d03fa 100644 --- a/vsprojects/libprotobuf-lite.vcproj +++ b/vsprojects/libprotobuf-lite.vcproj @@ -163,6 +163,10 @@ RelativePath=".\config.h" > + + diff --git a/vsprojects/libprotobuf.vcproj b/vsprojects/libprotobuf.vcproj index 095d3948..6712647d 100644 --- a/vsprojects/libprotobuf.vcproj +++ b/vsprojects/libprotobuf.vcproj @@ -163,6 +163,10 @@ RelativePath=".\config.h" > + + -- cgit v1.2.3