aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2018-06-27 13:36:30 -0400
committerDeterminant <ted.sybil@gmail.com>2018-06-27 13:36:30 -0400
commitb8f95225f752900471dedacbe9b71fc0523393d9 (patch)
tree2a3b763e527024fc3eb4ca43153141972a96fec4
parent353943edc5a7bbedc816f08031fb5bf16efeb23e (diff)
fix bugs in ref.h
-rw-r--r--include/salticidae/ref.h15
1 files changed, 7 insertions, 8 deletions
diff --git a/include/salticidae/ref.h b/include/salticidae/ref.h
index 83fd00b..001fd51 100644
--- a/include/salticidae/ref.h
+++ b/include/salticidae/ref.h
@@ -79,6 +79,7 @@ template<typename T, typename R> class RcObjBase;
template<typename T, typename R>
class WeakObjBase {
+ T *obj;
R *ctl;
void release() { if (ctl) ctl->release_weak(); }
public:
@@ -87,16 +88,19 @@ class WeakObjBase {
WeakObjBase(): ctl(nullptr) {}
WeakObjBase &operator=(const WeakObjBase &other) {
release();
+ obj = other.obj;
if ((ctl = other.ctl))
ctl->add_weak();
return *this;
}
- WeakObjBase(const WeakObjBase &other): ctl(other.ctl) {
+ WeakObjBase(const WeakObjBase &other):
+ obj(other.obj), ctl(other.ctl) {
if (ctl) ctl->add_weak();
}
- WeakObjBase(WeakObjBase &&other): ctl(other.ctl) {
+ WeakObjBase(WeakObjBase &&other):
+ obj(other.obj), ctl(other.ctl) {
other.ctl = nullptr;
}
@@ -132,11 +136,6 @@ class RcObjBase {
return *this;
}
- RcObjBase(const RcObjBase &other):
- obj(other.obj), ctl(other.ctl) {
- if (ctl) ctl->add_ref();
- }
-
template<typename T_>
RcObjBase(const RcObjBase<T_, R> &other):
obj(other.obj), ctl(other.ctl) {
@@ -178,7 +177,7 @@ RcObjBase<T, R> static_pointer_cast(const RcObjBase<T_, R> &other) {
template<typename T, typename R>
inline WeakObjBase<T, R>::WeakObjBase(const RcObjBase<T, R> &other):
- ctl(other.ctl) {
+ obj(other.obj), ctl(other.ctl) {
if (ctl) ctl->add_weak();
}