diff options
author | Adam Cozzette <acozzette@google.com> | 2018-07-06 14:12:33 -0700 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2018-07-06 15:02:40 -0700 |
commit | a9abc7831e45257d334cfa682746b6cadf9e95d9 (patch) | |
tree | fdb892e4e34269f6b3bbb6f629a912d4c63c2d70 /src/google/protobuf/generated_message_util.h | |
parent | f7ada1280fac4af717d478e6a9765d3f02b418b3 (diff) |
Fix initialization with Visual Studio
It appears that Visual Studio does not work well with std::once_flag
because it has a bug causing it to initialize that during dynamic
initialization instead of constant initialization. This change works
around the problem by using function static initializers instead.
@gerben-s originally wrote this change for the Google-internal codebase
but I am just cherry-picking it here.
This fixes #4773.
Diffstat (limited to 'src/google/protobuf/generated_message_util.h')
-rw-r--r-- | src/google/protobuf/generated_message_util.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index 706df383..04f68a6e 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -109,6 +109,13 @@ namespace internal { LIBPROTOBUF_EXPORT double Infinity(); LIBPROTOBUF_EXPORT double NaN(); +LIBPROTOBUF_EXPORT void InitProtobufDefaults(); + +// This used by proto1 +inline const std::string& GetEmptyString() { + InitProtobufDefaults(); + return GetEmptyStringAlreadyInited(); +} // True if IsInitialized() is true for all elements of t. Type is expected // to be a RepeatedPtrField<some message type>. It's useful to have this @@ -137,8 +144,6 @@ bool AllAreInitializedWeak(const ::google::protobuf::RepeatedPtrField<T>& t) { return true; } -LIBPROTOBUF_EXPORT void InitProtobufDefaults(); - struct LIBPROTOBUF_EXPORT FieldMetadata { uint32 offset; // offset of this field in the struct uint32 tag; // field * 8 + wire_type @@ -368,6 +373,17 @@ inline void InitSCC(SCCInfoBase* scc) { if (GOOGLE_PREDICT_FALSE(status != SCCInfoBase::kInitialized)) InitSCCImpl(scc); } +LIBPROTOBUF_EXPORT void DestroyMessage(const void* message); +LIBPROTOBUF_EXPORT void DestroyString(const void* s); +// Destroy (not delete) the message +inline void OnShutdownDestroyMessage(const void* ptr) { + OnShutdownRun(DestroyMessage, ptr); +} +// Destroy the string (call string destructor) +inline void OnShutdownDestroyString(const std::string* ptr) { + OnShutdownRun(DestroyString, ptr); +} + } // namespace internal } // namespace protobuf |