diff options
-rw-r--r-- | amount.cc | 14 | ||||
-rw-r--r-- | amount.h | 32 | ||||
-rw-r--r-- | balance.cc | 8 | ||||
-rw-r--r-- | balance.h | 20 | ||||
-rw-r--r-- | debug.cc | 76 | ||||
-rw-r--r-- | debug.h | 4 | ||||
-rw-r--r-- | format.h | 10 | ||||
-rw-r--r-- | journal.cc | 8 | ||||
-rw-r--r-- | journal.h | 34 | ||||
-rw-r--r-- | main.cc | 9 | ||||
-rw-r--r-- | report.cc | 2 | ||||
-rw-r--r-- | report.h | 2 | ||||
-rw-r--r-- | session.cc | 3 | ||||
-rw-r--r-- | session.h | 10 | ||||
-rw-r--r-- | trace.cc | 188 | ||||
-rw-r--r-- | trace.h | 44 | ||||
-rw-r--r-- | transform.h | 2 | ||||
-rw-r--r-- | value.h | 40 | ||||
-rw-r--r-- | xml.cc | 37 | ||||
-rw-r--r-- | xml.h | 130 | ||||
-rw-r--r-- | xpath.cc | 2 | ||||
-rw-r--r-- | xpath.h | 28 |
22 files changed, 340 insertions, 363 deletions
@@ -67,17 +67,17 @@ class amount_t::bigint_t unsigned int index; bigint_t() : prec(0), flags(0), ref(1), index(0) { - TRACE_CTOR("bigint_t()"); + TRACE_CTOR(bigint_t, ""); mpz_init(val); } bigint_t(mpz_t _val) : prec(0), flags(0), ref(1), index(0) { - TRACE_CTOR("bigint_t(mpz_t)"); + TRACE_CTOR(bigint_t, "mpz_t"); mpz_init_set(val, _val); } bigint_t(const bigint_t& other) : prec(other.prec), flags(other.flags & BIGINT_KEEP_PREC), ref(1), index(0) { - TRACE_CTOR("bigint_t(copy)"); + TRACE_CTOR(bigint_t, "copy"); mpz_init_set(val, other.val); } ~bigint_t(); @@ -97,7 +97,7 @@ static mpz_t divisor; static amount_t::bigint_t * true_value = NULL; inline amount_t::bigint_t::~bigint_t() { - TRACE_DTOR("bigint_t"); + TRACE_DTOR(bigint_t); assert(ref == 0 || (! do_cleanup && this == true_value)); mpz_clear(val); } @@ -219,7 +219,7 @@ static void mpz_round(mpz_t out, mpz_t value, int value_prec, int round_prec) amount_t::amount_t(const long val) { - TRACE_CTOR("amount_t(const long)"); + TRACE_CTOR(amount_t, "const long"); if (val != 0) { quantity = new bigint_t; mpz_set_si(MPZ(quantity), val); @@ -231,7 +231,7 @@ amount_t::amount_t(const long val) amount_t::amount_t(const unsigned long val) { - TRACE_CTOR("amount_t(const unsigned long)"); + TRACE_CTOR(amount_t, "const unsigned long"); if (val != 0) { quantity = new bigint_t; mpz_set_ui(MPZ(quantity), val); @@ -329,7 +329,7 @@ namespace { amount_t::amount_t(const double val) { - TRACE_CTOR("amount_t(const double)"); + TRACE_CTOR(amount_t, "const double"); quantity = new bigint_t; quantity->prec = convert_double(MPZ(quantity), val); commodity_ = NULL; @@ -48,7 +48,7 @@ #define _AMOUNT_H #include <map> -#include <deque> +#include <vector> #include <stack> #include <string> #include <cctype> @@ -107,21 +107,21 @@ class amount_t public: // constructors amount_t() : quantity(NULL), commodity_(NULL) { - TRACE_CTOR("amount_t()"); + TRACE_CTOR(amount_t, ""); } amount_t(const amount_t& amt) : quantity(NULL) { - TRACE_CTOR("amount_t(copy)"); + TRACE_CTOR(amount_t, "copy"); if (amt.quantity) _copy(amt); else commodity_ = NULL; } amount_t(const string& val) : quantity(NULL) { - TRACE_CTOR("amount_t(const string&)"); + TRACE_CTOR(amount_t, "const string&"); parse(val); } amount_t(const char * val) : quantity(NULL) { - TRACE_CTOR("amount_t(const char *)"); + TRACE_CTOR(amount_t, "const char *"); parse(val); } amount_t(const long val); @@ -130,7 +130,7 @@ class amount_t // destructor ~amount_t() { - TRACE_DTOR("amount_t"); + TRACE_DTOR(amount_t); if (quantity) _release(); } @@ -499,11 +499,11 @@ class commodity_base_t commodity_base_t() : precision(0), flags(COMMODITY_STYLE_DEFAULTS), smaller(NULL), larger(NULL), history(NULL) { - TRACE_CTOR("commodity_base_t()"); + TRACE_CTOR(commodity_base_t, ""); } commodity_base_t(const commodity_base_t&) { - TRACE_CTOR("commodity_base_t(copy)"); + TRACE_CTOR(commodity_base_t, "copy"); assert(0); } @@ -512,11 +512,11 @@ class commodity_base_t unsigned int _flags = COMMODITY_STYLE_DEFAULTS) : precision(_precision), flags(_flags), smaller(NULL), larger(NULL), symbol(_symbol), history(NULL) { - TRACE_CTOR("commodity_base_t(const string&, unsigned int, unsigned int)"); + TRACE_CTOR(commodity_base_t, "const string&, unsigned int, unsigned int"); } ~commodity_base_t() { - TRACE_DTOR("commodity_base_t"); + TRACE_DTOR(commodity_base_t); if (history) delete history; if (smaller) delete smaller; if (larger) delete larger; @@ -555,7 +555,7 @@ class commodity_base_t typedef std::map<const string, commodity_t *> commodities_map; typedef std::pair<const string, commodity_t *> commodities_pair; -typedef std::deque<commodity_t *> commodities_array; +typedef std::vector<commodity_t *> commodities_array; class commodity_t { @@ -590,15 +590,15 @@ class commodity_t public: explicit commodity_t() : base(NULL), annotated(false) { - TRACE_CTOR("commodity_t()"); + TRACE_CTOR(commodity_t, ""); } commodity_t(const commodity_t& o) : ident(o.ident), base(o.base), qualified_symbol(o.qualified_symbol), annotated(o.annotated) { - TRACE_CTOR("commodity_t(copy)"); + TRACE_CTOR(commodity_t, "copy"); } virtual ~commodity_t() { - TRACE_DTOR("commodity_t"); + TRACE_DTOR(commodity_t); } operator bool() const { @@ -703,11 +703,11 @@ class annotated_commodity_t : public commodity_t string tag; explicit annotated_commodity_t() { - TRACE_CTOR("annotated_commodity_t()"); + TRACE_CTOR(annotated_commodity_t, ""); annotated = true; } virtual ~annotated_commodity_t() { - TRACE_DTOR("annotated_commodity_t"); + TRACE_DTOR(annotated_commodity_t); } virtual bool operator==(const commodity_t& comm) const; @@ -1,7 +1,7 @@ #include "balance.h" #include "util.h" -#include <deque> +#include <vector> #include <algorithm> namespace ledger { @@ -115,8 +115,8 @@ void balance_t::write(std::ostream& out, out << std::right << (*i).second; } } else { - typedef std::deque<const amount_t *> amounts_deque; - amounts_deque sorted; + typedef std::vector<const amount_t *> amounts_array; + amounts_array sorted; for (amounts_map::const_iterator i = amounts.begin(); i != amounts.end(); @@ -127,7 +127,7 @@ void balance_t::write(std::ostream& out, std::stable_sort(sorted.begin(), sorted.end(), compare_amount_commodities()); - for (amounts_deque::const_iterator i = sorted.begin(); + for (amounts_array::const_iterator i = sorted.begin(); i != sorted.end(); i++) { int width; @@ -24,23 +24,23 @@ class balance_t // constructors balance_t() { - TRACE_CTOR("balance_t()"); + TRACE_CTOR(balance_t, ""); } balance_t(const balance_t& bal) { - TRACE_CTOR("balance_t(copy)"); + TRACE_CTOR(balance_t, "copy"); for (amounts_map::const_iterator i = bal.amounts.begin(); i != bal.amounts.end(); i++) *this += (*i).second; } balance_t(const amount_t& amt) { - TRACE_CTOR("balance_t(const amount_t&)"); + TRACE_CTOR(balance_t, "const amount_t&"); if (! amt.realzero()) amounts.insert(amounts_pair(&amt.commodity(), amt)); } template <typename T> balance_t(T val) { - TRACE_CTOR("balance_t(T)"); + TRACE_CTOR(balance_t, "T"); amount_t amt(val); if (! amt.realzero()) amounts.insert(amounts_pair(&amt.commodity(), amt)); @@ -502,30 +502,30 @@ class balance_pair_t // constructors balance_pair_t() : cost(NULL) { - TRACE_CTOR("balance_pair_t()"); + TRACE_CTOR(balance_pair_t, ""); } balance_pair_t(const balance_pair_t& bal_pair) : quantity(bal_pair.quantity), cost(NULL) { - TRACE_CTOR("balance_pair_t(copy)"); + TRACE_CTOR(balance_pair_t, "copy"); if (bal_pair.cost) cost = new balance_t(*bal_pair.cost); } balance_pair_t(const balance_t& _quantity) : quantity(_quantity), cost(NULL) { - TRACE_CTOR("balance_pair_t(const balance_t&)"); + TRACE_CTOR(balance_pair_t, "const balance_t&"); } balance_pair_t(const amount_t& _quantity) : quantity(_quantity), cost(NULL) { - TRACE_CTOR("balance_pair_t(const amount_t&)"); + TRACE_CTOR(balance_pair_t, "const amount_t&"); } template <typename T> balance_pair_t(T val) : quantity(val), cost(NULL) { - TRACE_CTOR("balance_pair_t(T)"); + TRACE_CTOR(balance_pair_t, "T"); } // destructor ~balance_pair_t() { - TRACE_DTOR("balance_pair_t"); + TRACE_DTOR(balance_pair_t); if (cost) delete cost; } @@ -8,88 +8,43 @@ #include <unistd.h> // for the `write' method -int offset = 0; - -std::map<void *, int> ptrs; - -#define PRINT_INC(x) { \ - char buf[128]; \ - std::sprintf(buf, "%d: %p: %s", ++offset, ptr, x); \ - write(1, buf, std::strlen(buf)); \ -} - -#define PRINT_DEC(x) { \ - char buf[128]; \ - std::sprintf(buf, "%d: %p: %s", --offset, ptr, x); \ - write(1, buf, std::strlen(buf)); \ -} +int new_calls = 0; +int new_size = 0; void * operator new(std::size_t size) throw (std::bad_alloc) { void * ptr = std::malloc(size); -#if 0 // jww (2007-04-19): these don't work with boost::regex - if (DEBUG("debug.alloc")) { - PRINT_INC("void * operator new(std::size_t size) throw (std::bad_alloc)\n"); - } -#endif + new_calls++; + new_size += size; return ptr; } void * operator new[](std::size_t size) throw (std::bad_alloc) { void * ptr = std::malloc(size); -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_INC("void * operator new[](std::size_t) throw (std::bad_alloc)\n"); - } -#endif + new_calls++; + new_size += size; return ptr; } void * operator new(std::size_t size, const std::nothrow_t&) throw() { void * ptr = std::malloc(size); -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_INC("void * operator new(std::size_t size, const std::nothrow_t&) throw()\n"); - } -#endif + new_calls++; + new_size += size; return ptr; } void * operator new[](std::size_t size, const std::nothrow_t&) throw() { void * ptr = std::malloc(size); -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_INC("void * operator new[](std::size_t size, const std::nothrow_t&) throw()\n"); - } -#endif + new_calls++; + new_size += size; return ptr; } void operator delete(void * ptr) throw() { -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_DEC("void operator delete(void * ptr) throw()\n"); - } -#endif std::free(ptr); } void operator delete[](void * ptr) throw() { -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_DEC("void operator delete[](void * ptr) throw()\n"); - } -#endif std::free(ptr); } void operator delete(void * ptr, const std::nothrow_t&) throw() { -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_DEC("void operator delete(void * ptr, const std::nothrow_t&) throw()\n"); - } -#endif std::free(ptr); } void operator delete[](void * ptr, const std::nothrow_t&) throw() { -#if 0 - if (DEBUG("debug.alloc")) { - PRINT_DEC("void operator delete[](void * ptr, const std::nothrow_t&) throw()\n"); - } -#endif std::free(ptr); } @@ -97,13 +52,20 @@ std::ostream * _debug_stream = &std::cerr; bool _free_debug_stream = false; boost::regex _debug_regex; bool _set_debug_regex = false; +bool _debug_regex_on = false; bool _debug_active(const char * const cls) { if (! _set_debug_regex) { - _debug_regex = std::getenv("DEBUG_CLASS"); + const char * user_class = std::getenv("DEBUG_CLASS"); + if (user_class) { + _debug_regex = user_class; + _debug_regex_on = true; + } _set_debug_regex = true; } - return boost::regex_match(cls, _debug_regex); + if (_debug_regex_on) + return boost::regex_match(cls, _debug_regex); + return false; } static struct init_streams { @@ -142,7 +142,7 @@ void operator delete[](void*, const std::nothrow_t&) throw(); #define CONFIRM(x) #ifndef TRACE_CTOR -#define TRACE_CTOR(cls) +#define TRACE_CTOR(cls, args) #define TRACE_DTOR(cls) #define TRACE(cat, msg) #define TRACE_PUSH(cat, msg) @@ -154,7 +154,7 @@ void operator delete[](void*, const std::nothrow_t&) throw(); #define CONFIRM(x) #ifndef TRACE_CTOR -#define TRACE_CTOR(cls) +#define TRACE_CTOR(cls, args) #define TRACE_DTOR(cls) #define TRACE(cat, msg) #define TRACE_PUSH(cat, msg) @@ -28,11 +28,11 @@ class format_t element_t() : align_left(false), min_width(-1), max_width(-1), kind(UNKNOWN), chars(NULL) { - TRACE_CTOR("element_t()"); + TRACE_CTOR(element_t, ""); } ~element_t() { - TRACE_DTOR("element_t"); + TRACE_DTOR(element_t); switch (kind) { case TEXT: @@ -68,10 +68,10 @@ class format_t public: format_t() { - TRACE_CTOR("format_t()"); + TRACE_CTOR(format_t, ""); } format_t(const string& fmt) { - TRACE_CTOR("format_t(const string&)"); + TRACE_CTOR(format_t, "const string&"); parse(fmt); } @@ -84,7 +84,7 @@ class format_t } virtual ~format_t() { - TRACE_DTOR("format_t"); + TRACE_DTOR(format_t); clear_elements(); } @@ -18,7 +18,7 @@ bool transaction_t::use_effective_date = false; transaction_t::~transaction_t() { - TRACE_DTOR("transaction_t"); + TRACE_DTOR(transaction_t); if (cost) delete cost; } @@ -274,7 +274,7 @@ entry_t::entry_t(const entry_t& e) : entry_base_t(e), _date(e._date), _date_eff(e._date_eff), code(e.code), payee(e.payee), data(NULL) { - TRACE_CTOR("entry_t(copy)"); + TRACE_CTOR(entry_t, "copy"); for (transactions_list::const_iterator i = transactions.begin(); i != transactions.end(); i++) @@ -366,7 +366,7 @@ void auto_entry_t::extend_entry(entry_base_t& entry, bool post) account_t::~account_t() { - TRACE_DTOR("account_t"); + TRACE_DTOR(account_t); for (accounts_map::iterator i = accounts.begin(); i != accounts.end(); @@ -493,7 +493,7 @@ bool account_t::valid() const journal_t::~journal_t() { - TRACE_DTOR("journal_t"); + TRACE_DTOR(journal_t); assert(master); delete master; @@ -46,7 +46,7 @@ class transaction_t : entry(NULL), account(_account), cost(NULL), state(UNCLEARED), flags(TRANSACTION_NORMAL), beg_pos(0), beg_line(0), end_pos(0), end_line(0), data(NULL) { - TRACE_CTOR("transaction_t(account_t *)"); + TRACE_CTOR(transaction_t, "account_t *"); } transaction_t(account_t * _account, const amount_t& _amount, @@ -56,14 +56,14 @@ class transaction_t state(UNCLEARED), flags(_flags), note(_note), beg_pos(0), beg_line(0), end_pos(0), end_line(0), data(NULL) { - TRACE_CTOR("transaction_t(account_t *, const amount_t&, unsigned int, const string&)"); + TRACE_CTOR(transaction_t, "account_t *, const amount_t&, unsigned int, const string&"); } transaction_t(const transaction_t& xact) : entry(xact.entry), account(xact.account), amount(xact.amount), cost(xact.cost ? new amount_t(*xact.cost) : NULL), state(xact.state), flags(xact.flags), note(xact.note), beg_pos(0), beg_line(0), end_pos(0), end_line(0), data(NULL) { - TRACE_CTOR("transaction_t(copy)"); + TRACE_CTOR(transaction_t, "copy"); } ~transaction_t(); @@ -112,19 +112,19 @@ class entry_base_t entry_base_t() : journal(NULL), beg_pos(0), beg_line(0), end_pos(0), end_line(0) { - TRACE_CTOR("entry_base_t()"); + TRACE_CTOR(entry_base_t, ""); } entry_base_t(const entry_base_t& e) : journal(NULL), beg_pos(0), beg_line(0), end_pos(0), end_line(0) { - TRACE_CTOR("entry_base_t(copy)"); + TRACE_CTOR(entry_base_t, "copy"); for (transactions_list::const_iterator i = e.transactions.begin(); i != e.transactions.end(); i++) transactions.push_back(new transaction_t(**i)); } virtual ~entry_base_t() { - TRACE_DTOR("entry_base_t"); + TRACE_DTOR(entry_base_t); for (transactions_list::iterator i = transactions.begin(); i != transactions.end(); i++) @@ -159,12 +159,12 @@ class entry_t : public entry_base_t mutable void * data; entry_t() : data(NULL) { - TRACE_CTOR("entry_t()"); + TRACE_CTOR(entry_t, ""); } entry_t(const entry_t& e); virtual ~entry_t() { - TRACE_DTOR("entry_t"); + TRACE_DTOR(entry_t); } moment_t actual_date() const { @@ -224,15 +224,15 @@ public: xml::xpath_t predicate; auto_entry_t() { - TRACE_CTOR("auto_entry_t()"); + TRACE_CTOR(auto_entry_t, ""); } auto_entry_t(const string& _predicate) : predicate(_predicate) { - TRACE_CTOR("auto_entry_t(const string&)"); + TRACE_CTOR(auto_entry_t, "const string&"); } virtual ~auto_entry_t() { - TRACE_DTOR("auto_entry_t"); + TRACE_DTOR(auto_entry_t); } virtual void extend_entry(entry_base_t& entry, bool post); @@ -255,19 +255,19 @@ class period_entry_t : public entry_base_t string period_string; period_entry_t() { - TRACE_CTOR("period_entry_t()"); + TRACE_CTOR(period_entry_t, ""); } period_entry_t(const string& _period) : period(_period), period_string(_period) { - TRACE_CTOR("period_entry_t(const string&)"); + TRACE_CTOR(period_entry_t, "const string&"); } period_entry_t(const period_entry_t& e) : entry_base_t(e), period(e.period), period_string(e.period_string) { - TRACE_CTOR("period_entry_t(copy)"); + TRACE_CTOR(period_entry_t, "copy"); } virtual ~period_entry_t() { - TRACE_DTOR("period_entry_t"); + TRACE_DTOR(period_entry_t); } virtual bool valid() const { @@ -300,7 +300,7 @@ class account_t const string& _note = "") : parent(_parent), name(_name), note(_note), depth(parent ? parent->depth + 1 : 0), data(NULL), ident(0) { - TRACE_CTOR("account_t(account_t *, const string&, const string&)"); + TRACE_CTOR(account_t, "account_t *, const string&, const string&"); } ~account_t(); @@ -407,7 +407,7 @@ class journal_t journal_t(session_t * _session) : session(_session), basket(NULL), item_pool(NULL), item_pool_end(NULL), document(NULL) { - TRACE_CTOR("journal_t()"); + TRACE_CTOR(journal_t, ""); master = new account_t(NULL, ""); master->journal = this; } @@ -396,6 +396,11 @@ static int read_and_report(report_t * report, int argc, char * argv[], return 0; } +#ifdef DEBUG_ENABLED +extern int new_calls; +extern int new_size; +#endif + int main(int argc, char * argv[], char * envp[]) { int status = 1; @@ -429,7 +434,7 @@ int main(int argc, char * argv[], char * envp[]) #if DEBUG_LEVEL >= BETA DEBUG_IF("ledger.trace.memory") { - ledger::trace_mode = true; + ledger::trace_class_mode = true; } #endif @@ -490,6 +495,8 @@ int main(int argc, char * argv[], char * envp[]) #if DEBUG_LEVEL >= BETA DEBUG_IF("ledger.trace.memory") { report_memory(std::cerr); + std::cerr << "Total calls to new: " << new_calls << std::endl + << "Total memory new'd: " << new_size << std::endl; } ledger::tracing_active = false; #endif @@ -6,7 +6,7 @@ namespace ledger { report_t::~report_t() { - TRACE_DTOR("report_t"); + TRACE_DTOR(report_t); for (std::list<transform_t *>::const_iterator i = transforms.begin(); i != transforms.end(); i++) @@ -40,7 +40,7 @@ class report_t : public xml::xpath_t::scope_t session(_session), last_transform(NULL) { - TRACE_CTOR("report_t(session_t *)"); + TRACE_CTOR(report_t, "session_t *"); eval("t=total,TOT=0,T()=(TOT=TOT+t,TOT)"); } @@ -226,7 +226,8 @@ void export_session() .def_readwrite("cache_dirty", &session_t::cache_dirty) .def_readwrite("debug_mode", &session_t::debug_mode) .def_readwrite("verbose_mode", &session_t::verbose_mode) - .def_readwrite("trace_mode", &session_t::trace_mode) + .def_readwrite("trace_alloc_mode", &session_t::trace_alloc_mode) + .def_readwrite("trace_class_mode", &session_t::trace_class_mode) .def_readwrite("journals", &session_t::journals) ; @@ -35,7 +35,8 @@ class session_t : public xml::xpath_t::scope_t bool cache_dirty; bool debug_mode; bool verbose_mode; - bool trace_mode; + bool trace_alloc_mode; + bool trace_class_mode; moment_t now; @@ -89,7 +90,8 @@ class session_t : public xml::xpath_t::scope_t cache_dirty(false), debug_mode(false), verbose_mode(false), - trace_mode(false), + trace_alloc_mode(false), + trace_class_mode(false), now(now), @@ -98,11 +100,11 @@ class session_t : public xml::xpath_t::scope_t ansi_codes(false), ansi_invert(false) { - TRACE_CTOR("session_t(xml::xpath_t::scope_t *)"); + TRACE_CTOR(session_t, "xml::xpath_t::scope_t *"); } virtual ~session_t() { - TRACE_DTOR("session_t"); + TRACE_DTOR(session_t); for (std::list<journal_t *>::iterator i = journals.begin(); i != journals.end(); @@ -6,7 +6,8 @@ namespace ledger { -bool trace_mode; +bool trace_alloc_mode; +bool trace_class_mode; void trace(const string& cat, const string& str) { @@ -37,94 +38,99 @@ object_count_map live_count; bool tracing_active = false; -bool trace_ctor(void * ptr, const char * name) +inline void add_to_count_map(object_count_map& the_map, + const char * name, std::size_t size) +{ + object_count_map::iterator k = the_map.find(name); + if (k != the_map.end()) { + (*k).second.first++; + (*k).second.second += size; + } else { + std::pair<object_count_map::iterator, bool> result = + the_map.insert(object_count_pair(name, count_size_pair(1, size))); + assert(result.second); + } +} + +inline void report_count_map(std::ostream& out, object_count_map& the_map) +{ + for (object_count_map::iterator i = the_map.begin(); + i != the_map.end(); + i++) + out << " " << std::right << std::setw(12) << (*i).second.first + << " " << std::right << std::setw(12) << (*i).second.second + << " " << std::left << (*i).first + << std::endl; +} + +bool trace_ctor(void * ptr, const char * cls_name, const char * args, + std::size_t cls_size) { if (! tracing_active) return true; - DEBUG_PRINT("ledger.trace.debug", "trace_ctor " << ptr << " " << name); + if (trace_class_mode && cls_name[0] == '_') + return true; + if (trace_alloc_mode && cls_name[0] != '_') + return true; + + static char name[1024]; + std::strcpy(name, cls_name); + std::strcat(name, "("); + std::strcat(name, args); + std::strcat(name, ")"); - const char * pos = std::strchr(name, '('); - static char cls_name[1024]; - std::strncpy(cls_name, name, pos - name); - cls_name[pos - name] = '\0'; + DEBUG_PRINT("ledger.trace.debug", + "trace_ctor " << ptr << " " << name); live_objects.insert(live_objects_pair(ptr, cls_name)); - object_count_map::iterator i = ctor_count.find(name); - if (i != ctor_count.end()) { - (*i).second++; - } else { - std::pair<object_count_map::iterator, bool> result - = ctor_count.insert(object_count_pair(name, 1)); - if (! result.second) { - tracing_active = false; - return false; - } - } - - object_count_map::iterator j = object_count.find(cls_name); - if (j != object_count.end()) { - (*j).second++; - } else { - std::pair<object_count_map::iterator, bool> result - = object_count.insert(object_count_pair(cls_name, 1)); - if (! result.second) { - tracing_active = false; - return false; - } - } - - object_count_map::iterator k = live_count.find(cls_name); - if (k != live_count.end()) { - (*k).second++; - } else { - std::pair<object_count_map::iterator, bool> result - = live_count.insert(object_count_pair(cls_name, 1)); - if (! result.second) { - tracing_active = false; - return false; - } - } + add_to_count_map(ctor_count, name, cls_size); + add_to_count_map(object_count, cls_name, cls_size); + add_to_count_map(object_count, "__ALL__", cls_size); + add_to_count_map(live_count, cls_name, cls_size); return true; } -bool trace_dtor(void * ptr, const char * name) +bool trace_dtor(void * ptr, const char * cls_name, std::size_t cls_size) { if (! tracing_active) return true; - DEBUG_PRINT("ledger.trace.debug", "trace_dtor " << ptr << " " << name); + if (trace_class_mode && cls_name[0] == '_') + return true; + if (trace_alloc_mode && cls_name[0] != '_') + return true; + + DEBUG_PRINT("ledger.trace.debug", "trace_dtor " << ptr << " " << cls_name); live_objects_map::iterator i = live_objects.find(ptr); if (i == live_objects.end()) { - std::cerr << "Destruction of unknown object " << name << " " << ptr - << std::endl;; - tracing_active = false; + std::cerr << "Destruction of unknown object of type " << cls_name + << " " << ptr << std::endl; + assert(0); return false; } - const char * cls_name = name; - int ptr_count = live_objects.count(ptr); - for (int x = 0; x < ptr_count; x++) { + for (int x = 0; x < ptr_count; x++, i++) { if ((*i).second == cls_name) { live_objects.erase(i); break; - } else { - i++; } } - object_count_map::iterator k = live_count.find(name); + object_count_map::iterator k = live_count.find(cls_name); if (k == live_count.end()) { - std::cerr << "Destruction of unregistered class " << name + std::cerr << "Destruction of unregistered class " << cls_name << std::endl;; - tracing_active = false; + assert(0); return false; } - if (--(*k).second == 0) + + (*k).second.second -= cls_size; + if (--(*k).second.first == 0) live_count.erase(k); return true; @@ -132,91 +138,67 @@ bool trace_dtor(void * ptr, const char * name) void report_memory(std::ostream& out) { - if (live_count.size() > 0) + if (live_count.size() > 0) { out << "Live object counts:" << std::endl; - - for (object_count_map::iterator i = live_count.begin(); - i != live_count.end(); - i++) { - out << " "; - out << std::right; - out.width(7); - out << (*i).second << " " << (*i).first << std::endl; + report_count_map(out, live_count); } - DEBUG_IF("ledger.trace.verbose") { - if (live_objects.size() > 0) - out << "Live objects:" << std::endl; + if (live_objects.size() > 0) { + out << "Live objects:" << std::endl; for (live_objects_map::iterator i = live_objects.begin(); i != live_objects.end(); - i++) { - out << " "; - out << std::right; - out.width(7); - out << (*i).first << " " << (*i).second << std::endl; - } + i++) + out << " " << std::right << std::setw(7) << (*i).first + << " " << std::left << (*i).second + << std::endl; } - if (object_count.size() > 0) + if (object_count.size() > 0) { out << "Object counts:" << std::endl; - - for (object_count_map::iterator i = object_count.begin(); - i != object_count.end(); - i++) { - out << " "; - out << std::right; - out.width(7); - out << (*i).second << " " << (*i).first << std::endl; + report_count_map(out, object_count); } - if (ctor_count.size() > 0) + if (ctor_count.size() > 0) { out << "Constructor counts:" << std::endl; - - for (object_count_map::iterator i = ctor_count.begin(); - i != ctor_count.end(); - i++) { - out << " "; - out << std::right; - out.width(7); - out << (*i).second << " " << (*i).first << std::endl; + report_count_map(out, ctor_count); } } #if DEBUG_LEVEL >= 4 string::string() : std::string() { - TRACE_CTOR("string()"); + TRACE_CTOR(string, ""); } string::string(const string& str) : std::string(str) { - TRACE_CTOR("string(const string&)"); + TRACE_CTOR(string, "const string&"); } string::string(const std::string& str) : std::string(str) { - TRACE_CTOR("string(const std::string&)"); + TRACE_CTOR(string, "const std::string&"); } string::string(const int len, char x) : std::string(len, x) { - TRACE_CTOR("string(const int, char)"); + TRACE_CTOR(string, "const int, char"); } string::string(const char * str) : std::string(str) { - TRACE_CTOR("string(const char *)"); + TRACE_CTOR(string, "const char *"); } string::string(const char * str, const char * end) : std::string(str, end) { - TRACE_CTOR("string(const char *, const char *)"); + TRACE_CTOR(string, "const char *, const char *"); } string::string(const string& str, int x) : std::string(str, x) { - TRACE_CTOR("string(const string&, int)"); + TRACE_CTOR(string, "const string&, int"); } string::string(const string& str, int x, int y) : std::string(str, x, y) { - TRACE_CTOR("string(const string&, int, int)"); + TRACE_CTOR(string, "const string&, int, int"); } string::string(const char * str, int x) : std::string(str, x) { - TRACE_CTOR("string(const char *, int)"); + TRACE_CTOR(string, "const char *, int"); } string::string(const char * str, int x, int y) : std::string(str, x, y) { - TRACE_CTOR("string(const char *, int, int)"); + TRACE_CTOR(string, "const char *, int, int"); } string::~string() { - TRACE_DTOR("string"); + TRACE_DTOR(string); } #endif @@ -8,7 +8,8 @@ namespace ledger { class timing_t; -extern bool trace_mode; +extern bool trace_alloc_mode; +extern bool trace_class_mode; #if DEBUG_LEVEL >= 4 class string; @@ -17,43 +18,50 @@ typedef std::string string; #endif void trace(const string& cat, const string& str); -void trace_push(const string& cat, const string& str, - timing_t& timer); -void trace_pop(const string& cat, const string& str, - timing_t& timer); +void trace_push(const string& cat, const string& str, timing_t& timer); +void trace_pop(const string& cat, const string& str, timing_t& timer); #ifndef TRACE -#define TRACE(cat, msg) if (trace_mode) trace(#cat, msg) -#define TRACE_(cat, msg) if (trace_mode) trace(#cat, msg) +#define TRACE(cat, msg) if (trace_class_mode) trace(#cat, msg) +#define TRACE_(cat, msg) if (trace_class_mode) trace(#cat, msg) #define TRACE_PUSH(cat, msg) \ timing_t timer_ ## cat(#cat); \ - if (trace_mode) trace_push(#cat, msg, timer_ ## cat) + if (trace_class_mode) trace_push(#cat, msg, timer_ ## cat) #define TRACE_POP(cat, msg) \ - if (trace_mode) trace_pop(#cat, msg, timer_ ## cat) + if (trace_class_mode) trace_pop(#cat, msg, timer_ ## cat) #endif -typedef std::multimap<void *, std::string> live_objects_map; -typedef std::pair<void *, std::string> live_objects_pair; -typedef std::map<std::string, int> object_count_map; -typedef std::pair<std::string, int> object_count_pair; +typedef std::multimap<void *, std::string> live_objects_map; +typedef std::pair<void *, std::string> live_objects_pair; +typedef std::pair<unsigned int, std::size_t> count_size_pair; +typedef std::map<std::string, count_size_pair> object_count_map; +typedef std::pair<std::string, count_size_pair> object_count_pair; extern live_objects_map live_objects; +extern object_count_map live_count; extern object_count_map ctor_count; extern object_count_map object_count; -extern object_count_map live_count; extern bool tracing_active; -bool trace_ctor(void * ptr, const char * name); -bool trace_dtor(void * ptr, const char * name); +bool trace_ctor(void * ptr, const char * cls_name, const char * args, + std::size_t cls_size); +bool trace_dtor(void * ptr, const char * cls_name, std::size_t cls_size); void report_memory(std::ostream& out); +#if 0 #ifndef TRACE_CTOR -#define TRACE_CTOR(cls) CONFIRM(ledger::trace_ctor(this, cls)) -#define TRACE_DTOR(cls) CONFIRM(ledger::trace_dtor(this, cls)) +#define TRACE_CTOR(cls, args) \ + CONFIRM(ledger::trace_ctor(this, #cls, args, sizeof(cls))) +#define TRACE_DTOR(cls) \ + CONFIRM(ledger::trace_dtor(this, #cls, sizeof(cls))) +#endif +#else +#define TRACE_CTOR(cls, args) +#define TRACE_DTOR(cls) #endif #if DEBUG_LEVEL >= 4 diff --git a/transform.h b/transform.h index e98c53a3..f4221288 100644 --- a/transform.h +++ b/transform.h @@ -4,7 +4,7 @@ #include "xpath.h" #include <list> -#include <deque> +#include <vector> namespace ledger { @@ -5,7 +5,9 @@ #include "balance.h" #include "error.h" -#include <deque> +#include "linked_list.h" // code by Donovan Rebbechi + +#include <vector> #include <exception> namespace ledger { @@ -26,7 +28,7 @@ namespace xml { class value_t { public: - typedef std::deque<value_t> sequence_t; + typedef std::vector<value_t> sequence_t; char data[sizeof(balance_pair_t)]; @@ -44,42 +46,42 @@ class value_t } type; value_t() { - TRACE_CTOR("value_t()"); + TRACE_CTOR(value_t, ""); *((long *) data) = 0; type = INTEGER; } value_t(const value_t& val) : type(INTEGER) { - TRACE_CTOR("value_t(copy)"); + TRACE_CTOR(value_t, "copy"); *this = val; } value_t(const bool val) { - TRACE_CTOR("value_t(const bool)"); + TRACE_CTOR(value_t, "const bool"); *((bool *) data) = val; type = BOOLEAN; } value_t(const long val) { - TRACE_CTOR("value_t(const long)"); + TRACE_CTOR(value_t, "const long"); *((long *) data) = val; type = INTEGER; } value_t(const moment_t val) { - TRACE_CTOR("value_t(const moment_t)"); + TRACE_CTOR(value_t, "const moment_t"); *((moment_t *) data) = val; type = DATETIME; } value_t(const unsigned long val) { - TRACE_CTOR("value_t(const unsigned long)"); + TRACE_CTOR(value_t, "const unsigned long"); new((amount_t *) data) amount_t(val); type = AMOUNT; } value_t(const double val) { - TRACE_CTOR("value_t(const double)"); + TRACE_CTOR(value_t, "const double"); new((amount_t *) data) amount_t(val); type = AMOUNT; } value_t(const string& val, bool literal = false) { - TRACE_CTOR("value_t(const string&, bool)"); + TRACE_CTOR(value_t, "const string&, bool"); if (literal) { type = INTEGER; set_string(val); @@ -89,38 +91,38 @@ class value_t } } value_t(const char * val) { - TRACE_CTOR("value_t(const char *)"); + TRACE_CTOR(value_t, "const char *"); new((amount_t *) data) amount_t(val); type = AMOUNT; } value_t(const amount_t& val) { - TRACE_CTOR("value_t(const amount_t&)"); + TRACE_CTOR(value_t, "const amount_t&"); new((amount_t *)data) amount_t(val); type = AMOUNT; } value_t(const balance_t& val) : type(INTEGER) { - TRACE_CTOR("value_t(const balance_t&)"); + TRACE_CTOR(value_t, "const balance_t&"); *this = val; } value_t(const balance_pair_t& val) : type(INTEGER) { - TRACE_CTOR("value_t(const balance_pair_t&)"); + TRACE_CTOR(value_t, "const balance_pair_t&"); *this = val; } value_t(xml::node_t * xml_node) : type(INTEGER) { // gets set in = - TRACE_CTOR("value_t(xml::node_t *)"); + TRACE_CTOR(value_t, "xml::node_t *"); *this = xml_node; } value_t(void * item) : type(INTEGER) { // gets set in = - TRACE_CTOR("value_t(void *)"); + TRACE_CTOR(value_t, "void *"); *this = item; } value_t(sequence_t * seq) : type(INTEGER) { // gets set in = - TRACE_CTOR("value_t(sequence_t *)"); + TRACE_CTOR(value_t, "sequence_t *"); *this = seq; } ~value_t() { - TRACE_DTOR("value_t"); + TRACE_DTOR(value_t); destroy(); } @@ -276,7 +278,7 @@ class value_t bool to_boolean() const; long to_integer() const; - moment_t to_datetime() const; + moment_t to_datetime() const; amount_t to_amount() const; balance_t to_balance() const; balance_pair_t to_balance_pair() const; @@ -11,21 +11,21 @@ namespace xml { document_t::document_t(node_t * _top, const char ** _builtins, const int _builtins_size) - : builtins(_builtins), builtins_size(_builtins_size), - top(_top ? _top : new terminal_node_t(this)) { - TRACE_CTOR("xml::document_t(node_t *, const char **, const int)"); + : builtins(_builtins), builtins_size(_builtins_size), stub(this), + top(_top ? _top : &stub) { + TRACE_CTOR(xml::document_t, "node_t *, const char **, const int"); } document_t::~document_t() { - TRACE_DTOR("xml::document_t"); - if (top) + TRACE_DTOR(xml::document_t); + if (top && top != &stub) delete top; } void document_t::set_top(node_t * _top) { - if (top) + if (top && top != &stub) delete top; top = _top; } @@ -117,7 +117,7 @@ node_t::node_t(document_t * _document, parent_node_t * _parent, : name_id(0), parent(_parent), next(NULL), prev(NULL), flags(_flags), info(NULL), attrs(NULL) { - TRACE_CTOR("node_t(document_t *, node_t *)"); + TRACE_CTOR(node_t, "document_t *, node_t *"); document = _document; if (document && ! document->top) document->set_top(this); @@ -147,6 +147,29 @@ void node_t::extract() prev = NULL; } +const char * node_t::name() const +{ + return document->lookup_name(name_id); +} + +int node_t::set_name(const char * _name) +{ + name_id = document->register_name(_name); + return name_id; +} + +node_t * node_t::lookup_child(const char * _name) +{ + int id = document->lookup_name_id(_name); + return lookup_child(id); +} + +node_t * node_t::lookup_child(const string& _name) +{ + int id = document->lookup_name_id(_name); + return lookup_child(id); +} + void parent_node_t::clear() { node_t * child = _children; @@ -21,44 +21,6 @@ class journal_t; namespace xml { -class node_t; - -class document_t -{ - const char ** builtins; - const int builtins_size; - - typedef std::deque<string> names_array; - - names_array names; - - typedef std::map<string, int> names_map; - typedef std::pair<string, int> names_pair; - - names_map names_index; - - public: - node_t * top; - - // Ids 0-9 are reserved. 10-999 are for "builtin" names. 1000+ are - // for dynamically registered names. - enum special_names_t { - CURRENT, PARENT, ROOT, ALL - }; - - document_t(node_t * _top = NULL, const char ** _builtins = NULL, - const int _builtins_size = 0); - ~document_t(); - - void set_top(node_t * _top); - - int register_name(const string& name); - int lookup_name_id(const string& name) const; - const char * lookup_name(int id) const; - - void write(std::ostream& out) const; -}; - #define XML_NODE_IS_PARENT 0x1 class conversion_error : public error { @@ -70,6 +32,7 @@ class conversion_error : public error { }; class parent_node_t; +class document_t; class node_t { @@ -95,7 +58,7 @@ public: unsigned int _flags = 0); virtual ~node_t() { - TRACE_DTOR("node_t"); + TRACE_DTOR(node_t); if (parent) extract(); if (attrs) delete attrs; } @@ -107,13 +70,8 @@ public: return NULL; } - const char * name() const { - return document->lookup_name(name_id); - } - int set_name(const char * _name) { - name_id = document->register_name(_name); - return name_id; - } + const char * name() const; + int set_name(const char * _name); int set_name(int _name_id) { name_id = _name_id; return name_id; @@ -135,14 +93,8 @@ public: return NULL; } - node_t * lookup_child(const char * _name) { - int id = document->lookup_name_id(_name); - return lookup_child(id); - } - node_t * lookup_child(const string& _name) { - int id = document->lookup_name_id(_name); - return lookup_child(id); - } + node_t * lookup_child(const char * _name); + node_t * lookup_child(const string& _name); virtual node_t * lookup_child(int /* _name_id */) { return NULL; } @@ -168,10 +120,10 @@ public: : node_t(_document, _parent, XML_NODE_IS_PARENT), _children(NULL), _last_child(NULL) { - TRACE_CTOR("parent_node_t(document_t *, parent_node_t *)"); + TRACE_CTOR(parent_node_t, "document_t *, parent_node_t *"); } virtual ~parent_node_t() { - TRACE_DTOR("parent_node_t"); + TRACE_DTOR(parent_node_t); if (_children) clear(); } @@ -201,10 +153,10 @@ public: terminal_node_t(document_t * _document, parent_node_t * _parent = NULL) : node_t(_document, _parent) { - TRACE_CTOR("terminal_node_t(document_t *, parent_node_t *)"); + TRACE_CTOR(terminal_node_t, "document_t *, parent_node_t *"); } virtual ~terminal_node_t() { - TRACE_DTOR("terminal_node_t"); + TRACE_DTOR(terminal_node_t); } virtual const char * text() const { @@ -228,6 +180,44 @@ private: terminal_node_t& operator=(const node_t&); }; +class document_t +{ + const char ** builtins; + const int builtins_size; + + typedef std::vector<string> names_array; + + names_array names; + + typedef std::map<string, int> names_map; + typedef std::pair<string, int> names_pair; + + names_map names_index; + + terminal_node_t stub; + + public: + node_t * top; + + // Ids 0-9 are reserved. 10-999 are for "builtin" names. 1000+ are + // for dynamically registered names. + enum special_names_t { + CURRENT, PARENT, ROOT, ALL + }; + + document_t(node_t * _top = NULL, const char ** _builtins = NULL, + const int _builtins_size = 0); + ~document_t(); + + void set_top(node_t * _top); + + int register_name(const string& name); + int lookup_name_id(const string& name) const; + const char * lookup_name(int id) const; + + void write(std::ostream& out) const; +}; + #if defined(HAVE_EXPAT) || defined(HAVE_XMLPARSE) class parser_t @@ -271,11 +261,11 @@ public: commodity_t * _commodity, parent_node_t * _parent = NULL) : parent_node_t(_document, _parent), commodity(_commodity) { - TRACE_CTOR("commodity_node_t(document_t *, commodity_t *, parent_node_t *)"); + TRACE_CTOR(commodity_node_t, "document_t *, commodity_t *, parent_node_t *"); set_name("commodity"); } virtual ~commodity_node_t() { - TRACE_DTOR("commodity_node_t"); + TRACE_DTOR(commodity_node_t); } virtual node_t * children() const; @@ -290,11 +280,11 @@ public: amount_t * _amount, parent_node_t * _parent = NULL) : parent_node_t(_document, _parent), amount(_amount) { - TRACE_CTOR("amount_node_t(document_t *, amount_t *, parent_node_t *)"); + TRACE_CTOR(amount_node_t, "document_t *, amount_t *, parent_node_t *"); set_name("amount"); } virtual ~amount_node_t() { - TRACE_DTOR("amount_node_t"); + TRACE_DTOR(amount_node_t); } virtual node_t * children() const; @@ -317,12 +307,12 @@ public: parent_node_t * _parent = NULL) : parent_node_t(_document, _parent), payee_virtual_node(NULL), transaction(_transaction) { - TRACE_CTOR("transaction_node_t(document_t *, transaction_t *, parent_node_t *)"); + TRACE_CTOR(transaction_node_t, "document_t *, transaction_t *, parent_node_t *"); set_name("transaction"); payee_id = document->register_name("payee"); } virtual ~transaction_node_t() { - TRACE_DTOR("transaction_node_t"); + TRACE_DTOR(transaction_node_t); if (payee_virtual_node) delete payee_virtual_node; } @@ -340,11 +330,11 @@ public: entry_node_t(document_t * _document, entry_t * _entry, parent_node_t * _parent = NULL) : parent_node_t(_document, _parent), entry(_entry) { - TRACE_CTOR("entry_node_t(document_t *, entry_t *, parent_node_t *)"); + TRACE_CTOR(entry_node_t, "document_t *, entry_t *, parent_node_t *"); set_name("entry"); } virtual ~entry_node_t() { - TRACE_DTOR("entry_node_t"); + TRACE_DTOR(entry_node_t); } virtual node_t * children() const; @@ -358,11 +348,11 @@ public: account_node_t(document_t * _document, account_t * _account, parent_node_t * _parent = NULL) : parent_node_t(_document, _parent), account(_account) { - TRACE_CTOR("account_node_t(document_t *, account_t *, parent_node_t *)"); + TRACE_CTOR(account_node_t, "document_t *, account_t *, parent_node_t *"); set_name("account"); } virtual ~account_node_t() { - TRACE_DTOR("account_node_t"); + TRACE_DTOR(account_node_t); } virtual node_t * children() const; @@ -376,11 +366,11 @@ public: journal_node_t(document_t * _document, journal_t * _journal, parent_node_t * _parent = NULL) : parent_node_t(_document, _parent), journal(_journal) { - TRACE_CTOR("journal_node_t(document_t *, journal_t *, parent_node_t *)"); + TRACE_CTOR(journal_node_t, "document_t *, journal_t *, parent_node_t *"); set_name("journal"); } virtual ~journal_node_t() { - TRACE_DTOR("journal_node_t"); + TRACE_DTOR(journal_node_t); } virtual node_t * children() const; @@ -546,7 +546,7 @@ bool xpath_t::function_scope_t::resolve(const string& name, xpath_t::op_t::~op_t() { - TRACE_DTOR("xpath_t::op_t"); + TRACE_DTOR(xpath_t::op_t); DEBUG_PRINT("ledger.xpath.memory", "Destroying " << this); assert(refc == 0); @@ -189,11 +189,11 @@ public: scope_t(scope_t * _parent = NULL, kind_t _kind = NORMAL) : parent(_parent), kind(_kind) { - TRACE_CTOR("xpath_t::scope_t(scope *, kind_t)"); + TRACE_CTOR(xpath_t::scope_t, "scope *, kind_t"); } virtual ~scope_t() { - TRACE_DTOR("xpath_t::scope_t"); + TRACE_DTOR(xpath_t::scope_t); for (symbol_map::iterator i = symbols.begin(); i != symbols.end(); i++) @@ -296,17 +296,17 @@ private: unsigned int length; token_t() : kind(UNKNOWN), length(0) { - TRACE_CTOR("xpath_t::token_t()"); + TRACE_CTOR(xpath_t::token_t, ""); } token_t(const token_t& other) { assert(0); - TRACE_CTOR("xpath_t::token_t(copy)"); + TRACE_CTOR(xpath_t::token_t, "copy"); *this = other; } ~token_t() { - TRACE_DTOR("xpath_t::token_t"); + TRACE_DTOR(xpath_t::token_t); } token_t& operator=(const token_t& other) { @@ -421,7 +421,7 @@ public: op_t(const kind_t _kind) : kind(_kind), refc(0), left(NULL), right(NULL) { - TRACE_CTOR("xpath_t::op_t(const kind_t)"); + TRACE_CTOR(xpath_t::op_t, "const kind_t"); } op_t(const op_t&); ~op_t(); @@ -618,31 +618,31 @@ public: unsigned short flags; // flags used to parse `expr' xpath_t() : ptr(NULL), use_lookahead(false), flags(0) { - TRACE_CTOR("xpath_t"); + TRACE_CTOR(xpath_t, ""); } xpath_t(op_t * _ptr) : ptr(_ptr), use_lookahead(false) { - TRACE_CTOR("xpath_t(op_t *)"); + TRACE_CTOR(xpath_t, "op_t *"); } xpath_t(const string& _expr, unsigned short _flags = XPATH_PARSE_RELAXED) : ptr(NULL), use_lookahead(false), flags(0) { - TRACE_CTOR("xpath_t(const string&, unsigned short)"); + TRACE_CTOR(xpath_t, "const string&, unsigned short"); if (! _expr.empty()) parse(_expr, _flags); } xpath_t(std::istream& in, unsigned short _flags = XPATH_PARSE_RELAXED) : ptr(NULL), use_lookahead(false), flags(0) { - TRACE_CTOR("xpath_t(std::istream&, unsigned short)"); + TRACE_CTOR(xpath_t, "std::istream&, unsigned short"); parse(in, _flags); } xpath_t(const xpath_t& other) : ptr(other.ptr ? other.ptr->acquire() : NULL), use_lookahead(false), expr(other.expr), flags(other.flags) { - TRACE_CTOR("xpath_t(copy)"); + TRACE_CTOR(xpath_t, "copy"); } virtual ~xpath_t() { - TRACE_DTOR("xpath_t"); + TRACE_DTOR(xpath_t); reset(NULL); } @@ -700,8 +700,8 @@ public: void compile(document_t * document, scope_t * scope = NULL) { if (! document) { - std::auto_ptr<document_t> tdoc(new xml::document_t); - compile(tdoc->top, scope); + document_t tdoc; + compile(tdoc.top, scope); } else { compile(document->top, scope); } |