Commit 71029967 authored by Thomas Guillem's avatar Thomas Guillem
Browse files

android/specific: factor get_env

This will be used by a future function.
parent 0c698c71
...@@ -183,12 +183,9 @@ fallback: ...@@ -183,12 +183,9 @@ fallback:
return psz_default_dir != NULL ? strdup(psz_default_dir) : NULL; 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; JNIEnv *env;
bool b_detach;
char *psz_ret = NULL;
if ((*s_jvm)->GetEnv(s_jvm, (void **)&env, JNI_VERSION_1_2) != JNI_OK) if ((*s_jvm)->GetEnv(s_jvm, (void **)&env, JNI_VERSION_1_2) != JNI_OK)
{ {
/* attach the thread to the Java VM */ /* attach the thread to the Java VM */
...@@ -200,10 +197,28 @@ static char *config_GetGenericDir(const char *psz_name) ...@@ -200,10 +197,28 @@ static char *config_GetGenericDir(const char *psz_name)
if ((*s_jvm)->AttachCurrentThread(s_jvm, &env, &args) != JNI_OK) if ((*s_jvm)->AttachCurrentThread(s_jvm, &env, &args) != JNI_OK)
return NULL; return NULL;
b_detach = true; *p_detach = true;
} }
else 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); jstring jname= (*env)->NewStringUTF(env, psz_name);
if ((*env)->ExceptionCheck(env)) if ((*env)->ExceptionCheck(env))
...@@ -234,8 +249,7 @@ static char *config_GetGenericDir(const char *psz_name) ...@@ -234,8 +249,7 @@ static char *config_GetGenericDir(const char *psz_name)
(*env)->DeleteLocalRef(env, jpath); (*env)->DeleteLocalRef(env, jpath);
error: error:
if (b_detach) release_env(b_detach);
(*s_jvm)->DetachCurrentThread(s_jvm);
return psz_ret; return psz_ret;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment