X-Git-Url: http://nitlanguage.org diff --git a/lib/jvm.nit b/lib/jvm.nit index a9f935b..36d3189 100644 --- a/lib/jvm.nit +++ b/lib/jvm.nit @@ -118,7 +118,7 @@ extern class JavaVM `{JavaVM *`} # Create the JVM, returns its handle and store the a pointer to JniEnv in `env_ref` # # Unavailable on Android, where you cannot instanciate a new JVM. - new(args: JavaVMInitArgs, env_ref: JniEnvRef) import jni_error, JniEnvRef.jni_env=, JniEnv as nullable `{ + new(args: JavaVMInitArgs, env_ref: JniEnvRef) import jni_error, JniEnvRef.jni_env=, JniEnv.as nullable `{ #ifdef ANDROID JavaVM_jni_error(NULL, "JVM creation not supported on Android", 0); @@ -163,7 +163,12 @@ extern class JavaVM `{JavaVM *`} fun attach_current_thread: JniEnv `{ JNIEnv *env; + #ifdef ANDROID + // the signature is different (better actually) on Android + int res = (*recv)->AttachCurrentThread(recv, &env, NULL); + #else int res = (*recv)->AttachCurrentThread(recv, (void**)&env, NULL); + #endif if (res != JNI_OK) { JavaVM_jni_error(NULL, "Could not attach current thread to Java VM", res); return NULL; @@ -251,7 +256,7 @@ extern class JniEnv `{JNIEnv *`} return (char*)(*recv)->GetStringUTFChars(recv, (jstring)jobj, NULL); `} - private fun convert_args_to_jni(args: nullable Array[nullable Object]): Pointer import Array[nullable Object] as not nullable, Array[nullable Object].[], Array[nullable Object].length, nullable Object.as(Int), nullable Object.as(Char), nullable Object.as(Bool), nullable Object.as(Float), nullable Object.as(JavaObject), nullable Object.as(String), String.to_cstring, String.length `{ + private fun convert_args_to_jni(args: nullable Array[nullable Object]): Pointer import Array[nullable Object].as not nullable, Array[nullable Object].[], Array[nullable Object].length, nullable Object.as(Int), nullable Object.as(Char), nullable Object.as(Bool), nullable Object.as(Float), nullable Object.as(JavaObject), nullable Object.as(String), String.to_cstring, String.length `{ if(nullable_Array_of_nullable_Object_is_null(args)){ return NULL; } @@ -369,6 +374,16 @@ extern class JniEnv `{JNIEnv *`} fun string_to_jobject(string: String): JavaObject `{ return (*recv)->NewStringUTF(recv, String_to_cstring(string)); `} + + # Pushes a local reference frame on the JNI stack + fun push_local_frame(capacity: Int): Bool `{ + return (*recv)->PushLocalFrame(recv, capacity); + `} + + # Pops the current local reference frame on the JNI stack + fun pop_local_frame `{ + (*recv)->PopLocalFrame(recv, NULL); + `} end # used to initialize a JavaVM @@ -385,7 +400,7 @@ extern class JMethodID `{jmethodID`} end # Represens a jni jobject -extern class JavaObject `{jobject`} +extern class JavaObject in "Java" `{ java.lang.Object `} end # Represents a jni JNINNativeMethod