re PR libgcj/23739 (JNI: IsAssignableFrom reverses arguments)

PR libgcj/23739:
	* testsuite/libjava.jni/pr23739.c: New file.
	* testsuite/libjava.jni/pr23739.java: New file.
	* testsuite/libjava.jni/pr23739.out: New file.
	* jni.cc (_Jv_JNI_IsAssignableFrom): Reversed arguments.
	* java/lang/reflect/natMethod.cc (invoke): Updated.
	* java/lang/natClass.cc (isAssignableFrom): Updated.
	(isInstance): Likewise.
	(_Jv_IsAssignableFrom): Reversed arguments.
	(_Jv_IsInstanceOf): Updated.
	(_Jv_CheckCast): Likewise.
	(_Jv_CheckArrayStore): Likewise.
	(_Jv_IsAssignableFromSlow): Reversed arguments.
	(_Jv_InterfaceAssignableFrom): Likewise.
	* link.cc (verify_type_assertions): Updated.
	* prims.cc (_Jv_CheckAccess): Updated.

From-SVN: r103953
This commit is contained in:
Tom Tromey 2005-09-06 16:01:31 +00:00 committed by Tom Tromey
parent 3e248b8315
commit 852993e381
10 changed files with 73 additions and 17 deletions

View File

@ -1,3 +1,22 @@
2005-09-06 Tom Tromey <tromey@redhat.com>
PR libgcj/23739:
* testsuite/libjava.jni/pr23739.c: New file.
* testsuite/libjava.jni/pr23739.java: New file.
* testsuite/libjava.jni/pr23739.out: New file.
* jni.cc (_Jv_JNI_IsAssignableFrom): Reversed arguments.
* java/lang/reflect/natMethod.cc (invoke): Updated.
* java/lang/natClass.cc (isAssignableFrom): Updated.
(isInstance): Likewise.
(_Jv_IsAssignableFrom): Reversed arguments.
(_Jv_IsInstanceOf): Updated.
(_Jv_CheckCast): Likewise.
(_Jv_CheckArrayStore): Likewise.
(_Jv_IsAssignableFromSlow): Reversed arguments.
(_Jv_InterfaceAssignableFrom): Likewise.
* link.cc (verify_type_assertions): Updated.
* prims.cc (_Jv_CheckAccess): Updated.
2005-09-05 Ranjit Mathew <rmathew@hotmail.com>
Testsuite changes for PR java/23431.

View File

@ -623,7 +623,7 @@ java::lang::Class::isAssignableFrom (jclass klass)
// Arguments may not have been initialized, given ".class" syntax.
_Jv_InitClass (this);
_Jv_InitClass (klass);
return _Jv_IsAssignableFrom (this, klass);
return _Jv_IsAssignableFrom (klass, this);
}
jboolean
@ -632,7 +632,7 @@ java::lang::Class::isInstance (jobject obj)
if (! obj)
return false;
_Jv_InitClass (this);
return _Jv_IsAssignableFrom (this, JV_CLASS (obj));
return _Jv_IsAssignableFrom (JV_CLASS (obj), this);
}
jobject
@ -964,7 +964,7 @@ _Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface, int method_idx)
}
jboolean
_Jv_IsAssignableFrom (jclass target, jclass source)
_Jv_IsAssignableFrom (jclass source, jclass target)
{
if (source == target)
return true;
@ -984,7 +984,7 @@ _Jv_IsAssignableFrom (jclass target, jclass source)
// two interfaces for assignability.
if (__builtin_expect
(source->idt == NULL || source->isInterface(), false))
return _Jv_InterfaceAssignableFrom (target, source);
return _Jv_InterfaceAssignableFrom (source, target);
_Jv_IDispatchTable *cl_idt = source->idt;
_Jv_IDispatchTable *if_idt = target->idt;
@ -1033,19 +1033,19 @@ _Jv_IsAssignableFrom (jclass target, jclass source)
// superinterface of SOURCE. This is used when SOURCE is also an interface,
// or a class with no interface dispatch table.
jboolean
_Jv_InterfaceAssignableFrom (jclass iface, jclass source)
_Jv_InterfaceAssignableFrom (jclass source, jclass iface)
{
for (int i = 0; i < source->interface_count; i++)
{
jclass interface = source->interfaces[i];
if (iface == interface
|| _Jv_InterfaceAssignableFrom (iface, interface))
|| _Jv_InterfaceAssignableFrom (interface, iface))
return true;
}
if (!source->isInterface()
&& source->superclass
&& _Jv_InterfaceAssignableFrom (iface, source->superclass))
&& _Jv_InterfaceAssignableFrom (source->superclass, iface))
return true;
return false;
@ -1056,14 +1056,14 @@ _Jv_IsInstanceOf(jobject obj, jclass cl)
{
if (__builtin_expect (!obj, false))
return false;
return (_Jv_IsAssignableFrom (cl, JV_CLASS (obj)));
return _Jv_IsAssignableFrom (JV_CLASS (obj), cl);
}
void *
_Jv_CheckCast (jclass c, jobject obj)
{
if (__builtin_expect
(obj != NULL && ! _Jv_IsAssignableFrom(c, JV_CLASS (obj)), false))
(obj != NULL && ! _Jv_IsAssignableFrom(JV_CLASS (obj), c), false))
throw new java::lang::ClassCastException
((new java::lang::StringBuffer
(obj->getClass()->getName()))->append
@ -1084,7 +1084,7 @@ _Jv_CheckArrayStore (jobject arr, jobject obj)
return;
jclass obj_class = JV_CLASS (obj);
if (__builtin_expect
(! _Jv_IsAssignableFrom (elt_class, obj_class), false))
(! _Jv_IsAssignableFrom (obj_class, elt_class), false))
throw new java::lang::ArrayStoreException
((new java::lang::StringBuffer
(JvNewStringUTF("Cannot store ")))->append
@ -1095,7 +1095,7 @@ _Jv_CheckArrayStore (jobject arr, jobject obj)
}
jboolean
_Jv_IsAssignableFromSlow (jclass target, jclass source)
_Jv_IsAssignableFromSlow (jclass source, jclass target)
{
// First, strip arrays.
while (target->isArray ())
@ -1129,7 +1129,7 @@ _Jv_IsAssignableFromSlow (jclass target, jclass source)
{
// We use a recursive call because we also need to
// check superinterfaces.
if (_Jv_IsAssignableFromSlow (target, source->getInterface (i)))
if (_Jv_IsAssignableFromSlow (source->getInterface (i), target))
return true;
}
}

