diff options
author | Allen Byrne <50328838+byrnHDF@users.noreply.github.com> | 2022-07-18 17:23:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-18 17:23:37 (GMT) |
commit | f6997681335f0b5fe2e8904f9108a71c5200fb2d (patch) | |
tree | edc5aabdcae1035ce6e888bde550e15b1ad2e878 /java/src/jni/h5util.c | |
parent | 7f9a5f0b6e58e9c04a18ea83ff0400f95294c6ac (diff) | |
download | hdf5-f6997681335f0b5fe2e8904f9108a71c5200fb2d.zip hdf5-f6997681335f0b5fe2e8904f9108a71c5200fb2d.tar.gz hdf5-f6997681335f0b5fe2e8904f9108a71c5200fb2d.tar.bz2 |
1.12 eliminate unnecessary errors in the error stack (#1880)
* Eliminate unnecessary error output
* Fix merge typo
* fix format
* Fix object address to tokens
* Fix conflict
Diffstat (limited to 'java/src/jni/h5util.c')
-rw-r--r-- | java/src/jni/h5util.c | 461 |
1 files changed, 132 insertions, 329 deletions
diff --git a/java/src/jni/h5util.c b/java/src/jni/h5util.c index a1a1eda..2de5d87 100644 --- a/java/src/jni/h5util.c +++ b/java/src/jni/h5util.c @@ -52,7 +52,6 @@ void * edata; /* Local Prototypes */ /********************/ -int h5str_old_region_dataset(JNIEnv *env, h5str_t *out_str, hid_t container, void *ref_buf, int expand_data); int h5str_region_dataset(JNIEnv *env, h5str_t *out_str, H5R_ref_t *ref_vp, int expand_data); static int h5str_dump_region_blocks(JNIEnv *env, h5str_t *str, hid_t region, hid_t region_obj, @@ -64,6 +63,7 @@ static int h5str_is_zero(const void *_mem, size_t size); static hid_t h5str_get_native_type(hid_t type); static hid_t h5str_get_little_endian_type(hid_t type); static hid_t h5str_get_big_endian_type(hid_t type); +static htri_t h5str_detect_vlen(hid_t tid); static htri_t h5str_detect_vlen_str(hid_t tid); static int h5str_dump_simple_data(JNIEnv *env, FILE *stream, hid_t container, hid_t type, void *_mem, hsize_t nelmts); @@ -642,33 +642,6 @@ done: } /* end h5str_convert */ /*------------------------------------------------------------------------- - * Function: h5str_sprint_old_reference - * - * Purpose: Object reference -- show the name of the 1.10 referenced object. - * - * Return: SUCCEED or FAIL - *------------------------------------------------------------------------- - */ -int -h5str_sprint_old_reference(JNIEnv *env, h5str_t *out_str, hid_t region_obj, void *ref_buf) -{ - hid_t region = H5I_INVALID_HID; - char ref_name[1024]; - - int ret_value = FAIL; - - if ((H5Rget_name(region_obj, H5R_DATASET_REGION, ref_buf, (char *)ref_name, 1024)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - if (!h5str_append(out_str, ref_name)) - H5_ASSERTION_ERROR(ENVONLY, "Unable to append string."); - - ret_value = SUCCEED; -done: - - return ret_value; -} /* h5str_sprint_reference */ - -/*------------------------------------------------------------------------- * Function: h5str_sprint_reference * * Purpose: Object reference -- show the name of the referenced object. @@ -732,48 +705,6 @@ done: } /* h5str_sprint_reference */ int -h5str_old_region_dataset(JNIEnv *env, h5str_t *out_str, hid_t container, void *ref_buf, int expand_data) -{ - H5S_sel_type region_type = H5S_SEL_ERROR; - hid_t region_obj = H5I_INVALID_HID; - hid_t region_sid = H5I_INVALID_HID; - - int ret_value = FAIL; - - if ((region_obj = H5Rdereference2(container, H5P_DEFAULT, H5R_DATASET_REGION, ref_buf)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if ((region_sid = H5Rget_region(container, H5R_DATASET_REGION, ref_buf)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (expand_data == 0) - if (h5str_sprint_old_reference(ENVONLY, out_str, region_obj, ref_buf) < 0) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - - if ((region_type = H5Sget_select_type(region_sid)) > H5S_SEL_ERROR) { - if (H5S_SEL_POINTS == region_type) { - if (h5str_dump_region_points(ENVONLY, out_str, region_sid, region_obj, expand_data) < 0) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - } - else if (H5S_SEL_HYPERSLABS == region_type) { - if (h5str_dump_region_blocks(ENVONLY, out_str, region_sid, region_obj, expand_data) < 0) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - } - } - - ret_value = SUCCEED; -done: - if (region_sid >= 0) - if (H5Sclose(region_sid) < 0) - H5_LIBRARY_ERROR(ENVONLY); - if (region_obj >= 0) - if (H5Dclose(region_obj) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - return ret_value; -} - -int h5str_region_dataset(JNIEnv *env, h5str_t *out_str, H5R_ref_t *ref_vp, int expand_data) { hid_t new_obj_id = H5I_INVALID_HID; @@ -1175,217 +1106,125 @@ h5str_sprintf(JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *i } case H5T_REFERENCE: { - if (H5R_DSET_REG_REF_BUF_SIZE == typeSize) { - if (h5str_old_region_dataset(ENVONLY, out_str, container, cptr, expand_data) < 0) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - } - else if (H5R_OBJ_REF_BUF_SIZE == typeSize) { - H5O_info2_t oi; - hid_t obj = H5I_INVALID_HID; - char * obj_tok_str = NULL; - - /* - * Object references -- show the type and OID of the referenced - * object. - */ - - if (NULL == (this_str = (char *)HDmalloc(64))) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - - if ((obj = H5Rdereference2(container, H5P_DEFAULT, H5R_OBJECT, cptr)) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - if (H5Oget_info3(obj, &oi, H5O_INFO_ALL) < 0) - H5_LIBRARY_ERROR(ENVONLY); - - /* Print object data and close object */ - H5Otoken_to_str(obj, &oi.token, &obj_tok_str); - - switch (oi.type) { - case H5O_TYPE_GROUP: - if (HDsprintf(this_str, "%s %s", H5_TOOLS_GROUP, obj_tok_str) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + /* H5T_STD_REF */ + hid_t new_obj_id = H5I_INVALID_HID; + H5O_type_t obj_type = -1; /* Object type */ + H5R_type_t ref_type; /* Reference type */ + + H5R_ref_t *ref_vp = (H5R_ref_t *)cptr; + + ref_type = H5Rget_type(ref_vp); + if (!h5str_is_zero(ref_vp, H5Tget_size(H5T_STD_REF))) { + switch (ref_type) { + case H5R_OBJECT1: + if (H5Rget_obj_type3(ref_vp, H5P_DEFAULT, &obj_type) >= 0) { + switch (obj_type) { + case H5O_TYPE_DATASET: + if (h5str_region_dataset(ENVONLY, out_str, ref_vp, expand_data) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + + case H5O_TYPE_GROUP: + case H5O_TYPE_NAMED_DATATYPE: + case H5O_TYPE_MAP: + case H5O_TYPE_UNKNOWN: + case H5O_TYPE_NTYPES: + default: { + /* Object references -- show the type and OID of the referenced object. */ + H5O_info2_t oi; + char * obj_tok_str = NULL; + if ((new_obj_id = H5Ropen_object(ref_vp, H5P_DEFAULT, H5P_DEFAULT)) >= + 0) { + H5Oget_info3(new_obj_id, &oi, H5O_INFO_BASIC); + H5Otoken_to_str(new_obj_id, &oi.token, &obj_tok_str); + if (H5Dclose(new_obj_id) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + else + H5_LIBRARY_ERROR(ENVONLY); + + size_t this_len = 14; + if (NULL == (this_str = (char *)HDmalloc(this_len))) + H5_OUT_OF_MEMORY_ERROR( + ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + if (HDsnprintf(this_str, this_len, "%u-", (unsigned)oi.type) < 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); + if (!h5str_append(out_str, this_str)) + H5_ASSERTION_ERROR(ENVONLY, "Unable to append string."); + HDfree(this_str); + this_str = NULL; + + /* Print OID */ + { + char *token_str; + + H5Otoken_to_str(tid, &oi.token, &token_str); + + size_t that_len = 64 + strlen(token_str) + 1; + if (NULL == (this_str = HDmalloc(that_len))) + H5_OUT_OF_MEMORY_ERROR( + ENVONLY, "h5str_sprintf: failed to allocate string buffer"); + if (HDsnprintf(this_str, that_len, "%lu:%s", oi.fileno, token_str) < + 0) + H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsnprintf failure"); + + H5free_memory(token_str); + } + } break; + } /* end switch */ + } + else + H5_LIBRARY_ERROR(ENVONLY); break; - - case H5O_TYPE_DATASET: - if (HDsprintf(this_str, "%s %s", H5_TOOLS_DATASET, obj_tok_str) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + case H5R_DATASET_REGION1: + if (h5str_region_dataset(ENVONLY, out_str, ref_vp, expand_data) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); break; - - case H5O_TYPE_NAMED_DATATYPE: - if (HDsprintf(this_str, "%s %s", H5_TOOLS_DATATYPE, obj_tok_str) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); + case H5R_OBJECT2: + if (H5Rget_obj_type3(ref_vp, H5P_DEFAULT, &obj_type) >= 0) { + switch (obj_type) { + case H5O_TYPE_GROUP: + break; + + case H5O_TYPE_DATASET: + if (h5str_region_dataset(ENVONLY, out_str, ref_vp, expand_data) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + + case H5O_TYPE_NAMED_DATATYPE: + break; + + case H5O_TYPE_MAP: + case H5O_TYPE_UNKNOWN: + case H5O_TYPE_NTYPES: + default: + break; + } /* end switch */ + } + else + H5_ASSERTION_ERROR(ENVONLY, "h5str_sprintf: H5R_OBJECT2 failed"); break; - - case H5O_TYPE_UNKNOWN: - case H5O_TYPE_NTYPES: + case H5R_DATASET_REGION2: + if (h5str_region_dataset(ENVONLY, out_str, ref_vp, expand_data) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + break; + case H5R_ATTR: + if ((new_obj_id = H5Ropen_attr(ref_vp, H5P_DEFAULT, H5P_DEFAULT)) >= 0) { + if (h5str_dump_region_attribute(ENVONLY, out_str, new_obj_id) < 0) + CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); + if (H5Aclose(new_obj_id) < 0) + H5_LIBRARY_ERROR(ENVONLY); + } + break; + case H5R_BADTYPE: + case H5R_MAXTYPE: default: - if (HDsprintf(this_str, "%u-%s", (unsigned)oi.type, obj_tok_str) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); break; - } - - if (obj_tok_str) { - H5free_memory(obj_tok_str); - obj_tok_str = NULL; - } - - if (H5Oclose(obj) < 0) - H5_LIBRARY_ERROR(ENVONLY); - obj = H5I_INVALID_HID; + } /* end switch */ } - else { - /* H5T_STD_REF */ - hid_t new_obj_id = H5I_INVALID_HID; - H5O_type_t obj_type = -1; /* Object type */ - H5R_type_t ref_type; /* Reference type */ - - H5R_ref_t *ref_vp = (H5R_ref_t *)cptr; - - ref_type = H5Rget_type(ref_vp); - if (!h5str_is_zero(ref_vp, H5Tget_size(H5T_STD_REF))) { - switch (ref_type) { - case H5R_OBJECT1: - if (H5Rget_obj_type3(ref_vp, H5P_DEFAULT, &obj_type) >= 0) { - switch (obj_type) { - case H5O_TYPE_DATASET: - if (h5str_region_dataset(ENVONLY, out_str, ref_vp, expand_data) < 0) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - break; - - case H5O_TYPE_GROUP: - case H5O_TYPE_NAMED_DATATYPE: - case H5O_TYPE_MAP: - case H5O_TYPE_UNKNOWN: - case H5O_TYPE_NTYPES: - default: { - /* Object references -- show the type and - * OID of the referenced object. */ - H5O_info2_t oi; - char * obj_tok_str = NULL; - if ((new_obj_id = H5Ropen_object(ref_vp, H5P_DEFAULT, H5P_DEFAULT)) >= - 0) { - H5Oget_info3(new_obj_id, &oi, H5O_INFO_BASIC); - H5Otoken_to_str(new_obj_id, &oi.token, &obj_tok_str); - if (H5Dclose(new_obj_id) < 0) - H5_LIBRARY_ERROR(ENVONLY); - } - else - H5_LIBRARY_ERROR(ENVONLY); - - size_t this_len = 14; - if (NULL == (this_str = (char *)HDmalloc(this_len))) - H5_OUT_OF_MEMORY_ERROR( - ENVONLY, "h5str_sprintf: failed to allocate string buffer"); - switch (oi.type) { - case H5O_TYPE_GROUP: - if (HDsnprintf(this_str, this_len, "%s ", H5_TOOLS_GROUP) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, - "h5str_sprintf: HDsnprintf failure"); - break; - - case H5O_TYPE_DATASET: - if (HDsnprintf(this_str, this_len, "%s ", H5_TOOLS_DATASET) < - 0) - H5_JNI_FATAL_ERROR(ENVONLY, - "h5str_sprintf: HDsnprintf failure"); - break; - - case H5O_TYPE_NAMED_DATATYPE: - if (HDsnprintf(this_str, this_len, "%s ", H5_TOOLS_DATATYPE) < - 0) - H5_JNI_FATAL_ERROR(ENVONLY, - "h5str_sprintf: HDsnprintf failure"); - break; - - case H5O_TYPE_UNKNOWN: - case H5O_TYPE_NTYPES: - default: - if (HDsnprintf(this_str, this_len, "%u-", (unsigned)oi.type) < - 0) - H5_JNI_FATAL_ERROR(ENVONLY, - "h5str_sprintf: HDsnprintf failure"); - break; - } /* end switch */ - if (!h5str_append(out_str, this_str)) - H5_ASSERTION_ERROR(ENVONLY, "Unable to append string."); - HDfree(this_str); - this_str = NULL; - - /* Print OID */ - { - char *token_str; - - H5Otoken_to_str(tid, &oi.token, &token_str); - - size_t that_len = 64 + strlen(token_str) + 1; - if (NULL == (this_str = HDmalloc(that_len))) - H5_OUT_OF_MEMORY_ERROR( - ENVONLY, - "h5str_sprintf: failed to allocate string buffer"); - if (HDsnprintf(this_str, that_len, "%lu:%s", oi.fileno, - token_str) < 0) - H5_JNI_FATAL_ERROR(ENVONLY, - "h5str_sprintf: HDsnprintf failure"); - - H5free_memory(token_str); - } - } break; - } /* end switch */ - } - else - H5_LIBRARY_ERROR(ENVONLY); - break; - case H5R_DATASET_REGION1: - if (h5str_region_dataset(ENVONLY, out_str, ref_vp, expand_data) < 0) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - break; - case H5R_OBJECT2: - if (H5Rget_obj_type3(ref_vp, H5P_DEFAULT, &obj_type) >= 0) { - switch (obj_type) { - case H5O_TYPE_GROUP: - break; - - case H5O_TYPE_DATASET: - if (h5str_region_dataset(ENVONLY, out_str, ref_vp, expand_data) < 0) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - break; - - case H5O_TYPE_NAMED_DATATYPE: - break; - - case H5O_TYPE_MAP: - case H5O_TYPE_UNKNOWN: - case H5O_TYPE_NTYPES: - default: - break; - } /* end switch */ - } - else - H5_ASSERTION_ERROR(ENVONLY, "h5str_sprintf: H5R_OBJECT2 failed"); - break; - case H5R_DATASET_REGION2: - if (h5str_region_dataset(ENVONLY, out_str, ref_vp, expand_data) < 0) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - break; - case H5R_ATTR: - if ((new_obj_id = H5Ropen_attr(ref_vp, H5P_DEFAULT, H5P_DEFAULT)) >= 0) { - if (h5str_dump_region_attribute(ENVONLY, out_str, new_obj_id) < 0) - CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); - if (H5Aclose(new_obj_id) < 0) - H5_LIBRARY_ERROR(ENVONLY); - } - break; - case H5R_BADTYPE: - case H5R_MAXTYPE: - default: - break; - } /* end switch */ - } - if (H5Rdestroy(ref_vp) < 0) - H5_LIBRARY_ERROR(ENVONLY); - } + if (H5Rdestroy(ref_vp) < 0) + H5_LIBRARY_ERROR(ENVONLY); break; } @@ -1922,7 +1761,7 @@ h5str_is_zero(const void *_mem, size_t size) * Negative value: error occurred *------------------------------------------------------------------------- */ -htri_t +static htri_t h5str_detect_vlen(hid_t tid) { htri_t ret = FAIL; @@ -3279,65 +3118,29 @@ done: return ret_value; } -/*------------------------------------------------------------------------- - * Function: H5Tdetect_variable_str - * - * Purpose: Recursive check for variable length string of a datatype. - * - * Return: TRUE : type contains any variable length string - * FALSE : type doesn't contain any variable length string - * Negative value: failed - *------------------------------------------------------------------------- - */ htri_t H5Tdetect_variable_str(hid_t tid) { - H5T_class_t tclass = -1; - htri_t ret = FALSE; - - ret = H5Tis_variable_str(tid); - if ((ret == TRUE) || (ret < 0)) - goto done; - - tclass = H5Tget_class(tid); - if (tclass == H5T_ARRAY || tclass == H5T_VLEN) { - hid_t btid = H5Tget_super(tid); - - if (btid < 0) { - ret = (htri_t)btid; - goto done; - } - ret = H5Tdetect_variable_str(btid); - if ((ret == TRUE) || (ret < 0)) { - H5Tclose(btid); - goto done; - } - } - else if (tclass == H5T_COMPOUND) { - unsigned nmembs; - int snmembs = H5Tget_nmembers(tid); - unsigned u; - - if (snmembs < 0) { - ret = FAIL; - goto done; - } - nmembs = (unsigned)snmembs; - - for (u = 0; u < nmembs; u++) { - hid_t mtid = H5Tget_member_type(tid, u); - - ret = H5Tdetect_variable_str(mtid); - if ((ret == TRUE) || (ret < 0)) { - H5Tclose(mtid); - goto done; - } + htri_t ret_val = 0; + + if (H5Tget_class(tid) == H5T_COMPOUND) { + unsigned i; + unsigned nm = (unsigned)H5Tget_nmembers(tid); + for (i = 0; i < nm; i++) { + htri_t status = 0; + hid_t mtid = 0; + if ((mtid = H5Tget_member_type(tid, i)) < 0) + return FAIL; /* exit immediately on error */ + if ((status = H5Tdetect_variable_str(mtid)) < 0) + return status; /* exit immediately on error */ + ret_val |= status; H5Tclose(mtid); - } - } + } /* end for */ + } /* end if */ + else + ret_val = H5Tis_variable_str(tid); -done: - return ret; + return ret_val; } /* end H5Tdetect_variable_str */ static int |