Re: [java-gnome-hackers] release candidate
Brought to you by:
afcowie
From: Andrew C. <an...@op...> - 2009-02-04 07:01:47
|
On Tue, 2009-02-03 at 10:16 +0100, Mark Wielaard wrote: > The problem is the definition of GetEnv which takes a (void **) as > second argument, but you are pointing it to a (JNIEnv **). I am not sure > why GetEnv is defined like that. It doesn't seem particular useful.... I'm sure the way we're using it was copy & pasted from some example in the book somewhere. > But > there is nothing you can do about that now since it is a standard > interface definition. That made me wonder if nonetheless we were doing it wrong. > union env_union > { > void **void_env; > JNIEnv **jni_env; > }; > > e.jni_env = &env; > result = (*cachedJavaVM)->GetEnv (cachedJavaVM, > e.void_env, > JNI_VERSION_1_4); The idea of using a union to hint the compiler is really interesting. Thanks! Instead of that, however, can we not just cast? I tried this: === modified file 'src/jni/bindings_java_util.c' --- src/jni/bindings_java_util.c 2009-02-01 14:53:00 +0000 +++ src/jni/bindings_java_util.c 2009-02-04 06:54:56 +0000 @@ -50,11 +50,13 @@ bindings_java_getEnv() { JNIEnv* env = NULL; + void* ptr = NULL; JavaVMAttachArgs args = { 0, }; static int i = 0; jint result; - result = (*cachedJavaVM)->GetEnv(cachedJavaVM, (void **) &env, JNI_VERSION_1_4); + result = (*cachedJavaVM)->GetEnv(cachedJavaVM, &ptr, JNI_VERSION_1_4); + env = (JNIEnv*) ptr; if (env != NULL) { return env; } @@ -64,7 +66,8 @@ args.version = JNI_VERSION_1_4; args.name = g_strdup_printf("NativeThread%d", i++); - result = (*cachedJavaVM)->AttachCurrentThreadAsDaemon(cachedJavaVM, (void **) &env, &args); + result = (*cachedJavaVM)->AttachCurrentThreadAsDaemon(cachedJavaVM, &ptr, &args); + env = (JNIEnv*) ptr; if ((result == JNI_OK) && (env != NULL)) { g_free(args.name); and the warnings have gone away for me. Any reason that isn't ok? This sort of casting is, after all, how the entire java-gnome library works. A bundle with this patch is attached. Give it a try? AfC Sydney -- Andrew Frederick Cowie Operational Dynamics is an operations and engineering consultancy focusing on IT strategy, organizational architecture, systems review, and effective procedures for change management: enabling successful deployment of mission critical information technology in enterprises, worldwide. http://www.operationaldynamics.com/ Sydney New York Toronto London |