natField.cc (setAddr): New function.

* java/lang/reflect/natField.cc (setAddr):  New function.
	Calls getAddr and then checks that the field isn't final.
	(setBoolean. setChar, setByte, setShort, setInt, setLong, setFloat,
	setDouble, set):  Use setAddr instead of getAddr, to check for FINAL.
	(set):  Call setAddr before check that new value has right type,
	to better match specified semantics.

From-SVN: r49153
This commit is contained in:
Per Bothner 2002-01-23 11:42:18 -08:00 committed by Per Bothner
parent c588e52b27
commit 033509daea
2 changed files with 28 additions and 9 deletions

View File

@ -1,3 +1,12 @@
2002-01-23 Per Bothner <per@bothner.com>
* java/lang/reflect/natField.cc (setAddr): New function.
Calls getAddr and then checks that the field isn't final.
(setBoolean. setChar, setByte, setShort, setInt, setLong, setFloat,
setDouble, set): Use setAddr instead of getAddr, to check for FINAL.
(set): Call setAddr before check that new value has right type,
to better match specified semantics.
2002-01-22 Tom Tromey <tromey@redhat.com>
* java/awt/TextField.java: Replaced with Classpath version.

View File

@ -16,6 +16,7 @@ details. */
#include <java/lang/reflect/Field.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/IllegalArgumentException.h>
#include <java/lang/IllegalAccessException.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/Byte.h>
#include <java/lang/Short.h>
@ -252,6 +253,15 @@ java::lang::reflect::Field::get (jclass caller, jobject obj)
throw new java::lang::IllegalArgumentException;
}
static void*
setAddr (java::lang::reflect::Field* field, jclass caller, jobject obj)
{
void *addr = getAddr(field, caller, obj);
if (field->getModifiers() & java::lang::reflect::Modifier::FINAL)
throw new java::lang::IllegalAccessException();
return addr;
}
static void
setBoolean (jclass type, void *addr, jboolean value)
{
@ -366,63 +376,63 @@ void
java::lang::reflect::Field::setBoolean (jclass caller, jobject obj, jboolean b)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setBoolean (fld->type, getAddr (this, caller, obj), b);
::setBoolean (fld->type, setAddr (this, caller, obj), b);
}
void
java::lang::reflect::Field::setChar (jclass caller, jobject obj, jchar c)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setChar (fld->type, getAddr (this, caller, obj), c);
::setChar (fld->type, setAddr (this, caller, obj), c);
}
void
java::lang::reflect::Field::setByte (jclass caller, jobject obj, jbyte b)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setByte (fld->type, getAddr (this, caller, obj), b);
::setByte (fld->type, setAddr (this, caller, obj), b);
}
void
java::lang::reflect::Field::setShort (jclass caller, jobject obj, jshort s)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setShort (fld->type, getAddr (this, caller, obj), s);
::setShort (fld->type, setAddr (this, caller, obj), s);
}
void
java::lang::reflect::Field::setInt (jclass caller, jobject obj, jint i)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setInt (fld->type, getAddr (this, caller, obj), i);
::setInt (fld->type, setAddr (this, caller, obj), i);
}
void
java::lang::reflect::Field::setLong (jclass caller, jobject obj, jlong l)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setLong (fld->type, getAddr (this, caller, obj), l);
::setLong (fld->type, setAddr (this, caller, obj), l);
}
void
java::lang::reflect::Field::setFloat (jclass caller, jobject obj, jfloat f)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setFloat (fld->type, getAddr (this, caller, obj), f);
::setFloat (fld->type, setAddr (this, caller, obj), f);
}
void
java::lang::reflect::Field::setDouble (jclass caller, jobject obj, jdouble d)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setDouble (fld->type, getAddr (this, caller, obj), d);
::setDouble (fld->type, setAddr (this, caller, obj), d);
}
void
java::lang::reflect::Field::set (jclass caller, jobject object, jobject value,
jclass type)
{
void* addr = setAddr (this, caller, object);
if (value != NULL && ! _Jv_IsInstanceOf (value, type))
throw new java::lang::IllegalArgumentException;
void* addr = getAddr (this, caller, object);
* (jobject*) addr = value;
}