Mercurial > octave-nkf
comparison libinterp/octave-value/ov-java.cc @ 20295:137f183b7dee stable
Fix conversion from string cell array into java's String[] (bug #45290)
* libinterp/octave-value/ov-java.cc: when unboxing an octave_value into a
java object, cell arrays were never handled because they were caught in
the block handling numeric arrays. This was a regression introduced by
cset 81fcf4aa9e03.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Mon, 15 Jun 2015 02:08:41 +0100 |
parents | 209ee4a730f6 |
children | 140ce5e857bf |
comparison
equal
deleted
inserted
replaced
20294:36b32c07c045 | 20295:137f183b7dee |
---|---|
1279 std::string s = val.string_value (); | 1279 std::string s = val.string_value (); |
1280 | 1280 |
1281 jobj = jni_env->NewStringUTF (s.c_str ()); | 1281 jobj = jni_env->NewStringUTF (s.c_str ()); |
1282 jcls = jni_env->GetObjectClass (jobj); | 1282 jcls = jni_env->GetObjectClass (jobj); |
1283 } | 1283 } |
1284 else if (val.is_cellstr ()) | |
1285 { | |
1286 const Array<std::string> str_arr = val.cellstr_value (); | |
1287 const octave_idx_type n = str_arr.numel (); | |
1288 jclass_ref scls (jni_env, jni_env->FindClass ("java/lang/String")); | |
1289 jobjectArray array = jni_env->NewObjectArray (n, scls, NULL); | |
1290 for (octave_idx_type i = 0; i < n; i++) | |
1291 { | |
1292 jstring_ref jstr (jni_env, jni_env->NewStringUTF (str_arr(i).c_str ())); | |
1293 jni_env->SetObjectArrayElement (array, i, jstr); | |
1294 } | |
1295 jobj = array; | |
1296 jcls = jni_env->GetObjectClass (jobj); | |
1297 } | |
1284 else if (val.numel () > 1 && val.dims ().is_vector ()) | 1298 else if (val.numel () > 1 && val.dims ().is_vector ()) |
1285 { | 1299 { |
1286 #define IF_UNBOX_PRIMITIVE_ARRAY(CHECK_TYPE, METHOD_TYPE, OCTAVE_TYPE, JAVA_TYPE, JAVA_TYPE_CAP) \ | 1300 #define IF_UNBOX_PRIMITIVE_ARRAY(CHECK_TYPE, METHOD_TYPE, OCTAVE_TYPE, JAVA_TYPE, JAVA_TYPE_CAP) \ |
1287 if (val.is_ ## CHECK_TYPE ## _type ()) \ | 1301 if (val.is_ ## CHECK_TYPE ## _type ()) \ |
1288 { \ | 1302 { \ |
1411 else | 1425 else |
1412 { | 1426 { |
1413 found = false; | 1427 found = false; |
1414 error ("cannot convert matrix of type '%s'", val.class_name ().c_str ()); | 1428 error ("cannot convert matrix of type '%s'", val.class_name ().c_str ()); |
1415 } | 1429 } |
1416 } | |
1417 else if (val.is_cellstr ()) | |
1418 { | |
1419 Cell cellStr = val.cell_value (); | |
1420 jclass_ref scls (jni_env, jni_env->FindClass ("java/lang/String")); | |
1421 jobjectArray array = jni_env->NewObjectArray (cellStr.length (), scls, 0); | |
1422 for (int i = 0; i < cellStr.length (); i++) | |
1423 { | |
1424 jstring_ref jstr (jni_env, | |
1425 jni_env->NewStringUTF (cellStr(i).string_value().c_str ())); | |
1426 jni_env->SetObjectArrayElement (array, i, jstr); | |
1427 } | |
1428 jobj = array; | |
1429 jcls = jni_env->GetObjectClass (jobj); | |
1430 } | 1430 } |
1431 else | 1431 else |
1432 { | 1432 { |
1433 jclass rcls = find_octave_class (jni_env, "org/octave/OctaveReference"); | 1433 jclass rcls = find_octave_class (jni_env, "org/octave/OctaveReference"); |
1434 jmethodID mID = jni_env->GetMethodID (rcls, "<init>", "(I)V"); | 1434 jmethodID mID = jni_env->GetMethodID (rcls, "<init>", "(I)V"); |
2500 %!testif HAVE_JAVA | 2500 %!testif HAVE_JAVA |
2501 %! assert (class (javaObject ("java.lang.Byte", uint8 (1))), "java.lang.Byte"); | 2501 %! assert (class (javaObject ("java.lang.Byte", uint8 (1))), "java.lang.Byte"); |
2502 %! assert (class (javaObject ("java.lang.Byte", int8 (1))), "java.lang.Byte"); | 2502 %! assert (class (javaObject ("java.lang.Byte", int8 (1))), "java.lang.Byte"); |
2503 %! assert (class (javaObject ("java.lang.Short", uint16 (1))), "java.lang.Short"); | 2503 %! assert (class (javaObject ("java.lang.Short", uint16 (1))), "java.lang.Short"); |
2504 %! assert (class (javaObject ("java.lang.Short", int16 (1))), "java.lang.Short"); | 2504 %! assert (class (javaObject ("java.lang.Short", int16 (1))), "java.lang.Short"); |
2505 | |
2506 ## Automatic conversion from string cell array into String[] (bug #45290) | |
2507 %!testif HAVE_JAVA | |
2508 %! assert (javaMethod ("binarySearch", "java.util.Arrays", {"aaa", "bbb", "ccc", "zzz"}, "aaa"), 0) | |
2509 %! assert (javaMethod ("binarySearch", "java.util.Arrays", {"aaa", "bbb", "ccc", "zzz"}, "zzz"), 3) | |
2510 %! assert (javaMethod ("binarySearch", "java.util.Arrays", {"aaa", "bbb", "ccc", "zzz"}, "hhh") < 0) | |
2505 */ | 2511 */ |