summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5diff_attr.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2017-10-13 21:34:01 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2017-10-13 21:34:01 (GMT)
commitd5c073d406f8d1e1ac3bcb05883bea406c8e9378 (patch)
treef9a8d818c032fa4d5f3cfa0857a799ecfa0cc9a7 /tools/lib/h5diff_attr.c
parentfc12672cdbd162f47293ec9ee2185e3efe1d0405 (diff)
downloadhdf5-d5c073d406f8d1e1ac3bcb05883bea406c8e9378.zip
hdf5-d5c073d406f8d1e1ac3bcb05883bea406c8e9378.tar.gz
hdf5-d5c073d406f8d1e1ac3bcb05883bea406c8e9378.tar.bz2
HDFFV-10296 Update tools lib to use the error handling macros.
Diffstat (limited to 'tools/lib/h5diff_attr.c')
-rw-r--r--tools/lib/h5diff_attr.c223
1 files changed, 108 insertions, 115 deletions
diff --git a/tools/lib/h5diff_attr.c b/tools/lib/h5diff_attr.c
index 9bebcbe..f381393 100644
--- a/tools/lib/h5diff_attr.c
+++ b/tools/lib/h5diff_attr.c
@@ -136,32 +136,32 @@ static void table_attr_mark_exist(unsigned *exist, char *name, table_attrs_t *ta
*
* Parameter:
* table_out [OUT] : return the list
- *
- * Programmer: Jonathan Kim
- *
- * Date: March 15, 2011
*------------------------------------------------------------------------*/
static herr_t build_match_list_attrs(hid_t loc1_id, hid_t loc2_id, table_attrs_t ** table_out, diff_opt_t *options)
{
- H5O_info_t oinfo1, oinfo2; /* Object info */
- hid_t attr1_id=-1; /* attr ID */
- hid_t attr2_id=-1; /* attr ID */
- size_t curr1 = 0;
- size_t curr2 = 0;
- unsigned infile[2];
- char name1[ATTR_NAME_MAX];
- char name2[ATTR_NAME_MAX];
- int cmp;
- unsigned i;
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
+ H5O_info_t oinfo1, oinfo2; /* Object info */
+ hid_t attr1_id = -1; /* attr ID */
+ hid_t attr2_id = -1; /* attr ID */
+ size_t curr1 = 0;
+ size_t curr2 = 0;
+ unsigned infile[2];
+ char name1[ATTR_NAME_MAX];
+ char name2[ATTR_NAME_MAX];
+ int cmp;
+ unsigned i;
table_attrs_t *table_lp = NULL;
h5difftrace("build_match_list_attrs start\n");
+
if(H5Oget_info(loc1_id, &oinfo1) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Oget_info first object failed");
if(H5Oget_info(loc2_id, &oinfo2) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Oget_info second object failed");
- table_attrs_init( &table_lp );
+ table_attrs_init(&table_lp);
+ if (table_lp == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Table allocation failed");
h5diffdebug3("build_match_list_attrs: %ld - %ld\n", curr1 < oinfo1.num_attrs, curr2 < oinfo2.num_attrs);
@@ -172,18 +172,18 @@ static herr_t build_match_list_attrs(hid_t loc1_id, hid_t loc2_id, table_attrs_t
/*------------------
* open attribute1 */
if((attr1_id = H5Aopen_by_idx(loc1_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr1, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx first attribute failed");
/* get name */
if(H5Aget_name(attr1_id, (size_t)ATTR_NAME_MAX, name1) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_name first attribute failed");
/*------------------
* open attribute2 */
if((attr2_id = H5Aopen_by_idx(loc2_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr2, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx second attribute failed");
/* get name */
if(H5Aget_name(attr2_id, (size_t)ATTR_NAME_MAX, name2) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_name second attribute failed");
/* criteria is string compare */
cmp = HDstrcmp(name1, name2);
@@ -224,10 +224,10 @@ static herr_t build_match_list_attrs(hid_t loc1_id, hid_t loc2_id, table_attrs_t
/*------------------
* open attribute1 */
if((attr1_id = H5Aopen_by_idx(loc1_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr1, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx first attribute failed");
/* get name */
if(H5Aget_name(attr1_id, (size_t)ATTR_NAME_MAX, name1) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_name first attribute failed");
h5diffdebug2("build_match_list_attrs #1 name - %s\n", name1);
table_attr_mark_exist(infile, name1, table_lp);
@@ -246,10 +246,10 @@ static herr_t build_match_list_attrs(hid_t loc1_id, hid_t loc2_id, table_attrs_t
/*------------------
* open attribute2 */
if((attr2_id = H5Aopen_by_idx(loc2_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)curr2, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx second attribute failed");
/* get name */
if(H5Aget_name(attr2_id, (size_t)ATTR_NAME_MAX, name2) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_name second attribute failed");
h5diffdebug2("build_match_list_attrs #2 name - %s\n", name2);
table_attr_mark_exist(infile, name2, table_lp);
@@ -258,6 +258,7 @@ static herr_t build_match_list_attrs(hid_t loc1_id, hid_t loc2_id, table_attrs_t
/* close for next turn */
H5Aclose(attr2_id);
+ attr2_id = -1;
}
/*------------------------------------------------------
@@ -280,39 +281,30 @@ static herr_t build_match_list_attrs(hid_t loc1_id, hid_t loc2_id, table_attrs_t
table_lp->nattrs - table_lp->nattrs_only1 - table_lp->nattrs_only2,
table_lp->nattrs_only1, table_lp->nattrs_only2);
+done:
*table_out = table_lp;
- h5difftrace("build_match_list_attrs end\n");
- return 0;
-
-error:
- if (0 < attr1_id)
+ /* disable error reporting */
+ H5E_BEGIN_TRY {
H5Aclose(attr1_id);
- if (0 < attr2_id)
H5Aclose(attr2_id);
+ } H5E_END_TRY;
+
+ h5difftrace("build_match_list_attrs end\n");
- h5difftrace("build_match_list_attrs end with error\n");
- return -1;
+ return ret_value;
}
/*-------------------------------------------------------------------------
* Function: diff_attr
*
- * Purpose: compare attributes located in LOC1_ID and LOC2_ID, which are
- * obtained either from
- * loc_id = H5Gopen2(fid, name, H5P_DEFAULT);
- * loc_id = H5Dopen2(fid, name);
- * loc_id = H5Topen2(fid, name, H5P_DEFAULT);
- *
- * Return: number of differences found
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: November, 03, 2003
- *
- * Modifications:
- * March, 02, 2007: return the number of differences found
+ * Purpose: compare attributes located in LOC1_ID and LOC2_ID, which are
+ * obtained either from
+ * loc_id = H5Gopen2(fid, name, H5P_DEFAULT);
+ * loc_id = H5Dopen2(fid, name);
+ * loc_id = H5Topen2(fid, name, H5P_DEFAULT);
*
+ * Return: number of differences found
*-------------------------------------------------------------------------
*/
@@ -322,41 +314,45 @@ hsize_t diff_attr(hid_t loc1_id,
const char *path2,
diff_opt_t *options)
{
- hid_t attr1_id=-1; /* attr ID */
- hid_t attr2_id=-1; /* attr ID */
- hid_t space1_id=-1; /* space ID */
- hid_t space2_id=-1; /* space ID */
- hid_t ftype1_id=-1; /* file data type ID */
- hid_t ftype2_id=-1; /* file data type ID */
- int vstrtype1=0; /* ftype1 is a variable string */
- int vstrtype2=0; /* ftype2 is a variable string */
- hid_t mtype1_id=-1; /* memory data type ID */
- hid_t mtype2_id=-1; /* memory data type ID */
- size_t msize1; /* memory size of memory type */
- size_t msize2; /* memory size of memory type */
- void *buf1=NULL; /* data buffer */
- void *buf2=NULL; /* data buffer */
- hbool_t buf1hasdata=FALSE; /* buffer has data */
- hbool_t buf2hasdata=FALSE; /* buffer has data */
- hsize_t nelmts1; /* number of elements in dataset */
- int rank1; /* rank of dataset */
- int rank2; /* rank of dataset */
- hsize_t dims1[H5S_MAX_RANK];/* dimensions of dataset */
- hsize_t dims2[H5S_MAX_RANK];/* dimensions of dataset */
- char *name1;
- char *name2;
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
+ hid_t attr1_id = -1; /* attr ID */
+ hid_t attr2_id = -1; /* attr ID */
+ hid_t space1_id = -1; /* space ID */
+ hid_t space2_id = -1; /* space ID */
+ hid_t ftype1_id = -1; /* file data type ID */
+ hid_t ftype2_id = -1; /* file data type ID */
+ int vstrtype1 = 0; /* ftype1 is a variable string */
+ int vstrtype2 = 0; /* ftype2 is a variable string */
+ hid_t mtype1_id = -1; /* memory data type ID */
+ hid_t mtype2_id = -1; /* memory data type ID */
+ size_t msize1; /* memory size of memory type */
+ size_t msize2; /* memory size of memory type */
+ void *buf1 = NULL; /* data buffer */
+ void *buf2 = NULL; /* data buffer */
+ hbool_t buf1hasdata = FALSE; /* buffer has data */
+ hbool_t buf2hasdata = FALSE; /* buffer has data */
+ hsize_t nelmts1; /* number of elements in dataset */
+ int rank1; /* rank of dataset */
+ int rank2; /* rank of dataset */
+ hsize_t dims1[H5S_MAX_RANK]; /* dimensions of dataset */
+ hsize_t dims2[H5S_MAX_RANK]; /* dimensions of dataset */
+ char *name1 = NULL;
+ char *name2 = NULL;
char np1[512];
char np2[512];
- unsigned u; /* Local index variable */
+ unsigned u; /* Local index variable */
hsize_t nfound = 0;
hsize_t nfound_total = 0;
int j;
+ /* Initialize error status */
+ options->err_stat = 1;
+
table_attrs_t *match_list_attrs = NULL;
h5difftrace("diff_attr start\n");
if(build_match_list_attrs(loc1_id, loc2_id, &match_list_attrs, options) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "build_match_list_attrs failed");
/* if detect any unique extra attr */
if(match_list_attrs->nattrs_only1 || match_list_attrs->nattrs_only2) {
@@ -373,21 +369,22 @@ hsize_t diff_attr(hid_t loc1_id,
/*--------------
* attribute 1 */
if((attr1_id = H5Aopen(loc1_id, name1, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen first attribute failed");
/*--------------
* attribute 2 */
if((attr2_id = H5Aopen(loc2_id, name2, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen second attribute failed");
h5difftrace("diff_attr got attributes\n");
/* get the datatypes */
if((ftype1_id = H5Aget_type(attr1_id)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type first attribute failed");
vstrtype1 = H5Tis_variable_str(ftype1_id);
if((ftype2_id = H5Aget_type(attr2_id)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type second attribute failed");
vstrtype2 = H5Tis_variable_str(ftype2_id);
+
/* no compare if either one but not both are variable string type */
if (vstrtype1 != vstrtype2) {
if((options->m_verbose || options->m_list_not_cmp))
@@ -395,37 +392,37 @@ hsize_t diff_attr(hid_t loc1_id,
path1, name1, path2, name2);
options->not_cmp = 1;
if (H5Tclose(ftype1_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose first attribute ftype failed");
if (H5Tclose(ftype2_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose second attribute ftype failed");
if (H5Aclose(attr1_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose first attribute failed");
if (H5Aclose(attr2_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose second attribute failed");
continue;
}
if((mtype1_id = H5Tget_native_type(ftype1_id, H5T_DIR_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_native_type first attribute ftype failed");
if((mtype2_id = H5Tget_native_type(ftype2_id, H5T_DIR_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_native_type second attribute ftype failed");
if((msize1 = H5Tget_size(mtype1_id)) == 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size first attribute mtype failed");
if((msize2 = H5Tget_size(mtype2_id)) == 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size second attribute mtype failed");
/* get the dataspace */
if((space1_id = H5Aget_space(attr1_id)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_space first attribute failed");
if((space2_id = H5Aget_space(attr2_id)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_space second attribute failed");
/* get dimensions */
if((rank1 = H5Sget_simple_extent_dims(space1_id, dims1, NULL)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims first attribute failed");
if((rank2 = H5Sget_simple_extent_dims(space2_id, dims2, NULL)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims second attribute failed");
/*----------------------------------------------------------------------
* check for comparable TYPE and SPACE
@@ -437,21 +434,21 @@ hsize_t diff_attr(hid_t loc1_id,
if(diff_can_type(ftype1_id, ftype2_id, rank1, rank2, dims1, dims2,
dims1, dims2, name1, name2, options, 0) != 1) {
if(H5Tclose(ftype1_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose first attribute ftype failed");
if(H5Tclose(ftype2_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose second attribute ftype failed");
if(H5Sclose(space1_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose first attribute failed");
if(H5Sclose(space2_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose second attribute failed");
if(H5Aclose(attr1_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose first attribute failed");
if(H5Aclose(attr2_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose second attribute failed");
if(H5Tclose(mtype1_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose first attribute mtype failed");
if(H5Tclose(mtype2_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose second attribute mtype failed");
continue;
}
@@ -462,7 +459,7 @@ hsize_t diff_attr(hid_t loc1_id,
*/
if(FAIL == match_up_memsize(ftype1_id, ftype2_id, &mtype1_id,
&mtype2_id, &msize1, &msize2))
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "match_up_memsize failed");
/*---------------------------------------------------------------------
* read
@@ -476,18 +473,18 @@ hsize_t diff_attr(hid_t loc1_id,
buf2 = (void *)HDcalloc((size_t)(nelmts1), msize2);
if(buf1 == NULL || buf2 == NULL) {
parallel_print("cannot read into memory\n");
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "buffer allocation failed");
}
if(H5Aread(attr1_id, mtype1_id, buf1) < 0) {
parallel_print("Failed reading attribute1 %s/%s\n", path1, name1);
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type first attribute failed");
}
else
buf1hasdata = TRUE;
if(H5Aread(attr2_id, mtype2_id, buf2) < 0) {
parallel_print("Failed reading attribute2 %s/%s\n", path2, name2);
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type second attribute failed");
}
else
buf2hasdata = TRUE;
@@ -545,32 +542,29 @@ hsize_t diff_attr(hid_t loc1_id,
buf2 = NULL;
if(H5Tclose(ftype1_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type first attribute failed");
if(H5Tclose(ftype2_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type second attribute failed");
if(H5Sclose(space1_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type first attribute failed");
if(H5Sclose(space2_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type second attribute failed");
if(H5Aclose(attr1_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type first attribute failed");
if(H5Aclose(attr2_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type second attribute failed");
if(H5Tclose(mtype1_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose first attribute mtype failed");
if(H5Tclose(mtype2_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose second attribute mtype failed");
nfound_total += nfound;
}
} /* u */
- table_attrs_free(match_list_attrs);
-
- h5difftrace("diff_attr end\n");
- return nfound_total;
+ options->err_stat = 0;
-error:
+done:
H5E_BEGIN_TRY {
if(buf1) {
if(buf1hasdata && TRUE == h5tools_detect_vlen(mtype1_id))
@@ -595,8 +589,7 @@ error:
H5Aclose(attr2_id);
} H5E_END_TRY;
- options->err_stat = 1;
- h5difftrace("diff_attr end with error\n");
+ h5difftrace("diff_attr end\n");
return nfound_total;
}