Patch: JNI dot/slash change
Anthony Green
green@redhat.com
Sun Feb 13 20:25:00 GMT 2005
_Jv_JNI_RegisterNatives is passed method signatures with slashes in
them. We store them in a hash table like this. Unfortunately, gcj's
internal representation uses dots instead of slashes so our hashtable
searches always fail. See this thread for more details:
http://gcc.gnu.org/ml/java/2005-02/msg00118.html
Attached is the patch I used to get the JNI code for jogl working.
Ok?
AG
-------------- next part --------------
2005-02-13 Anthony Green <green@redhat.com>
* jni.cc (nathash_add): Don't strdup the method signature.
(_Jv_JNI_RegisterNatives): Convert the slashes to dots in the
method signature.
Update copyright.
Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.93
diff -u -p -r1.93 jni.cc
--- jni.cc 14 Jan 2005 07:36:26 -0000 1.93
+++ jni.cc 13 Feb 2005 19:09:39 -0000
@@ -1880,7 +1880,8 @@ nathash_add (const JNINativeMethod *meth
return;
// FIXME
slot->name = strdup (method->name);
- slot->signature = strdup (method->signature);
+ // This was already strduped in _Jv_JNI_RegisterNatives.
+ slot->signature = method->signature;
slot->fnPtr = method->fnPtr;
}
@@ -1894,6 +1895,8 @@ _Jv_JNI_RegisterNatives (JNIEnv *env, jc
// the nathash table.
JvSynchronize sync (global_ref_table);
+ JNINativeMethod dottedMethod;
+
// Look at each descriptor given us, and find the corresponding
// method in the class.
for (int j = 0; j < nMethods; ++j)
@@ -1905,15 +1908,28 @@ _Jv_JNI_RegisterNatives (JNIEnv *env, jc
{
_Jv_Method *self = &imeths[i];
- if (! strcmp (self->name->chars (), methods[j].name)
- && ! strcmp (self->signature->chars (), methods[j].signature))
+ // Copy this JNINativeMethod and do a slash to dot
+ // conversion on the signature.
+ dottedMethod.name = methods[j].name;
+ dottedMethod.signature = strdup (methods[j].signature);
+ dottedMethod.fnPtr = methods[j].fnPtr;
+ char *c = dottedMethod.signature;
+ while (*c)
+ {
+ if (*c == '/')
+ *c = '.';
+ c++;
+ }
+
+ if (! strcmp (self->name->chars (), dottedMethod.name)
+ && ! strcmp (self->signature->chars (), dottedMethod.signature))
{
if (! (self->accflags & java::lang::reflect::Modifier::NATIVE))
break;
// Found a match that is native.
found = true;
- nathash_add (&methods[j]);
+ nathash_add (&dottedMethod);
break;
}
More information about the Java-patches
mailing list