From ddb0c502ede9d46c43ef0cecee5cb1fc03c5f6b5 Mon Sep 17 00:00:00 2001 From: Allen Byrne <50328838+byrnHDF@users.noreply.github.com> Date: Tue, 12 Jul 2022 10:47:06 -0500 Subject: 1 10 HDFFV-11310 implement JNI VL support for primitive types (#1858) * HDFFV-11310 - implement vlen read/write for atomic types. * HDFFV-11310 - VL read/write function for primitive types * Add read/write VL option * fix function name typo * remove debugging prints * Remove more debugging code * Correct note to match change in code. * HDFFV-11318 add VL references as byte arrays * Fix unreleased allocations, fix debug * Fix format * Fix formatting * Correct typo --- java/src/hdf/hdf5lib/H5.java | 22 +- java/src/hdf/hdf5lib/HDF5Constants.java | 12 +- java/src/jni/h5aImp.c | 818 ++++++++++++++++++++++++++------ java/src/jni/h5aImp.h | 18 +- java/src/jni/h5dImp.c | 805 ++++++++++++++++++++++--------- java/src/jni/h5dImp.h | 4 +- java/src/jni/h5util.c | 243 ++++++---- java/src/jni/h5util.h | 1 + java/test/TestH5A.java | 259 +++++++++- java/test/TestH5D.java | 221 ++++++++- java/test/TestH5R.java | 469 ++++++++++++++++++ java/test/testfiles/JUnit-TestH5A.txt | 3 +- java/test/testfiles/JUnit-TestH5D.txt | 5 +- java/test/testfiles/JUnit-TestH5R.txt | 4 +- release_docs/RELEASE.txt | 33 +- 15 files changed, 2415 insertions(+), 502 deletions(-) diff --git a/java/src/hdf/hdf5lib/H5.java b/java/src/hdf/hdf5lib/H5.java index b95495a..e96cf06 100644 --- a/java/src/hdf/hdf5lib/H5.java +++ b/java/src/hdf/hdf5lib/H5.java @@ -246,7 +246,7 @@ public class H5 implements java.io.Serializable { * * Make sure to update the versions number when a different library is used. */ - public final static int LIB_VERSION[] = {1, 10, 9}; + public final static int LIB_VERSION[] = {1, 10, 10}; /** * add system property to load library by path @@ -1267,6 +1267,10 @@ public class H5 implements java.io.Serializable { log.trace("H5Aread_string type"); status = H5Aread_string(attr_id, mem_type_id, (String[])obj); } + else if (H5.H5Tget_class(mem_type_id) == HDF5Constants.H5T_VLEN) { + log.trace("H5AreadVL type"); + status = H5AreadVL(attr_id, mem_type_id, (Object[])obj); + } else { // Create a data buffer to hold the data into a Java Array HDFArray theArray = new HDFArray(obj); @@ -1813,6 +1817,10 @@ public class H5 implements java.io.Serializable { log.trace("H5Dwrite_string type"); status = H5Awrite_string(attr_id, mem_type_id, (String[])obj); } + else if (H5.H5Tget_class(mem_type_id) == HDF5Constants.H5T_VLEN) { + log.trace("H5AwriteVL type"); + status = H5AwriteVL(attr_id, mem_type_id, (Object[])obj); + } else { HDFArray theArray = new HDFArray(obj); byte[] buf = theArray.byteify(); @@ -2797,6 +2805,11 @@ public class H5 implements java.io.Serializable { status = H5Dread_string(dataset_id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, (String[])obj); } + else if (H5.H5Tget_class(mem_type_id) == HDF5Constants.H5T_VLEN) { + log.trace("H5DreadVL type"); + status = + H5DreadVL(dataset_id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, (Object[])obj); + } else { // Create a data buffer to hold the data into a Java Array HDFArray theArray = new HDFArray(obj); @@ -3472,6 +3485,11 @@ public class H5 implements java.io.Serializable { status = H5Dwrite_string(dataset_id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, (String[])obj); } + else if (H5.H5Tget_class(mem_type_id) == HDF5Constants.H5T_VLEN) { + log.trace("H5DwriteVL type"); + status = H5DwriteVL(dataset_id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, + (Object[])obj); + } else { HDFArray theArray = new HDFArray(obj); byte[] buf = theArray.byteify(); @@ -6468,7 +6486,7 @@ public class H5 implements java.io.Serializable { /** * H5Oget_info_by_name retrieves the metadata for an object, identifying the object by location and - *relative name. + * relative name. * * @param loc_id * IN: File or group identifier specifying location of group in which object is located diff --git a/java/src/hdf/hdf5lib/HDF5Constants.java b/java/src/hdf/hdf5lib/HDF5Constants.java index 7c02af9..bcf3eab 100644 --- a/java/src/hdf/hdf5lib/HDF5Constants.java +++ b/java/src/hdf/hdf5lib/HDF5Constants.java @@ -81,7 +81,8 @@ public class HDF5Constants { H5AC_METADATA_WRITE_STRATEGY_DISTRIBUTED(); /** Don't attempt to increase the size of the cache automatically */ public static final int H5C_incr_off = H5C_incr_off(); - /** Attempt to increase the size of the cache + /** + * Attempt to increase the size of the cache * whenever the average hit rate over the last epoch drops * below the value supplied in the lower_hr_threshold * field @@ -93,19 +94,22 @@ public class HDF5Constants { public static final int H5C_flash_incr_add_space = H5C_flash_incr_add_space(); /** Don't attempt to decrease the size of the cache automatically */ public static final int H5C_decr_off = H5C_decr_off(); - /** Attempt to decrease the size of the cache + /** + * Attempt to decrease the size of the cache * whenever the average hit rate over the last epoch rises * above the value supplied in the upper_hr_threshold * field */ public static final int H5C_decr_threshold = H5C_decr_threshold(); - /** At the end of each epoch, search the cache for + /** + * At the end of each epoch, search the cache for * entries that have not been accessed for at least the number * of epochs specified in the epochs_before_eviction field, and * evict these entries */ public static final int H5C_decr_age_out = H5C_decr_age_out(); - /** Same as age_out, but we only + /** + * Same as age_out, but we only * attempt to reduce the cache size when the hit rate observed * over the last epoch exceeds the value provided in the * upper_hr_threshold field diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c index f06075c..065022d 100644 --- a/java/src/jni/h5aImp.c +++ b/java/src/jni/h5aImp.c @@ -56,7 +56,7 @@ static herr_t H5A_iterate_cb(hid_t g_id, const char *name, const H5A_info_t *inf /* * Class: hdf_hdf5lib_H5 - * Method: H5Acreate + * Method: _H5Acreate * Signature: (JLjava/lang/String;JJJ)J */ JNIEXPORT jlong JNICALL @@ -86,7 +86,7 @@ done: /* * Class: hdf_hdf5lib_H5 - * Method: H5Aopen_name + * Method: _H5Aopen_name * Signature: (JLjava/lang/String;)J */ JNIEXPORT jlong JNICALL @@ -124,7 +124,7 @@ done: /* * Class: hdf_hdf5lib_H5 - * Method: H5Aopen_idx + * Method: _H5Aopen_idx * Signature: (JI)J */ JNIEXPORT jlong JNICALL @@ -158,7 +158,10 @@ Java_hdf_hdf5lib_H5_H5Aread(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_t { jboolean readBufIsCopy; jbyte * readBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -166,18 +169,20 @@ Java_hdf_hdf5lib_H5_H5Aread(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_t if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: variable length type not supported"); - - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) - H5_LIBRARY_ERROR(ENVONLY); + if (vl_data_class) { + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: variable length type not supported"); + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } if (isCriticalPinning) { PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, @@ -187,11 +192,17 @@ Java_hdf_hdf5lib_H5_H5Aread(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_t PIN_BYTE_ARRAY(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Aread: read buffer not pinned"); } - if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0) + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, (void *)readBuf)) < 0) H5_LIBRARY_ERROR(ENVONLY); done: if (readBuf) { + if ((status >= 0) && vl_data_class) { + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, readBuf); + if (sid >= 0) + H5Sclose(sid); + } + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -214,7 +225,10 @@ Java_hdf_hdf5lib_H5_H5Awrite(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_ { jboolean writeBufIsCopy; jbyte * writeBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -222,18 +236,18 @@ Java_hdf_hdf5lib_H5_H5Awrite(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_ if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: variable length type not supported"); + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: variable length type not supported"); + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); if (isCriticalPinning) { PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, @@ -248,6 +262,9 @@ Java_hdf_hdf5lib_H5_H5Awrite(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_ done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -270,7 +287,10 @@ Java_hdf_hdf5lib_H5_H5Aread_1short(JNIEnv *env, jclass clss, jlong attr_id, jlon { jboolean readBufIsCopy; jshort * readBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -278,18 +298,20 @@ Java_hdf_hdf5lib_H5_H5Aread_1short(JNIEnv *env, jclass clss, jlong attr_id, jlon if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_short: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_short: variable length type not supported"); - - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) - H5_LIBRARY_ERROR(ENVONLY); + if (vl_data_class) { + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_short: variable length type not supported"); + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } if (isCriticalPinning) { PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, @@ -304,6 +326,12 @@ Java_hdf_hdf5lib_H5_H5Aread_1short(JNIEnv *env, jclass clss, jlong attr_id, jlon done: if (readBuf) { + if ((status >= 0) && vl_data_class) { + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, readBuf); + if (sid >= 0) + H5Sclose(sid); + } + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -326,7 +354,10 @@ Java_hdf_hdf5lib_H5_H5Awrite_1short(JNIEnv *env, jclass clss, jlong attr_id, jlo { jboolean writeBufIsCopy; jshort * writeBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -334,18 +365,18 @@ Java_hdf_hdf5lib_H5_H5Awrite_1short(JNIEnv *env, jclass clss, jlong attr_id, jlo if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_short: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_short: variable length type not supported"); + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_short: variable length type not supported"); + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); if (isCriticalPinning) { PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, @@ -360,6 +391,9 @@ Java_hdf_hdf5lib_H5_H5Awrite_1short(JNIEnv *env, jclass clss, jlong attr_id, jlo done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -381,27 +415,32 @@ Java_hdf_hdf5lib_H5_H5Aread_1int(JNIEnv *env, jclass clss, jlong attr_id, jlong jboolean isCriticalPinning) { jboolean readBufIsCopy; - htri_t data_class; jint * readBuf = NULL; - herr_t status = FAIL; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; + herr_t status = FAIL; UNUSED(clss); if (buf == NULL) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: variable length type not supported"); - - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) - H5_LIBRARY_ERROR(ENVONLY); + if (vl_data_class) { + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: variable length type not supported"); + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } if (isCriticalPinning) { PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, @@ -416,6 +455,12 @@ Java_hdf_hdf5lib_H5_H5Aread_1int(JNIEnv *env, jclass clss, jlong attr_id, jlong done: if (readBuf) { + if ((status >= 0) && vl_data_class) { + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, readBuf); + if (sid >= 0) + H5Sclose(sid); + } + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -438,7 +483,10 @@ Java_hdf_hdf5lib_H5_H5Awrite_1int(JNIEnv *env, jclass clss, jlong attr_id, jlong { jboolean writeBufIsCopy; jint * writeBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -446,18 +494,18 @@ Java_hdf_hdf5lib_H5_H5Awrite_1int(JNIEnv *env, jclass clss, jlong attr_id, jlong if (buf == NULL) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_int: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_int: variable length type not supported"); + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_int: variable length type not supported"); + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); if (isCriticalPinning) { PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, @@ -472,6 +520,9 @@ Java_hdf_hdf5lib_H5_H5Awrite_1int(JNIEnv *env, jclass clss, jlong attr_id, jlong done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -494,7 +545,10 @@ Java_hdf_hdf5lib_H5_H5Aread_1long(JNIEnv *env, jclass clss, jlong attr_id, jlong { jboolean readBufIsCopy; jlong * readBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -502,18 +556,20 @@ Java_hdf_hdf5lib_H5_H5Aread_1long(JNIEnv *env, jclass clss, jlong attr_id, jlong if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_long: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_long: variable length type not supported"); - - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) - H5_LIBRARY_ERROR(ENVONLY); + if (vl_data_class) { + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_long: variable length type not supported"); + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } if (isCriticalPinning) { PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, @@ -528,6 +584,12 @@ Java_hdf_hdf5lib_H5_H5Aread_1long(JNIEnv *env, jclass clss, jlong attr_id, jlong done: if (readBuf) { + if ((status >= 0) && vl_data_class) { + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, readBuf); + if (sid >= 0) + H5Sclose(sid); + } + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -550,7 +612,10 @@ Java_hdf_hdf5lib_H5_H5Awrite_1long(JNIEnv *env, jclass clss, jlong attr_id, jlon { jboolean writeBufIsCopy; jlong * writeBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -558,18 +623,18 @@ Java_hdf_hdf5lib_H5_H5Awrite_1long(JNIEnv *env, jclass clss, jlong attr_id, jlon if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_long: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_long: variable length type not supported"); + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_long: variable length type not supported"); + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); if (isCriticalPinning) { PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, @@ -584,6 +649,9 @@ Java_hdf_hdf5lib_H5_H5Awrite_1long(JNIEnv *env, jclass clss, jlong attr_id, jlon done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -606,7 +674,10 @@ Java_hdf_hdf5lib_H5_H5Aread_1float(JNIEnv *env, jclass clss, jlong attr_id, jlon { jboolean readBufIsCopy; jfloat * readBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -614,18 +685,20 @@ Java_hdf_hdf5lib_H5_H5Aread_1float(JNIEnv *env, jclass clss, jlong attr_id, jlon if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_float: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_float: variable length type not supported"); - - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) - H5_LIBRARY_ERROR(ENVONLY); + if (vl_data_class) { + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_float: variable length type not supported"); + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } if (isCriticalPinning) { PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, @@ -640,6 +713,12 @@ Java_hdf_hdf5lib_H5_H5Aread_1float(JNIEnv *env, jclass clss, jlong attr_id, jlon done: if (readBuf) { + if ((status >= 0) && vl_data_class) { + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, readBuf); + if (sid >= 0) + H5Sclose(sid); + } + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -662,7 +741,10 @@ Java_hdf_hdf5lib_H5_H5Awrite_1float(JNIEnv *env, jclass clss, jlong attr_id, jlo { jboolean writeBufIsCopy; jfloat * writeBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -670,18 +752,18 @@ Java_hdf_hdf5lib_H5_H5Awrite_1float(JNIEnv *env, jclass clss, jlong attr_id, jlo if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_float: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_float: variable length type not supported"); + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_float: variable length type not supported"); + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); if (isCriticalPinning) { PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, @@ -696,6 +778,9 @@ Java_hdf_hdf5lib_H5_H5Awrite_1float(JNIEnv *env, jclass clss, jlong attr_id, jlo done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -718,7 +803,10 @@ Java_hdf_hdf5lib_H5_H5Aread_1double(JNIEnv *env, jclass clss, jlong attr_id, jlo { jboolean readBufIsCopy; jdouble *readBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -726,18 +814,20 @@ Java_hdf_hdf5lib_H5_H5Aread_1double(JNIEnv *env, jclass clss, jlong attr_id, jlo if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_double: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_double: variable length type not supported"); - - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) - H5_LIBRARY_ERROR(ENVONLY); + if (vl_data_class) { + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_double: variable length type not supported"); + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } if (isCriticalPinning) { PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, @@ -752,6 +842,12 @@ Java_hdf_hdf5lib_H5_H5Aread_1double(JNIEnv *env, jclass clss, jlong attr_id, jlo done: if (readBuf) { + if ((status >= 0) && vl_data_class) { + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, readBuf); + if (sid >= 0) + H5Sclose(sid); + } + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -774,7 +870,10 @@ Java_hdf_hdf5lib_H5_H5Awrite_1double(JNIEnv *env, jclass clss, jlong attr_id, jl { jboolean writeBufIsCopy; jdouble *writeBuf = NULL; - htri_t data_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -782,18 +881,17 @@ Java_hdf_hdf5lib_H5_H5Awrite_1double(JNIEnv *env, jclass clss, jlong attr_id, jl if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: variable length type not supported"); + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: buf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: variable length type not supported"); + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); if (isCriticalPinning) { PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, @@ -808,6 +906,9 @@ Java_hdf_hdf5lib_H5_H5Awrite_1double(JNIEnv *env, jclass clss, jlong attr_id, jl done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -958,12 +1059,456 @@ done: /* * Class: hdf_hdf5lib_H5 * Method: H5AreadVL - * Signature: (JJ[Ljava/lang/String;)I + * Signature: (JJ[java/util/ArrayList;)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) { H5T_class_t type_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; + herr_t status = FAIL; + jboolean readBufIsCopy; + jbyteArray *readBuf = NULL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AreadVL: read buffer is NULL"); + + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (vl_data_class) { + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } + + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + + if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + if (type_class == H5T_VLEN) { + size_t typeSize; + hid_t memb = H5I_INVALID_HID; + H5T_class_t vlClass; + size_t vlSize; + void * rawBuf = NULL; + jobject * jList = NULL; + + size_t i, j, x; + char * cp_vp = NULL; + + if (!(typeSize = H5Tget_size(mem_type_id))) + H5_LIBRARY_ERROR(ENVONLY); + + 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); + + if (NULL == (rawBuf = HDcalloc((size_t)n, typeSize))) + H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AreadVL: failed to allocate raw VL read buffer"); + + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, (void *)rawBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* Cache class types */ + jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); + 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 boolValueMid = + ENVPTR->GetStaticMethodID(ENVONLY, cBool, "valueOf", "(Z)Ljava/lang/Boolean;"); + 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;"); + + // retrieve the java.util.List interface class + jclass cList = ENVPTR->FindClass(ENVONLY, "java/util/List"); + jmethodID addMethod = ENVPTR->GetMethodID(ENVONLY, cList, "add", "(Ljava/lang/Object;)Z"); + + /* Convert each element to a list */ + for (i = 0; i < (size_t)n; i++) { + // The list we're going to return: + if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cp_vp = (char *)rawBuf + i * typeSize; + /* Get the number of sequence elements */ + jsize nelmts = ((hvl_t *)cp_vp)->len; + + jobject jobj = NULL; + for (j = 0; j < nelmts; j++) { + switch (vlClass) { + /* case H5T_BOOL: { + jboolean boolValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&boolValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j*vlSize+x]; + } + + jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cBool, boolValueMid, boolValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } */ + case H5T_INTEGER: { + switch (vlSize) { + case sizeof(jbyte): { + jbyte byteValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&byteValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = + ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid, byteValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + case sizeof(jshort): { + jshort shortValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&shortValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid, + shortValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + case sizeof(jint): { + jint intValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&intValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + case sizeof(jlong): { + jlong longValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&longValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = + ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid, longValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + } + break; + } + case H5T_FLOAT: { + switch (vlSize) { + case sizeof(jfloat): { + jfloat floatValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&floatValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid, + floatValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + case sizeof(jdouble): { + jdouble doubleValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&doubleValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid, + doubleValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + } + break; + } + case H5T_REFERENCE: { + jboolean bb; + jbyte * barray = NULL; + if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, vlSize))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, &bb, + "readVL reference: byte array not pinned"); + + for (x = 0; x < (int)vlSize; x++) { + barray[x] = ((jbyte *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT); + break; + } + default: + H5_UNIMPLEMENTED(ENVONLY, "H5AreadVL: invalid class type"); + break; + } + + // Add it to the list + ENVPTR->CallBooleanMethod(ENVONLY, jList, addMethod, jobj); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + } /* end for */ + + if (rawBuf) + HDfree(rawBuf); + } + else { + if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, (void *)readBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + +done: + if (readBuf) { + if ((status >= 0) && vl_data_class) { + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, readBuf); + if (sid >= 0) + H5Sclose(sid); + } + + UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5AreadVL */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5AwriteVL + * Signature: (JJ[java/util/ArrayList;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) +{ + H5T_class_t type_class; + hsize_t dims[H5S_MAX_RANK]; + hid_t sid = H5I_INVALID_HID; + jsize n; + htri_t vl_data_class; + herr_t status = FAIL; + jboolean writeBufIsCopy; + jbyteArray *writeBuf = NULL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL: write buffer is NULL"); + + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL: readBuf length < 0"); + } + + dims[0] = (hsize_t)n; + if ((sid = H5Screate_simple(1, dims, NULL)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + if (type_class == H5T_VLEN) { + size_t typeSize; + hid_t memb = H5I_INVALID_HID; + H5T_class_t vlClass; + size_t vlSize; + void * rawBuf = NULL; + jobject * jList = NULL; + + size_t i, j, x; + char * cp_vp = NULL; + + if (!(typeSize = H5Tget_size(mem_type_id))) + H5_LIBRARY_ERROR(ENVONLY); + + 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); + + if (NULL == (rawBuf = HDcalloc((size_t)n, typeSize))) + H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AwriteVL: failed to allocate raw VL write buffer"); + + /* Cache class types */ + jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); + 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 boolValueMid = ENVPTR->GetMethodID(ENVONLY, cBool, "booleanValue", "()Z"); + 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"); + + /* Convert each list to a vlen element */ + for (i = 0; i < (size_t)n; i++) { + if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + // retrieve the java.util.List interface class + jclass cList = ENVPTR->FindClass(ENVONLY, "java/util/List"); + + // retrieve the toArray method and invoke it + jmethodID mToArray = ENVPTR->GetMethodID(ENVONLY, cList, "toArray", "()[Ljava/lang/Object;"); + if (mToArray == NULL) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, jList, mToArray); + jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array); + + cp_vp = (char *)rawBuf + i * typeSize; + ((hvl_t *)cp_vp)->len = jnelmts; + + if (NULL == (((hvl_t *)cp_vp)->p = HDmalloc(jnelmts * vlSize))) + H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AwriteVL: failed to allocate vlen ptr buffer"); + + jobject jobj = NULL; + for (j = 0; j < (int)jnelmts; j++) { + if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)array, (jsize)j))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + switch (vlClass) { + /* case H5T_BOOL: { + jboolean boolValue = ENVPTR->CallBooleanMethod(ENVONLY, jobj, boolValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&boolValue)[x]; + } + break; + } */ + case H5T_INTEGER: { + switch (vlSize) { + case sizeof(jbyte): { + jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, jobj, byteValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&byteValue)[x]; + } + break; + } + case sizeof(jshort): { + jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, jobj, shortValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&shortValue)[x]; + } + break; + } + case sizeof(jint): { + jint intValue = ENVPTR->CallIntMethod(ENVONLY, jobj, intValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&intValue)[x]; + } + break; + } + case sizeof(jlong): { + jlong longValue = ENVPTR->CallLongMethod(ENVONLY, jobj, longValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&longValue)[x]; + } + break; + } + } + break; + } + case H5T_FLOAT: { + switch (vlSize) { + case sizeof(jfloat): { + jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, jobj, floatValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&floatValue)[x]; + } + break; + } + case sizeof(jdouble): { + jdouble doubleValue = ENVPTR->CallDoubleMethod(ENVONLY, jobj, doubleValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&doubleValue)[x]; + } + break; + } + } + break; + } + case H5T_REFERENCE: { + jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, jobj, 0); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)barray)[x]; + } + ENVPTR->ReleaseByteArrayElements(ENVONLY, jobj, barray, 0); + break; + } + default: + H5_UNIMPLEMENTED(ENVONLY, "H5AwriteVL: invalid class type"); + break; + } + ENVPTR->DeleteLocalRef(ENVONLY, jobj); + } + ENVPTR->DeleteLocalRef(ENVONLY, jList); + } /* end for (i = 0; i < n; i++) */ + + if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, rawBuf)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (rawBuf) + HDfree(rawBuf); + } + else { + PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5AwriteVL: write buffer not pinned"); + if ((status = H5Awrite((hid_t)attr_id, (hid_t)mem_type_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + +done: + if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(attr_id, sid, H5P_DEFAULT, writeBuf); + + if (type_class != H5T_VLEN) + UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5AwriteVL */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Aread_VLStrings + * Signature: (JJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Aread_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, + jobjectArray buf) +{ + H5T_class_t type_class; htri_t isStr = 0; htri_t isVlenStr = 0; htri_t isComplex = 0; @@ -974,7 +1519,7 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem UNUSED(clss); if (NULL == buf) - H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AreadVL: read buffer is NULL"); + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_VLStrings: read buffer is NULL"); if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0) H5_LIBRARY_ERROR(ENVONLY); @@ -1024,7 +1569,7 @@ done: H5Tclose(nested_tid); return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Aread_1VL */ +} /* end Java_hdf_hdf5lib_H5_H5Aread_1VLStrings */ /* * Helper method to read in a buffer of variable-length strings from an HDF5 @@ -1160,11 +1705,12 @@ done: /* * Class: hdf_hdf5lib_H5 - * Method: H5AwriteVL + * Method: H5Awrite_VLStrings * Signature: (JJ[Ljava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) +Java_hdf_hdf5lib_H5_H5Awrite_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, + jobjectArray buf) { H5T_class_t type_class; htri_t isStr = 0; @@ -1177,7 +1723,7 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me UNUSED(clss); if (NULL == buf) - H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL: write buffer is NULL"); + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_VLStrings: write buffer is NULL"); if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0) H5_LIBRARY_ERROR(ENVONLY); @@ -1227,7 +1773,7 @@ done: H5Tclose(nested_tid); return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Awrite_1VL */ +} /* end Java_hdf_hdf5lib_H5_H5Awrite_1VLStrings */ /* * Helper method to convert an array of Java strings into a buffer of C-strings. @@ -1273,7 +1819,7 @@ H5AwriteVL_str(JNIEnv *env, hid_t aid, hid_t tid, jobjectArray buf) if (NULL == (writeBuf[i] = (char *)HDmalloc((size_t)length + 1))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AwriteVL_str: failed to allocate string buffer"); - HDstrncpy(writeBuf[i], utf8, (size_t)length); + HDstrncpy(writeBuf[i], utf8, (size_t)length + 1); writeBuf[i][length] = '\0'; UNPIN_JAVA_STRING(ENVONLY, obj, utf8); @@ -1297,8 +1843,8 @@ done: HDfree(writeBuf); } - return (jint)status; -} + return status; +} /* end H5AwriteVL_str */ /* * Helper method to convert an array of Java strings into a buffer of @@ -1385,7 +1931,7 @@ done: H5Sclose(sid); return status; -} /* end H5AwriteVL_str */ +} /* end H5AwriteVL_asstr */ /* * Class: hdf_hdf5lib_H5 diff --git a/java/src/jni/h5aImp.h b/java/src/jni/h5aImp.h index aee0e40..094f990 100644 --- a/java/src/jni/h5aImp.h +++ b/java/src/jni/h5aImp.h @@ -22,7 +22,7 @@ extern "C" { /* * Class: hdf_hdf5lib_H5 - * Method: H5Acreate + * Method: _H5Acreate * Signature: (JLjava/lang/String;JJJ)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Acreate(JNIEnv *, jclass, jlong, jstring, jlong, jlong, @@ -30,14 +30,14 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Acreate(JNIEnv *, jclass, jlong, /* * Class: hdf_hdf5lib_H5 - * Method: H5Aopen_name + * Method: _H5Aopen_name * Signature: (JLjava/lang/String;)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aopen_1name(JNIEnv *, jclass, jlong, jstring); /* * Class: hdf_hdf5lib_H5 - * Method: H5Aopen_idx + * Method: _H5Aopen_idx * Signature: (JI)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aopen_1idx(JNIEnv *, jclass, jlong, jint); @@ -137,14 +137,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Awrite_1double(JNIEnv *, jclass, jl /* * Class: hdf_hdf5lib_H5 * Method: H5AreadVL - * Signature: (JJ[Ljava/lang/String;)I + * Signature: (JJ[Ljava/util/ArrayList;)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *, jclass, jlong, jlong, jobjectArray); /* * Class: hdf_hdf5lib_H5 * Method: H5AwriteVL - * Signature: (JJ[Ljava/lang/String;)I + * Signature: (JJ[Ljava/util/ArrayList;)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *, jclass, jlong, jlong, jobjectArray); @@ -185,14 +185,14 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref(JNIEnv *, jclass, j /* * Class: hdf_hdf5lib_H5 - * Method: H5Aget_space + * Method: _H5Aget_space * Signature: (J)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aget_1space(JNIEnv *, jclass, jlong); /* * Class: hdf_hdf5lib_H5 - * Method: H5Aget_type + * Method: _H5Aget_type * Signature: (J)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aget_1type(JNIEnv *, jclass, jlong); @@ -220,7 +220,7 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Adelete(JNIEnv *, jclass, jlong, js /* * Class: hdf_hdf5lib_H5 - * Method: H5Aclose + * Method: _H5Aclose * Signature: (J)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5__1H5Aclose(JNIEnv *, jclass, jlong); @@ -350,7 +350,7 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aopen_1by_1name(JNIEnv *, jclass /* * Class: hdf_hdf5lib_H5 - * Method: H5Aget_create_plist + * Method: _H5Aget_create_plist * Signature: (J)J */ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Aget_1create_1plist(JNIEnv *, jclass, jlong); diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c index 24263a5..136d82f 100644 --- a/java/src/jni/h5dImp.c +++ b/java/src/jni/h5dImp.c @@ -183,28 +183,24 @@ Java_hdf_hdf5lib_H5_H5Dread(JNIEnv *env, jclass clss, jlong dataset_id, jlong me jboolean isCriticalPinning) { jboolean readBufIsCopy; - htri_t data_class; jbyte * readBuf = NULL; - herr_t status = FAIL; + htri_t vl_data_class; + herr_t status = FAIL; UNUSED(clss); if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: variable length type not supported"); - if (isCriticalPinning) { PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread: read buffer not critically pinned"); @@ -219,6 +215,9 @@ Java_hdf_hdf5lib_H5_H5Dread(JNIEnv *env, jclass clss, jlong dataset_id, jlong me done: if (readBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -241,28 +240,24 @@ Java_hdf_hdf5lib_H5_H5Dwrite(JNIEnv *env, jclass clss, jlong dataset_id, jlong m jboolean isCriticalPinning) { jboolean writeBufIsCopy; - htri_t data_class; jbyte * writeBuf = NULL; - herr_t status = FAIL; + htri_t vl_data_class; + herr_t status = FAIL; UNUSED(clss); if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite: variable length type not supported"); - if (isCriticalPinning) { PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite: write buffer not critically pinned"); @@ -277,6 +272,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite(JNIEnv *env, jclass clss, jlong dataset_id, jlong m done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -371,7 +369,7 @@ Java_hdf_hdf5lib_H5_H5Dread_1short(JNIEnv *env, jclass clss, jlong dataset_id, j { jboolean readBufIsCopy; jshort * readBuf = NULL; - htri_t data_class; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -379,19 +377,15 @@ Java_hdf_hdf5lib_H5_H5Dread_1short(JNIEnv *env, jclass clss, jlong dataset_id, j if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_short: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_short: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_short: variable length type not supported"); - if (isCriticalPinning) { PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_short: read buffer not critically pinned"); @@ -406,6 +400,9 @@ Java_hdf_hdf5lib_H5_H5Dread_1short(JNIEnv *env, jclass clss, jlong dataset_id, j done: if (readBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -429,7 +426,7 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1short(JNIEnv *env, jclass clss, jlong dataset_id, { jboolean writeBufIsCopy; jshort * writeBuf = NULL; - htri_t data_class; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -437,19 +434,15 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1short(JNIEnv *env, jclass clss, jlong dataset_id, if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_short: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_short: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_short: variable length type not supported"); - if (isCriticalPinning) { PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_short: write buffer not critically pinned"); @@ -464,6 +457,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1short(JNIEnv *env, jclass clss, jlong dataset_id, done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -486,28 +482,24 @@ Java_hdf_hdf5lib_H5_H5Dread_1int(JNIEnv *env, jclass clss, jlong dataset_id, jlo jboolean isCriticalPinning) { jboolean readBufIsCopy; - htri_t data_class; jint * readBuf = NULL; - herr_t status = FAIL; + htri_t vl_data_class; + herr_t status = FAIL; UNUSED(clss); if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_int: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_int: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_int: variable length type not supported"); - if (isCriticalPinning) { PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_int: read buffer not critically pinned"); @@ -522,6 +514,9 @@ Java_hdf_hdf5lib_H5_H5Dread_1int(JNIEnv *env, jclass clss, jlong dataset_id, jlo done: if (readBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -544,28 +539,24 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1int(JNIEnv *env, jclass clss, jlong dataset_id, jl jboolean isCriticalPinning) { jboolean writeBufIsCopy; - htri_t data_class; jint * writeBuf = NULL; - herr_t status = FAIL; + htri_t vl_data_class; + herr_t status = FAIL; UNUSED(clss); if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_int: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_int: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_int: variable length type not supported"); - if (isCriticalPinning) { PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_int: write buffer not critically pinned"); @@ -580,6 +571,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1int(JNIEnv *env, jclass clss, jlong dataset_id, jl done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -602,28 +596,24 @@ Java_hdf_hdf5lib_H5_H5Dread_1long(JNIEnv *env, jclass clss, jlong dataset_id, jl jlongArray buf, jboolean isCriticalPinning) { jboolean readBufIsCopy; - htri_t data_class; jlong * readBuf = NULL; - herr_t status = FAIL; + htri_t vl_data_class; + herr_t status = FAIL; UNUSED(clss); if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_long: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_long: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_long: variable length type not supported"); - if (isCriticalPinning) { PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_long: read buffer not critically pinned"); @@ -638,6 +628,9 @@ Java_hdf_hdf5lib_H5_H5Dread_1long(JNIEnv *env, jclass clss, jlong dataset_id, jl done: if (readBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -660,28 +653,24 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1long(JNIEnv *env, jclass clss, jlong dataset_id, j jlongArray buf, jboolean isCriticalPinning) { jboolean writeBufIsCopy; - htri_t data_class; jlong * writeBuf = NULL; - herr_t status = FAIL; + htri_t vl_data_class; + herr_t status = FAIL; UNUSED(clss); if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_long: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_long: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_long: variable length type not supported"); - if (isCriticalPinning) { PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_long: write buffer not critically pinned"); @@ -696,6 +685,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1long(JNIEnv *env, jclass clss, jlong dataset_id, j done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -718,28 +710,24 @@ Java_hdf_hdf5lib_H5_H5Dread_1float(JNIEnv *env, jclass clss, jlong dataset_id, j jfloatArray buf, jboolean isCriticalPinning) { jboolean readBufIsCopy; - htri_t data_class; jfloat * readBuf = NULL; - herr_t status = FAIL; + htri_t vl_data_class; + herr_t status = FAIL; UNUSED(clss); if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_float: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_float: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_float: variable length type not supported"); - if (isCriticalPinning) { PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_float: read buffer not critically pinned"); @@ -754,6 +742,9 @@ Java_hdf_hdf5lib_H5_H5Dread_1float(JNIEnv *env, jclass clss, jlong dataset_id, j done: if (readBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -776,27 +767,23 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1float(JNIEnv *env, jclass clss, jlong dataset_id, jfloatArray buf, jboolean isCriticalPinning) { jboolean writeBufIsCopy; - htri_t data_class; jfloat * writeBuf = NULL; - herr_t status = FAIL; + htri_t vl_data_class; + herr_t status = FAIL; UNUSED(clss); if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_float: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_float: variable length type not supported"); - - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_float: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread: readBuf length < 0"); + } if (isCriticalPinning) { PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, @@ -812,6 +799,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1float(JNIEnv *env, jclass clss, jlong dataset_id, done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -835,7 +825,7 @@ Java_hdf_hdf5lib_H5_H5Dread_1double(JNIEnv *env, jclass clss, jlong dataset_id, { jboolean readBufIsCopy; jdouble *readBuf = NULL; - htri_t data_class; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -843,19 +833,15 @@ Java_hdf_hdf5lib_H5_H5Dread_1double(JNIEnv *env, jclass clss, jlong dataset_id, if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_double: read buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_double: variable length type not supported"); + /* Get size of data array */ + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_double: variable length type not supported"); - if (isCriticalPinning) { PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy, "H5Dread_double: read buffer not critically pinned"); @@ -870,6 +856,9 @@ Java_hdf_hdf5lib_H5_H5Dread_1double(JNIEnv *env, jclass clss, jlong dataset_id, done: if (readBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); } @@ -893,7 +882,7 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1double(JNIEnv *env, jclass clss, jlong dataset_id, { jboolean writeBufIsCopy; jdouble *writeBuf = NULL; - htri_t data_class; + htri_t vl_data_class; herr_t status = FAIL; UNUSED(clss); @@ -901,19 +890,14 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1double(JNIEnv *env, jclass clss, jlong dataset_id, if (NULL == buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_double: write buffer is NULL"); - if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_double: variable length type not supported"); + if (ENVPTR->GetArrayLength(ENVONLY, buf) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_double: buf length < 0"); + } - /* Recursively detect any vlen string in type (compound, array ...) */ - if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0) + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - if (data_class) - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_double: variable length type not supported"); - if (isCriticalPinning) { PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5Dwrite_double: write buffer not critically pinned"); @@ -928,6 +912,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1double(JNIEnv *env, jclass clss, jlong dataset_id, done: if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf); + if (isCriticalPinning) { UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); } @@ -1082,13 +1069,445 @@ done: /* * Class: hdf_hdf5lib_H5 * Method: H5DreadVL - * Signature: (JJJJJ[Ljava/lang/String;)I + * Signature: (JJJJJ[java/util/ArrayList;)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) { H5T_class_t type_class; + jsize n; + htri_t vl_data_class; + herr_t status = FAIL; + jboolean readBufIsCopy; + jbyteArray *readBuf = NULL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: read buffer is NULL"); + + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: readBuf length < 0"); + } + + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + if (type_class == H5T_VLEN) { + size_t typeSize; + hid_t memb = H5I_INVALID_HID; + H5T_class_t vlClass; + size_t vlSize; + void * rawBuf = NULL; + jobject * jList = NULL; + + size_t i, j, x; + char * cp_vp = NULL; + + if (!(typeSize = H5Tget_size(mem_type_id))) + H5_LIBRARY_ERROR(ENVONLY); + + 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); + + if (NULL == (rawBuf = HDcalloc((size_t)n, typeSize))) + 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 *)rawBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + /* Cache class types */ + jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); + 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 boolValueMid = + ENVPTR->GetStaticMethodID(ENVONLY, cBool, "valueOf", "(Z)Ljava/lang/Boolean;"); + 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;"); + + // retrieve the java.util.List interface class + jclass cList = ENVPTR->FindClass(ENVONLY, "java/util/List"); + jmethodID addMethod = ENVPTR->GetMethodID(ENVONLY, cList, "add", "(Ljava/lang/Object;)Z"); + + /* Convert each element to a list */ + for (i = 0; i < (size_t)n; i++) { + // The list we're going to return: + if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + cp_vp = (char *)rawBuf + i * typeSize; + /* Get the number of sequence elements */ + jsize nelmts = ((hvl_t *)cp_vp)->len; + + jobject jobj = NULL; + for (j = 0; j < nelmts; j++) { + switch (vlClass) { + /*case H5T_BOOL: { + jboolean boolValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&boolValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j*vlSize+x]; + } + + jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cBool, boolValueMid, boolValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } */ + case H5T_INTEGER: { + switch (vlSize) { + case sizeof(jbyte): { + jbyte byteValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&byteValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = + ENVPTR->CallStaticObjectMethod(ENVONLY, cByte, byteValueMid, byteValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + case sizeof(jshort): { + jshort shortValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&shortValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cShort, shortValueMid, + shortValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + case sizeof(jint): { + jint intValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&intValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cInt, intValueMid, intValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + case sizeof(jlong): { + jlong longValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&longValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = + ENVPTR->CallStaticObjectMethod(ENVONLY, cLong, longValueMid, longValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + } + break; + } + case H5T_FLOAT: { + switch (vlSize) { + case sizeof(jfloat): { + jfloat floatValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&floatValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cFloat, floatValueMid, + floatValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + case sizeof(jdouble): { + jdouble doubleValue; + for (x = 0; x < (int)vlSize; x++) { + ((char *)&doubleValue)[x] = ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + + jobj = ENVPTR->CallStaticObjectMethod(ENVONLY, cDouble, doubleValueMid, + doubleValue); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + } + } + break; + } + case H5T_REFERENCE: { + jboolean bb; + jbyte * barray = NULL; + if (NULL == (jobj = ENVPTR->NewByteArray(ENVONLY, vlSize))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + PIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, &bb, + "readVL reference: byte array not pinned"); + + for (x = 0; x < (int)vlSize; x++) { + barray[x] = ((jbyte *)((hvl_t *)cp_vp)->p)[j * vlSize + x]; + } + if (barray) + UNPIN_BYTE_ARRAY(ENVONLY, (jbyteArray)jobj, barray, jobj ? 0 : JNI_ABORT); + break; + } + default: + H5_UNIMPLEMENTED(ENVONLY, "H5DreadVL: invalid class type"); + break; + } + + // Add it to the list + ENVPTR->CallBooleanMethod(ENVONLY, jList, addMethod, jobj); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + } /* end for */ + + if (rawBuf) + HDfree(rawBuf); + } + else { + 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) + H5_LIBRARY_ERROR(ENVONLY); + } + +done: + if (readBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf); + + UNPIN_BYTE_ARRAY(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0); + } + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5DreadVL */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5DwriteVL + * Signature: (JJJJJ[java/util/ArrayList;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, + jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) +{ + H5T_class_t type_class; + jsize n; + htri_t vl_data_class; + herr_t status = FAIL; + jboolean writeBufIsCopy; + jbyteArray *writeBuf = NULL; + + UNUSED(clss); + + if (NULL == buf) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: write buffer is NULL"); + + /* Get size of data array */ + if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: readBuf length < 0"); + } + + if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if ((type_class = H5Tget_class((hid_t)mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + if (type_class == H5T_VLEN) { + size_t typeSize; + hid_t memb = H5I_INVALID_HID; + H5T_class_t vlClass; + size_t vlSize; + void * rawBuf = NULL; + jobject * jList = NULL; + + size_t i, j, x; + char * cp_vp = NULL; + + if (!(typeSize = H5Tget_size(mem_type_id))) + H5_LIBRARY_ERROR(ENVONLY); + + 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); + + if (NULL == (rawBuf = HDcalloc((size_t)n, typeSize))) + H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5DwriteVL: failed to allocate raw VL write buffer"); + + /* Cache class types */ + jclass cBool = ENVPTR->FindClass(ENVONLY, "java/lang/Boolean"); + 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 boolValueMid = ENVPTR->GetMethodID(ENVONLY, cBool, "booleanValue", "()Z"); + 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"); + + /* Convert each list to a vlen element */ + for (i = 0; i < (size_t)n; i++) { + if (NULL == (jList = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + // retrieve the java.util.List interface class + jclass cList = ENVPTR->FindClass(ENVONLY, "java/util/List"); + + // retrieve the toArray method and invoke it + jmethodID mToArray = ENVPTR->GetMethodID(ENVONLY, cList, "toArray", "()[Ljava/lang/Object;"); + if (mToArray == NULL) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + jobjectArray array = (jobjectArray)ENVPTR->CallObjectMethod(ENVONLY, jList, mToArray); + jsize jnelmts = ENVPTR->GetArrayLength(ENVONLY, array); + + cp_vp = (char *)rawBuf + i * typeSize; + ((hvl_t *)cp_vp)->len = jnelmts; + + if (NULL == (((hvl_t *)cp_vp)->p = HDmalloc(jnelmts * vlSize))) + H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5DwriteVL: failed to allocate vlen ptr buffer"); + jobject jobj = NULL; + for (j = 0; j < (int)jnelmts; j++) { + if (NULL == (jobj = ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)array, (jsize)j))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + switch (vlClass) { + /* case H5T_BOOL: { + jboolean boolValue = ENVPTR->CallBooleanMethod(ENVONLY, jobj, boolValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&boolValue)[x]; + } + break; + } */ + case H5T_INTEGER: { + switch (vlSize) { + case sizeof(jbyte): { + jbyte byteValue = ENVPTR->CallByteMethod(ENVONLY, jobj, byteValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&byteValue)[x]; + } + break; + } + case sizeof(jshort): { + jshort shortValue = ENVPTR->CallShortMethod(ENVONLY, jobj, shortValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&shortValue)[x]; + } + break; + } + case sizeof(jint): { + jint intValue = ENVPTR->CallIntMethod(ENVONLY, jobj, intValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&intValue)[x]; + } + break; + } + case sizeof(jlong): { + jlong longValue = ENVPTR->CallLongMethod(ENVONLY, jobj, longValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&longValue)[x]; + } + break; + } + } + break; + } + case H5T_FLOAT: { + switch (vlSize) { + case sizeof(jfloat): { + jfloat floatValue = ENVPTR->CallFloatMethod(ENVONLY, jobj, floatValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&floatValue)[x]; + } + break; + } + case sizeof(jdouble): { + jdouble doubleValue = ENVPTR->CallDoubleMethod(ENVONLY, jobj, doubleValueMid); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)&doubleValue)[x]; + } + break; + } + } + break; + } + case H5T_REFERENCE: { + jbyte *barray = (jbyte *)ENVPTR->GetByteArrayElements(ENVONLY, jobj, 0); + for (x = 0; x < (int)vlSize; x++) { + ((char *)((hvl_t *)cp_vp)->p)[j * vlSize + x] = ((char *)barray)[x]; + } + ENVPTR->ReleaseByteArrayElements(ENVONLY, jobj, barray, 0); + break; + } + default: + H5_UNIMPLEMENTED(ENVONLY, "H5DwriteVL: invalid class type"); + break; + } + ENVPTR->DeleteLocalRef(ENVONLY, jobj); + } + ENVPTR->DeleteLocalRef(ENVONLY, jList); + } /* end for (i = 0; i < n; i++) */ + + if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, rawBuf)) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (rawBuf) + HDfree(rawBuf); + } + else { + PIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, &writeBufIsCopy, "H5DwriteVL: write buffer not pinned"); + if ((status = H5Dwrite((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, + (hid_t)file_space_id, (hid_t)xfer_plist_id, writeBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + +done: + if (writeBuf) { + if ((status >= 0) && vl_data_class) + H5Dvlen_reclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf); + + if (type_class != H5T_VLEN) + UNPIN_BYTE_ARRAY(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0); + } + + return (jint)status; +} /* end Java_hdf_hdf5lib_H5_H5DwriteVL */ + +/* + * Class: hdf_hdf5lib_H5 + * Method: H5Dread_VLStrings + * Signature: (JJJJJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5Dread_1VLStrings(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, + jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, + jobjectArray buf) +{ + H5T_class_t type_class; htri_t isStr = 0; htri_t isVlenStr = 0; htri_t isComplex = 0; @@ -1099,7 +1518,7 @@ Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong UNUSED(clss); if (NULL == buf) - H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DreadVL: read buffer is NULL"); + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DreadVLStrings: read buffer is NULL"); if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0) H5_LIBRARY_ERROR(ENVONLY); @@ -1151,7 +1570,7 @@ done: H5Tclose(nested_tid); return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Dread_1VL */ +} /* end Java_hdf_hdf5lib_H5_H5Dread_1VLStrings */ /* * Helper method to read in a buffer of variable-length strings from an HDF5 @@ -1303,54 +1722,15 @@ done: return status; } -/** - * Read VLEN data into array of arrays. - * Object[] buf contains VL arrays of data points - * Currently only deal with variable length of atomic data types - */ -/* old version */ - -/* - * Class: hdf_hdf5lib_H5 - * Method: H5Dread_VLStrings - * Signature: (JJJJJ[Ljava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Dread_1VLStrings(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, - jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, - jobjectArray buf) -{ - htri_t isVlenStr = 0; - herr_t status = FAIL; - - UNUSED(clss); - - if (NULL == buf) - H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dread_VLStrings: read buffer is NULL"); - - if ((isVlenStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (isVlenStr) { - if ((status = H5DreadVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buf)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - } - else - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_VLStrings: datatype is not variable length String"); - -done: - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Dread_1VLStrings */ - /* * Class: hdf_hdf5lib_H5 - * Method: H5DwriteVL + * Method: H5Dwrite_VLStrings * Signature: (JJJJJ[Ljava/lang/String;)I */ JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, - jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) +Java_hdf_hdf5lib_H5_H5Dwrite_1VLStrings(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, + jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, + jobjectArray buf) { H5T_class_t type_class; htri_t isStr = 0; @@ -1363,7 +1743,7 @@ Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *env, jclass clss, jlong dataset_id, jlong UNUSED(clss); if (NULL == buf) - H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DwriteVL: write buffer is NULL"); + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5DwriteVLStrings: write buffer is NULL"); if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0) H5_LIBRARY_ERROR(ENVONLY); @@ -1415,7 +1795,7 @@ done: H5Tclose(nested_tid); return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Dwrite_1VL */ +} /* end Java_hdf_hdf5lib_H5_H5Dwrite_1VLStrings */ /* * Helper method to convert an array of Java strings into a buffer of C-strings. @@ -1428,7 +1808,7 @@ H5DwriteVL_str(JNIEnv *env, hid_t dataset_id, hid_t mem_type_id, hid_t mem_space const char *utf8 = NULL; jstring obj; jsize size; - jsize i; + jint i; char ** writeBuf = NULL; herr_t status = FAIL; @@ -1500,7 +1880,7 @@ H5DwriteVL_asstr(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_si jobjectArray buf) { const char *utf8 = NULL; - jstring obj = NULL; + jstring jstr = NULL; hbool_t close_mem_space = FALSE; size_t typeSize; size_t i; @@ -1537,7 +1917,7 @@ H5DwriteVL_asstr(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_si H5_OUT_OF_MEMORY_ERROR(ENVONLY, "H5AwriteVL_asstr: failed to allocate write buffer"); for (i = 0; i < (size_t)n; ++i) { - if (NULL == (obj = (jstring)ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i))) { + if (NULL == (jstr = (jstring)ENVPTR->GetObjectArrayElement(ENVONLY, (jobjectArray)buf, (jsize)i))) { CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); /* @@ -1548,11 +1928,11 @@ H5DwriteVL_asstr(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_si } /* - * length = ENVPTR->GetStringUTFLength(ENVONLY, obj); + * length = ENVPTR->GetStringUTFLength(ENVONLY, jstr); * CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); */ - PIN_JAVA_STRING(ENVONLY, obj, utf8, NULL, "H5DwriteVL_asstr: failed to pin string buffer"); + PIN_JAVA_STRING(ENVONLY, jstr, utf8, NULL, "H5DwriteVL_asstr: failed to pin string buffer"); /* * TODO: If the string isn't a copy, we should probably make @@ -1562,10 +1942,10 @@ H5DwriteVL_asstr(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_si if (!h5str_convert(ENVONLY, (char **)&utf8, did, tid, &(((char *)writeBuf)[i * typeSize]), 0)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + UNPIN_JAVA_STRING(ENVONLY, jstr, utf8); utf8 = NULL; - ENVPTR->DeleteLocalRef(ENVONLY, obj); + ENVPTR->DeleteLocalRef(ENVONLY, jstr); } /* end for (i = 0; i < size; ++i) */ if ((status = H5Dwrite(did, tid, mem_sid, file_sid, xfer_plist_id, writeBuf)) < 0) @@ -1573,7 +1953,7 @@ H5DwriteVL_asstr(JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_si done: if (utf8) - UNPIN_JAVA_STRING(ENVONLY, obj, utf8); + UNPIN_JAVA_STRING(ENVONLY, jstr, utf8); if (writeBuf) { H5Dvlen_reclaim(tid, mem_space, xfer_plist_id, writeBuf); HDfree(writeBuf); @@ -1586,39 +1966,6 @@ done: /* * Class: hdf_hdf5lib_H5 - * Method: H5Dwrite_VLStrings - * Signature: (JJJJJ[Ljava/lang/String;)I - */ -JNIEXPORT jint JNICALL -Java_hdf_hdf5lib_H5_H5Dwrite_1VLStrings(JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, - jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, - jobjectArray buf) -{ - htri_t isVlenStr = 0; - herr_t status = FAIL; - - UNUSED(clss); - - if (NULL == buf) - H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_VLStrings: write buffer is NULL"); - - if ((isVlenStr = H5Tis_variable_str((hid_t)mem_type_id)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (isVlenStr) { - if ((status = H5DwriteVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, - (hid_t)file_space_id, (hid_t)xfer_plist_id, buf)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - } /* end if */ - else - H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dwrite_VLStrings: datatype is not variable length String"); - -done: - return (jint)status; -} /* end Java_hdf_hdf5lib_H5_H5Dwrite_1VLStrings */ - -/* - * Class: hdf_hdf5lib_H5 * Method: H5Dread_reg_ref * Signature: (JJJJJ[Ljava/lang/String;)I */ diff --git a/java/src/jni/h5dImp.h b/java/src/jni/h5dImp.h index e339dad..f79cc2c 100644 --- a/java/src/jni/h5dImp.h +++ b/java/src/jni/h5dImp.h @@ -177,7 +177,7 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Dwrite_1double(JNIEnv *, jclass, jl /* * Class: hdf_hdf5lib_H5 * Method: H5DreadVL - * Signature: (JJJJJ[Ljava/lang/String;)I + * Signature: (JJJJJ[Ljava/util/ArrayList;)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *, jclass, jlong, jlong, jlong, jlong, jlong, jobjectArray); @@ -185,7 +185,7 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5DreadVL(JNIEnv *, jclass, jlong, jl /* * Class: hdf_hdf5lib_H5 * Method: H5DwriteVL - * Signature: (JJJJJ[Ljava/lang/String;)I + * Signature: (JJJJJ[Ljava/util/ArrayList;)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5DwriteVL(JNIEnv *, jclass, jlong, jlong, jlong, jlong, jlong, jobjectArray); diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c index 4568880..7de5a05 100644 --- a/java/src/jni/h5util.c +++ b/java/src/jni/h5util.c @@ -62,7 +62,6 @@ static int h5str_is_zero(const void *_mem, size_t size); static hid_t h5str_get_native_type(hid_t type); static hid_t h5str_get_little_endian_type(hid_t type); static hid_t h5str_get_big_endian_type(hid_t type); -static htri_t h5str_detect_vlen(hid_t tid); static htri_t h5str_detect_vlen_str(hid_t tid); static int h5str_dump_simple_data(JNIEnv *env, FILE *stream, hid_t container, hid_t type, void *_mem, hsize_t nelmts); @@ -210,10 +209,10 @@ h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_ /* Build default formats for long long types */ if (!fmt_llong[0]) { - if (HDsprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: HDsprintf failure"); - if (HDsprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: HDsprintf failure"); + if (HDsnprintf(fmt_llong, sizeof(fmt_llong), "%%%sd", H5_PRINTF_LL_WIDTH) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: HDsnprintf failure"); + if (HDsnprintf(fmt_ullong, sizeof(fmt_ullong), "%%%su", H5_PRINTF_LL_WIDTH) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: HDsnprintf failure"); } /* end if */ switch (tclass) { @@ -651,9 +650,8 @@ done: int h5str_sprint_reference(JNIEnv *env, h5str_t *out_str, hid_t region_obj, void *ref_buf) { - hid_t region = H5I_INVALID_HID; - char ref_name[1024]; - const char *path; + hid_t region = H5I_INVALID_HID; + char ref_name[1024]; int ret_value = FAIL; @@ -756,11 +754,12 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i HDmemcpy(&tmp_float, cptr, sizeof(float)); - if (NULL == (this_str = (char *)HDmalloc(25))) + size_t this_len = 25; + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%g", tmp_float) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%g", tmp_float) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); break; } @@ -770,11 +769,12 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i HDmemcpy(&tmp_double, cptr, sizeof(double)); - if (NULL == (this_str = (char *)HDmalloc(25))) + size_t this_len = 25; + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%g", tmp_double) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%g", tmp_double) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); break; } @@ -784,11 +784,12 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i HDmemcpy(&tmp_ldouble, cptr, sizeof(long double)); - if (NULL == (this_str = (char *)HDmalloc(27))) + size_t this_len = 27; + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%Lg", tmp_ldouble) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%Lg", tmp_ldouble) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); break; } @@ -850,25 +851,26 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i unsigned char tmp_uchar = 0; char tmp_char = 0; + size_t this_len = 7; if (H5T_SGN_NONE == nsign) { HDmemcpy(&tmp_uchar, cptr, sizeof(unsigned char)); - if (NULL == (this_str = (char *)HDmalloc(7))) + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%hhu", tmp_uchar) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%hhu", tmp_uchar) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } else { HDmemcpy(&tmp_char, cptr, sizeof(char)); - if (NULL == (this_str = (char *)HDmalloc(7))) + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%hhd", tmp_char) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%hhd", tmp_char) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } break; @@ -878,25 +880,26 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i unsigned short tmp_ushort = 0; short tmp_short = 0; + size_t this_len = 9; if (H5T_SGN_NONE == nsign) { HDmemcpy(&tmp_ushort, cptr, sizeof(unsigned short)); - if (NULL == (this_str = (char *)HDmalloc(9))) + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%hu", tmp_ushort) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%hu", tmp_ushort) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } else { HDmemcpy(&tmp_short, cptr, sizeof(short)); - if (NULL == (this_str = (char *)HDmalloc(9))) + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%hd", tmp_short) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%hd", tmp_short) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } break; @@ -906,25 +909,26 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i unsigned int tmp_uint = 0; int tmp_int = 0; + size_t this_len = 14; if (H5T_SGN_NONE == nsign) { HDmemcpy(&tmp_uint, cptr, sizeof(unsigned int)); - if (NULL == (this_str = (char *)HDmalloc(14))) + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%u", tmp_uint) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%u", tmp_uint) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } else { HDmemcpy(&tmp_int, cptr, sizeof(int)); - if (NULL == (this_str = (char *)HDmalloc(14))) + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%d", tmp_int) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%d", tmp_int) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } break; @@ -934,25 +938,26 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i unsigned long tmp_ulong = 0; long tmp_long = 0; + size_t this_len = 23; if (H5T_SGN_NONE == nsign) { HDmemcpy(&tmp_ulong, cptr, sizeof(unsigned long)); - if (NULL == (this_str = (char *)HDmalloc(23))) + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%lu", tmp_ulong) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%lu", tmp_ulong) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } else { HDmemcpy(&tmp_long, cptr, sizeof(long)); - if (NULL == (this_str = (char *)HDmalloc(23))) + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%ld", tmp_long) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%ld", tmp_long) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } break; @@ -963,25 +968,26 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i unsigned long long tmp_ullong = 0; long long tmp_llong = 0; + size_t this_len = 25; if (H5T_SGN_NONE == nsign) { HDmemcpy(&tmp_ullong, cptr, sizeof(unsigned long long)); - if (NULL == (this_str = (char *)HDmalloc(25))) + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, fmt_ullong, tmp_ullong) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, fmt_ullong, tmp_ullong) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } else { HDmemcpy(&tmp_llong, cptr, sizeof(long long)); - if (NULL == (this_str = (char *)HDmalloc(25))) + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, fmt_llong, tmp_llong) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, fmt_llong, tmp_llong) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } break; @@ -1041,17 +1047,18 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i else { size_t i; - if (NULL == (this_str = (char *)HDmalloc(4 * (typeSize + 1)))) + size_t this_len = 4 * (typeSize + 1); + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (1 == typeSize) { - if (HDsprintf(this_str, "%#02x", ucptr[0]) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%#02x", ucptr[0]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } else { for (i = 0; i < typeSize; i++) - if (HDsprintf(this_str, "%s%02x", i ? ":" : "", ucptr[i]) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%s%02x", i ? ":" : "", ucptr[i]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } } @@ -1088,8 +1095,29 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i H5_LIBRARY_ERROR(ENVONLY); /* Print object data and close object */ - if (HDsprintf(this_str, "%u-%llu", (unsigned)oi.type, oi.addr) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + switch (oi.type) { + case H5O_TYPE_GROUP: + if (HDsprintf(this_str, "%s %llu", H5_TOOLS_GROUP, oi.addr) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + break; + + case H5O_TYPE_DATASET: + if (HDsprintf(this_str, "%s %llu", H5_TOOLS_DATASET, oi.addr) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + break; + + case H5O_TYPE_NAMED_DATATYPE: + if (HDsprintf(this_str, "%s %llu", H5_TOOLS_DATATYPE, oi.addr) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + break; + + case H5O_TYPE_UNKNOWN: + case H5O_TYPE_NTYPES: + default: + if (HDsprintf(this_str, "%u-%llu", (unsigned)oi.type, oi.addr) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + break; + } /* end switch */ if (H5Oclose(obj) < 0) H5_LIBRARY_ERROR(ENVONLY); @@ -1189,17 +1217,18 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i /* All other types get printed as hexadecimal */ - if (NULL == (this_str = (char *)HDmalloc(4 * (typeSize + 1)))) + size_t this_len = 4 * (typeSize + 1); + if (NULL == (this_str = (char *)HDmalloc(this_len))) H5_OUT_OF_MEMORY_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (1 == typeSize) { - if (HDsprintf(this_str, "%#02x", ucptr[0]) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%#02x", ucptr[0]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } else { for (i = 0; i < typeSize; i++) - if (HDsprintf(this_str, "%s%02x", i ? ":" : "", ucptr[i]) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (HDsnprintf(this_str, this_len, "%s%02x", i ? ":" : "", ucptr[i]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); } break; @@ -1230,7 +1259,7 @@ done: * This is a special case subfunction to print the data in a region reference of type blocks. * * Return: - * The function returns FAIL if there was an error, otherwise SUCEED + * The function returns FAIL if there was an error, otherwise SUCCEED *------------------------------------------------------------------------- */ static int @@ -1401,8 +1430,9 @@ h5str_dump_region_blocks(JNIEnv *env, h5str_t *str, hid_t region_space, hid_t re for (j = 0; j < ndims; j++) { tmp_str[0] = '\0'; - if (HDsprintf(tmp_str, "%s%lu", j ? "," : "(", (unsigned long)ptdata[i * 2 * ndims + j]) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks: HDsprintf failure"); + if (HDsnprintf(tmp_str, sizeof(tmp_str), "%s%lu", j ? "," : "(", + (unsigned long)ptdata[i * 2 * ndims + j]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks: HDsnprintf failure"); if (!h5str_append(str, tmp_str)) H5_ASSERTION_ERROR(ENVONLY, "Unable to append string."); @@ -1411,9 +1441,9 @@ h5str_dump_region_blocks(JNIEnv *env, h5str_t *str, hid_t region_space, hid_t re for (j = 0; j < ndims; j++) { tmp_str[0] = '\0'; - if (HDsprintf(tmp_str, "%s%lu", j ? "," : ")-(", - (unsigned long)ptdata[i * 2 * ndims + j + ndims]) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks: HDsprintf failure"); + if (HDsnprintf(tmp_str, sizeof(tmp_str), "%s%lu", j ? "," : ")-(", + (unsigned long)ptdata[i * 2 * ndims + j + ndims]) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks: HDsnprintf failure"); if (!h5str_append(str, tmp_str)) H5_ASSERTION_ERROR(ENVONLY, "Unable to append string."); @@ -1578,8 +1608,9 @@ h5str_dump_region_points(JNIEnv *env, h5str_t *str, hid_t region_space, hid_t re for (j = 0; j < ndims; j++) { tmp_str[0] = '\0'; - if (HDsprintf(tmp_str, "%s%lu", j ? "," : "(", (unsigned long)(ptdata[i * ndims + j])) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_points: HDsprintf failure"); + if (HDsnprintf(tmp_str, sizeof(tmp_str), "%s%lu", j ? "," : "(", + (unsigned long)(ptdata[i * ndims + j])) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_points: HDsnprintf failure"); if (!h5str_append(str, tmp_str)) H5_ASSERTION_ERROR(ENVONLY, "Unable to append string."); @@ -1628,7 +1659,7 @@ h5str_is_zero(const void *_mem, size_t size) * Negative value: error occurred *------------------------------------------------------------------------- */ -static htri_t +htri_t h5str_detect_vlen(hid_t tid) { htri_t ret = FAIL; @@ -1653,7 +1684,7 @@ done: * Purpose: Recursive check for variable length string of a datatype. * * Return: - * TRUE : type conatains any variable length string + * TRUE : type contains any variable length string * FALSE : type doesn't contain any variable length string * Negative value: error occur * @@ -2187,7 +2218,7 @@ done: * This is a special case subfunction to print the data in a region reference of type blocks. * * Return: - * The function returns FAIL if there was an error, otherwise SUCEED + * The function returns FAIL if there was an error, otherwise SUCCEED * *------------------------------------------------------------------------- */ @@ -2838,29 +2869,65 @@ done: return ret_value; } +/*------------------------------------------------------------------------- + * Function: H5Tdetect_variable_str + * + * Purpose: Recursive check for variable length string of a datatype. + * + * Return: TRUE : type contains any variable length string + * FALSE : type doesn't contain any variable length string + * Negative value: failed + *------------------------------------------------------------------------- + */ htri_t H5Tdetect_variable_str(hid_t tid) { - htri_t ret_val = 0; - - if (H5Tget_class(tid) == H5T_COMPOUND) { - unsigned i; - unsigned nm = (unsigned)H5Tget_nmembers(tid); - for (i = 0; i < nm; i++) { - htri_t status = 0; - hid_t mtid = 0; - if ((mtid = H5Tget_member_type(tid, i)) < 0) - return FAIL; /* exit immediately on error */ - if ((status = H5Tdetect_variable_str(mtid)) < 0) - return status; /* exit immediately on error */ - ret_val |= status; + H5T_class_t tclass = -1; + htri_t ret = FALSE; + + ret = H5Tis_variable_str(tid); + if ((ret == TRUE) || (ret < 0)) + goto done; + + tclass = H5Tget_class(tid); + if (tclass == H5T_ARRAY || tclass == H5T_VLEN) { + hid_t btid = H5Tget_super(tid); + + if (btid < 0) { + ret = (htri_t)btid; + goto done; + } + ret = H5Tdetect_variable_str(btid); + if ((ret == TRUE) || (ret < 0)) { + H5Tclose(btid); + goto done; + } + } + else if (tclass == H5T_COMPOUND) { + unsigned nmembs; + int snmembs = H5Tget_nmembers(tid); + unsigned u; + + if (snmembs < 0) { + ret = FAIL; + goto done; + } + nmembs = (unsigned)snmembs; + + for (u = 0; u < nmembs; u++) { + hid_t mtid = H5Tget_member_type(tid, u); + + ret = H5Tdetect_variable_str(mtid); + if ((ret == TRUE) || (ret < 0)) { + H5Tclose(mtid); + goto done; + } H5Tclose(mtid); - } /* end for */ - } /* end if */ - else - ret_val = H5Tis_variable_str(tid); + } + } - return ret_val; +done: + return ret; } /* end H5Tdetect_variable_str */ static int diff --git a/java/src/jni/h5util.h b/java/src/jni/h5util.h index b7f12bd..9517630 100644 --- a/java/src/jni/h5util.h +++ b/java/src/jni/h5util.h @@ -39,6 +39,7 @@ extern void h5str_new(h5str_t *str, size_t len); extern void h5str_free(h5str_t *str); extern void h5str_resize(h5str_t *str, size_t new_len); extern char * h5str_append(h5str_t *str, const char *cstr); +extern htri_t h5str_detect_vlen(hid_t tid); extern size_t h5str_convert(JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_buf, size_t out_buf_offset); extern int h5str_sprint_reference(JNIEnv *env, h5str_t *out_str, hid_t region_obj, void *ref_buf); diff --git a/java/test/TestH5A.java b/java/test/TestH5A.java index 113196a..52731b3 100644 --- a/java/test/TestH5A.java +++ b/java/test/TestH5A.java @@ -20,6 +20,8 @@ import static org.junit.Assert.fail; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; @@ -249,9 +251,8 @@ public class TestH5A { // Opening the existing attribute, obj_name(Created by H5ACreate2) // by index, attached to an object identifier. - attribute_id = - H5.H5Aopen_by_idx(H5did, ".", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0, - HDF5Constants.H5P_DEFAULT, lapl_id); + attribute_id = H5.H5Aopen_by_idx(H5did, ".", HDF5Constants.H5_INDEX_CRT_ORDER, + HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT, lapl_id); assertTrue("testH5Aopen_by_idx: H5Aopen_by_idx", attribute_id >= 0); @@ -313,9 +314,9 @@ public class TestH5A { boolean bool_val = false; try { - attribute_id = - H5.H5Acreate_by_name(H5fid, obj_name, attr_name, type_id, space_id, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT, lapl_id); + attribute_id = H5.H5Acreate_by_name(H5fid, obj_name, attr_name, type_id, space_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, + lapl_id); assertTrue("testH5Acreate_by_name: H5Acreate_by_name", attribute_id >= 0); // Check if the name of attribute attached to the object specified @@ -433,9 +434,9 @@ public class TestH5A { long attribute_id = HDF5Constants.H5I_INVALID_HID; try { - attribute_id = - H5.H5Acreate_by_name(H5fid, obj_name, attr_name, type_id, space_id, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT, lapl_id); + attribute_id = H5.H5Acreate_by_name(H5fid, obj_name, attr_name, type_id, space_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, + lapl_id); assertTrue("testH5Aget_name: H5Acreate_by_name ", attribute_id > 0); ret_name = H5.H5Aget_name(attribute_id); assertEquals(ret_name, attr_name); @@ -539,7 +540,7 @@ public class TestH5A { try { attr_id = H5.H5Acreate(H5did, "dset", type_id, space_id, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); attribute_id = H5.H5Aopen(H5did, "dset", HDF5Constants.H5P_DEFAULT); // Calling H5Aget_info with attribute_id returned from H5Aopen. attr_info = H5.H5Aget_info(attribute_id); @@ -580,7 +581,7 @@ public class TestH5A { try { attr_id = H5.H5Acreate(H5did, ".", type_id, space_id, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); attribute_id = H5.H5Aopen_by_idx(H5did, ".", HDF5Constants.H5_INDEX_CRT_ORDER, order, 0, HDF5Constants.H5P_DEFAULT, lapl_id); // Calling H5Aget_info with attribute_id returned from @@ -623,7 +624,7 @@ public class TestH5A { try { attr_id = H5.H5Acreate(H5did, "dset1", type_id, space_id, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); attr2_id = H5.H5Acreate(H5did, "dataset2", type_id, space_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); @@ -700,7 +701,7 @@ public class TestH5A { try { attr_id = H5.H5Acreate_by_name(H5fid, obj_name, attr_name, type_id, space_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); attr_info = H5.H5Aget_info_by_name(H5fid, obj_name, attr_name, lapl_id); assertNotNull(attr_info); } @@ -1064,7 +1065,7 @@ public class TestH5A { HDF5Constants.H5P_DEFAULT); assertTrue("testH5Awrite_readVL: ", attr_id >= 0); - H5.H5AwriteVL(attr_id, atype_id, str_data); + H5.H5Awrite_VLStrings(attr_id, atype_id, str_data); H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); @@ -1076,7 +1077,7 @@ public class TestH5A { strs[j] = ""; } try { - H5.H5AreadVL(attr_id, atype_id, strs); + H5.H5Aread_VLStrings(attr_id, atype_id, strs); } catch (Exception ex) { ex.printStackTrace(); @@ -1151,12 +1152,12 @@ public class TestH5A { fail("H5.H5Acreate: " + err); } - /* Close the property list, and get the attribute's property list */ + // Close the property list, and get the attribute's property list H5.H5Pclose(plist_id); plist_id = H5.H5Aget_create_plist(attribute_id); assertTrue(plist_id > 0); - /* Get the character encoding and ensure that it is the default (ASCII) */ + // Get the character encoding and ensure that it is the default (ASCII) try { char_encoding = H5.H5Pget_char_encoding(plist_id); } @@ -1213,13 +1214,13 @@ public class TestH5A { } try { attr1_id = H5.H5Acreate_by_name(H5fid, ".", "attribute1", type_id, space_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); attr2_id = H5.H5Acreate_by_name(H5fid, ".", "attribute2", type_id, space_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); attr3_id = H5.H5Acreate_by_name(H5fid, ".", "attribute3", type_id, space_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); attr4_id = H5.H5Acreate_by_name(H5fid, ".", "attribute4", type_id, space_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); H5A_iterate_cb iter_cb = new H5A_iter_callback(); try { H5.H5Aiterate(H5fid, HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0L, iter_cb, @@ -1306,13 +1307,13 @@ public class TestH5A { } try { attr1_id = H5.H5Acreate_by_name(H5fid, ".", "attribute4", type_id, space_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); attr2_id = H5.H5Acreate_by_name(H5fid, ".", "attribute3", type_id, space_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); attr3_id = H5.H5Acreate_by_name(H5fid, ".", "attribute2", type_id, space_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); attr4_id = H5.H5Acreate_by_name(H5fid, ".", "attribute1", type_id, space_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id); H5A_iterate_cb iter_cb = new H5A_iter_callback(); try { H5.H5Aiterate_by_name(H5fid, ".", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0L, @@ -1360,4 +1361,212 @@ public class TestH5A { } } } + + @Test + public void testH5AVLwr() + { + String attr_int_name = "VLIntdata"; + String attr_dbl_name = "VLDbldata"; + long attr_int_id = HDF5Constants.H5I_INVALID_HID; + long attr_dbl_id = HDF5Constants.H5I_INVALID_HID; + long atype_int_id = HDF5Constants.H5I_INVALID_HID; + long atype_dbl_id = HDF5Constants.H5I_INVALID_HID; + long aspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + + ArrayList[] vl_int_data = new ArrayList[4]; + ArrayList[] vl_dbl_data = new ArrayList[4]; + try { + // Write Integer data + vl_int_data[0] = new ArrayList(Arrays.asList(1)); + vl_int_data[1] = new ArrayList(Arrays.asList(2, 3)); + vl_int_data[2] = new ArrayList(Arrays.asList(4, 5, 6)); + vl_int_data[3] = new ArrayList(Arrays.asList(7, 8, 9, 10)); + Class dataClass = vl_int_data.getClass(); + assertTrue("testH5AVLwr.getClass: " + dataClass, dataClass.isArray()); + + try { + atype_int_id = H5.H5Tvlen_create(HDF5Constants.H5T_STD_U32LE); + assertTrue("testH5AVLwr.H5Tvlen_create: ", atype_int_id >= 0); + } + catch (Exception err) { + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5AVLwr: " + err); + } + + try { + aspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(aspace_id > 0); + attr_int_id = H5.H5Acreate(H5did, attr_int_name, atype_int_id, aspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5AVLwr: ", attr_int_id >= 0); + + H5.H5AwriteVL(attr_int_id, atype_int_id, vl_int_data); + } + catch (Exception err) { + if (attr_int_id > 0) + try { + H5.H5Aclose(attr_int_id); + } + catch (Exception ex) { + } + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5AVLwr: " + err); + } + finally { + if (aspace_id > 0) + try { + H5.H5Sclose(aspace_id); + } + catch (Exception ex) { + } + } + + // Write Double data + vl_dbl_data[0] = new ArrayList(Arrays.asList(1.1)); + vl_dbl_data[1] = new ArrayList(Arrays.asList(2.2, 3.3)); + vl_dbl_data[2] = new ArrayList(Arrays.asList(4.4, 5.5, 6.6)); + vl_dbl_data[3] = new ArrayList(Arrays.asList(7.7, 8.8, 9.9, 10.0)); + dataClass = vl_dbl_data.getClass(); + assertTrue("testH5AVLwr.getClass: " + dataClass, dataClass.isArray()); + + try { + atype_dbl_id = H5.H5Tvlen_create(HDF5Constants.H5T_NATIVE_DOUBLE); + assertTrue("testH5AVLwr.H5Tvlen_create: ", atype_dbl_id >= 0); + } + catch (Exception err) { + if (atype_dbl_id > 0) + try { + H5.H5Tclose(atype_dbl_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5AVLwr: " + err); + } + + try { + aspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(aspace_id > 0); + attr_dbl_id = H5.H5Acreate(H5did, attr_dbl_name, atype_dbl_id, aspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5AVLwr: ", attr_dbl_id >= 0); + + H5.H5AwriteVL(attr_dbl_id, atype_dbl_id, vl_dbl_data); + } + catch (Exception err) { + if (attr_dbl_id > 0) + try { + H5.H5Aclose(attr_dbl_id); + } + catch (Exception ex) { + } + if (atype_dbl_id > 0) + try { + H5.H5Tclose(atype_dbl_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5AVLwr: " + err); + } + finally { + if (aspace_id > 0) + try { + H5.H5Sclose(aspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) { + lsize *= dims[j]; + } + + // Read Integer data + ArrayList[] vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + vl_readbuf[j] = new ArrayList(); + + try { + H5.H5AreadVL(attr_int_id, atype_int_id, vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5AVLwr:" + vl_readbuf[0].get(0), + vl_int_data[0].get(0).equals(vl_readbuf[0].get(0))); + assertTrue("testH5AVLwr:" + vl_readbuf[1].get(0), + vl_int_data[1].get(0).equals(vl_readbuf[1].get(0))); + assertTrue("testH5AVLwr:" + vl_readbuf[2].get(0), + vl_int_data[2].get(0).equals(vl_readbuf[2].get(0))); + assertTrue("testH5AVLwr:" + vl_readbuf[3].get(0), + vl_int_data[3].get(0).equals(vl_readbuf[3].get(0))); + + // Read Double data + vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + vl_readbuf[j] = new ArrayList(); + + try { + H5.H5AreadVL(attr_dbl_id, atype_dbl_id, vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5AVLwr:" + vl_readbuf[0].get(0), + vl_dbl_data[0].get(0).equals(vl_readbuf[0].get(0))); + assertTrue("testH5AVLwr:" + vl_readbuf[1].get(0), + vl_dbl_data[1].get(0).equals(vl_readbuf[1].get(0))); + assertTrue("testH5AVLwr:" + vl_readbuf[2].get(0), + vl_dbl_data[2].get(0).equals(vl_readbuf[2].get(0))); + assertTrue("testH5AVLwr:" + vl_readbuf[3].get(0), + vl_dbl_data[3].get(0).equals(vl_readbuf[3].get(0))); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5AVLwr: " + err); + } + finally { + if (attr_dbl_id > 0) + try { + H5.H5Aclose(attr_dbl_id); + } + catch (Exception ex) { + } + if (attr_int_id > 0) + try { + H5.H5Aclose(attr_int_id); + } + catch (Exception ex) { + } + if (atype_dbl_id > 0) + try { + H5.H5Tclose(atype_dbl_id); + } + catch (Exception ex) { + } + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + } + } } diff --git a/java/test/TestH5D.java b/java/test/TestH5D.java index 4bab1a9..f7e5702 100644 --- a/java/test/TestH5D.java +++ b/java/test/TestH5D.java @@ -17,6 +17,9 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; @@ -961,8 +964,8 @@ public class TestH5D { assertTrue("H5Dvlen_get_buf_size " + vl_size + " == " + str_data_bytes, vl_size == str_data_bytes); } - @Test(expected = IllegalArgumentException.class) - public void testH5Dvlen_read_invalid_buffer() throws Throwable + @Test + public void testH5Dvlen_read_default_buffer() throws Throwable { String[] str_data = {"Parting", "is such", "sweet", "sorrow.", "Testing", "one", "two", "three.", "Dog,", "man's", "best", "friend.", "Diamonds", "are", "a", "girls!", @@ -1013,4 +1016,218 @@ public class TestH5D { assertTrue("testH5Dvlen_write_read " + str_wdata[v] + " == " + str_rdata[v], str_wdata[v] == str_wdata[v]); } + + @Test + public void testH5DVLwr() + { + String dset_int_name = "VLIntdata"; + String dset_dbl_name = "VLDbldata"; + long dset_int_id = HDF5Constants.H5I_INVALID_HID; + long dset_dbl_id = HDF5Constants.H5I_INVALID_HID; + long dtype_int_id = HDF5Constants.H5I_INVALID_HID; + long dtype_dbl_id = HDF5Constants.H5I_INVALID_HID; + long dspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + + ArrayList[] vl_int_data = new ArrayList[4]; + ArrayList[] vl_dbl_data = new ArrayList[4]; + try { + // Write Integer data + vl_int_data[0] = new ArrayList(Arrays.asList(1)); + vl_int_data[1] = new ArrayList(Arrays.asList(2, 3)); + vl_int_data[2] = new ArrayList(Arrays.asList(4, 5, 6)); + vl_int_data[3] = new ArrayList(Arrays.asList(7, 8, 9, 10)); + Class dataClass = vl_int_data.getClass(); + assertTrue("testH5DVLwr.getClass: " + dataClass, dataClass.isArray()); + + try { + dtype_int_id = H5.H5Tvlen_create(HDF5Constants.H5T_STD_U32LE); + assertTrue("testH5DVLwr.H5Tvlen_create: ", dtype_int_id >= 0); + } + catch (Exception err) { + if (dtype_int_id > 0) + try { + H5.H5Tclose(dtype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5DVLwr: " + err); + } + + try { + dspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(dspace_id > 0); + dset_int_id = + H5.H5Dcreate(H5fid, dset_int_name, dtype_int_id, dspace_id, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5DVLwr: ", dset_int_id >= 0); + + H5.H5DwriteVL(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_int_data); + } + catch (Exception err) { + if (dset_int_id > 0) + try { + H5.H5Dclose(dset_int_id); + } + catch (Exception ex) { + } + if (dtype_int_id > 0) + try { + H5.H5Tclose(dtype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5DVLwr: " + err); + } + finally { + if (dspace_id > 0) + try { + H5.H5Sclose(dspace_id); + } + catch (Exception ex) { + } + } + + // Write Double data + vl_dbl_data[0] = new ArrayList(Arrays.asList(1.1)); + vl_dbl_data[1] = new ArrayList(Arrays.asList(2.2, 3.3)); + vl_dbl_data[2] = new ArrayList(Arrays.asList(4.4, 5.5, 6.6)); + vl_dbl_data[3] = new ArrayList(Arrays.asList(7.7, 8.8, 9.9, 10.0)); + dataClass = vl_dbl_data.getClass(); + assertTrue("testH5DVLwr.getClass: " + dataClass, dataClass.isArray()); + + try { + dtype_dbl_id = H5.H5Tvlen_create(HDF5Constants.H5T_NATIVE_DOUBLE); + assertTrue("testH5DVLwr.H5Tvlen_create: ", dtype_dbl_id >= 0); + } + catch (Exception err) { + if (dtype_dbl_id > 0) + try { + H5.H5Tclose(dtype_dbl_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5DVLwr: " + err); + } + + try { + dspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(dspace_id > 0); + dset_dbl_id = + H5.H5Dcreate(H5fid, dset_dbl_name, dtype_dbl_id, dspace_id, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5DVLwr: ", dset_dbl_id >= 0); + + H5.H5DwriteVL(dset_dbl_id, dtype_dbl_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_dbl_data); + } + catch (Exception err) { + if (dset_dbl_id > 0) + try { + H5.H5Dclose(dset_dbl_id); + } + catch (Exception ex) { + } + if (dtype_dbl_id > 0) + try { + H5.H5Tclose(dtype_dbl_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5DVLwr: " + err); + } + finally { + if (dspace_id > 0) + try { + H5.H5Sclose(dspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) { + lsize *= dims[j]; + } + + // Read Integer data + ArrayList[] vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + vl_readbuf[j] = new ArrayList(); + + try { + H5.H5DreadVL(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5DVLwr:" + vl_readbuf[0].get(0), + vl_int_data[0].get(0).equals(vl_readbuf[0].get(0))); + assertTrue("testH5DVLwr:" + vl_readbuf[1].get(0), + vl_int_data[1].get(0).equals(vl_readbuf[1].get(0))); + assertTrue("testH5DVLwr:" + vl_readbuf[2].get(0), + vl_int_data[2].get(0).equals(vl_readbuf[2].get(0))); + assertTrue("testH5DVLwr:" + vl_readbuf[3].get(0), + vl_int_data[3].get(0).equals(vl_readbuf[3].get(0))); + + // Read Double data + vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + vl_readbuf[j] = new ArrayList(); + + try { + H5.H5DreadVL(dset_dbl_id, dtype_dbl_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5DVLwr:" + vl_readbuf[0].get(0), + vl_dbl_data[0].get(0).equals(vl_readbuf[0].get(0))); + assertTrue("testH5DVLwr:" + vl_readbuf[1].get(0), + vl_dbl_data[1].get(0).equals(vl_readbuf[1].get(0))); + assertTrue("testH5DVLwr:" + vl_readbuf[2].get(0), + vl_dbl_data[2].get(0).equals(vl_readbuf[2].get(0))); + assertTrue("testH5DVLwr:" + vl_readbuf[3].get(0), + vl_dbl_data[3].get(0).equals(vl_readbuf[3].get(0))); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5DVLwr: " + err); + } + finally { + if (dset_dbl_id > 0) + try { + H5.H5Dclose(dset_dbl_id); + } + catch (Exception ex) { + } + if (dset_int_id > 0) + try { + H5.H5Dclose(dset_int_id); + } + catch (Exception ex) { + } + if (dtype_dbl_id > 0) + try { + H5.H5Tclose(dtype_dbl_id); + } + catch (Exception ex) { + } + if (dtype_int_id > 0) + try { + H5.H5Tclose(dtype_int_id); + } + catch (Exception ex) { + } + } + } } diff --git a/java/test/TestH5R.java b/java/test/TestH5R.java index a8e7387..54ff9c2 100644 --- a/java/test/TestH5R.java +++ b/java/test/TestH5R.java @@ -19,6 +19,9 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; @@ -407,4 +410,470 @@ public class TestH5R { ref2 = H5.H5Rcreate(H5gid, "/Group1", HDF5Constants.H5R_OBJECT, -1); H5.H5Rdereference(H5gid, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, ref1); } + + @Test + public void testH5RVLattr_ref() + { + String attr_obj_name = "VLObjRefdata"; + String attr_reg_name = "VLRegRefdata"; + long attr_obj_id = HDF5Constants.H5I_INVALID_HID; + long attr_reg_id = HDF5Constants.H5I_INVALID_HID; + long atype_obj_id = HDF5Constants.H5I_INVALID_HID; + long atype_reg_id = HDF5Constants.H5I_INVALID_HID; + long aspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + byte[] ref1 = null; + byte[] ref2 = null; + byte[] ref3 = null; + byte[] ref4 = null; + + try { + // Create reference on dataset + ref1 = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_DATASET_REGION, H5dsid); + assertNotNull(ref1); + ref2 = H5.H5Rcreate(H5gid, "dset2", HDF5Constants.H5R_DATASET_REGION, H5dsid); + assertNotNull(ref2); + ref3 = H5.H5Rcreate(H5gid, "/dset", HDF5Constants.H5R_OBJECT, -1); + assertNotNull(ref3); + + // Create reference on group + ref4 = H5.H5Rcreate(H5gid, "/Group1", HDF5Constants.H5R_OBJECT, -1); + assertNotNull(ref3); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5RVLattr_ref: " + err); + } + + ArrayList[] vl_obj_data = new ArrayList[4]; + ArrayList[] vl_reg_data = new ArrayList[4]; + try { + // Write Object Reference data + vl_obj_data[0] = new ArrayList(Arrays.asList(ref3)); + vl_obj_data[1] = new ArrayList(Arrays.asList(ref3, ref4)); + vl_obj_data[2] = new ArrayList(Arrays.asList(ref3, ref3, ref3)); + vl_obj_data[3] = new ArrayList(Arrays.asList(ref4, ref4, ref4, ref4)); + Class dataClass = vl_obj_data.getClass(); + assertTrue("testH5RVLattr_ref.getClass: " + dataClass, dataClass.isArray()); + + try { + atype_obj_id = H5.H5Tvlen_create(HDF5Constants.H5T_STD_REF_OBJ); + assertTrue("testH5RVLattr_ref.H5Tvlen_create: ", atype_obj_id >= 0); + } + catch (Exception err) { + if (atype_obj_id > 0) + try { + H5.H5Tclose(atype_obj_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5RVLattr_ref: " + err); + } + + try { + aspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(aspace_id > 0); + attr_obj_id = H5.H5Acreate(H5did, attr_obj_name, atype_obj_id, aspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5RVLattr_ref: ", attr_obj_id >= 0); + + H5.H5AwriteVL(attr_obj_id, atype_obj_id, vl_obj_data); + } + catch (Exception err) { + if (attr_obj_id > 0) + try { + H5.H5Aclose(attr_obj_id); + } + catch (Exception ex) { + } + if (atype_obj_id > 0) + try { + H5.H5Tclose(atype_obj_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5RVLattr_ref: " + err); + } + finally { + if (aspace_id > 0) + try { + H5.H5Sclose(aspace_id); + } + catch (Exception ex) { + } + } + + // Write Region Reference data + vl_reg_data[0] = new ArrayList(Arrays.asList(ref1)); + vl_reg_data[1] = new ArrayList(Arrays.asList(ref1, ref2)); + vl_reg_data[2] = new ArrayList(Arrays.asList(ref1, ref1, ref1)); + vl_reg_data[3] = new ArrayList(Arrays.asList(ref2, ref2, ref2, ref2)); + dataClass = vl_reg_data.getClass(); + assertTrue("testH5RVLattr_ref.getClass: " + dataClass, dataClass.isArray()); + + try { + atype_reg_id = H5.H5Tvlen_create(HDF5Constants.H5T_STD_REF_DSETREG); + assertTrue("testH5RVLattr_ref.H5Tvlen_create: ", atype_reg_id >= 0); + } + catch (Exception err) { + if (atype_reg_id > 0) + try { + H5.H5Tclose(atype_reg_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5RVLattr_ref: " + err); + } + + try { + aspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(aspace_id > 0); + attr_reg_id = H5.H5Acreate(H5did, attr_reg_name, atype_reg_id, aspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5RVLattr_ref: ", attr_reg_id >= 0); + + H5.H5AwriteVL(attr_reg_id, atype_reg_id, vl_reg_data); + } + catch (Exception err) { + if (attr_reg_id > 0) + try { + H5.H5Aclose(attr_reg_id); + } + catch (Exception ex) { + } + if (atype_reg_id > 0) + try { + H5.H5Tclose(atype_reg_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5RVLattr_ref: " + err); + } + finally { + if (aspace_id > 0) + try { + H5.H5Sclose(aspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) { + lsize *= dims[j]; + } + + // Read Object Reference data + ArrayList[] vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + vl_readbuf[j] = new ArrayList(); + + try { + H5.H5AreadVL(attr_obj_id, atype_obj_id, vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5RVLattr_ref:" + ((byte[])vl_readbuf[0].get(0))[0], + ((byte[])vl_obj_data[0].get(0))[0] == ((byte[])vl_readbuf[0].get(0))[0]); + assertTrue("testH5RVLattr_ref:" + ((byte[])vl_readbuf[1].get(0))[0], + ((byte[])vl_obj_data[1].get(0))[0] == ((byte[])vl_readbuf[1].get(0))[0]); + assertTrue("testH5RVLattr_ref:" + ((byte[])vl_readbuf[2].get(0))[0], + ((byte[])vl_obj_data[2].get(0))[0] == ((byte[])vl_readbuf[2].get(0))[0]); + assertTrue("testH5RVLattr_ref:" + ((byte[])vl_readbuf[3].get(0))[0], + ((byte[])vl_obj_data[3].get(0))[0] == ((byte[])vl_readbuf[3].get(0))[0]); + + // Read Region Reference data + vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + vl_readbuf[j] = new ArrayList(); + + try { + H5.H5AreadVL(attr_reg_id, atype_reg_id, vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5RVLattr_ref:" + ((byte[])vl_readbuf[0].get(0))[0], + ((byte[])vl_reg_data[0].get(0))[0] == ((byte[])vl_readbuf[0].get(0))[0]); + assertTrue("testH5RVLattr_ref:" + ((byte[])vl_readbuf[1].get(0))[0], + ((byte[])vl_reg_data[1].get(0))[0] == ((byte[])vl_readbuf[1].get(0))[0]); + assertTrue("testH5RVLattr_ref:" + ((byte[])vl_readbuf[2].get(0))[0], + ((byte[])vl_reg_data[2].get(0))[0] == ((byte[])vl_readbuf[2].get(0))[0]); + assertTrue("testH5RVLattr_ref:" + ((byte[])vl_readbuf[3].get(0))[0], + ((byte[])vl_reg_data[3].get(0))[0] == ((byte[])vl_readbuf[3].get(0))[0]); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5RVLattr_ref: " + err); + } + finally { + if (attr_reg_id > 0) + try { + H5.H5Aclose(attr_reg_id); + } + catch (Exception ex) { + } + if (attr_obj_id > 0) + try { + H5.H5Aclose(attr_obj_id); + } + catch (Exception ex) { + } + if (atype_reg_id > 0) + try { + H5.H5Tclose(atype_reg_id); + } + catch (Exception ex) { + } + if (atype_obj_id > 0) + try { + H5.H5Tclose(atype_obj_id); + } + catch (Exception ex) { + } + } + } + + @Test + public void testH5RVLdset_ref() + { + String dset_obj_name = "VLObjRefdata"; + String dset_reg_name = "VLRegRefdata"; + long dset_obj_id = HDF5Constants.H5I_INVALID_HID; + long dset_reg_id = HDF5Constants.H5I_INVALID_HID; + long dtype_obj_id = HDF5Constants.H5I_INVALID_HID; + long dtype_reg_id = HDF5Constants.H5I_INVALID_HID; + long dspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + byte[] ref1 = null; + byte[] ref2 = null; + byte[] ref3 = null; + byte[] ref4 = null; + + try { + // Create reference on dataset + ref1 = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_DATASET_REGION, H5dsid); + assertNotNull(ref1); + ref2 = H5.H5Rcreate(H5gid, "dset2", HDF5Constants.H5R_DATASET_REGION, H5dsid); + assertNotNull(ref2); + ref3 = H5.H5Rcreate(H5gid, "/dset", HDF5Constants.H5R_OBJECT, -1); + assertNotNull(ref3); + + // Create reference on group + ref4 = H5.H5Rcreate(H5gid, "/Group1", HDF5Constants.H5R_OBJECT, -1); + assertNotNull(ref3); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5RVLattr_ref: " + err); + } + + ArrayList[] vl_obj_data = new ArrayList[4]; + ArrayList[] vl_reg_data = new ArrayList[4]; + try { + // Write Object Reference data + vl_obj_data[0] = new ArrayList(Arrays.asList(ref3)); + vl_obj_data[1] = new ArrayList(Arrays.asList(ref3, ref4)); + vl_obj_data[2] = new ArrayList(Arrays.asList(ref3, ref3, ref3)); + vl_obj_data[3] = new ArrayList(Arrays.asList(ref4, ref4, ref4, ref4)); + Class dataClass = vl_obj_data.getClass(); + assertTrue("testH5RVLdset_ref.getClass: " + dataClass, dataClass.isArray()); + + try { + dtype_obj_id = H5.H5Tvlen_create(HDF5Constants.H5T_STD_REF_OBJ); + assertTrue("testH5RVLdset_ref.H5Tvlen_create: ", dtype_obj_id >= 0); + } + catch (Exception err) { + if (dtype_obj_id > 0) + try { + H5.H5Tclose(dtype_obj_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5RVLdset_ref: " + err); + } + + try { + dspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(dspace_id > 0); + dset_obj_id = + H5.H5Dcreate(H5fid, dset_obj_name, dtype_obj_id, dspace_id, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5RVLdset_ref: ", dset_obj_id >= 0); + + H5.H5DwriteVL(dset_obj_id, dtype_obj_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_obj_data); + } + catch (Exception err) { + if (dset_obj_id > 0) + try { + H5.H5Dclose(dset_obj_id); + } + catch (Exception ex) { + } + if (dtype_obj_id > 0) + try { + H5.H5Tclose(dtype_obj_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5RVLdset_ref: " + err); + } + finally { + if (dspace_id > 0) + try { + H5.H5Sclose(dspace_id); + } + catch (Exception ex) { + } + } + + // Write Region Reference data + vl_reg_data[0] = new ArrayList(Arrays.asList(ref1)); + vl_reg_data[1] = new ArrayList(Arrays.asList(ref1, ref2)); + vl_reg_data[2] = new ArrayList(Arrays.asList(ref1, ref1, ref1)); + vl_reg_data[3] = new ArrayList(Arrays.asList(ref2, ref2, ref2, ref2)); + dataClass = vl_reg_data.getClass(); + assertTrue("testH5RVLdset_ref.getClass: " + dataClass, dataClass.isArray()); + + try { + dtype_reg_id = H5.H5Tvlen_create(HDF5Constants.H5T_STD_REF_DSETREG); + assertTrue("testH5RVLdset_ref.H5Tvlen_create: ", dtype_reg_id >= 0); + } + catch (Exception err) { + if (dtype_reg_id > 0) + try { + H5.H5Tclose(dtype_reg_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5RVLdset_ref: " + err); + } + + try { + dspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(dspace_id > 0); + dset_reg_id = + H5.H5Dcreate(H5fid, dset_reg_name, dtype_reg_id, dspace_id, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5RVLdset_ref: ", dset_reg_id >= 0); + + H5.H5DwriteVL(dset_reg_id, dtype_reg_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_reg_data); + } + catch (Exception err) { + if (dset_reg_id > 0) + try { + H5.H5Dclose(dset_reg_id); + } + catch (Exception ex) { + } + if (dtype_reg_id > 0) + try { + H5.H5Tclose(dtype_reg_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5RVLdset_ref: " + err); + } + finally { + if (dspace_id > 0) + try { + H5.H5Sclose(dspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) { + lsize *= dims[j]; + } + + // Read Object Reference data + ArrayList[] vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + vl_readbuf[j] = new ArrayList(); + + try { + H5.H5DreadVL(dset_obj_id, dtype_obj_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5RVLdset_ref:" + ((byte[])vl_readbuf[0].get(0))[0], + ((byte[])vl_obj_data[0].get(0))[0] == ((byte[])vl_readbuf[0].get(0))[0]); + assertTrue("testH5RVLdset_ref:" + ((byte[])vl_readbuf[1].get(0))[0], + ((byte[])vl_obj_data[1].get(0))[0] == ((byte[])vl_readbuf[1].get(0))[0]); + assertTrue("testH5RVLdset_ref:" + ((byte[])vl_readbuf[2].get(0))[0], + ((byte[])vl_obj_data[2].get(0))[0] == ((byte[])vl_readbuf[2].get(0))[0]); + assertTrue("testH5RVLdset_ref:" + ((byte[])vl_readbuf[3].get(0))[0], + ((byte[])vl_obj_data[3].get(0))[0] == ((byte[])vl_readbuf[3].get(0))[0]); + + // Read Region Reference data + vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + vl_readbuf[j] = new ArrayList(); + + try { + H5.H5DreadVL(dset_reg_id, dtype_reg_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5RVLdset_ref:" + ((byte[])vl_readbuf[0].get(0))[0], + ((byte[])vl_reg_data[0].get(0))[0] == ((byte[])vl_readbuf[0].get(0))[0]); + assertTrue("testH5RVLdset_ref:" + ((byte[])vl_readbuf[1].get(0))[0], + ((byte[])vl_reg_data[1].get(0))[0] == ((byte[])vl_readbuf[1].get(0))[0]); + assertTrue("testH5RVLdset_ref:" + ((byte[])vl_readbuf[2].get(0))[0], + ((byte[])vl_reg_data[2].get(0))[0] == ((byte[])vl_readbuf[2].get(0))[0]); + assertTrue("testH5RVLdset_ref:" + ((byte[])vl_readbuf[3].get(0))[0], + ((byte[])vl_reg_data[3].get(0))[0] == ((byte[])vl_readbuf[3].get(0))[0]); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5RVLdset_ref: " + err); + } + finally { + if (dset_reg_id > 0) + try { + H5.H5Dclose(dset_reg_id); + } + catch (Exception ex) { + } + if (dset_obj_id > 0) + try { + H5.H5Dclose(dset_obj_id); + } + catch (Exception ex) { + } + if (dtype_reg_id > 0) + try { + H5.H5Tclose(dtype_reg_id); + } + catch (Exception ex) { + } + if (dtype_obj_id > 0) + try { + H5.H5Tclose(dtype_obj_id); + } + catch (Exception ex) { + } + } + } } diff --git a/java/test/testfiles/JUnit-TestH5A.txt b/java/test/testfiles/JUnit-TestH5A.txt index 2026d21..efdd4a2 100644 --- a/java/test/testfiles/JUnit-TestH5A.txt +++ b/java/test/testfiles/JUnit-TestH5A.txt @@ -6,6 +6,7 @@ JUnit version 4.11 .testH5Aiterate .testH5Aopen_by_idx .testH5Aopen_invalidname +.testH5AVLwr .testH5Aopen .testH5Aget_info_by_name .testH5Aget_create_plist @@ -30,5 +31,5 @@ JUnit version 4.11 Time: XXXX -OK (28 tests) +OK (29 tests) diff --git a/java/test/testfiles/JUnit-TestH5D.txt b/java/test/testfiles/JUnit-TestH5D.txt index 987655b..288e6d0 100644 --- a/java/test/testfiles/JUnit-TestH5D.txt +++ b/java/test/testfiles/JUnit-TestH5D.txt @@ -4,6 +4,7 @@ JUnit version 4.11 .testH5Dcreate .testH5Dget_offset .testH5Dget_type +.testH5DVLwr .testH5Dfill .testH5Dopen .testH5Dcreate_anon @@ -11,15 +12,15 @@ JUnit version 4.11 .testH5Dget_storage_size_empty .testH5Diterate .testH5Dget_access_plist -.testH5Dvlen_read_invalid_buffer .testH5Dvlen_get_buf_size .testH5Dget_space_closed .testH5Dget_space_status .testH5Dvlen_write_read .testH5Dget_space .testH5Dget_type_closed +.testH5Dvlen_read_default_buffer Time: XXXX -OK (19 tests) +OK (20 tests) diff --git a/java/test/testfiles/JUnit-TestH5R.txt b/java/test/testfiles/JUnit-TestH5R.txt index 150df54..ecdd322 100644 --- a/java/test/testfiles/JUnit-TestH5R.txt +++ b/java/test/testfiles/JUnit-TestH5R.txt @@ -2,6 +2,8 @@ JUnit version 4.11 .testH5Rgetregion_Nullreference .testH5Rget_obj_type2_Invalidreftype .testH5Rdereference +.testH5RVLdset_ref +.testH5RVLattr_ref .testH5Rget_name .testH5Rcreate_Invalidreftype .testH5Rget_name_NULLreference @@ -19,5 +21,5 @@ JUnit version 4.11 Time: XXXX -OK (17 tests) +OK (19 tests) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 85ccf45..eb94be8 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -74,7 +74,38 @@ New Features Java Library: ------------- - - + - Added reference support to H5A and H5D read write vlen JNI functions. + + Added the implementation to handle VL references as an Array of Lists + of byte arrays. + + The JNI wrappers translate the Array of Lists to/from the hvl_t vlen + structures. The wrappers use the specified datatype arguments for the + List type translation, it is expected that the Java type is correct. + + (ADB - 2022/07/11, HDFFV-11318) + + - H5A and H5D read write vlen JNI functions were incorrect. + + Corrected the vlen function implementations for the basic primitive types. + The VLStrings functions now correctly use the implementation that had been + the VL functions. (VLStrings functions did not have an implementation.) + The new VL functions implementation now expect an Array of Lists between + Java and the JNI wrapper. + + The JNI wrappers translate the Array of Lists to/from the hvl_t vlen + structures. The wrappers use the specified datatype arguments for the + List type translation, it is expected that the Java type is correct. + + (ADB - 2022/07/07, HDFFV-11310) + + - H5A and H5D read write JNI functions had flawed vlen datatype check. + + Adapted tools function for JNI utils file. This reduced multiple calls + to a single check and variable. The variable can then be used to call + the H5Treclaim function. Adjusted existing test and added new test. + + (ADB - 2022/06/22) Tools: -- cgit v0.12