diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2024-08-20 23:21:06 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2024-08-20 23:21:06 +0200 |
| commit | 9b7f943969e17273ac9bd78bb238ffbea3865993 (patch) | |
| tree | 32d7d5c5f35414717b8bfa25f786fc4d2ebce029 /libs/samba/src/main/cpp | |
| parent | 088a7aef623700798647ad5b279388c4f7a59299 (diff) | |
Support building libsamba.so for unittests
Unittests still fail as there is no samba server to talk to (step 2).
Diffstat (limited to 'libs/samba/src/main/cpp')
| -rw-r--r-- | libs/samba/src/main/cpp/jni.cpp | 26 | ||||
| -rw-r--r-- | libs/samba/src/main/cpp/samba.cpp | 1 |
2 files changed, 27 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) { diff --git a/libs/samba/src/main/cpp/samba.cpp b/libs/samba/src/main/cpp/samba.cpp index 7b83eb4..7266a7f 100644 --- a/libs/samba/src/main/cpp/samba.cpp +++ b/libs/samba/src/main/cpp/samba.cpp @@ -1,3 +1,4 @@ +#include <algorithm> #include <cassert> #include <jni.h> #include <memory> |
