Fix a wp<> bug where the owner ID would be wrong

this was introduced recently. we make sure to use
the correct owner id (the sp) instead of the wp.

Change-Id: I78fdc6ec0c2d3e687278b70442d74d1924b512a2
This commit is contained in:
Mathias Agopian 2011-02-24 18:12:34 -08:00
parent f14a1046e7
commit d005004f14
2 changed files with 10 additions and 11 deletions

View File

@ -425,8 +425,11 @@ void wp<T>::set_object_and_refs(T* other, weakref_type* refs)
template<typename T>
sp<T> wp<T>::promote() const
{
T* p = (m_ptr && m_refs->attemptIncStrong(this)) ? m_ptr : 0;
return sp<T>(p, true);
sp<T> result;
if (m_ptr && m_refs->attemptIncStrong(&result)) {
result.set_pointer(m_ptr);
}
return result;
}
template<typename T>

View File

@ -104,11 +104,8 @@ public:
private:
template<typename Y> friend class sp;
template<typename Y> friend class wp;
// Optimization for wp::promote().
sp(T* p, bool);
T* m_ptr;
void set_pointer(T* ptr);
T* m_ptr;
};
#undef COMPARE
@ -206,10 +203,9 @@ void sp<T>::clear()
}
template<typename T>
sp<T>::sp(T* p, bool)
: m_ptr(p)
{
}
void sp<T>::set_pointer(T* ptr) {
m_ptr = ptr;
}
template <typename T>
inline TextOutput& operator<<(TextOutput& to, const sp<T>& val)