diff options
author | Adam Cozzette <acozzette@gmail.com> | 2018-07-09 11:45:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-09 11:45:39 -0700 |
commit | 4129b6aaad1aa9d48dea1b4ad64c2a64747cb537 (patch) | |
tree | 528cf866e94f2dcc3e55d45dce3cf42ef60848bc /src/google/protobuf/stubs/common.h | |
parent | 61476b8e74357ea875f71bb321874ca4530b7d50 (diff) | |
parent | e1845779ed1115dd61eb2a3b8f0a78c252ca5b2b (diff) |
Merge pull request #4882 from google/3.6.x
Merge 3.6.x into master
Diffstat (limited to 'src/google/protobuf/stubs/common.h')
-rw-r--r-- | src/google/protobuf/stubs/common.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 5d320764..f505f46a 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -193,17 +193,22 @@ LIBPROTOBUF_EXPORT char* UTF8CoerceToStructurallyValid( // // It is safe to call this multiple times. However, it is not safe to use // any other part of the protocol buffers library after -// ShutdownProtobufLibrary() has been called. +// ShutdownProtobufLibrary() has been called. Furthermore this call is not +// thread safe, user needs to synchronize multiple calls. LIBPROTOBUF_EXPORT void ShutdownProtobufLibrary(); namespace internal { // Register a function to be called when ShutdownProtocolBuffers() is called. LIBPROTOBUF_EXPORT void OnShutdown(void (*func)()); -// Destroy the string (call string destructor) -LIBPROTOBUF_EXPORT void OnShutdownDestroyString(const std::string* ptr); -// Destroy (not delete) the message -LIBPROTOBUF_EXPORT void OnShutdownDestroyMessage(const void* ptr); +// Run an arbitrary function on an arg +LIBPROTOBUF_EXPORT void OnShutdownRun(void (*f)(const void*), const void* arg); + +template <typename T> +T* OnShutdownDelete(T* p) { + OnShutdownRun([](const void* p) { delete static_cast<const T*>(p); }, p); + return p; +} } // namespace internal |