Skip to content

Commit

Permalink
Cope with implementation inconsistencies in AttachCurrentThread
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed May 8, 2017
1 parent b5e3d06 commit 6654bc2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion include/jni/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,23 @@ namespace jni

inline UniqueEnv AttachCurrentThread(JavaVM& vm)
{
// Some implementations type the parameter as JNIEnv**, others as void**.
// See https://bugs.openjdk.java.net/browse/JDK-6569899
struct JNIEnvCast
{
void** operator()(JNIEnv** env, jint (JavaVM::*)(void**, void*))
{
return reinterpret_cast<void**>(env);
}

JNIEnv** operator()(JNIEnv** env, jint (JavaVM::*)(JNIEnv**, void*))
{
return env;
}
};

JNIEnv* result;
CheckErrorCode(vm.AttachCurrentThread(&result, nullptr));
CheckErrorCode(vm.AttachCurrentThread(JNIEnvCast()(&result, &JavaVM::AttachCurrentThread), nullptr));
return UniqueEnv(result, JNIEnvDeleter(vm));
}

Expand Down

0 comments on commit 6654bc2

Please sign in to comment.