This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: jni.cc fixes
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 23 Oct 2002 17:13:16 -0600
- Subject: Patch: FYI: jni.cc fixes
- Reply-to: tromey at redhat dot com
I'm checking this in.
This fixes a minor jni.cc problem.
First, a C float will be promoted to double when passed via varargs.
We didn't take that into account.
Also, it seemed best to use the C types for varargs arguments: int,
long, double, and then cast them to the Java types. This is more
correct (though not perfectly so) when the types differ. The only
remaining problem case is when, say, `int' is smaller than `jint'.
However, that is both unlikely and unsupported anyway.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* jni.cc (_Jv_JNI_AllocObject): Removed old FIXME comment.
(array_from_valist): Correctly handle promotion for jint, jlong,
jfloat, and jdouble.
Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.63
diff -u -r1.63 jni.cc
--- jni.cc 10 May 2002 01:47:55 -0000 1.63
+++ jni.cc 23 Oct 2002 23:16:20 -0000
@@ -600,10 +600,7 @@
if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers()))
env->ex = new java::lang::InstantiationException ();
else
- {
- // FIXME: will this work for String?
- obj = JvAllocObject (clazz);
- }
+ obj = JvAllocObject (clazz);
}
catch (jthrowable t)
{
@@ -694,18 +691,21 @@
jclass *arg_elts = elements (arg_types);
for (int i = 0; i < arg_types->length; ++i)
{
+ // Here we assume that sizeof(int) >= sizeof(jint), because we
+ // use `int' when decoding the varargs. Likewise for
+ // long/jlong, float, and double.
if (arg_elts[i] == JvPrimClass (byte))
values[i].b = (jbyte) va_arg (vargs, int);
else if (arg_elts[i] == JvPrimClass (short))
values[i].s = (jshort) va_arg (vargs, int);
else if (arg_elts[i] == JvPrimClass (int))
- values[i].i = va_arg (vargs, jint);
+ values[i].i = (jint) va_arg (vargs, int);
else if (arg_elts[i] == JvPrimClass (long))
- values[i].j = va_arg (vargs, jlong);
+ values[i].j = (jlong) va_arg (vargs, long);
else if (arg_elts[i] == JvPrimClass (float))
- values[i].f = va_arg (vargs, jfloat);
+ values[i].f = (jfloat) va_arg (vargs, double);
else if (arg_elts[i] == JvPrimClass (double))
- values[i].d = va_arg (vargs, jdouble);
+ values[i].d = (jdouble) va_arg (vargs, double);
else if (arg_elts[i] == JvPrimClass (boolean))
values[i].z = (jboolean) va_arg (vargs, int);
else if (arg_elts[i] == JvPrimClass (char))