Commit 62a04081 by Tom Tromey Committed by Tom Tromey

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
parent 6cbd1b6f
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> 2001-10-01 Mark Wielaard <mark@klomp.org>
* java/io/FileWriter.java: Merge with Classpath. * java/io/FileWriter.java: Merge with Classpath.
......
...@@ -43,11 +43,12 @@ java::lang::reflect::Array::newInstance (jclass componentType, jint length) ...@@ -43,11 +43,12 @@ java::lang::reflect::Array::newInstance (jclass componentType, jint length)
} }
jobject jobject
java::lang::reflect::Array::newInstance (jclass componentType, jintArray dimensions) java::lang::reflect::Array::newInstance (jclass componentType,
jintArray dimensions)
{ {
jint ndims = dimensions->length; jint ndims = dimensions->length;
if (ndims == 0) if (ndims == 0)
return componentType->newInstance (); throw new java::lang::IllegalArgumentException ();
jint* dims = elements (dimensions); jint* dims = elements (dimensions);
if (ndims == 1) if (ndims == 1)
return newInstance (componentType, dims[0]); return newInstance (componentType, dims[0]);
......
...@@ -100,8 +100,8 @@ can_widen (jclass from, jclass to) ...@@ -100,8 +100,8 @@ can_widen (jclass from, jclass to)
// Boolean arguments may not be widened. // Boolean arguments may not be widened.
if (fromx == BOOLEAN && tox != BOOLEAN) if (fromx == BOOLEAN && tox != BOOLEAN)
return false; return false;
// Special-case short->char conversions. // Nothing promotes to char.
if (fromx == SHORT && tox == CHAR) if (tox == CHAR && fromx != CHAR)
return false; return false;
return fromx <= tox; return fromx <= tox;
......
...@@ -516,8 +516,10 @@ _Jv_NewArray (jint type, jint size) ...@@ -516,8 +516,10 @@ _Jv_NewArray (jint type, jint size)
return NULL; // Placate compiler. return NULL; // Placate compiler.
} }
jobject // Allocate a possibly multi-dimensional array but don't check that
_Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes) // any array length is <0.
static jobject
_Jv_NewMultiArrayUnchecked (jclass type, jint dimensions, jint *sizes)
{ {
JvAssert (type->isArray()); JvAssert (type->isArray());
jclass element_type = type->getComponentType(); jclass element_type = type->getComponentType();
...@@ -533,7 +535,7 @@ _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes) ...@@ -533,7 +535,7 @@ _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
JvAssert (element_type->isArray()); JvAssert (element_type->isArray());
jobject *contents = elements ((jobjectArray) result); jobject *contents = elements ((jobjectArray) result);
for (int i = 0; i < sizes[0]; ++i) for (int i = 0; i < sizes[0]; ++i)
contents[i] = _Jv_NewMultiArray (element_type, dimensions - 1, contents[i] = _Jv_NewMultiArrayUnchecked (element_type, dimensions - 1,
sizes + 1); sizes + 1);
} }
...@@ -541,6 +543,16 @@ _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes) ...@@ -541,6 +543,16 @@ _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
} }
jobject 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, ...) _Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
{ {
va_list args; va_list args;
...@@ -549,11 +561,13 @@ _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) for (int i = 0; i < dimensions; ++i)
{ {
jint size = va_arg (args, jint); jint size = va_arg (args, jint);
if (size < 0)
throw new java::lang::NegativeArraySizeException;
sizes[i] = size; sizes[i] = size;
} }
va_end (args); va_end (args);
return _Jv_NewMultiArray (array_type, dimensions, sizes); return _Jv_NewMultiArrayUnchecked (array_type, dimensions, sizes);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment