From cf61098fa66bfba8a44738f7cc8843d667064596 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Fri, 6 Dec 2019 12:57:38 -0600 Subject: Fix compile errors - mostly in jni --- java/src/jni/h5aImp.c | 6 ++-- java/src/jni/h5dImp.c | 6 ++-- java/src/jni/h5util.c | 93 +++++++++++++++++++++++++++++++++++-------------- src/H5private.h | 38 +++++++++----------- tools/lib/h5tools.h | 4 +-- tools/lib/h5tools_str.c | 41 +++++++++++----------- 6 files changed, 113 insertions(+), 75 deletions(-) diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c index 9f22665..099c88d 100644 --- a/java/src/jni/h5aImp.c +++ b/java/src/jni/h5aImp.c @@ -1390,7 +1390,7 @@ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) { - hdset_reg_ref_t *ref_data = NULL; + H5R_ref_t *ref_data = NULL; h5str_t h5str; jstring jstr; jsize i, n; @@ -1405,7 +1405,7 @@ Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread_reg_ref: buf length < 0"); } - if (NULL == (ref_data = (hdset_reg_ref_t *) HDcalloc(1, (size_t)n * sizeof(hdset_reg_ref_t)))) + if (NULL == (ref_data = (H5R_ref_t *) HDcalloc(1, (size_t)n * sizeof(H5R_ref_t)))) H5_JNI_FATAL_ERROR(ENVONLY, "H5Aread_reg_ref: failed to allocate read buffer"); if ((status = H5Aread((hid_t)attr_id, (hid_t)mem_type_id, ref_data)) < 0) @@ -1419,7 +1419,7 @@ Java_hdf_hdf5lib_H5_H5Aread_1reg_1ref for (i = 0; i < n; i++) { h5str.s[0] = '\0'; - if (!h5str_sprintf(ENVONLY, &h5str, (hid_t)attr_id, (hid_t)mem_type_id, ref_data[i], 0, 0)) + if (!h5str_sprintf(ENVONLY, &h5str, (hid_t)attr_id, (hid_t)mem_type_id, (void*)&ref_data[i], 0, 0)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, h5str.s))) diff --git a/java/src/jni/h5dImp.c b/java/src/jni/h5dImp.c index b395189..a305eef 100644 --- a/java/src/jni/h5dImp.c +++ b/java/src/jni/h5dImp.c @@ -1630,7 +1630,7 @@ Java_hdf_hdf5lib_H5_H5Dread_1reg_1ref jlong dataset_id, jlong mem_type_id, jlong mem_space_id, jlong file_space_id, jlong xfer_plist_id, jobjectArray buf) { - hdset_reg_ref_t *ref_data = NULL; + H5R_ref_t *ref_data = NULL; h5str_t h5str; jstring jstr; jsize i, n; @@ -1645,7 +1645,7 @@ Java_hdf_hdf5lib_H5_H5Dread_1reg_1ref H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Dread_reg_ref: buf length < 0"); } - if (NULL == (ref_data = (hdset_reg_ref_t *) HDcalloc(1, (size_t)n * sizeof(hdset_reg_ref_t)))) + if (NULL == (ref_data = (H5R_ref_t *) HDcalloc(1, (size_t)n * sizeof(H5R_ref_t)))) H5_JNI_FATAL_ERROR(ENVONLY, "H5Dread_reg_ref: failed to allocate read buffer"); if ((status = H5Dread((hid_t)dataset_id, (hid_t)mem_type_id, (hid_t)mem_space_id, (hid_t)file_space_id, xfer_plist_id, ref_data)) < 0) @@ -1659,7 +1659,7 @@ Java_hdf_hdf5lib_H5_H5Dread_1reg_1ref for (i = 0; i < n; i++) { h5str.s[0] = '\0'; - if (!h5str_sprintf(ENVONLY, &h5str, (hid_t)dataset_id, (hid_t)mem_type_id, &ref_data[i], 0, 0)) + if (!h5str_sprintf(ENVONLY, &h5str, (hid_t)dataset_id, (hid_t)mem_type_id, (void*)&ref_data[i], 0, 0)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, h5str.s))) diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c index cd54f8b..367f5e0 100644 --- a/java/src/jni/h5util.c +++ b/java/src/jni/h5util.c @@ -642,21 +642,22 @@ done: void h5str_sprint_reference(JNIEnv *env, h5str_t *out_str, hid_t container, void *ref_p) { - ssize_t buf_size, status; + ssize_t buf_size; char *ref_name = NULL; const H5R_ref_t *ref_vp = (H5R_ref_t *)ref_p; UNUSED(container); - if (!h5str_append(out_str, " ")) + if (!h5str_append(out_str, " \"")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); buf_size = H5Rget_file_name(ref_vp, NULL, 0); if (buf_size) { ref_name = (char *)HDmalloc(sizeof(char) * (size_t)buf_size + 1); - status = H5Rget_file_name(ref_vp, ref_name, buf_size + 1); - ref_name[buf_size] = '\0'; - if (!h5str_append(out_str, ref_name)) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + if (H5Rget_file_name(ref_vp, ref_name, buf_size + 1) >= 0) { + ref_name[buf_size] = '\0'; + if (!h5str_append(out_str, ref_name)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } HDfree(ref_name); ref_name = NULL; } @@ -664,10 +665,11 @@ h5str_sprint_reference(JNIEnv *env, h5str_t *out_str, hid_t container, void *ref buf_size = H5Rget_obj_name(ref_vp, H5P_DEFAULT, NULL, 0); if (buf_size) { ref_name = (char *)HDmalloc(sizeof(char) * (size_t)buf_size + 1); - status = H5Rget_obj_name(ref_vp, H5P_DEFAULT, ref_name, buf_size + 1); - ref_name[buf_size] = '\0'; - if (!h5str_append(out_str, ref_name)) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + if (H5Rget_obj_name(ref_vp, H5P_DEFAULT, ref_name, buf_size + 1) >= 0) { + ref_name[buf_size] = '\0'; + if (!h5str_append(out_str, ref_name)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } HDfree(ref_name); ref_name = NULL; } @@ -676,14 +678,17 @@ h5str_sprint_reference(JNIEnv *env, h5str_t *out_str, hid_t container, void *ref buf_size = H5Rget_attr_name(ref_vp, NULL, 0); if (buf_size) { ref_name = (char *)HDmalloc(sizeof(char) * (size_t)buf_size + 1); - status = H5Rget_attr_name(ref_vp, ref_name, buf_size + 1); - ref_name[buf_size] = '\0'; - if (!h5str_append(out_str, ref_name)) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + if (H5Rget_attr_name(ref_vp, ref_name, buf_size + 1) >= 0) { + ref_name[buf_size] = '\0'; + if (!h5str_append(out_str, ref_name)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } HDfree(ref_name); ref_name = NULL; } } + if (!h5str_append(out_str, "\"")) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); done: if (ref_name) HDfree(ref_name); @@ -703,8 +708,11 @@ h5str_sprintf unsigned char *ucptr = (unsigned char *) in_buf; static char fmt_llong[8], fmt_ullong[8]; H5T_class_t tclass = H5T_NO_CLASS; + H5T_str_t pad; size_t typeSize = 0; + H5T_sign_t nsign = H5T_SGN_ERROR; hid_t mtid = H5I_INVALID_HID; + hid_t obj = H5I_INVALID_HID; char *cptr = (char *) in_buf; char *this_str = NULL; int n; @@ -719,12 +727,14 @@ h5str_sprintf H5_LIBRARY_ERROR(ENVONLY); if (!(typeSize = H5Tget_size(tid))) H5_LIBRARY_ERROR(ENVONLY); + if (!(nsign = H5Tget_sign(tid))) + H5_LIBRARY_ERROR(ENVONLY); /* Build default formats for long long types */ if (!fmt_llong[0]) { - if (HDsprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH) < 0) + if (HDsnprintf(fmt_llong, sizeof(fmt_llong), "%%%sd", H5_PRINTF_LL_WIDTH) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: sprintf failure"); - if (HDsprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH) < 0) + if (HDsnprintf(fmt_ullong, sizeof(fmt_ullong), "%%%su", H5_PRINTF_LL_WIDTH) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: sprintf failure"); } /* end if */ @@ -788,27 +798,28 @@ h5str_sprintf case H5T_STRING: { - htri_t is_variable; - char *tmp_str; - - typeSize = 0; + htri_t is_variable; + char *tmp_str; if ((is_variable = H5Tis_variable_str(tid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (is_variable) { - if (NULL != (tmp_str = *(char **) in_buf)) + /* cp_vp is the pointer into the struct where a `char*' is stored. So we have + * to dereference the pointer to get the `char*' to pass to HDstrlen(). */ + tmp_str = *(char **)in_buf; + if (NULL != tmp_str) typeSize = HDstrlen(tmp_str); } else { tmp_str = cptr; } + pad = H5Tget_strpad(tid); /* Check for NULL pointer for string */ if (!tmp_str) { if (NULL == (this_str = (char *) HDmalloc(5))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - HDstrncpy(this_str, "NULL", 5); } else { @@ -826,7 +837,6 @@ h5str_sprintf case H5T_INTEGER: { - H5T_sign_t nsign = H5T_SGN_ERROR; if (H5T_SGN_ERROR == (nsign = H5Tget_sign(tid))) H5_LIBRARY_ERROR(ENVONLY); @@ -843,7 +853,7 @@ h5str_sprintf if (NULL == (this_str = (char *) HDmalloc(7))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%u", tmp_uchar) < 0) + if (HDsprintf(this_str, "%hhu", tmp_uchar) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } else { @@ -870,7 +880,7 @@ h5str_sprintf if (NULL == (this_str = (char *) HDmalloc(9))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%u", tmp_ushort) < 0) + if (HDsprintf(this_str, "%hu", tmp_ushort) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } else { @@ -879,7 +889,7 @@ h5str_sprintf if (NULL == (this_str = (char *) HDmalloc(9))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - if (HDsprintf(this_str, "%d", tmp_short) < 0) + if (HDsprintf(this_str, "%hd", tmp_short) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } @@ -1057,6 +1067,27 @@ h5str_sprintf H5Rget_obj_type3(ref_vp, H5P_DEFAULT, &obj_type); switch (ref_type) { case H5R_OBJECT1: + { + /* Object references -- show the type and OID of the referenced object. */ + H5O_info_t oi; + + if((obj = H5Ropen_object(ref_vp, H5P_DEFAULT, H5P_DEFAULT)) >= 0) { + H5Oget_info2(obj, &oi, H5O_INFO_BASIC); + if(H5Oclose(obj) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + } + else + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + + if (NULL == (this_str = (char *) HDmalloc(14))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + if (HDsprintf(this_str, "%u-", (unsigned) oi.type) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + if (!h5str_append(out_str, this_str)) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + HDfree(this_str); + this_str = NULL; + switch (obj_type) { case H5O_TYPE_GROUP: if (!h5str_append(out_str, H5_TOOLS_GROUP)) @@ -1079,6 +1110,16 @@ h5str_sprintf default: break; } /* end switch */ + H5Oclose(obj); + h5str_sprint_reference(ENVONLY, out_str, container, ref_vp); + + /* Print OID */ + if (NULL == (this_str = (char *) HDmalloc(64))) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + if (HDsprintf(this_str, "%lu:"H5_PRINTF_HADDR_FMT" ", oi.fileno, oi.addr) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + } + break; case H5R_DATASET_REGION1: if (!h5str_append(out_str, H5_TOOLS_DATASET)) diff --git a/src/H5private.h b/src/H5private.h index c39c946..5ab9daf 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1190,13 +1190,23 @@ typedef off_t h5_stat_size_t; #define HDrandom() HDrand() #endif /* HDrandom */ H5_DLL int HDrand(void); -#elif H5_HAVE_RANDOM + #ifndef HDsrandom + #define HDsrandom(S) HDsrand(S) + #endif /* HDsrandom */ + H5_DLL void HDsrand(unsigned int seed); +#elif defined(H5_HAVE_RANDOM) #ifndef HDrand #define HDrand() random() #endif /* HDrand */ #ifndef HDrandom #define HDrandom() random() #endif /* HDrandom */ + #ifndef HDsrand + #define HDsrand(S) srandom(S) + #endif /* HDsrand */ + #ifndef HDsrandom + #define HDsrandom(S) srandom(S) + #endif /* HDsrandom */ #else /* H5_HAVE_RANDOM */ #ifndef HDrand #define HDrand() rand() @@ -1204,6 +1214,12 @@ typedef off_t h5_stat_size_t; #ifndef HDrandom #define HDrandom() rand() #endif /* HDrandom */ + #ifndef HDsrand + #define HDsrand(S) srand(S) + #endif /* HDsrand */ + #ifndef HDsrandom + #define HDsrandom(S) srand(S) + #endif /* HDsrandom */ #endif /* H5_HAVE_RANDOM */ #ifndef HDread @@ -1324,26 +1340,6 @@ typedef off_t h5_stat_size_t; #ifndef HDsqrt #define HDsqrt(X) sqrt(X) #endif /* HDsqrt */ -#ifdef H5_HAVE_RAND_R - H5_DLL void HDsrand(unsigned int seed); - #ifndef HDsrandom - #define HDsrandom(S) HDsrand(S) - #endif /* HDsrandom */ -#elif H5_HAVE_RANDOM - #ifndef HDsrand - #define HDsrand(S) srandom(S) - #endif /* HDsrand */ - #ifndef HDsrandom - #define HDsrandom(S) srandom(S) - #endif /* HDsrandom */ -#else /* H5_HAVE_RAND_R */ - #ifndef HDsrand - #define HDsrand(S) srand(S) - #endif /* HDsrand */ - #ifndef HDsrandom - #define HDsrandom(S) srand(S) - #endif /* HDsrandom */ -#endif /* H5_HAVE_RAND_R */ #ifndef HDsscanf #define HDsscanf(S,FMT,...) sscanf(S,FMT,__VA_ARGS__) #endif /* HDsscanf */ diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index dde3c15..11ba612 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -480,10 +480,10 @@ typedef struct h5tool_format_t { /*used to skip the first set of checks for line length*/ int skip_first; - /*flag used to hide or show the file number for obj refs*/ + /*flag used to hide or show the file number for object refs*/ int obj_hidefileno; - /*string used to format the output for the obje refs*/ + /*string used to format the output for the object refs*/ const char *obj_format; /*flag used to hide or show the file number for dataset regions*/ diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 80a442a..f35fdab 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -764,7 +764,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai /* cp_vp is the pointer into the struct where a `char*' is stored. So we have * to dereference the pointer to get the `char*' to pass to HDstrlen(). */ s = *(char **)((void *)cp_vp); - if(s != NULL) size = HDstrlen(s); + if(s != NULL) + size = HDstrlen(s); } else { s = cp_vp; @@ -784,8 +785,9 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai * threshold is zero then that means it can repeat any number * of times. */ - if(info->str_repeat > 0) while (i + j < size && s[i] == s[i + j]) - j++; + if(info->str_repeat > 0) + while (i + j < size && s[i] == s[i + j]) + j++; /* * Print the opening quote. If the repeat count is high enough to @@ -1091,7 +1093,6 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_append(str, "NULL"); else { if (H5Tequal(type, H5T_STD_REF)) { - char *obj_name = NULL; H5O_type_t obj_type; /* Object type */ H5R_type_t ref_type; /* Reference type */ const H5R_ref_t *ref_vp = (const H5R_ref_t *)vp; @@ -1358,7 +1359,7 @@ h5tools_str_sprint_reference(h5tools_str_t *str, const h5tool_format_t *info, hid_t container, H5R_ref_t *ref_vp) { H5TOOLS_ERR_INIT(int, SUCCEED) - ssize_t buf_size, status; + ssize_t buf_size; H5TOOLS_PUSH_STACK(); H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "enter"); @@ -1368,11 +1369,11 @@ h5tools_str_sprint_reference(h5tools_str_t *str, const h5tool_format_t *info, H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "buf_size=%ld", buf_size); if (buf_size) { char *file_name = (char *)HDmalloc(sizeof(char) * (size_t)buf_size + 1); - status = H5Rget_file_name(ref_vp, file_name, buf_size + 1); - file_name[buf_size] = '\0'; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "name=%s", file_name); - - h5tools_str_append(str, "%s", file_name); + if (H5Rget_file_name(ref_vp, file_name, buf_size + 1) >= 0) { + file_name[buf_size] = '\0'; + H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "name=%s", file_name); + h5tools_str_append(str, "%s", file_name); + } HDfree(file_name); } @@ -1380,11 +1381,11 @@ h5tools_str_sprint_reference(h5tools_str_t *str, const h5tool_format_t *info, H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "buf_size=%ld", buf_size); if (buf_size) { char *obj_name = (char *)HDmalloc(sizeof(char) * (size_t)buf_size + 1); - status = H5Rget_obj_name(ref_vp, H5P_DEFAULT, obj_name, buf_size + 1); - obj_name[buf_size] = '\0'; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "name=%s", obj_name); - - h5tools_str_append(str, "%s", obj_name); + if (H5Rget_obj_name(ref_vp, H5P_DEFAULT, obj_name, buf_size + 1) >= 0) { + obj_name[buf_size] = '\0'; + H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "name=%s", obj_name); + h5tools_str_append(str, "%s", obj_name); + } HDfree(obj_name); } @@ -1393,11 +1394,11 @@ h5tools_str_sprint_reference(h5tools_str_t *str, const h5tool_format_t *info, H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "buf_size=%ld", buf_size); if (buf_size) { char *attr_name = (char *)HDmalloc(sizeof(char) * (size_t)buf_size + 1); - status = H5Rget_attr_name(ref_vp, attr_name, buf_size + 1); - attr_name[buf_size] = '\0'; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "name=%s", attr_name); - - h5tools_str_append(str, "/%s", attr_name); + if (H5Rget_attr_name(ref_vp, attr_name, buf_size + 1) >= 0) { + attr_name[buf_size] = '\0'; + H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "name=%s", attr_name); + h5tools_str_append(str, "/%s", attr_name); + } HDfree(attr_name); } } -- cgit v0.12