mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-24 07:40:26 +08:00
prims.cc (_Jv_NewMultiArrayUnchecked): New method.
* prims.cc (_Jv_NewMultiArrayUnchecked): New method. (_Jv_NewMultiArray): Use it. Check each array dimension. (_Jv_NewMultiArray): Likewise. * java/lang/reflect/natMethod.cc (can_widen): Nothing promotes to `char'. * java/lang/reflect/natArray.cc (newInstance): Throw IllegalArgumentException if there are no dimensions. From-SVN: r45951
This commit is contained in:
parent
6cbd1b6f7e
commit
62a040818a
libjava
@ -1,3 +1,13 @@
|
||||
2001-10-01 Tom Tromey <tromey@redhat.com>
|
||||
|
||||
* prims.cc (_Jv_NewMultiArrayUnchecked): New method.
|
||||
(_Jv_NewMultiArray): Use it. Check each array dimension.
|
||||
(_Jv_NewMultiArray): Likewise.
|
||||
* java/lang/reflect/natMethod.cc (can_widen): Nothing promotes to
|
||||
`char'.
|
||||
* java/lang/reflect/natArray.cc (newInstance): Throw
|
||||
IllegalArgumentException if there are no dimensions.
|
||||
|
||||
2001-10-01 Mark Wielaard <mark@klomp.org>
|
||||
|
||||
* java/io/FileWriter.java: Merge with Classpath.
|
||||
|
@ -43,11 +43,12 @@ java::lang::reflect::Array::newInstance (jclass componentType, jint length)
|
||||
}
|
||||
|
||||
jobject
|
||||
java::lang::reflect::Array::newInstance (jclass componentType, jintArray dimensions)
|
||||
java::lang::reflect::Array::newInstance (jclass componentType,
|
||||
jintArray dimensions)
|
||||
{
|
||||
jint ndims = dimensions->length;
|
||||
if (ndims == 0)
|
||||
return componentType->newInstance ();
|
||||
throw new java::lang::IllegalArgumentException ();
|
||||
jint* dims = elements (dimensions);
|
||||
if (ndims == 1)
|
||||
return newInstance (componentType, dims[0]);
|
||||
|
@ -100,8 +100,8 @@ can_widen (jclass from, jclass to)
|
||||
// Boolean arguments may not be widened.
|
||||
if (fromx == BOOLEAN && tox != BOOLEAN)
|
||||
return false;
|
||||
// Special-case short->char conversions.
|
||||
if (fromx == SHORT && tox == CHAR)
|
||||
// Nothing promotes to char.
|
||||
if (tox == CHAR && fromx != CHAR)
|
||||
return false;
|
||||
|
||||
return fromx <= tox;
|
||||
|
@ -516,8 +516,10 @@ _Jv_NewArray (jint type, jint size)
|
||||
return NULL; // Placate compiler.
|
||||
}
|
||||
|
||||
jobject
|
||||
_Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
|
||||
// Allocate a possibly multi-dimensional array but don't check that
|
||||
// any array length is <0.
|
||||
static jobject
|
||||
_Jv_NewMultiArrayUnchecked (jclass type, jint dimensions, jint *sizes)
|
||||
{
|
||||
JvAssert (type->isArray());
|
||||
jclass element_type = type->getComponentType();
|
||||
@ -533,13 +535,23 @@ _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
|
||||
JvAssert (element_type->isArray());
|
||||
jobject *contents = elements ((jobjectArray) result);
|
||||
for (int i = 0; i < sizes[0]; ++i)
|
||||
contents[i] = _Jv_NewMultiArray (element_type, dimensions - 1,
|
||||
sizes + 1);
|
||||
contents[i] = _Jv_NewMultiArrayUnchecked (element_type, dimensions - 1,
|
||||
sizes + 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
jobject
|
||||
_Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
|
||||
{
|
||||
for (int i = 0; i < dimensions; ++i)
|
||||
if (sizes[i] < 0)
|
||||
throw new java::lang::NegativeArraySizeException;
|
||||
|
||||
return _Jv_NewMultiArrayUnchecked (type, dimensions, sizes);
|
||||
}
|
||||
|
||||
jobject
|
||||
_Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
|
||||
{
|
||||
@ -549,11 +561,13 @@ _Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
|
||||
for (int i = 0; i < dimensions; ++i)
|
||||
{
|
||||
jint size = va_arg (args, jint);
|
||||
if (size < 0)
|
||||
throw new java::lang::NegativeArraySizeException;
|
||||
sizes[i] = size;
|
||||
}
|
||||
va_end (args);
|
||||
|
||||
return _Jv_NewMultiArray (array_type, dimensions, sizes);
|
||||
return _Jv_NewMultiArrayUnchecked (array_type, dimensions, sizes);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user