diff options
Diffstat (limited to 'java/src/jni/h5rImp.c')
-rw-r--r-- | java/src/jni/h5rImp.c | 399 |
1 files changed, 189 insertions, 210 deletions
diff --git a/java/src/jni/h5rImp.c b/java/src/jni/h5rImp.c index 5f2b86d..9278113 100644 --- a/java/src/jni/h5rImp.c +++ b/java/src/jni/h5rImp.c @@ -26,8 +26,10 @@ extern "C" { #include "h5jni.h" #include "h5rImp.h" -extern JavaVM *jvm; - +/* + * Pointer to the JNI's Virtual Machine; used for callback functions. + */ +/* extern JavaVM *jvm; */ /* * Class: hdf_hdf5lib_H5 @@ -38,47 +40,42 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Rcreate (JNIEnv *env, jclass clss, jbyteArray ref, jlong loc_id, jstring name, jint ref_type, jlong space_id) { - const char *rName; - herr_t status = -1; - jbyte *refP; - jboolean isCopy2; - - PIN_JAVA_STRING(name, rName); - if (rName != NULL) { - if (ref == NULL) { - h5nullArgument( env, "H5Rcreate: ref is NULL"); - } /* end if */ - else { - if ((ref_type == H5R_OBJECT) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_OBJ_REF_BUF_SIZE) { - h5badArgument( env, "H5Rcreate: ref input array != H5R_OBJ_REF_BUF_SIZE"); - } /* end if */ - else if ((ref_type == H5R_DATASET_REGION) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_DSET_REG_REF_BUF_SIZE) { - h5badArgument( env, "H5Rcreate: region ref input array != H5R_DSET_REG_REF_BUF_SIZE"); - } /* end else if */ - else if ((ref_type != H5R_OBJECT) && (ref_type != H5R_DATASET_REGION)) { - h5badArgument( env, "H5Rcreate: ref_type unknown type "); - } /* end else if */ - else { - refP = (jbyte*)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy2); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rcreate: ref not pinned"); - } /* end if */ - else { - status = H5Rcreate(refP, (hid_t)loc_id, rName, (H5R_type_t)ref_type, (hid_t)space_id); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - UNPIN_JAVA_STRING(name, rName); + const char *refName = NULL; + jboolean isCopy; + jbyte *refBuf = NULL; + jsize refBufLen; + herr_t status = FAIL; + + UNUSED(clss); + + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rcreate: reference is NULL"); + + if ((refBufLen = ENVPTR->GetArrayLength(ENVONLY, ref)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rcreate: ref array length < 0"); } + if ((H5R_OBJECT == ref_type) && (refBufLen != H5R_OBJ_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rcreate: reference input array length != H5R_OBJ_REF_BUF_SIZE") + else if ((H5R_DATASET_REGION == ref_type) && (refBufLen != H5R_DSET_REG_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rcreate: region reference input array length != H5R_DSET_REG_REF_BUF_SIZE") + else if ((H5R_OBJECT != ref_type) && (H5R_DATASET_REGION != ref_type)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rcreate: unknown reference type"); + + PIN_JAVA_STRING(ENVONLY, name, refName, NULL, "H5Rcreate: reference name not pinned"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rcreate: reference buffer not pinned"); + + if ((status = H5Rcreate(refBuf, (hid_t)loc_id, refName, (H5R_type_t)ref_type, (hid_t)space_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, (status < 0) ? JNI_ABORT : 0); + if (refName) + UNPIN_JAVA_STRING(ENVONLY, name, refName); + return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Rcreate */ @@ -91,33 +88,36 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Rdereference (JNIEnv *env, jclass clss, jlong dataset, jlong access_list, jint ref_type, jbyteArray ref) { - jboolean isCopy; - jbyte *refP; - hid_t retVal = -1; - - if (ref == NULL) { - h5nullArgument( env, "H5Rdereference: ref is NULL"); - } /* end if */ - else if ((ref_type == H5R_OBJECT) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_OBJ_REF_BUF_SIZE) { - h5badArgument( env, "H5Rdereference: obj ref input array != H5R_OBJ_REF_BUF_SIZE"); - } /* end else if */ - else if ((ref_type == H5R_DATASET_REGION) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_DSET_REG_REF_BUF_SIZE) { - h5badArgument( env, "H5Rdereference: region ref input array != H5R_DSET_REG_REF_BUF_SIZE"); - } /* end else if */ - else { - refP = (jbyte*)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rderefernce: ref not pinned"); - } /* end if */ - else { - retVal = H5Rdereference2((hid_t)dataset, (hid_t)access_list, (H5R_type_t)ref_type, refP); - - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - - if (retVal < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ + jboolean isCopy; + jbyte *refBuf = NULL; + jsize refBufLen; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); + + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rdereference: reference buffer is NULL"); + + if ((refBufLen = ENVPTR->GetArrayLength(ENVONLY, ref)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rdereference: ref array length < 0"); + } + + if ((H5R_OBJECT == ref_type) && (refBufLen != H5R_OBJ_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rdereference: reference input array length != H5R_OBJ_REF_BUF_SIZE") + else if ((H5R_DATASET_REGION == ref_type) && (refBufLen != H5R_DSET_REG_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rdereference: region reference input array length != H5R_DSET_REG_REF_BUF_SIZE") + else if ((H5R_OBJECT != ref_type) && (H5R_DATASET_REGION != ref_type)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rdereference: unknown reference type"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rderefernce: reference buffer not pinned"); + + if ((retVal = H5Rdereference2((hid_t)dataset, (hid_t)access_list, (H5R_type_t)ref_type, refBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, (retVal < 0) ? JNI_ABORT : 0); return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Rdereference */ @@ -131,33 +131,34 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Rget_1region (JNIEnv *env, jclass clss, jlong dataset, jint ref_type, jbyteArray ref) { - hid_t retVal = -1; - jboolean isCopy; - jbyte *refP; - - if (ref_type != H5R_DATASET_REGION) { - h5badArgument( env, "H5Rget_region: bad ref_type "); - } /* end if */ - else if (ref == NULL) { - h5nullArgument( env, "H5Rget_region: ref is NULL"); - } /* end if */ - else if ( ENVPTR->GetArrayLength(ENVPAR ref) != H5R_DSET_REG_REF_BUF_SIZE) { - h5badArgument( env, "H5Rget_region: region ref input array != H5R_DSET_REG_REF_BUF_SIZE"); - } /* end if */ - else { - refP = (jbyte*)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rget_region: ref not pinned"); - } /* end if */ - else { - retVal = H5Rget_region((hid_t)dataset, (H5R_type_t)ref_type, refP); - - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - - if (retVal < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ + jboolean isCopy; + jbyte *refBuf = NULL; + jsize refBufLen; + hid_t retVal = H5I_INVALID_HID; + + UNUSED(clss); + + if (H5R_DATASET_REGION != ref_type) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_region: bad reference type"); + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rget_region: reference buffer is NULL"); + + if ((refBufLen = ENVPTR->GetArrayLength(ENVONLY, ref)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_region: ref array length < 0"); + } + + if (refBufLen != H5R_DSET_REG_REF_BUF_SIZE) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_region: region reference input array length != H5R_DSET_REG_REF_BUF_SIZE"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rget_region: reference buffer not pinned"); + + if ((retVal = H5Rget_region((hid_t)dataset, (H5R_type_t)ref_type, refBuf)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, (retVal < 0) ? JNI_ABORT : 0); return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Rget_1region */ @@ -171,31 +172,27 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Rget_1obj_1type (JNIEnv *env, jclass clss, jlong loc_id, jint ref_type, jbyteArray ref) { - int retVal =-1; - jboolean isCopy; - jbyte *refP; - H5O_type_t object_info; - - - if (ref == NULL) { - h5nullArgument( env, "H5Rget_object_type: ref is NULL"); - } /* end if */ - else { - refP = (jbyte*)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rget_object_type: ref not pinned"); - } /* end if */ - else { - retVal = H5Rget_obj_type2((hid_t)loc_id, (H5R_type_t)ref_type, refP, &object_info); - if(retVal >= 0) - retVal = object_info; - - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - - if (retVal < 0) - h5libraryError(env); - } /* end else */ - } /* end else */ + H5O_type_t object_info; + jboolean isCopy; + jbyte *refBuf = NULL; + int retVal = -1; + + UNUSED(clss); + + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rget_obj_type: reference buffer is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rget_obj_type: reference buffer not pinned"); + + if ((retVal = H5Rget_obj_type2((hid_t)loc_id, (H5R_type_t)ref_type, refBuf, &object_info)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + if (retVal >= 0) + retVal = object_info; + +done: + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, (retVal < 0) ? JNI_ABORT : 0); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Rget_1obj_1type */ @@ -209,46 +206,33 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Rget_1obj_1type2 (JNIEnv *env, jclass clss, jlong loc_id, jint ref_type, jbyteArray ref, jintArray ref_obj) { + jboolean isCopy, isCopy2; + jbyte *refBuf = NULL; + jint *ref_objP = NULL; + jint status; + int retVal = -1; + + UNUSED(clss); + + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rget_obj_type: reference buffer is NULL"); + if (NULL == ref_obj) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rget_obj_type: reference object is NULL"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rget_obj_type: reference buffer not pinned"); - jint status; - jboolean isCopy; - jbyte *refP; - jint *ref_objP; - int retVal = -1; - - - if (ref == NULL) { - h5nullArgument( env, "H5Rget_object_type: ref is NULL"); - } /* end if */ - else if (ref_obj == NULL) { - h5nullArgument( env, "H5Rget_object_type: ref_obj is NULL"); - } /* end else if */ - else { - refP = (jbyte *)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rget_object_type: ref not pinned"); - } /* end if */ - else { - ref_objP = (jint *)ENVPTR->GetIntArrayElements(ENVPAR ref_obj, &isCopy); - if (ref_objP == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR ref,refP,0); - h5JNIFatalError(env, "H5Rget_object_type: ref_obj not pinned"); - } /* end if */ - else { - status = H5Rget_obj_type2((hid_t)loc_id, (H5R_type_t)ref_type, refP, (H5O_type_t*)ref_objP); - retVal = ref_objP[0]; - - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR ref_obj,ref_objP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - ENVPTR->ReleaseIntArrayElements(ENVPAR ref_obj, ref_objP, 0); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + PIN_INT_ARRAY(ENVONLY, ref_obj, ref_objP, &isCopy2, "H5Rget_obj_type: reference object array not pinned"); + + if ((status = H5Rget_obj_type2((hid_t)loc_id, (H5R_type_t)ref_type, refBuf, (H5O_type_t *)ref_objP)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + + retVal = ref_objP[0]; + +done: + if (ref_objP) + UNPIN_INT_ARRAY(ENVONLY, ref_obj, ref_objP, (status < 0) ? JNI_ABORT : 0); + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, JNI_ABORT); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Rget_1obj_1type2 */ @@ -262,57 +246,52 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5_H5Rget_1name (JNIEnv *env, jclass clss, jlong loc_id, jint ref_type, jbyteArray ref, jobjectArray name, jlong size) { - jlong ret_val = -1; - jbyte *refP; - jboolean isCopy; - char *aName = NULL; - jstring str; - size_t bs; - - bs = (size_t)size; - if (bs <= 0) { - h5badArgument(env, "H5Rget_name: size <= 0"); - } /* end if */ - else if (ref == NULL) { - h5nullArgument(env, "H5Rget_name: ref is NULL"); - } /* end else if */ - else { - if ((ref_type == H5R_OBJECT) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_OBJ_REF_BUF_SIZE) { - h5badArgument(env, "H5Rget_name: obj ref input array != H5R_OBJ_REF_BUF_SIZE"); - } /* end if */ - else if ((ref_type == H5R_DATASET_REGION) - && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_DSET_REG_REF_BUF_SIZE) { - h5badArgument(env, "H5Rget_name: region ref input array != H5R_DSET_REG_REF_BUF_SIZE"); - } /* end else if */ - else { - refP = (jbyte *)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy); - if (refP == NULL) { - h5JNIFatalError(env, "H5Rget_name: ref not pinned"); - } /* end if */ - else { - aName = (char*)HDmalloc(sizeof(char)*bs); - if (aName == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - h5outOfMemory(env, "H5Rget_name: malloc failed"); - } /* end if */ - else { - ret_val = (jlong)H5Rget_name((hid_t)loc_id, (H5R_type_t)ref_type, refP, aName, bs) ; - - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - if (ret_val < 0) { - HDfree(aName); - h5libraryError(env); - } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR aName); - ENVPTR->SetObjectArrayElement(ENVPAR name, 0, str); - - HDfree(aName); - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ - } /* end else */ + jboolean isCopy; + jstring str; + jsize refBufLen; + jbyte *refBuf = NULL; + char *aName = NULL; + jlong ret_val = -1; + + UNUSED(clss); + + if (size <= 0) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: size <= 0"); + if (NULL == ref) + H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: reference buffer is NULL"); + + if ((refBufLen = ENVPTR->GetArrayLength(ENVONLY, ref)) < 0) { + CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: ref array length < 0"); + } + + if ((H5R_OBJECT == ref_type) && (refBufLen != H5R_OBJ_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: reference input array length != H5R_OBJ_REF_BUF_SIZE") + else if ((H5R_DATASET_REGION == ref_type) && (refBufLen != H5R_DSET_REG_REF_BUF_SIZE)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: region reference input array length != H5R_DSET_REG_REF_BUF_SIZE") + else if ((H5R_OBJECT != ref_type) && (H5R_DATASET_REGION != ref_type)) + H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Rget_name: unknown reference type"); + + PIN_BYTE_ARRAY(ENVONLY, ref, refBuf, &isCopy, "H5Rget_name: reference buffer not pinned"); + + if (NULL == (aName = (char *) HDmalloc(sizeof(char) * (size_t)size + 1))) + H5_JNI_FATAL_ERROR(ENVONLY, "H5Rget_name: failed to allocate referenced object name buffer"); + + if ((ret_val = (jlong)H5Rget_name((hid_t)loc_id, (H5R_type_t)ref_type, refBuf, aName, (size_t)size + 1)) < 0) + H5_LIBRARY_ERROR(ENVONLY); + aName[(size_t)size] = '\0'; + + if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, aName))) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + ENVPTR->SetObjectArrayElement(ENVONLY, name, (jsize) 0, str); + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + +done: + if (aName) + HDfree(aName); + if (refBuf) + UNPIN_BYTE_ARRAY(ENVONLY, ref, refBuf, JNI_ABORT); return ret_val; } /* end Java_hdf_hdf5lib_H5_H5Rget_1name */ |