summaryrefslogtreecommitdiff
path: root/integer.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-11-19 01:39:47 -0500
committerJeffrey Walton <noloader@gmail.com>2017-11-19 01:39:47 -0500
commit23d95e803df6ff3c2e140e6b665efd8439c86472 (patch)
treea42ecd919330d02f613807298ddd024c51a3eff7 /integer.cpp
parent63e53e845e899cc0708708f6a2e9af753f3509cd (diff)
downloadcryptopp-git-23d95e803df6ff3c2e140e6b665efd8439c86472.tar.gz
Provide virtual destructor for Threefish_Base
Diffstat (limited to 'integer.cpp')
-rw-r--r--integer.cpp84
1 files changed, 50 insertions, 34 deletions
diff --git a/integer.cpp b/integer.cpp
index ef5c2b67..691746d1 100644
--- a/integer.cpp
+++ b/integer.cpp
@@ -44,6 +44,12 @@
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
+// Define this to statically initialize Integer Zero(), One()
+// and Two() using Microsoft init_seg(). This is useful for
+// testing Integer code for leaks when the MSC compiler
+// does not fold use of the Singletons.
+// #define USE_MSC_INIT_PRIORITY 1
+
#ifndef CRYPTOPP_IMPORTS
#include "integer.h"
@@ -117,6 +123,7 @@ InitializeInteger::InitializeInteger()
#endif // C++11 or C++03 flag
#endif // not GCC and MSC init priorities
}
+
template <long i>
struct NewInteger
{
@@ -3044,36 +3051,6 @@ Integer Integer::Power2(size_t e)
return r;
}
-const Integer &Integer::Zero()
-{
-#if defined(CRYPTOPP_CXX11_DYNAMIC_INIT)
- static Integer s_zero(0L);
- return s_zero;
-#else
- return Singleton<Integer, NewInteger<0L> >().Ref();
-#endif
-}
-
-const Integer &Integer::One()
-{
-#if defined(CRYPTOPP_CXX11_DYNAMIC_INIT)
- static Integer s_one(1L);
- return s_one;
-#else
- return Singleton<Integer, NewInteger<1L> >().Ref();
-#endif
-}
-
-const Integer &Integer::Two()
-{
-#if defined(CRYPTOPP_CXX11_DYNAMIC_INIT)
- static Integer s_two(2L);
- return s_two;
-#else
- return Singleton<Integer, NewInteger<2L> >().Ref();
-#endif
-}
-
bool Integer::operator!() const
{
return IsNegative() ? false : (reg[0]==0 && WordCount()==0);
@@ -4779,8 +4756,6 @@ bool AssignIntToInteger(const std::type_info &valueType, void *pInteger, const v
// *************************** C++ Static Initialization ***************************
-ANONYMOUS_NAMESPACE_BEGIN
-
class InitInteger
{
public:
@@ -4796,16 +4771,57 @@ public:
#if HAVE_GCC_INIT_PRIORITY
const InitInteger s_init __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 10))) = InitInteger();
-#elif HAVE_MSC_INIT_PRIORITY
+#elif defined(HAVE_MSC_INIT_PRIORITY)
#pragma warning(disable: 4075)
#pragma init_seg(".CRT$XCU")
const InitInteger s_init;
+# if defined(USE_MSC_INIT_PRIORITY)
+ const Integer g_zero(0L);
+ const Integer g_one(1L);
+ const Integer g_two(2L);
+# endif
#pragma warning(default: 4075)
#else
const InitInteger s_init;
#endif
-ANONYMOUS_NAMESPACE_END
+// ***************** Library code ********************
+
+const Integer &Integer::Zero()
+{
+#if defined(CRYPTOPP_CXX11_DYNAMIC_INIT)
+ static Integer s_zero(0L);
+ return s_zero;
+#elif defined(HAVE_MSC_INIT_PRIORITY) && defined(USE_MSC_INIT_PRIORITY)
+ return g_zero;
+#else
+ return Singleton<Integer, NewInteger<0L> >().Ref();
+#endif
+}
+
+const Integer &Integer::One()
+{
+#if defined(CRYPTOPP_CXX11_DYNAMIC_INIT)
+ static Integer s_one(1L);
+ return s_one;
+#elif defined(HAVE_MSC_INIT_PRIORITY) && defined(USE_MSC_INIT_PRIORITY)
+ return g_one;
+#else
+ return Singleton<Integer, NewInteger<1L> >().Ref();
+#endif
+}
+
+const Integer &Integer::Two()
+{
+#if defined(CRYPTOPP_CXX11_DYNAMIC_INIT)
+ static Integer s_two(2L);
+ return s_two;
+#elif defined(HAVE_MSC_INIT_PRIORITY) && defined(USE_MSC_INIT_PRIORITY)
+ return g_two;
+#else
+ return Singleton<Integer, NewInteger<2L> >().Ref();
+#endif
+}
NAMESPACE_END