diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-05 05:53:36 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-05 05:53:36 -0600 |
commit | 036200e959db6a3b9fe0d02f9eec3eb131983ab4 (patch) | |
tree | 02e86d54089da915cb98e3752c3cf77410ab25c4 /src | |
parent | 96ec764c4ad31e3d66782775fcc6885ad0818111 (diff) | |
download | fork-ledger-036200e959db6a3b9fe0d02f9eec3eb131983ab4.tar.gz fork-ledger-036200e959db6a3b9fe0d02f9eec3eb131983ab4.tar.bz2 fork-ledger-036200e959db6a3b9fe0d02f9eec3eb131983ab4.zip |
Make copying of format_t objects memory-safe
Diffstat (limited to 'src')
-rw-r--r-- | src/format.cc | 11 | ||||
-rw-r--r-- | src/format.h | 9 |
2 files changed, 4 insertions, 16 deletions
diff --git a/src/format.cc b/src/format.cc index f16b4ba9..9824d5f7 100644 --- a/src/format.cc +++ b/src/format.cc @@ -40,16 +40,6 @@ namespace ledger { format_t::elision_style_t format_t::default_style = TRUNCATE_TRAILING; bool format_t::default_style_changed = false; -format_t::element_t::element_t(const element_t& elem) - : supports_flags<>(), - type(elem.type), - min_width(elem.min_width), - max_width(elem.max_width), - data(elem.data) -{ - TRACE_CTOR(element_t, "copy"); -} - void format_t::element_t::dump(std::ostream& out) const { out << "Element: "; @@ -426,7 +416,6 @@ string format_t::real_calc(scope_t& scope) case element_t::EXPR: { expr_t& expr(boost::get<expr_t>(elem->data)); try { - expr.compile(scope); value_t value; diff --git a/src/format.h b/src/format.h index 0073b427..1b8513bb 100644 --- a/src/format.h +++ b/src/format.h @@ -51,7 +51,7 @@ class unistring; DECLARE_EXCEPTION(format_error, std::runtime_error); -class format_t : public expr_base_t<string> +class format_t : public expr_base_t<string>, public noncopyable { typedef expr_base_t<string> base_type; @@ -65,14 +65,12 @@ class format_t : public expr_base_t<string> std::size_t min_width; std::size_t max_width; variant<string, expr_t> data; - scoped_ptr<struct element_t> next; + shared_ptr<struct element_t> next; element_t() throw() : supports_flags<>(), type(STRING), min_width(0), max_width(0) { TRACE_CTOR(element_t, ""); } - element_t(const element_t& elem); - ~element_t() throw() { TRACE_DTOR(element_t); } @@ -84,6 +82,7 @@ class format_t : public expr_base_t<string> min_width = elem.min_width; max_width = elem.max_width; data = elem.data; + next = elem.next; } return *this; } @@ -105,7 +104,7 @@ class format_t : public expr_base_t<string> void dump(std::ostream& out) const; }; - scoped_ptr<element_t> elements; + shared_ptr<element_t> elements; public: static enum elision_style_t { |