From 3030e604f4abe3d2155eb77c124829f1d7213f35 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 13 Mar 2006 23:42:21 +0000 Subject: Don't cleanup commodities if Ledger was built in release mode. --- amount.cc | 20 ++++++++++++++------ amount.h | 2 ++ main.cc | 3 +++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/amount.cc b/amount.cc index a2735d37..d9171715 100644 --- a/amount.cc +++ b/amount.cc @@ -9,6 +9,8 @@ namespace ledger { +bool do_cleanup = true; + #define BIGINT_BULK_ALLOC 0x0001 class amount_t::bigint_t { @@ -29,10 +31,7 @@ class amount_t::bigint_t { : prec(other.prec), flags(0), ref(1), index(0) { mpz_init_set(val, other.val); } - ~bigint_t() { - assert(ref == 0); - mpz_clear(val); - } + ~bigint_t(); }; unsigned int sizeof_bigint_t() { @@ -41,10 +40,16 @@ unsigned int sizeof_bigint_t() { #define MPZ(x) ((x)->val) -static mpz_t temp; -static mpz_t divisor; +static mpz_t temp; +static mpz_t divisor; + static amount_t::bigint_t true_value; +inline amount_t::bigint_t::~bigint_t() { + assert(ref == 0 || (! do_cleanup && this == &true_value)); + mpz_clear(val); +} + commodity_t::updater_t * commodity_t::updater = NULL; commodities_map commodity_t::commodities; commodity_t * commodity_t::null_commodity; @@ -83,6 +88,9 @@ static struct _init_amounts { } ~_init_amounts() { + if (! do_cleanup) + return; + mpz_clear(temp); mpz_clear(divisor); diff --git a/amount.h b/amount.h index 98df367b..d64c3c2d 100644 --- a/amount.h +++ b/amount.h @@ -12,6 +12,8 @@ namespace ledger { +extern bool do_cleanup; + class commodity_t; class amount_t diff --git a/main.cc b/main.cc index 7769a7c9..930fc903 100644 --- a/main.cc +++ b/main.cc @@ -350,6 +350,9 @@ int parse_and_report(int argc, char * argv[], char * envp[]) int main(int argc, char * argv[], char * envp[]) { try { +#if DEBUG_LEVEL < BETA + ledger::do_cleanup = false; +#endif return parse_and_report(argc, argv, envp); } catch (const std::exception& err) { -- cgit v1.2.3