This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Class.isAssignableFrom() and Method.invoke() (PR libgcj/1516)


From the JDK 1.3 online docs for Class.isAssignableFrom():

"If this Class object represents a primitive type, this method returns
true if the specified Class parameter is exactly this Class object;
otherwise it returns false. "

Previously we would return true for the case where a primitive TYPE
argument was tested against java.lang.Object. The first patch fixes
that.

The second patch fixes the PR libgcj/1516 reported by Jeff Sturm, and
cleans up _Jv_CallAnyMethodA() and can_widen() a little.

I'm checking these in.

regards

  [ bryce ]


2000-12-28  Bryce McKinlay  <bryce@albatross.co.nz>

	* java/lang/natClass.cc (_Jv_IsAssignableFrom): Primitive TYPEs can
	not be assigned to Object.

Index: natClass.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/natClass.cc,v
retrieving revision 1.30
diff -u -r1.30 natClass.cc
--- natClass.cc	2000/11/26 03:58:55	1.30
+++ natClass.cc	2000/12/28 02:34:14
@@ -909,8 +909,8 @@
 jboolean
 _Jv_IsAssignableFrom (jclass target, jclass source)
 {
-  if (target == &ObjectClass 
-      || source == target 
+  if (source == target
+      || (target == &ObjectClass && !source->isPrimitive())
       || (source->ancestors != NULL 
           && source->ancestors[source->depth - target->depth] == target))
      return true;
2000-12-28  Bryce McKinlay  <bryce@albatross.co.nz>

	Fix for PR libgcj/1516:
	* java/lang/reflect/natMethod.cc (primitives): Remove void entry.
	Add boolean entry.
	(can_widen): Declared inline. Remove check for void arguments. Remove
	redundant special-case check for char->short conversion. Add special
	case for boolean conversions.
	(ffi_type): Declared inline.
	(_Jv_CallAnyMethodA): Move unwrapping logic inside isPrimitive() block.

Index: natMethod.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/reflect/natMethod.cc,v
retrieving revision 1.18
diff -u -r1.18 natMethod.cc
--- natMethod.cc	2000/11/16 21:34:48	1.18
+++ natMethod.cc	2000/12/28 04:09:33
@@ -47,6 +47,7 @@
 #include <ffi.h>
 
 // FIXME: remove these.
+#define BooleanClass java::lang::Boolean::class$
 #define VoidClass java::lang::Void::class$
 #define ByteClass java::lang::Byte::class$
 #define ShortClass java::lang::Short::class$
@@ -66,8 +67,8 @@
 // allowed.
 static cpair primitives[] =
 {
-#define VOID 0
-  { JvPrimClass (void), &VoidClass },
+#define BOOLEAN 0
+  { JvPrimClass (boolean), &BooleanClass },
   { JvPrimClass (byte), &ByteClass },
 #define SHORT 2
   { JvPrimClass (short), &ShortClass },
@@ -80,7 +81,7 @@
   { NULL, NULL }
 };
 
-static jboolean
+static inline jboolean
 can_widen (jclass from, jclass to)
 {
   int fromx = -1, tox = -1;
@@ -96,17 +97,17 @@
   // Can't handle a miss.
   if (fromx == -1 || tox == -1)
     return false;
-  // Can't handle Void arguments.
-  if (fromx == VOID || tox == VOID)
+  // Boolean arguments may not be widened.
+  if (fromx == BOOLEAN && tox != BOOLEAN)
     return false;
-  // Special-case short/char conversions.
-  if ((fromx == SHORT && tox == CHAR) || (fromx == CHAR && tox == SHORT))
+  // Special-case short->char conversions.
+  if (fromx == SHORT && tox == CHAR)
     return false;
 
   return fromx <= tox;
 }
 
-static ffi_type *
+static inline ffi_type *
 get_ffi_type (jclass klass)
 {
   // A special case.
@@ -469,37 +470,36 @@
 	      || ! k
 	      || ! can_widen (k, paramelts[i]))
 	    JvThrow (new java::lang::IllegalArgumentException);
+	    
+	  if (paramelts[i] == JvPrimClass (boolean))
+	    COPY (&argvals[i],
+		  ((java::lang::Boolean *) argelts[i])->booleanValue(),
+		  jboolean);
+	  else if (paramelts[i] == JvPrimClass (char))
+	    COPY (&argvals[i],
+		  ((java::lang::Character *) argelts[i])->charValue(),
+		  jchar);
+          else
+	    {
+	      java::lang::Number *num = (java::lang::Number *) argelts[i];
+	      if (paramelts[i] == JvPrimClass (byte))
+		COPY (&argvals[i], num->byteValue(), jbyte);
+	      else if (paramelts[i] == JvPrimClass (short))
+		COPY (&argvals[i], num->shortValue(), jshort);
+	      else if (paramelts[i] == JvPrimClass (int))
+		COPY (&argvals[i], num->intValue(), jint);
+	      else if (paramelts[i] == JvPrimClass (long))
+		COPY (&argvals[i], num->longValue(), jlong);
+	      else if (paramelts[i] == JvPrimClass (float))
+		COPY (&argvals[i], num->floatValue(), jfloat);
+	      else if (paramelts[i] == JvPrimClass (double))
+		COPY (&argvals[i], num->doubleValue(), jdouble);
+	    }
 	}
       else
 	{
 	  if (argelts[i] && ! paramelts[i]->isAssignableFrom (k))
 	    JvThrow (new java::lang::IllegalArgumentException);
-	}
-
-      java::lang::Number *num = (java::lang::Number *) argelts[i];
-      if (paramelts[i] == JvPrimClass (byte))
-	COPY (&argvals[i], num->byteValue(), jbyte);
-      else if (paramelts[i] == JvPrimClass (short))
-	COPY (&argvals[i], num->shortValue(), jshort);
-      else if (paramelts[i] == JvPrimClass (int))
-	COPY (&argvals[i], num->intValue(), jint);
-      else if (paramelts[i] == JvPrimClass (long))
-	COPY (&argvals[i], num->longValue(), jlong);
-      else if (paramelts[i] == JvPrimClass (float))
-	COPY (&argvals[i], num->floatValue(), jfloat);
-      else if (paramelts[i] == JvPrimClass (double))
-	COPY (&argvals[i], num->doubleValue(), jdouble);
-      else if (paramelts[i] == JvPrimClass (boolean))
-	COPY (&argvals[i],
-	      ((java::lang::Boolean *) argelts[i])->booleanValue(),
-	      jboolean);
-      else if (paramelts[i] == JvPrimClass (char))
-	COPY (&argvals[i],
-	      ((java::lang::Character *) argelts[i])->charValue(),
-	      jchar);
-      else
-	{
-	  JvAssert (! paramelts[i]->isPrimitive());
 	  COPY (&argvals[i], argelts[i], jobject);
 	}
     }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]