summaryrefslogtreecommitdiffstats
path: root/java/src/jni/h5aImp.c
diff options
context:
space:
mode:
authorAllen Byrne <50328838+byrnHDF@users.noreply.github.com>2022-07-18 17:23:37 (GMT)
committerGitHub <noreply@github.com>2022-07-18 17:23:37 (GMT)
commitf6997681335f0b5fe2e8904f9108a71c5200fb2d (patch)
treeedc5aabdcae1035ce6e888bde550e15b1ad2e878 /java/src/jni/h5aImp.c
parent7f9a5f0b6e58e9c04a18ea83ff0400f95294c6ac (diff)
downloadhdf5-f6997681335f0b5fe2e8904f9108a71c5200fb2d.zip
hdf5-f6997681335f0b5fe2e8904f9108a71c5200fb2d.tar.gz
hdf5-f6997681335f0b5fe2e8904f9108a71c5200fb2d.tar.bz2
1.12 eliminate unnecessary errors in the error stack (#1880)
* Eliminate unnecessary error output * Fix merge typo * fix format * Fix object address to tokens * Fix conflict
Diffstat (limited to 'java/src/jni/h5aImp.c')
-rw-r--r--java/src/jni/h5aImp.c818
1 files changed, 136 insertions, 682 deletions
diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c
index 32bae07..6bf86d0 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,10 +158,7 @@ Java_hdf_hdf5lib_H5_H5Aread(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_t
{
jboolean readBufIsCopy;
jbyte * readBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -169,20 +166,18 @@ 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 ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 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);
- }
+ /* Recursively detect any vlen string in type (compound, array ...) */
+ if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: variable length type not supported");
if (isCriticalPinning) {
PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy,
@@ -192,17 +187,11 @@ 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, (void *)readBuf)) < 0)
+ if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, readBuf)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
done:
if (readBuf) {
- if ((status >= 0) && vl_data_class) {
- H5Treclaim(attr_id, sid, H5P_DEFAULT, readBuf);
- if (sid >= 0)
- H5Sclose(sid);
- }
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -225,10 +214,7 @@ Java_hdf_hdf5lib_H5_H5Awrite(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_
{
jboolean writeBufIsCopy;
jbyte * writeBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -236,19 +222,19 @@ 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");
- /* 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)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: 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 (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: variable length type not supported");
+
if (isCriticalPinning) {
PIN_BYTE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy,
"H5Awrite: write buffer not critically pinned");
@@ -262,9 +248,6 @@ Java_hdf_hdf5lib_H5_H5Awrite(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_
done:
if (writeBuf) {
- if ((status >= 0) && vl_data_class)
- H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf);
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -287,10 +270,7 @@ Java_hdf_hdf5lib_H5_H5Aread_1short(JNIEnv *env, jclass clss, jlong attr_id, jlon
{
jboolean readBufIsCopy;
jshort * readBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -298,20 +278,18 @@ 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 ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 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);
- }
+ /* Recursively detect any vlen string in type (compound, array ...) */
+ if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_short: variable length type not supported");
if (isCriticalPinning) {
PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy,
@@ -326,12 +304,6 @@ Java_hdf_hdf5lib_H5_H5Aread_1short(JNIEnv *env, jclass clss, jlong attr_id, jlon
done:
if (readBuf) {
- if ((status >= 0) && vl_data_class) {
- H5Treclaim(attr_id, sid, H5P_DEFAULT, readBuf);
- if (sid >= 0)
- H5Sclose(sid);
- }
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -354,10 +326,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1short(JNIEnv *env, jclass clss, jlong attr_id, jlo
{
jboolean writeBufIsCopy;
jshort * writeBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -365,19 +334,19 @@ 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");
- /* 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)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_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 (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_short: variable length type not supported");
+
if (isCriticalPinning) {
PIN_SHORT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy,
"H5Awrite_short: write buffer not critically pinned");
@@ -391,9 +360,6 @@ Java_hdf_hdf5lib_H5_H5Awrite_1short(JNIEnv *env, jclass clss, jlong attr_id, jlo
done:
if (writeBuf) {
- if ((status >= 0) && vl_data_class)
- H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf);
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -415,32 +381,27 @@ 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;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
- herr_t status = FAIL;
+ herr_t status = FAIL;
UNUSED(clss);
if (buf == NULL)
H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: read buffer is NULL");
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 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);
- }
+ /* Recursively detect any vlen string in type (compound, array ...) */
+ if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_int: variable length type not supported");
if (isCriticalPinning) {
PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy,
@@ -455,12 +416,6 @@ Java_hdf_hdf5lib_H5_H5Aread_1int(JNIEnv *env, jclass clss, jlong attr_id, jlong
done:
if (readBuf) {
- if ((status >= 0) && vl_data_class) {
- H5Treclaim(attr_id, sid, H5P_DEFAULT, readBuf);
- if (sid >= 0)
- H5Sclose(sid);
- }
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -483,10 +438,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1int(JNIEnv *env, jclass clss, jlong attr_id, jlong
{
jboolean writeBufIsCopy;
jint * writeBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -494,19 +446,19 @@ 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");
- /* 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)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_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 (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_int: variable length type not supported");
+
if (isCriticalPinning) {
PIN_INT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy,
"H5Awrite_int: write buffer not critically pinned");
@@ -520,9 +472,6 @@ Java_hdf_hdf5lib_H5_H5Awrite_1int(JNIEnv *env, jclass clss, jlong attr_id, jlong
done:
if (writeBuf) {
- if ((status >= 0) && vl_data_class)
- H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf);
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -545,10 +494,7 @@ Java_hdf_hdf5lib_H5_H5Aread_1long(JNIEnv *env, jclass clss, jlong attr_id, jlong
{
jboolean readBufIsCopy;
jlong * readBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -556,20 +502,18 @@ 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 ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 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);
- }
+ /* Recursively detect any vlen string in type (compound, array ...) */
+ if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_long: variable length type not supported");
if (isCriticalPinning) {
PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy,
@@ -584,12 +528,6 @@ Java_hdf_hdf5lib_H5_H5Aread_1long(JNIEnv *env, jclass clss, jlong attr_id, jlong
done:
if (readBuf) {
- if ((status >= 0) && vl_data_class) {
- H5Treclaim(attr_id, sid, H5P_DEFAULT, readBuf);
- if (sid >= 0)
- H5Sclose(sid);
- }
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -612,10 +550,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1long(JNIEnv *env, jclass clss, jlong attr_id, jlon
{
jboolean writeBufIsCopy;
jlong * writeBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -623,19 +558,19 @@ 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");
- /* 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)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_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 (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_long: variable length type not supported");
+
if (isCriticalPinning) {
PIN_LONG_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy,
"H5Awrite_long: write buffer not critically pinned");
@@ -649,9 +584,6 @@ Java_hdf_hdf5lib_H5_H5Awrite_1long(JNIEnv *env, jclass clss, jlong attr_id, jlon
done:
if (writeBuf) {
- if ((status >= 0) && vl_data_class)
- H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf);
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -674,10 +606,7 @@ Java_hdf_hdf5lib_H5_H5Aread_1float(JNIEnv *env, jclass clss, jlong attr_id, jlon
{
jboolean readBufIsCopy;
jfloat * readBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -685,20 +614,18 @@ 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 ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 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);
- }
+ /* Recursively detect any vlen string in type (compound, array ...) */
+ if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_float: variable length type not supported");
if (isCriticalPinning) {
PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy,
@@ -713,12 +640,6 @@ Java_hdf_hdf5lib_H5_H5Aread_1float(JNIEnv *env, jclass clss, jlong attr_id, jlon
done:
if (readBuf) {
- if ((status >= 0) && vl_data_class) {
- H5Treclaim(attr_id, sid, H5P_DEFAULT, readBuf);
- if (sid >= 0)
- H5Sclose(sid);
- }
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -741,10 +662,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1float(JNIEnv *env, jclass clss, jlong attr_id, jlo
{
jboolean writeBufIsCopy;
jfloat * writeBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -752,19 +670,19 @@ 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");
- /* 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)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_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 (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_float: variable length type not supported");
+
if (isCriticalPinning) {
PIN_FLOAT_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy,
"H5Awrite_float: write buffer not critically pinned");
@@ -778,9 +696,6 @@ Java_hdf_hdf5lib_H5_H5Awrite_1float(JNIEnv *env, jclass clss, jlong attr_id, jlo
done:
if (writeBuf) {
- if ((status >= 0) && vl_data_class)
- H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf);
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -803,10 +718,7 @@ Java_hdf_hdf5lib_H5_H5Aread_1double(JNIEnv *env, jclass clss, jlong attr_id, jlo
{
jboolean readBufIsCopy;
jdouble *readBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -814,20 +726,18 @@ 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 ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 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);
- }
+ /* Recursively detect any vlen string in type (compound, array ...) */
+ if ((data_class = H5Tdetect_variable_str(mem_type_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_double: variable length type not supported");
if (isCriticalPinning) {
PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, readBuf, &readBufIsCopy,
@@ -842,12 +752,6 @@ Java_hdf_hdf5lib_H5_H5Aread_1double(JNIEnv *env, jclass clss, jlong attr_id, jlo
done:
if (readBuf) {
- if ((status >= 0) && vl_data_class) {
- H5Treclaim(attr_id, sid, H5P_DEFAULT, readBuf);
- if (sid >= 0)
- H5Sclose(sid);
- }
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -870,10 +774,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1double(JNIEnv *env, jclass clss, jlong attr_id, jl
{
jboolean writeBufIsCopy;
jdouble *writeBuf = NULL;
- hsize_t dims[H5S_MAX_RANK];
- hid_t sid = H5I_INVALID_HID;
- jsize n;
- htri_t vl_data_class;
+ htri_t data_class;
herr_t status = FAIL;
UNUSED(clss);
@@ -881,18 +782,19 @@ 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 ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) {
- CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
- H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: buf length < 0");
- }
-
- dims[0] = (hsize_t)n;
- if ((sid = H5Screate_simple(1, dims, NULL)) < 0)
+ if ((data_class = H5Tdetect_class(mem_type_id, H5T_VLEN)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
- if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0)
+ if (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_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 (data_class)
+ H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite_double: variable length type not supported");
+
if (isCriticalPinning) {
PIN_DOUBLE_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, &writeBufIsCopy,
"H5Awrite_double: write buffer not critically pinned");
@@ -906,9 +808,6 @@ Java_hdf_hdf5lib_H5_H5Awrite_1double(JNIEnv *env, jclass clss, jlong attr_id, jl
done:
if (writeBuf) {
- if ((status >= 0) && vl_data_class)
- H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf);
-
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -1059,454 +958,10 @@ done:
/*
* Class: hdf_hdf5lib_H5
* Method: H5AreadVL
- * 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) {
- H5Treclaim(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)
- H5Treclaim(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)
+Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf)
{
H5T_class_t type_class;
htri_t isStr = 0;
@@ -1519,7 +974,7 @@ Java_hdf_hdf5lib_H5_H5Aread_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id,
UNUSED(clss);
if (NULL == buf)
- H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Aread_VLStrings: read buffer is NULL");
+ H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AreadVL: read buffer is NULL");
if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
@@ -1569,7 +1024,7 @@ done:
H5Tclose(nested_tid);
return (jint)status;
-} /* end Java_hdf_hdf5lib_H5_H5Aread_1VLStrings */
+} /* end Java_hdf_hdf5lib_H5_H5Aread_1VL */
/*
* Helper method to read in a buffer of variable-length strings from an HDF5
@@ -1705,12 +1160,11 @@ done:
/*
* Class: hdf_hdf5lib_H5
- * Method: H5Awrite_VLStrings
+ * Method: H5AwriteVL
* Signature: (JJ[Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL
-Java_hdf_hdf5lib_H5_H5Awrite_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id,
- jobjectArray buf)
+Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf)
{
H5T_class_t type_class;
htri_t isStr = 0;
@@ -1723,7 +1177,7 @@ Java_hdf_hdf5lib_H5_H5Awrite_1VLStrings(JNIEnv *env, jclass clss, jlong attr_id,
UNUSED(clss);
if (NULL == buf)
- H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Awrite_VLStrings: write buffer is NULL");
+ H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5AwriteVL: write buffer is NULL");
if ((isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
@@ -1773,7 +1227,7 @@ done:
H5Tclose(nested_tid);
return (jint)status;
-} /* end Java_hdf_hdf5lib_H5_H5Awrite_1VLStrings */
+} /* end Java_hdf_hdf5lib_H5_H5Awrite_1VL */
/*
* Helper method to convert an array of Java strings into a buffer of C-strings.
@@ -1819,7 +1273,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 + 1);
+ HDstrncpy(writeBuf[i], utf8, (size_t)length);
writeBuf[i][length] = '\0';
UNPIN_JAVA_STRING(ENVONLY, obj, utf8);
@@ -1843,8 +1297,8 @@ done:
HDfree(writeBuf);
}
- return status;
-} /* end H5AwriteVL_str */
+ return (jint)status;
+}
/*
* Helper method to convert an array of Java strings into a buffer of
@@ -1931,7 +1385,7 @@ done:
H5Sclose(sid);
return status;
-} /* end H5AwriteVL_asstr */
+} /* end H5AwriteVL_str */
/*
* Class: hdf_hdf5lib_H5