mirror of
https://github.com/EttusResearch/uhd.git
synced 2026-10-25 17:36:10 +00:00
rpc: Fix operators in object class
This commit makes it explicit which assignment operators and constructors are available on the object class. Furthermore the copy constructor and assignment operator make deep copies of the object. This prevents double free operations with the rpc_error class.
This commit is contained in:
parent
96f31806dc
commit
cf78e1cfd5
@ -52,6 +52,14 @@ public:
|
||||
object_handle(clmdep_msgpack::object const& obj, std::unique_ptr<clmdep_msgpack::zone> z) :
|
||||
m_obj(obj), m_zone(std::move(z)) { }
|
||||
|
||||
// Copy constructor and assignment declared here, defined after clone() below
|
||||
object_handle(const object_handle& other);
|
||||
object_handle& operator=(const object_handle& other);
|
||||
|
||||
// Default move semantics
|
||||
object_handle(object_handle&& other) noexcept = default;
|
||||
object_handle& operator=(object_handle&& other) noexcept = default;
|
||||
|
||||
// obsolete
|
||||
void set(clmdep_msgpack::object const& obj)
|
||||
{ m_obj = obj; }
|
||||
@ -135,6 +143,28 @@ inline object_handle clone(clmdep_msgpack::object const& obj) {
|
||||
return object_handle(newobj, std::move(z));
|
||||
}
|
||||
|
||||
// Define object_handle copy constructor and assignment after clone is declared
|
||||
inline object_handle::object_handle(const object_handle& other) {
|
||||
if (other.m_zone) {
|
||||
*this = clmdep_msgpack::clone(other.m_obj);
|
||||
} else {
|
||||
m_obj = other.m_obj;
|
||||
m_zone.reset();
|
||||
}
|
||||
}
|
||||
|
||||
inline object_handle& object_handle::operator=(const object_handle& other) {
|
||||
if (this != &other) {
|
||||
if (other.m_zone) {
|
||||
*this = clmdep_msgpack::clone(other.m_obj);
|
||||
} else {
|
||||
m_obj = other.m_obj;
|
||||
m_zone.reset();
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
struct object::implicit_type {
|
||||
implicit_type(object const& o) : obj(o) { }
|
||||
~implicit_type() { }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user