From 55d5397f4fabd8335adf3d99a2a675338933665e Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Sat, 20 Mar 2021 04:49:47 +0100 Subject: [PATCH] implement move behavior for cs_value this prevents things from going horribly wrong when people do move the values (since the implicit implementations don't take care of handling the refcounts) --- include/cubescript/cubescript.hh | 2 ++ src/cs_val.cc | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 4f6b644..39ee987 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -118,8 +118,10 @@ struct OSTD_EXPORT cs_value { cs_value(cs_shared_state &); cs_value(cs_value const &); + cs_value(cs_value &&v); cs_value &operator=(cs_value const &); + cs_value &operator=(cs_value &&); cs_value_type get_type() const; diff --git a/src/cs_val.cc b/src/cs_val.cc index b4d3884..7d591be 100644 --- a/src/cs_val.cc +++ b/src/cs_val.cc @@ -72,6 +72,10 @@ cs_value::cs_value(cs_value const &v): cs_value(*v.state()) { *this = v; } +cs_value::cs_value(cs_value &&v): cs_value(*v.state()) { + *this = std::move(v); +} + cs_value &cs_value::operator=(cs_value const &v) { csv_cleanup(p_type, p_stor); p_type = cs_value_type::NONE; @@ -97,6 +101,12 @@ cs_value &cs_value::operator=(cs_value const &v) { return *this; } +cs_value &cs_value::operator=(cs_value &&v) { + *this = v; + v.set_none(); + return *this; +} + cs_value_type cs_value::get_type() const { return p_type; }