Merge "Fix sp<> conversion operator / constructor"

This commit is contained in:
Mathias Agopian
2011-02-28 12:50:04 -08:00
committed by Android (Google) Code Review
3 changed files with 34 additions and 8 deletions

View File

@ -177,7 +177,7 @@ static sp<Surface> getSurface(JNIEnv* env, jobject clazz)
sp<ANativeWindow> android_Surface_getNativeWindow( sp<ANativeWindow> android_Surface_getNativeWindow(
JNIEnv* env, jobject clazz) { JNIEnv* env, jobject clazz) {
return getSurface(env, clazz).get(); return getSurface(env, clazz);
} }
static void setSurface(JNIEnv* env, jobject clazz, const sp<Surface>& surface) static void setSurface(JNIEnv* env, jobject clazz, const sp<Surface>& surface)

View File

@ -133,7 +133,7 @@ sp<T>::sp(const sp<T>& other)
template<typename T> template<typename U> template<typename T> template<typename U>
sp<T>::sp(U* other) : m_ptr(other) sp<T>::sp(U* other) : m_ptr(other)
{ {
if (other) other->incStrong(this); if (other) ((T*)other)->incStrong(this);
} }
template<typename T> template<typename U> template<typename T> template<typename U>
@ -170,7 +170,7 @@ sp<T>& sp<T>::operator = (T* other)
template<typename T> template<typename U> template<typename T> template<typename U>
sp<T>& sp<T>::operator = (const sp<U>& other) sp<T>& sp<T>::operator = (const sp<U>& other)
{ {
U* otherPtr(other.m_ptr); T* otherPtr(other.m_ptr);
if (otherPtr) otherPtr->incStrong(this); if (otherPtr) otherPtr->incStrong(this);
if (m_ptr) m_ptr->decStrong(this); if (m_ptr) m_ptr->decStrong(this);
m_ptr = otherPtr; m_ptr = otherPtr;
@ -180,7 +180,7 @@ sp<T>& sp<T>::operator = (const sp<U>& other)
template<typename T> template<typename U> template<typename T> template<typename U>
sp<T>& sp<T>::operator = (U* other) sp<T>& sp<T>::operator = (U* other)
{ {
if (other) other->incStrong(this); if (other) ((T*)other)->incStrong(this);
if (m_ptr) m_ptr->decStrong(this); if (m_ptr) m_ptr->decStrong(this);
m_ptr = other; m_ptr = other;
return *this; return *this;

View File

@ -99,20 +99,38 @@ public:
#if DEBUG_REFS_FATAL_SANITY_CHECKS #if DEBUG_REFS_FATAL_SANITY_CHECKS
LOG_ALWAYS_FATAL("Strong references remain!"); LOG_ALWAYS_FATAL("Strong references remain!");
#else #else
LOGE("Strong references remain!"); LOGE("Strong references remain:");
#endif #endif
ref_entry* refs = mStrongRefs;
while (refs) {
char inc = refs->ref >= 0 ? '+' : '-';
LOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref);
#if DEBUG_REFS_CALLSTACK_ENABLED
refs->stack.dump();
#endif;
refs = refs->next;
}
} }
if (!mRetain && mWeakRefs != NULL) { if (!mRetain && mWeakRefs != NULL) {
dumpStack = true; dumpStack = true;
#if DEBUG_REFS_FATAL_SANITY_CHECKS #if DEBUG_REFS_FATAL_SANITY_CHECKS
LOG_ALWAYS_FATAL("Weak references remain!"); LOG_ALWAYS_FATAL("Weak references remain:");
#else #else
LOGE("Weak references remain!"); LOGE("Weak references remain!");
#endif #endif
ref_entry* refs = mWeakRefs;
while (refs) {
char inc = refs->ref >= 0 ? '+' : '-';
LOGD("\t%c ID %p (ref %d):", inc, refs->id, refs->ref);
#if DEBUG_REFS_CALLSTACK_ENABLED
refs->stack.dump();
#endif;
refs = refs->next;
}
} }
if (dumpStack) { if (dumpStack) {
LOGE("above errors at:");
CallStack stack; CallStack stack;
stack.update(); stack.update();
stack.dump(); stack.dump();
@ -228,7 +246,8 @@ private:
if (mTrackEnabled) { if (mTrackEnabled) {
AutoMutex _l(mMutex); AutoMutex _l(mMutex);
ref_entry* ref = *refs; ref_entry* const head = *refs;
ref_entry* ref = head;
while (ref != NULL) { while (ref != NULL) {
if (ref->id == id) { if (ref->id == id) {
*refs = ref->next; *refs = ref->next;
@ -249,6 +268,13 @@ private:
"(weakref_type %p) that doesn't exist!", "(weakref_type %p) that doesn't exist!",
id, mBase, this); id, mBase, this);
ref = head;
while (ref) {
char inc = ref->ref >= 0 ? '+' : '-';
LOGD("\t%c ID %p (ref %d):", inc, ref->id, ref->ref);
ref = ref->next;
}
CallStack stack; CallStack stack;
stack.update(); stack.update();
stack.dump(); stack.dump();