summaryrefslogtreecommitdiffstats
path: root/java/src/jni/h5dImp.c
diff options
context:
space:
mode:
authorLarry Knox <lrknox@hdfgroup.org>2022-07-26 19:30:04 (GMT)
committerGitHub <noreply@github.com>2022-07-26 19:30:04 (GMT)
commitd0739f13c131fd8d85c4b3247c26ca2bca515ece (patch)
treea70ce4e47b6689ae6b9aa5d47c9e143347998a97 /java/src/jni/h5dImp.c
parent6eaa59d2f83a89e9b4808f04caa48d313e658df1 (diff)
downloadhdf5-d0739f13c131fd8d85c4b3247c26ca2bca515ece.zip
hdf5-d0739f13c131fd8d85c4b3247c26ca2bca515ece.tar.gz
hdf5-d0739f13c131fd8d85c4b3247c26ca2bca515ece.tar.bz2
Revert "1.12 eliminate unnecessary errors in the error stack (#1880)" (#1935)
This reverts commit f6997681335f0b5fe2e8904f9108a71c5200fb2d.
Diffstat (limited to 'java/src/jni/h5dImp.c')
-rw-r--r--java/src/jni/h5dImp.c805
1 files changed, 576 insertions, 229 deletions
diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c
index 73b252a..a20bb6c 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)
+ H5Treclaim(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)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -383,7 +381,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);
@@ -391,19 +389,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");
@@ -418,6 +412,9 @@ Java_hdf_hdf5lib_H5_H5Dread_1short(JNIEnv *env, jclass clss, jlong dataset_id, j
done:
if (readBuf) {
+ if ((status >= 0) && vl_data_class)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -441,7 +438,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);
@@ -449,19 +446,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");
@@ -476,6 +469,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1short(JNIEnv *env, jclass clss, jlong dataset_id,
done:
if (writeBuf) {
+ if ((status >= 0) && vl_data_class)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -498,28 +494,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");
@@ -534,6 +526,9 @@ Java_hdf_hdf5lib_H5_H5Dread_1int(JNIEnv *env, jclass clss, jlong dataset_id, jlo
done:
if (readBuf) {
+ if ((status >= 0) && vl_data_class)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -556,28 +551,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");
@@ -592,6 +583,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1int(JNIEnv *env, jclass clss, jlong dataset_id, jl
done:
if (writeBuf) {
+ if ((status >= 0) && vl_data_class)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -614,28 +608,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");
@@ -650,6 +640,9 @@ Java_hdf_hdf5lib_H5_H5Dread_1long(JNIEnv *env, jclass clss, jlong dataset_id, jl
done:
if (readBuf) {
+ if ((status >= 0) && vl_data_class)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -672,28 +665,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");
@@ -708,6 +697,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1long(JNIEnv *env, jclass clss, jlong dataset_id, j
done:
if (writeBuf) {
+ if ((status >= 0) && vl_data_class)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -730,28 +722,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");
@@ -766,6 +754,9 @@ Java_hdf_hdf5lib_H5_H5Dread_1float(JNIEnv *env, jclass clss, jlong dataset_id, j
done:
if (readBuf) {
+ if ((status >= 0) && vl_data_class)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -788,27 +779,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)
+ 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");
-
- /* 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, "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,
@@ -824,6 +811,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1float(JNIEnv *env, jclass clss, jlong dataset_id,
done:
if (writeBuf) {
+ if ((status >= 0) && vl_data_class)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -847,7 +837,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);
@@ -855,19 +845,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");
@@ -882,6 +868,9 @@ Java_hdf_hdf5lib_H5_H5Dread_1double(JNIEnv *env, jclass clss, jlong dataset_id,
done:
if (readBuf) {
+ if ((status >= 0) && vl_data_class)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, readBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, readBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -905,7 +894,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);
@@ -913,19 +902,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");
@@ -940,6 +924,9 @@ Java_hdf_hdf5lib_H5_H5Dwrite_1double(JNIEnv *env, jclass clss, jlong dataset_id,
done:
if (writeBuf) {
+ if ((status >= 0) && vl_data_class)
+ H5Treclaim(dataset_id, mem_space_id, H5P_DEFAULT, writeBuf);
+
if (isCriticalPinning) {
UNPIN_ARRAY_CRITICAL(ENVONLY, buf, writeBuf, (status < 0) ? JNI_ABORT : 0);
}
@@ -1094,13 +1081,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)
+ H5Treclaim(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)
+ H5Treclaim(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;
@@ -1111,7 +1530,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);
@@ -1163,7 +1582,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
@@ -1315,54 +1734,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;
@@ -1375,7 +1755,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);
@@ -1427,7 +1807,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.
@@ -1440,7 +1820,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;
@@ -1512,7 +1892,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;
@@ -1549,7 +1929,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);
/*
@@ -1560,11 +1940,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
@@ -1574,10 +1954,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)
@@ -1585,7 +1965,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) {
H5Treclaim(tid, mem_space, xfer_plist_id, writeBuf);
HDfree(writeBuf);
@@ -1598,39 +1978,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
*/