Delete local JNI references in SAF VFS implementation (#18503)

This commit is contained in:
刘皓 2025-12-11 22:22:26 -05:00 committed by GitHub
parent 80241cf6af
commit 3828186f7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 100 additions and 1 deletions

View File

@ -2480,7 +2480,9 @@ static int frontend_unix_parse_drive_list(void *data, bool load_content)
(*env)->ExceptionClear(env);
}
else
for (jsize i = 0; i < trees_length; ++i)
{
jsize i;
for (i = 0; i < trees_length; ++i)
{
const char *tree_chars;
char *serialized_path;
@ -2496,6 +2498,12 @@ static int frontend_unix_parse_drive_list(void *data, bool load_content)
{
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
(*env)->DeleteLocalRef(env, tree);
if ((*env)->ExceptionOccurred(env))
{
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
}
continue;
}
if ((serialized_path = retro_vfs_path_join_saf(tree_chars, "")) != NULL)
@ -2513,7 +2521,20 @@ static int frontend_unix_parse_drive_list(void *data, bool load_content)
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
}
(*env)->DeleteLocalRef(env, tree);
if ((*env)->ExceptionOccurred(env))
{
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
}
}
}
(*env)->DeleteLocalRef(env, trees);
if ((*env)->ExceptionOccurred(env))
{
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
}
}
}

View File

