diff options
author | Jordan Henderson <jhenderson@hdfgroup.org> | 2019-12-28 05:02:26 (GMT) |
---|---|---|
committer | Jordan Henderson <jhenderson@hdfgroup.org> | 2019-12-28 20:08:04 (GMT) |
commit | 2cbf31cb3ad8032fb1915c783dc52a2050aaf7da (patch) | |
tree | d88ce3a7584792894bd073df1f2290f22eb69daa /tools/lib/h5tools_str.c | |
parent | 34a68acc934800d6b8c9a51c2ce91155b3178111 (diff) | |
download | hdf5-2cbf31cb3ad8032fb1915c783dc52a2050aaf7da.zip hdf5-2cbf31cb3ad8032fb1915c783dc52a2050aaf7da.tar.gz hdf5-2cbf31cb3ad8032fb1915c783dc52a2050aaf7da.tar.bz2 |
Refactor tools library error handling macros
Diffstat (limited to 'tools/lib/h5tools_str.c')
-rw-r--r-- | tools/lib/h5tools_str.c | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 4b27847..c555a61 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -294,22 +294,22 @@ h5tools_str_prefix(h5tools_str_t *str/*in,out*/, const h5tool_format_t *info, hsize_t curr_pos = elmtno; H5TOOLS_PUSH_STACK(); - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "enter"); + H5TOOLS_DEBUG("enter"); - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "elmtno=%ld, ctx->ndims=%d", elmtno, ctx->ndims); + H5TOOLS_DEBUG("elmtno=%ld, ctx->ndims=%d", elmtno, ctx->ndims); h5tools_str_reset(str); - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ndims=%d", ndims); + H5TOOLS_DEBUG("ndims=%d", ndims); if(ndims > 0) { /* * Calculate the number of elements represented by a unit change in a * certain index position. */ for(i = 0; i < (size_t) ndims; i++) { - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "curr_pos=%ld - ctx->acc[%d]=%ld", curr_pos, i, ctx->acc[i]); + H5TOOLS_DEBUG("curr_pos=%ld - ctx->acc[%d]=%ld", curr_pos, i, ctx->acc[i]); ctx->pos[i] = curr_pos / ctx->acc[i]; curr_pos -= ctx->acc[i] * ctx->pos[i]; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "curr_pos=%ld - ctx->pos[%d]=%ld - ctx->acc[%d]=%ld", curr_pos, i, ctx->pos[i], i, ctx->acc[i]); + H5TOOLS_DEBUG("curr_pos=%ld - ctx->pos[%d]=%ld - ctx->acc[%d]=%ld", curr_pos, i, ctx->pos[i], i, ctx->acc[i]); } HDassert(curr_pos == 0); @@ -325,9 +325,9 @@ h5tools_str_prefix(h5tools_str_t *str/*in,out*/, const h5tool_format_t *info, } else /* Scalar */ h5tools_str_append(str, OPT(info->idx_n_fmt, HSIZE_T_FORMAT), (hsize_t)elmtno); - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "str=%s", str->s); + H5TOOLS_DEBUG("str=%s", str->s); - H5TOOLS_ENDDEBUG(H5E_tools_min_dbg_id_g, "exit"); + H5TOOLS_ENDDEBUG("exit"); H5TOOLS_POP_STACK(); /* Add prefix and suffix to the index */ @@ -697,7 +697,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai H5T_class_t type_class; H5TOOLS_PUSH_STACK(); - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "enter"); + H5TOOLS_DEBUG("enter"); /* Build default formats for long long types */ if(!fmt_llong[0]) { HDsnprintf(fmt_llong, sizeof(fmt_llong), "%%%sd", H5_PRINTF_LL_WIDTH); @@ -726,7 +726,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai return NULL; switch (type_class) { case H5T_FLOAT: - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_FLOAT"); + H5TOOLS_DEBUG("H5T_FLOAT"); if(sizeof(float) == nsize) { /* if (H5Tequal(type, H5T_NATIVE_FLOAT)) */ float tempfloat; @@ -758,7 +758,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai char quote = '\0'; char *s; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_STRING"); + H5TOOLS_DEBUG("H5T_STRING"); quote = '\0'; if(H5Tis_variable_str(type)) { /* cp_vp is the pointer into the struct where a `char*' is stored. So we have @@ -833,7 +833,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai break; case H5T_INTEGER: - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_INTEGER"); + H5TOOLS_DEBUG("H5T_INTEGER"); if(sizeof(char) == nsize) { if(info->ascii) h5tools_print_char(str, info, (char) (*ucp_vp)); @@ -971,7 +971,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai break; case H5T_COMPOUND: - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_COMPOUND"); + H5TOOLS_DEBUG("H5T_COMPOUND"); if(ctx->cmpd_listv) { /* there is <list_of_fields> */ unsigned save_indent_level; /* The indentation level */ size_t curr_field; /* Current field to display */ @@ -1073,7 +1073,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai { char enum_name[1024]; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_ENUM"); + H5TOOLS_DEBUG("H5T_ENUM"); if(H5Tenum_nameof(type, vp, enum_name, sizeof enum_name) >= 0) h5tools_str_append(str, h5tools_escape(enum_name, sizeof(enum_name))); else { @@ -1088,7 +1088,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai break; case H5T_REFERENCE: - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_REFERENCE"); + H5TOOLS_DEBUG("H5T_REFERENCE"); if(h5tools_str_is_zero(vp, nsize)) h5tools_str_append(str, "NULL"); else { @@ -1097,7 +1097,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai H5R_type_t ref_type; /* Reference type */ const H5R_ref_t *ref_vp = (const H5R_ref_t *)vp; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_REFERENCE:H5T_STD_REF"); + H5TOOLS_DEBUG("H5T_REFERENCE:H5T_STD_REF"); ref_type = H5Rget_type(ref_vp); H5Rget_obj_type3(ref_vp, H5P_DEFAULT, &obj_type); switch (ref_type) { @@ -1106,16 +1106,14 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai /* Object references -- show the type and OID of the referenced object. */ H5O_info_t oi; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ref_type is H5R_OBJECT1"); + H5TOOLS_DEBUG("ref_type is H5R_OBJECT1"); if((obj = H5Ropen_object(ref_vp, H5P_DEFAULT, H5P_DEFAULT)) >= 0) { H5Oget_info2(obj, &oi, H5O_INFO_BASIC); if(H5Oclose(obj) < 0) - H5Epush2(H5tools_ERR_STACK_g, __FILE__, FUNC, __LINE__, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g, - "H5Oclose H5R_OBJECT1 failed"); + H5TOOLS_GOTO_ERROR(NULL, "H5Oclose H5R_OBJECT1 failed"); } else - H5Epush2(H5tools_ERR_STACK_g, __FILE__, FUNC, __LINE__, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g, - "H5Ropen_object H5R_OBJECT1 failed"); + H5TOOLS_GOTO_ERROR(NULL, "H5Ropen_object H5R_OBJECT1 failed"); /* Print object type and close object */ switch (obj_type) { @@ -1149,12 +1147,12 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } break; case H5R_DATASET_REGION1: - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ref_type is H5R_DATASET_REGION1"); + H5TOOLS_DEBUG("ref_type is H5R_DATASET_REGION1"); h5tools_str_append(str, H5_TOOLS_DATASET); h5tools_str_sprint_reference(str, info, container, ref_vp); break; case H5R_OBJECT2: - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ref_type is H5R_OBJECT2"); + H5TOOLS_DEBUG("ref_type is H5R_OBJECT2"); switch (obj_type) { case H5O_TYPE_GROUP: h5tools_str_append(str, H5_TOOLS_GROUP); @@ -1178,12 +1176,12 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_sprint_reference(str, info, container, ref_vp); break; case H5R_DATASET_REGION2: - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ref_type is H5R_DATASET_REGION2"); + H5TOOLS_DEBUG("ref_type is H5R_DATASET_REGION2"); h5tools_str_append(str, H5_TOOLS_DATASET); h5tools_str_sprint_reference(str, info, container, ref_vp); break; case H5R_ATTR: - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ref_type is H5R_ATTR"); + H5TOOLS_DEBUG("ref_type is H5R_ATTR"); h5tools_str_append(str, H5_TOOLS_ATTRIBUTE); h5tools_str_sprint_reference(str, info, container, ref_vp); break; @@ -1192,15 +1190,15 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai default: break; } /* end switch */ - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_REFERENCE:H5T_STD_REF end"); + H5TOOLS_DEBUG("H5T_REFERENCE:H5T_STD_REF end"); } else if (H5Tequal(type, H5T_STD_REF_DSETREG)) { /* if(nsize == H5R_DSET_REG_REF_BUF_SIZE) */ - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_REFERENCE:H5T_STD_REF_DSETREG"); + H5TOOLS_DEBUG("H5T_REFERENCE:H5T_STD_REF_DSETREG"); } else if (H5Tequal(type, H5T_STD_REF_OBJ)) { /* if (nsize == H5R_OBJ_REF_BUF_SIZE) */ - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_REFERENCE:H5T_STD_REF_OBJ"); + H5TOOLS_DEBUG("H5T_REFERENCE:H5T_STD_REF_OBJ"); } /* end else if (H5Tequal(type, H5T_STD_REF_OBJ)) */ } break; @@ -1211,7 +1209,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai hsize_t i, dims[H5S_MAX_RANK], temp_nelmts; static int is_next_arry_elmt = 0; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_ARRAY"); + H5TOOLS_DEBUG("H5T_ARRAY"); /* Get the array's base datatype for each element */ memb = H5Tget_super(type); size = H5Tget_size(memb); @@ -1273,7 +1271,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai { unsigned int i; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5T_VLEN"); + H5TOOLS_DEBUG("H5T_VLEN"); /* Get the VL sequences's base datatype for each element */ memb = H5Tget_super(type); size = H5Tget_size(memb); @@ -1323,7 +1321,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai /* All other types get printed as hexadecimal */ size_t i; - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "OTHER"); + H5TOOLS_DEBUG("OTHER"); if(1 == nsize) h5tools_str_append(str, "0x%02x", ucp_vp[0]); else @@ -1339,10 +1337,13 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai break; } /* end switch */ } + +done: + CATCH ret_value = h5tools_str_fmt(str, start, OPT(info->elmt_fmt, "%s")); - H5TOOLS_ENDDEBUG(H5E_tools_min_dbg_id_g, "exit with %s", ret_value); + H5TOOLS_ENDDEBUG("exit with %s", ret_value); H5TOOLS_POP_STACK(); return ret_value; } @@ -1364,28 +1365,28 @@ h5tools_str_sprint_reference(h5tools_str_t *str, const h5tool_format_t *info, ssize_t buf_size; H5TOOLS_PUSH_STACK(); - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "enter"); + H5TOOLS_DEBUG("enter"); h5tools_str_append(str, " \""); buf_size = H5Rget_file_name(ref_vp, NULL, 0); - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "buf_size=%ld", buf_size); + H5TOOLS_DEBUG("buf_size=%ld", buf_size); if (buf_size) { char *file_name = (char *)HDmalloc(sizeof(char) * (size_t)buf_size + 1); 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_DEBUG("name=%s", file_name); h5tools_str_append(str, "%s", file_name); } HDfree(file_name); } buf_size = H5Rget_obj_name(ref_vp, H5P_DEFAULT, NULL, 0); - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "buf_size=%ld", buf_size); + H5TOOLS_DEBUG("buf_size=%ld", buf_size); if (buf_size) { char *obj_name = (char *)HDmalloc(sizeof(char) * (size_t)buf_size + 1); 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_DEBUG("name=%s", obj_name); h5tools_str_append(str, "%s", obj_name); } HDfree(obj_name); @@ -1393,12 +1394,12 @@ h5tools_str_sprint_reference(h5tools_str_t *str, const h5tool_format_t *info, if (H5Rget_type(ref_vp) == H5R_ATTR) { buf_size = H5Rget_attr_name(ref_vp, NULL, 0); - H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "buf_size=%ld", buf_size); + H5TOOLS_DEBUG("buf_size=%ld", buf_size); if (buf_size) { char *attr_name = (char *)HDmalloc(sizeof(char) * (size_t)buf_size + 1); 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_DEBUG("name=%s", attr_name); h5tools_str_append(str, "/%s", attr_name); } HDfree(attr_name); @@ -1407,7 +1408,7 @@ h5tools_str_sprint_reference(h5tools_str_t *str, const h5tool_format_t *info, h5tools_str_append(str, "\""); CATCH - H5TOOLS_ENDDEBUG(H5E_tools_min_dbg_id_g, "exit"); + H5TOOLS_ENDDEBUG("exit"); H5TOOLS_POP_STACK(); } |