[vlc-commits] android/specific: factor get_env
Thomas Guillem
git at videolan.org
Mon Jul 18 15:43:08 CEST 2016
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Jul 18 15:11:11 2016 +0200| [71029967afbf21e82ccf11e6fa0d751a6a430a4b] | committer: Thomas Guillem
android/specific: factor get_env
This will be used by a future function.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=71029967afbf21e82ccf11e6fa0d751a6a430a4b
---
src/android/specific.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/android/specific.c b/src/android/specific.c
index cd064b7..49955dc 100644
--- a/src/android/specific.c
+++ b/src/android/specific.c
@@ -183,12 +183,9 @@ fallback:
return psz_default_dir != NULL ? strdup(psz_default_dir) : NULL;
}
-static char *config_GetGenericDir(const char *psz_name)
+static JNIEnv *get_env(bool *p_detach)
{
JNIEnv *env;
- bool b_detach;
- char *psz_ret = NULL;
-
if ((*s_jvm)->GetEnv(s_jvm, (void **)&env, JNI_VERSION_1_2) != JNI_OK)
{
/* attach the thread to the Java VM */
@@ -200,10 +197,28 @@ static char *config_GetGenericDir(const char *psz_name)
if ((*s_jvm)->AttachCurrentThread(s_jvm, &env, &args) != JNI_OK)
return NULL;
- b_detach = true;
+ *p_detach = true;
}
else
- b_detach = false;
+ *p_detach = false;
+ return env;
+}
+
+static void release_env(bool b_detach)
+{
+ if (b_detach)
+ (*s_jvm)->DetachCurrentThread(s_jvm);
+}
+
+static char *config_GetGenericDir(const char *psz_name)
+{
+ JNIEnv *env;
+ bool b_detach;
+ char *psz_ret = NULL;
+
+ env = get_env(&b_detach);
+ if (env == NULL)
+ return NULL;
jstring jname= (*env)->NewStringUTF(env, psz_name);
if ((*env)->ExceptionCheck(env))
@@ -234,8 +249,7 @@ static char *config_GetGenericDir(const char *psz_name)
(*env)->DeleteLocalRef(env, jpath);
error:
- if (b_detach)
- (*s_jvm)->DetachCurrentThread(s_jvm);
+ release_env(b_detach);
return psz_ret;
}
More information about the vlc-commits
mailing list