diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2018-06-29 14:57:47 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2018-06-29 14:57:47 (GMT) |
commit | c0dfec8913497d62cf1ab7e13e62e3fe55d6e859 (patch) | |
tree | 22033ce7d1d7d6949671d37102ddb4cfd1e14b3a /java/src/jni | |
parent | 2e0b95819636bb743dd1ac63e53e6c9fab9a107a (diff) | |
download | hdf5-c0dfec8913497d62cf1ab7e13e62e3fe55d6e859.zip hdf5-c0dfec8913497d62cf1ab7e13e62e3fe55d6e859.tar.gz hdf5-c0dfec8913497d62cf1ab7e13e62e3fe55d6e859.tar.bz2 |
HDFFV-10519 Disable WriteVL JNI function, updgrade JNI
Diffstat (limited to 'java/src/jni')
-rw-r--r-- | java/src/jni/h5dImp.c | 111 | ||||
-rw-r--r-- | java/src/jni/h5dImp.h | 9 | ||||
-rw-r--r-- | java/src/jni/h5util.c | 413 | ||||
-rw-r--r-- | java/src/jni/h5util.h | 2 |
4 files changed, 531 insertions, 4 deletions
diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c index 1d7b823..42bfa1e 100644 --- a/java/src/jni/h5dImp.c +++ b/java/src/jni/h5dImp.c @@ -56,6 +56,7 @@ extern jobject visit_callback; static herr_t H5DreadVL_asstr (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); static herr_t H5DreadVL_str (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); static herr_t H5DreadVL_array (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); +static herr_t H5DwriteVL_asstr (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); static herr_t H5DwriteVL_str (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); static herr_t H5DwriteVL_array (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf); @@ -1194,7 +1195,7 @@ H5DreadVL_asstr /* we will need to read n number of hvl_t structures */ rdata = (hvl_t*)HDcalloc((size_t)n, sizeof(hvl_t)); if (rdata == NULL) { - h5JNIFatalError(env, "H5DreadVL_notstr: failed to allocate buff for read"); + h5JNIFatalError(env, "H5DreadVL_asstr: failed to allocate buff for read"); } /* end if */ else { status = H5Dread(did, tid, mem_sid, file_sid, xfer_plist_id, rdata); @@ -1202,7 +1203,7 @@ H5DreadVL_asstr if (status < 0) { H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, rdata); HDfree(rdata); - h5JNIFatalError(env, "H5DreadVL_notstr: failed to read data"); + h5JNIFatalError(env, "H5DreadVL_asstr: failed to read data"); } /* end if */ else { /* calculate the largest size of all the hvl_t structures read */ @@ -1220,7 +1221,7 @@ H5DreadVL_asstr if (h5str.s == NULL) { H5Dvlen_reclaim(tid, mem_sid, xfer_plist_id, rdata); HDfree(rdata); - h5JNIFatalError(env, "H5DreadVL_notstr: failed to allocate buf"); + h5JNIFatalError(env, "H5DreadVL_asstr: failed to allocate buf"); } /* end if */ else { H5T_class_t tclass = H5Tget_class(tid); @@ -1329,6 +1330,108 @@ H5DreadVL_str /* * Class: hdf_hdf5lib_H5 + * Method: H5DwriteVL + * Signature: (JJJJJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5DwriteVL + (JNIEnv *env, jclass clss, jlong dataset_id, jlong mem_type_id, jlong mem_space_id, + jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) +{ + herr_t status = -1; + htri_t isStr = 0; + htri_t isVlenStr = 0; + htri_t isComplex = 0; + + h5unimplemented(env, "H5DwriteVL: not implemented"); + return -1; +#ifdef notdef + if (buf == NULL) { + h5nullArgument(env, "H5DwriteVL: buf is NULL"); + } /* end if */ + else { + isStr = H5Tdetect_class((hid_t)mem_type_id, H5T_STRING); + if (H5Tget_class((hid_t)mem_type_id) == H5T_COMPOUND) { + unsigned i; + int nm = H5Tget_nmembers(mem_type_id); + for(i = 0; i <nm; i++) { + hid_t nested_tid = H5Tget_member_type((hid_t)mem_type_id, i); + isComplex = H5Tdetect_class((hid_t)nested_tid, H5T_COMPOUND) || + H5Tdetect_class((hid_t)nested_tid, H5T_VLEN); + H5Tclose(nested_tid); + } + } + else if (H5Tget_class((hid_t)mem_type_id) == H5T_VLEN) { + isVlenStr = 1; /* strings created by H5Tvlen_create(H5T_C_S1) */ + } + if (isStr == 0 || isComplex>0 || isVlenStr) { + status = H5DwriteVL_asstr(env, (hid_t)dataset_id, (hid_t)mem_type_id, + (hid_t)mem_space_id, (hid_t)file_space_id, + (hid_t)xfer_plist_id, buf); + } + else if (isStr > 0) { + status = H5DwriteVL_str(env, (hid_t)dataset_id, (hid_t)mem_type_id, + (hid_t)mem_space_id, (hid_t)file_space_id, + (hid_t)xfer_plist_id, buf); + } + } /* end else */ + + return (jint)status; +#endif +} /* end Java_hdf_hdf5lib_H5_H5Dwrite_1VL */ + +herr_t +H5DwriteVL_asstr + (JNIEnv *env, hid_t did, hid_t tid, hid_t mem_sid, hid_t file_sid, hid_t xfer_plist_id, jobjectArray buf) +{ + herr_t status = -1; + hvl_t *wdata; + jsize size; + jint i; + jint n; + + /* Get size of string array */ + n = ENVPTR->GetArrayLength(ENVPAR buf); + wdata = (hvl_t*)HDcalloc((size_t)n, sizeof(hvl_t)); + + if (wdata == NULL) { + h5JNIFatalError(env, "H5DwriteVL_asstr: failed to allocate buff for write"); + } /* end if */ + else { + for (i = 0; i < n; ++i) { + jstring obj = (jstring) ENVPTR->GetObjectArrayElement(ENVPAR (jobjectArray)buf, i); + if (obj != 0) { + jsize length = ENVPTR->GetStringUTFLength(ENVPAR obj); + const char *utf8 = ENVPTR->GetStringUTFChars(ENVPAR obj, 0); + + if (utf8) { + h5str_vlconvert(utf8, did, tid, wdata+i, 0); + } /* end if */ + + ENVPTR->ReleaseStringUTFChars(ENVPAR obj, utf8); + ENVPTR->DeleteLocalRef(ENVPAR obj); + } /* end if */ + } /* end for (i = 0; i < size; ++i) */ + + status = H5Dwrite(did, tid, mem_sid, file_sid, xfer_plist_id, wdata); + + /* now free memory*/ + for (i = 0; i < n; i++) { + if(wdata+i) { + HDfree(wdata+i); + } /* end if */ + } /* end for */ + HDfree(wdata); + + if (status < 0) + h5libraryError(env); + } /* end else */ + + return status; +} /* end H5DwriteVL_asstr */ + +/* + * Class: hdf_hdf5lib_H5 * Method: H5Dwrite_VLStrings * Signature: (JJJJJ[Ljava/lang/String;)I */ @@ -1371,7 +1474,7 @@ H5DwriteVL_str wdata = (char**)HDmalloc((size_t)size * sizeof (char*)); if (!wdata) { - h5JNIFatalError(env, "H5DwriteVL_string: cannot allocate buffer"); + h5JNIFatalError(env, "H5DwriteVL_str: cannot allocate buffer"); } /* end if */ else { HDmemset(wdata, 0, (size_t)size * sizeof(char*)); diff --git a/java/src/jni/h5dImp.h b/java/src/jni/h5dImp.h index 3cf24fe..1fe71a8 100644 --- a/java/src/jni/h5dImp.h +++ b/java/src/jni/h5dImp.h @@ -213,6 +213,15 @@ Java_hdf_hdf5lib_H5_H5DreadVL /* * Class: hdf_hdf5lib_H5 + * Method: H5DwriteVL + * Signature: (JJJJJ[Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL +Java_hdf_hdf5lib_H5_H5DwriteVL +(JNIEnv*, jclass, jlong, jlong, jlong, jlong, jlong, jobjectArray); + +/* + * Class: hdf_hdf5lib_H5 * Method: H5Dread_string * Signature: (JJJJJ[Ljava/lang/String;)I */ diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c index 385bfc7..33dca7f 100644 --- a/java/src/jni/h5util.c +++ b/java/src/jni/h5util.c @@ -159,6 +159,419 @@ h5str_append On error, a negative number is returned. */ size_t +h5str_vlconvert + (char *str, hid_t container, hid_t tid, hvl_t *ptr, int expand_data) +{ + unsigned char tmp_uchar = 0; + char tmp_char = 0; + unsigned short tmp_ushort = 0; + short tmp_short = 0; + unsigned int tmp_uint = 0; + int tmp_int = 0; + unsigned long tmp_ulong = 0; + long tmp_long = 0; + unsigned long long tmp_ullong = 0; + long long tmp_llong = 0; + float tmp_float = 0.0; + double tmp_double = 0.0; + long double tmp_ldouble = 0.0; + static char fmt_llong[8], fmt_ullong[8]; + + hid_t mtid = -1; + size_t offset; + size_t nll; + char *this_str; + size_t this_strlen; + int n; + H5T_class_t tclass = H5Tget_class(tid); + size_t size = H5Tget_size(tid); + H5T_sign_t nsign = H5Tget_sign(tid); + int bdata_print = 0; + + if (!str || !ptr) + return 0; + + this_str = NULL; + this_strlen = 0; + + switch (tclass) { + case H5T_COMPOUND: + { + unsigned i; + n = H5Tget_nmembers(tid); + + /* remove compound indicators */ + if (str[0] == ' ') + str++; + if (str[0] == '{') + str++; + + ptr->p = HDcalloc((size_t)1, size); + ptr->len = size; + for (i = 0; i < n; i++) { + offset = H5Tget_member_offset(tid, i); + mtid = H5Tget_member_type(tid, i); + str += offset; + h5str_convert(&str, container, mtid, ptr, 0, expand_data); + /* remove compound indicators */ + if (str[0] == ',') + str++; + if (str[0] == ' ') + str++; + H5Tclose(mtid); + } + /* remove compound indicators */ + if (str[0] == '}') + str++; + if (str[0] == ' ') + str++; + } + break; + case H5T_ARRAY: + { + int rank = 0; + hsize_t i, dims[H5S_MAX_RANK], total_elmts; + + /* remove array indicators */ + if (str[0] == '[') + str++; + if (str[0] == ' ') + str++; + + mtid = H5Tget_super(tid); + size = H5Tget_size(mtid); + rank = H5Tget_array_ndims(tid); + + H5Tget_array_dims2(tid, dims); + + total_elmts = 1; + for (i = 0; i < rank; i++) + total_elmts *= dims[i]; + + ptr->p = HDcalloc((size_t)total_elmts, size); + ptr->len = total_elmts; + h5str_convert(&str, container, mtid, ptr, 0, expand_data); + H5Tclose(mtid); + /* remove array indicators */ + if (str[0] == ' ') + str++; + if (str[0] == ']') + str++; + if (str[0] == ' ') + str++; + } + break; + default: + ptr->len = size; + ptr->p = HDcalloc(1, size); + this_strlen = h5str_convert(&str, container, tid, ptr, 0, expand_data); + break; + } /* end switch */ + + return this_strlen; +} /* end h5str_vlconvert */ + +/** print value of a data point into string. + Return Value: + On success, the total number of characters printed is returned. + On error, a negative number is returned. + */ +size_t +h5str_convert + (char **str, hid_t container, hid_t tid, hvl_t *ptr, int ptroffset, int expand_data) +{ + unsigned char tmp_uchar = 0; + char tmp_char = 0; + unsigned short tmp_ushort = 0; + short tmp_short = 0; + unsigned int tmp_uint = 0; + int tmp_int = 0; + unsigned long tmp_ulong = 0; + long tmp_long = 0; + unsigned long long tmp_ullong = 0; + long long tmp_llong = 0; + float tmp_float = 0.0; + double tmp_double = 0.0; + long double tmp_ldouble = 0.0; + static char fmt_llong[8], fmt_ullong[8]; + const char delimiter[] = " ,}]"; + + char *token; + hid_t mtid = -1; + size_t offset; + size_t nll; + char *this_str = *str; + size_t this_strlen; + int n; + char *cptr = ((char*) ((hvl_t *) ptr)->p) + ptroffset; + unsigned char *ucptr = ((unsigned char*) ((hvl_t *) ptr)->p) + ptroffset; + H5T_class_t tclass = H5Tget_class(tid); + size_t size = H5Tget_size(tid); + H5T_sign_t nsign = H5Tget_sign(tid); + int bdata_print = 0; + + if (!str || !ptr) + return 0; + + /* Build default formats for long long types */ + if (!fmt_llong[0]) { + sprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH); + sprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH); + } /* end if */ + + this_strlen = HDstrlen(this_str); + + switch (tclass) { + case H5T_FLOAT: + token = HDstrtok (this_str, delimiter); + if (sizeof(float) == size) { + /* if (H5Tequal(tid, H5T_NATIVE_FLOAT)) */ + tmp_float = 0; + sscanf(token, "%f", &tmp_float); + HDmemcpy(cptr, &tmp_float, sizeof(float)); + } + else if (sizeof(double) == size) { + /* if (H5Tequal(tid, H5T_NATIVE_DOUBLE)) */ + tmp_double = 0; + sscanf(token, "%%lf", &tmp_double); + HDmemcpy(cptr, &tmp_double, sizeof(double)); + } +#if H5_SIZEOF_LONG_DOUBLE !=0 + else if (sizeof(long double) == size) { + /* if (H5Tequal(tid, H5T_NATIVE_LDOUBLE)) */ + tmp_ldouble = 0; + sscanf(token, "%Lf", &tmp_ldouble); + HDmemcpy(cptr, &tmp_ldouble, sizeof(long double)); + } +#endif + break; + case H5T_STRING: + { + if (this_strlen > 0) { + HDstrncpy(cptr, this_str, size); + } + else { + cptr = NULL; + } + } + break; + case H5T_INTEGER: + token = HDstrtok (this_str, delimiter); + if (sizeof(char) == size) { + if(H5T_SGN_NONE == nsign) { + /* if (H5Tequal(tid, H5T_NATIVE_UCHAR)) */ + tmp_uchar = 0; + sscanf(token, "%hu", &tmp_uchar); + HDmemcpy(cptr, &tmp_uchar, sizeof(unsigned char)); + } + else { + /* if (H5Tequal(tid, H5T_NATIVE_SCHAR)) */ + tmp_char = 0; + sscanf(token, "%hd", &tmp_char); + HDmemcpy(cptr, &tmp_char, sizeof(char)); + } + } + else if (sizeof(int) == size) { + if(H5T_SGN_NONE == nsign) { + /* if (H5Tequal(tid, H5T_NATIVE_UINT)) */ + tmp_uint = 0; + sscanf(token, "%u", &tmp_uint); + HDmemcpy(cptr, &tmp_uint, sizeof(unsigned int)); + } + else { + /* if (H5Tequal(tid, H5T_NATIVE_INT)) */ + tmp_int = 0; + sscanf(token, "%d", &tmp_int); + HDmemcpy(cptr, &tmp_int, sizeof(int)); + } + } + else if (sizeof(short) == size) { + if(H5T_SGN_NONE == nsign) { + /* if (H5Tequal(tid, H5T_NATIVE_USHORT)) */ + tmp_ushort = 0; + sscanf(token, "%u", &tmp_ushort); + HDmemcpy(&tmp_ushort, cptr, sizeof(unsigned short)); + } + else { + /* if (H5Tequal(tid, H5T_NATIVE_SHORT)) */ + tmp_short = 0; + sscanf(token, "%d", &tmp_short); + HDmemcpy(&tmp_short, cptr, sizeof(short)); + } + } + else if (sizeof(long) == size) { + if(H5T_SGN_NONE == nsign) { + /* if (H5Tequal(tid, H5T_NATIVE_ULONG)) */ + tmp_ulong = 0; + sscanf(token, "%lu", &tmp_ulong); + HDmemcpy(cptr, &tmp_ulong, sizeof(unsigned long)); + } + else { + /* if (H5Tequal(tid, H5T_NATIVE_LONG)) */ + tmp_long = 0; + sscanf(token, "%ld", &tmp_long); + HDmemcpy(cptr, &tmp_long, sizeof(long)); + } + } + else if (sizeof(long long) == size) { + if(H5T_SGN_NONE == nsign) { + /* if (H5Tequal(tid, H5T_NATIVE_ULLONG)) */ + tmp_ullong = 0; + sscanf(token, fmt_ullong, &tmp_ullong); + HDmemcpy(cptr, &tmp_ullong, sizeof(unsigned long long)); + } + else { + /* if (H5Tequal(tid, H5T_NATIVE_LLONG)) */ + tmp_llong = 0; + sscanf(token, fmt_llong, &tmp_llong); + HDmemcpy(cptr, &tmp_llong, sizeof(long long)); + } + } + break; + case H5T_COMPOUND: + { + unsigned i; + n = H5Tget_nmembers(tid); + /* remove compound indicators */ + if ((*str)[0] == ' ') + (*str)++; + if ((*str)[0] == '{') + (*str)++; + + for (i = 0; i < n; i++) { + offset = H5Tget_member_offset(tid, i); + mtid = H5Tget_member_type(tid, i); + h5str_convert(str, container, mtid, ptr, offset, expand_data); + /* remove compound indicators */ + if ((*str)[0] == ',') + (*str)++; + if ((*str)[0] == ' ') + (*str)++; + H5Tclose(mtid); + } + /* remove compound indicators */ + if ((*str)[0] == '}') + (*str)++; + if ((*str)[0] == ' ') + (*str)++; + } + break; + case H5T_ENUM: + { + char enum_name[1024]; + void *value; + if (sizeof(char) == size) { + tmp_uchar = 0; + value = &tmp_uchar; + } + else if (sizeof(short) == size) { + tmp_ushort = 0; + value = &tmp_ushort; + } + else if (sizeof(long) == size) { + tmp_ulong = 0; + value = &tmp_ulong; + } + else if (sizeof(long long) == size) { + tmp_ullong = 0; + value = &tmp_ullong; + } + else { + tmp_uint = 0; + value = &tmp_uint; + } + token = HDstrtok (this_str, delimiter); + H5Tenum_valueof(tid, token, value); + HDmemcpy(ucptr, value, size); + } + break; + case H5T_REFERENCE: + /* TODO handle reference writing */ + cptr = NULL; + break; + case H5T_ARRAY: + { + int rank = 0; + hsize_t i, dims[H5S_MAX_RANK], total_elmts; + /* remove array indicators */ + if ((*str)[0] == '[') + (*str)++; + if ((*str)[0] == ' ') + (*str)++; + + mtid = H5Tget_super(tid); + offset = H5Tget_size(mtid); + rank = H5Tget_array_ndims(tid); + + H5Tget_array_dims2(tid, dims); + + total_elmts = 1; + for (i = 0; i < rank; i++) + total_elmts *= dims[i]; + + cptr = HDcalloc((size_t)total_elmts, offset); + for (i = 0; i < total_elmts; i++) { + h5str_convert(str, container, mtid, cptr + (i*offset), offset, expand_data); + /* remove array indicators */ + if ((*str)[0] == ',') + (*str)++; + if ((*str)[0] == ' ') + (*str)++; + } + H5Tclose(mtid); + /* remove array indicators */ + if ((*str)[0] == ' ') + (*str)++; + if ((*str)[0] == ']') + (*str)++; + if ((*str)[0] == ' ') + (*str)++; + } + break; + case H5T_VLEN: + { + unsigned int i; + mtid = H5Tget_super(tid); + offset = H5Tget_size(mtid); + + /* remove vlen indicators */ + if ((*str)[0] == '{') + (*str)++; + cptr = HDcalloc(offset, sizeof(hvl_t)); + for (i = 0; (i*offset) < (int)size; i++) { + h5str_convert(str, container, mtid, cptr + (i*offset), offset, expand_data); + /* remove vlen indicators */ + if ((*str)[0] == ',') + (*str)++; + if ((*str)[0] == ' ') + (*str)++; + if ((*str)[0] == '}') + break; + } + H5Tclose(mtid); + /* remove vlen indicators */ + if ((*str)[0] == '}') + (*str)++; + } + break; + + default: + { + /* All other types get copied raw */ + HDmemcpy(ucptr, this_str, size); + } + break; + } /* end switch */ + + return this_strlen; +} /* end h5str_convert */ + +/** print value of a vlen data point into string. + Return Value: + On success, the total number of characters printed is returned. + On error, a negative number is returned. + */ +size_t h5str_vlsprintf (h5str_t *str, hid_t container, hid_t tid, hvl_t *ptr, int expand_data) { diff --git a/java/src/jni/h5util.h b/java/src/jni/h5util.h index c6b41d2..23bc424 100644 --- a/java/src/jni/h5util.h +++ b/java/src/jni/h5util.h @@ -41,6 +41,8 @@ extern void h5str_resize (h5str_t *str, size_t new_len); extern char* h5str_append (h5str_t *str, const char* cstr); extern size_t h5str_vlsprintf(h5str_t *str, hid_t container, hid_t tid, hvl_t *buf, int expand_data); extern size_t h5str_sprintf(h5str_t *str, hid_t container, hid_t tid, void *buf, int ptrlen, int expand_data); +extern size_t h5str_vlsconvert(char *str, hid_t container, hid_t tid, hvl_t *buf, int expand_data); +extern size_t h5str_convert(char **str, hid_t container, hid_t tid, hvl_t *buf, int ptroffset, int expand_data); extern void h5str_array_free(char **strs, size_t len); extern int h5str_dump_simple_dset(FILE *stream, hid_t dset, int binary_order); extern int h5str_dump_region_blocks_data(h5str_t *str, hid_t region, hid_t region_obj); |