Passing Parameters with variable values
OK,
I'll try this again.
The function in the header file (no source)is:
NEWTON_API NewtonWorld* NewtonCreate (NewtonAllocMemory malloc, NewtonFreeMemory mfree);
In the documentation are the following statements:
Parameters
NewtonAllocMemory mallocFnt - is a pointer to the memory allocator callback function. If this parameter is NULL the standard malloc function is used.
NewtonFreeMemory mfreeFnt - is a pointer to the memory release callback function. If this parameter is NULL the standard free function is used.
I implemented it like this:
JNIEXPORT jint JNICALL Java_jnewton_JNewton_newtonCreate
(JNIEnv *env, jobject class, jobject obj1, jobject obj2){
jint result;
jobject lrObj1 = (*env)->NewLocalRef(env, obj1);
jobject lrObj2 = (*env)->NewLocalRef(env, obj2);
NewtonWorld* nw = NewtonCreate(lrObj1, lrObj2);
result = (jint)nw;
(*env)->DeleteLocalRef(*env, lrObj1);
(*env)->DeleteLocalRef(*env, lrObj2);
return(result);
}
and prototype it like this:
publicnativeint newtonCreate(Object o1, Object o2);
and call it like this:
jn.newtonWorld = jn.newtonCreate(null,null);
My rationale is the only thing in Java which can have the values of null and something is a class instance. In order to allow for passing a variety of things I used Object.
Originally, I feed the jobjects to the DLL function, thinking that the null value would be preserved. This resulted in warnings that my pointer conversion was from incompatible types. So I createdthe local references. This got rid of the compiler warnings, but now I get a runtime error:
Stack: [0x00030000,0x00070000), sp=0x0006fa10, free space=254k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [jvm.dll+0x41d78]
V [jvm.dll+0x8abb4]
j jnewton.JNewton.newtonCreate(Ljava/lang/Object;Ljava/lang/Object;)I+0
j jnewton.JNewton.main([Ljava/lang/String;)V+12
This seems to indicate that there is a problem with the two LocalRef creations.
1. What should I pass as a parameter?
2. How should I handle it inside the JNI function?
Any other advice is appreciated.
Jim

