JNI Convenience: Use isSameObject() when comparing jobjects.
Comparing the value of two jobjects are not safe, as it's not guaranteed that two jobjects that is referencing the same object, will have the same value. To make things worse two jobjects might have the same value even though they reference two different objects... Change-Id: I997ea8abfb8c687c342b261bba3848cbbd741633 Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>bb10
parent
fa8786c397
commit
0ccb75b5fc
|
|
@ -157,33 +157,39 @@ private:
|
|||
template <class T, class X>
|
||||
bool operator==(const QJNILocalRef<T> &ptr1, const QJNILocalRef<X> &ptr2)
|
||||
{
|
||||
return ptr1.m_obj == ptr2.m_obj;
|
||||
QAttachedJNIEnv env;
|
||||
return env->IsSameObject(ptr1.m_obj, ptr2.m_obj);
|
||||
}
|
||||
template <class T, class X>
|
||||
bool operator!=(const QJNILocalRef<T> &ptr1, const QJNILocalRef<X> &ptr2)
|
||||
{
|
||||
return ptr1.m_obj != ptr2.m_obj;
|
||||
QAttachedJNIEnv env;
|
||||
return !env->IsSameObject(ptr1.m_obj, ptr2.m_obj);
|
||||
}
|
||||
|
||||
template <class T, class X>
|
||||
bool operator==(const QJNILocalRef<T> &ptr1, X ptr2)
|
||||
{
|
||||
return ptr1.m_obj == ptr2;
|
||||
QAttachedJNIEnv env;
|
||||
return env->IsSameObject(ptr1.m_obj, ptr2);
|
||||
}
|
||||
template <class T, class X>
|
||||
bool operator==(T ptr1, const QJNILocalRef<X> &ptr2)
|
||||
{
|
||||
return ptr1 == ptr2.m_obj;
|
||||
QAttachedJNIEnv env;
|
||||
return env->IsSameObject(ptr1, ptr2.m_obj);
|
||||
}
|
||||
template <class T, class X>
|
||||
bool operator!=(const QJNILocalRef<T> &ptr1, X ptr2)
|
||||
{
|
||||
return !(ptr1 == ptr2);
|
||||
QAttachedJNIEnv env;
|
||||
return !env->IsSameObject(ptr1.m_obj, ptr2);
|
||||
}
|
||||
template <class T, class X>
|
||||
bool operator!=(const T *ptr1, const QJNILocalRef<X> &ptr2)
|
||||
{
|
||||
return !(ptr2 == ptr1);
|
||||
QAttachedJNIEnv env;
|
||||
return !env->IsSameObject(ptr1, ptr2.m_obj);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Reference in New Issue