summaryrefslogtreecommitdiffstats
path: root/java/src/jni/h5gImp.c
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/jni/h5gImp.c')
-rw-r--r--java/src/jni/h5gImp.c236
1 files changed, 148 insertions, 88 deletions
diff --git a/java/src/jni/h5gImp.c b/java/src/jni/h5gImp.c
index 42c042a..b579f31 100644
--- a/java/src/jni/h5gImp.c
+++ b/java/src/jni/h5gImp.c
@@ -29,7 +29,10 @@ extern "C" {
#include "h5util.h"
#include "h5gImp.h"
-extern JavaVM *jvm;
+/*
+ * Pointer to the JNI's Virtual Machine; used for callback functions.
+ */
+/* extern JavaVM *jvm; */
/*
* Class: hdf_hdf5lib_H5
@@ -40,12 +43,14 @@ JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5__1H5Gclose
(JNIEnv *env, jclass clss, jlong group_id)
{
- herr_t retVal = -1;
+ herr_t retVal = FAIL;
+
+ UNUSED(clss);
- retVal = H5Gclose((hid_t)group_id);
- if (retVal < 0)
- h5libraryError(env);
+ if ((retVal = H5Gclose((hid_t)group_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+done:
return (jint)retVal;
} /* end Java_hdf_hdf5lib_H5__1H5Gclose */
@@ -63,33 +68,46 @@ jobject
create_H5G_info_t
(JNIEnv *env, H5G_info_t group_info)
{
- jclass cls;
+ jfieldID fid_storage_type, fid_nlinks, fid_max_corder, fid_mounted;
jboolean jmounted;
+ jclass cls;
jint storage_type;
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) {
- 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);
- }
- }
- }
- }
- }
- }
+ if (NULL == (cls = ENVPTR->FindClass(ENVONLY, "hdf/hdf5lib/structs/H5G_info_t")))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ if (NULL == (obj = ENVPTR->AllocObject(ENVONLY, cls)))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ if (NULL == (fid_storage_type = ENVPTR->GetFieldID(ENVONLY, cls, "storage_type", "I")))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ if (NULL == (fid_nlinks = ENVPTR->GetFieldID(ENVONLY, cls, "nlinks", "J")))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ if (NULL == (fid_max_corder = ENVPTR->GetFieldID(ENVONLY, cls, "max_corder", "J")))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ if (NULL == (fid_mounted = ENVPTR->GetFieldID(ENVONLY, cls, "mounted", "Z")))
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ jmounted = (group_info.mounted == 0) ? JNI_FALSE : JNI_TRUE;
+ storage_type = (jint)group_info.storage_type;
+
+ ENVPTR->SetIntField(ENVONLY, obj, fid_storage_type, (jint)storage_type);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ ENVPTR->SetLongField(ENVONLY, obj, fid_nlinks, (jlong)group_info.nlinks);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ ENVPTR->SetLongField(ENVONLY, obj, fid_max_corder, (jlong)group_info.max_corder);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+ ENVPTR->SetBooleanField(ENVONLY, obj, fid_mounted, jmounted);
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
+
+done:
return obj;
} /* end create_H5G_info_t */
@@ -103,17 +121,22 @@ Java_hdf_hdf5lib_H5__1H5Gcreate2
(JNIEnv *env, jclass clss, jlong loc_id, jstring name,
jlong link_plist_id, jlong create_plist_id, jlong access_plist_id)
{
- hid_t group_id = -1;
- const char *gName;
+ const char *grpName = NULL;
+ hid_t group_id = H5I_INVALID_HID;
- 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 );
+ UNUSED(clss);
- UNPIN_JAVA_STRING(name, gName);
- if (group_id < 0)
- h5libraryError(env);
- }
+ if (NULL == name)
+ H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gcreate2: group name is NULL");
+
+ PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Gcreate2: group name not pinned");
+
+ if ((group_id = H5Gcreate2((hid_t)loc_id, grpName, (hid_t)link_plist_id, (hid_t)create_plist_id, (hid_t)access_plist_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+done:
+ if (grpName)
+ UNPIN_JAVA_STRING(ENVONLY, name, grpName);
return (jlong)group_id;
} /* end Java_hdf_hdf5lib_H5__1H5Gcreate2 */
@@ -127,12 +150,14 @@ JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Gcreate_1anon
(JNIEnv *env, jclass cls, jlong loc_id, jlong gcpl_id, jlong gapl_id)
{
- hid_t group_id = -1;
+ hid_t group_id = H5I_INVALID_HID;
+
+ UNUSED(cls);
- group_id = H5Gcreate_anon((hid_t)loc_id, (hid_t)gcpl_id, (hid_t)gapl_id);
- if (group_id < 0)
- h5libraryError(env);
+ if ((group_id = H5Gcreate_anon((hid_t)loc_id, (hid_t)gcpl_id, (hid_t)gapl_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+done:
return (jlong)group_id;
} /* end Java_hdf_hdf5lib_H5__1H5Gcreate_1anon */
@@ -145,18 +170,22 @@ JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5__1H5Gopen2
(JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_plist_id)
{
- hid_t group_id = -1;
- const char *gName;
+ const char *grpName = NULL;
+ hid_t group_id = H5I_INVALID_HID;
- PIN_JAVA_STRING(name, gName);
- if (gName != NULL) {
- group_id = H5Gopen2((hid_t)loc_id, gName, (hid_t)access_plist_id );
+ UNUSED(clss);
- UNPIN_JAVA_STRING(name, gName);
+ if (NULL == name)
+ H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gopen2: group name is NULL");
- if (group_id < 0)
- h5libraryError(env);
- }
+ PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Gopen2: group name not pinned");
+
+ if ((group_id = H5Gopen2((hid_t)loc_id, grpName, (hid_t)access_plist_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+done:
+ if (grpName)
+ UNPIN_JAVA_STRING(ENVONLY, name, grpName);
return (jlong)group_id;
} /* end Java_hdf_hdf5lib_H5__1H5Gopen2 */
@@ -171,11 +200,14 @@ JNIEXPORT jlong JNICALL
Java_hdf_hdf5lib_H5_H5Gget_1create_1plist
(JNIEnv *env, jclass cls, jlong loc_id)
{
- hid_t plist_id = H5Gget_create_plist((hid_t)loc_id);
+ hid_t plist_id = H5I_INVALID_HID;
- if (plist_id < 0)
- h5libraryError(env);
+ UNUSED(cls);
+ if ((plist_id = H5Gget_create_plist((hid_t)loc_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+done:
return (jlong)plist_id;
} /* end Java_hdf_hdf5lib_H5_H5Gget_1create_1plist */
@@ -188,14 +220,18 @@ JNIEXPORT jobject JNICALL
Java_hdf_hdf5lib_H5_H5Gget_1info
(JNIEnv *env, jclass cls, jlong loc_id)
{
- jobject obj = NULL;
H5G_info_t group_info;
+ jobject obj = NULL;
+
+ UNUSED(cls);
if (H5Gget_info((hid_t)loc_id, &group_info) < 0)
- h5libraryError(env);
- else
- obj = create_H5G_info_t(env, group_info);
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (NULL == (obj = create_H5G_info_t(env, group_info)))
+ H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_info: unable to create H5G_info_t object");
+done:
return obj;
} /* end Java_hdf_hdf5lib_H5_H5Gget_1info */
@@ -208,23 +244,30 @@ 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;
+ const char *grpName = NULL;
+ jobject obj = NULL;
+ herr_t ret_val = FAIL;
+
+ UNUSED(cls);
+
+ if (NULL == name)
+ H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_info_by_name: group name is 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);
+ PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Gget_info_by_name: group name not pinned");
- UNPIN_JAVA_STRING(name, gName);
+ if ((ret_val = H5Gget_info_by_name((hid_t)loc_id, grpName, &group_info, (hid_t)lapl_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
- if (ret_val < 0)
- h5libraryError(env);
- else
- obj = create_H5G_info_t(env, group_info);
+ if (NULL == (obj = create_H5G_info_t(env, group_info))) {
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_info_by_name: unable to create H5G_info_t object");
}
+done:
+ if (grpName)
+ UNPIN_JAVA_STRING(ENVONLY, name, grpName);
+
return obj;
} /* end Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1name */
@@ -238,26 +281,33 @@ 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);
- 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);
-
- if (ret_val < 0)
- h5libraryError(env);
- else
- obj = create_H5G_info_t(env, group_info);
+ H5_iter_order_t corder = (H5_iter_order_t)order;
+ H5_index_t cindex_type = (H5_index_t)index_type;
+ H5G_info_t group_info;
+ const char *grpName = NULL;
+ jobject obj = NULL;
+ herr_t ret_val = FAIL;
+
+ UNUSED(cls);
+
+ if (NULL == name)
+ H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_info_by_idx: group name is NULL");
+
+ PIN_JAVA_STRING(ENVONLY, name, grpName, NULL, "H5Gget_info_by_idx: group name not pinned");
+
+ if ((ret_val = H5Gget_info_by_idx((hid_t)loc_id, grpName, cindex_type,
+ corder, (hsize_t)n, &group_info, (hid_t)lapl_id)) < 0)
+ H5_LIBRARY_ERROR(ENVONLY);
+
+ if (NULL == (obj = create_H5G_info_t(env, group_info))) {
+ CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE);
+ H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_info_by_idx: unable to create H5G_info_t object");
}
+done:
+ if (grpName)
+ UNPIN_JAVA_STRING(ENVONLY, name, grpName);
+
return obj;
} /* end Java_hdf_hdf5lib_H5_H5Gget_1info_1by_1idx */
@@ -270,8 +320,13 @@ JNIEXPORT void JNICALL
Java_hdf_hdf5lib_H5_H5Gflush
(JNIEnv *env, jclass clss, jlong loc_id)
{
+ UNUSED(clss);
+
if (H5Gflush((hid_t)loc_id) < 0)
- h5libraryError(env);
+ H5_LIBRARY_ERROR(ENVONLY);
+
+done:
+ return;
} /* end Java_hdf_hdf5lib_H5_H5Gflush */
/*
@@ -283,8 +338,13 @@ JNIEXPORT void JNICALL
Java_hdf_hdf5lib_H5_H5Grefresh
(JNIEnv *env, jclass clss, jlong loc_id)
{
+ UNUSED(clss);
+
if (H5Grefresh((hid_t)loc_id) < 0)
- h5libraryError(env);
+ H5_LIBRARY_ERROR(ENVONLY);
+
+done:
+ return;
} /* end Java_hdf_hdf5lib_H5_H5Grefresh */