Only initialize the amount_t module if it hasn't been already.
This commit is contained in:
parent
b4662911cc
commit
a085f8e9ad
2 changed files with 18 additions and 9 deletions
|
|
@ -87,13 +87,17 @@ struct amount_t::bigint_t : public supports_flags<>
|
||||||
|
|
||||||
shared_ptr<commodity_pool_t> amount_t::current_pool;
|
shared_ptr<commodity_pool_t> amount_t::current_pool;
|
||||||
|
|
||||||
|
bool amount_t::is_initialized = false;
|
||||||
|
|
||||||
void amount_t::initialize(shared_ptr<commodity_pool_t> pool)
|
void amount_t::initialize(shared_ptr<commodity_pool_t> pool)
|
||||||
{
|
{
|
||||||
mpz_init(temp);
|
if (! is_initialized) {
|
||||||
mpq_init(tempq);
|
mpz_init(temp);
|
||||||
mpfr_init(tempf);
|
mpq_init(tempq);
|
||||||
mpfr_init(tempfb);
|
mpfr_init(tempf);
|
||||||
|
mpfr_init(tempfb);
|
||||||
|
is_initialized = true;
|
||||||
|
}
|
||||||
current_pool = pool;
|
current_pool = pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,10 +110,13 @@ void amount_t::shutdown()
|
||||||
{
|
{
|
||||||
current_pool.reset();
|
current_pool.reset();
|
||||||
|
|
||||||
mpz_clear(temp);
|
if (is_initialized) {
|
||||||
mpq_clear(tempq);
|
mpz_clear(temp);
|
||||||
mpfr_clear(tempf);
|
mpq_clear(tempq);
|
||||||
mpfr_clear(tempfb);
|
mpfr_clear(tempf);
|
||||||
|
mpfr_clear(tempfb);
|
||||||
|
is_initialized = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void amount_t::_copy(const amount_t& amt)
|
void amount_t::_copy(const amount_t& amt)
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,8 @@ public:
|
||||||
@note Normally called by session_t::shutdown(). */
|
@note Normally called by session_t::shutdown(). */
|
||||||
static void shutdown();
|
static void shutdown();
|
||||||
|
|
||||||
|
static bool is_initialized;
|
||||||
|
|
||||||
/** The amount's decimal precision. */
|
/** The amount's decimal precision. */
|
||||||
typedef uint_least16_t precision_t;
|
typedef uint_least16_t precision_t;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue