summaryrefslogtreecommitdiff
path: root/libs/samba/src/main/cpp/jni.cpp
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2024-08-22 22:30:25 +0200
committerJoel Klinghed <the_jk@spawned.biz>2024-08-22 22:30:25 +0200
commite38036e670d234b36053e03be92dd8f27acb16c0 (patch)
treead7ac56ca22db512fcb66254db77102fe113a4db /libs/samba/src/main/cpp/jni.cpp
parent8f506f21cbf127832bf47f9ca1f6cb18bfe80089 (diff)
samba: Cleanup jni layer
Remember that jni::GlobalRef can be used on multiple threads so we can't store the env, need to call AttachCurrentThread. Fix AttachCurrentThread (g_vm was forgotten). More consistent move and copy constructors in refs. Removed env() method as it would only be valid for Param and Local anyway.
Diffstat (limited to 'libs/samba/src/main/cpp/jni.cpp')
-rw-r--r--libs/samba/src/main/cpp/jni.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/libs/samba/src/main/cpp/jni.cpp b/libs/samba/src/main/cpp/jni.cpp
index aac1d28..5a69dc5 100644
--- a/libs/samba/src/main/cpp/jni.cpp
+++ b/libs/samba/src/main/cpp/jni.cpp
@@ -79,6 +79,22 @@ void _abort_with_exception(const char* file, int line, JNIEnv* env) {
}
}
+JNIEnv* NonFatalAttachCurrentThread() {
+#ifdef ANDROID
+ JNIEnv* env;
+ auto ret = g_vm->AttachCurrentThread(&env, nullptr);
+ if (ret == JNI_OK)
+ return env;
+ return nullptr;
+#else
+ void* v_env;
+ auto ret = g_vm->AttachCurrentThread(&v_env, nullptr);
+ if (ret == JNI_OK)
+ return reinterpret_cast<JNIEnv*>(v_env);
+ return nullptr;
+#endif
+}
+
} // namespace internal
JNIEnv* AttachCurrentThread() {
@@ -99,6 +115,7 @@ JNIEnv* OnLoad(JavaVM* vm) {
void* v_env;
auto ret = vm->GetEnv(&v_env, JNI_VERSION);
ABORT_IF_NOT_OK(ret);
+ g_vm = vm;
return reinterpret_cast<JNIEnv*>(v_env);
}