summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@theqtcompany.com>2015-02-03 17:43:02 +0100
committerChristian Stromme <christian.stromme@theqtcompany.com>2015-02-26 13:02:27 +0000
commitc8d64cbcc6728e8862cc16bb1d007349fd7012b4 (patch)
treed7d665c1b7b0c70873ff594494985a092a88b37d /src/corelib
parentcb27388eb06335ce50bf599e5fc15b2d2c9a543a (diff)
Android: Add scoped local ref. handler.
Adds an internal class for handling local jni references. When calling raw jni functions the returned object is usually a local reference, to avoid overflowing the local reference table we need to free any local ref. as soon as we're done with them. The class QJNIScopedLocalRef, a QScopedPointer, makes this process a lot easier. Change-Id: I093e5671f0dcd254d5c2c7985c8c0f625d5592a4 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/kernel/qjni.cpp10
-rw-r--r--src/corelib/kernel/qjni_p.h8
2 files changed, 17 insertions, 1 deletions
diff --git a/src/corelib/kernel/qjni.cpp b/src/corelib/kernel/qjni.cpp
index 694463b9d8..2290a74c31 100644
--- a/src/corelib/kernel/qjni.cpp
+++ b/src/corelib/kernel/qjni.cpp
@@ -204,6 +204,15 @@ static jfieldID getCachedFieldID(JNIEnv *env,
}
}
+void QJNILocalRefDeleter::cleanup(jobject obj)
+{
+ if (obj == 0)
+ return;
+
+ QJNIEnvironmentPrivate env;
+ env->DeleteLocalRef(obj);
+}
+
class QJNIEnvironmentPrivateTLS
{
public:
@@ -2258,4 +2267,3 @@ bool QJNIObjectPrivate::isSameObject(const QJNIObjectPrivate &other) const
}
QT_END_NAMESPACE
-
diff --git a/src/corelib/kernel/qjni_p.h b/src/corelib/kernel/qjni_p.h
index e79caed5b8..ae9c7c3a7e 100644
--- a/src/corelib/kernel/qjni_p.h
+++ b/src/corelib/kernel/qjni_p.h
@@ -51,6 +51,14 @@
QT_BEGIN_NAMESPACE
+struct Q_CORE_EXPORT QJNILocalRefDeleter
+{
+ static void cleanup(jobject obj);
+};
+
+// To simplify this we only define it for jobjects.
+typedef QScopedPointer<_jobject, QJNILocalRefDeleter> QJNIScopedLocalRef;
+
class Q_CORE_EXPORT QJNIEnvironmentPrivate
{
public: