diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2016-09-14 21:02:43 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2016-09-14 21:02:43 (GMT) |
commit | 7f817fea7c50cea4305bc14fcaf4d80fb3dc42e4 (patch) | |
tree | e18b6cefc2cc51c58ebacec1d6a9051742754f71 /java | |
parent | c1c384878ba58193120c3da804d761542c47bd7d (diff) | |
parent | 052efd9bde06ea2427beffd3ea493cbc53a17608 (diff) | |
download | hdf5-7f817fea7c50cea4305bc14fcaf4d80fb3dc42e4.zip hdf5-7f817fea7c50cea4305bc14fcaf4d80fb3dc42e4.tar.gz hdf5-7f817fea7c50cea4305bc14fcaf4d80fb3dc42e4.tar.bz2 |
Merge branch 'develop' into evict_on_close
Diffstat (limited to 'java')
30 files changed, 1848 insertions, 1681 deletions
diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt index 0440d41..706b196 100644 --- a/java/CMakeLists.txt +++ b/java/CMakeLists.txt @@ -13,6 +13,12 @@ find_package (JNI) INCLUDE_DIRECTORIES ( ${JNI_INCLUDE_DIRS} ) +if (WIN32) + set (HDF_JRE_DIRECTORY "C:/Program Files/Java/jre8") +else (WIN32) + set (HDF_JRE_DIRECTORY "/usr/lib/jvm/jre") +endif (WIN32) + #----------------------------------------------------------------------------- # Include the main src and config directories #----------------------------------------------------------------------------- @@ -61,17 +67,9 @@ install ( #----------------------------------------------------------------------------- option (HDF5_JAVA_PACK_JRE "Package a JRE installer directory" OFF) if (HDF5_JAVA_PACK_JRE) - if (WIN32) - install ( - DIRECTORY "C:/Program Files/Java/jre8" - DESTINATION ${HDF5_INSTALL_BIN_DIR} - USE_SOURCE_PERMISSIONS - ) - else (WIN32) - install ( - DIRECTORY "/usr/lib/jvm/jre" - DESTINATION ${HDF5_INSTALL_BIN_DIR} - USE_SOURCE_PERMISSIONS - ) - endif (WIN32) + install ( + DIRECTORY ${HDF_JRE_DIRECTORY} + DESTINATION ${HDF5_INSTALL_BIN_DIR} + USE_SOURCE_PERMISSIONS + ) endif (HDF5_JAVA_PACK_JRE) diff --git a/java/examples/datasets/CMakeLists.txt b/java/examples/datasets/CMakeLists.txt index 5f5f37c..0ba2331 100644 --- a/java/examples/datasets/CMakeLists.txt +++ b/java/examples/datasets/CMakeLists.txt @@ -63,7 +63,11 @@ endforeach (HDFJAVA_JAR) MACRO (ADD_H5_TEST resultfile resultcode) if (CMAKE_BUILD_TYPE MATCHES Debug) - set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;") + if (WIN32) + set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_D;") + else() + set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;") + endif() endif(CMAKE_BUILD_TYPE MATCHES Debug) add_test ( NAME JAVA_datasets-${resultfile} diff --git a/java/examples/datatypes/CMakeLists.txt b/java/examples/datatypes/CMakeLists.txt index 1e305be..5ab513c 100644 --- a/java/examples/datatypes/CMakeLists.txt +++ b/java/examples/datatypes/CMakeLists.txt @@ -63,7 +63,11 @@ endforeach (HDFJAVA_JAR) MACRO (ADD_H5_TEST resultfile resultcode) if (CMAKE_BUILD_TYPE MATCHES Debug) - set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;") + if (WIN32) + set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_D;") + else() + set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;") + endif() endif(CMAKE_BUILD_TYPE MATCHES Debug) add_test ( NAME JAVA_datatypes-${resultfile} diff --git a/java/examples/datatypes/H5Ex_T_ObjectReference.java b/java/examples/datatypes/H5Ex_T_ObjectReference.java index 3cad6c9..8a09f5b 100644 --- a/java/examples/datatypes/H5Ex_T_ObjectReference.java +++ b/java/examples/datatypes/H5Ex_T_ObjectReference.java @@ -256,11 +256,10 @@ public class H5Ex_T_ObjectReference { object_id = H5.H5Rdereference(dataset_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, dset_data[indx]); object_type = H5.H5Rget_obj_type(dataset_id, HDF5Constants.H5R_OBJECT, dset_data[indx]); } - String[] obj_name = new String[1]; - long name_size = 1; + String obj_name = null; if (object_type >= 0) { // Get the length of the name and retrieve the name. - name_size = 1 + H5.H5Iget_name(object_id, obj_name, name_size); + obj_name = H5.H5Iget_name(object_id); } if ((object_id >= 0) && (object_type >= -1)) { switch (H5G_obj.get(object_type)) { @@ -299,8 +298,7 @@ public class H5Ex_T_ObjectReference { } } // Print the name. - if (name_size > 1) - System.out.println(": " + obj_name[0]); + System.out.println(": " + obj_name); } catch (Exception e) { e.printStackTrace(); diff --git a/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java b/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java index e354029..e366681 100644 --- a/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java +++ b/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java @@ -289,11 +289,10 @@ public class H5Ex_T_ObjectReferenceAttribute { object_id = H5.H5Rdereference(dataset_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, dset_data[indx]); object_type = H5.H5Rget_obj_type(dataset_id, HDF5Constants.H5R_OBJECT, dset_data[indx]); } - String[] obj_name = new String[1]; - long name_size = 1; + String obj_name = null; if (object_type >= 0) { // Get the length of the name and retrieve the name. - name_size = 1 + H5.H5Iget_name(object_id, obj_name, name_size); + obj_name = H5.H5Iget_name(object_id); } if ((object_id >= 0) && (object_type >= -1)) { switch (H5G_obj.get(object_type)) { @@ -332,8 +331,7 @@ public class H5Ex_T_ObjectReferenceAttribute { } } // Print the name. - if (name_size > 1) - System.out.println(": " + obj_name[0]); + System.out.println(": " + obj_name); } catch (Exception e) { e.printStackTrace(); diff --git a/java/examples/groups/CMakeLists.txt b/java/examples/groups/CMakeLists.txt index 1d61614..c23b7d3 100644 --- a/java/examples/groups/CMakeLists.txt +++ b/java/examples/groups/CMakeLists.txt @@ -56,19 +56,17 @@ set (HDF_JAVA_TEST_FILES ) foreach (h5_file ${HDF_JAVA_TEST_FILES}) - set (dest "${PROJECT_BINARY_DIR}/${h5_file}") - #message (STATUS " Copying ${h5_file}") - add_custom_command ( - TARGET H5Ex_G_Visit - POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy_if_different ${PROJECT_SOURCE_DIR}/${h5_file} ${dest} - ) + HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/${h5_file}" "${PROJECT_BINARY_DIR}/${h5_file}" "H5Ex_G_Visit_files") endforeach (h5_file ${HDF_JAVA_TEST_FILES}) +add_custom_target(H5Ex_G_Visit_files ALL COMMENT "Copying files needed by H5Ex_G_Visit tests" DEPENDS ${H5Ex_G_Visit_files_list}) MACRO (ADD_H5_TEST resultfile resultcode) if (CMAKE_BUILD_TYPE MATCHES Debug) - set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;") + if (WIN32) + set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_D;") + else() + set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;") + endif() endif(CMAKE_BUILD_TYPE MATCHES Debug) add_test ( NAME JAVA_groups-${resultfile} diff --git a/java/examples/intro/CMakeLists.txt b/java/examples/intro/CMakeLists.txt index 8679943..6b77382 100644 --- a/java/examples/intro/CMakeLists.txt +++ b/java/examples/intro/CMakeLists.txt @@ -64,7 +64,11 @@ endforeach (example ${HDF_JAVA_OBJECT_EXAMPLES}) MACRO (ADD_H5_TEST resultfile resultcode) if (CMAKE_BUILD_TYPE MATCHES Debug) - set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;") + if (WIN32) + set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_D;") + else() + set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;") + endif() endif(CMAKE_BUILD_TYPE MATCHES Debug) add_test ( NAME JAVA_intro-${resultfile} diff --git a/java/examples/testfiles/examples.datatypes.H5Ex_T_ObjectReference.txt b/java/examples/testfiles/examples.datatypes.H5Ex_T_ObjectReference.txt index 827c042..d8afa56 100644 --- a/java/examples/testfiles/examples.datatypes.H5Ex_T_ObjectReference.txt +++ b/java/examples/testfiles/examples.datatypes.H5Ex_T_ObjectReference.txt @@ -1,4 +1,4 @@ DS1[0]: - ->H5G_GROUP: + ->H5G_GROUP: /G1 DS1[1]: - ->H5G_DATASET: + ->H5G_DATASET: /DS2 diff --git a/java/examples/testfiles/examples.datatypes.H5Ex_T_ObjectReferenceAttribute.txt b/java/examples/testfiles/examples.datatypes.H5Ex_T_ObjectReferenceAttribute.txt index fe3cdc0..3fabd66 100644 --- a/java/examples/testfiles/examples.datatypes.H5Ex_T_ObjectReferenceAttribute.txt +++ b/java/examples/testfiles/examples.datatypes.H5Ex_T_ObjectReferenceAttribute.txt @@ -1,4 +1,4 @@ A1[0]: - ->H5G_GROUP: + ->H5G_GROUP: /G1 A1[1]: - ->H5G_DATASET: + ->H5G_DATASET: /DS2 diff --git a/java/src/hdf/hdf5lib/H5.java b/java/src/hdf/hdf5lib/H5.java index e555a4f..7614292 100644 --- a/java/src/hdf/hdf5lib/H5.java +++ b/java/src/hdf/hdf5lib/H5.java @@ -1061,6 +1061,9 @@ public class H5 implements java.io.Serializable { public synchronized static native int H5AreadVL(long attr_id, long mem_type_id, String[] buf) throws HDF5LibraryException, NullPointerException; + public synchronized static native int H5AreadComplex(long attr_id, long mem_type_id, String[] buf) + throws HDF5LibraryException, NullPointerException; + /** * H5Arename changes the name of attribute that is attached to the object specified by loc_id. The attribute named * old_attr_name is renamed new_attr_name. @@ -3348,8 +3351,22 @@ public class H5 implements java.io.Serializable { public synchronized static native long H5Iget_file_id(long obj_id) throws HDF5LibraryException; - public synchronized static native long H5Iget_name(long obj_id, String[] name, long size) + @Deprecated + public synchronized static native long H5Iget_name_long(long obj_id, String[] name, long size) throws HDF5LibraryException, NullPointerException; + /** + * H5Iget_name_str retrieves the name of an object specified by the identifier, obj_id. + * + * @param obj_id + * IN: Identifier of the object. + * + * @return String for Attribute name. + * + * @exception HDF5LibraryException + * - Error from the HDF-5 Library. + **/ + public synchronized static native String H5Iget_name(long obj_id) + throws HDF5LibraryException; public synchronized static native int H5Iget_ref(long obj_id) throws HDF5LibraryException, NullPointerException; diff --git a/java/src/jni/CMakeLists.txt b/java/src/jni/CMakeLists.txt index ef80072..2e4a821 100644 --- a/java/src/jni/CMakeLists.txt +++ b/java/src/jni/CMakeLists.txt @@ -57,6 +57,9 @@ SET_GLOBAL_VARIABLE (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF H5_SET_LIB_OPTIONS (${HDF5_JAVA_JNI_LIB_TARGET} ${HDF5_JAVA_JNI_LIB_NAME} SHARED ${HDF5_JAVA_PACKAGE_SOVERSION}) if (WIN32) get_filename_component (HDF5_JAVA_JNI_DLL_NAME ${HDF5_JAVA_JNI_LIB_TARGET} NAME_WE) + if (CMAKE_BUILD_TYPE MATCHES Debug) + set (HDF5_JAVA_JNI_DLL_NAME "${HDF5_JAVA_JNI_DLL_NAME}_D") + endif () # message (STATUS "HDF5_JAVA_JNI_DLL_NAME: ${HDF5_JAVA_JNI_DLL_NAME}") if (BUILD_TESTING) add_custom_target (HDF5_JAVA_JNI-Test-Copy ALL diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c index 5af60fb..5af8aae 100644 --- a/java/src/jni/h5aImp.c +++ b/java/src/jni/h5aImp.c @@ -67,14 +67,15 @@ Java_hdf_hdf5lib_H5__1H5Acreate hid_t attr_id = -1; const char *aName; - PIN_JAVA_STRING(name, aName, -1); + PIN_JAVA_STRING(name, aName); + if (aName != NULL) { + attr_id = H5Acreate2((hid_t)loc_id, aName, (hid_t)type_id, (hid_t)space_id, (hid_t)create_plist, (hid_t)H5P_DEFAULT); - attr_id = H5Acreate2((hid_t)loc_id, aName, (hid_t)type_id, (hid_t)space_id, (hid_t)create_plist, (hid_t)H5P_DEFAULT); + UNPIN_JAVA_STRING(name, aName); - UNPIN_JAVA_STRING(name, aName); - - if (attr_id < 0) - h5libraryError(env); + if (attr_id < 0) + h5libraryError(env); + } return (jlong)attr_id; } /* end Java_hdf_hdf5lib_H5__1H5Acreate */ @@ -91,14 +92,15 @@ Java_hdf_hdf5lib_H5__1H5Aopen_1name hid_t attr_id = -1; const char *aName; - PIN_JAVA_STRING(name, aName, -1); + PIN_JAVA_STRING(name, aName); + if (aName != NULL) { + attr_id = H5Aopen_name((hid_t)loc_id, aName); - attr_id = H5Aopen_name((hid_t)loc_id, aName); + UNPIN_JAVA_STRING(name,aName); - UNPIN_JAVA_STRING(name,aName); - - if (attr_id < 0) - h5libraryError(env); + if (attr_id < 0) + h5libraryError(env); + } return (jlong)attr_id; } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1name */ @@ -242,8 +244,7 @@ Java_hdf_hdf5lib_H5_H5Aget_1name ssize_t buf_size; /* get the length of the name */ - buf_size = H5Aget_name((hid_t)attr_id, NULL, 0); - + buf_size = H5Aget_name((hid_t)attr_id, 0, NULL); if (buf_size <= 0) { h5badArgument(env, "H5Aget_name: buf_size <= 0"); } /* end if */ @@ -299,14 +300,15 @@ Java_hdf_hdf5lib_H5_H5Adelete herr_t status = -1; const char *aName; - PIN_JAVA_STRING(name, aName, -1); - - status = H5Adelete((hid_t)loc_id, aName); + PIN_JAVA_STRING(name, aName); + if (aName != NULL) { + status = H5Adelete((hid_t)loc_id, aName); - UNPIN_JAVA_STRING(name, aName); + UNPIN_JAVA_STRING(name, aName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Adelete */ @@ -344,15 +346,16 @@ Java_hdf_hdf5lib_H5__1H5Acreate2 hid_t status = -1; const char *aName; - PIN_JAVA_STRING(name, aName, -1); + PIN_JAVA_STRING(name, aName); + if (aName != NULL) { + status = H5Acreate2((hid_t)loc_id, aName, (hid_t)type_id, + (hid_t)space_id, (hid_t)create_plist, (hid_t)access_plist ); - status = H5Acreate2((hid_t)loc_id, aName, (hid_t)type_id, - (hid_t)space_id, (hid_t)create_plist, (hid_t)access_plist ); + UNPIN_JAVA_STRING(name, aName); - UNPIN_JAVA_STRING(name, aName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Acreate2 */ @@ -371,14 +374,15 @@ Java_hdf_hdf5lib_H5__1H5Aopen hid_t retVal = -1; const char *aName; - PIN_JAVA_STRING(name, aName, -1); + PIN_JAVA_STRING(name, aName); + if (aName != NULL) { + retVal = H5Aopen((hid_t)obj_id, aName, (hid_t)access_plist); - retVal = H5Aopen((hid_t)obj_id, aName, (hid_t)access_plist); + UNPIN_JAVA_STRING(name, aName); - UNPIN_JAVA_STRING(name, aName); - - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Aopen */ @@ -395,15 +399,16 @@ Java_hdf_hdf5lib_H5__1H5Aopen_1by_1idx hid_t retVal = -1; const char *aName; - PIN_JAVA_STRING(name, aName, -1); - - retVal = H5Aopen_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, - (H5_iter_order_t)order, (hsize_t)n, (hid_t)aapl_id, (hid_t)lapl_id); + PIN_JAVA_STRING(name, aName); + if (aName != NULL) { + retVal = H5Aopen_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, + (H5_iter_order_t)order, (hsize_t)n, (hid_t)aapl_id, (hid_t)lapl_id); - UNPIN_JAVA_STRING(name, aName); + UNPIN_JAVA_STRING(name, aName); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1by_1idx */ @@ -421,15 +426,16 @@ Java_hdf_hdf5lib_H5__1H5Acreate_1by_1name const char *aName; const char *attrName; - PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName, -1); - - retVal = H5Acreate_by_name((hid_t)loc_id, aName, attrName, (hid_t)type_id, - (hid_t)space_id, (hid_t)acpl_id, (hid_t)aapl_id, (hid_t)lapl_id); + PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + if (aName != NULL && attrName != NULL) { + retVal = H5Acreate_by_name((hid_t)loc_id, aName, attrName, (hid_t)type_id, + (hid_t)space_id, (hid_t)acpl_id, (hid_t)aapl_id, (hid_t)lapl_id); - UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Acreate_1by_1name */ @@ -443,20 +449,23 @@ JNIEXPORT jboolean JNICALL Java_hdf_hdf5lib_H5_H5Aexists_1by_1name (JNIEnv *env, jclass clss, jlong loc_id, jstring obj_name, jstring attr_name, jlong lapl_id) { - htri_t retVal = -1; + htri_t bval = JNI_FALSE; const char *aName; const char *attrName; - PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName, JNI_FALSE); - - retVal = H5Aexists_by_name((hid_t)loc_id, aName, attrName, (hid_t)lapl_id); + PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + if (aName != NULL && attrName != NULL) { + bval = H5Aexists_by_name((hid_t)loc_id, aName, attrName, (hid_t)lapl_id); - UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); - if (retVal < 0) - h5libraryError(env); + if (bval > 0) + bval = JNI_TRUE; + else if (bval < 0) + h5libraryError(env); + } - return (jboolean)retVal; + return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Aexists_1by_1name */ /* @@ -472,14 +481,15 @@ Java_hdf_hdf5lib_H5_H5Arename const char *oName; const char *nName; - PIN_JAVA_STRING_TWO(old_attr_name, oName, new_attr_name, nName, -1); - - retVal = H5Arename((hid_t)loc_id, oName, nName); + PIN_JAVA_STRING_TWO(old_attr_name, oName, new_attr_name, nName); + if (oName != NULL && nName != NULL) { + retVal = H5Arename((hid_t)loc_id, oName, nName); - UNPIN_JAVA_STRING_TWO(old_attr_name, oName, new_attr_name, nName); + UNPIN_JAVA_STRING_TWO(old_attr_name, oName, new_attr_name, nName); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Arename */ @@ -499,14 +509,15 @@ Java_hdf_hdf5lib_H5_H5Arename_1by_1name const char *oName; const char *nName; - PIN_JAVA_STRING_THREE(obj_name, aName, old_attr_name, oName, new_attr_name, nName, -1); - - retVal = H5Arename_by_name((hid_t)loc_id, aName, oName, nName, (hid_t)lapl_id); + PIN_JAVA_STRING_THREE(obj_name, aName, old_attr_name, oName, new_attr_name, nName); + if (aName != NULL && oName != NULL && nName != NULL) { + retVal = H5Arename_by_name((hid_t)loc_id, aName, oName, nName, (hid_t)lapl_id); - UNPIN_JAVA_STRING_THREE(obj_name, aName, old_attr_name, oName, new_attr_name, nName); + UNPIN_JAVA_STRING_THREE(obj_name, aName, old_attr_name, oName, new_attr_name, nName); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Arename_1by_1name */ @@ -526,44 +537,45 @@ Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx jstring str = NULL; const char *aName; - PIN_JAVA_STRING(obj_name, aName, NULL); + PIN_JAVA_STRING(obj_name, aName); + if (aName != NULL) { + /* get the length of the attribute name */ + status_size = H5Aget_name_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, + (H5_iter_order_t) order, (hsize_t) n, (char*)NULL, (size_t)0, (hid_t)lapl_id); - /* get the length of the attribute name */ - status_size = H5Aget_name_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, - (H5_iter_order_t) order, (hsize_t) n, (char*)NULL, (size_t)0, (hid_t)lapl_id); - - if(status_size < 0) { - UNPIN_JAVA_STRING(obj_name, aName); - h5libraryError(env); - } /* end if */ - else { - buf_size = (size_t)status_size + 1;/* add extra space for the null terminator */ - - aValue = (char*)HDmalloc(sizeof(char) * buf_size); - if (aValue == NULL) { + if(status_size < 0) { UNPIN_JAVA_STRING(obj_name, aName); - h5outOfMemory(env, "H5Aget_name_by_idx: malloc failed "); + h5libraryError(env); } /* end if */ else { - status_size = H5Aget_name_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, - (H5_iter_order_t) order, (hsize_t) n, (char*)aValue, (size_t)buf_size, (hid_t)lapl_id); - - UNPIN_JAVA_STRING(obj_name, aName); + buf_size = (size_t)status_size + 1;/* add extra space for the null terminator */ - if (status_size < 0) { - HDfree(aValue); - h5libraryError(env); + aValue = (char*)HDmalloc(sizeof(char) * buf_size); + if (aValue == NULL) { + UNPIN_JAVA_STRING(obj_name, aName); + h5outOfMemory(env, "H5Aget_name_by_idx: malloc failed "); } /* end if */ else { - str = ENVPTR->NewStringUTF(ENVPAR aValue); - HDfree(aValue); - if (str == NULL) { - /* exception -- fatal JNI error */ - h5JNIFatalError(env, "H5Aget_name_by_idx: return string not created"); + status_size = H5Aget_name_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, + (H5_iter_order_t) order, (hsize_t) n, (char*)aValue, (size_t)buf_size, (hid_t)lapl_id); + + UNPIN_JAVA_STRING(obj_name, aName); + + if (status_size < 0) { + HDfree(aValue); + h5libraryError(env); } /* end if */ + else { + str = ENVPTR->NewStringUTF(ENVPAR aValue); + HDfree(aValue); + if (str == NULL) { + /* exception -- fatal JNI error */ + h5JNIFatalError(env, "H5Aget_name_by_idx: return string not created"); + } /* end if */ + } /* end else */ } /* end else */ } /* end else */ - } /* end else */ + } return str; } /* end Java_hdf_hdf5lib_H5_H5Aget_1name_1by_1idx */ @@ -628,23 +640,24 @@ Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1idx jobject ret_obj = NULL; const char *aName; - PIN_JAVA_STRING(obj_name, aName, NULL); + PIN_JAVA_STRING(obj_name, aName); + if (aName != NULL) { + status = H5Aget_info_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, + (H5_iter_order_t)order, (hsize_t)n, &ainfo, (hid_t)lapl_id); - status = H5Aget_info_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, - (H5_iter_order_t)order, (hsize_t)n, &ainfo, (hid_t)lapl_id); - - UNPIN_JAVA_STRING(obj_name, aName); + UNPIN_JAVA_STRING(obj_name, aName); - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].z = ainfo.corder_valid; - args[1].j = ainfo.corder; - args[2].i = ainfo.cset; - args[3].j = (jlong)ainfo.data_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args); - } /* end else */ + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + args[0].z = ainfo.corder_valid; + args[1].j = ainfo.corder; + args[2].i = ainfo.cset; + args[3].j = (jlong)ainfo.data_size; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args); + } /* end else */ + } return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1idx */ @@ -664,22 +677,23 @@ Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1name jvalue args[4]; jobject ret_obj = NULL; - PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName, NULL); + PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + if (aName != NULL && attrName != NULL) { + status = H5Aget_info_by_name((hid_t)loc_id, aName, attrName, &ainfo, (hid_t)lapl_id); - status = H5Aget_info_by_name((hid_t)loc_id, aName, attrName, &ainfo, (hid_t)lapl_id); + UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); - UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); - - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].z = ainfo.corder_valid; - args[1].j = ainfo.corder; - args[2].i = ainfo.cset; - args[3].j = (jlong)ainfo.data_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args); - } /* end else */ + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + args[0].z = ainfo.corder_valid; + args[1].j = ainfo.corder; + args[2].i = ainfo.cset; + args[3].j = (jlong)ainfo.data_size; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5A_info_t", "(ZJIJ)V", args); + } /* end else */ + } return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Aget_1info_1by_1name */ @@ -696,14 +710,15 @@ Java_hdf_hdf5lib_H5_H5Adelete_1by_1name const char *aName; const char *attrName; - PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName, -1); - - retVal = H5Adelete_by_name((hid_t)loc_id, aName, attrName, (hid_t)lapl_id); + PIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + if (aName != NULL && attrName != NULL) { + retVal = H5Adelete_by_name((hid_t)loc_id, aName, attrName, (hid_t)lapl_id); - UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); + UNPIN_JAVA_STRING_TWO(obj_name, aName, attr_name, attrName); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Adelete_1by_1name */ @@ -720,16 +735,17 @@ Java_hdf_hdf5lib_H5_H5Aexists htri_t bval = JNI_FALSE; const char *aName; - PIN_JAVA_STRING(attr_name, aName, JNI_FALSE); + PIN_JAVA_STRING(attr_name, aName); + if (aName != NULL) { + bval = H5Aexists((hid_t)obj_id, aName); - bval = H5Aexists((hid_t)obj_id, aName); + UNPIN_JAVA_STRING(attr_name, aName); - UNPIN_JAVA_STRING(attr_name, aName); - - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + if (bval > 0) + bval = JNI_TRUE; + else if (bval < 0) + h5libraryError(env); + } return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Aexists */ @@ -746,14 +762,15 @@ Java_hdf_hdf5lib_H5_H5Adelete_1by_1idx herr_t status = -1; const char *aName; - PIN_JAVA_STRING0(obj_name, aName); - - status = H5Adelete_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t)n, (hid_t)lapl_id); + PIN_JAVA_STRING(obj_name, aName); + if (aName != NULL) { + status = H5Adelete_by_idx((hid_t)loc_id, aName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t)n, (hid_t)lapl_id); - UNPIN_JAVA_STRING(obj_name, aName); + UNPIN_JAVA_STRING(obj_name, aName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Adelete_1by_1idx */ /* @@ -770,14 +787,15 @@ Java_hdf_hdf5lib_H5__1H5Aopen_1by_1name const char *aName; const char *oName; - PIN_JAVA_STRING_TWO(obj_name, oName, attr_name, aName, -1); - - status = H5Aopen_by_name((hid_t)loc_id, oName, aName, (hid_t)aapl_id, (hid_t)lapl_id); + PIN_JAVA_STRING_TWO(obj_name, oName, attr_name, aName); + if (oName != NULL && aName != NULL) { + status = H5Aopen_by_name((hid_t)loc_id, oName, aName, (hid_t)aapl_id, (hid_t)lapl_id); - UNPIN_JAVA_STRING_TWO(obj_name, oName, attr_name, aName); + UNPIN_JAVA_STRING_TWO(obj_name, oName, attr_name, aName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Aopen_1by_1name */ @@ -892,14 +910,15 @@ Java_hdf_hdf5lib_H5_H5Aiterate_1by_1name h5nullArgument(env, "H5Literate_by_name: op_data or callback_op is NULL"); } /* end if */ else { - PIN_JAVA_STRING(name, lName, -1); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + status = H5Aiterate_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5A_operator2_t)H5A_iterate_cb, (void*)op_data, (hid_t)access_id); - status = H5Aiterate_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5A_operator2_t)H5A_iterate_cb, (void*)op_data, (hid_t)access_id); + UNPIN_JAVA_STRING(name, lName); - UNPIN_JAVA_STRING(name, lName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end else */ return (jint)status; diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c index 9bcbd5f..ed1db41 100644 --- a/java/src/jni/h5dImp.c +++ b/java/src/jni/h5dImp.c @@ -161,14 +161,15 @@ Java_hdf_hdf5lib_H5__1H5Dcreate hid_t dset_id = -1; const char *fileName; - PIN_JAVA_STRING(name, fileName, -1); + PIN_JAVA_STRING(name, fileName); + if (fileName != NULL) { + dset_id = H5Dcreate2((hid_t)loc_id, fileName, (hid_t)type_id, (hid_t)space_id, H5P_DEFAULT, (hid_t)create_plist_id, H5P_DEFAULT); - dset_id = H5Dcreate2((hid_t)loc_id, fileName, (hid_t)type_id, (hid_t)space_id, H5P_DEFAULT, (hid_t)create_plist_id, H5P_DEFAULT); + UNPIN_JAVA_STRING(name, fileName); - UNPIN_JAVA_STRING(name, fileName); - - if (dset_id < 0) - h5libraryError(env); + if (dset_id < 0) + h5libraryError(env); + } return (jlong)dset_id; } /* end Java_hdf_hdf5lib_H5__1H5Dcreate */ @@ -185,13 +186,14 @@ Java_hdf_hdf5lib_H5__1H5Dopen hid_t dset_id = -1; const char *fileName; - PIN_JAVA_STRING(name, fileName, -1); - - dset_id = H5Dopen2((hid_t)loc_id, fileName, H5P_DEFAULT); + PIN_JAVA_STRING(name, fileName); + if (fileName != NULL) { + dset_id = H5Dopen2((hid_t)loc_id, fileName, H5P_DEFAULT); - UNPIN_JAVA_STRING(name, fileName); - if (dset_id < 0) - h5libraryError(env); + UNPIN_JAVA_STRING(name, fileName); + if (dset_id < 0) + h5libraryError(env); + } return (jlong)dset_id; } /* end Java_hdf_hdf5lib_H5__1H5Dopen */ @@ -285,7 +287,7 @@ Java_hdf_hdf5lib_H5_H5Dread (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jbyteArray buf, jboolean isCriticalPinning) { - herr_t status; + herr_t status = -1; jbyte *buffP; jboolean isCopy; htri_t data_class; @@ -341,7 +343,7 @@ Java_hdf_hdf5lib_H5_H5Dwrite (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jbyteArray buf, jboolean isCriticalPinning) { - herr_t status; + herr_t status = -1; jbyte *buffP; jboolean isCopy; htri_t data_class; @@ -1151,7 +1153,7 @@ Java_hdf_hdf5lib_H5_H5Dread_1VLStrings h5nullArgument(env, "H5Dread_VLStrings: buf is NULL"); } /* end if */ else { - isVlenStr = H5Tis_variable_str((hid_t)mem_type_id); + isVlenStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING); if (isVlenStr) { status = H5DreadVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, @@ -1445,13 +1447,14 @@ Java_hdf_hdf5lib_H5__1H5Dcreate2 hid_t dset_id = -1; const char *fileName; - PIN_JAVA_STRING(name, fileName, -1); - - dset_id = H5Dcreate2((hid_t)loc_id, fileName, (hid_t)type_id, (hid_t)space_id, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id); + PIN_JAVA_STRING(name, fileName); + if (fileName != NULL) { + dset_id = H5Dcreate2((hid_t)loc_id, fileName, (hid_t)type_id, (hid_t)space_id, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id); - UNPIN_JAVA_STRING(name, fileName); - if (dset_id < 0) - h5libraryError(env); + UNPIN_JAVA_STRING(name, fileName); + if (dset_id < 0) + h5libraryError(env); + } return (jlong)dset_id; } /* end Java_hdf_hdf5lib_H5__1H5Dcreate2 */ @@ -1465,16 +1468,17 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Dopen2 (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist) { - hid_t dset_id; + hid_t dset_id = -1; const char *fileName; - PIN_JAVA_STRING(name, fileName, -1); + PIN_JAVA_STRING(name, fileName); + if (fileName != NULL) { + dset_id = H5Dopen2((hid_t)loc_id, fileName, (hid_t)access_plist); - dset_id = H5Dopen2((hid_t)loc_id, fileName, (hid_t)access_plist); - - UNPIN_JAVA_STRING(name, fileName); - if (dset_id < 0) - h5libraryError(env); + UNPIN_JAVA_STRING(name, fileName); + if (dset_id < 0) + h5libraryError(env); + } return (jlong)dset_id; } /* end Java_hdf_hdf5lib_H5__1H5Dopen2 */ @@ -1585,39 +1589,40 @@ Java_hdf_hdf5lib_H5_H5Dfill if (buf == NULL) { h5nullArgument(env, "H5Dfill: buf is NULL"); - return; } /* end if */ - buffP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy2); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Dfill: buf not pinned"); - return; - } /* end if */ - - if(fill) { - fillP = ENVPTR->GetByteArrayElements(ENVPAR fill, &isCopy1); - if (fillP == NULL) { - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, JNI_ABORT); - h5JNIFatalError( env, "H5Dfill: fill not pinned"); - return; + else { + buffP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy2); + if (buffP == NULL) { + h5JNIFatalError(env, "H5Dfill: buf not pinned"); } /* end if */ - } /* end if */ - else - fillP = NULL; + else { + if(fill) { + fillP = ENVPTR->GetByteArrayElements(ENVPAR fill, &isCopy1); + if (fillP == NULL) { + ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, JNI_ABORT); + h5JNIFatalError( env, "H5Dfill: fill not pinned"); + return; + } /* end if */ + } /* end if */ + else + fillP = NULL; - status = H5Dfill((const void*)fillP, (hid_t)fill_type_id, (void*)buffP, (hid_t)buf_type_id, (hid_t)space_id); - if(fillP) { - /* free the buffer without copying back */ - /* end if */ ENVPTR->ReleaseByteArrayElements(ENVPAR fill, fillP, JNI_ABORT); + status = H5Dfill((const void*)fillP, (hid_t)fill_type_id, (void*)buffP, (hid_t)buf_type_id, (hid_t)space_id); + if(fillP) { + /* free the buffer without copying back */ + ENVPTR->ReleaseByteArrayElements(ENVPAR fill, fillP, JNI_ABORT); + } /* end if */ + if (status < 0) { + ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, JNI_ABORT); + h5libraryError(env); + } /* end if */ + else { + if (isCopy2 == JNI_TRUE) { + ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, 0); + } /* end if */ + } /* end else */ + } } - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - if (isCopy2 == JNI_TRUE) { - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, 0); - } /* end if */ - } /* end else */ } /* end Java_hdf_hdf5lib_H5_H5Dfill */ /* @@ -1638,35 +1643,35 @@ Java_hdf_hdf5lib_H5_H5Dset_1extent if (buf == NULL) { h5nullArgument(env, "H5Dset_extent: buf is NULL"); - return; - } /* end if */ - - rank = ENVPTR->GetArrayLength(ENVPAR buf); - if (rank <= 0) { - h5JNIFatalError(env, "H5Dset_extent: rank <=0"); } /* end if */ else { - buffP = ENVPTR->GetLongArrayElements(ENVPAR buf, &isCopy); - if (buffP == NULL) { - h5JNIFatalError( env, "H5Dset_extent: buf not pinned"); + rank = ENVPTR->GetArrayLength(ENVPAR buf); + if (rank <= 0) { + h5JNIFatalError(env, "H5Dset_extent: rank <=0"); } /* end if */ else { - dims = (hsize_t*)HDmalloc((size_t)rank * sizeof(hsize_t)); - for (i = 0; i< rank; i++) - dims[i] = (hsize_t)buffP[i]; + buffP = ENVPTR->GetLongArrayElements(ENVPAR buf, &isCopy); + if (buffP == NULL) { + h5JNIFatalError( env, "H5Dset_extent: buf not pinned"); + } /* end if */ + else { + dims = (hsize_t*)HDmalloc((size_t)rank * sizeof(hsize_t)); + for (i = 0; i< rank; i++) + dims[i] = (hsize_t)buffP[i]; - status = H5Dset_extent((hid_t)loc_id, (hsize_t*)dims); + status = H5Dset_extent((hid_t)loc_id, (hsize_t*)dims); - HDfree (dims); + HDfree (dims); - /* free the buffer without copying back */ - ENVPTR->ReleaseLongArrayElements(ENVPAR buf, buffP, JNI_ABORT); + /* free the buffer without copying back */ + ENVPTR->ReleaseLongArrayElements(ENVPAR buf, buffP, JNI_ABORT); - if (status < 0) { - h5libraryError(env); - } /* end if */ + if (status < 0) { + h5libraryError(env); + } /* end if */ + } /* end else */ } /* end else */ - } /* end else */ + } } /* end Java_hdf_hdf5lib_H5_H5Dset_1extent */ static herr_t @@ -1747,34 +1752,32 @@ Java_hdf_hdf5lib_H5_H5Diterate if (op_data == NULL) { h5nullArgument(env, "H5Diterate: op_data is NULL"); - return -1; } /* end if */ - if (callback_op == NULL) { + else if (callback_op == NULL) { h5nullArgument(env, "H5Diterate: callback_op is NULL"); - return -1; } /* end if */ - - if (buf == NULL) { + else if (buf == NULL) { h5nullArgument(env, "H5Diterate: buf is NULL"); - return -1; - } /* end if */ - buffP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy); - if (buffP == NULL) { - h5JNIFatalError(env, "H5Diterate: buf not pinned"); } /* end if */ else { - status = H5Diterate((void*)buffP, (hid_t)buf_type, (hid_t)space, (H5D_operator_t)H5D_iterate_cb, (void*)op_data); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, JNI_ABORT); - h5libraryError(env); + buffP = ENVPTR->GetByteArrayElements(ENVPAR buf, &isCopy); + if (buffP == NULL) { + h5JNIFatalError(env, "H5Diterate: buf not pinned"); } /* end if */ else { - if (isCopy == JNI_TRUE) { - ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, 0); + status = H5Diterate((void*)buffP, (hid_t)buf_type, (hid_t)space, (H5D_operator_t)H5D_iterate_cb, (void*)op_data); + + if (status < 0) { + ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, JNI_ABORT); + h5libraryError(env); } /* end if */ + else { + if (isCopy == JNI_TRUE) { + ENVPTR->ReleaseByteArrayElements(ENVPAR buf, buffP, 0); + } /* end if */ + } /* end else */ } /* end else */ - } /* end else */ + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Diterate */ @@ -1786,7 +1789,7 @@ Java_hdf_hdf5lib_H5_H5Diterate */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Dflush - (JNIEnv *env, jclass clss, jlong loc_id) + (JNIEnv *env, jclass clss, jlong loc_id) { if (H5Dflush((hid_t)loc_id) < 0) h5libraryError(env); @@ -1799,7 +1802,7 @@ Java_hdf_hdf5lib_H5_H5Dflush */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Drefresh - (JNIEnv *env, jclass clss, jlong loc_id) + (JNIEnv *env, jclass clss, jlong loc_id) { if (H5Drefresh((hid_t)loc_id) < 0) h5libraryError(env); diff --git a/java/src/jni/h5eImp.c b/java/src/jni/h5eImp.c index 84cbacd..6e05515 100644 --- a/java/src/jni/h5eImp.c +++ b/java/src/jni/h5eImp.c @@ -98,14 +98,15 @@ Java_hdf_hdf5lib_H5_H5Eregister_1class const char* the_lib_name; const char* the_version; - PIN_JAVA_STRING_THREE(cls_name, the_cls_name, lib_name, the_lib_name, version, the_version, -1); + PIN_JAVA_STRING_THREE(cls_name, the_cls_name, lib_name, the_lib_name, version, the_version); + if (the_cls_name != NULL && the_lib_name != NULL && the_version != NULL) { + ret_val = H5Eregister_class(the_cls_name, the_lib_name, the_version); - ret_val = H5Eregister_class(the_cls_name, the_lib_name, the_version); + UNPIN_JAVA_STRING_THREE(cls_name, the_cls_name, lib_name, the_lib_name, version, the_version); - UNPIN_JAVA_STRING_THREE(cls_name, the_cls_name, lib_name, the_lib_name, version, the_version); - - if (ret_val < 0) - h5libraryError(env); + if (ret_val < 0) + h5libraryError(env); + } return (jlong)ret_val; } /* end Java_hdf_hdf5lib_H5_H5Eregister_1class */ @@ -159,14 +160,15 @@ Java_hdf_hdf5lib_H5_H5Ecreate_1msg h5badArgument(env, "H5Ecreate_msg: invalid argument"); } /* end if */ else { - PIN_JAVA_STRING(err_msg, the_err_msg, -1); - - ret_val = H5Ecreate_msg((hid_t)err_id, error_msg_type, the_err_msg); + PIN_JAVA_STRING(err_msg, the_err_msg); + if (the_err_msg != NULL) { + ret_val = H5Ecreate_msg((hid_t)err_id, error_msg_type, the_err_msg); - UNPIN_JAVA_STRING(err_msg, the_err_msg); + UNPIN_JAVA_STRING(err_msg, the_err_msg); - if (ret_val < 0) - h5libraryError(env); + if (ret_val < 0) + h5libraryError(env); + } } /* end else */ return (jlong)ret_val; @@ -305,7 +307,7 @@ Java_hdf_hdf5lib_H5_H5Eget_1class_1name */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Eset_1current_1stack - (JNIEnv *env, jclass cls, jlong stk_id) + (JNIEnv *env, jclass cls, jlong stk_id) { if (stk_id < 0) { h5badArgument(env, "H5Eset_current_stack: invalid argument"); @@ -358,15 +360,16 @@ Java_hdf_hdf5lib_H5_H5Epush2 h5badArgument(env, "H5Epush: invalid minor_id argument"); } /* end else if */ else { - PIN_JAVA_STRING_THREE0(filename, fName, funcname, fncName, err_desc, errMsg); + PIN_JAVA_STRING_THREE(filename, fName, funcname, fncName, err_desc, errMsg); + if (fName != NULL && fncName != NULL && errMsg != NULL) { + ret_val = H5Epush2((hid_t)stk_id, fName, fncName, (unsigned)linenumber, (hid_t)class_id, + (hid_t)major_id, (hid_t)minor_id, errMsg); - ret_val = H5Epush2((hid_t)stk_id, fName, fncName, (unsigned)linenumber, (hid_t)class_id, - (hid_t)major_id, (hid_t)minor_id, errMsg); + UNPIN_JAVA_STRING_THREE(filename, fName, funcname, fncName, err_desc, errMsg); - UNPIN_JAVA_STRING_THREE(filename, fName, funcname, fncName, err_desc, errMsg); - - if (ret_val < 0) - h5libraryError(env); + if (ret_val < 0) + h5libraryError(env); + } } /* end else */ } /* end Java_hdf_hdf5lib_H5_H5Epush2 */ diff --git a/java/src/jni/h5fImp.c b/java/src/jni/h5fImp.c index 33a5932..5862ae7 100644 --- a/java/src/jni/h5fImp.c +++ b/java/src/jni/h5fImp.c @@ -45,14 +45,15 @@ Java_hdf_hdf5lib_H5__1H5Fopen hid_t status = -1; const char *fileName; - PIN_JAVA_STRING(name, fileName, -1); + PIN_JAVA_STRING(name, fileName); + if (fileName != NULL) { + status = H5Fopen(fileName, (unsigned)flags, (hid_t)access_id ); - status = H5Fopen(fileName, (unsigned)flags, (hid_t)access_id ); + UNPIN_JAVA_STRING(name, fileName); - UNPIN_JAVA_STRING(name, fileName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Fopen */ @@ -69,14 +70,15 @@ Java_hdf_hdf5lib_H5__1H5Fcreate hid_t status = -1; const char *fileName; - PIN_JAVA_STRING(name, fileName, -1); + PIN_JAVA_STRING(name, fileName); + if (fileName != NULL) { + status = H5Fcreate(fileName, (unsigned)flags, create_id, access_id); - status = H5Fcreate(fileName, (unsigned)flags, create_id, access_id); + UNPIN_JAVA_STRING(name, fileName); - UNPIN_JAVA_STRING(name, fileName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Fcreate */ @@ -152,16 +154,17 @@ Java_hdf_hdf5lib_H5_H5Fis_1hdf5 htri_t bval = JNI_FALSE; const char *fileName; - PIN_JAVA_STRING(name, fileName, JNI_FALSE); - - bval = H5Fis_hdf5(fileName); + PIN_JAVA_STRING(name, fileName); + if (fileName != NULL) { + bval = H5Fis_hdf5(fileName); - UNPIN_JAVA_STRING(name, fileName); + UNPIN_JAVA_STRING(name, fileName); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + if (bval > 0) + bval = JNI_TRUE; + else if (bval < 0) + h5libraryError(env); + } return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Fis_1hdf5 */ @@ -251,14 +254,15 @@ Java_hdf_hdf5lib_H5_H5Fmount herr_t status = -1; const char *fileName; - PIN_JAVA_STRING(name, fileName, -1); - - status = H5Fmount((hid_t)loc_id, fileName, (hid_t)child_id, (hid_t)plist_id); + PIN_JAVA_STRING(name, fileName); + if (fileName != NULL) { + status = H5Fmount((hid_t)loc_id, fileName, (hid_t)child_id, (hid_t)plist_id); - UNPIN_JAVA_STRING(name, fileName); + UNPIN_JAVA_STRING(name, fileName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Fmount */ @@ -275,14 +279,15 @@ Java_hdf_hdf5lib_H5_H5Funmount herr_t status = -1; const char *fileName; - PIN_JAVA_STRING(name, fileName, -1); + PIN_JAVA_STRING(name, fileName); + if (fileName != NULL) { + status = H5Funmount((hid_t)loc_id, fileName); - status = H5Funmount((hid_t)loc_id, fileName); + UNPIN_JAVA_STRING(name, fileName); - UNPIN_JAVA_STRING(name, fileName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Funmount */ diff --git a/java/src/jni/h5gImp.c b/java/src/jni/h5gImp.c index a2c0de0..c40ed64 100644 --- a/java/src/jni/h5gImp.c +++ b/java/src/jni/h5gImp.c @@ -69,33 +69,30 @@ create_H5G_info_t jclass cls; jboolean jmounted; jint storage_type; - jobject obj; + jobject obj = NULL; jfieldID fid_storage_type, fid_nlinks, fid_max_corder, fid_mounted; cls = ENVPTR->FindClass(ENVPAR "hdf/hdf5lib/structs/H5G_info_t"); - if (cls == NULL) - return NULL; - - obj = ENVPTR->AllocObject(ENVPAR cls); - if (obj == NULL) - return NULL; - - fid_storage_type = ENVPTR->GetFieldID(ENVPAR cls, "storage_type", "I"); - fid_nlinks = ENVPTR->GetFieldID(ENVPAR cls, "nlinks", "J"); - fid_max_corder = ENVPTR->GetFieldID(ENVPAR cls, "max_corder", "J"); - fid_mounted = ENVPTR->GetFieldID(ENVPAR cls, "mounted", "Z"); - - if (fid_storage_type==NULL || fid_nlinks==NULL || fid_max_corder==NULL || fid_mounted == NULL) - return NULL; - - jmounted = (group_info.mounted==0) ? JNI_FALSE : JNI_TRUE; - storage_type = (jint)group_info.storage_type; - - ENVPTR->SetIntField(ENVPAR obj, fid_storage_type, (jint)storage_type); - ENVPTR->SetLongField(ENVPAR obj, fid_nlinks, (jlong)group_info.nlinks); - ENVPTR->SetLongField(ENVPAR obj, fid_max_corder, (jlong)group_info.max_corder); - ENVPTR->SetBooleanField(ENVPAR obj, fid_mounted, jmounted); - + if (cls != NULL) { + obj = ENVPTR->AllocObject(ENVPAR cls); + if (obj != NULL) { + if ((fid_storage_type = ENVPTR->GetFieldID(ENVPAR cls, "storage_type", "I")) != NULL) { + if ((fid_nlinks = ENVPTR->GetFieldID(ENVPAR cls, "nlinks", "J")) != NULL) { + if ((fid_max_corder = ENVPTR->GetFieldID(ENVPAR cls, "max_corder", "J")) != NULL) { + if ((fid_mounted = ENVPTR->GetFieldID(ENVPAR cls, "mounted", "Z")) != NULL) { + jmounted = (group_info.mounted==0) ? JNI_FALSE : JNI_TRUE; + storage_type = (jint)group_info.storage_type; + + ENVPTR->SetIntField(ENVPAR obj, fid_storage_type, (jint)storage_type); + ENVPTR->SetLongField(ENVPAR obj, fid_nlinks, (jlong)group_info.nlinks); + ENVPTR->SetLongField(ENVPAR obj, fid_max_corder, (jlong)group_info.max_corder); + ENVPTR->SetBooleanField(ENVPAR obj, fid_mounted, jmounted); + } + } + } + } + } + } return obj; } /* end create_H5G_info_t */ @@ -112,13 +109,14 @@ Java_hdf_hdf5lib_H5__1H5Gcreate2 hid_t group_id = -1; const char *gName; - PIN_JAVA_STRING(name, gName, -1); + PIN_JAVA_STRING(name, gName); + if (gName != NULL) { + group_id = H5Gcreate2((hid_t)loc_id, gName, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id ); - group_id = H5Gcreate2((hid_t)loc_id, gName, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id ); - - UNPIN_JAVA_STRING(name, gName); - if (group_id < 0) - h5libraryError(env); + UNPIN_JAVA_STRING(name, gName); + if (group_id < 0) + h5libraryError(env); + } return (jlong)group_id; } /* end Java_hdf_hdf5lib_H5__1H5Gcreate2 */ @@ -153,14 +151,15 @@ Java_hdf_hdf5lib_H5__1H5Gopen2 hid_t group_id = -1; const char *gName; - PIN_JAVA_STRING(name, gName, -1); + PIN_JAVA_STRING(name, gName); + if (gName != NULL) { + group_id = H5Gopen2((hid_t)loc_id, gName, (hid_t)access_plist_id ); - group_id = H5Gopen2((hid_t)loc_id, gName, (hid_t)access_plist_id ); + UNPIN_JAVA_STRING(name, gName); - UNPIN_JAVA_STRING(name, gName); - - if (group_id < 0) - h5libraryError(env); + if (group_id < 0) + h5libraryError(env); + } return (jlong)group_id; } /* end Java_hdf_hdf5lib_H5__1H5Gopen2 */ @@ -192,14 +191,15 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Gget_1info (JNIEnv *env, jclass cls, jlong loc_id) { + jobject obj = NULL; H5G_info_t group_info; - if (H5Gget_info((hid_t)loc_id, &group_info) < 0) { + if (H5Gget_info((hid_t)loc_id, &group_info) < 0) h5libraryError(env); - return NULL; - } /* end if */ + else + obj = create_H5G_info_t(env, group_info); - return create_H5G_info_t(env, group_info); + return obj; } /* end Java_hdf_hdf5lib_H5_H5Gget_1info */ /* @@ -211,22 +211,24 @@ JNIEXPORT jobject JNICALL Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1name (JNIEnv *env, jclass cls, jlong loc_id, jstring name, jlong lapl_id) { + jobject obj = NULL; herr_t ret_val = -1; const char *gName; H5G_info_t group_info; - PIN_JAVA_STRING(name, gName, NULL); + PIN_JAVA_STRING(name, gName); + if (gName != NULL) { + ret_val = H5Gget_info_by_name((hid_t)loc_id, gName, &group_info, (hid_t)lapl_id); - ret_val = H5Gget_info_by_name((hid_t)loc_id, gName, &group_info, (hid_t)lapl_id); + UNPIN_JAVA_STRING(name, gName); - UNPIN_JAVA_STRING(name, gName); - - if (ret_val < 0) { - h5libraryError(env); - return NULL; - } /* end if */ + if (ret_val < 0) + h5libraryError(env); + else + obj = create_H5G_info_t(env, group_info); + } - return create_H5G_info_t(env, group_info); + return obj; } /* end Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1name */ /* @@ -239,25 +241,27 @@ Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1idx (JNIEnv *env, jclass cls, jlong loc_id, jstring name, jint index_type, jint order, jlong n, jlong lapl_id) { + jobject obj = NULL; herr_t ret_val = -1; const char *gName; H5G_info_t group_info; H5_index_t cindex_type = (H5_index_t)index_type; H5_iter_order_t corder = (H5_iter_order_t)order; - PIN_JAVA_STRING(name, gName, NULL); - - ret_val = H5Gget_info_by_idx((hid_t)loc_id, gName, cindex_type, - corder, (hsize_t)n, &group_info, (hid_t)lapl_id); + PIN_JAVA_STRING(name, gName); + if (gName != NULL) { + ret_val = H5Gget_info_by_idx((hid_t)loc_id, gName, cindex_type, + corder, (hsize_t)n, &group_info, (hid_t)lapl_id); - UNPIN_JAVA_STRING(name, gName); + UNPIN_JAVA_STRING(name, gName); - if (ret_val < 0) { - h5libraryError(env); - return NULL; - } /* end if */ + if (ret_val < 0) + h5libraryError(env); + else + obj = create_H5G_info_t(env, group_info); + } - return create_H5G_info_t(env, group_info); + return obj; } /* end Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1idx */ /* @@ -267,7 +271,7 @@ Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1idx */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Gflush - (JNIEnv *env, jclass clss, jlong loc_id) + (JNIEnv *env, jclass clss, jlong loc_id) { if (H5Gflush((hid_t)loc_id) < 0) h5libraryError(env); @@ -280,7 +284,7 @@ Java_hdf_hdf5lib_H5_H5Gflush */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Grefresh - (JNIEnv *env, jclass clss, jlong loc_id) + (JNIEnv *env, jclass clss, jlong loc_id) { if (H5Grefresh((hid_t)loc_id) < 0) h5libraryError(env); diff --git a/java/src/jni/h5iImp.c b/java/src/jni/h5iImp.c index 9fce3ef..71e1b71 100644 --- a/java/src/jni/h5iImp.c +++ b/java/src/jni/h5iImp.c @@ -52,11 +52,11 @@ Java_hdf_hdf5lib_H5_H5Iget_1type /* * Class: hdf_hdf5lib_H5 - * Method: H5Iget_name + * Method: H5Iget_name_long * Signature: (JLjava/lang/String;J)J */ JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Iget_1name +Java_hdf_hdf5lib_H5_H5Iget_1name_1long (JNIEnv *env, jclass clss, jlong obj_id, jobjectArray name, jlong buf_size) { char *aName; @@ -91,6 +91,45 @@ Java_hdf_hdf5lib_H5_H5Iget_1name /* * Class: hdf_hdf5lib_H5 + * Method: H5Iget_name + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Iget_1name + (JNIEnv *env, jclass clss, jlong obj_id) +{ + char *aName; + jstring str = NULL; + ssize_t buf_size; + + /* get the length of the name */ + buf_size = H5Iget_name((hid_t)obj_id, NULL, 0); + + if (buf_size <= 0) { + h5badArgument(env, "H5Iget_name: buf_size <= 0"); + } /* end if */ + else { + buf_size++; /* add extra space for the null terminator */ + aName = (char*)HDmalloc(sizeof(char) * (size_t)buf_size); + if (aName == NULL) { + h5outOfMemory(env, "H5Iget_name: malloc failed"); + } /* end if */ + else { + buf_size = H5Iget_name((hid_t)obj_id, aName, (size_t)buf_size); + if (buf_size < 0) { + h5libraryError(env); + } /* end if */ + else { + str = ENVPTR->NewStringUTF(ENVPAR aName); + } + HDfree(aName); + } + } + return str; +} /* end Java_hdf_hdf5lib_H5_H5Iget_1name */ + +/* + * Class: hdf_hdf5lib_H5 * Method: H5Iget_ref * Signature: (J)I */ diff --git a/java/src/jni/h5iImp.h b/java/src/jni/h5iImp.h index f7472b8..2bf839bc 100644 --- a/java/src/jni/h5iImp.h +++ b/java/src/jni/h5iImp.h @@ -34,15 +34,24 @@ Java_hdf_hdf5lib_H5_H5Iget_1type /* * Class: hdf_hdf5lib_H5 - * Method: H5Iget_name + * Method: H5Iget_name_long * Signature: (JLjava/lang/String;J)J */ JNIEXPORT jlong JNICALL -Java_hdf_hdf5lib_H5_H5Iget_1name +Java_hdf_hdf5lib_H5_H5Iget_1name_1long (JNIEnv*, jclass, jlong, jobjectArray, jlong); /* * Class: hdf_hdf5lib_H5 + * Method: H5Iget_name + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_hdf_hdf5lib_H5_H5Iget_1name + (JNIEnv*, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 * Method: H5Iget_ref * Signature: (J)I */ diff --git a/java/src/jni/h5jni.h b/java/src/jni/h5jni.h index da49eeb..9414d31 100644 --- a/java/src/jni/h5jni.h +++ b/java/src/jni/h5jni.h @@ -67,29 +67,17 @@ /* Macros for string access */ -#define PIN_JAVA_STRING(javastr,localstr,retdefault) { \ +#define PIN_JAVA_STRING(javastr,localstr) { \ jboolean isCopy; \ + (localstr) = NULL; \ if ((javastr) == NULL) { \ h5nullArgument(env, "java string is NULL"); \ - return (retdefault); \ } \ - (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ - if ((localstr) == NULL) { \ - h5JNIFatalError(env, "local c string is not pinned"); \ - return (retdefault); \ - } \ -} - -#define PIN_JAVA_STRING0(javastr,localstr) { \ - jboolean isCopy; \ - if ((javastr) == NULL) { \ - h5nullArgument(env, "java string is NULL"); \ - return; \ - } \ - (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ - if ((localstr) == NULL) { \ - h5JNIFatalError(env, "local c string is not pinned"); \ - return; \ + else { \ + (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ + if ((localstr) == NULL) { \ + h5JNIFatalError(env, "local c string is not pinned"); \ + } \ } \ } @@ -97,49 +85,28 @@ ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ } -#define PIN_JAVA_STRING_TWO(javastr,localstr,java2str,local2str,retdefault) { \ +#define PIN_JAVA_STRING_TWO(javastr,localstr,java2str,local2str) { \ jboolean isCopy; \ + (localstr) = NULL; \ + (local2str) = NULL; \ if ((javastr) == NULL) { \ h5nullArgument(env, "java string is NULL"); \ - return (retdefault); \ } \ - if ((java2str) == NULL) { \ + else if ((java2str) == NULL) { \ h5nullArgument(env, "second java string is NULL"); \ - return (retdefault); \ } \ - (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ - if ((localstr) == NULL) { \ - h5JNIFatalError(env, "local c string is not pinned"); \ - return (retdefault); \ - } \ - (local2str) = ENVPTR->GetStringUTFChars(ENVPAR (java2str), &isCopy); \ - if ((local2str) == NULL) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - h5JNIFatalError(env, "second local c string is not pinned"); \ - return (retdefault); \ - } \ -} - -#define PIN_JAVA_STRING_TWO0(javastr,localstr,java2str,local2str) { \ - jboolean isCopy; \ - if ((javastr) == NULL) { \ - h5nullArgument(env, "java string is NULL"); \ - return; \ - } \ - if ((java2str) == NULL) { \ - h5nullArgument(env, "second java string is NULL"); \ - return; \ - } \ - (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ - if ((localstr) == NULL) { \ - h5JNIFatalError(env, "local c string is not pinned"); \ - return; \ - } \ - (local2str) = ENVPTR->GetStringUTFChars(ENVPAR (java2str), &isCopy); \ - if ((local2str) == NULL) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - h5JNIFatalError(env, "second local c string is not pinned"); \ - return; \ + else { \ + (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ + if ((localstr) == NULL) { \ + h5JNIFatalError(env, "local c string is not pinned"); \ + } \ + else { \ + (local2str) = ENVPTR->GetStringUTFChars(ENVPAR (java2str), &isCopy); \ + if ((local2str) == NULL) { \ + ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ + h5JNIFatalError(env, "second local c string is not pinned"); \ + } \ + } \ } \ } @@ -148,71 +115,40 @@ ENVPTR->ReleaseStringUTFChars(ENVPAR (java2str), (local2str)); \ } -#define PIN_JAVA_STRING_THREE(javastr,localstr,java2str,local2str,java3str,local3str,retdefault) { \ - jboolean isCopy; \ - if ((javastr) == NULL) { \ - h5nullArgument(env, "java string is NULL"); \ - return (retdefault); \ - } \ - if ((java2str) == NULL) { \ - h5nullArgument(env, "second java string is NULL"); \ - return (retdefault); \ - } \ - if ((java3str) == NULL) { \ - h5nullArgument(env, "third java string is NULL"); \ - return (retdefault); \ - } \ - (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ - if ((localstr) == NULL) { \ - h5JNIFatalError(env, "local c string is not pinned"); \ - return (retdefault); \ - } \ - (local2str) = ENVPTR->GetStringUTFChars(ENVPAR (java2str), &isCopy); \ - if ((local2str) == NULL) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - h5JNIFatalError(env, "second local c string is not pinned"); \ - return (retdefault); \ - } \ - (local3str) = ENVPTR->GetStringUTFChars(ENVPAR (java3str), &isCopy); \ - if ((local3str) == NULL) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (java2str), (local2str)); \ - h5JNIFatalError(env, "third local c string is not pinned"); \ - return (retdefault); \ - } \ -} - -#define PIN_JAVA_STRING_THREE0(javastr,localstr,java2str,local2str,java3str,local3str) { \ +#define PIN_JAVA_STRING_THREE(javastr,localstr,java2str,local2str,java3str,local3str) { \ jboolean isCopy; \ + (localstr) = NULL; \ + (local2str) = NULL; \ + (local3str) = NULL; \ if ((javastr) == NULL) { \ h5nullArgument(env, "java string is NULL"); \ - return; \ } \ - if ((java2str) == NULL) { \ + else if ((java2str) == NULL) { \ h5nullArgument(env, "second java string is NULL"); \ - return; \ } \ - if ((java3str) == NULL) { \ + else if ((java3str) == NULL) { \ h5nullArgument(env, "third java string is NULL"); \ - return; \ - } \ - (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ - if ((localstr) == NULL) { \ - h5JNIFatalError(env, "local c string is not pinned"); \ - return; \ - } \ - (local2str) = ENVPTR->GetStringUTFChars(ENVPAR (java2str), &isCopy); \ - if ((local2str) == NULL) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - h5JNIFatalError(env, "second local c string is not pinned"); \ - return; \ } \ - (local3str) = ENVPTR->GetStringUTFChars(ENVPAR (java3str), &isCopy); \ - if ((local3str) == NULL) { \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ - ENVPTR->ReleaseStringUTFChars(ENVPAR (java2str), (local2str)); \ - h5JNIFatalError(env, "third local c string is not pinned"); \ - return; \ + else { \ + (localstr) = ENVPTR->GetStringUTFChars(ENVPAR (javastr), &isCopy); \ + if ((localstr) == NULL) { \ + h5JNIFatalError(env, "local c string is not pinned"); \ + } \ + else { \ + (local2str) = ENVPTR->GetStringUTFChars(ENVPAR (java2str), &isCopy); \ + if ((local2str) == NULL) { \ + ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ + h5JNIFatalError(env, "second local c string is not pinned"); \ + } \ + else { \ + (local3str) = ENVPTR->GetStringUTFChars(ENVPAR (java3str), &isCopy); \ + if ((local3str) == NULL) { \ + ENVPTR->ReleaseStringUTFChars(ENVPAR (javastr), (localstr)); \ + ENVPTR->ReleaseStringUTFChars(ENVPAR (java2str), (local2str)); \ + h5JNIFatalError(env, "third local c string is not pinned"); \ + } \ + } \ + } \ } \ } diff --git a/java/src/jni/h5lImp.c b/java/src/jni/h5lImp.c index eecb1cd..473b1c7 100644 --- a/java/src/jni/h5lImp.c +++ b/java/src/jni/h5lImp.c @@ -52,14 +52,15 @@ Java_hdf_hdf5lib_H5_H5Lcopy const char *lCurName; const char *lDstName; - PIN_JAVA_STRING_TWO0(cur_name, lCurName, dst_name, lDstName); + PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + if (lCurName != NULL && lDstName != NULL) { + status = H5Lcopy((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); - status = H5Lcopy((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Lcopy */ /* @@ -77,14 +78,15 @@ Java_hdf_hdf5lib_H5_H5Lcreate_1external const char *lCurName; const char *lDstName; - PIN_JAVA_STRING_THREE0(file_name, lFileName, cur_name, lCurName, dst_name, lDstName); - - status = H5Lcreate_external(lFileName, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + PIN_JAVA_STRING_THREE(file_name, lFileName, cur_name, lCurName, dst_name, lDstName); + if (lFileName != NULL && lCurName != NULL && lDstName != NULL) { + status = H5Lcreate_external(lFileName, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); - UNPIN_JAVA_STRING_THREE(file_name, lFileName, cur_name, lCurName, dst_name, lDstName); + UNPIN_JAVA_STRING_THREE(file_name, lFileName, cur_name, lCurName, dst_name, lDstName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Lcreate_1external */ /* @@ -101,14 +103,15 @@ Java_hdf_hdf5lib_H5_H5Lcreate_1hard const char *lCurName; const char *lDstName; - PIN_JAVA_STRING_TWO0(cur_name, lCurName, dst_name, lDstName); + PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + if (lCurName != NULL && lDstName != NULL) { + status = H5Lcreate_hard((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); - status = H5Lcreate_hard((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Lcreate_1hard */ /* @@ -125,14 +128,15 @@ Java_hdf_hdf5lib_H5_H5Lcreate_1soft const char *lCurName; const char *lDstName; - PIN_JAVA_STRING_TWO0(cur_name, lCurName, dst_name, lDstName); - - status = H5Lcreate_soft(lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + if (lCurName != NULL && lDstName != NULL) { + status = H5Lcreate_soft(lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); - UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Lcreate_1soft */ /* @@ -147,14 +151,15 @@ Java_hdf_hdf5lib_H5_H5Ldelete herr_t status = -1; const char *lName; - PIN_JAVA_STRING0(name, lName); - - status = H5Ldelete((hid_t)loc_id, lName, (hid_t)access_id); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + status = H5Ldelete((hid_t)loc_id, lName, (hid_t)access_id); - UNPIN_JAVA_STRING(name, lName); + UNPIN_JAVA_STRING(name, lName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Ldelete */ /* @@ -171,14 +176,15 @@ Java_hdf_hdf5lib_H5_H5Ldelete_1by_1idx herr_t status; const char *lName; - PIN_JAVA_STRING0(name, lName); - - status = H5Ldelete_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, n, (hid_t)access_id); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + status = H5Ldelete_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, n, (hid_t)access_id); - UNPIN_JAVA_STRING(name, lName); + UNPIN_JAVA_STRING(name, lName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Ldelete_1by_1idx */ /* @@ -193,16 +199,17 @@ Java_hdf_hdf5lib_H5_H5Lexists htri_t bval = JNI_FALSE; const char *lName; - PIN_JAVA_STRING(name, lName, JNI_FALSE); - - bval = H5Lexists((hid_t)loc_id, lName, (hid_t)access_id); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + bval = H5Lexists((hid_t)loc_id, lName, (hid_t)access_id); - UNPIN_JAVA_STRING(name, lName); + UNPIN_JAVA_STRING(name, lName); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + if (bval > 0) + bval = JNI_TRUE; + else if (bval < 0) + h5libraryError(env); + } return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Lexists */ @@ -222,26 +229,27 @@ Java_hdf_hdf5lib_H5_H5Lget_1info H5L_info_t infobuf; const char *lName; - PIN_JAVA_STRING(name, lName, NULL); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + status = H5Lget_info((hid_t)loc_id, lName, &infobuf, (hid_t)access_id); - status = H5Lget_info((hid_t)loc_id, lName, &infobuf, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); + UNPIN_JAVA_STRING(name, lName); - if (status < 0) { - h5libraryError(env); + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + args[0].i = infobuf.type; + args[1].z = infobuf.corder_valid; + args[2].j = infobuf.corder; + args[3].i = infobuf.cset; + if(infobuf.type==0) + args[4].j = (jlong)infobuf.u.address; + else + args[4].j = (jlong)infobuf.u.val_size; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5L_info_t", "(IZJIJ)V", args); + } /* end else */ } /* end if */ - else { - args[0].i = infobuf.type; - args[1].z = infobuf.corder_valid; - args[2].j = infobuf.corder; - args[3].i = infobuf.cset; - if(infobuf.type==0) - args[4].j = (jlong)infobuf.u.address; - else - args[4].j = (jlong)infobuf.u.val_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5L_info_t", "(IZJIJ)V", args); - } /* end else */ return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Lget_1info */ @@ -261,26 +269,27 @@ Java_hdf_hdf5lib_H5_H5Lget_1info_1by_1idx H5L_info_t infobuf; const char *lName; - PIN_JAVA_STRING(name, lName, NULL); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + status = H5Lget_info_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id); - status = H5Lget_info_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); + UNPIN_JAVA_STRING(name, lName); - if (status < 0) { - h5libraryError(env); - } /* end if */ - else { - args[0].i = infobuf.type; - args[1].z = infobuf.corder_valid; - args[2].j = infobuf.corder; - args[3].i = infobuf.cset; - if(infobuf.type==0) - args[4].j = (jlong)infobuf.u.address; - else - args[4].j = (jlong)infobuf.u.val_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5L_info_t", "(IZJIJ)V", args); - } /* end els */ + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + args[0].i = infobuf.type; + args[1].z = infobuf.corder_valid; + args[2].j = infobuf.corder; + args[3].i = infobuf.cset; + if(infobuf.type==0) + args[4].j = (jlong)infobuf.u.address; + else + args[4].j = (jlong)infobuf.u.val_size; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5L_info_t", "(IZJIJ)V", args); + } /* end els */ + } return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Lget_1info_1by_1idx */ @@ -289,7 +298,7 @@ Java_hdf_hdf5lib_H5_H5Lget_1info_1by_1idx * Method: H5Lget_name_by_idx * Signature: (JLjava/lang/String;IIJJ)Ljava/lang/String; */ -JNIEXPORT jobject JNICALL +JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Lget_1name_1by_1idx (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jint index_field, jint order, jlong link_n, jlong access_id) @@ -300,39 +309,38 @@ Java_hdf_hdf5lib_H5_H5Lget_1name_1by_1idx const char *lName; char *lValue; - PIN_JAVA_STRING(name, lName, NULL); - - /* get the length of the link name */ - status_size = H5Lget_name_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (char*)NULL, (size_t)0, H5P_DEFAULT); - if(status_size < 0) { - UNPIN_JAVA_STRING(name, lName); - h5libraryError(env); - } /* end if */ - else { - buf_size = (size_t)status_size + 1;/* add extra space for the null terminator */ - - lValue = (char*)HDmalloc(sizeof(char) * buf_size); - if (lValue == NULL) { - UNPIN_JAVA_STRING(name, lName); - h5outOfMemory(env, "H5Lget_name_by_idx: malloc failed "); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + /* get the length of the link name */ + status_size = H5Lget_name_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (char*)NULL, (size_t)0, H5P_DEFAULT); + if(status_size < 0) { + h5libraryError(env); } /* end if */ else { - status_size = H5Lget_name_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (char*)lValue, (size_t)buf_size, (hid_t)access_id); + buf_size = (size_t)status_size + 1;/* add extra space for the null terminator */ - UNPIN_JAVA_STRING(name, lName); - - if (status_size < 0) { - HDfree(lValue); - h5libraryError(env); + lValue = (char*)HDmalloc(sizeof(char) * buf_size); + if (lValue == NULL) { + h5outOfMemory(env, "H5Lget_name_by_idx: malloc failed "); } /* end if */ else { - str = ENVPTR->NewStringUTF(ENVPAR lValue); - HDfree(lValue); - if (str == NULL) - h5JNIFatalError(env, "H5Lget_name_by_idx: return string not created"); + status_size = H5Lget_name_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (char*)lValue, (size_t)buf_size, (hid_t)access_id); + + if (status_size < 0) { + HDfree(lValue); + h5libraryError(env); + } /* end if */ + else { + str = ENVPTR->NewStringUTF(ENVPAR lValue); + HDfree(lValue); + if (str == NULL) + h5JNIFatalError(env, "H5Lget_name_by_idx: return string not created"); + } /* end else */ } /* end else */ } /* end else */ - } /* end else */ + UNPIN_JAVA_STRING(name, lName); + } + return str; } /* end Java_hdf_hdf5lib_H5_H5Lget_1name_1by_1idx */ @@ -354,79 +362,70 @@ Java_hdf_hdf5lib_H5_H5Lget_1value const char *obj_name; jstring str; - PIN_JAVA_STRING(name, lName, -1); - infobuf.type = -1; - /* get the length of the link val */ - status = H5Lget_info((hid_t)loc_id, lName, &infobuf, H5P_DEFAULT); - if(status < 0) { - UNPIN_JAVA_STRING(name, lName); - h5libraryError(env); - } /* end if */ - else { - buf_size = infobuf.u.val_size + 1;/* add extra space for the null terminator */ - - if(infobuf.type == H5L_TYPE_HARD) { - UNPIN_JAVA_STRING(name, lName); - h5JNIFatalError(env, "H5Lget_val: link is hard type"); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + /* get the length of the link val */ + status = H5Lget_info((hid_t)loc_id, lName, &infobuf, H5P_DEFAULT); + if(status < 0) { + h5libraryError(env); } /* end if */ else { - lValue = (char*)HDmalloc(sizeof(char) * buf_size); - if (lValue == NULL) { - UNPIN_JAVA_STRING(name, lName); - h5outOfMemory(env, "H5Lget_val: malloc failed"); + buf_size = infobuf.u.val_size + 1;/* add extra space for the null terminator */ + + if(infobuf.type == H5L_TYPE_HARD) { + h5JNIFatalError(env, "H5Lget_val: link is hard type"); } /* end if */ else { - status = H5Lget_val((hid_t)loc_id, lName, (void*)lValue, buf_size, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); - - if (status < 0) { - HDfree(lValue); - h5libraryError(env); + lValue = (char*)HDmalloc(sizeof(char) * buf_size); + if (lValue == NULL) { + h5outOfMemory(env, "H5Lget_val: malloc failed"); } /* end if */ - else if(infobuf.type == H5L_TYPE_EXTERNAL) { - status = H5Lunpack_elink_val(lValue, (size_t)infobuf.u.val_size, (unsigned*)NULL, &file_name, &obj_name); + else { + status = H5Lget_val((hid_t)loc_id, lName, (void*)lValue, buf_size, (hid_t)access_id); + if (status < 0) { - HDfree(lValue); h5libraryError(env); } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR obj_name); - if (str == NULL) { - HDfree(lValue); - h5JNIFatalError(env, "H5Lget_val: return string not created"); + else if(infobuf.type == H5L_TYPE_EXTERNAL) { + status = H5Lunpack_elink_val(lValue, (size_t)infobuf.u.val_size, (unsigned*)NULL, &file_name, &obj_name); + if (status < 0) { + h5libraryError(env); } /* end if */ else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); - - str = ENVPTR->NewStringUTF(ENVPAR file_name); + str = ENVPTR->NewStringUTF(ENVPAR obj_name); if (str == NULL) { - HDfree(lValue); h5JNIFatalError(env, "H5Lget_val: return string not created"); } /* end if */ else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 1, str); - HDfree(lValue); + ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); + + str = ENVPTR->NewStringUTF(ENVPAR file_name); + if (str == NULL) { + h5JNIFatalError(env, "H5Lget_val: return string not created"); + } /* end if */ + else { + ENVPTR->SetObjectArrayElement(ENVPAR link_value, 1, str); + } /* end else */ } /* end else */ } /* end else */ - } /* end else */ - } /* end else if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR lValue); - if (str == NULL) { - /* exception -- fatal JNI error */ - HDfree(lValue); - h5JNIFatalError(env, "H5Lget_val: return string not created"); - } /* end if */ + } /* end else if */ else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); - HDfree(lValue); + str = ENVPTR->NewStringUTF(ENVPAR lValue); + if (str == NULL) { + /* exception -- fatal JNI error */ + h5JNIFatalError(env, "H5Lget_val: return string not created"); + } /* end if */ + else { + ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); + } /* end else */ } /* end else */ + HDfree(lValue); } /* end else */ } /* end else */ } /* end else */ - } /* end else */ + UNPIN_JAVA_STRING(name, lName); + } return infobuf.type; } /* end Java_hdf_hdf5lib_H5_H5Lget_1val */ @@ -450,80 +449,69 @@ Java_hdf_hdf5lib_H5_H5Lget_1value_1by_1idx const char *obj_name; jstring str; - PIN_JAVA_STRING(name, lName, -1); - infobuf.type = -1; - /* get the length of the link valuee */ - status = H5Lget_info_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id); - if(status < 0) { - UNPIN_JAVA_STRING(name, lName); - h5libraryError(env); - return -1; - } /* end if */ - else { - buf_size = infobuf.u.val_size; - if(buf_size < 0) { - UNPIN_JAVA_STRING(name, lName); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + /* get the length of the link valuee */ + status = H5Lget_info_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id); + if(status < 0) { h5libraryError(env); - return -1; } /* end if */ else { - lValue = (void*)HDmalloc(buf_size); - if (lValue == NULL) { - UNPIN_JAVA_STRING(name, lName); - h5outOfMemory(env, "H5Lget_val_by_idx: malloc failed "); - return -1; + buf_size = infobuf.u.val_size; + if(buf_size < 0) { + h5libraryError(env); } /* end if */ else { - status = H5Lget_val_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (void*)lValue, (size_t)buf_size, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); - - if (status < 0) { - HDfree(lValue); - h5libraryError(env); + lValue = (void*)HDmalloc(buf_size); + if (lValue == NULL) { + h5outOfMemory(env, "H5Lget_val_by_idx: malloc failed "); } /* end if */ - else if(infobuf.type == H5L_TYPE_EXTERNAL) { - status = H5Lunpack_elink_val((char*)lValue, (size_t)infobuf.u.val_size, (unsigned*)NULL, (const char**)&file_name, (const char**)&obj_name); + else { + status = H5Lget_val_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (void*)lValue, (size_t)buf_size, (hid_t)access_id); + if (status < 0) { - HDfree(lValue); h5libraryError(env); } /* end if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR obj_name); - if (str == NULL) { - HDfree(lValue); - h5JNIFatalError(env, "H5Lget_val_by_idx: return string not created"); + else if(infobuf.type == H5L_TYPE_EXTERNAL) { + status = H5Lunpack_elink_val((char*)lValue, (size_t)infobuf.u.val_size, (unsigned*)NULL, (const char**)&file_name, (const char**)&obj_name); + if (status < 0) { + h5libraryError(env); } /* end if */ else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); - - str = ENVPTR->NewStringUTF(ENVPAR file_name); + str = ENVPTR->NewStringUTF(ENVPAR obj_name); if (str == NULL) { - HDfree(lValue); h5JNIFatalError(env, "H5Lget_val_by_idx: return string not created"); } /* end if */ else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 1, str); - HDfree(lValue); + ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); + + str = ENVPTR->NewStringUTF(ENVPAR file_name); + if (str == NULL) { + h5JNIFatalError(env, "H5Lget_val_by_idx: return string not created"); + } /* end if */ + else { + ENVPTR->SetObjectArrayElement(ENVPAR link_value, 1, str); + } /* end else */ } /* end else */ } /* end else */ - } /* end else */ - } /* end else if */ - else { - str = ENVPTR->NewStringUTF(ENVPAR (char *)lValue); - if (str == NULL) { - HDfree(lValue); - h5JNIFatalError(env, "H5Lget_val_by_idx: return string not created"); - } /* end if */ + } /* end else if */ else { - ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); - HDfree(lValue); + str = ENVPTR->NewStringUTF(ENVPAR (char *)lValue); + if (str == NULL) { + h5JNIFatalError(env, "H5Lget_val_by_idx: return string not created"); + } /* end if */ + else { + ENVPTR->SetObjectArrayElement(ENVPAR link_value, 0, str); + } /* end else */ } /* end else */ + HDfree(lValue); } /* end else */ } /* end else */ } /* end else */ - } /* end else */ + UNPIN_JAVA_STRING(name, lName); + } + return infobuf.type; } /* end Java_hdf_hdf5lib_H5_H5Lget_1val_1by_1idx */ @@ -541,20 +529,21 @@ Java_hdf_hdf5lib_H5_H5Lmove const char *lCurName; const char *lDstName; - PIN_JAVA_STRING_TWO0(cur_name, lCurName, dst_name, lDstName); + PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + if (lCurName != NULL && lDstName != NULL) { + status = H5Lmove((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); - status = H5Lmove((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Lmove */ static herr_t H5L_iterate_cb - (hid_t g_id, const char *name, const H5L_info_t *info, void *op_data) + (hid_t g_id, const char *name, const H5L_info_t *info, void *op_data) { JNIEnv *cbenv; jint status; @@ -645,14 +634,15 @@ Java_hdf_hdf5lib_H5_H5Lvisit_1by_1name h5nullArgument(env, "H5Lvisit_by_name: op_data or callback_op is NULL"); } /* end if */ else { - PIN_JAVA_STRING(name, lName, -1); - - status = H5Lvisit_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5L_iterate_t)H5L_iterate_cb, (void*)op_data, (hid_t)access_id); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + status = H5Lvisit_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5L_iterate_t)H5L_iterate_cb, (void*)op_data, (hid_t)access_id); - UNPIN_JAVA_STRING(name, lName); + UNPIN_JAVA_STRING(name, lName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end else */ return status; @@ -708,14 +698,15 @@ Java_hdf_hdf5lib_H5_H5Literate_1by_1name h5nullArgument(env, "H5Literate_by_name: op_data or callback_op is NULL"); } /* end if */ else { - PIN_JAVA_STRING(name, lName, -1); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + status = H5Literate_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5L_iterate_t)H5L_iterate_cb, (void*)op_data, (hid_t)access_id); - status = H5Literate_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (hsize_t*)&start_idx, (H5L_iterate_t)H5L_iterate_cb, (void*)op_data, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); + UNPIN_JAVA_STRING(name, lName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end else */ return status; diff --git a/java/src/jni/h5lImp.h b/java/src/jni/h5lImp.h index 93a187b..6b2f3e1 100644 --- a/java/src/jni/h5lImp.h +++ b/java/src/jni/h5lImp.h @@ -110,7 +110,7 @@ Java_hdf_hdf5lib_H5_H5Lget_1info_1by_1idx * Method: H5Lget_name_by_idx * Signature: (JLjava/lang/String;IIJJ)Ljava/lang/String; */ -JNIEXPORT jobject JNICALL +JNIEXPORT jstring JNICALL Java_hdf_hdf5lib_H5_H5Lget_1name_1by_1idx (JNIEnv*, jclass, jlong, jstring, jint, jint, jlong, jlong); diff --git a/java/src/jni/h5oImp.c b/java/src/jni/h5oImp.c index 872bb4c..24f6988 100644 --- a/java/src/jni/h5oImp.c +++ b/java/src/jni/h5oImp.c @@ -46,17 +46,18 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Oopen (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist_id) { - hid_t status; + hid_t status = -1; const char *oName; - PIN_JAVA_STRING(name, oName, -1); + PIN_JAVA_STRING(name, oName); + if (oName != NULL) { + status = H5Oopen((hid_t)loc_id, oName, (hid_t)access_plist_id ); - status = H5Oopen((hid_t)loc_id, oName, (hid_t)access_plist_id ); - - UNPIN_JAVA_STRING(name, oName); + UNPIN_JAVA_STRING(name, oName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Oopen */ @@ -92,14 +93,15 @@ Java_hdf_hdf5lib_H5_H5Ocopy const char *lCurName; const char *lDstName; - PIN_JAVA_STRING_TWO0(cur_name, lCurName, dst_name, lDstName); + PIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); + if (lCurName != NULL && lDstName != NULL) { + status = H5Ocopy((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); - status = H5Ocopy((hid_t)cur_loc_id, lCurName, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - UNPIN_JAVA_STRING_TWO(cur_name, lCurName, dst_name, lDstName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Ocopy */ /* @@ -123,44 +125,44 @@ Java_hdf_hdf5lib_H5_H5Oget_1info if (status < 0) { h5libraryError(env); - return NULL; } /* end if */ - - args[0].i = (jint)infobuf.hdr.version; - args[1].i = (jint)infobuf.hdr.nmesgs; - args[2].i = (jint)infobuf.hdr.nchunks; - args[3].i = (jint)infobuf.hdr.flags; - args[4].j = (jlong)infobuf.hdr.space.total; - args[5].j = (jlong)infobuf.hdr.space.meta; - args[6].j = (jlong)infobuf.hdr.space.mesg; - args[7].j = (jlong)infobuf.hdr.space.free; - args[8].j = (jlong)infobuf.hdr.mesg.present; - args[9].j = (jlong)infobuf.hdr.mesg.shared; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args); - hdrinfobuf = ret_obj; - - args[0].j = (jlong)infobuf.meta_size.obj.index_size; - args[1].j = (jlong)infobuf.meta_size.obj.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf1 = ret_obj; - args[0].j = (jlong)infobuf.meta_size.attr.index_size; - args[1].j = (jlong)infobuf.meta_size.attr.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf2 = ret_obj; - - args[0].j = (jlong)infobuf.fileno; - args[1].j = (jlong)infobuf.addr; - args[2].i = infobuf.type; - args[3].i = (jint)infobuf.rc; - args[4].j = (jlong)infobuf.num_attrs; - args[5].j = infobuf.atime; - args[6].j = infobuf.mtime; - args[7].j = infobuf.ctime; - args[8].j = infobuf.btime; - args[9].l = hdrinfobuf; - args[10].l = ihinfobuf1; - args[11].l = ihinfobuf2; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args); + else { + args[0].i = (jint)infobuf.hdr.version; + args[1].i = (jint)infobuf.hdr.nmesgs; + args[2].i = (jint)infobuf.hdr.nchunks; + args[3].i = (jint)infobuf.hdr.flags; + args[4].j = (jlong)infobuf.hdr.space.total; + args[5].j = (jlong)infobuf.hdr.space.meta; + args[6].j = (jlong)infobuf.hdr.space.mesg; + args[7].j = (jlong)infobuf.hdr.space.free; + args[8].j = (jlong)infobuf.hdr.mesg.present; + args[9].j = (jlong)infobuf.hdr.mesg.shared; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args); + hdrinfobuf = ret_obj; + + args[0].j = (jlong)infobuf.meta_size.obj.index_size; + args[1].j = (jlong)infobuf.meta_size.obj.heap_size; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); + ihinfobuf1 = ret_obj; + args[0].j = (jlong)infobuf.meta_size.attr.index_size; + args[1].j = (jlong)infobuf.meta_size.attr.heap_size; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); + ihinfobuf2 = ret_obj; + + args[0].j = (jlong)infobuf.fileno; + args[1].j = (jlong)infobuf.addr; + args[2].i = infobuf.type; + args[3].i = (jint)infobuf.rc; + args[4].j = (jlong)infobuf.num_attrs; + args[5].j = infobuf.atime; + args[6].j = infobuf.mtime; + args[7].j = infobuf.ctime; + args[8].j = infobuf.btime; + args[9].l = hdrinfobuf; + args[10].l = ihinfobuf1; + args[11].l = ihinfobuf2; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args); + } return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Oget_1info */ @@ -183,52 +185,53 @@ Java_hdf_hdf5lib_H5_H5Oget_1info_1by_1name jobject ihinfobuf2; jobject ret_obj = NULL; - PIN_JAVA_STRING(name, lName, NULL); - - status = H5Oget_info_by_name((hid_t)loc_id, lName, &infobuf, (hid_t)access_id); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + status = H5Oget_info_by_name((hid_t)loc_id, lName, &infobuf, (hid_t)access_id); - UNPIN_JAVA_STRING(name, lName); + UNPIN_JAVA_STRING(name, lName); - if (status < 0) { - h5libraryError(env); - return NULL; - } /* end if */ - - args[0].i = (jint)infobuf.hdr.version; - args[1].i = (jint)infobuf.hdr.nmesgs; - args[2].i = (jint)infobuf.hdr.nchunks; - args[3].i = (jint)infobuf.hdr.flags; - args[4].j = (jlong)infobuf.hdr.space.total; - args[5].j = (jlong)infobuf.hdr.space.meta; - args[6].j = (jlong)infobuf.hdr.space.mesg; - args[7].j = (jlong)infobuf.hdr.space.free; - args[8].j = (jlong)infobuf.hdr.mesg.present; - args[9].j = (jlong)infobuf.hdr.mesg.shared; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args); - hdrinfobuf = ret_obj; - - args[0].j = (jlong)infobuf.meta_size.obj.index_size; - args[1].j = (jlong)infobuf.meta_size.obj.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf1 = ret_obj; - args[0].j = (jlong)infobuf.meta_size.attr.index_size; - args[1].j = (jlong)infobuf.meta_size.attr.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf2 = ret_obj; - - args[0].j = (jlong)infobuf.fileno; - args[1].j = (jlong)infobuf.addr; - args[2].i = infobuf.type; - args[3].i = (jint)infobuf.rc; - args[4].j = (jlong)infobuf.num_attrs; - args[5].j = infobuf.atime; - args[6].j = infobuf.mtime; - args[7].j = infobuf.ctime; - args[8].j = infobuf.btime; - args[9].l = hdrinfobuf; - args[10].l = ihinfobuf1; - args[11].l = ihinfobuf2; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args); + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + args[0].i = (jint)infobuf.hdr.version; + args[1].i = (jint)infobuf.hdr.nmesgs; + args[2].i = (jint)infobuf.hdr.nchunks; + args[3].i = (jint)infobuf.hdr.flags; + args[4].j = (jlong)infobuf.hdr.space.total; + args[5].j = (jlong)infobuf.hdr.space.meta; + args[6].j = (jlong)infobuf.hdr.space.mesg; + args[7].j = (jlong)infobuf.hdr.space.free; + args[8].j = (jlong)infobuf.hdr.mesg.present; + args[9].j = (jlong)infobuf.hdr.mesg.shared; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args); + hdrinfobuf = ret_obj; + + args[0].j = (jlong)infobuf.meta_size.obj.index_size; + args[1].j = (jlong)infobuf.meta_size.obj.heap_size; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); + ihinfobuf1 = ret_obj; + args[0].j = (jlong)infobuf.meta_size.attr.index_size; + args[1].j = (jlong)infobuf.meta_size.attr.heap_size; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); + ihinfobuf2 = ret_obj; + + args[0].j = (jlong)infobuf.fileno; + args[1].j = (jlong)infobuf.addr; + args[2].i = infobuf.type; + args[3].i = (jint)infobuf.rc; + args[4].j = (jlong)infobuf.num_attrs; + args[5].j = infobuf.atime; + args[6].j = infobuf.mtime; + args[7].j = infobuf.ctime; + args[8].j = infobuf.btime; + args[9].l = hdrinfobuf; + args[10].l = ihinfobuf1; + args[11].l = ihinfobuf2; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args); + } + } return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Oget_1info_1by_1name */ @@ -252,52 +255,53 @@ Java_hdf_hdf5lib_H5_H5Oget_1info_1by_1idx jobject ihinfobuf2; jobject ret_obj = NULL; - PIN_JAVA_STRING(name, lName, NULL); + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + status = H5Oget_info_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id); - status = H5Oget_info_by_idx((hid_t)loc_id, lName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, &infobuf, (hid_t)access_id); + UNPIN_JAVA_STRING(name, lName); - UNPIN_JAVA_STRING(name, lName); - - if (status < 0) { - h5libraryError(env); - return NULL; - } /* end if */ - - args[0].i = (jint)infobuf.hdr.version; - args[1].i = (jint)infobuf.hdr.nmesgs; - args[2].i = (jint)infobuf.hdr.nchunks; - args[3].i = (jint)infobuf.hdr.flags; - args[4].j = (jlong)infobuf.hdr.space.total; - args[5].j = (jlong)infobuf.hdr.space.meta; - args[6].j = (jlong)infobuf.hdr.space.mesg; - args[7].j = (jlong)infobuf.hdr.space.free; - args[8].j = (jlong)infobuf.hdr.mesg.present; - args[9].j = (jlong)infobuf.hdr.mesg.shared; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args); - hdrinfobuf = ret_obj; - - args[0].j = (jlong)infobuf.meta_size.obj.index_size; - args[1].j = (jlong)infobuf.meta_size.obj.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf1 = ret_obj; - args[0].j = (jlong)infobuf.meta_size.attr.index_size; - args[1].j = (jlong)infobuf.meta_size.attr.heap_size; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); - ihinfobuf2 = ret_obj; - - args[0].j = (jlong)infobuf.fileno; - args[1].j = (jlong)infobuf.addr; - args[2].i = infobuf.type; - args[3].i = (jint)infobuf.rc; - args[4].j = (jlong)infobuf.num_attrs; - args[5].j = infobuf.atime; - args[6].j = infobuf.mtime; - args[7].j = infobuf.ctime; - args[8].j = infobuf.btime; - args[9].l = hdrinfobuf; - args[10].l = ihinfobuf1; - args[11].l = ihinfobuf2; - CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args); + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + args[0].i = (jint)infobuf.hdr.version; + args[1].i = (jint)infobuf.hdr.nmesgs; + args[2].i = (jint)infobuf.hdr.nchunks; + args[3].i = (jint)infobuf.hdr.flags; + args[4].j = (jlong)infobuf.hdr.space.total; + args[5].j = (jlong)infobuf.hdr.space.meta; + args[6].j = (jlong)infobuf.hdr.space.mesg; + args[7].j = (jlong)infobuf.hdr.space.free; + args[8].j = (jlong)infobuf.hdr.mesg.present; + args[9].j = (jlong)infobuf.hdr.mesg.shared; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_hdr_info_t", "(IIIIJJJJJJ)V", args); + hdrinfobuf = ret_obj; + + args[0].j = (jlong)infobuf.meta_size.obj.index_size; + args[1].j = (jlong)infobuf.meta_size.obj.heap_size; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); + ihinfobuf1 = ret_obj; + args[0].j = (jlong)infobuf.meta_size.attr.index_size; + args[1].j = (jlong)infobuf.meta_size.attr.heap_size; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5_ih_info_t", "(JJ)V", args); + ihinfobuf2 = ret_obj; + + args[0].j = (jlong)infobuf.fileno; + args[1].j = (jlong)infobuf.addr; + args[2].i = infobuf.type; + args[3].i = (jint)infobuf.rc; + args[4].j = (jlong)infobuf.num_attrs; + args[5].j = infobuf.atime; + args[6].j = infobuf.mtime; + args[7].j = infobuf.ctime; + args[8].j = infobuf.btime; + args[9].l = hdrinfobuf; + args[10].l = ihinfobuf1; + args[11].l = ihinfobuf2; + CALL_CONSTRUCTOR("hdf/hdf5lib/structs/H5O_info_t", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V", args); + } + } return ret_obj; } /* end Java_hdf_hdf5lib_H5_H5Oget_1info_1by_1idx */ @@ -315,14 +319,15 @@ Java_hdf_hdf5lib_H5_H5Olink herr_t status = -1; const char *lDstName; - PIN_JAVA_STRING0(dst_name, lDstName); - - status = H5Olink((hid_t)cur_loc_id, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); + PIN_JAVA_STRING(dst_name, lDstName); + if (lDstName != NULL) { + status = H5Olink((hid_t)cur_loc_id, (hid_t)dst_loc_id, lDstName, (hid_t)create_id, (hid_t)access_id); - UNPIN_JAVA_STRING(dst_name, lDstName); + UNPIN_JAVA_STRING(dst_name, lDstName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Olink */ static herr_t @@ -347,90 +352,71 @@ H5O_iterate_cb return -1; } /* end if */ cls = CBENVPTR->GetObjectClass(CBENVPAR visit_callback); - if (cls == 0) { - /* printf("JNI H5O_iterate_cb error: GetObjectClass failed\n"); */ - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5O_info_t;Lhdf/hdf5lib/callbacks/H5O_iterate_t;)I"); - if (mid == 0) { - /* printf("JNI H5O_iterate_cb error: GetMethodID failed\n"); */ - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; + if (cls != 0) { + mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5O_info_t;Lhdf/hdf5lib/callbacks/H5O_iterate_t;)I"); + if (mid != 0) { + str = CBENVPTR->NewStringUTF(CBENVPAR name); + + args[0].i = (jint)info->hdr.version; + args[1].i = (jint)info->hdr.nmesgs; + args[2].i = (jint)info->hdr.nchunks; + args[3].i = (jint)info->hdr.flags; + args[4].j = (jlong)info->hdr.space.total; + args[5].j = (jlong)info->hdr.space.meta; + args[6].j = (jlong)info->hdr.space.mesg; + args[7].j = (jlong)info->hdr.space.free; + args[8].j = (jlong)info->hdr.mesg.present; + args[9].j = (jlong)info->hdr.mesg.shared; + // get a reference to the H5_hdr_info_t class + cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5O_hdr_info_t"); + if (cls != 0) { + // get a reference to the constructor; the name is <init> + constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "<init>", "(IIIIJJJJJJ)V"); + if (constructor != 0) { + hdrinfobuf = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); + + args[0].j = (jlong)info->meta_size.obj.index_size; + args[1].j = (jlong)info->meta_size.obj.heap_size; + // get a reference to the H5_ih_info_t class + cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5_ih_info_t"); + if (cls != 0) { + // get a reference to the constructor; the name is <init> + constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "<init>", "(JJ)V"); + if (constructor != 0) { + ihinfobuf1 = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); + args[0].j = (jlong)info->meta_size.attr.index_size; + args[1].j = (jlong)info->meta_size.attr.heap_size; + ihinfobuf2 = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); + + args[0].j = (jlong)info->fileno; + args[1].j = (jlong)info->addr; + args[2].i = info->type; + args[3].i = (jint)info->rc; + args[4].j = (jlong)info->num_attrs; + args[5].j = info->atime; + args[6].j = info->mtime; + args[7].j = info->ctime; + args[8].j = info->btime; + args[9].l = hdrinfobuf; + args[10].l = ihinfobuf1; + args[11].l = ihinfobuf2; + // get a reference to the H5O_info_t class + cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5O_info_t"); + if (cls != 0) { + // get a reference to the constructor; the name is <init> + constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "<init>", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V"); + if (constructor != 0) { + cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); + + status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); + } + } + } + } + } + } + } } /* end if */ - str = CBENVPTR->NewStringUTF(CBENVPAR name); - - args[0].i = (jint)info->hdr.version; - args[1].i = (jint)info->hdr.nmesgs; - args[2].i = (jint)info->hdr.nchunks; - args[3].i = (jint)info->hdr.flags; - args[4].j = (jlong)info->hdr.space.total; - args[5].j = (jlong)info->hdr.space.meta; - args[6].j = (jlong)info->hdr.space.mesg; - args[7].j = (jlong)info->hdr.space.free; - args[8].j = (jlong)info->hdr.mesg.present; - args[9].j = (jlong)info->hdr.mesg.shared; - // get a reference to the H5_hdr_info_t class - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5O_hdr_info_t"); - if (cls == 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - // get a reference to the constructor; the name is <init> - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "<init>", "(IIIIJJJJJJ)V"); - if (constructor == 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - hdrinfobuf = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - - args[0].j = (jlong)info->meta_size.obj.index_size; - args[1].j = (jlong)info->meta_size.obj.heap_size; - // get a reference to the H5_ih_info_t class - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5_ih_info_t"); - if (cls == 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - // get a reference to the constructor; the name is <init> - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "<init>", "(JJ)V"); - if (constructor == 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - ihinfobuf1 = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - args[0].j = (jlong)info->meta_size.attr.index_size; - args[1].j = (jlong)info->meta_size.attr.heap_size; - ihinfobuf2 = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - - args[0].j = (jlong)info->fileno; - args[1].j = (jlong)info->addr; - args[2].i = info->type; - args[3].i = (jint)info->rc; - args[4].j = (jlong)info->num_attrs; - args[5].j = info->atime; - args[6].j = info->mtime; - args[7].j = info->ctime; - args[8].j = info->btime; - args[9].l = hdrinfobuf; - args[10].l = ihinfobuf1; - args[11].l = ihinfobuf2; - // get a reference to the H5O_info_t class - cls = CBENVPTR->FindClass(CBENVPAR "hdf/hdf5lib/structs/H5O_info_t"); - if (cls == 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - // get a reference to the constructor; the name is <init> - constructor = CBENVPTR->GetMethodID(CBENVPAR cls, "<init>", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V"); - if (constructor == 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - cb_info_t = CBENVPTR->NewObjectA(CBENVPAR cls, constructor, args); - - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, g_id, str, cb_info_t, op_data); - JVMPTR->DetachCurrentThread(JVMPAR); return status; @@ -453,17 +439,16 @@ Java_hdf_hdf5lib_H5_H5Ovisit if (op_data == NULL) { h5nullArgument(env, "H5Ovisit: op_data is NULL"); - return -1; } /* end if */ - if (callback_op == NULL) { + else if (callback_op == NULL) { h5nullArgument(env, "H5Ovisit: callback_op is NULL"); - return -1; } /* end if */ + else { + status = H5Ovisit((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5O_iterate_t)H5O_iterate_cb, (void*)op_data); - status = H5Ovisit((hid_t)grp_id, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5O_iterate_t)H5O_iterate_cb, (void*)op_data); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return status; } /* end Java_hdf_hdf5lib_H5_H5Ovisit */ @@ -488,19 +473,21 @@ Java_hdf_hdf5lib_H5_H5Ovisit_1by_1name h5nullArgument(env, "H5Ovisit_by_name: op_data is NULL"); return -1; } /* end if */ - if (callback_op == NULL) { + else if (callback_op == NULL) { h5nullArgument(env, "H5Ovisit_by_name: callback_op is NULL"); return -1; } /* end if */ + else { + PIN_JAVA_STRING(name, lName); + if (lName != NULL) { + status = H5Ovisit_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5O_iterate_t)H5O_iterate_cb, (void*)op_data, (hid_t)access_id); - PIN_JAVA_STRING(name, lName, -1); - - status = H5Ovisit_by_name((hid_t)grp_id, lName, (H5_index_t)idx_type, (H5_iter_order_t)order, (H5O_iterate_t)H5O_iterate_cb, (void*)op_data, (hid_t)access_id); - - UNPIN_JAVA_STRING(name, lName); + UNPIN_JAVA_STRING(name, lName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } + } return status; } /* end Java_hdf_hdf5lib_H5_H5Ovisit_1by_1name */ @@ -515,24 +502,20 @@ Java_hdf_hdf5lib_H5_H5Oset_1comment (JNIEnv *env, jclass clss, jlong loc_id, jstring comment) { herr_t status = -1; - const char *oComment; + const char *oComment = NULL; jboolean isCopy; if (comment == NULL) { - oComment = NULL; + status = H5Oset_comment((hid_t)loc_id, oComment); } /* end if */ else { oComment = ENVPTR->GetStringUTFChars(ENVPAR comment, &isCopy); - if (oComment == NULL) { - h5JNIFatalError( env, "H5Oset_comment: comment not pinned"); - return; - } /* end if */ - } /* end else */ - - status = H5Oset_comment((hid_t)loc_id, oComment); + if (oComment != NULL) { + status = H5Oset_comment((hid_t)loc_id, oComment); - if(oComment) - ENVPTR->ReleaseStringUTFChars(ENVPAR comment, oComment); + ENVPTR->ReleaseStringUTFChars(ENVPAR comment, oComment); + } + } /* end else */ if (status < 0) h5libraryError(env); @@ -552,30 +535,25 @@ Java_hdf_hdf5lib_H5_H5Oset_1comment_1by_1name const char *oName; const char *oComment; - PIN_JAVA_STRING0(name, oName); - - if (comment == NULL) { - oComment = NULL; - } /* end if */ - else { - jboolean isCopy; - oComment = ENVPTR->GetStringUTFChars(ENVPAR comment, &isCopy); - if (oComment == NULL) { - UNPIN_JAVA_STRING(name, oName); - h5JNIFatalError( env, "H5Oset_comment_by_name: comment not pinned"); - return; + PIN_JAVA_STRING(name, oName); + if (oName != NULL) { + if (comment == NULL) { + status = H5Oset_comment_by_name((hid_t)loc_id, oName, NULL, (hid_t)access_id); } /* end if */ - } /* end else */ - - status = H5Oset_comment_by_name((hid_t)loc_id, oName, oComment, (hid_t)access_id); + else { + jboolean isCopy; + oComment = ENVPTR->GetStringUTFChars(ENVPAR comment, &isCopy); + if (oComment != NULL) { + status = H5Oset_comment_by_name((hid_t)loc_id, oName, oComment, (hid_t)access_id); + ENVPTR->ReleaseStringUTFChars(ENVPAR comment, oComment); + } /* end if */ + } /* end else */ - UNPIN_JAVA_STRING(name, oName); - - if(oComment) - ENVPTR->ReleaseStringUTFChars(ENVPAR comment, oComment); + UNPIN_JAVA_STRING(name, oName); - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Oset_1comment_1by_1name */ /* @@ -596,34 +574,30 @@ Java_hdf_hdf5lib_H5_H5Oget_1comment buf_size = H5Oget_comment((hid_t)loc_id, NULL, 0); if (buf_size < 0) { h5badArgument( env, "H5Oget_comment: buf_size < 0"); - return NULL; - } /* end if */ - if (buf_size == 0) { - return NULL; } /* end if */ - - buf_size++; /* add extra space for the null terminator */ - oComment = (char *)HDmalloc(sizeof(char) * (size_t)buf_size); - if (oComment == NULL) { - /* exception -- out of memory */ - h5outOfMemory( env, "H5Oget_comment: malloc failed"); - return NULL; - } /* end if */ - - status = H5Oget_comment((hid_t)loc_id, oComment, (size_t)buf_size); - - if (status >= 0) { - /* may throw OutOfMemoryError */ - str = ENVPTR->NewStringUTF(ENVPAR oComment); - HDfree(oComment); - if (str == NULL) { - h5JNIFatalError( env, "H5Oget_comment: return string not allocated"); + else if (buf_size > 0) { + buf_size++; /* add extra space for the null terminator */ + oComment = (char *)HDmalloc(sizeof(char) * (size_t)buf_size); + if (oComment == NULL) { + /* exception -- out of memory */ + h5outOfMemory( env, "H5Oget_comment: malloc failed"); } /* end if */ - } /* end if */ - else { - HDfree(oComment); - h5libraryError(env); - } /* end else */ + else { + status = H5Oget_comment((hid_t)loc_id, oComment, (size_t)buf_size); + + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + /* may throw OutOfMemoryError */ + str = ENVPTR->NewStringUTF(ENVPAR oComment); + if (str == NULL) { + h5JNIFatalError( env, "H5Oget_comment: return string not allocated"); + } /* end if */ + } /* end else */ + HDfree(oComment); + } + } /* end else if */ return (jstring)str; } /* end Java_hdf_hdf5lib_H5_H5Oget_1comment */ @@ -643,43 +617,37 @@ Java_hdf_hdf5lib_H5_H5Oget_1comment_1by_1name ssize_t status; jstring str = NULL; - PIN_JAVA_STRING(name, oName, NULL); - - /* get the length of the comment */ - buf_size = H5Oget_comment_by_name((hid_t)loc_id, oName, NULL, 0, (hid_t)access_id); - if (buf_size < 0) { - UNPIN_JAVA_STRING(name, oName); - h5badArgument( env, "H5Oget_comment_by_name: buf_size < 0"); - return NULL; - } /* end if */ - if (buf_size == 0) { - UNPIN_JAVA_STRING(name, oName); - return NULL; - } /* end if */ - - buf_size++; /* add extra space for the null terminator */ - oComment = (char *)HDmalloc(sizeof(char) * (size_t)buf_size); - if (oComment == NULL) { - UNPIN_JAVA_STRING(name, oName); - h5outOfMemory( env, "H5Oget_comment_by_name: malloc failed"); - return NULL; - } /* end if */ - - status = H5Oget_comment_by_name((hid_t)loc_id, oName, oComment, (size_t)buf_size, (hid_t)access_id); - UNPIN_JAVA_STRING(name, oName); - - if (status >= 0) { - /* may throw OutOfMemoryError */ - str = ENVPTR->NewStringUTF(ENVPAR oComment); - HDfree(oComment); - if (str == NULL) { - h5JNIFatalError( env, "H5Oget_comment_by_name: return string not allocated"); + PIN_JAVA_STRING(name, oName); + if (oName != NULL) { + /* get the length of the comment */ + buf_size = H5Oget_comment_by_name((hid_t)loc_id, oName, NULL, 0, (hid_t)access_id); + if (buf_size < 0) { + h5badArgument( env, "H5Oget_comment_by_name: buf_size < 0"); } /* end if */ - } /* end if */ - else { - HDfree(oComment); - h5libraryError(env); - } /* end else */ + else if (buf_size > 0) { + buf_size++; /* add extra space for the null terminator */ + oComment = (char *)HDmalloc(sizeof(char) * (size_t)buf_size); + if (oComment == NULL) { + h5outOfMemory( env, "H5Oget_comment_by_name: malloc failed"); + } /* end if */ + else { + status = H5Oget_comment_by_name((hid_t)loc_id, oName, oComment, (size_t)buf_size, (hid_t)access_id); + + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + /* may throw OutOfMemoryError */ + str = ENVPTR->NewStringUTF(ENVPAR oComment); + if (str == NULL) { + h5JNIFatalError( env, "H5Oget_comment_by_name: return string not allocated"); + } /* end if */ + } /* end else */ + HDfree(oComment); + } + } /* end if */ + UNPIN_JAVA_STRING(name, oName); + } return (jstring)str; } /* end Java_hdf_hdf5lib_H5_H5Oget_1comment_1by_1name */ @@ -696,16 +664,17 @@ Java_hdf_hdf5lib_H5_H5Oexists_1by_1name htri_t bval = JNI_FALSE; const char *oName; - PIN_JAVA_STRING(name, oName, JNI_FALSE); - - bval = H5Oexists_by_name((hid_t)loc_id, oName, (hid_t)access_id); + PIN_JAVA_STRING(name, oName); + if (oName != NULL) { + bval = H5Oexists_by_name((hid_t)loc_id, oName, (hid_t)access_id); - UNPIN_JAVA_STRING(name, oName); + UNPIN_JAVA_STRING(name, oName); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + if (bval > 0) + bval = JNI_TRUE; + else if (bval < 0) + h5libraryError(env); + } return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Oexists_1by_1name */ @@ -767,14 +736,15 @@ Java_hdf_hdf5lib_H5__1H5Oopen_1by_1idx hid_t retVal = -1; const char *oName; - PIN_JAVA_STRING(name, oName, -1); + PIN_JAVA_STRING(name, oName); + if (oName != NULL) { + retVal = H5Oopen_by_idx((hid_t)loc_id, oName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (hid_t)lapl_id ); - retVal = H5Oopen_by_idx((hid_t)loc_id, oName, (H5_index_t)index_field, (H5_iter_order_t)order, (hsize_t)link_n, (hid_t)lapl_id ); + UNPIN_JAVA_STRING(name, oName); - UNPIN_JAVA_STRING(name, oName); - - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5__1H5Oopen_1by_1idx */ @@ -786,7 +756,7 @@ Java_hdf_hdf5lib_H5__1H5Oopen_1by_1idx */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Oflush - (JNIEnv *env, jclass clss, jlong loc_id) + (JNIEnv *env, jclass clss, jlong loc_id) { if (H5Oflush((hid_t)loc_id) < 0) h5libraryError(env); @@ -799,7 +769,7 @@ Java_hdf_hdf5lib_H5_H5Oflush */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5Orefresh - (JNIEnv *env, jclass clss, jlong loc_id) + (JNIEnv *env, jclass clss, jlong loc_id) { if (H5Orefresh((hid_t)loc_id) < 0) h5libraryError(env); diff --git a/java/src/jni/h5pImp.c b/java/src/jni/h5pImp.c index 11dcbe5..ad79733 100644 --- a/java/src/jni/h5pImp.c +++ b/java/src/jni/h5pImp.c @@ -632,14 +632,15 @@ Java_hdf_hdf5lib_H5_H5Pset_1external off = (off_t)offset; sz = (hsize_t)size; - PIN_JAVA_STRING(name, fileName, -1); + PIN_JAVA_STRING(name, fileName); + if (fileName != NULL) { + status = H5Pset_external(plid, fileName, off, sz); - status = H5Pset_external(plid, fileName, off, sz); + UNPIN_JAVA_STRING(name, fileName); - UNPIN_JAVA_STRING(name, fileName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Pset_1external */ @@ -675,66 +676,57 @@ Java_hdf_hdf5lib_H5_H5Pget_1external herr_t status = -1; jlong *theArray; jboolean isCopy; - char *file; + char *file = NULL; jstring str; off_t o; hsize_t s; if (name_size < 0) { h5badArgument(env, "H5Pget_external: name_size < 0"); - return -1; } /* end if */ - else if (name_size == 0) { - file = NULL; + else if ((size != NULL) && (ENVPTR->GetArrayLength(ENVPAR size) < 2)) { + h5badArgument(env, "H5Pget_external: size input array < 2"); } /* end else if */ else { - file = (char *)HDmalloc(sizeof(char)*(size_t)name_size); - } /* end else */ + if (name_size > 0) { + file = (char *)HDmalloc(sizeof(char)*(size_t)name_size); + } /* end else */ - if (size != NULL) { - if (ENVPTR->GetArrayLength(ENVPAR size) < 2) { - HDfree(file); - h5badArgument(env, "H5Pget_external: size input array < 2"); - return -1; - } /* end if */ - theArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR size, &isCopy); - if (theArray == NULL) { + status = H5Pget_external((hid_t) plist, (unsigned)idx, (size_t)name_size, + file, (off_t *)&o, (hsize_t *)&s); + if (status < 0) { HDfree(file); - h5JNIFatalError( env, "H5Pget_external: size array not pinned"); - return -1; - } /* end if */ - } /* end if */ - - status = H5Pget_external((hid_t) plist, (unsigned)idx, (size_t)name_size, - file, (off_t *)&o, (hsize_t *)&s); - if (status < 0) { - if (size != NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR size, theArray, JNI_ABORT); - } /* end if */ - HDfree(file); - h5libraryError(env); - } /* end if */ - else { - if (size != NULL) { - theArray[0] = o; - theArray[1] = (jlong)s; - ENVPTR->ReleaseLongArrayElements(ENVPAR size, theArray, 0); + h5libraryError(env); } /* end if */ + else { + if (size != NULL) { + theArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR size, &isCopy); + if (theArray == NULL) { + h5JNIFatalError( env, "H5Pget_external: size array not pinned"); + } /* end if */ + else { + theArray[0] = o; + theArray[1] = (jlong)s; + ENVPTR->ReleaseLongArrayElements(ENVPAR size, theArray, 0); + } + } /* end if */ - if (file != NULL) { - /* NewStringUTF may throw OutOfMemoryError */ - str = ENVPTR->NewStringUTF(ENVPAR file); - if (str == NULL) { - HDfree(file); - h5JNIFatalError(env, "H5Pget_external: return array not created"); + if (file != NULL) { + /* NewStringUTF may throw OutOfMemoryError */ + str = ENVPTR->NewStringUTF(ENVPAR file); + if (str == NULL) { + HDfree(file); + h5JNIFatalError(env, "H5Pget_external: return array not created"); + } /* end if */ + else { + /* SetObjectArrayElement may raise exceptions */ + ENVPTR->SetObjectArrayElement(ENVPAR name, 0, (jobject)str); + HDfree(file); + } /* end else */ } /* end if */ - else { - /* SetObjectArrayElement may raise exceptions */ - ENVPTR->SetObjectArrayElement(ENVPAR name, 0, (jobject)str); - HDfree(file); - } /* end else */ - } /* end if */ - } /* end else */ + } /* end else */ + } + return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Pget_1external */ @@ -748,26 +740,28 @@ Java_hdf_hdf5lib_H5_H5Pset_1fill_1value (JNIEnv *env, jclass clss, jlong plist_id, jlong type_id, jbyteArray value) { jint status = -1; - jbyte *byteP; + jbyte *byteP = NULL; jboolean isCopy; if (value != NULL) { byteP = ENVPTR->GetByteArrayElements(ENVPAR value, &isCopy); if (byteP == NULL) { h5JNIFatalError(env, "H5Pget_fill_value: value array not pinned"); - return -1; } /* end if */ - } /* end if */ - - status = H5Pset_fill_value((hid_t)plist_id, (hid_t)type_id, byteP); + else { + status = H5Pset_fill_value((hid_t)plist_id, (hid_t)type_id, byteP); - if (value != NULL) - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); + ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); + } + } /* end if */ + else { + status = H5Pset_fill_value((hid_t)plist_id, (hid_t)type_id, byteP); + } if (status < 0) h5libraryError(env); - return status; + return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Pset_1fill_1value */ /* @@ -802,7 +796,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1fill_1value } /* end else */ } /* end else */ - return status; + return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Pget_1fill_1value */ /* @@ -874,6 +868,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1filter jint *flagsArray; jlong *cd_nelmtsArray; jint *cd_valuesArray; + jint mode = JNI_ABORT; jboolean isCopy; jstring str; char *filter; @@ -893,65 +888,59 @@ Java_hdf_hdf5lib_H5_H5Pget_1filter else { filter = (char *)HDmalloc(sizeof(char)*(size_t)namelen); if (filter == NULL) { - h5outOfMemory(env, "H5Pget_filter: namelent malloc failed"); - return -1; - } /* end if */ - flagsArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR flags, &isCopy); - if (flagsArray == NULL) { - HDfree(filter); - h5JNIFatalError(env, "H5Pget_filter: flags array not pinned"); - return -1; - } /* end if */ - cd_nelmtsArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR cd_nelmts, &isCopy); - if (cd_nelmtsArray == NULL) { - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - HDfree(filter); - h5JNIFatalError(env, "H5Pget_filter: nelmts array not pinned"); - return -1; - } /* end if */ - cd_valuesArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR cd_values, &isCopy); - if (cd_valuesArray == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - HDfree(filter); - h5JNIFatalError(env, "H5Pget_filter: elmts array not pinned"); - return -1; - } /* end if */ - - { /* direct cast (size_t *)variable fails on 32-bit environment */ - long long cd_nelmts_temp = *(cd_nelmtsArray); - size_t cd_nelmts_t = (size_t)cd_nelmts_temp; - unsigned int filter_config; - status = H5Pget_filter2((hid_t)plist, (unsigned)filter_number, - (unsigned int *)flagsArray, &cd_nelmts_t, (unsigned int *)cd_valuesArray, - (size_t)namelen, filter, &filter_config); - - *cd_nelmtsArray = (jlong)cd_nelmts_t; - } /* end direct cast special */ - - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, JNI_ABORT); - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, JNI_ABORT); - HDfree(filter); - h5libraryError(env); + h5outOfMemory(env, "H5Pget_filter: namelen malloc failed"); } /* end if */ else { - ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, 0); - ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, 0); - ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, 0); - - /* NewStringUTF may throw OutOfMemoryError */ - str = ENVPTR->NewStringUTF(ENVPAR filter); - HDfree(filter); - if (str == NULL) { - h5JNIFatalError(env, "H5Pget_filter: return string not pinned"); + flagsArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR flags, &isCopy); + if (flagsArray == NULL) { + h5JNIFatalError(env, "H5Pget_filter: flags array not pinned"); } /* end if */ else { - /* SetObjectArrayElement may throw exceptiosn */ - ENVPTR->SetObjectArrayElement(ENVPAR name, 0, (jobject)str); - } /* end else */ - } /* end else */ + cd_nelmtsArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR cd_nelmts, &isCopy); + if (cd_nelmtsArray == NULL) { + h5JNIFatalError(env, "H5Pget_filter: nelmts array not pinned"); + } /* end if */ + else { + cd_valuesArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR cd_values, &isCopy); + if (cd_valuesArray == NULL) { + h5JNIFatalError(env, "H5Pget_filter: elmts array not pinned"); + } /* end if */ + else { + /* direct cast (size_t *)variable fails on 32-bit environment */ + long long cd_nelmts_temp = *(cd_nelmtsArray); + size_t cd_nelmts_t = (size_t)cd_nelmts_temp; + unsigned int filter_config; + status = H5Pget_filter2((hid_t)plist, (unsigned)filter_number, + (unsigned int *)flagsArray, &cd_nelmts_t, (unsigned int *)cd_valuesArray, + (size_t)namelen, filter, &filter_config); + + *cd_nelmtsArray = (jlong)cd_nelmts_t; + /* end direct cast special */ + + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + mode = 0; + + /* NewStringUTF may throw OutOfMemoryError */ + str = ENVPTR->NewStringUTF(ENVPAR filter); + if (str == NULL) { + h5JNIFatalError(env, "H5Pget_filter: return string not pinned"); + } /* end if */ + else { + /* SetObjectArrayElement may throw exceptiosn */ + ENVPTR->SetObjectArrayElement(ENVPAR name, 0, (jobject)str); + } /* end else */ + } /* end else */ + ENVPTR->ReleaseIntArrayElements(ENVPAR cd_values, cd_valuesArray, mode); + } + ENVPTR->ReleaseLongArrayElements(ENVPAR cd_nelmts, cd_nelmtsArray, mode); + } + ENVPTR->ReleaseIntArrayElements(ENVPAR flags, flagsArray, mode); + } + HDfree(filter); + } } /* end else */ return (jint)status; @@ -1007,15 +996,12 @@ Java_hdf_hdf5lib_H5_H5Pget_1cache { herr_t status = -1; jint mode; - jdouble *w0Array; - jlong *rdcc_nelmtsArray; - jlong *nbytesArray; + jdouble *w0Array = (jdouble *)NULL; + jlong *rdcc_nelmtsArray = (jlong *)NULL; + jlong *nbytesArray = (jlong *)NULL; jboolean isCopy; - if (rdcc_w0 == NULL) { - w0Array = (jdouble *)NULL; - } /* end if */ - else { + if (rdcc_w0 != NULL) { w0Array = (jdouble *)ENVPTR->GetDoubleArrayElements(ENVPAR rdcc_w0, &isCopy); if (w0Array == NULL) { h5JNIFatalError(env, "H5Pget_cache: w0_array array not pinned"); @@ -1023,10 +1009,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1cache } /* end if */ } /* end else */ - if (rdcc_nelmts == NULL) { - rdcc_nelmtsArray = (jlong *) NULL; - } /* end if */ - else { + if (rdcc_nelmts != NULL) { rdcc_nelmtsArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR rdcc_nelmts, &isCopy); if (rdcc_nelmtsArray == NULL) { /* exception -- out of memory */ @@ -1038,10 +1021,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1cache } /* end if */ } /* end else */ - if (rdcc_nbytes == NULL) { - nbytesArray = (jlong *) NULL; - } /* end if */ - else { + if (rdcc_nbytes != NULL) { nbytesArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR rdcc_nbytes, &isCopy); if (nbytesArray == NULL) { if (w0Array != NULL) { @@ -1148,7 +1128,7 @@ Java_hdf_hdf5lib_H5_H5Pset_1buffer if (bkg != NULL) ENVPTR->ReleaseByteArrayElements(ENVPAR bkg, bkgP, 0); - return status; + return (jint)status; #endif } /* end Java_hdf_hdf5lib_H5_H5Pset_1buffer */ @@ -1200,7 +1180,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1buffer ENVPTR->ReleaseByteArrayElements(ENVPAR tconv, tconvP, 0); ENVPTR->ReleaseByteArrayElements(ENVPAR bkg, bkgP, 0); - return status; + return (jint)status; #endif } /* end Java_hdf_hdf5lib_H5_H5Pget_1buffer */ @@ -1998,6 +1978,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1fapl_1family herr_t status = -1; jlong *sizeArray; jlong *plistArray; + jint mode = JNI_ABORT; jboolean isCopy; hsize_t *sa; size_t i; @@ -2013,39 +1994,36 @@ Java_hdf_hdf5lib_H5_H5Pget_1fapl_1family sizeArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR memb_size, &isCopy); if (sizeArray == NULL) { h5JNIFatalError(env, "H5Pget_family: sizeArray not pinned"); - return -1; - } /* end if */ - rank = (size_t)ENVPTR->GetArrayLength(ENVPAR memb_size); - sa = (hsize_t *)HDmalloc(rank * sizeof(hsize_t)); - if (sa == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR memb_size, sizeArray, JNI_ABORT); - h5JNIFatalError(env, "H5Screate-simple: dims not converted to hsize_t"); - return -1; - } /* end if */ - plistArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR memb_plist, &isCopy); - if (plistArray == NULL) { - HDfree(sa); - ENVPTR->ReleaseLongArrayElements(ENVPAR memb_size, sizeArray, JNI_ABORT); - h5JNIFatalError(env, "H5Pget_family: plistArray not pinned"); - return -1; - } /* end if */ - - status = H5Pget_fapl_family ((hid_t)tid, sa, (hid_t *)plistArray); - - if (status < 0) { - HDfree(sa); - ENVPTR->ReleaseLongArrayElements(ENVPAR memb_size, sizeArray, JNI_ABORT); - ENVPTR->ReleaseLongArrayElements(ENVPAR memb_plist, plistArray, JNI_ABORT); - h5libraryError(env); } /* end if */ else { - for (i = 0; i < rank; i++) { - sizeArray[i] = (jlong)sa[i]; - } /* end for */ - HDfree(sa); - ENVPTR->ReleaseLongArrayElements(ENVPAR memb_size, sizeArray, 0); - ENVPTR->ReleaseLongArrayElements(ENVPAR memb_plist, plistArray, 0); - } /* end else */ + rank = (size_t)ENVPTR->GetArrayLength(ENVPAR memb_size); + sa = (hsize_t *)HDmalloc(rank * sizeof(hsize_t)); + if (sa == NULL) { + h5JNIFatalError(env, "H5Screate-simple: dims not converted to hsize_t"); + } /* end if */ + else { + plistArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR memb_plist, &isCopy); + if (plistArray == NULL) { + h5JNIFatalError(env, "H5Pget_family: plistArray not pinned"); + } /* end if */ + else { + status = H5Pget_fapl_family ((hid_t)tid, sa, (hid_t *)plistArray); + + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + for (i = 0; i < rank; i++) { + sizeArray[i] = (jlong)sa[i]; + } /* end for */ + mode = 0; + } /* end else */ + ENVPTR->ReleaseLongArrayElements(ENVPAR memb_plist, plistArray, mode); + } + HDfree(sa); + } + ENVPTR->ReleaseLongArrayElements(ENVPAR memb_size, sizeArray, mode); + } } /* end else */ return (jint)status; @@ -2079,6 +2057,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1fapl_1core (JNIEnv *env, jclass clss, jlong fapl_id, jlongArray increment, jbooleanArray backing_store) { herr_t status = -1; + jint mode = JNI_ABORT; jlong *incArray; jboolean *backArray; jboolean isCopy; @@ -2093,34 +2072,32 @@ Java_hdf_hdf5lib_H5_H5Pget_1fapl_1core incArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR increment, &isCopy); if (incArray == NULL) { h5JNIFatalError(env, "H5Pget_fapl_core: incArray not pinned"); - return -1; - } /* end if */ - - backArray = (jboolean *)ENVPTR->GetBooleanArrayElements(ENVPAR backing_store, &isCopy); - if (backArray == NULL) { - ENVPTR->ReleaseLongArrayElements(ENVPAR increment, incArray, JNI_ABORT); - h5JNIFatalError(env, "H5Pget_fapl_core: backArray not pinned"); - return -1; } /* end if */ + else { + backArray = (jboolean *)ENVPTR->GetBooleanArrayElements(ENVPAR backing_store, &isCopy); + if (backArray == NULL) { + h5JNIFatalError(env, "H5Pget_fapl_core: backArray not pinned"); + } /* end if */ + else { + /* direct cast (size_t *)variable fails on 32-bit environment */ + long long inc_temp = *(incArray); + size_t inc_t = (size_t)inc_temp; - { /* direct cast (size_t *)variable fails on 32-bit environment */ - long long inc_temp = *(incArray); - size_t inc_t = (size_t)inc_temp; - - status = H5Pget_fapl_core((hid_t)fapl_id, &inc_t, (hbool_t *)backArray); + status = H5Pget_fapl_core((hid_t)fapl_id, &inc_t, (hbool_t *)backArray); - *incArray = (jlong)inc_t; - } /* end direct cast special */ + *incArray = (jlong)inc_t; + /* end direct cast special */ - if (status < 0) { - ENVPTR->ReleaseLongArrayElements(ENVPAR increment, incArray, JNI_ABORT); - ENVPTR->ReleaseBooleanArrayElements(ENVPAR backing_store, backArray, JNI_ABORT); - h5libraryError(env); - } /* end if */ - else { - ENVPTR->ReleaseLongArrayElements(ENVPAR increment, incArray, 0); - ENVPTR->ReleaseBooleanArrayElements(ENVPAR backing_store, backArray, 0); - } /* end else */ + if (status < 0) { + h5libraryError(env); + } /* end if */ + else { + mode = 0; + } /* end else */ + ENVPTR->ReleaseBooleanArrayElements(ENVPAR backing_store, backArray, mode); + } + ENVPTR->ReleaseLongArrayElements(ENVPAR increment, incArray, mode); + } } /* end else */ return (jint)status; @@ -2175,14 +2152,15 @@ Java_hdf_hdf5lib_H5_H5Pset_1fapl_1log herr_t retVal = -1; const char *pLogfile; - PIN_JAVA_STRING0(logfile, pLogfile); - - retVal = H5Pset_fapl_log( (hid_t)fapl_id, pLogfile, (unsigned long long)flags, (size_t)buf_size ); + PIN_JAVA_STRING(logfile, pLogfile); + if (pLogfile != NULL) { + retVal = H5Pset_fapl_log( (hid_t)fapl_id, pLogfile, (unsigned long long)flags, (size_t)buf_size ); - UNPIN_JAVA_STRING(logfile, pLogfile); + UNPIN_JAVA_STRING(logfile, pLogfile); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1log */ /* @@ -2200,7 +2178,7 @@ Java_hdf_hdf5lib_H5_H5P1remove_1filter if (status < 0) h5libraryError(env); - return status; + return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5P1remove_1filter */ @@ -2216,14 +2194,15 @@ Java_hdf_hdf5lib_H5_H5Pset hid_t retVal = -1; const char *cstr; - PIN_JAVA_STRING(name, cstr, -1); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + retVal = H5Pset((hid_t)plid, cstr, &val); - retVal = H5Pset((hid_t)plid, cstr, &val); - - UNPIN_JAVA_STRING(name, cstr); + UNPIN_JAVA_STRING(name, cstr); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jlong)retVal; } /* end Java_hdf_hdf5lib_H5_H5Pset */ @@ -2240,16 +2219,17 @@ Java_hdf_hdf5lib_H5_H5Pexist htri_t bval = JNI_FALSE; const char *cstr; - PIN_JAVA_STRING(name, cstr, JNI_FALSE); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + bval = H5Pexist((hid_t)plid, cstr); - bval = H5Pexist((hid_t)plid, cstr); - - UNPIN_JAVA_STRING(name, cstr); + UNPIN_JAVA_STRING(name, cstr); - if (bval > 0) - bval = JNI_TRUE; - else if (bval < 0) - h5libraryError(env); + if (bval > 0) + bval = JNI_TRUE; + else if (bval < 0) + h5libraryError(env); + } return (jboolean)bval; } /* end Java_hdf_hdf5lib_H5_H5Pexist */ @@ -2265,16 +2245,17 @@ Java_hdf_hdf5lib_H5_H5Pget_1size { hid_t retVal = -1; const char *cstr; - size_t size; + size_t size = 0; - PIN_JAVA_STRING(name, cstr, -1); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + retVal = H5Pget_size((hid_t)plid, cstr, &size); - retVal = H5Pget_size((hid_t)plid, cstr, &size); - - UNPIN_JAVA_STRING(name, cstr); + UNPIN_JAVA_STRING(name, cstr); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jlong) size; } /* end Java_hdf_hdf5lib_H5_H5Pget_1size */ @@ -2306,7 +2287,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1class_1name (JNIEnv *env, jclass clss, jlong plid) { char *c_str; - jstring j_str; + jstring j_str = NULL; c_str = H5Pget_class_name((hid_t)plid); if (c_str == NULL) { @@ -2371,14 +2352,15 @@ Java_hdf_hdf5lib_H5_H5Pget const char *cstr; jint val; - PIN_JAVA_STRING(name, cstr, -1); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + retVal = H5Pget((hid_t)plid, cstr, &val); - retVal = H5Pget((hid_t)plid, cstr, &val); - - UNPIN_JAVA_STRING(name, cstr); + UNPIN_JAVA_STRING(name, cstr); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jint)val; } /* end Java_hdf_hdf5lib_H5_H5Pget */ @@ -2413,14 +2395,15 @@ Java_hdf_hdf5lib_H5_H5Pcopy_1prop herr_t retVal = -1; const char *cstr; - PIN_JAVA_STRING(name, cstr, -1); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + retVal = H5Pcopy_prop((hid_t)dst_plid, (hid_t)src_plid, cstr); - retVal = H5Pcopy_prop((hid_t)dst_plid, (hid_t)src_plid, cstr); - - UNPIN_JAVA_STRING(name, cstr); + UNPIN_JAVA_STRING(name, cstr); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Pcopy_1prop */ @@ -2437,14 +2420,15 @@ Java_hdf_hdf5lib_H5_H5Premove herr_t retVal = -1; const char *cstr; - PIN_JAVA_STRING(name, cstr, -1); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + retVal = H5Premove((hid_t)plid, cstr); - retVal = H5Premove((hid_t)plid, cstr); - - UNPIN_JAVA_STRING(name, cstr); + UNPIN_JAVA_STRING(name, cstr); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Premove */ @@ -2461,14 +2445,15 @@ Java_hdf_hdf5lib_H5_H5Punregister herr_t retVal = -1; const char *cstr; - PIN_JAVA_STRING(name, cstr, -1); - - retVal = H5Punregister((hid_t)plid, cstr); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + retVal = H5Punregister((hid_t)plid, cstr); - UNPIN_JAVA_STRING(name, cstr); + UNPIN_JAVA_STRING(name, cstr); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Punregister */ @@ -2976,14 +2961,15 @@ Java_hdf_hdf5lib_H5_H5Pset_1data_1transform herr_t retVal = -1; const char *express; - PIN_JAVA_STRING(expression, express, -1); - - retVal = H5Pset_data_transform((hid_t)plist_id, express); + PIN_JAVA_STRING(expression, express); + if (express != NULL) { + retVal = H5Pset_data_transform((hid_t)plist_id, express); - UNPIN_JAVA_STRING(expression, express); + UNPIN_JAVA_STRING(expression, express); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Pset_1data_1transform */ @@ -3566,14 +3552,15 @@ Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix herr_t retVal = -1; const char *aName; - PIN_JAVA_STRING(prefix, aName, -1); + PIN_JAVA_STRING(prefix, aName); + if (aName != NULL) { + retVal = H5Pset_elink_prefix((hid_t)lapl_id, aName); - retVal = H5Pset_elink_prefix((hid_t)lapl_id, aName); + UNPIN_JAVA_STRING(prefix, aName); - UNPIN_JAVA_STRING(prefix, aName); - - if(retVal < 0) - h5libraryError(env); + if(retVal < 0) + h5libraryError(env); + } return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Pset_1elink_1prefix */ @@ -3589,7 +3576,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1elink_1prefix { size_t size = 0; char *pre; - jlong prefix_size; + jlong prefix_size = -1; jstring str = NULL; if (prefix == NULL) { @@ -3966,14 +3953,15 @@ Java_hdf_hdf5lib_H5_H5Pset_1fapl_1split const char *mstr; const char *rstr; - PIN_JAVA_STRING_TWO0(metaext, mstr, rawext, rstr); + PIN_JAVA_STRING_TWO(metaext, mstr, rawext, rstr); + if (mstr != NULL && rstr != NULL) { + retVal = H5Pset_fapl_split((hid_t)fapl_id, mstr, (hid_t)meta_pl_id, rstr, (hid_t)raw_pl_id); - retVal = H5Pset_fapl_split((hid_t)fapl_id, mstr, (hid_t)meta_pl_id, rstr, (hid_t)raw_pl_id); + UNPIN_JAVA_STRING_TWO(metaext, mstr, rawext, rstr); - UNPIN_JAVA_STRING_TWO(metaext, mstr, rawext, rstr); - - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Pset_1fapl_1split */ /* @@ -4034,7 +4022,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1sieve_1buf_1size { size_t s; - if ( H5Pget_sieve_buf_size((hid_t)plist, &s) < 0) + if (H5Pget_sieve_buf_size((hid_t)plist, &s) < 0) h5libraryError(env); return (jlong)s; @@ -4486,13 +4474,13 @@ Java_hdf_hdf5lib_H5_H5Pset_1mdc_1config cacheinfo.metadata_write_strategy = ENVPTR->GetIntField(ENVPAR cache_config, fid); if(ENVPTR->ExceptionOccurred(ENVONLY)) { h5JNIFatalError(env, "H5Pset_mdc_config: loading metadata_write_strategy failed"); - return; } /* end if */ + else { + status = H5Pset_mdc_config((hid_t)plist, &cacheinfo); - status = H5Pset_mdc_config((hid_t)plist, &cacheinfo); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Pset_1mdc_1config */ /* @@ -4521,15 +4509,12 @@ Java_hdf_hdf5lib_H5_H5Pget_1chunk_1cache { herr_t status = -1; jint mode; - jdouble *w0Array; - jlong *rdcc_nslotsArray; - jlong *nbytesArray; + jdouble *w0Array = (jdouble *)NULL; + jlong *rdcc_nslotsArray = (jlong *)NULL; + jlong *nbytesArray = (jlong *)NULL; jboolean isCopy; - if (rdcc_w0 == NULL) { - w0Array = (jdouble *)NULL; - } /* end if */ - else { + if (rdcc_w0 != NULL) { w0Array = (jdouble *)ENVPTR->GetDoubleArrayElements(ENVPAR rdcc_w0, &isCopy); if (w0Array == NULL) { h5JNIFatalError(env, "H5Pget_chunk_cache: w0_array array not pinned"); @@ -4537,10 +4522,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1chunk_1cache } /* end if */ } /* end else */ - if (rdcc_nslots == NULL) { - rdcc_nslotsArray = (jlong *)NULL; - } /* end if */ - else { + if (rdcc_nslots != NULL) { rdcc_nslotsArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR rdcc_nslots, &isCopy); if (rdcc_nslotsArray == NULL) { /* exception -- out of memory */ @@ -4552,10 +4534,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1chunk_1cache } /* end if */ } /* end else */ - if (rdcc_nbytes == NULL) { - nbytesArray = (jlong *)NULL; - } /* end if */ - else { + if (rdcc_nbytes != NULL) { nbytesArray = (jlong *)ENVPTR->GetLongArrayElements(ENVPAR rdcc_nbytes, &isCopy); if (nbytesArray == NULL) { if (w0Array != NULL) { @@ -4691,14 +4670,15 @@ Java_hdf_hdf5lib_H5_H5Pset_1virtual const char *fstr; const char *dstr; - PIN_JAVA_STRING_TWO0(src_file_name, fstr, src_dset_name, dstr); - - retVal = H5Pset_virtual((hid_t)dcpl_id, (hid_t)vspace_id, fstr, dstr, (hid_t)src_space_id); + PIN_JAVA_STRING_TWO(src_file_name, fstr, src_dset_name, dstr); + if (fstr != NULL && dstr != NULL) { + retVal = H5Pset_virtual((hid_t)dcpl_id, (hid_t)vspace_id, fstr, dstr, (hid_t)src_space_id); - UNPIN_JAVA_STRING_TWO(src_file_name, fstr, src_dset_name, dstr); + UNPIN_JAVA_STRING_TWO(src_file_name, fstr, src_dset_name, dstr); - if (retVal < 0) - h5libraryError(env); + if (retVal < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Pset_1virtual */ /* @@ -4981,7 +4961,7 @@ H5P_cls_create_cb } /* end if */ } /* end if */ JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5P_cls_create_cb */ static herr_t @@ -4989,7 +4969,7 @@ H5P_cls_copy_cb (hid_t new_prop_id, hid_t old_prop_id, void *copy_data) { JNIEnv *cbenv; - jint status; + jint status = -1; jclass cls; jmethodID mid; jmethodID constructor; @@ -5004,7 +4984,7 @@ H5P_cls_copy_cb } /* end if */ } /* end if */ JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5P_cls_ccopy_cb */ static herr_t @@ -5012,7 +4992,7 @@ H5P_cls_close_cb (hid_t prop_id, void *close_data) { JNIEnv *cbenv; - jint status; + jint status = -1; jclass cls; jmethodID mid; jmethodID constructor; @@ -5027,7 +5007,7 @@ H5P_cls_close_cb } /* end if */ } /* end if */ JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5P_cls_close_cb */ static herr_t @@ -5035,7 +5015,7 @@ H5D_append_cb (hid_t dataset_id, hsize_t *cur_dims, void *op_data) { JNIEnv *cbenv; - jint status; + jint status = -1; jclass cls; jmethodID mid; jlongArray cur_dimsArray; @@ -5046,33 +5026,22 @@ H5D_append_cb return -1; } /* end if */ cls = CBENVPTR->GetObjectClass(CBENVPAR visit_callback); - if (cls == 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(J[JLhdf/hdf5lib/callbacks/H5D_append_t;)I"); - if (mid == 0) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - - if (cur_dims == NULL) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; - } /* end if */ - - cur_dimsArray = CBENVPTR->NewLongArray(CBENVPAR 2); - if (cur_dimsArray == NULL) { - JVMPTR->DetachCurrentThread(JVMPAR); - return -1; + if (cls != 0) { + mid = CBENVPTR->GetMethodID(CBENVPAR cls, "callback", "(J[JLhdf/hdf5lib/callbacks/H5D_append_t;)I"); + if (mid != 0) { + if (cur_dims != NULL) { + cur_dimsArray = CBENVPTR->NewLongArray(CBENVPAR 2); + if (cur_dimsArray != NULL) { + CBENVPTR->SetLongArrayRegion(CBENVPAR cur_dimsArray, 0, 2, (const jlong *)cur_dims); + + status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, dataset_id, cur_dims, op_data); + } + } + } } /* end if */ - CBENVPTR->SetLongArrayRegion(CBENVPAR cur_dimsArray, 0, 2, (const jlong *)cur_dims); - - status = CBENVPTR->CallIntMethod(CBENVPAR visit_callback, mid, dataset_id, cur_dims, op_data); - JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5D_append_cb */ /* @@ -5115,14 +5084,15 @@ Java_hdf_hdf5lib_H5__1H5Pcreate_1class_1nocb hid_t class_id = -1; const char *cstr; - PIN_JAVA_STRING(name, cstr, -1); - - class_id = H5Pcreate_class((hid_t)parent_class, cstr, NULL, NULL, NULL, NULL, NULL, NULL); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + class_id = H5Pcreate_class((hid_t)parent_class, cstr, NULL, NULL, NULL, NULL, NULL, NULL); - UNPIN_JAVA_STRING(name, cstr); + UNPIN_JAVA_STRING(name, cstr); - if (class_id < 0) - h5libraryError(env); + if (class_id < 0) + h5libraryError(env); + } return (jlong)class_id; } /* end Java_hdf_hdf5lib_H5__1H5Pcreate_1class_1nocb */ @@ -5143,15 +5113,16 @@ Java_hdf_hdf5lib_H5__1H5Pcreate_1class close_callback = close_op; create_callback = create_op; - PIN_JAVA_STRING(name, cstr, -1); - - class_id = H5Pcreate_class((hid_t)parent_class, cstr, (H5P_cls_create_func_t)H5P_cls_create_cb, (void*) create_data, - (H5P_cls_copy_func_t)H5P_cls_copy_cb, (void*) copy_data, (H5P_cls_close_func_t)H5P_cls_close_cb, (void*) close_data); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + class_id = H5Pcreate_class((hid_t)parent_class, cstr, (H5P_cls_create_func_t)H5P_cls_create_cb, (void*) create_data, + (H5P_cls_copy_func_t)H5P_cls_copy_cb, (void*) copy_data, (H5P_cls_close_func_t)H5P_cls_close_cb, (void*) close_data); - UNPIN_JAVA_STRING(name, cstr); + UNPIN_JAVA_STRING(name, cstr); - if (class_id < 0) - h5libraryError(env); + if (class_id < 0) + h5libraryError(env); + } return (jlong)class_id; } /* end Java_hdf_hdf5lib_H5__1H5Pcreate_1class */ @@ -5161,7 +5132,7 @@ H5P_prp_create_cb (const char *name, size_t size, void *value) { JNIEnv *cbenv; - jint status; + jint status = -1; jclass cls; jmethodID mid; jmethodID constructor; @@ -5178,7 +5149,7 @@ H5P_prp_create_cb } /* end if */ } /* end if */ JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5P_prp_create_cb */ static herr_t @@ -5186,7 +5157,7 @@ H5P_prp_copy_cb (const char *name, size_t size, void *value) { JNIEnv *cbenv; - jint status; + jint status = -1; jclass cls; jmethodID mid; jmethodID constructor; @@ -5203,7 +5174,7 @@ H5P_prp_copy_cb } /* end if */ } /* end if */ JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5P_prp_copy_cb */ static herr_t @@ -5211,7 +5182,7 @@ H5P_prp_close_cb (const char *name, size_t size, void *value) { JNIEnv *cbenv; - jint status; + jint status = -1; jclass cls; jmethodID mid; jmethodID constructor; @@ -5228,7 +5199,7 @@ H5P_prp_close_cb } /* end if */ } /* end if */ JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5P_prp_close_cb */ static int @@ -5236,7 +5207,7 @@ H5P_prp_compare_cb (void *value1, void *value2, size_t size) { JNIEnv *cbenv; - jint status; + jint status = -1; jclass cls; jmethodID mid; jmethodID constructor; @@ -5251,7 +5222,7 @@ H5P_prp_compare_cb } /* end if */ } /* end if */ JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5P_prp_compare_cb */ static herr_t @@ -5259,7 +5230,7 @@ H5P_prp_get_cb (hid_t prop_id, const char *name, size_t size, void *value) { JNIEnv *cbenv; - jint status; + jint status = -1; jclass cls; jmethodID mid; jmethodID constructor; @@ -5276,7 +5247,7 @@ H5P_prp_get_cb } /* end if */ } /* end if */ JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5P_prp_get_cb */ static herr_t @@ -5284,7 +5255,7 @@ H5P_prp_set_cb (hid_t prop_id, const char *name, size_t size, void *value) { JNIEnv *cbenv; - jint status; + jint status = -1; jclass cls; jmethodID mid; jmethodID constructor; @@ -5301,7 +5272,7 @@ H5P_prp_set_cb } /* end if */ } /* end if */ JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5P_prp_set_cb */ static herr_t @@ -5309,7 +5280,7 @@ H5P_prp_delete_cb (hid_t prop_id, const char *name, size_t size, void *value) { JNIEnv *cbenv; - jint status; + jint status = -1; jclass cls; jmethodID mid; jmethodID constructor; @@ -5326,7 +5297,7 @@ H5P_prp_delete_cb } /* end if */ } /* end if */ JVMPTR->DetachCurrentThread(JVMPAR); - return status; + return (herr_t)status; } /* end H5P_prp_delete_cb */ /* @@ -5343,24 +5314,25 @@ Java_hdf_hdf5lib_H5_H5Pregister2_1nocb jboolean isCopy2; const char *cstr; - PIN_JAVA_STRING0(name, cstr); - buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); - if (buffP == NULL) { - UNPIN_JAVA_STRING(name, cstr); - h5JNIFatalError(env, "H5Pregister2: buf not pinned"); - } /* end if */ - else { - status = H5Pregister2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - - UNPIN_JAVA_STRING(name, cstr); - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); - h5libraryError(env); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); + if (buffP == NULL) { + h5JNIFatalError(env, "H5Pregister2: buf not pinned"); } /* end if */ else { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); + status = H5Pregister2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + + if (status < 0) { + ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); + h5libraryError(env); + } /* end if */ + else { + ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); + } /* end else */ } /* end else */ - } /* end else */ + UNPIN_JAVA_STRING(name, cstr); + } } /* end Java_hdf_hdf5lib_H5_H5Pregister2_1nocb */ /* @@ -5386,26 +5358,27 @@ Java_hdf_hdf5lib_H5_H5Pregister2 get_callback = prp_get; delete_callback = prp_delete; - PIN_JAVA_STRING0(name, cstr); - buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); - if (buffP == NULL) { - UNPIN_JAVA_STRING(name, cstr); - h5JNIFatalError(env, "H5Pregister2: buf not pinned"); - } /* end if */ - else { - status = H5Pregister2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, (H5P_prp_create_func_t)H5P_prp_create_cb, - (H5P_prp_set_func_t)H5P_prp_set_cb, (H5P_prp_get_func_t)H5P_prp_get_cb, (H5P_prp_delete_func_t)H5P_prp_delete_cb, - (H5P_prp_copy_func_t)H5P_prp_copy_cb, (H5P_prp_compare_func_t)H5P_prp_compare_cb, (H5P_prp_close_func_t)H5P_prp_close_cb); - - UNPIN_JAVA_STRING(name, cstr); - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); - h5libraryError(env); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); + if (buffP == NULL) { + h5JNIFatalError(env, "H5Pregister2: buf not pinned"); } /* end if */ else { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); + status = H5Pregister2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, (H5P_prp_create_func_t)H5P_prp_create_cb, + (H5P_prp_set_func_t)H5P_prp_set_cb, (H5P_prp_get_func_t)H5P_prp_get_cb, (H5P_prp_delete_func_t)H5P_prp_delete_cb, + (H5P_prp_copy_func_t)H5P_prp_copy_cb, (H5P_prp_compare_func_t)H5P_prp_compare_cb, (H5P_prp_close_func_t)H5P_prp_close_cb); + + if (status < 0) { + ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); + h5libraryError(env); + } /* end if */ + else { + ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); + } /* end else */ } /* end else */ - } /* end else */ + UNPIN_JAVA_STRING(name, cstr); + } } /* end Java_hdf_hdf5lib_H5_H5Pregister2 */ /* @@ -5422,24 +5395,25 @@ Java_hdf_hdf5lib_H5_H5Pinsert2_1nocb jboolean isCopy2; const char *cstr; - PIN_JAVA_STRING0(name, cstr); - buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); - if (buffP == NULL) { - UNPIN_JAVA_STRING(name, cstr); - h5JNIFatalError(env, "H5Pinsert2: buf not pinned"); - } /* end if */ - else { - status = H5Pinsert2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, NULL, NULL, NULL, NULL, NULL, NULL); - - UNPIN_JAVA_STRING(name, cstr); - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); - h5libraryError(env); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); + if (buffP == NULL) { + h5JNIFatalError(env, "H5Pinsert2: buf not pinned"); } /* end if */ else { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); + status = H5Pinsert2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, NULL, NULL, NULL, NULL, NULL, NULL); + + if (status < 0) { + ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); + h5libraryError(env); + } /* end if */ + else { + ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); + } /* end else */ } /* end else */ - } /* end else */ + UNPIN_JAVA_STRING(name, cstr); + } } /* end Java_hdf_hdf5lib_H5_H5Pinsert2 */ @@ -5465,26 +5439,28 @@ Java_hdf_hdf5lib_H5_H5Pinsert2 get_callback = prp_get; delete_callback = prp_delete; - PIN_JAVA_STRING0(name, cstr); - buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); - if (buffP == NULL) { - UNPIN_JAVA_STRING(name, cstr); - h5JNIFatalError(env, "H5Pinsert2: buf not pinned"); - } /* end if */ - else { - status = H5Pinsert2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, - (H5P_prp_set_func_t)H5P_prp_set_cb, (H5P_prp_get_func_t)H5P_prp_get_cb, (H5P_prp_delete_func_t)H5P_prp_delete_cb, - (H5P_prp_copy_func_t)H5P_prp_copy_cb, (H5P_prp_compare_func_t)H5P_prp_compare_cb, (H5P_prp_close_func_t)H5P_prp_close_cb); - - UNPIN_JAVA_STRING(name, cstr); - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); - h5libraryError(env); + PIN_JAVA_STRING(name, cstr); + if (cstr != NULL) { + buffP = ENVPTR->GetByteArrayElements(ENVPAR def_value, &isCopy2); + if (buffP == NULL) { + UNPIN_JAVA_STRING(name, cstr); + h5JNIFatalError(env, "H5Pinsert2: buf not pinned"); } /* end if */ else { - ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); + status = H5Pinsert2((hid_t)cls_id, cstr, (size_t)prp_size, (void*)buffP, + (H5P_prp_set_func_t)H5P_prp_set_cb, (H5P_prp_get_func_t)H5P_prp_get_cb, (H5P_prp_delete_func_t)H5P_prp_delete_cb, + (H5P_prp_copy_func_t)H5P_prp_copy_cb, (H5P_prp_compare_func_t)H5P_prp_compare_cb, (H5P_prp_close_func_t)H5P_prp_close_cb); + + if (status < 0) { + ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, JNI_ABORT); + h5libraryError(env); + } /* end if */ + else { + ENVPTR->ReleaseByteArrayElements(ENVPAR def_value, buffP, 0); + } /* end else */ } /* end else */ - } /* end else */ + UNPIN_JAVA_STRING(name, cstr); + } } /* end Java_hdf_hdf5lib_H5_H5Pinsert2 */ static herr_t @@ -5561,9 +5537,9 @@ Java_hdf_hdf5lib_H5_H5Piterate theArray = (jint *)ENVPTR->GetIntArrayElements(ENVPAR idx, &isCopy); if (theArray == NULL) { h5JNIFatalError(env, "H5Piterate: idx not pinned"); - return -1; } /* end if */ - status = H5Piterate((hid_t)prop_id, (int*)&theArray[0], (H5P_iterate_t)H5P_iterate_cb, (void*)op_data); + else + status = H5Piterate((hid_t)prop_id, (int*)&theArray[0], (H5P_iterate_t)H5P_iterate_cb, (void*)op_data); } /* end else */ if (status < 0) { @@ -5575,7 +5551,7 @@ Java_hdf_hdf5lib_H5_H5Piterate ENVPTR->ReleaseIntArrayElements(ENVPAR idx, theArray, 0); } /* end else */ - return status; + return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Piterate */ #ifdef __cplusplus diff --git a/java/src/jni/h5rImp.c b/java/src/jni/h5rImp.c index df0ea3c..647f973 100644 --- a/java/src/jni/h5rImp.c +++ b/java/src/jni/h5rImp.c @@ -46,45 +46,41 @@ Java_hdf_hdf5lib_H5_H5Rcreate jbyte *refP; jboolean isCopy2; - PIN_JAVA_STRING(name, rName, -1); - - if (ref == NULL) { - UNPIN_JAVA_STRING(name, rName); - h5nullArgument( env, "H5Rcreate: ref is NULL"); - } /* end if */ - else { - if ((ref_type == H5R_OBJECT) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_OBJ_REF_BUF_SIZE) { - UNPIN_JAVA_STRING(name, rName); - h5badArgument( env, "H5Rcreate: ref input array != H5R_OBJ_REF_BUF_SIZE"); + PIN_JAVA_STRING(name, rName); + if (rName != NULL) { + if (ref == NULL) { + h5nullArgument( env, "H5Rcreate: ref is NULL"); } /* end if */ - else if ((ref_type == H5R_DATASET_REGION) && ENVPTR->GetArrayLength(ENVPAR ref) != H5R_DSET_REG_REF_BUF_SIZE) { - UNPIN_JAVA_STRING(name, rName); - 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)) { - UNPIN_JAVA_STRING(name, rName); - h5badArgument( env, "H5Rcreate: ref_type unknown type "); - } /* end else if */ else { - refP = (jbyte*)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy2); - if (refP == NULL) { - UNPIN_JAVA_STRING(name, rName); - h5JNIFatalError(env, "H5Rcreate: ref not pinned"); + 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 { - status = H5Rcreate(refP, (hid_t)loc_id, rName, (H5R_type_t)ref_type, (hid_t)space_id); - - UNPIN_JAVA_STRING(name, rName); - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, JNI_ABORT); - h5libraryError(env); + refP = (jbyte*)ENVPTR->GetByteArrayElements(ENVPAR ref, &isCopy2); + if (refP == NULL) { + h5JNIFatalError(env, "H5Rcreate: ref not pinned"); } /* end if */ else { - ENVPTR->ReleaseByteArrayElements(ENVPAR ref, refP, 0); + 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 */ - } /* end else */ + UNPIN_JAVA_STRING(name, rName); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Rcreate */ diff --git a/java/src/jni/h5tImp.c b/java/src/jni/h5tImp.c index 55e16f8..1467b41 100644 --- a/java/src/jni/h5tImp.c +++ b/java/src/jni/h5tImp.c @@ -43,17 +43,18 @@ JNIEXPORT jlong JNICALL Java_hdf_hdf5lib_H5__1H5Topen2 (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist) { - hid_t status; + hid_t status = -1; const char *tName; - PIN_JAVA_STRING(name, tName, -1); + PIN_JAVA_STRING(name, tName); + if (tName != NULL) { + status = H5Topen2((hid_t)loc_id, tName, (hid_t)access_plist); - status = H5Topen2((hid_t)loc_id, tName, (hid_t)access_plist); + UNPIN_JAVA_STRING(name, tName); - UNPIN_JAVA_STRING(name, tName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jlong)status; } /* end Java_hdf_hdf5lib_H5__1H5Topen2 */ @@ -789,14 +790,15 @@ Java_hdf_hdf5lib_H5_H5Tget_1member_1index const char *tName; int index = -1; - PIN_JAVA_STRING(field_name, tName, -1); + PIN_JAVA_STRING(field_name, tName); + if (tName != NULL) { + index = H5Tget_member_index((hid_t)type_id, tName); - index = H5Tget_member_index((hid_t)type_id, tName); + UNPIN_JAVA_STRING(field_name, tName); - UNPIN_JAVA_STRING(field_name, tName); - - if (index < 0) - h5libraryError(env); + if (index < 0) + h5libraryError(env); + } return (jint)index; } /* end Java_hdf_hdf5lib_H5_H5Tget_1member_1index */ @@ -858,17 +860,18 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Tinsert (JNIEnv *env, jclass clss, jlong type_id, jstring name, jlong offset, jlong field_id) { - herr_t status; + herr_t status = -1; const char *tName; long off = (long)offset; - PIN_JAVA_STRING(name, tName, -1); + PIN_JAVA_STRING(name, tName); + if (tName != NULL) { + status = H5Tinsert((hid_t)type_id, tName, (size_t)off, field_id); - status = H5Tinsert((hid_t)type_id, tName, (size_t)off, field_id); - - UNPIN_JAVA_STRING(name,tName); - if (status < 0) - h5libraryError(env); + UNPIN_JAVA_STRING(name,tName); + if (status < 0) + h5libraryError(env); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Tinsert */ @@ -939,14 +942,15 @@ Java_hdf_hdf5lib_H5_H5Tset_1tag herr_t status = -1; const char *tagP; - PIN_JAVA_STRING(tag, tagP, -1); + PIN_JAVA_STRING(tag, tagP); + if (tagP != NULL) { + status = H5Tset_tag((hid_t)type, tagP); - status = H5Tset_tag((hid_t)type, tagP); + UNPIN_JAVA_STRING(tag,tagP); - UNPIN_JAVA_STRING(tag,tagP); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Tset_1tag */ @@ -1029,21 +1033,22 @@ Java_hdf_hdf5lib_H5_H5Tenum_1insert_1int h5nullArgument(env, "H5Tenum_insert: value is NULL"); } /* end if */ else { - PIN_JAVA_STRING(name, nameP, -1); - - intP = ENVPTR->GetIntArrayElements(ENVPAR value, &isCopy2); - if (intP == NULL) { - h5JNIFatalError(env, "H5Tenum_insert: value not pinned"); - } /* end if */ - else { - status = H5Tenum_insert((hid_t)type_id, nameP, intP); + PIN_JAVA_STRING(name, nameP); + if (nameP != NULL) { + intP = ENVPTR->GetIntArrayElements(ENVPAR value, &isCopy2); + if (intP == NULL) { + h5JNIFatalError(env, "H5Tenum_insert: value not pinned"); + } /* end if */ + else { + status = H5Tenum_insert((hid_t)type_id, nameP, intP); - ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, JNI_ABORT); + ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, JNI_ABORT); - if (status < 0) - h5libraryError(env); - } /* end else */ - UNPIN_JAVA_STRING(name, nameP); + if (status < 0) + h5libraryError(env); + } /* end else */ + UNPIN_JAVA_STRING(name, nameP); + } } /* end else */ return (jint)status; @@ -1067,21 +1072,22 @@ Java_hdf_hdf5lib_H5_H5Tenum_1insert h5nullArgument(env, "H5Tenum_insert: value is NULL"); } /* end if */ else { - PIN_JAVA_STRING0(name, nameP); - - byteP = ENVPTR->GetByteArrayElements(ENVPAR value, &isCopy2); - if (byteP == NULL) { - h5JNIFatalError(env, "H5Tenum_insert: value not pinned"); - } /* end if */ - else { - status = H5Tenum_insert((hid_t)type_id, nameP, byteP); + PIN_JAVA_STRING(name, nameP); + if (nameP != NULL) { + byteP = ENVPTR->GetByteArrayElements(ENVPAR value, &isCopy2); + if (byteP == NULL) { + h5JNIFatalError(env, "H5Tenum_insert: value not pinned"); + } /* end if */ + else { + status = H5Tenum_insert((hid_t)type_id, nameP, byteP); - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); + ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); - if (status < 0) - h5libraryError(env); - } /* end else */ - UNPIN_JAVA_STRING(name, nameP); + if (status < 0) + h5libraryError(env); + } /* end else */ + UNPIN_JAVA_STRING(name, nameP); + } } /* end else */ } /* end Java_hdf_hdf5lib_H5_H5Tenum_1insert */ @@ -1218,23 +1224,24 @@ Java_hdf_hdf5lib_H5_H5Tenum_1valueof_1int h5nullArgument(env, "H5Tenum_valueof: value is NULL"); } /* end if */ else { - PIN_JAVA_STRING(name, nameP, -1); - - intP = ENVPTR->GetIntArrayElements(ENVPAR value, &isCopy2); - if (intP == NULL) { - h5JNIFatalError(env, "H5Tenum_valueof: value not pinned"); - } /* end if */ - else { - status = H5Tenum_valueof((hid_t)type_id, nameP, intP); - - if (status < 0) { - ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, JNI_ABORT); - h5libraryError(env); + PIN_JAVA_STRING(name, nameP); + if (nameP != NULL) { + intP = ENVPTR->GetIntArrayElements(ENVPAR value, &isCopy2); + if (intP == NULL) { + h5JNIFatalError(env, "H5Tenum_valueof: value not pinned"); } /* end if */ - else - ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, 0); - } /* end else */ - UNPIN_JAVA_STRING(name, nameP); + else { + status = H5Tenum_valueof((hid_t)type_id, nameP, intP); + + if (status < 0) { + ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, JNI_ABORT); + h5libraryError(env); + } /* end if */ + else + ENVPTR->ReleaseIntArrayElements(ENVPAR value, intP, 0); + } /* end else */ + UNPIN_JAVA_STRING(name, nameP); + } } /* end else */ return (jint)status; @@ -1258,23 +1265,24 @@ Java_hdf_hdf5lib_H5_H5Tenum_1valueof h5nullArgument(env, "H5Tenum_valueof: value is NULL"); } /* end if */ else { - PIN_JAVA_STRING0(name, nameP); - - byteP = ENVPTR->GetByteArrayElements(ENVPAR value, &isCopy2); - if (byteP == NULL) { - h5JNIFatalError(env, "H5Tenum_valueof: value not pinned"); - } /* end if */ - else { - status = H5Tenum_valueof((hid_t)type_id, nameP, byteP); - - if (status < 0) { - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); - h5libraryError(env); + PIN_JAVA_STRING(name, nameP); + if (nameP != NULL) { + byteP = ENVPTR->GetByteArrayElements(ENVPAR value, &isCopy2); + if (byteP == NULL) { + h5JNIFatalError(env, "H5Tenum_valueof: value not pinned"); } /* end if */ - else - ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, 0); - } /* end else */ - UNPIN_JAVA_STRING(name, nameP); + else { + status = H5Tenum_valueof((hid_t)type_id, nameP, byteP); + + if (status < 0) { + ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, JNI_ABORT); + h5libraryError(env); + } /* end if */ + else + ENVPTR->ReleaseByteArrayElements(ENVPAR value, byteP, 0); + } /* end else */ + UNPIN_JAVA_STRING(name, nameP); + } } /* end else */ } /* end Java_hdf_hdf5lib_H5_H5Tenum_1valueof */ @@ -1487,14 +1495,15 @@ Java_hdf_hdf5lib_H5_H5Tcommit herr_t status = -1; const char *tName; - PIN_JAVA_STRING0(name, tName); + PIN_JAVA_STRING(name, tName); + if (tName != NULL) { + status = H5Tcommit2((hid_t)loc_id, tName, (hid_t)type, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id); - status = H5Tcommit2((hid_t)loc_id, tName, (hid_t)type, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id); + UNPIN_JAVA_STRING(name, tName); - UNPIN_JAVA_STRING(name, tName); - - if (status < 0) - h5libraryError(env); + if (status < 0) + h5libraryError(env); + } } /* end Java_hdf_hdf5lib_H5_H5Tcommit */ /* diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c index e39b342..acf57c8 100644 --- a/java/src/jni/h5util.c +++ b/java/src/jni/h5util.c @@ -2009,6 +2009,60 @@ Java_hdf_hdf5lib_H5_H5AreadVL } /* end Java_hdf_hdf5lib_H5_H5AreadVL */ /* + * Class: hdf_hdf5lib_H5 + * Method: H5AreadComplex + * Signature: (JJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5AreadComplex +(JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) +{ + herr_t status = -1; + int i; + int n; + char *rdata; + size_t max_len = 0; + size_t size; + h5str_t h5str; + hid_t p_type = -1; + jstring jstr; + + p_type = H5Tget_native_type(mem_type_id, H5T_DIR_DEFAULT); + size = (((H5Tget_size(mem_type_id))>(H5Tget_size(p_type))) ? (H5Tget_size(mem_type_id)) : (H5Tget_size(p_type))); + H5Tclose(p_type); + + n = ENVPTR->GetArrayLength(ENVPAR buf); + rdata = (char *)malloc((size_t)n * size); + if (rdata == NULL) { + h5JNIFatalError(env, "H5AreadComplex: failed to allocate buff for read"); + } /* end if */ + else { + status = H5Aread(attr_id, mem_type_id, rdata); + if (status < 0) { + h5JNIFatalError(env, "H5AreadComplex: failed to read data"); + } /* end if */ + else { + HDmemset(&h5str, 0, sizeof(h5str_t)); + h5str_new(&h5str, 4 * size); + if (h5str.s == NULL) { + h5JNIFatalError(env, "H5AreadComplex: failed to allocate string buf"); + } /* end if */ + else { + for (i = 0; i < n; i++) { + h5str.s[0] = '\0'; + h5str_sprintf(&h5str, attr_id, mem_type_id, rdata + ((size_t)i * size), 0); + jstr = ENVPTR->NewStringUTF(ENVPAR h5str.s); + ENVPTR->SetObjectArrayElement(ENVPAR buf, i, jstr); + } /* end for */ + } /* end else */ + h5str_free(&h5str); + } /* end else */ + HDfree(rdata); + } /* end else */ + return status; +} + +/* * Copies the content of one dataset to another dataset * Class: hdf_hdf5lib_H5 * Method: H5Acopy @@ -2580,49 +2634,50 @@ Java_hdf_hdf5lib_H5_H5export_1dataset h5nullArgument(env, "HDF5Library_export_data: object_path is NULL"); } /* end else if */ else { - PIN_JAVA_STRING0(file_name, fileName); + PIN_JAVA_STRING(file_name, fileName); + if (fileName != NULL) { + file_id = H5Fopen(fileName, (unsigned)H5F_ACC_RDWR, (hid_t)H5P_DEFAULT); - file_id = H5Fopen(fileName, (unsigned)H5F_ACC_RDWR, (hid_t)H5P_DEFAULT); + UNPIN_JAVA_STRING(file_name, fileName); - UNPIN_JAVA_STRING(file_name, fileName); - - if (file_id < 0) { - /* throw exception */ - h5libraryError(env); - } /* end if */ - else { - object_name = ENVPTR->GetStringUTFChars(ENVPAR object_path, &isCopy2); - if (object_name == NULL) { - h5JNIFatalError( env, "H5Dopen: object name not pinned"); + if (file_id < 0) { + /* throw exception */ + h5libraryError(env); } /* end if */ else { - dataset_id = H5Dopen2(file_id, object_name, H5P_DEFAULT); - - ENVPTR->ReleaseStringUTFChars(ENVPAR object_path, object_name); - - if (dataset_id < 0) { - H5Fclose(file_id); - h5libraryError(env); + object_name = ENVPTR->GetStringUTFChars(ENVPAR object_path, &isCopy2); + if (object_name == NULL) { + h5JNIFatalError( env, "H5Dopen: object name not pinned"); } /* end if */ else { - file_export = ENVPTR->GetStringUTFChars(ENVPAR file_export_name, 0); - stream = HDfopen(file_export, "w+"); - ENVPTR->ReleaseStringUTFChars(ENVPAR file_export_name, file_export); + dataset_id = H5Dopen2(file_id, object_name, H5P_DEFAULT); - ret_val = h5str_dump_simple_dset(stream, dataset_id, binary_order); + ENVPTR->ReleaseStringUTFChars(ENVPAR object_path, object_name); - if (stream) - HDfclose(stream); + if (dataset_id < 0) { + H5Fclose(file_id); + h5libraryError(env); + } /* end if */ + else { + file_export = ENVPTR->GetStringUTFChars(ENVPAR file_export_name, 0); + stream = HDfopen(file_export, "w+"); + ENVPTR->ReleaseStringUTFChars(ENVPAR file_export_name, file_export); - H5Dclose(dataset_id); + ret_val = h5str_dump_simple_dset(stream, dataset_id, binary_order); - H5Fclose(file_id); + if (stream) + HDfclose(stream); - if (ret_val < 0) - h5libraryError(env); + H5Dclose(dataset_id); + + H5Fclose(file_id); + + if (ret_val < 0) + h5libraryError(env); + } /* end else */ } /* end else */ } /* end else */ - } /* end else */ + } } /* end else */ } /* end Java_hdf_hdf5lib_H5_H5export_1dataset */ diff --git a/java/src/jni/h5util.h b/java/src/jni/h5util.h index ab8da98..f690e8b 100644 --- a/java/src/jni/h5util.h +++ b/java/src/jni/h5util.h @@ -66,6 +66,15 @@ Java_hdf_hdf5lib_H5_H5AreadVL (JNIEnv *, jclass, jlong, jlong, jobjectArray); /* + * Class: hdf_hdf5lib_H5 + * Method: H5AreadComplex + * Signature: (JJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5AreadComplex + (JNIEnv *, jclass, jlong, jlong, jobjectArray); + +/* * Copies the content of one dataset to another dataset * Class: hdf_hdf5lib_H5 * Method: H5Acopy diff --git a/java/test/CMakeLists.txt b/java/test/CMakeLists.txt index 9038800..8cb41f7 100644 --- a/java/test/CMakeLists.txt +++ b/java/test/CMakeLists.txt @@ -68,22 +68,11 @@ set (HDF_JAVA_TEST_FILES ) foreach (h5_file ${HDF_JAVA_TEST_FILES}) - set (dest "${PROJECT_BINARY_DIR}/${h5_file}") - #message (STATUS " Copying ${h5_file}") - add_custom_command ( - TARGET ${HDF5_JAVA_TEST_LIB_TARGET} - POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy_if_different ${PROJECT_SOURCE_DIR}/${h5_file} ${dest} - ) + HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/${h5_file}" "${PROJECT_BINARY_DIR}/${h5_file}" "${HDF5_JAVA_TEST_LIB_TARGET}_files") endforeach (h5_file ${HDF_JAVA_TEST_FILES}) -add_custom_command ( - TARGET ${HDF5_JAVA_TEST_LIB_TARGET} - POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy_if_different ${PROJECT_SOURCE_DIR}/h5ex_g_iterate.orig ${PROJECT_BINARY_DIR}/h5ex_g_iterate.hdf -) +HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/h5ex_g_iterate.orig" "${PROJECT_BINARY_DIR}/h5ex_g_iterate.hdf" "${HDF5_JAVA_TEST_LIB_TARGET}_files") +add_custom_target(${HDF5_JAVA_TEST_LIB_TARGET}_files ALL COMMENT "Copying files needed by ${HDF5_JAVA_TEST_LIB_TARGET} tests" DEPENDS ${${HDF5_JAVA_TEST_LIB_TARGET}_files_list}) if (WIN32) set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";") @@ -99,7 +88,11 @@ set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP} set (testfilter "OK (598 tests)") if (CMAKE_BUILD_TYPE MATCHES Debug) - set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;") + if (WIN32) + set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_D;") + else() + set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;") + endif() endif(CMAKE_BUILD_TYPE MATCHES Debug) add_test ( @@ -128,4 +121,7 @@ add_test ( -D "TEST_REFERENCE=JUnit-interface.txt" -P "${HDF_RESOURCES_DIR}/jrunTest.cmake" ) -set_tests_properties (JUnit-interface PROPERTIES DEPENDS "JUnit-interface-clearall-objects") +set_tests_properties (JUnit-interface PROPERTIES + ENVIRONMENT "HDF5_PLUGIN_PATH=${CMAKE_BINARY_DIR}/testdir2" + DEPENDS "JUnit-interface-clearall-objects" +) diff --git a/java/test/TestH5PL.java b/java/test/TestH5PL.java index afcb88a..9f1876c 100644 --- a/java/test/TestH5PL.java +++ b/java/test/TestH5PL.java @@ -23,12 +23,22 @@ import hdf.hdf5lib.exceptions.HDF5LibraryException; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; public class TestH5PL { @Rule public TestName testname = new TestName(); + private static String FILENAME = "h5_dlopenChunk.h5"; + private static String DATASETNAME = "DS1"; + private static final int DIM_X = 6; + private static final int DIM_Y = 8; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 4; + private static final int RANK = 2; + private static final int NDIMS = 2; + private static final int H5Z_FILTER_DYNLIB4 = 260; @Before public void checkOpenIDs() { @@ -58,4 +68,117 @@ public class TestH5PL { fail("TestH5PLplugins " + err); } } + + @Ignore + public void TestH5PLdlopen() { + long file_id = -1; + long filespace_id = -1; + long dataset_id = -1; + long fapl_id = -1; + long dcpl_id = -1; + try { + int[] cd_values = {9, 0, 0, 0}; + int[] libversion = {0, 0, 0}; + long[] dims = { DIM_X, DIM_Y }; + long[] chunk_dims = { CHUNK_X, CHUNK_Y }; + int[][] dset_data = new int[DIM_X][DIM_Y]; + int[] mdc_nelmts = {0}; + long[] rdcc_nelmts = {0}; + long[] rdcc_nbytes = {0}; + double[] rdcc_w0 = {0}; + + // Initialize data to "1", to make it easier to see the selections. + for (int indx = 0; indx < DIM_X; indx++) + for (int jndx = 0; jndx < DIM_Y; jndx++) + dset_data[indx][jndx] = 1; + + // Create a new file using default properties. + try { + file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT); + } + catch (Exception e) { + e.printStackTrace(); + fail("TestH5PLdlopen H5Fcreate:" + e); + } + + // Create dataspace. Setting maximum size to NULL sets the maximum + // size to be the current size. + try { + filespace_id = H5.H5Screate_simple(RANK, dims, null); + } + catch (Exception e) { + e.printStackTrace(); + fail("TestH5PLdlopen H5Screate_simple:" + e); + } + + // Create the dataset creation property list. + try { + dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE); + } + catch (Exception e) { + e.printStackTrace(); + fail("TestH5PLdlopen H5Pcreate:" + e); + } + + // Set the chunk size. + try { + if (dcpl_id >= 0) + H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims); + } + catch (Exception e) { + e.printStackTrace(); + fail("TestH5PLdlopen H5Pset_chunk:" + e); + } + + try { + H5.H5get_libversion(libversion); + cd_values[1] = libversion[0]; + cd_values[2] = libversion[1]; + cd_values[3] = libversion[2]; + if (dcpl_id >= 0) + H5.H5Pset_filter(dcpl_id, H5Z_FILTER_DYNLIB4, HDF5Constants.H5Z_FLAG_MANDATORY, 4, cd_values); + } + catch (Exception e) { + e.printStackTrace(); + fail("TestH5PLdlopen H5Pset_filter:" + e); + } + + // Create the chunked dataset. + try { + if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) + dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_NATIVE_INT, filespace_id, + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + } + catch (Exception e) { + e.printStackTrace(); + fail("TestH5PLdlopen H5Dcreate:" + e); + } + + try { + if (dataset_id >= 0) + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, dset_data); + } + catch (Exception e) { + e.printStackTrace(); + fail("TestH5PLdlopen H5Dwrite:" + e); + } + } + catch (Throwable err) { + err.printStackTrace(); + fail("TestH5PLdlopen " + err); + } + finally { + // End access to the dataset and release resources used by it. + if (dcpl_id >= 0) + try {H5.H5Pclose_class(dcpl_id);} catch (Throwable err) {} + if (dataset_id >= 0) + try {H5.H5Dclose(dataset_id);} catch (Throwable err) {} + if (filespace_id >= 0) + try {H5.H5Sclose(filespace_id);} catch (Throwable err) {} + if (file_id >= 0) + try {H5.H5Fclose(file_id);} catch (Throwable err) {} + } + } } diff --git a/java/test/junit.sh.in b/java/test/junit.sh.in index f37703a..5001c32 100644 --- a/java/test/junit.sh.in +++ b/java/test/junit.sh.in @@ -111,7 +111,7 @@ CLEAN_LIBFILES_AND_BLDLIBDIR() # skip rm if srcdir is same as destdir # this occurs when build/test performed in source dir and # make cp fail - SDIR=`$DIRNAME $HDFLIB_HOME/junit.jar` + SDIR=$HDFLIB_HOME INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` INODE_DDIR=`$LS -i -d $BLDLIBDIR | $AWK -F' ' '{print $1}'` if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then |