diff options
Diffstat (limited to 'libs/samba/src/main/cpp/jni.cpp')
| -rw-r--r-- | libs/samba/src/main/cpp/jni.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libs/samba/src/main/cpp/jni.cpp b/libs/samba/src/main/cpp/jni.cpp index 30f03a9..aac1d28 100644 --- a/libs/samba/src/main/cpp/jni.cpp +++ b/libs/samba/src/main/cpp/jni.cpp @@ -1,6 +1,10 @@ #include "jni.hpp" +#ifdef ANDROID #include <android/log.h> +#else +#include <iostream> +#endif namespace { @@ -35,7 +39,12 @@ namespace internal { void _abort_if_not_ok(const char *file, int line, jint ret) { if (ret == JNI_OK) [[likely]] return; +#ifdef ANDROID __android_log_assert(nullptr, "jni", "JNI error: %s", _jni_error(ret)); +#else + std::cerr << "JNI error: " << _jni_error(ret) << std::endl; + abort(); +#endif } void _abort_with_exception(const char* file, int line, JNIEnv* env) { @@ -51,22 +60,39 @@ void _abort_with_exception(const char* file, int line, JNIEnv* env) { auto description = jni::CallObjectMethod<jstring>(env, throwable, throwable_toString); auto str = jni::StringToUTF8(env, description); +#ifdef ANDROID __android_log_assert(nullptr, "jni", "JNI error: %s", str.c_str()); +#else + std::cerr << "JNI error: " << str << std::endl; + abort(); +#endif } } env->ExceptionClear(); +#ifdef ANDROID __android_log_assert(nullptr, "jni", "Unexpected NULL but no exception"); +#else + std::cerr << "Unexpected NULL but no exception" << std::endl; + abort(); +#endif } } } // namespace internal JNIEnv* AttachCurrentThread() { +#ifdef ANDROID JNIEnv* env; auto ret = g_vm->AttachCurrentThread(&env, nullptr); ABORT_IF_NOT_OK(ret); return env; +#else + void* v_env; + auto ret = g_vm->AttachCurrentThread(&v_env, nullptr); + ABORT_IF_NOT_OK(ret); + return reinterpret_cast<JNIEnv*>(v_env); +#endif } JNIEnv* OnLoad(JavaVM* vm) { |