View File

@ -163,7 +163,7 @@ java::lang::reflect::Method::invoke (jobject obj, jobjectArray args)
else
{
jclass objClass = JV_CLASS (obj);
if (! _Jv_IsAssignableFrom (declaringClass, objClass))
if (! _Jv_IsAssignableFrom (objClass, declaringClass))
throw new java::lang::IllegalArgumentException;
}

View File

@ -552,7 +552,7 @@ _Jv_JNI_GetSuperclass (JNIEnv *env, jclass clazz)
static jboolean JNICALL
_Jv_JNI_IsAssignableFrom (JNIEnv *, jclass clazz1, jclass clazz2)
{
return unwrap (clazz1)->isAssignableFrom (unwrap (clazz2));
return unwrap (clazz2)->isAssignableFrom (unwrap (clazz1));
}
static jint JNICALL

View File

@ -1620,7 +1620,7 @@ _Jv_Linker::verify_type_assertions (jclass klass)
if (cl1 == NULL || cl2 == NULL)
continue;
if (! _Jv_IsAssignableFromSlow (cl2, cl1))
if (! _Jv_IsAssignableFromSlow (cl1, cl2))
{
jstring s = JvNewStringUTF ("Incompatible types: In class ");
s = s->concat (klass->getName());

View File

@ -1557,7 +1557,7 @@ _Jv_CheckAccess (jclass self_klass, jclass other_klass, jint flags)
return ((self_klass == other_klass)
|| ((flags & Modifier::PUBLIC) != 0)
|| (((flags & Modifier::PROTECTED) != 0)
&& _Jv_IsAssignableFromSlow (other_klass, self_klass))
&& _Jv_IsAssignableFromSlow (self_klass, other_klass))
|| (((flags & Modifier::PRIVATE) == 0)
&& _Jv_ClassNameSamePackage (self_klass->name,
other_klass->name)));

View File

@ -1,4 +1,4 @@
# Makefile.in generated by automake 1.9.4 from Makefile.am.
# Makefile.in generated by automake 1.9.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,

View File

@ -0,0 +1,12 @@
#include <stdio.h>
#include "pr23739.h"
JNIEXPORT void JNICALL
Java_pr23739_checkOrder (JNIEnv *env, jclass cls, jclass clazz1, jclass clazz2)
{
printf ("B extends A\n");
printf ("isAssignableFrom (A, B): %d\n",
(*env)->IsAssignableFrom (env, clazz1, clazz2));
printf ("isAssignableFrom (B, A): %d\n",
(*env)->IsAssignableFrom (env, clazz2, clazz1));
}

View File

@ -0,0 +1,22 @@
public class pr23739
{
static
{
System.loadLibrary ("pr23739");
}
public static class A
{
}
public static class B extends A
{
}
static native void checkOrder (Class clazz1, Class clazz2);
public static void main (String[] args)
{
checkOrder (A.class, B.class);
}
}

View File

@ -0,0 +1,3 @@
B extends A
isAssignableFrom (A, B): 0
isAssignableFrom (B, A): 1