Patch: FYI: jni.cc fixes

Tom Tromey tromey@redhat.com
Mon Nov 4 12:08:00 GMT 2002


>>>>> "Ulrich" == Ulrich Weigand <Ulrich.Weigand@de.ibm.com> writes:

>> +      // Here we assume that sizeof(int) >= sizeof(jint), because we
>> +      // use `int' when decoding the varargs.  Likewise for
>> +      // long/jlong, float, and double.

Ulrich> is violated: jlong is a 64-bit type, while long is 32-bit ...

Thanks.  Sorry about that.

Is there a simple, robust way to write this?  I'm tempted to just
change long->jlong, since that should work "everywhere".  But it would
be nicer to have something more robust.

At the very least I can add assertions.  How about the appended?

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* jni.cc (array_from_valist): Assume that jlong won't be
	promoted.

Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.64
diff -u -r1.64 jni.cc
--- jni.cc 23 Oct 2002 23:19:55 -0000 1.64
+++ jni.cc 4 Nov 2002 20:07:07 -0000
@@ -693,7 +693,13 @@
     {
       // Here we assume that sizeof(int) >= sizeof(jint), because we
       // use `int' when decoding the varargs.  Likewise for
-      // long/jlong, float, and double.
+      // float, and double.  Also we assume that sizeof(jlong) >=
+      // sizeof (int), i.e. that jlong values are not further
+      // promoted.
+      JvAssert (sizeof (int) >= sizeof (jint));
+      JvAssert (sizeof (jlong) >= sizeof (int));
+      JvAssert (sizeof (float) >= sizeof (jfloat));
+      JvAssert (sizeof (double) >= sizeof (jdouble));
       if (arg_elts[i] == JvPrimClass (byte))
 	values[i].b = (jbyte) va_arg (vargs, int);
       else if (arg_elts[i] == JvPrimClass (short))



More information about the Java-patches mailing list