| diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc |
| index dae24f9eb204..4824c0f93606 100644 |
| --- a/src/google/protobuf/descriptor.cc |
| +++ b/src/google/protobuf/descriptor.cc |
| @@ -510,7 +510,9 @@ void InitAllowedProto3Extendee() { |
| // instead of comparing the descriptor directly because the extensions may be |
| // defined in a different pool. |
| bool AllowedExtendeeInProto3(const string& name) { |
| - ::google::protobuf::GoogleOnceInit(&allowed_proto3_extendees_init_, &InitAllowedProto3Extendee); |
| + ::google::protobuf::GoogleOnceInit( |
| + &GOOGLE_PROTOBUF_GET_ONCE(allowed_proto3_extendees_init_), |
| + &InitAllowedProto3Extendee); |
| return allowed_proto3_extendees_->find(name) != |
| allowed_proto3_extendees_->end(); |
| } |
| @@ -846,7 +848,8 @@ void InitFileDescriptorTables() { |
| |
| inline void InitFileDescriptorTablesOnce() { |
| ::google::protobuf::GoogleOnceInit( |
| - &file_descriptor_tables_once_init_, &InitFileDescriptorTables); |
| + &GOOGLE_PROTOBUF_GET_ONCE(file_descriptor_tables_once_init_), |
| + &InitFileDescriptorTables); |
| } |
| |
| } // anonymous namespace |
| @@ -1358,7 +1361,8 @@ static void InitGeneratedPool() { |
| } |
| |
| inline void InitGeneratedPoolOnce() { |
| - ::google::protobuf::GoogleOnceInit(&generated_pool_init_, &InitGeneratedPool); |
| + ::google::protobuf::GoogleOnceInit( |
| + &GOOGLE_PROTOBUF_GET_ONCE(generated_pool_init_), &InitGeneratedPool); |
| } |
| |
| } // anonymous namespace |
| diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc |
| index b587b38f161e..417f167d3633 100644 |
| --- a/src/google/protobuf/extension_set.cc |
| +++ b/src/google/protobuf/extension_set.cc |
| @@ -97,7 +97,8 @@ void InitRegistry() { |
| // safety. |
| void Register(const MessageLite* containing_type, |
| int number, ExtensionInfo info) { |
| - ::google::protobuf::GoogleOnceInit(®istry_init_, &InitRegistry); |
| + ::google::protobuf::GoogleOnceInit(&GOOGLE_PROTOBUF_GET_ONCE(registry_init_), |
| + &InitRegistry); |
| |
| if (!InsertIfNotPresent(registry_, std::make_pair(containing_type, number), |
| info)) { |
| diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h |
| index c4796629a9e1..2e830e3571ed 100644 |
| --- a/src/google/protobuf/extension_set.h |
| +++ b/src/google/protobuf/extension_set.h |
| @@ -878,7 +878,8 @@ class RepeatedPrimitiveTypeTraits { |
| } |
| }; |
| |
| -LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_primitive_generic_type_traits_once_init_; |
| +LIBPROTOBUF_EXPORT extern GOOGLE_PROTOBUF_FORWARD_ONCE( |
| + repeated_primitive_generic_type_traits_once_init_); |
| |
| class LIBPROTOBUF_EXPORT RepeatedPrimitiveGenericTypeTraits { |
| private: |
| @@ -894,52 +895,58 @@ class LIBPROTOBUF_EXPORT RepeatedPrimitiveGenericTypeTraits { |
| static const RepeatedField<bool>* default_repeated_field_bool_; |
| }; |
| |
| -#define PROTOBUF_DEFINE_PRIMITIVE_TYPE(TYPE, METHOD) \ |
| -template<> inline TYPE PrimitiveTypeTraits<TYPE>::Get( \ |
| - int number, const ExtensionSet& set, TYPE default_value) { \ |
| - return set.Get##METHOD(number, default_value); \ |
| -} \ |
| -template<> inline void PrimitiveTypeTraits<TYPE>::Set( \ |
| - int number, FieldType field_type, TYPE value, ExtensionSet* set) { \ |
| - set->Set##METHOD(number, field_type, value, NULL); \ |
| -} \ |
| - \ |
| -template<> inline TYPE RepeatedPrimitiveTypeTraits<TYPE>::Get( \ |
| - int number, const ExtensionSet& set, int index) { \ |
| - return set.GetRepeated##METHOD(number, index); \ |
| -} \ |
| -template<> inline void RepeatedPrimitiveTypeTraits<TYPE>::Set( \ |
| - int number, int index, TYPE value, ExtensionSet* set) { \ |
| - set->SetRepeated##METHOD(number, index, value); \ |
| -} \ |
| -template<> inline void RepeatedPrimitiveTypeTraits<TYPE>::Add( \ |
| - int number, FieldType field_type, bool is_packed, \ |
| - TYPE value, ExtensionSet* set) { \ |
| - set->Add##METHOD(number, field_type, is_packed, value, NULL); \ |
| -} \ |
| -template<> inline const RepeatedField<TYPE>* \ |
| - RepeatedPrimitiveTypeTraits<TYPE>::GetDefaultRepeatedField() { \ |
| - ::google::protobuf::GoogleOnceInit( \ |
| - &repeated_primitive_generic_type_traits_once_init_, \ |
| - &RepeatedPrimitiveGenericTypeTraits::InitializeDefaultRepeatedFields); \ |
| - return RepeatedPrimitiveGenericTypeTraits:: \ |
| - default_repeated_field_##TYPE##_; \ |
| -} \ |
| -template<> inline const RepeatedField<TYPE>& \ |
| - RepeatedPrimitiveTypeTraits<TYPE>::GetRepeated(int number, \ |
| - const ExtensionSet& set) { \ |
| - return *reinterpret_cast<const RepeatedField<TYPE>*>( \ |
| - set.GetRawRepeatedField( \ |
| - number, GetDefaultRepeatedField())); \ |
| -} \ |
| -template<> inline RepeatedField<TYPE>* \ |
| - RepeatedPrimitiveTypeTraits<TYPE>::MutableRepeated(int number, \ |
| - FieldType field_type, \ |
| - bool is_packed, \ |
| - ExtensionSet* set) { \ |
| - return reinterpret_cast<RepeatedField<TYPE>*>( \ |
| - set->MutableRawRepeatedField(number, field_type, is_packed, NULL)); \ |
| -} |
| +#define PROTOBUF_DEFINE_PRIMITIVE_TYPE(TYPE, METHOD) \ |
| + template <> \ |
| + inline TYPE PrimitiveTypeTraits<TYPE>::Get( \ |
| + int number, const ExtensionSet& set, TYPE default_value) { \ |
| + return set.Get##METHOD(number, default_value); \ |
| + } \ |
| + template <> \ |
| + inline void PrimitiveTypeTraits<TYPE>::Set(int number, FieldType field_type, \ |
| + TYPE value, ExtensionSet* set) { \ |
| + set->Set##METHOD(number, field_type, value, NULL); \ |
| + } \ |
| + \ |
| + template <> \ |
| + inline TYPE RepeatedPrimitiveTypeTraits<TYPE>::Get( \ |
| + int number, const ExtensionSet& set, int index) { \ |
| + return set.GetRepeated##METHOD(number, index); \ |
| + } \ |
| + template <> \ |
| + inline void RepeatedPrimitiveTypeTraits<TYPE>::Set( \ |
| + int number, int index, TYPE value, ExtensionSet* set) { \ |
| + set->SetRepeated##METHOD(number, index, value); \ |
| + } \ |
| + template <> \ |
| + inline void RepeatedPrimitiveTypeTraits<TYPE>::Add( \ |
| + int number, FieldType field_type, bool is_packed, TYPE value, \ |
| + ExtensionSet* set) { \ |
| + set->Add##METHOD(number, field_type, is_packed, value, NULL); \ |
| + } \ |
| + template <> \ |
| + inline const RepeatedField<TYPE>* \ |
| + RepeatedPrimitiveTypeTraits<TYPE>::GetDefaultRepeatedField() { \ |
| + ::google::protobuf::GoogleOnceInit( \ |
| + &GOOGLE_PROTOBUF_GET_ONCE( \ |
| + repeated_primitive_generic_type_traits_once_init_), \ |
| + &RepeatedPrimitiveGenericTypeTraits::InitializeDefaultRepeatedFields); \ |
| + return RepeatedPrimitiveGenericTypeTraits:: \ |
| + default_repeated_field_##TYPE##_; \ |
| + } \ |
| + template <> \ |
| + inline const RepeatedField<TYPE>& \ |
| + RepeatedPrimitiveTypeTraits<TYPE>::GetRepeated(int number, \ |
| + const ExtensionSet& set) { \ |
| + return *reinterpret_cast<const RepeatedField<TYPE>*>( \ |
| + set.GetRawRepeatedField(number, GetDefaultRepeatedField())); \ |
| + } \ |
| + template <> \ |
| + inline RepeatedField<TYPE>* \ |
| + RepeatedPrimitiveTypeTraits<TYPE>::MutableRepeated( \ |
| + int number, FieldType field_type, bool is_packed, ExtensionSet* set) { \ |
| + return reinterpret_cast<RepeatedField<TYPE>*>( \ |
| + set->MutableRawRepeatedField(number, field_type, is_packed, NULL)); \ |
| + } |
| |
| PROTOBUF_DEFINE_PRIMITIVE_TYPE( int32, Int32) |
| PROTOBUF_DEFINE_PRIMITIVE_TYPE( int64, Int64) |
| @@ -980,7 +987,8 @@ class LIBPROTOBUF_EXPORT StringTypeTraits { |
| } |
| }; |
| |
| -LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_string_type_traits_once_init_; |
| +LIBPROTOBUF_EXPORT extern GOOGLE_PROTOBUF_FORWARD_ONCE( |
| + repeated_string_type_traits_once_init_); |
| |
| class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { |
| public: |
| @@ -1025,8 +1033,9 @@ class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { |
| } |
| |
| static const RepeatedFieldType* GetDefaultRepeatedField() { |
| - ::google::protobuf::GoogleOnceInit(&repeated_string_type_traits_once_init_, |
| - &InitializeDefaultRepeatedFields); |
| + ::google::protobuf::GoogleOnceInit( |
| + &GOOGLE_PROTOBUF_GET_ONCE(repeated_string_type_traits_once_init_), |
| + &InitializeDefaultRepeatedFields); |
| return default_repeated_field_; |
| } |
| |
| @@ -1230,7 +1239,8 @@ class RepeatedMessageTypeTraits { |
| } |
| }; |
| |
| -LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_message_generic_type_traits_once_init_; |
| +LIBPROTOBUF_EXPORT extern GOOGLE_PROTOBUF_FORWARD_ONCE( |
| + repeated_message_generic_type_traits_once_init_); |
| |
| // This class exists only to hold a generic default empty repeated field for all |
| // message-type repeated field extensions. |
| @@ -1248,7 +1258,8 @@ template<typename Type> inline |
| const typename RepeatedMessageTypeTraits<Type>::RepeatedFieldType* |
| RepeatedMessageTypeTraits<Type>::GetDefaultRepeatedField() { |
| ::google::protobuf::GoogleOnceInit( |
| - &repeated_message_generic_type_traits_once_init_, |
| + &GOOGLE_PROTOBUF_GET_ONCE( |
| + repeated_message_generic_type_traits_once_init_), |
| &RepeatedMessageGenericTypeTraits::InitializeDefaultRepeatedFields); |
| return reinterpret_cast<const RepeatedFieldType*>( |
| RepeatedMessageGenericTypeTraits::default_repeated_field_); |
| diff --git a/src/google/protobuf/implicit_weak_message.cc b/src/google/protobuf/implicit_weak_message.cc |
| index 7a1d4446bf32..d7ba74c79153 100644 |
| --- a/src/google/protobuf/implicit_weak_message.cc |
| +++ b/src/google/protobuf/implicit_weak_message.cc |
| @@ -53,8 +53,9 @@ void InitImplicitWeakMessageDefaultInstance() { |
| } |
| |
| const ImplicitWeakMessage* ImplicitWeakMessage::default_instance() { |
| - ::google::protobuf::GoogleOnceInit(&implicit_weak_message_once_init_, |
| - &InitImplicitWeakMessageDefaultInstance); |
| + ::google::protobuf::GoogleOnceInit( |
| + &GOOGLE_PROTOBUF_GET_ONCE(implicit_weak_message_once_init_), |
| + &InitImplicitWeakMessageDefaultInstance); |
| return &implicit_weak_message_default_instance.get(); |
| } |
| |
| diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc |
| index 810db233baec..755efbbbd208 100644 |
| --- a/src/google/protobuf/message.cc |
| +++ b/src/google/protobuf/message.cc |
| @@ -300,8 +300,9 @@ GeneratedMessageFactory::GeneratedMessageFactory() {} |
| GeneratedMessageFactory::~GeneratedMessageFactory() {} |
| |
| GeneratedMessageFactory* GeneratedMessageFactory::singleton() { |
| - ::google::protobuf::GoogleOnceInit(&generated_message_factory_once_init_, |
| - &InitGeneratedMessageFactory); |
| + ::google::protobuf::GoogleOnceInit( |
| + &GOOGLE_PROTOBUF_GET_ONCE(generated_message_factory_once_init_), |
| + &InitGeneratedMessageFactory); |
| return generated_message_factory_; |
| } |
| |
| diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc |
| index 329b475cb835..42f79361bfe5 100644 |
| --- a/src/google/protobuf/message_lite.cc |
| +++ b/src/google/protobuf/message_lite.cc |
| @@ -401,7 +401,8 @@ void SetProto3PreserveUnknownsDefault(bool preserve) { |
| } |
| |
| const ::std::string& GetEmptyString() { |
| - ::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString); |
| + ::google::protobuf::GoogleOnceInit( |
| + &GOOGLE_PROTOBUF_GET_ONCE(empty_string_once_init_), &InitEmptyString); |
| return GetEmptyStringAlreadyInited(); |
| } |
| |
| diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h |
| index 86120ef03e80..87a234f69d4e 100644 |
| --- a/src/google/protobuf/message_lite.h |
| +++ b/src/google/protobuf/message_lite.h |
| @@ -129,7 +129,7 @@ class ExplicitlyConstructed { |
| // Default empty string object. Don't use this directly. Instead, call |
| // GetEmptyString() to get the reference. |
| LIBPROTOBUF_EXPORT extern ExplicitlyConstructed<::std::string> fixed_address_empty_string; |
| -LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_; |
| +LIBPROTOBUF_EXPORT extern GOOGLE_PROTOBUF_FORWARD_ONCE(empty_string_once_init_); |
| LIBPROTOBUF_EXPORT void InitEmptyString(); |
| |
| |
| diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc |
| index 33d24c57cb93..a865fc2dc741 100755 |
| --- a/src/google/protobuf/stubs/common.cc |
| +++ b/src/google/protobuf/stubs/common.cc |
| @@ -188,7 +188,8 @@ void InitLogSilencerCount() { |
| OnShutdown(&DeleteLogSilencerCount); |
| } |
| void InitLogSilencerCountOnce() { |
| - GoogleOnceInit(&log_silencer_count_init_, &InitLogSilencerCount); |
| + GoogleOnceInit(&GOOGLE_PROTOBUF_GET_ONCE(log_silencer_count_init_), |
| + &InitLogSilencerCount); |
| } |
| |
| LogMessage& LogMessage::operator<<(const string& value) { |
| @@ -364,7 +365,8 @@ void InitShutdownFunctions() { |
| } |
| |
| inline void InitShutdownFunctionsOnce() { |
| - GoogleOnceInit(&shutdown_functions_init, &InitShutdownFunctions); |
| + GoogleOnceInit(&GOOGLE_PROTOBUF_GET_ONCE(shutdown_functions_init), |
| + &InitShutdownFunctions); |
| } |
| |
| void OnShutdown(void (*func)()) { |
| diff --git a/src/google/protobuf/stubs/once.h b/src/google/protobuf/stubs/once.h |
| index b6d9fea3f3ef..d481bdf40f98 100644 |
| --- a/src/google/protobuf/stubs/once.h |
| +++ b/src/google/protobuf/stubs/once.h |
| @@ -119,8 +119,16 @@ class GoogleOnceDynamic { |
| }; |
| |
| #define GOOGLE_PROTOBUF_ONCE_TYPE ::google::protobuf::ProtobufOnceType |
| -#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \ |
| - ::google::protobuf::ProtobufOnceType NAME |
| +#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \ |
| + ::google::protobuf::ProtobufOnceType& get_once_##NAME() { \ |
| + static ::google::protobuf::ProtobufOnceType once; \ |
| + return once; \ |
| + } |
| + |
| +#define GOOGLE_PROTOBUF_FORWARD_ONCE(NAME) \ |
| + ::google::protobuf::ProtobufOnceType& get_once_##NAME() |
| + |
| +#define GOOGLE_PROTOBUF_GET_ONCE(NAME) (get_once_##NAME()) |
| |
| } // namespace protobuf |
| } // namespace google |
| diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc |
| index 0ada85e57043..7877f2525461 100644 |
| --- a/src/google/protobuf/unknown_field_set.cc |
| +++ b/src/google/protobuf/unknown_field_set.cc |
| @@ -65,8 +65,9 @@ GOOGLE_PROTOBUF_DECLARE_ONCE(default_unknown_field_set_once_init_); |
| } |
| |
| const UnknownFieldSet* UnknownFieldSet::default_instance() { |
| - ::google::protobuf::GoogleOnceInit(&default_unknown_field_set_once_init_, |
| - &InitDefaultUnknownFieldSet); |
| + ::google::protobuf::GoogleOnceInit( |
| + &GOOGLE_PROTOBUF_GET_ONCE(default_unknown_field_set_once_init_), |
| + &InitDefaultUnknownFieldSet); |
| return default_unknown_field_set_instance_; |
| } |
| |
| diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc |
| index 56e6db124332..5fe5c89a137a 100644 |
| --- a/src/google/protobuf/util/internal/protostream_objectsource.cc |
| +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc |
| @@ -737,7 +737,8 @@ void ProtoStreamObjectSource::DeleteRendererMap() { |
| // static |
| ProtoStreamObjectSource::TypeRenderer* |
| ProtoStreamObjectSource::FindTypeRenderer(const string& type_url) { |
| - ::google::protobuf::GoogleOnceInit(&source_renderers_init_, &InitRendererMap); |
| + ::google::protobuf::GoogleOnceInit( |
| + &GOOGLE_PROTOBUF_GET_ONCE(source_renderers_init_), &InitRendererMap); |
| return FindOrNull(*renderers_, type_url); |
| } |
| |
| diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc |
| index 2edfd0759ce5..1ce871e41bb9 100644 |
| --- a/src/google/protobuf/util/internal/protostream_objectwriter.cc |
| +++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc |
| @@ -1194,7 +1194,8 @@ void ProtoStreamObjectWriter::DeleteRendererMap() { |
| |
| ProtoStreamObjectWriter::TypeRenderer* |
| ProtoStreamObjectWriter::FindTypeRenderer(const string& type_url) { |
| - ::google::protobuf::GoogleOnceInit(&writer_renderers_init_, &InitRendererMap); |
| + ::google::protobuf::GoogleOnceInit( |
| + &GOOGLE_PROTOBUF_GET_ONCE(writer_renderers_init_), &InitRendererMap); |
| return FindOrNull(*renderers_, type_url); |
| } |
| |
| diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc |
| index f81a7a306172..186f8e5d75ca 100644 |
| --- a/src/google/protobuf/util/json_util.cc |
| +++ b/src/google/protobuf/util/json_util.cc |
| @@ -209,7 +209,9 @@ void InitGeneratedTypeResolver() { |
| } |
| |
| TypeResolver* GetGeneratedTypeResolver() { |
| - ::google::protobuf::GoogleOnceInit(&generated_type_resolver_init_, &InitGeneratedTypeResolver); |
| + ::google::protobuf::GoogleOnceInit( |
| + &GOOGLE_PROTOBUF_GET_ONCE(generated_type_resolver_init_), |
| + &InitGeneratedTypeResolver); |
| return generated_type_resolver_; |
| } |
| } // namespace |