From 60c5222287356d36903ae0cde9ad8fa76752192f Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 28 Jul 2015 16:16:16 -0700 Subject: [PATCH 1/5] Include pthread.h when using GOOGLE_PROTOBUF_NO_THREADLOCAL. When GOOGLE_PROTOBUF_NO_THREADLOCAL is defined, classes that depend on pthread functions are included (such as ThreadLocalStorage). --- src/google/protobuf/stubs/platform_macros.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h index 9e0344d8f..fcafcc14b 100644 --- a/src/google/protobuf/stubs/platform_macros.h +++ b/src/google/protobuf/stubs/platform_macros.h @@ -115,6 +115,8 @@ GOOGLE_PROTOBUF_PLATFORM_ERROR // TLS support on android. // iOS also does not support the __thread keyword. #define GOOGLE_PROTOBUF_NO_THREADLOCAL + +#include #endif #endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_ From 6d72d12575c3fa764f27b91985c5a5c79bc4ccd6 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 28 Jul 2015 16:18:35 -0700 Subject: [PATCH 2/5] Set cmake include directories on library targets. cmake targets that depend on these libraries will automatically have these include directories. --- cmake/libprotobuf-lite.cmake | 1 + cmake/libprotobuf.cmake | 1 + 2 files changed, 2 insertions(+) diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake index db55ea92f..e323840a1 100644 --- a/cmake/libprotobuf-lite.cmake +++ b/cmake/libprotobuf-lite.cmake @@ -24,6 +24,7 @@ set(libprotobuf_lite_files add_library(libprotobuf-lite ${libprotobuf_lite_files}) target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT}) +target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src) set_target_properties(libprotobuf-lite PROPERTIES COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS OUTPUT_NAME ${LIB_PREFIX}protobuf-lite) diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 53ba3d3ef..31fb1fb22 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -54,6 +54,7 @@ set(libprotobuf_files add_library(libprotobuf ${libprotobuf_lite_files} ${libprotobuf_files}) target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES}) +target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src) set_target_properties(libprotobuf PROPERTIES COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS OUTPUT_NAME ${LIB_PREFIX}protobuf) From 56327ecc02943c1cf0e218caad3dc82231717a0b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 29 Jul 2015 13:00:06 -0700 Subject: [PATCH 3/5] Fix compilation error when using C++11. The issue occurs when the template type deduction results in NodeType being const. Shortened version of compile error: no matching function for call to 'operator new' new (p) NodeType(std::forward(args)...); candidate function not viable: no known conversion from 'const std::__1::basic_string, std::__1::allocator > *' to 'void *' for 2nd argument; take the address of the argument with & inline __attribute__ ((__visibility__("hidden"), __always_inline__)) void* operator new (std::size_t, void* __p) noexcept {return __p;} --- src/google/protobuf/map.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index 163ce9dca..d928b7a75 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -172,7 +172,7 @@ class Map { !defined(GOOGLE_PROTOBUF_OS_NACL) && !defined(GOOGLE_PROTOBUF_OS_ANDROID) template void construct(NodeType* p, Args&&... args) { - new (p) NodeType(std::forward(args)...); + new ((void*)p) NodeType(std::forward(args)...); } template From 93ba9333639b45969138dde2caa647243b8159d4 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 29 Jul 2015 14:27:05 -0700 Subject: [PATCH 4/5] Remove unused private fields. Fixes compilation when -Wunused-private-field is enabled (e.g., when using -Wall). --- src/google/protobuf/compiler/java/java_map_field.cc | 4 +--- src/google/protobuf/compiler/java/java_map_field.h | 3 --- src/google/protobuf/compiler/java/java_map_field_lite.cc | 4 +--- src/google/protobuf/compiler/java/java_map_field_lite.h | 3 --- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/google/protobuf/compiler/java/java_map_field.cc b/src/google/protobuf/compiler/java/java_map_field.cc index f25970e56..44b86cd74 100644 --- a/src/google/protobuf/compiler/java/java_map_field.cc +++ b/src/google/protobuf/compiler/java/java_map_field.cc @@ -156,9 +156,7 @@ ImmutableMapFieldGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), messageBitIndex_(messageBitIndex), - builderBitIndex_(builderBitIndex), context_(context), - name_resolver_(context->GetNameResolver()) { + : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_); diff --git a/src/google/protobuf/compiler/java/java_map_field.h b/src/google/protobuf/compiler/java/java_map_field.h index 80a94f456..f2768f3ae 100644 --- a/src/google/protobuf/compiler/java/java_map_field.h +++ b/src/google/protobuf/compiler/java/java_map_field.h @@ -68,9 +68,6 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { private: const FieldDescriptor* descriptor_; map variables_; - const int messageBitIndex_; - const int builderBitIndex_; - Context* context_; ClassNameResolver* name_resolver_; }; diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.cc b/src/google/protobuf/compiler/java/java_map_field_lite.cc index ccc1b32e7..cd1698f0b 100644 --- a/src/google/protobuf/compiler/java/java_map_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_map_field_lite.cc @@ -139,9 +139,7 @@ ImmutableMapFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), messageBitIndex_(messageBitIndex), - builderBitIndex_(builderBitIndex), context_(context), - name_resolver_(context->GetNameResolver()) { + : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_); diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.h b/src/google/protobuf/compiler/java/java_map_field_lite.h index 824726022..a09cd5363 100644 --- a/src/google/protobuf/compiler/java/java_map_field_lite.h +++ b/src/google/protobuf/compiler/java/java_map_field_lite.h @@ -67,9 +67,6 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator { private: const FieldDescriptor* descriptor_; map variables_; - const int messageBitIndex_; - const int builderBitIndex_; - Context* context_; ClassNameResolver* name_resolver_; }; From c6095505dc0c1da8a85e4bd9c50917c6286c9724 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 30 Jul 2015 09:30:31 -0700 Subject: [PATCH 5/5] Move pthread include. Based on pull request feedback. See commit 60c5222 for why the pthread header is necessary. --- src/google/protobuf/stubs/mutex.h | 4 ++++ src/google/protobuf/stubs/platform_macros.h | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/stubs/mutex.h b/src/google/protobuf/stubs/mutex.h index 2cce0561c..7ef1cb691 100644 --- a/src/google/protobuf/stubs/mutex.h +++ b/src/google/protobuf/stubs/mutex.h @@ -30,6 +30,10 @@ #ifndef GOOGLE_PROTOBUF_STUBS_MUTEX_H_ #define GOOGLE_PROTOBUF_STUBS_MUTEX_H_ +#ifdef GOOGLE_PROTOBUF_NO_THREADLOCAL +#include +#endif + #include // =================================================================== diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h index fcafcc14b..9e0344d8f 100644 --- a/src/google/protobuf/stubs/platform_macros.h +++ b/src/google/protobuf/stubs/platform_macros.h @@ -115,8 +115,6 @@ GOOGLE_PROTOBUF_PLATFORM_ERROR // TLS support on android. // iOS also does not support the __thread keyword. #define GOOGLE_PROTOBUF_NO_THREADLOCAL - -#include #endif #endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_