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/unknown_field_set.cc | |
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/unknown_field_set.cc')
-rw-r--r-- | src/google/protobuf/unknown_field_set.cc | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc index 0ada85e5..35f24e7a 100644 --- a/src/google/protobuf/unknown_field_set.cc +++ b/src/google/protobuf/unknown_field_set.cc @@ -46,28 +46,9 @@ namespace google { namespace protobuf { -namespace { -// This global instance is returned by unknown_fields() on any message class -// when the object has no unknown fields. This is necessary because we now -// instantiate the UnknownFieldSet dynamically only when required. -UnknownFieldSet* default_unknown_field_set_instance_ = NULL; - -void DeleteDefaultUnknownFieldSet() { - delete default_unknown_field_set_instance_; -} - -void InitDefaultUnknownFieldSet() { - default_unknown_field_set_instance_ = new UnknownFieldSet(); - internal::OnShutdown(&DeleteDefaultUnknownFieldSet); -} - -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); - return default_unknown_field_set_instance_; + static auto instance = internal::OnShutdownDelete(new UnknownFieldSet()); + return instance; } void UnknownFieldSet::ClearFallback() { |