diff options
author | John Wiegley <johnw@newartisans.com> | 2008-07-26 05:06:06 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-07-26 05:06:06 -0400 |
commit | 162d982b0cf1a5ac2e67012a3b8eadae3c1ac59f (patch) | |
tree | 1d29680db03ab4f8a82f77630a6e1a9fc10571bb | |
parent | 961b30926b3b9f2b3e9c1a99df3f25fea6b13118 (diff) | |
download | fork-ledger-162d982b0cf1a5ac2e67012a3b8eadae3c1ac59f.tar.gz fork-ledger-162d982b0cf1a5ac2e67012a3b8eadae3c1ac59f.tar.bz2 fork-ledger-162d982b0cf1a5ac2e67012a3b8eadae3c1ac59f.zip |
The --verify option is now working properly again. Use "--verify --verbose"
if you wish to see memory usage statistics along with a top-level trace.
-rw-r--r-- | format.cc | 16 | ||||
-rw-r--r-- | main.cc | 25 | ||||
-rw-r--r-- | session.cc | 2 | ||||
-rw-r--r-- | textual.cc | 14 | ||||
-rw-r--r-- | textual.h | 2 | ||||
-rw-r--r-- | utils.cc | 21 | ||||
-rw-r--r-- | valexpr.cc | 29 | ||||
-rw-r--r-- | valexpr.h | 28 | ||||
-rw-r--r-- | walk.h | 9 |
9 files changed, 98 insertions, 48 deletions
@@ -343,11 +343,19 @@ void format_t::format(std::ostream& out_str, const details_t& details) const case element_t::AMOUNT: case element_t::TOTAL: case element_t::VALUE_EXPR: { - value_expr calc; + value_expr * calc; switch (elem->type) { - case element_t::AMOUNT: calc = amount_expr; break; - case element_t::TOTAL: calc = total_expr; break; - case element_t::VALUE_EXPR: calc = elem->val_expr; break; + case element_t::AMOUNT: + assert(value_expr::amount_expr.get()); + calc = value_expr::amount_expr.get(); + break; + case element_t::TOTAL: + assert(value_expr::total_expr.get()); + calc = value_expr::total_expr.get(); + break; + case element_t::VALUE_EXPR: + calc = const_cast<value_expr *>(&elem->val_expr); + break; default: assert(false); break; @@ -314,6 +314,31 @@ static int read_and_report(ledger::report_t& report, int argc, char * argv[], INFO_FINISH(command); + // Clean up memory, if we + + if (DO_VERIFY()) { + TRACE_START(cleanup, 1, "Cleaning up allocated memory"); + + clear_transaction_xdata xact_cleaner; + walk_entries(journal.entries, xact_cleaner); + + clear_account_xdata acct_cleaner; + walk_accounts(*journal.master, acct_cleaner); + + if (report.output_file) + checked_delete(out); + +#if 0 + for (std::list<item_handler<transaction_t> *>::iterator i + = formatter_ptrs.begin(); + i != formatter_ptrs.end(); + i++) + checked_delete(*i); +#endif + + TRACE_FINISH(cleanup, 1); + } + // Write out the binary cache, if need be if (session.use_cache && session.cache_dirty && session.cache_file) { @@ -301,10 +301,12 @@ static void initialize() { amount_t::initialize(); value_t::initialize(); + value_expr::initialize(); } static void shutdown() { + value_expr::shutdown(); value_t::shutdown(); amount_t::shutdown(); } @@ -50,14 +50,14 @@ struct time_entry_t #endif namespace { - expr::parser_t amount_parser; - - static value_expr parse_amount_expr(std::istream& in, amount_t& amount, - transaction_t * xact, - unsigned short flags = 0) + value_expr parse_amount_expr(std::istream& in, + amount_t& amount, + transaction_t * xact, + unsigned short flags = 0) { value_expr expr = - amount_parser.parse(in, flags | EXPR_PARSE_RELAXED | EXPR_PARSE_PARTIAL); + value_expr::parser->parse(in, flags | + EXPR_PARSE_RELAXED | EXPR_PARSE_PARTIAL); DEBUG("ledger.textual.parse", "line " << linenum << ": " << "Parsed an amount expression"); @@ -870,7 +870,7 @@ unsigned int textual_parser_t::parse(std::istream& in, default: { unsigned long pos = beg_pos; - TRACE_START(entries, 1, "Time spent handling entries:"); + TRACE_START(entries, 1, "Time spent handling entries:"); if (entry_t * entry = parse_entry(in, line, account_stack.front(), *this, pos)) { if (journal.add_entry(entry)) { @@ -9,7 +9,7 @@ namespace ledger { class textual_parser_t : public parser_t { - public: +public: virtual bool test(std::istream& in) const; virtual unsigned int parse(std::istream& in, @@ -109,21 +109,20 @@ void shutdown_memory_tracing() if (live_objects) { IF_DEBUG("memory.counts") report_memory(std::cerr, true); - else - IF_DEBUG("memory.counts.live") - report_memory(std::cerr); + else IF_DEBUG("memory.counts.live") + report_memory(std::cerr); else if (live_objects->size() > 0) report_memory(std::cerr); } - checked_delete(live_memory); live_memory = NULL; - checked_delete(live_memory_count); live_memory_count = NULL; + checked_delete(live_memory); live_memory = NULL; + checked_delete(live_memory_count); live_memory_count = NULL; checked_delete(total_memory_count); total_memory_count = NULL; - checked_delete(live_objects); live_objects = NULL; - checked_delete(live_object_count); live_object_count = NULL; + checked_delete(live_objects); live_objects = NULL; + checked_delete(live_object_count); live_object_count = NULL; checked_delete(total_object_count); total_object_count = NULL; - checked_delete(total_ctor_count); total_ctor_count = NULL; + checked_delete(total_ctor_count); total_ctor_count = NULL; } inline void add_to_count_map(object_count_map& the_map, @@ -254,7 +253,7 @@ inline void report_count_map(std::ostream& out, object_count_map& the_map) i != the_map.end(); i++) out << " " << std::right << std::setw(12) << (*i).second.first - << " " << std::right << std::setw(12) << (*i).second.second + << " " << std::right << std::setw(7) << (*i).second.second << " " << std::left << (*i).first << std::endl; } @@ -347,7 +346,7 @@ void report_memory(std::ostream& out, bool report_all) for (live_memory_map::const_iterator i = live_memory->begin(); i != live_memory->end(); i++) - out << " " << std::right << std::setw(7) << (*i).first + out << " " << std::right << std::setw(12) << (*i).first << " " << std::right << std::setw(7) << (*i).second.second << " " << std::left << (*i).second.first << std::endl; @@ -369,7 +368,7 @@ void report_memory(std::ostream& out, bool report_all) for (live_objects_map::const_iterator i = live_objects->begin(); i != live_objects->end(); i++) - out << " " << std::right << std::setw(7) << (*i).first + out << " " << std::right << std::setw(12) << (*i).first << " " << std::right << std::setw(7) << (*i).second.second << " " << std::left << (*i).second.first << std::endl; @@ -36,9 +36,6 @@ namespace ledger { -value_expr amount_expr; -value_expr total_expr; - namespace expr { std::auto_ptr<symbol_scope_t> global_scope; @@ -307,14 +304,14 @@ void op_t::compute(value_t& result, const details_t& details, break; case VALUE_EXPR: - if (amount_expr.get()) - amount_expr->compute(result, details, context); + if (value_expr::amount_expr.get()) + value_expr::amount_expr->compute(result, details, context); else result = 0L; break; case TOTAL_EXPR: - if (total_expr.get()) - total_expr->compute(result, details, context); + if (value_expr::total_expr.get()) + value_expr::total_expr->compute(result, details, context); else result = 0L; break; @@ -1080,8 +1077,20 @@ value_t op_t::calc(scope_t& scope) } // namespace expr -namespace { - expr::parser_t value_expr_parser; +std::auto_ptr<value_expr> value_expr::amount_expr; +std::auto_ptr<value_expr> value_expr::total_expr; +std::auto_ptr<expr::parser_t> value_expr::parser; + +void value_expr::initialize() +{ + parser.reset(new expr::parser_t); +} + +void value_expr::shutdown() +{ + amount_expr.reset(); + total_expr.reset(); + parser.reset(); } value_expr::value_expr(const string& _expr_str) : expr_str(_expr_str) @@ -1089,7 +1098,7 @@ value_expr::value_expr(const string& _expr_str) : expr_str(_expr_str) TRACE_CTOR(value_expr, "const string&"); if (! _expr_str.empty()) - ptr = value_expr_parser.parse(expr_str).ptr; + ptr = parser->parse(expr_str).ptr; } } // namespace ledger @@ -825,6 +825,8 @@ inline ptr_op_t op_t::wrap_functor(const function_t& fobj) { return temp; } +class parser_t; + } // namespace expr ////////////////////////////////////////////////////////////////////// @@ -902,33 +904,37 @@ public: const expr::ptr_op_t node_to_find, unsigned long * start_pos, unsigned long * end_pos); + + static std::auto_ptr<value_expr> amount_expr; + static std::auto_ptr<value_expr> total_expr; + static std::auto_ptr<expr::parser_t> parser; + + static void initialize(); + static void shutdown(); }; typedef value_expr::details_t details_t; // jww (2008-07-20): remove -extern value_expr amount_expr; -extern value_expr total_expr; - inline void compute_amount(value_t& result, const details_t& details = details_t()) { - if (amount_expr) - amount_expr->compute(result, details); + if (value_expr::amount_expr.get()) + value_expr::amount_expr->compute(result, details); } inline value_t compute_amount(const details_t& details = details_t()) { - if (amount_expr) - return amount_expr->compute(details); + if (value_expr::amount_expr.get()) + return value_expr::amount_expr->compute(details); } inline void compute_total(value_t& result, const details_t& details = details_t()) { - if (total_expr) - total_expr->compute(result, details); + if (value_expr::total_expr.get()) + value_expr::total_expr->compute(result, details); } inline value_t compute_total(const details_t& details = details_t()) { - if (total_expr) - return total_expr->compute(details); + if (value_expr::total_expr.get()) + return value_expr::total_expr->compute(details); } ////////////////////////////////////////////////////////////////////// @@ -110,7 +110,6 @@ struct transaction_xdata_t : public noncopyable account(NULL), ptr(NULL), component_xacts(NULL) { TRACE_CTOR(transaction_xdata_t, ""); } - ~transaction_xdata_t() { TRACE_DTOR(transaction_xdata_t); if (component_xacts) @@ -154,9 +153,11 @@ transaction_xdata_t& transaction_xdata(const transaction_t& xact); void add_transaction_to(const transaction_t& xact, value_t& value); inline account_t * xact_account(transaction_t& xact) { - account_t * account = transaction_xdata(xact).account; - if (account) - return account; + if (xact.data) { + account_t * account = transaction_xdata(xact).account; + if (account) + return account; + } return xact.account; } |