B4Alpha-Aft3r0mega / javacpp

Automatically exported from code.google.com/p/javacpp
GNU General Public License v2.0
0 stars 0 forks source link

FunctionPointer use was not generating the proper code #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Extend a FunctionPointer
2. Add "native void allocate()" & "native OUTPUT call(INPUT)"
3. Generate code

What is the expected output? What do you see instead?
Call to AttachCurrentThread was doing a wrong cast:
if (JavaCPP_vm->AttachCurrentThread((void**)&e, NULL) != JNI_OK) {
should have been
if (JavaCPP_vm->AttachCurrentThread(&e, NULL) != JNI_OK) {

Also there is no DetachCurrentThread, so when the C/C++ threads finish we get a 
seg fault under Android (at least).
if (JavaCPP_vm->DetachCurrentThread() != JNI_OK) {
    return;
}

What version of the product are you using? On what operating system?
20111001 under Win7 x64

Please provide any additional information below.
Attached is the patch for Generator.java.

Original issue reported on code.google.com by bid...@gmail.com on 12 Oct 2011 at 7:06

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for the patch! I will make sure to add this to the next release. I am 
not sure if it's a good idea to call DetachCurrentThread() like that all the 
time though, but then again, we might never get the chance to run on that 
thread again to detach it so.. Some people seem to have issues with 
DetachCurrentThread() on Android though:
http://groups.google.com/group/android-ndk/browse_thread/thread/d87f33e60acdaa3a
I guess I will try to do what Alan said in the last message of that thread...

Original comment by samuel.a...@gmail.com on 14 Oct 2011 at 12:51

GoogleCodeExporter commented 8 years ago
I made changes in the SVN repository. It should fix this issue. Can you check? 
Thank you

Original comment by samuel.a...@gmail.com on 20 Oct 2011 at 2:19

GoogleCodeExporter commented 8 years ago
Finally got around to testing it. The detach problem was fixed. However, I had 
to define _JavaVM under ANDROID to get it to compile.

Original comment by bid...@gmail.com on 25 Oct 2011 at 2:07

GoogleCodeExporter commented 8 years ago
What does your jni.h file look like?

Original comment by samuel.a...@gmail.com on 26 Oct 2011 at 2:38

GoogleCodeExporter commented 8 years ago
From the jni.h:

struct _JNIEnv;
struct _JavaVM;
typedef const struct JNINativeInterface* C_JNIEnv;

#if defined(__cplusplus)
typedef _JNIEnv JNIEnv;
typedef _JavaVM JavaVM;
#else
typedef const struct JNINativeInterface* JNIEnv;
typedef const struct JNIInvokeInterface* JavaVM;
#endif

...

/*
 * C++ version.
 */
struct _JavaVM {
    const struct JNIInvokeInterface* functions;

#if defined(__cplusplus)
    jint DestroyJavaVM()
    { return functions->DestroyJavaVM(this); }
    jint AttachCurrentThread(JNIEnv** p_env, void* thr_args)
    { return functions->AttachCurrentThread(this, p_env, thr_args); }
    jint DetachCurrentThread()
    { return functions->DetachCurrentThread(this); }
    jint GetEnv(void** env, jint version)
    { return functions->GetEnv(this, env, version); }
    jint AttachCurrentThreadAsDaemon(JNIEnv** p_env, void* thr_args)
    { return functions->AttachCurrentThreadAsDaemon(this, p_env, thr_args); }
#endif /*__cplusplus*/
};

Original comment by bid...@gmail.com on 26 Oct 2011 at 2:49

GoogleCodeExporter commented 8 years ago
And “#ifdef _JavaVM“ returns false? What compiler/NDK version?

Original comment by samuel.a...@gmail.com on 26 Oct 2011 at 2:54

GoogleCodeExporter commented 8 years ago
Building this with NDK r6b. For API 10. Using the Windows SDK version 

Original comment by bid...@gmail.com on 26 Oct 2011 at 2:58

GoogleCodeExporter commented 8 years ago
Hum, typedef should not work with #ifdef, I wonder why it seemed to work... 
Anyway, I found a better way to handle this. I updated the SVN repo 
accordingly, please test it out! thanks

Original comment by samuel.a...@gmail.com on 26 Oct 2011 at 4:22

GoogleCodeExporter commented 8 years ago
That worked. Thank you.

Original comment by bid...@gmail.com on 26 Oct 2011 at 2:02

GoogleCodeExporter commented 8 years ago
You are welcome!

Original comment by samuel.a...@gmail.com on 29 Oct 2011 at 5:11