Skip to content

Commit

Permalink
Merge pull request #140 from kthornberrysc/check-jni-fixes
Browse files Browse the repository at this point in the history
Fixes for a couple of issues found when running with check:jni enabled
  • Loading branch information
li-feng-sc authored May 8, 2023
2 parents 04e8687 + d4b3ae0 commit 0986d44
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion support-lib/jni/Marshal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ namespace djinni
{
auto j = T::makePrimitiveArray(jniEnv, static_cast<jint>(c.size()));
if (c.size() > 0) {
auto deleter = [jniEnv, j] (void* c) {if (c) {jniEnv->ReleasePrimitiveArrayCritical(j, c, JNI_ABORT);}};
auto deleter = [jniEnv, j] (void* c) {if (c) {jniEnv->ReleasePrimitiveArrayCritical(j, c, 0);}};
std::unique_ptr<EJniType, decltype(deleter)> ptr(
reinterpret_cast<EJniType*>(jniEnv->GetPrimitiveArrayCritical(j, nullptr)),
deleter);
Expand Down
1 change: 1 addition & 0 deletions support-lib/jni/Outcome_jni.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Outcome
return RESULT::Boxed::toCpp(jniEnv, reinterpret_cast<typename RESULT::Boxed::JniType>(r.get()));
} else {
auto e = LocalRef<jobject>(jniEnv, jniEnv->CallObjectMethod(j, outcomeJniInfo.method_error_or_null));
jniExceptionCheck(jniEnv);
// if result is not present then error must be present, we can skip the present check
return make_unexpected(ERROR::Boxed::toCpp(jniEnv, reinterpret_cast<typename ERROR::Boxed::JniType>(e.get())));
}
Expand Down
1 change: 1 addition & 0 deletions support-lib/jni/djinni_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ void jniInit(JavaVM * jvm) {
jclass classClass = env->GetObjectClass(ourClass);
jmethodID getClassLoaderMethod = env->GetMethodID(classClass, "getClassLoader", "()Ljava/lang/ClassLoader;");
jobject tmp = env->CallObjectMethod(ourClass, getClassLoaderMethod);
jniExceptionCheck(env);
g_ourClassLoader = (jobject)env->NewGlobalRef(tmp);

jclass classLoaderClass = env->FindClass("java/lang/ClassLoader");
Expand Down
2 changes: 1 addition & 1 deletion test-suite/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ java_test(
"@maven_djinni//:io_reactivex_rxjava2_rxjava",
"@com_google_protobuf//java/core:core",
],
jvm_flags = ["-Ddjinni.native_libs_dirs=./test-suite/libdjinni-tests-jni.so"],
jvm_flags = ["-Ddjinni.native_libs_dirs=./test-suite/libdjinni-tests-jni.so", "-Xcheck:jni"],
)

macos_unit_test(
Expand Down

0 comments on commit 0986d44

Please sign in to comment.