Fixes PR52.
[cacao.git] / src / vm / array.c
index b517b4e428b54309ffd2afaf49ddac94c7139a7f..30f231d3e720a8a60ae388a7dfb5abed406b3114 100644 (file)
@@ -304,30 +304,21 @@ void array_##name##array_element_set(java_handle_##name##array_t *a, int32_t ind
 
 void array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value)
 {
-       arraydescriptor *ad;
-       classinfo *cc;
-       int32_t    size;
+       int32_t size;
 
        if (a == NULL) {
                exceptions_throw_nullpointerexception();
                return;
        }
 
-       /* TODO Write inline functions for that and use LLNI. */
+       /* Sanity check. */
 
-       LLNI_CRITICAL_START;
+       assert(a->header.objheader.vftbl->arraydesc->arraytype == ARRAYTYPE_OBJECT);
 
-       ad = a->header.objheader.vftbl->arraydesc;
-       cc = ad->componentvftbl->class;
-
-       LLNI_CRITICAL_END;
-
-       if (ad->arraytype == ARRAYTYPE_OBJECT) {
-               if (value != NULL) {
-                       if (builtin_instanceof(value, cc) == false) {
-                               exceptions_throw_illegalargumentexception();
-                               return;
-                       }
+       if (value != NULL) {
+               if (builtin_canstore(a, value) == false) {
+                       exceptions_throw_illegalargumentexception();
+                       return;
                }
        }
 
@@ -361,8 +352,8 @@ ARRAY_TYPEARRAY_ELEMENT_SET(double,  double)
        a ... Java array
 
    RETURN VALUE:
-        0 ... exception thrown
-          >0 ... length of the Java array
+         -1 ... exception thrown
+          >0 ... length of the Java array
 
 *******************************************************************************/
 
@@ -373,7 +364,7 @@ int32_t array_length_get(java_handle_t *a)
 
        if (a == NULL) {
                exceptions_throw_nullpointerexception();
-               return 0;
+               return -1;
        }
 
        LLNI_class_get(a, c);
@@ -381,16 +372,11 @@ int32_t array_length_get(java_handle_t *a)
        if (!class_is_array(c)) {
 /*             exceptions_throw_illegalargumentexception("Argument is not an array"); */
                exceptions_throw_illegalargumentexception();
-               return 0;
+               return -1;
        }
 
        size = LLNI_array_size(a);
 
-       if ((size <= 0) || (size > /* MAX_DIM */ 255)) {
-               exceptions_throw_illegalargumentexception();
-               return 0;
-       }
-
        return size;
 }