summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schuh <andreas.schuh.84@gmail.com>2016-02-19 12:59:05 +0000
committerAndreas Schuh <andreas.schuh.84@gmail.com>2016-02-19 12:59:05 +0000
commit7a69001868a32d80166cc9510379c980de4abaa4 (patch)
treea21775a2000d51328e93110e71bf98a6f962e126 /src
parent3f968fc16b95c7b9e14dcc6ee4cd1c0753e378d0 (diff)
downloadgflags-7a69001868a32d80166cc9510379c980de4abaa4.tar.gz
gflags-7a69001868a32d80166cc9510379c980de4abaa4.tar.bz2
gflags-7a69001868a32d80166cc9510379c980de4abaa4.zip
#51 Use static StringFlagDestructor to destruct string objects allocated by placement new
Diffstat (limited to 'src')
-rw-r--r--src/gflags.h.in21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/gflags.h.in b/src/gflags.h.in
index 0324d39..88ab1aa 100644
--- a/src/gflags.h.in
+++ b/src/gflags.h.in
@@ -538,6 +538,26 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot,
}
inline clstring* dont_pass0toDEFINE_string(char *stringspot,
int value);
+
+// Auxiliary class used to explicitly call destructor of string objects
+// allocated using placement new during static program deinitialization.
+// The destructor MUST be an inline function such that the explicit
+// destruction occurs in the same compilation unit as the placement new.
+class StringFlagDestructor {
+ void *current_storage_;
+ void *defvalue_storage_;
+
+public:
+
+ StringFlagDestructor(void *current, void *defvalue)
+ : current_storage_(current), defvalue_storage_(defvalue) {}
+
+ ~StringFlagDestructor() {
+ reinterpret_cast<clstring*>(current_storage_ )->~clstring();
+ reinterpret_cast<clstring*>(defvalue_storage_)->~clstring();
+ }
+};
+
} // namespace fLS
// We need to define a var named FLAGS_no##name so people don't define
@@ -557,6 +577,7 @@ inline clstring* dont_pass0toDEFINE_string(char *stringspot,
static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \
#name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \
s_##name[0].s, new (s_##name[1].s) clstring(*FLAGS_no##name)); \
+ static StringFlagDestructor d_##name(s_##name[0].s, s_##name[1].s); \
extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \
using fLS::FLAGS_##name; \
clstring& FLAGS_##name = *FLAGS_no##name; \