|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83519 - in trunk: boost/multiprecision libs/multiprecision/example libs/multiprecision/test
From: john_at_[hidden]
Date: 2013-03-22 12:55:37
Author: johnmaddock
Date: 2013-03-22 12:55:36 EDT (Fri, 22 Mar 2013)
New Revision: 83519
URL: http://svn.boost.org/trac/boost/changeset/83519
Log:
Fix valgrind errors
Text files modified:
trunk/boost/multiprecision/gmp.hpp | 2 +-
trunk/boost/multiprecision/mpfr.hpp | 21 +++++++++++++++++++++
trunk/libs/multiprecision/example/gmp_snips.cpp | 3 +++
trunk/libs/multiprecision/example/mpfi_snips.cpp | 1 +
trunk/libs/multiprecision/example/mpfr_snips.cpp | 1 +
trunk/libs/multiprecision/test/test_gmp_conversions.cpp | 4 ++++
trunk/libs/multiprecision/test/test_mpfr_conversions.cpp | 5 +++++
7 files changed, 36 insertions(+), 1 deletions(-)
Modified: trunk/boost/multiprecision/gmp.hpp
==============================================================================
--- trunk/boost/multiprecision/gmp.hpp (original)
+++ trunk/boost/multiprecision/gmp.hpp 2013-03-22 12:55:36 EDT (Fri, 22 Mar 2013)
@@ -177,7 +177,7 @@
int e;
long double f, term;
- mpf_init_set_ui(m_data, 0u);
+ mpf_set_ui(m_data, 0u);
f = frexp(a, &e);
Modified: trunk/boost/multiprecision/mpfr.hpp
==============================================================================
--- trunk/boost/multiprecision/mpfr.hpp (original)
+++ trunk/boost/multiprecision/mpfr.hpp 2013-03-22 12:55:36 EDT (Fri, 22 Mar 2013)
@@ -39,6 +39,22 @@
namespace detail{
+template <bool b>
+struct mpfr_cleanup
+{
+ struct initializer
+ {
+ initializer() {}
+ ~initializer(){ mpfr_free_cache(); }
+ void force_instantiate()const {}
+ };
+ static const initializer init;
+ static void force_instantiate() { init.force_instantiate(); }
+};
+
+template <bool b>
+typename mpfr_cleanup<b>::initializer const mpfr_cleanup<b>::init;
+
inline long get_default_precision() { return 50; }
template <unsigned digits10, mpfr_allocation_type AllocationType>
@@ -291,6 +307,7 @@
{
if(m_data[0]._mpfr_d)
mpfr_clear(m_data);
+ detail::mpfr_cleanup<true>::force_instantiate();
}
void negate() BOOST_NOEXCEPT
{
@@ -355,6 +372,10 @@
static const unsigned digits2 = (digits10 * 1000uL) / 301uL + ((digits10 * 1000uL) % 301 ? 2u : 1u);
static const unsigned limb_count = mpfr_custom_get_size(digits2) / sizeof(mp_limb_t);
+ ~mpfr_float_imp() BOOST_NOEXCEPT
+ {
+ detail::mpfr_cleanup<true>::force_instantiate();
+ }
mpfr_float_imp()
{
mpfr_custom_init(m_buffer, digits2);
Modified: trunk/libs/multiprecision/example/gmp_snips.cpp
==============================================================================
--- trunk/libs/multiprecision/example/gmp_snips.cpp (original)
+++ trunk/libs/multiprecision/example/gmp_snips.cpp 2013-03-22 12:55:36 EDT (Fri, 22 Mar 2013)
@@ -27,6 +27,7 @@
mpz_init(z);
mpz_set(z, v.backend().data());
//]
+ mpz_clear(z);
}
void t2()
@@ -57,6 +58,7 @@
mpf_init(f);
mpf_set(f, a.backend().data());
//]
+ mpf_clear(f);
}
void t3()
@@ -85,6 +87,7 @@
mpq_init(q);
mpq_set(q, v.backend().data());
//]
+ mpq_clear(q);
}
int main()
Modified: trunk/libs/multiprecision/example/mpfi_snips.cpp
==============================================================================
--- trunk/libs/multiprecision/example/mpfi_snips.cpp (original)
+++ trunk/libs/multiprecision/example/mpfi_snips.cpp 2013-03-22 12:55:36 EDT (Fri, 22 Mar 2013)
@@ -38,6 +38,7 @@
std::cout << overlap(i1, i2) << std::endl;
std::cout << subset(i1, i2) << std::endl;
//]
+ mpfi_clear(r);
}
int main()
Modified: trunk/libs/multiprecision/example/mpfr_snips.cpp
==============================================================================
--- trunk/libs/multiprecision/example/mpfr_snips.cpp (original)
+++ trunk/libs/multiprecision/example/mpfr_snips.cpp 2013-03-22 12:55:36 EDT (Fri, 22 Mar 2013)
@@ -35,6 +35,7 @@
mpfr_init(r);
mpfr_set(r, b.backend().data(), GMP_RNDN);
//]
+ mpfr_clear(r);
}
int main()
Modified: trunk/libs/multiprecision/test/test_gmp_conversions.cpp
==============================================================================
--- trunk/libs/multiprecision/test/test_gmp_conversions.cpp (original)
+++ trunk/libs/multiprecision/test/test_gmp_conversions.cpp 2013-03-22 12:55:36 EDT (Fri, 22 Mar 2013)
@@ -146,6 +146,10 @@
f100 = f50;
BOOST_TEST(f100 == 2);
+
+ mpf_clear(mpf);
+ mpz_clear(mpz);
+ mpq_clear(mpq);
return boost::report_errors();
}
Modified: trunk/libs/multiprecision/test/test_mpfr_conversions.cpp
==============================================================================
--- trunk/libs/multiprecision/test/test_mpfr_conversions.cpp (original)
+++ trunk/libs/multiprecision/test/test_mpfr_conversions.cpp 2013-03-22 12:55:36 EDT (Fri, 22 Mar 2013)
@@ -118,6 +118,11 @@
BOOST_TEST(f100 == 2);
f50 = static_cast<mpfr_float_50>(f100);
+
+ mpf_clear(mpf);
+ mpz_clear(mpz);
+ mpq_clear(mpq);
+ mpfr_clear(mpfr);
return boost::report_errors();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk