summaryrefslogtreecommitdiffstats
path: root/java/src/jni
diff options
context:
space:
mode:
authorAllen Byrne <50328838+byrnHDF@users.noreply.github.com>2022-12-06 04:29:42 (GMT)
committerGitHub <noreply@github.com>2022-12-06 04:29:42 (GMT)
commit2376723d4a8999e5969c862a3ba8619951126cad (patch)
tree6f63238c5d47b4c6ea6900887cad432b8361e632 /java/src/jni
parent281984b3e3c0ca7ad92055852534577da34777e8 (diff)
downloadhdf5-2376723d4a8999e5969c862a3ba8619951126cad.zip
hdf5-2376723d4a8999e5969c862a3ba8619951126cad.tar.gz
hdf5-2376723d4a8999e5969c862a3ba8619951126cad.tar.bz2
Develop jni trans (#2266)
* Add compound and refactor out atomic types * Add Array String tests back * Convert Attribute version of compound example * Update transfer atom8ic read to return object
Diffstat (limited to 'java/src/jni')
-rw-r--r--java/src/jni/h5aImp.c20
-rw-r--r--java/src/jni/h5dImp.c30
-rw-r--r--java/src/jni/h5util.c901
-rw-r--r--java/src/jni/h5util.h8
4 files changed, 676 insertions, 283 deletions
diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c
index 71caf76..07ecdb8 100644
--- a/java/src/jni/h5aImp.c
+++ b/java/src/jni/h5aImp.c
@@ -1115,7 +1115,8 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
H5T_class_t type_class;
jsize vl_array_len;
htri_t vl_data_class;
- herr_t status = FAIL;
+ herr_t status = FAIL;
+ htri_t is_variable = 0;
UNUSED(clss);
@@ -1124,10 +1125,11 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem
if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
-
/* Get size of data array */
if ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0)
H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0");
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
@@ -1154,7 +1156,10 @@ done:
if (sid >= 0)
H5Sclose(sid);
}
-
+ if (is_variable) {
+ for (size_t i = 0; i < (size_t)vl_array_len; i++)
+ HDfree(((char **)readBuf)[i]);
+ }
HDfree(readBuf);
}
@@ -1177,7 +1182,8 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
H5T_class_t type_class;
jsize vl_array_len;
htri_t vl_data_class;
- herr_t status = FAIL;
+ herr_t status = FAIL;
+ htri_t is_variable = 0;
UNUSED(clss);
@@ -1192,6 +1198,8 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: write buffer length < 0");
}
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
@@ -1216,6 +1224,10 @@ done:
H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf);
}
+ if (is_variable) {
+ for (size_t i = 0; i < (size_t)vl_array_len; i++)
+ HDfree(((char **)writeBuf)[i]);
+ }
HDfree(writeBuf);
}
diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c
index 56c5cc8..efddb96 100644
--- a/java/src/jni/h5dImp.c
+++ b/java/src/jni/h5dImp.c
@@ -1140,26 +1140,29 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
H5T_class_t type_class;
jsize vl_array_len;
htri_t vl_data_class;
- herr_t status = FAIL;
+ herr_t status = FAIL;
+ htri_t is_variable = 0;
UNUSED(clss);
if (NULL == buf)
- H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread: read buffer is NULL");
+ H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: read buffer is NULL");
if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
/* Get size of data array */
if ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0");
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: readBuf length < 0");
}
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
if (NULL == (readBuf = HDcalloc((size_t)vl_array_len, typeSize)))
- H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Dread: failed to allocate raw VL read buffer");
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5DreadVL: failed to allocate raw VL read buffer");
if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, (hid_t)file_space_id,
(hid_t)xfer_plist_id, (void *)readBuf)) < 0)
@@ -1173,6 +1176,10 @@ done:
if (readBuf) {
if ((status >= 0) && vl_data_class)
H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf);
+ if (is_variable) {
+ for (size_t i = 0; i < (size_t)vl_array_len; i++)
+ HDfree(((char **)readBuf)[i]);
+ }
HDfree(readBuf);
}
@@ -1194,12 +1201,13 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
H5T_class_t type_class;
jsize vl_array_len; // Only used by vl_data_class types
htri_t vl_data_class;
- herr_t status = FAIL;
+ herr_t status = FAIL;
+ htri_t is_variable = 0;
UNUSED(clss);
if (NULL == buf)
- H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: write buffer is NULL");
+ H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: write buffer is NULL");
if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
@@ -1207,14 +1215,16 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong
/* Get size of data array */
if ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: write buffer length < 0");
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: write buffer length < 0");
}
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
if (NULL == (writeBuf = HDcalloc((size_t)vl_array_len, typeSize)))
- H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5Dwrite: failed to allocate raw VL write buffer");
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5DwriteVL: failed to allocate raw VL write buffer");
if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
@@ -1229,6 +1239,10 @@ done:
if (writeBuf) {
if ((status >= 0) && vl_data_class)
H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf);
+ if (is_variable) {
+ for (size_t i = 0; i < (size_t)vl_array_len; i++)
+ HDfree(((char **)writeBuf)[i]);
+ }
HDfree(writeBuf);
}
diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c
index 4e62085..77fb244 100644
--- a/java/src/jni/h5util.c
+++ b/java/src/jni/h5util.c
@@ -77,6 +77,10 @@ static int render_bin_output_region_data_points(FILE *stream, hid_t region_sp
hsize_t *ptdata);
static int render_bin_output_region_points(FILE *stream, hid_t region_space, hid_t region_id,
hid_t container);
+jobject translate_atomic_rbuf(JNIEnv *env, jobject ret_buf, jlong mem_type_id, H5T_class_t type_class,
+ void *raw_buf);
+void translate_atomic_wbuf(JNIEnv *env, jobject in_obj, jlong mem_type_id, H5T_class_t type_class,
+ void *raw_buf);
/* Strings for output */
#define H5_TOOLS_GROUP "GROUP"
@@ -4040,16 +4044,20 @@ done:
H5Aclose(attr_id);
} /* end Java_hdf_hdf5lib_H5_H5export_1attribute */
-herr_t
-translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class, jsize count,
- jbyte *raw_buf)
+jobject
+translate_atomic_rbuf(JNIEnv *env, jobject ret_buf, jlong mem_type_id, H5T_class_t type_class, void *raw_buf)
{
- herr_t status = FAIL;
- hid_t memb = H5I_INVALID_HID;
- H5T_class_t vlClass;
- size_t vlSize;
- size_t i, x;
- size_t typeSize;
+ jobject jobj = NULL;
+ hid_t memb = H5I_INVALID_HID;
+ int ret_buflen = -1;
+ jboolean found_jList = JNI_TRUE;
+ jobjectArray jList = NULL;
+ H5T_class_t vlClass;
+ size_t vlSize;
+ size_t i, x;
+ size_t typeSize;
+ // raw_buf is normally bytes except when used for variable length strings
+ char *char_buf = (char *)raw_buf;
/* retrieve the java.util.ArrayList interface class */
jclass arrCList = ENVPTR->FindClass(ENVONLY, "java/util/ArrayList");
@@ -4079,6 +4087,485 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
+ ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf);
+ switch (type_class) {
+ case H5T_VLEN: {
+ if (!(memb = H5Tget_super(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ /* Convert element to a list */
+ hvl_t vl_elem;
+
+ found_jList = JNI_TRUE;
+ jList = NULL;
+
+ /* Get the number of sequence elements */
+ HDmemcpy(&vl_elem, char_buf, sizeof(hvl_t));
+ jsize nelmts = (jsize)vl_elem.len;
+ if (vl_elem.len != (size_t)nelmts)
+ H5_JNI_FATAL_ERROR(ENVONLY, "translate_atomic_rbuf: overflow of number of VL elements");
+
+ if (nelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_atomic_rbuf: number of VL elements < 0");
+
+ /* The list we're going to return: */
+ if (NULL == (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate list read buffer");
+
+ translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)nelmts, vl_elem.p);
+ jobj = jList;
+ break;
+ } /* H5T_VLEN */
+ case H5T_COMPOUND: {
+ int nmembs = H5Tget_nmembers(mem_type_id);
+ void *objBuf = NULL;
+
+ /* The list we're going to return: */
+ if (NULL == (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate list read buffer");
+
+ /* Convert each element to a compound object */
+ for (i = 0; i < (size_t)nmembs; i++) {
+ H5T_class_t memb_vlClass;
+ size_t memb_vlSize;
+ size_t memb_offset;
+
+ if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)i)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_offset = H5Tget_member_offset(mem_type_id, (unsigned int)i)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(memb_vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ translate_atomic_rbuf(ENVONLY, jList, memb, memb_vlClass,
+ char_buf + i * typeSize + memb_offset);
+ H5Tclose(memb);
+ }
+ jobj = jList;
+ break;
+ } /* H5T_COMPOUND */
+ case H5T_ARRAY: {
+ void *objBuf = NULL;
+ size_t typeCount;
+
+ if (!(memb = H5Tget_super(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(typeSize = H5Tget_size(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ typeCount = typeSize / vlSize;
+
+ if (NULL == (objBuf = HDmalloc(typeSize)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate buffer");
+
+ /* Convert each element */
+ /* Get the object element */
+ HDmemcpy((char *)objBuf, char_buf, typeSize);
+
+ /* The list we're going to return: */
+ if (NULL == (jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: failed to allocate list read buffer");
+
+ translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)typeCount, objBuf);
+ jobj = jList;
+
+ if (objBuf)
+ HDfree(objBuf);
+
+ break;
+ } /* H5T_ARRAY */
+ case H5T_ENUM:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_INTEGER: {
+ /* Convert each element */
+ switch (typeSize) {
+ case sizeof(jbyte): {
+ jbyte byteValue;
+ HDmemcpy(((char *)&byteValue), char_buf, typeSize);
+
+ if (NULL ==
+ (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid, byteValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jshort): {
+ jshort shortValue;
+ HDmemcpy(((char *)&shortValue), char_buf, typeSize);
+
+ if (NULL ==
+ (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid, shortValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jint): {
+ jint intValue;
+
+ HDmemcpy(((char *)&intValue), char_buf, typeSize);
+
+ if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jlong): {
+ jlong longValue;
+ HDmemcpy(((char *)&longValue), char_buf, typeSize);
+
+ if (NULL ==
+ (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid, longValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ }
+ break;
+ } /* H5T_INTEGER */
+ case H5T_FLOAT: {
+ /* Convert each element to a list */
+ switch (typeSize) {
+ case sizeof(jfloat): {
+ jfloat floatValue;
+ HDmemcpy(((char *)&floatValue), char_buf, typeSize);
+
+ if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
+ (double)floatValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ case sizeof(jdouble): {
+ jdouble doubleValue;
+ HDmemcpy(((char *)&doubleValue), char_buf, typeSize);
+
+ if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid,
+ doubleValue)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ break;
+ }
+ }
+ break;
+ } /* H5T_FLOAT */
+ case H5T_REFERENCE: {
+ /* Convert each element to a list */
+ jboolean bb;
+ jbyte *barray = NULL;
+
+ jsize byteArraySize = (jsize)typeSize;
+ if (typeSize != (size_t)byteArraySize)
+ H5_JNI_FATAL_ERROR(ENVONLY, "translate_atomic_rbuf: overflow of byteArraySize");
+
+ if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, byteArraySize)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ PIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, &bb,
+ "translate_atomic_rbuf reference: byte array not pinned");
+
+ HDmemcpy(barray, ((jbyte *)raw_buf), typeSize);
+ if (barray)
+ UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT);
+
+ break;
+ } /* H5T_REFERENCE */
+ case H5T_STRING: {
+ htri_t is_variable = 0;
+
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ /* Convert each element */
+ if (is_variable) {
+ char **var_str_buf = (char **)raw_buf;
+ if (NULL == (jobj = ENVPTR->NewStringUTF(ENVONLY, *var_str_buf))) {
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: out of memory - unable to "
+ "construct string from UTF characters");
+ }
+ }
+ else {
+ if (NULL == (jobj = ENVPTR->NewStringUTF(ENVONLY, char_buf))) {
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_rbuf: out of memory - unable to "
+ "construct string from UTF characters");
+ }
+ }
+
+ break;
+ } /* H5T_STRING */
+ default:
+ H5_UNIMPLEMENTED(ENVONLY, "translate_atomic_rbuf: invalid class type");
+ break;
+ } /* switch(type_class) */
+
+done:
+
+ return jobj;
+}
+
+void
+translate_atomic_wbuf(JNIEnv *env, jobject in_obj, jlong mem_type_id, H5T_class_t type_class, void *raw_buf)
+{
+ hid_t memb = H5I_INVALID_HID;
+ H5T_class_t vlClass;
+ size_t vlSize;
+ size_t i, x;
+ size_t typeSize;
+ // raw_buf is normally bytes except when used for variable length strings
+ char *char_buf = (char *)raw_buf;
+
+ /* retrieve the java.util.ArrayList interface class */
+ jclass arrCList = ENVPTR->FindClass(ENVONLY, "java/util/ArrayList");
+ /* retrieve the toArray method */
+ jmethodID mToArray = ENVPTR->GetMethodID(ENVONLY, arrCList, "toArray", "()[Ljava/lang/Object;");
+
+ /* Cache class types */
+ jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
+ jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
+ jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
+ jclass cLong = ENVPTR->FindClass(ENVONLY, "java/lang/Long");
+ jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
+ jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
+
+ jmethodID byteValueMid = ENVPTR->GetMethodID(ENVONLY, cByte, "byteValue", "()B");
+ jmethodID shortValueMid = ENVPTR->GetMethodID(ENVONLY, cShort, "shortValue", "()S");
+ jmethodID intValueMid = ENVPTR->GetMethodID(ENVONLY, cInt, "intValue", "()I");
+ jmethodID longValueMid = ENVPTR->GetMethodID(ENVONLY, cLong, "longValue", "()J");
+ jmethodID floatValueMid = ENVPTR->GetMethodID(ENVONLY, cFloat, "floatValue", "()F");
+ jmethodID doubleValueMid = ENVPTR->GetMethodID(ENVONLY, cDouble, "doubleValue", "()D");
+
+ if (!(typeSize = H5Tget_size(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ switch (type_class) {
+ case H5T_VLEN: {
+ if (!(memb = H5Tget_super(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((vlClass = H5Tget_class((hid_t)memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ /* Convert element to a vlen element */
+ hvl_t vl_elem;
+
+ jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, in_obj);
+
+ if (jnelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_atomic_wbuf: number of VL elements < 0");
+
+ vl_elem.len = (size_t)jnelmts;
+
+ if (NULL == (vl_elem.p = HDmalloc((size_t)jnelmts * vlSize)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_wbuf: failed to allocate vlen ptr buffer");
+
+ translate_wbuf(ENVONLY, (jobjectArray)in_obj, memb, vlClass, (jsize)jnelmts, vl_elem.p);
+
+ HDmemcpy(char_buf, &vl_elem, sizeof(hvl_t));
+ break;
+ } /* H5T_VLEN */
+ case H5T_COMPOUND: {
+ void *objBuf = NULL;
+
+ /* Convert each compound element */
+ int nmembs = H5Tget_nmembers(mem_type_id);
+
+ /* invoke the toArray method */
+ if (mToArray == NULL)
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, in_obj, mToArray);
+ jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
+
+ if (jnelmts != nmembs)
+ H5_BAD_ARGUMENT_ERROR(
+ ENVONLY, "translate_atomic_wbuf: number of elements not equal to number of members");
+
+ /* Convert each compound object to an element */
+ for (i = 0; i < (size_t)nmembs; i++) {
+ H5T_class_t memb_vlClass;
+ size_t memb_vlSize;
+ size_t memb_offset;
+
+ if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)i)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_offset = H5Tget_member_offset(mem_type_id, (unsigned int)i)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(memb_vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ jobject arr_obj = ENVPTR->GetObjectArrayElement(ENVONLY, array, i);
+ translate_atomic_wbuf(ENVONLY, arr_obj, memb, memb_vlClass,
+ char_buf + i * typeSize + memb_offset);
+ ENVPTR->DeleteLocalRef(ENVONLY, arr_obj);
+ H5Tclose(memb);
+ }
+ break;
+ } /* H5T_COMPOUND */
+ case H5T_ARRAY: {
+ void *objBuf = NULL;
+
+ if (!(memb = H5Tget_super(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ /* Convert each array element */
+ /* invoke the toArray method */
+ if (mToArray == NULL)
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, in_obj, mToArray);
+ jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
+
+ if (jnelmts < 0)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_atomic_wbuf: number of array elements < 0");
+
+ if (NULL == (objBuf = HDmalloc((size_t)jnelmts * vlSize)))
+ H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_atomic_wbuf: failed to allocate buffer");
+
+ translate_wbuf(ENVONLY, array, memb, vlClass, (jsize)jnelmts, objBuf);
+
+ HDmemcpy(char_buf, (char *)objBuf, vlSize * jnelmts);
+ break;
+ } /* H5T_ARRAY */
+ case H5T_ENUM:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_INTEGER: {
+ /* Convert each element */
+ switch (typeSize) {
+ case sizeof(jbyte): {
+ jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, in_obj, byteValueMid);
+ HDmemcpy(char_buf, ((char *)&byteValue), typeSize);
+ }
+ case sizeof(jshort): {
+ jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, in_obj, shortValueMid);
+ HDmemcpy(char_buf, ((char *)&shortValue), typeSize);
+ break;
+ }
+ case sizeof(jint): {
+ jint intValue = ENVPTR->CallIntMethod(ENVONLY, in_obj, intValueMid);
+ HDmemcpy(char_buf, ((char *)&intValue), typeSize);
+ break;
+ }
+ case sizeof(jlong): {
+ jlong longValue = ENVPTR->CallLongMethod(ENVONLY, in_obj, longValueMid);
+ HDmemcpy(char_buf, ((char *)&longValue), typeSize);
+ break;
+ }
+ }
+ break;
+ } /* H5T_INTEGER */
+ case H5T_FLOAT: {
+ /* Convert each element */
+ switch (typeSize) {
+ case sizeof(jfloat): {
+ jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, in_obj, floatValueMid);
+ HDmemcpy(char_buf, ((char *)&floatValue), typeSize);
+ break;
+ }
+ case sizeof(jdouble): {
+ jdouble doubleValue = ENVPTR->CallDoubleMethod(ENVONLY, in_obj, doubleValueMid);
+ HDmemcpy(char_buf, ((char *)&doubleValue), typeSize);
+ break;
+ }
+ }
+ break;
+ } /* H5T_FLOAT */
+ case H5T_REFERENCE: {
+ /* Convert each array element */
+ jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, in_obj, 0);
+ HDmemcpy(char_buf, ((char *)barray), typeSize);
+ ENVPTR->ReleaseByteArrayElements(ENVONLY, in_obj, barray, 0);
+ break;
+ } /* H5T_REFERENCE */
+ case H5T_STRING: {
+ htri_t is_variable = 0;
+
+ if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ /* Convert each pointer element */
+ jsize length;
+ const char *utf8 = NULL;
+
+ HDmemset(char_buf, 0, typeSize);
+ if (NULL != in_obj) {
+ PIN_JAVA_STRING(ENVONLY, in_obj, utf8, NULL, "translate_atomic_wbuf jobj not pinned");
+ length = ENVPTR->GetStringUTFLength(ENVONLY, in_obj);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ if (is_variable) {
+ char *new_buf = (char *)HDcalloc((size_t)1, length + 1);
+ HDmemcpy(((char *)new_buf), utf8, length);
+ HDmemcpy(char_buf, &new_buf, typeSize);
+ }
+ else {
+ HDmemcpy(char_buf, utf8, length);
+ }
+ UNPIN_JAVA_STRING(ENVONLY, in_obj, utf8);
+ utf8 = NULL;
+ }
+ break;
+ } /* H5T_STRING */
+ default:
+ H5_UNIMPLEMENTED(ENVONLY, "translate_atomic_wbuf: invalid class type");
+ break;
+ } /* switch(type_class) */
+
+done:
+
+ return;
+}
+
+void
+translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class, jsize count,
+ void *raw_buf)
+{
+ hid_t memb = H5I_INVALID_HID;
+ int ret_buflen = -1;
+ jboolean found_jList = JNI_TRUE;
+ jobjectArray jList = NULL;
+ jobject jobj = NULL;
+ H5T_class_t vlClass;
+ size_t vlSize;
+ size_t i, x;
+ size_t typeSize;
+ // raw_buf is normally bytes except when used for variable length strings
+ char *char_buf = (char *)raw_buf;
+
+ /* retrieve the java.util.ArrayList interface class */
+ jclass arrCList = ENVPTR->FindClass(ENVONLY, "java/util/ArrayList");
+ jmethodID arrListMethod = ENVPTR->GetMethodID(ENVONLY, arrCList, "<init>", "(I)V");
+ jmethodID arrAddMethod = ENVPTR->GetMethodID(ENVONLY, arrCList, "add", "(Ljava/lang/Object;)Z");
+
+ /* Cache class types */
+ jclass cByte = ENVPTR->FindClass(ENVONLY, "java/lang/Byte");
+ jclass cShort = ENVPTR->FindClass(ENVONLY, "java/lang/Short");
+ jclass cInt = ENVPTR->FindClass(ENVONLY, "java/lang/Integer");
+ jclass cLong = ENVPTR->FindClass(ENVONLY, "java/lang/Long");
+ jclass cFloat = ENVPTR->FindClass(ENVONLY, "java/lang/Float");
+ jclass cDouble = ENVPTR->FindClass(ENVONLY, "java/lang/Double");
+ jmethodID byteValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cByte, "valueOf", "(B)Ljava/lang/Byte;");
+ jmethodID shortValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cShort, "valueOf", "(S)Ljava/lang/Short;");
+ jmethodID intValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cInt, "valueOf", "(I)Ljava/lang/Integer;");
+ jmethodID longValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cLong, "valueOf", "(J)Ljava/lang/Long;");
+ jmethodID floatValueMid = ENVPTR->GetStaticMethodID(ENVONLY, cFloat, "valueOf", "(F)Ljava/lang/Float;");
+ jmethodID doubleValueMid =
+ ENVPTR->GetStaticMethodID(ENVONLY, cDouble, "valueOf", "(D)Ljava/lang/Double;");
+
+ if (!(typeSize = H5Tget_size(mem_type_id)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf);
switch (type_class) {
case H5T_VLEN: {
if (!(memb = H5Tget_super(mem_type_id)))
@@ -4090,13 +4577,13 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
/* Convert each element to a list */
for (i = 0; i < (size_t)count; i++) {
- hvl_t vl_elem;
- jboolean found_jList = JNI_TRUE;
- int ret_buflen = -1;
- jobjectArray jList = NULL;
+ hvl_t vl_elem;
+
+ found_jList = JNI_TRUE;
+ jList = NULL;
/* Get the number of sequence elements */
- HDmemcpy(&vl_elem, (char *)raw_buf + i * sizeof(hvl_t), sizeof(hvl_t));
+ HDmemcpy(&vl_elem, char_buf + i * sizeof(hvl_t), sizeof(hvl_t));
jsize nelmts = (jsize)vl_elem.len;
if (vl_elem.len != (size_t)nelmts)
H5_JNI_FATAL_ERROR(ENVONLY, "translate_rbuf: overflow of number of VL elements");
@@ -4104,7 +4591,6 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
if (nelmts < 0)
H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_rbuf: number of VL elements < 0");
- ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf);
/* The list we're going to return: */
if (i < ret_buflen) {
jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)ret_buf, (jsize)i);
@@ -4125,64 +4611,70 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
if (!addResult)
H5_JNI_FATAL_ERROR(ENVONLY, "translate_rbuf: cannot add VL element");
}
+ else {
+ ENVPTR->SetObjectArrayElement(ENVONLY, ret_buf, i, (jobject)jList);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ }
ENVPTR->DeleteLocalRef(ENVONLY, jList);
}
break;
} /* H5T_VLEN */
case H5T_COMPOUND: {
- int nmembs = H5Tget_nmembers(mem_type_id);
- void *objBuf = NULL;
- size_t offset;
-
- if (!(memb = H5Tget_super(mem_type_id)))
- H5_LIBRARY_ERROR(ENVONLY);
- if ((vlClass = H5Tget_class(memb)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- if (!(vlSize = H5Tget_size(memb)))
- H5_LIBRARY_ERROR(ENVONLY);
-
- if (nmembs < 0)
- goto done;
-
- /* Convert each element to a list */
- for (i = 0; i < (size_t)nmembs; i++) {
- jboolean found_jList = JNI_TRUE;
- jobjectArray jList = NULL;
- int ret_buflen = -1;
-
- if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)i)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- offset = H5Tget_member_offset(mem_type_id, (unsigned int)i);
-
- if ((vlClass = H5Tget_class(memb)) < 0)
- H5_LIBRARY_ERROR(ENVONLY);
- if (!(vlSize = H5Tget_size(memb)))
- H5_LIBRARY_ERROR(ENVONLY);
+ void *objBuf = NULL;
- /* Get the object element */
- HDmemcpy(&objBuf, (char *)raw_buf + offset, vlSize);
+ /* Convert each compound element to a list */
+ for (i = 0; i < (size_t)count; i++) {
+ found_jList = JNI_TRUE;
+ jList = NULL;
- ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf);
/* The list we're going to return: */
if (i < ret_buflen) {
- if (NULL ==
- (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)ret_buf, (jsize)i)))
- found_jList = JNI_FALSE;
+ jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)ret_buf, (jsize)i);
}
if (NULL == jList) {
+ found_jList = JNI_FALSE;
if (NULL ==
(jList = (jobjectArray)ENVPTR->NewObject(ENVONLY, arrCList, arrListMethod, 0)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY,
"translate_rbuf: failed to allocate list read buffer");
}
+ int nmembs = H5Tget_nmembers(mem_type_id);
+ /* Convert each element to a list */
+ for (x = 0; x < (size_t)nmembs; x++) {
+ H5T_class_t memb_vlClass;
+ size_t memb_vlSize;
+ size_t memb_offset;
+
+ if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)x)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_offset = H5Tget_member_offset(mem_type_id, (unsigned int)x)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
- translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)1, objBuf);
- if (!found_jList) {
- ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jList);
- ENVPTR->DeleteLocalRef(ENVONLY, jList);
+ if ((memb_vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(memb_vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ jobj = translate_atomic_rbuf(ENVONLY, jList, memb, memb_vlClass,
+ char_buf + i * typeSize + memb_offset);
+ if (jobj) {
+ if (found_jList == JNI_FALSE)
+ ENVPTR->CallBooleanMethod(ENVONLY, jList, arrAddMethod, (jobject)jobj);
+ else
+ ENVPTR->SetObjectArrayElement(ENVONLY, jList, i, (jobject)jobj);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ ENVPTR->DeleteLocalRef(ENVONLY, jobj);
+ }
+
+ H5Tclose(memb);
}
+ if (ret_buflen == 0)
+ ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jList);
+ else
+ ENVPTR->SetObjectArrayElement(ENVONLY, ret_buf, i, jList);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ ENVPTR->DeleteLocalRef(ENVONLY, jList);
}
- H5Tclose(memb);
break;
} /* H5T_COMPOUND */
case H5T_ARRAY: {
@@ -4195,7 +4687,6 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
H5_LIBRARY_ERROR(ENVONLY);
if (!(vlSize = H5Tget_size(memb)))
H5_LIBRARY_ERROR(ENVONLY);
-
if (!(typeSize = H5Tget_size(mem_type_id)))
H5_LIBRARY_ERROR(ENVONLY);
@@ -4206,14 +4697,12 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
/* Convert each element to a list */
for (i = 0; i < (size_t)count; i++) {
- jboolean found_jList = JNI_TRUE;
- jobjectArray jList = NULL;
- int ret_buflen = -1;
+ found_jList = JNI_TRUE;
+ jList = NULL;
/* Get the object element */
- HDmemcpy((char *)objBuf, (char *)raw_buf + i * typeSize, typeSize);
+ HDmemcpy((char *)objBuf, char_buf + i * typeSize, typeSize);
- ret_buflen = ENVPTR->GetArrayLength(ENVONLY, ret_buf);
/* The list we're going to return: */
if (i < ret_buflen) {
if (NULL ==
@@ -4228,10 +4717,12 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
}
translate_rbuf(ENVONLY, jList, memb, vlClass, (jsize)typeCount, objBuf);
- if (!found_jList) {
+ if (found_jList == JNI_FALSE)
ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jList);
- ENVPTR->DeleteLocalRef(ENVONLY, jList);
- }
+ else
+ ENVPTR->SetObjectArrayElement(ENVONLY, ret_buf, i, jList);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ ENVPTR->DeleteLocalRef(ENVONLY, jList);
}
if (objBuf)
@@ -4239,130 +4730,28 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
break;
} /* H5T_ARRAY */
- case H5T_INTEGER: {
- /* Convert each element to a list */
- for (i = 0; i < (size_t)count; i++) {
- jobject jobj = NULL;
- switch (typeSize) {
- case sizeof(jbyte): {
- jbyte byteValue;
- for (x = 0; x < typeSize; x++) {
- ((char *)&byteValue)[x] = ((char *)raw_buf)[i * typeSize + x];
- }
-
- if (NULL ==
- (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid, byteValue)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jshort): {
- jshort shortValue;
- for (x = 0; x < typeSize; x++) {
- ((char *)&shortValue)[x] = ((char *)raw_buf)[i * typeSize + x];
- }
-
- if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid,
- shortValue)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jint): {
- jint intValue;
- for (x = 0; x < typeSize; x++) {
- ((char *)&intValue)[x] = ((char *)raw_buf)[i * typeSize + x];
- }
-
- if (NULL ==
- (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jlong): {
- jlong longValue;
- for (x = 0; x < typeSize; x++) {
- ((char *)&longValue)[x] = ((char *)raw_buf)[i * typeSize + x];
- }
-
- if (NULL ==
- (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid, longValue)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- }
- if (jobj) {
- ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jobj);
- ENVPTR->DeleteLocalRef(ENVONLY, jobj);
- }
- else {
- }
- }
- break;
- } /* H5T_INTEGER */
- case H5T_FLOAT: {
- /* Convert each element to a list */
- for (i = 0; i < (size_t)count; i++) {
- jobject jobj = NULL;
- switch (typeSize) {
- case sizeof(jfloat): {
- jfloat floatValue;
- for (x = 0; x < typeSize; x++) {
- ((char *)&floatValue)[x] = ((char *)raw_buf)[i * typeSize + x];
- }
-
- if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid,
- (double)floatValue)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- case sizeof(jdouble): {
- jdouble doubleValue;
- for (x = 0; x < typeSize; x++) {
- ((char *)&doubleValue)[x] = ((char *)raw_buf)[i * typeSize + x];
- }
-
- if (NULL == (jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid,
- doubleValue)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- break;
- }
- }
- if (jobj) {
- ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jobj);
- ENVPTR->DeleteLocalRef(ENVONLY, jobj);
- }
- }
- break;
- } /* H5T_FLOAT */
- case H5T_REFERENCE: {
+ case H5T_ENUM:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_REFERENCE:
+ case H5T_STRING: {
/* Convert each element to a list */
for (i = 0; i < (size_t)count; i++) {
- jboolean bb;
- jbyte *barray = NULL;
- jobject jobj = NULL;
-
- jsize byteArraySize = (jsize)typeSize;
- if (typeSize != (size_t)byteArraySize)
- H5_JNI_FATAL_ERROR(ENVONLY, "translate_rbuf: overflow of byteArraySize");
-
- if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, byteArraySize)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
-
- PIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, &bb,
- "translate_rbuf reference: byte array not pinned");
-
- for (x = 0; x < typeSize; x++) {
- barray[x] = ((jbyte *)raw_buf)[i * typeSize + x];
- }
- if (barray)
- UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT);
-
+ jobj =
+ translate_atomic_rbuf(ENVONLY, ret_buf, mem_type_id, type_class, char_buf + i * typeSize);
if (jobj) {
- ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, jobj);
+ if (ret_buflen == 0)
+ ENVPTR->CallBooleanMethod(ENVONLY, ret_buf, arrAddMethod, (jobject)jobj);
+ else
+ ENVPTR->SetObjectArrayElement(ENVONLY, ret_buf, i, (jobject)jobj);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
ENVPTR->DeleteLocalRef(ENVONLY, jobj);
}
}
break;
- } /* H5T_REFERENCE */
+ }
default:
H5_UNIMPLEMENTED(ENVONLY, "translate_rbuf: invalid class type");
break;
@@ -4370,21 +4759,22 @@ translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t
done:
- return (jint)status;
+ return;
}
-herr_t
+void
translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t type_class, jsize count,
- jbyte *raw_buf)
+ void *raw_buf)
{
- herr_t status = FAIL;
- hid_t memb = H5I_INVALID_HID;
- jobjectArray jList = NULL;
- jobject jobj = NULL;
+ hid_t memb = H5I_INVALID_HID;
+ jobjectArray jList = NULL;
+ jobject jobj = NULL;
H5T_class_t vlClass;
size_t vlSize;
size_t i, x;
size_t typeSize;
+ // raw_buf is normally bytes except when used for variable length strings
+ char *char_buf = (char *)raw_buf;
/* retrieve the java.util.ArrayList interface class */
jclass arrCList = ENVPTR->FindClass(ENVONLY, "java/util/ArrayList");
@@ -4441,16 +4831,59 @@ translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t
if (NULL == (vl_elem.p = HDmalloc((size_t)jnelmts * vlSize)))
H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_wbuf: failed to allocate vlen ptr buffer");
- translate_wbuf(ENVONLY, (jobjectArray)array, memb, vlClass, (jsize)jnelmts, vl_elem.p);
+ translate_wbuf(ENVONLY, array, memb, vlClass, (jsize)jnelmts, vl_elem.p);
- HDmemcpy((char *)raw_buf + i * sizeof(hvl_t), &vl_elem, sizeof(hvl_t));
+ HDmemcpy(char_buf + i * sizeof(hvl_t), &vl_elem, sizeof(hvl_t));
ENVPTR->DeleteLocalRef(ENVONLY, jList);
} /* end for (i = 0; i < count; i++) */
break;
} /* H5T_VLEN */
case H5T_COMPOUND: {
- H5_UNIMPLEMENTED(ENVONLY, "translate_wbuf: invalid H5T_COMPOUND type");
+ void *objBuf = NULL;
+
+ /* Convert each list to a compound element */
+ for (i = 0; i < (size_t)count; i++) {
+ if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ int nmembs = H5Tget_nmembers(mem_type_id);
+
+ /* invoke the toArray method */
+ if (mToArray == NULL)
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+ jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, jList, mToArray);
+ jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array);
+
+ if (jnelmts != nmembs)
+ H5_BAD_ARGUMENT_ERROR(
+ ENVONLY, "translate_wbuf: number of elements not equal to number of members");
+
+ /* Convert each compound object to an element */
+ for (x = 0; x < (size_t)nmembs; x++) {
+ H5T_class_t memb_vlClass;
+ size_t memb_vlSize;
+ size_t memb_offset;
+
+ if ((memb = H5Tget_member_type(mem_type_id, (unsigned int)x)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if ((memb_offset = H5Tget_member_offset(mem_type_id, (unsigned int)x)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if ((memb_vlClass = H5Tget_class(memb)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+ if (!(memb_vlSize = H5Tget_size(memb)))
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ jobject arr_obj = ENVPTR->GetObjectArrayElement(ENVONLY, array, x);
+ translate_atomic_wbuf(ENVONLY, arr_obj, memb, memb_vlClass,
+ char_buf + i * typeSize + memb_offset);
+ ENVPTR->DeleteLocalRef(ENVONLY, arr_obj);
+ H5Tclose(memb);
+ }
+
+ ENVPTR->DeleteLocalRef(ENVONLY, jList);
+ } /* end for (i = 0; i < count; i++) */
break;
} /* H5T_COMPOUND */
case H5T_ARRAY: {
@@ -4477,91 +4910,25 @@ translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t
if (jnelmts < 0)
H5_BAD_ARGUMENT_ERROR(ENVONLY, "translate_wbuf: number of array elements < 0");
- if (NULL == (objBuf = HDmalloc((size_t)jnelmts * vlSize)))
- H5_OUT_OF_MEMORY_ERROR(ENVONLY, "translate_wbuf: failed to allocate buffer");
-
- translate_wbuf(ENVONLY, (jobjectArray)array, memb, vlClass, (jsize)jnelmts, objBuf);
-
- HDmemcpy((char *)raw_buf + i * vlSize * jnelmts, (char *)objBuf, vlSize * jnelmts);
+ translate_wbuf(ENVONLY, array, memb, vlClass, (jsize)jnelmts,
+ char_buf + i * vlSize * jnelmts); // objBuf);
ENVPTR->DeleteLocalRef(ENVONLY, jList);
} /* end for (i = 0; i < count; i++) */
break;
} /* H5T_ARRAY */
- case H5T_INTEGER: {
- /* Convert each list to an array element */
- for (i = 0; i < (size_t)count; i++) {
- if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- switch (typeSize) {
- case sizeof(jbyte): {
- jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, jobj, byteValueMid);
- for (x = 0; x < typeSize; x++) {
- ((char *)raw_buf)[i * typeSize + x] = ((char *)&byteValue)[x];
- }
- break;
- }
- case sizeof(jshort): {
- jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, jobj, shortValueMid);
- for (x = 0; x < typeSize; x++) {
- ((char *)raw_buf)[i * typeSize + x] = ((char *)&shortValue)[x];
- }
- break;
- }
- case sizeof(jint): {
- jint intValue = ENVPTR->CallIntMethod(ENVONLY, jobj, intValueMid);
- for (x = 0; x < typeSize; x++) {
- ((char *)raw_buf)[i * typeSize + x] = ((char *)&intValue)[x];
- }
- break;
- }
- case sizeof(jlong): {
- jlong longValue = ENVPTR->CallLongMethod(ENVONLY, jobj, longValueMid);
- for (x = 0; x < typeSize; x++) {
- ((char *)raw_buf)[i * typeSize + x] = ((char *)&longValue)[x];
- }
- break;
- }
- }
- ENVPTR->DeleteLocalRef(ENVONLY, jobj);
- }
- break;
- } /* H5T_INTEGER */
- case H5T_FLOAT: {
- /* Convert each list to an array element */
- for (i = 0; i < (size_t)count; i++) {
- if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i)))
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- switch (typeSize) {
- case sizeof(jfloat): {
- jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, jobj, floatValueMid);
- for (x = 0; x < typeSize; x++) {
- ((char *)raw_buf)[i * typeSize + x] = ((char *)&floatValue)[x];
- }
- break;
- }
- case sizeof(jdouble): {
- jdouble doubleValue = ENVPTR->CallDoubleMethod(ENVONLY, jobj, doubleValueMid);
- for (x = 0; x < typeSize; x++) {
- ((char *)raw_buf)[i * typeSize + x] = ((char *)&doubleValue)[x];
- }
- break;
- }
- }
- ENVPTR->DeleteLocalRef(ENVONLY, jobj);
- }
- break;
- } /* H5T_FLOAT */
- case H5T_REFERENCE: {
+ case H5T_ENUM:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_INTEGER:
+ case H5T_FLOAT:
+ case H5T_REFERENCE:
+ case H5T_STRING: {
/* Convert each list to an array element */
for (i = 0; i < (size_t)count; i++) {
if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)in_buf, (jsize)i)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
- jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, jobj, 0);
- for (x = 0; x < typeSize; x++) {
- ((char *)raw_buf)[i * typeSize + x] = ((char *)barray)[x];
- }
- ENVPTR->ReleaseByteArrayElements(ENVONLY, jobj, barray, 0);
+ translate_atomic_wbuf(ENVONLY, jobj, mem_type_id, type_class, char_buf + i * typeSize);
ENVPTR->DeleteLocalRef(ENVONLY, jobj);
}
break;
@@ -4573,7 +4940,7 @@ translate_wbuf(JNIEnv *env, jobjectArray in_buf, jlong mem_type_id, H5T_class_t
done:
- return (jint)status;
+ return;
}
#ifdef __cplusplus
diff --git a/java/src/jni/h5util.h b/java/src/jni/h5util.h
index 27c9178..d8ecef9 100644
--- a/java/src/jni/h5util.h
+++ b/java/src/jni/h5util.h
@@ -51,10 +51,10 @@ extern int h5str_dump_simple_mem(JNIEnv *env, FILE *stream, hid_t attr, int b
extern htri_t H5Tdetect_variable_str(hid_t tid);
-extern herr_t translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class,
- jsize count, jbyte *raw_buf);
-extern herr_t translate_wbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class,
- jsize count, jbyte *raw_buf);
+extern void translate_rbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class,
+ jsize count, void *raw_buf);
+extern void translate_wbuf(JNIEnv *env, jobjectArray ret_buf, jlong mem_type_id, H5T_class_t type_class,
+ jsize count, void *raw_buf);
/*
* Symbols used to format the output of h5str_sprintf and