unix/modjni: array(): Support creation of object arrays.

This commit is contained in:
Paul Sokolovsky 2016-09-18 13:37:40 +03:00
parent d08c9d342f
commit 5bf1b4e9d9

View File

@ -655,38 +655,46 @@ STATIC mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mod_jni_cls_obj, mod_jni_cls); MP_DEFINE_CONST_FUN_OBJ_1(mod_jni_cls_obj, mod_jni_cls);
STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) { STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) {
const char *type = mp_obj_str_get_str(type_in);
mp_int_t size = mp_obj_get_int(size_in);
if (!env) { if (!env) {
create_jvm(); create_jvm();
} }
mp_int_t size = mp_obj_get_int(size_in);
jobject res = NULL; jobject res = NULL;
switch (*type) {
case 'Z': if (MP_OBJ_IS_TYPE(type_in, &jclass_type)) {
res = JJ(NewBooleanArray, size);
break; mp_obj_jclass_t *jcls = type_in;
case 'B': res = JJ(NewObjectArray, size, jcls->cls, NULL);
res = JJ(NewByteArray, size);
break; } else if (MP_OBJ_IS_STR(type_in)) {
case 'C': const char *type = mp_obj_str_get_str(type_in);
res = JJ(NewCharArray, size); switch (*type) {
break; case 'Z':
case 'S': res = JJ(NewBooleanArray, size);
res = JJ(NewShortArray, size); break;
break; case 'B':
case 'I': res = JJ(NewByteArray, size);
res = JJ(NewIntArray, size); break;
break; case 'C':
case 'J': res = JJ(NewCharArray, size);
res = JJ(NewLongArray, size); break;
break; case 'S':
case 'F': res = JJ(NewShortArray, size);
res = JJ(NewFloatArray, size); break;
break; case 'I':
case 'D': res = JJ(NewIntArray, size);
res = JJ(NewDoubleArray, size); break;
break; case 'J':
res = JJ(NewLongArray, size);
break;
case 'F':
res = JJ(NewFloatArray, size);
break;
case 'D':
res = JJ(NewDoubleArray, size);
break;
}
} }
return new_jobject(res); return new_jobject(res);