summaryrefslogtreecommitdiff
path: root/cryptlib.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-03-17 20:47:32 -0400
committerJeffrey Walton <noloader@gmail.com>2017-03-17 20:47:32 -0400
commit301437e693fe8bfff6471ff3d88b31a85627d1a7 (patch)
tree8d9e52a6100f68fcaff5020042263537113842b7 /cryptlib.cpp
parentbed31de2f60caced01958a464c98bf3a17586ea0 (diff)
downloadcryptopp-git-301437e693fe8bfff6471ff3d88b31a85627d1a7.tar.gz
Updated static initializers
When MSVC init_seg or GCC init_priority is available, we don't need to use the Singleton. We only need to create a file scope class variable and place it in the segment for MSVC or provide the attribute for GCC. An additional upside is we cleared all the memory leaks that used to be reported by MSVC for debug builds.
Diffstat (limited to 'cryptlib.cpp')
-rw-r--r--cryptlib.cpp33
1 files changed, 15 insertions, 18 deletions
diff --git a/cryptlib.cpp b/cryptlib.cpp
index 140184ae..189f7759 100644
--- a/cryptlib.cpp
+++ b/cryptlib.cpp
@@ -42,33 +42,30 @@ CRYPTOPP_COMPILE_ASSERT(sizeof(word64) == 8);
CRYPTOPP_COMPILE_ASSERT(sizeof(dword) == 2*sizeof(word));
#endif
-#if HAVE_GCC_INIT_PRIORITY
-CRYPTOPP_COMPILE_ASSERT(CRYPTOPP_INIT_PRIORITY >= 101);
-const std::string DEFAULT_CHANNEL __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 25))) = "";
-const std::string AAD_CHANNEL __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 26))) = "AAD";
-#elif HAVE_MSC_INIT_PRIORITY
-#pragma warning(disable: 4073)
-#pragma init_seg(lib)
-const std::string DEFAULT_CHANNEL = "";
-const std::string AAD_CHANNEL = "AAD";
-#pragma warning(default: 4073)
-#else
-static const std::string s1(""), s2("AAD");
-const std::string DEFAULT_CHANNEL = s1;
-const std::string AAD_CHANNEL = s2;
-#endif
-
class NullNameValuePairs : public NameValuePairs
{
public:
+ NullNameValuePairs() {} // Clang complaint a default ctor must be avilable
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
{CRYPTOPP_UNUSED(name); CRYPTOPP_UNUSED(valueType); CRYPTOPP_UNUSED(pValue); return false;}
};
#if HAVE_GCC_INIT_PRIORITY
-const simple_ptr<NullNameValuePairs> s_pNullNameValuePairs __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 30))) = new NullNameValuePairs;
-const NameValuePairs &g_nullNameValuePairs = *s_pNullNameValuePairs.m_p;
+const std::string DEFAULT_CHANNEL __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 10))) = "";
+const std::string AAD_CHANNEL __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 11))) = "AAD";
+const NullNameValuePairs s_nullNameValuePairs __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 12)));
+const NameValuePairs &g_nullNameValuePairs = dynamic_cast<const NameValuePairs&>(s_nullNameValuePairs);
+#elif HAVE_MSC_INIT_PRIORITY
+#pragma warning(disable: 4073)
+#pragma init_seg(lib)
+const std::string DEFAULT_CHANNEL = "";
+const std::string AAD_CHANNEL = "AAD";
+const NullNameValuePairs s_nullNameValuePairs;
+const NameValuePairs &g_nullNameValuePairs = dynamic_cast<const NameValuePairs&>(s_nullNameValuePairs);
+#pragma warning(default: 4073)
#else
+const std::string DEFAULT_CHANNEL = "";
+const std::string AAD_CHANNEL = "AAD";
const simple_ptr<NullNameValuePairs> s_pNullNameValuePairs(new NullNameValuePairs);
const NameValuePairs &g_nullNameValuePairs = *s_pNullNameValuePairs.m_p;
#endif