@ -55,6 +55,14 @@ bool retro_vfs_init_saf(JNIEnv *(*get_jni_env)(void), jobject activity_object)
if (env == NULL)
return false;
(*env)->PushLocalFrame(env, 14);
if ((*env)->ExceptionOccurred(env))
{
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
return false;
}
vfs_saf_content_resolver_object = NULL;
vfs_saf_vfs_implementation_saf_class = NULL;
vfs_saf_saf_stat_class = NULL;
@ -172,6 +180,7 @@ bool retro_vfs_init_saf(JNIEnv *(*get_jni_env)(void), jobject activity_object)
}
vfs_saf_get_jni_env = get_jni_env;
(*env)->PopLocalFrame(env, NULL);
return true;
error:
@ -201,6 +210,7 @@ error:
vfs_saf_saf_directory_class = NULL;
if ((*env)->ExceptionOccurred(env)) goto error;
}
(*env)->PopLocalFrame(env, NULL);
return false;
}
@ -376,6 +386,14 @@ int retro_vfs_file_open_saf(const char *tree, const char *path, unsigned mode)
if (env == NULL)
return -1;
(*env)->PushLocalFrame(env, 2);
if ((*env)->ExceptionOccurred(env))
{
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
return -1;
}
tree_object = (*env)->NewStringUTF(env, tree);
if ((*env)->ExceptionOccurred(env)) goto error;
@ -385,11 +403,13 @@ int retro_vfs_file_open_saf(const char *tree, const char *path, unsigned mode)
fd = (*env)->CallStaticIntMethod(env, vfs_saf_vfs_implementation_saf_class, vfs_saf_open_saf_file_method, vfs_saf_content_resolver_object, tree_object, path_object, !!(mode & RETRO_VFS_FILE_ACCESS_READ), !!(mode & RETRO_VFS_FILE_ACCESS_WRITE), !(mode & RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING));
if ((*env)->ExceptionOccurred(env)) goto error;
(*env)->PopLocalFrame(env, NULL);
return fd;
error:
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
(*env)->PopLocalFrame(env, NULL);
return -1;
}
@ -406,6 +426,14 @@ int retro_vfs_file_remove_saf(const char *tree, const char *path)
if (env == NULL)
return -1;
(*env)->PushLocalFrame(env, 2);
if ((*env)->ExceptionOccurred(env))
{
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
return -1;
}
tree_object = (*env)->NewStringUTF(env, tree);
if ((*env)->ExceptionOccurred(env)) goto error;
@ -415,11 +443,13 @@ int retro_vfs_file_remove_saf(const char *tree, const char *path)
ret = (*env)->CallStaticBooleanMethod(env, vfs_saf_vfs_implementation_saf_class, vfs_saf_remove_saf_file_method, vfs_saf_content_resolver_object, tree_object, path_object);
if ((*env)->ExceptionOccurred(env)) goto error;
(*env)->PopLocalFrame(env, NULL);
return ret ? 0 : -1;
error:
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
(*env)->PopLocalFrame(env, NULL);
return -1;
}
@ -443,6 +473,14 @@ int retro_vfs_stat_saf(const char *tree, const char *path, int32_t *size)
if (env == NULL)
return 0;
(*env)->PushLocalFrame(env, 3);
if ((*env)->ExceptionOccurred(env))
{
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
return 0;
}
tree_object = (*env)->NewStringUTF(env, tree);
if ((*env)->ExceptionOccurred(env)) goto error;
@ -457,14 +495,20 @@ int retro_vfs_stat_saf(const char *tree, const char *path, int32_t *size)
saf_stat_size = (*env)->CallLongMethod(env, saf_stat, vfs_saf_saf_stat_get_size_method);
if ((*env)->ExceptionOccurred(env)) goto error;
if (saf_stat_size < 0)
{
(*env)->PopLocalFrame(env, NULL);
return 0;
}
}
else
{
bool saf_stat_is_open = (*env)->CallBooleanMethod(env, saf_stat, vfs_saf_saf_stat_get_is_open_method);
if ((*env)->ExceptionOccurred(env)) goto error;
if (!saf_stat_is_open)
{
(*env)->PopLocalFrame(env, NULL);
return 0;
}
}
saf_stat_is_directory = (*env)->CallBooleanMethod(env, saf_stat, vfs_saf_saf_stat_get_is_directory_method);
@ -473,11 +517,13 @@ int retro_vfs_stat_saf(const char *tree, const char *path, int32_t *size)
if (size != NULL)
*size = saf_stat_size > INT32_MAX ? INT32_MAX : (int32_t)saf_stat_size;
(*env)->PopLocalFrame(env, NULL);
return saf_stat_is_directory ? RETRO_VFS_STAT_IS_VALID | RETRO_VFS_STAT_IS_DIRECTORY : RETRO_VFS_STAT_IS_VALID;
error:
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
(*env)->PopLocalFrame(env, NULL);
return 0;
}
@ -494,6 +540,14 @@ int retro_vfs_mkdir_saf(const char *tree, const char *dir)
if (env == NULL)
return -1;
(*env)->PushLocalFrame(env, 2);
if ((*env)->ExceptionOccurred(env))
{
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
return -1;
}
tree_object = (*env)->NewStringUTF(env, tree);
if ((*env)->ExceptionOccurred(env)) goto error;
@ -503,11 +557,13 @@ int retro_vfs_mkdir_saf(const char *tree, const char *dir)
ret = (*env)->CallStaticIntMethod(env, vfs_saf_vfs_implementation_saf_class, vfs_saf_mkdir_saf_method, vfs_saf_content_resolver_object, tree_object, path_object);
if ((*env)->ExceptionOccurred(env)) goto error;
(*env)->PopLocalFrame(env, NULL);
return ret;
error:
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
(*env)->PopLocalFrame(env, NULL);
return -1;
}
@ -528,6 +584,15 @@ libretro_vfs_implementation_saf_dir *retro_vfs_opendir_saf(const char *tree, con
if (dirstream == NULL)
return NULL;
(*env)->PushLocalFrame(env, 2);
if ((*env)->ExceptionOccurred(env))
{
free(dirstream);
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
return NULL;
}
tree_object = (*env)->NewStringUTF(env, tree);
if ((*env)->ExceptionOccurred(env)) goto error;
@ -543,12 +608,14 @@ libretro_vfs_implementation_saf_dir *retro_vfs_opendir_saf(const char *tree, con
dirstream->dirent_name_object = NULL;
dirstream->dirent_name = NULL;
dirstream->dirent_is_dir = false;
(*env)->PopLocalFrame(env, NULL);
return dirstream;
error:
free(dirstream);
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
(*env)->PopLocalFrame(env, NULL);
return NULL;
}
@ -565,6 +632,14 @@ bool retro_vfs_readdir_saf(libretro_vfs_implementation_saf_dir *dirstream)
if (env == NULL)
return false;
(*env)->PushLocalFrame(env, 1);
if ((*env)->ExceptionOccurred(env))
{
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
return false;
}
ret = (*env)->CallBooleanMethod(env, dirstream->directory_object, vfs_saf_saf_directory_readdir_method);
if ((*env)->ExceptionOccurred(env)) goto error;
@ -584,6 +659,7 @@ bool retro_vfs_readdir_saf(libretro_vfs_implementation_saf_dir *dirstream)
if (!ret)
{
dirstream->dirent_is_dir = false;
(*env)->PopLocalFrame(env, NULL);
return false;
}
@ -601,6 +677,7 @@ bool retro_vfs_readdir_saf(libretro_vfs_implementation_saf_dir *dirstream)
if ((*env)->ExceptionOccurred(env)) goto error;
dirstream->dirent_name = dirent_name;
(*env)->PopLocalFrame(env, NULL);
return true;
error:
@ -619,6 +696,7 @@ error:
if ((*env)->ExceptionOccurred(env)) goto error;
}
dirstream->dirent_is_dir = false;
(*env)->PopLocalFrame(env, NULL);
return false;
}