diff options
Diffstat (limited to 'java/src/jni/h5oImp.c')
-rw-r--r-- | java/src/jni/h5oImp.c | 674 |
1 files changed, 322 insertions, 352 deletions
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); |