diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2016-09-28 16:49:06 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2016-09-28 16:49:06 (GMT) |
commit | 50d3fc7a61f4b1dbe2ead376b778f5743060cc6e (patch) | |
tree | cc0f0e419e786bc47a4acfb479671faf717bdd9f /tools/h5repack/h5repack_refs.c | |
parent | 0f89cff001e619bf5eeb5351f2e32fc06075cc5e (diff) | |
download | hdf5-50d3fc7a61f4b1dbe2ead376b778f5743060cc6e.zip hdf5-50d3fc7a61f4b1dbe2ead376b778f5743060cc6e.tar.gz hdf5-50d3fc7a61f4b1dbe2ead376b778f5743060cc6e.tar.bz2 |
Merge/align with trunk
Diffstat (limited to 'tools/h5repack/h5repack_refs.c')
-rw-r--r-- | tools/h5repack/h5repack_refs.c | 256 |
1 files changed, 126 insertions, 130 deletions
diff --git a/tools/h5repack/h5repack_refs.c b/tools/h5repack/h5repack_refs.c index 2b39249..f0f32c3 100644 --- a/tools/h5repack/h5repack_refs.c +++ b/tools/h5repack/h5repack_refs.c @@ -1,4 +1,3 @@ - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * Copyright by the Board of Trustees of the University of Illinois. * @@ -50,6 +49,7 @@ int do_copy_refobjs(hid_t fidin, trav_table_t *travt, pack_opt_t *options) /* repack options */ { + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ hid_t grp_in = (-1); /* read group ID */ hid_t grp_out = (-1); /* write group ID */ hid_t dset_in = (-1); /* read dataset ID */ @@ -85,18 +85,18 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if((grp_out = H5Gopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed"); if((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed"); if(copy_refs_attr(grp_in, grp_out, options, travt, fidout) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_refs_attr failed"); if(H5Gclose(grp_out) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed"); if(H5Gclose(grp_in) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed"); /*------------------------------------------------------------------------- * check for hard links @@ -113,26 +113,26 @@ int do_copy_refobjs(hid_t fidin, */ case H5TRAV_TYPE_DATASET: if((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); if((space_id = H5Dget_space(dset_in)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); if((ftype_id = H5Dget_type(dset_in)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed"); if((dcpl_id = H5Dget_create_plist(dset_in)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed"); if((rank = H5Sget_simple_extent_ndims(space_id)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); if(H5Sget_simple_extent_dims(space_id, dims, NULL) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); nelmts = 1; for(k = 0; k < rank; k++) nelmts *= dims[k]; if((mtype_id = h5tools_get_native_type(ftype_id)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5tools_get_native_type failed"); if((msize = H5Tget_size(mtype_id)) == 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); /*------------------------------------------------------------------------- * check if the dataset creation property list has filters that @@ -168,19 +168,19 @@ int do_copy_refobjs(hid_t fidin, buf = (hobj_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf==NULL) { printf("cannot read into memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Dread(dset_in, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed"); refbuf = (hobj_ref_t*) HDcalloc((unsigned)nelmts, msize); if(refbuf == NULL){ printf("cannot allocate memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ for(u = 0; u < nelmts; u++) { H5E_BEGIN_TRY { - if((refobj_id = H5Rdereference(dset_in, H5R_OBJECT, &buf[u])) < 0) + if((refobj_id = H5Rdereference2(dset_in, H5P_DEFAULT, H5R_OBJECT, &buf[u])) < 0) continue; } H5E_END_TRY; @@ -190,7 +190,7 @@ int do_copy_refobjs(hid_t fidin, if((refname = MapIdToName(refobj_id, travt)) != NULL) { /* create the reference, -1 parameter for objects */ if(H5Rcreate(&refbuf[u], fidout, refname, H5R_OBJECT, (hid_t)-1) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed"); if(options->verbose) { printf(FORMAT_OBJ,"dset",travt->objs[i].name ); @@ -208,10 +208,10 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if((dset_out = H5Dcreate2(fidout, travt->objs[i].name, mtype_id, space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dcreate2 failed"); if(nelmts) if(H5Dwrite(dset_out, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, refbuf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dwrite failed"); if(buf) HDfree(buf); @@ -222,7 +222,7 @@ int do_copy_refobjs(hid_t fidin, * copy attrs *----------------------------------------------------*/ if(copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed"); } /*H5T_STD_REF_OBJ*/ /*------------------------------------------------------------------------- @@ -245,10 +245,10 @@ int do_copy_refobjs(hid_t fidin, buf = (hdset_reg_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf == NULL) { printf("cannot read into memory\n"); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Dread(dset_in, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed"); /*------------------------------------------------------------------------- * create output @@ -257,12 +257,12 @@ int do_copy_refobjs(hid_t fidin, refbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)nelmts); /*init to zero */ if(refbuf == NULL) { printf("cannot allocate memory\n"); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ for(u = 0; u < nelmts; u++) { H5E_BEGIN_TRY { - if((refobj_id = H5Rdereference(dset_in, H5R_DATASET_REGION, &buf[u])) < 0) + if((refobj_id = H5Rdereference2(dset_in, H5P_DEFAULT, H5R_DATASET_REGION, &buf[u])) < 0) continue; } H5E_END_TRY; @@ -273,18 +273,15 @@ int do_copy_refobjs(hid_t fidin, hid_t region_id; /* region id of the referenced dataset */ if((region_id = H5Rget_region(dset_in, H5R_DATASET_REGION, &buf[u])) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rget_region failed"); /* create the reference, we need the space_id */ if(H5Rcreate(&refbuf[u], fidout, refname, H5R_DATASET_REGION, region_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed"); if(H5Sclose(region_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(options->verbose) { - - - printf(FORMAT_OBJ,"dset",travt->objs[i].name ); printf("object <%s> region reference created to <%s>\n", travt->objs[i].name, @@ -300,10 +297,10 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if((dset_out = H5Dcreate2(fidout, travt->objs[i].name, mtype_id, space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dcreate2 failed"); if(nelmts) if(H5Dwrite(dset_out, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, refbuf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dwrite failed"); if(buf) HDfree(buf); @@ -314,7 +311,7 @@ int do_copy_refobjs(hid_t fidin, * copy attrs *----------------------------------------------------*/ if(copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed"); } /* H5T_STD_REF_DSETREG */ /*------------------------------------------------------------------------- * not references, open previously created object in 1st traversal @@ -322,7 +319,7 @@ int do_copy_refobjs(hid_t fidin, */ else { if((dset_out = H5Dopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); } /* end else */ HDassert(dset_out != FAIL); @@ -332,7 +329,7 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if(copy_refs_attr(dset_in, dset_out, options, travt, fidout) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_refs_attr failed"); /*------------------------------------------------------------------------- * check for hard links @@ -343,7 +340,7 @@ int do_copy_refobjs(hid_t fidin, H5Lcreate_hard(fidout, travt->objs[i].name, H5L_SAME_LOC, travt->objs[i].links[j].new_name, H5P_DEFAULT, H5P_DEFAULT); if(H5Dclose(dset_out) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); } /*can_read*/ /*------------------------------------------------------------------------- @@ -351,15 +348,15 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if(H5Tclose(ftype_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if(H5Tclose(mtype_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if(H5Pclose(dcpl_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); if(H5Sclose(space_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(H5Dclose(dset_in) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); break; /*------------------------------------------------------------------------- @@ -368,9 +365,9 @@ int do_copy_refobjs(hid_t fidin, */ case H5TRAV_TYPE_NAMED_DATATYPE: if((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Topen2 failed"); if(H5Tclose(type_in) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); break; /*------------------------------------------------------------------------- @@ -383,7 +380,7 @@ int do_copy_refobjs(hid_t fidin, case H5TRAV_TYPE_UNKNOWN: case H5TRAV_TYPE_UDLINK: - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5TRAV invalid type"); default: break; @@ -396,9 +393,9 @@ int do_copy_refobjs(hid_t fidin, */ named_datatype_free(&named_dt_head, 0); - return 0; + return ret_value; -error: +done: H5E_BEGIN_TRY { H5Gclose(grp_in); H5Gclose(grp_out); @@ -412,7 +409,7 @@ error: named_datatype_free(&named_dt_head, 0); } H5E_END_TRY; - return -1; + return ret_value; } @@ -450,6 +447,7 @@ static int copy_refs_attr(hid_t loc_in, hid_t fidout /* for saving references */ ) { + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ hid_t attr_id = -1; /* attr ID */ hid_t attr_out = -1; /* attr ID */ hid_t space_id = -1; /* space ID */ @@ -467,32 +465,32 @@ static int copy_refs_attr(hid_t loc_in, void *refbuf = NULL; void *buf = NULL; const char* refname = NULL; - int *ref_comp_index = NULL; + unsigned *ref_comp_index = NULL; size_t *ref_comp_size = NULL; int ref_comp_field_n = 0; if(H5Oget_info(loc_in, &oinfo) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Oget_info failed"); for(u = 0; u < (unsigned)oinfo.num_attrs; u++) { is_ref = is_ref_vlen = is_ref_array = is_ref_comp = 0; /* open attribute */ if((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx failed"); /* get the file datatype */ if((ftype_id = H5Aget_type(attr_id)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type failed"); type_class = H5Tget_class(ftype_id); if((mtype_id = h5tools_get_native_type(ftype_id)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5tools_get_native_type failed"); if((msize = H5Tget_size(mtype_id)) == 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); is_ref = (type_class == H5T_REFERENCE); @@ -516,10 +514,10 @@ static int copy_refs_attr(hid_t loc_in, int nmembers = H5Tget_nmembers(ftype_id) ; if (nmembers < 1) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); - ref_comp_index = (int *)HDmalloc(nmembers*sizeof (int)); - ref_comp_size = (size_t *)HDmalloc(nmembers*sizeof(ref_comp_size)); + ref_comp_index = (unsigned *)HDmalloc((size_t)nmembers*sizeof(unsigned)); + ref_comp_size = (size_t *)HDmalloc((size_t)nmembers*sizeof(ref_comp_size)); ref_comp_field_n = 0; for (i=0; i<(unsigned)nmembers; i++) { @@ -560,15 +558,15 @@ static int copy_refs_attr(hid_t loc_in, /* get name */ if(H5Aget_name(attr_id, 255, name) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_name failed"); /* get the dataspace handle */ if((space_id = H5Aget_space(attr_id)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_space failed"); /* get dimensions */ if((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); /*------------------------------------------------------------------------- @@ -580,8 +578,8 @@ static int copy_refs_attr(hid_t loc_in, nelmts *= dims[j]; if (is_ref_array) { - unsigned array_rank = 0; - hsize_t array_size = 1; + unsigned array_rank = 0; + hsize_t array_size = 1; hsize_t array_dims[H5S_MAX_RANK]; hid_t base_type; @@ -589,7 +587,7 @@ static int copy_refs_attr(hid_t loc_in, msize = H5Tget_size(base_type); H5Tclose(base_type); - array_rank = H5Tget_array_ndims(mtype_id); + array_rank = (unsigned)H5Tget_array_ndims(mtype_id); H5Tget_array_dims2(mtype_id, array_dims); for(j = 0; j <array_rank; j++) array_size *= array_dims[j]; @@ -597,7 +595,7 @@ static int copy_refs_attr(hid_t loc_in, } if((attr_out = H5Acreate2(loc_out, name, ftype_id, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Acreate2 failed"); if (nelmts>0) { /* handle object references */ @@ -605,15 +603,15 @@ static int copy_refs_attr(hid_t loc_in, buf = (hobj_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf == NULL) { printf("cannot read into memory\n"); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Aread(attr_id, mtype_id, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed"); refbuf = (hobj_ref_t *)HDcalloc((unsigned)nelmts, msize); if(refbuf == NULL) { printf("cannot allocate memory\n"); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ for(i = 0; i < (unsigned)nelmts; i++) { @@ -629,10 +627,10 @@ static int copy_refs_attr(hid_t loc_in, if(buf == NULL) { printf( "cannot read into memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Aread(attr_id, mtype_id, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed"); /*------------------------------------------------------------------------- * create output @@ -641,7 +639,7 @@ static int copy_refs_attr(hid_t loc_in, refbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)nelmts); /*init to zero */ if(refbuf == NULL) { printf( "cannot allocate memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ for(i = 0; i < (unsigned)nelmts; i++) { @@ -659,11 +657,11 @@ static int copy_refs_attr(hid_t loc_in, if(buf == NULL) { printf( "cannot read into memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Aread(attr_id, mtype_id, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed"); if (H5R_OBJ_REF_BUF_SIZE==msize) { hobj_ref_t ref_out; @@ -700,41 +698,43 @@ static int copy_refs_attr(hid_t loc_in, if(buf == NULL) { printf( "cannot read into memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Aread(attr_id, mtype_id, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed"); for (i=0; i<(unsigned)nelmts; i++) { - for (j=0; j<(unsigned)ref_comp_field_n; j++) { - if (ref_comp_size[j] == H5R_OBJ_REF_BUF_SIZE) { - int idx = i*msize+H5Tget_member_offset( mtype_id, (unsigned)ref_comp_index[j]); - hobj_ref_t ref_out; - if (update_ref_value(attr_id, H5R_OBJECT, (hobj_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0) - continue; - HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]); - } /* if */ - else if (ref_comp_size[j] == H5R_DSET_REG_REF_BUF_SIZE) { - int idx = i*msize+H5Tget_member_offset( mtype_id, (unsigned)ref_comp_index[j]); - hdset_reg_ref_t ref_out; - if (update_ref_value(attr_id, H5R_DATASET_REGION, (hdset_reg_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0) - continue; - HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]); - } /* else if */ - } /* j */ + for (j=0; j<(unsigned)ref_comp_field_n; j++) { + if (ref_comp_size[j] == H5R_OBJ_REF_BUF_SIZE) { + size_t idx = (i * msize) + H5Tget_member_offset(mtype_id, ref_comp_index[j]); + hobj_ref_t ref_out; + + if (update_ref_value(attr_id, H5R_OBJECT, (hobj_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0) + continue; + HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]); + } /* if */ + else if (ref_comp_size[j] == H5R_DSET_REG_REF_BUF_SIZE) { + size_t idx = i * msize + H5Tget_member_offset(mtype_id, ref_comp_index[j]); + hdset_reg_ref_t ref_out; + + if (update_ref_value(attr_id, H5R_DATASET_REGION, (hdset_reg_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0) + continue; + HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]); + } /* else if */ + } /* j */ } /* i */ } /* else if (is_ref_comp) */ if(H5Awrite(attr_out, mtype_id, refbuf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Awrite failed"); if (is_ref_vlen && buf) H5Dvlen_reclaim (mtype_id, space_id, H5P_DEFAULT, buf); } /* if (nelmts) */ if (refbuf == buf) - refbuf = NULL; /* set it to NULL to avoid double free since buf and refbuf are the same. */ + refbuf = NULL; /* set it to NULL to avoid double free since buf and refbuf are the same. */ if(buf) { HDfree(buf); @@ -747,39 +747,39 @@ static int copy_refs_attr(hid_t loc_in, } if (ref_comp_index) { - HDfree(ref_comp_index); - ref_comp_index = NULL; + HDfree(ref_comp_index); + ref_comp_index = NULL; } if (ref_comp_size) { - HDfree(ref_comp_size); - ref_comp_size = NULL; + HDfree(ref_comp_size); + ref_comp_size = NULL; } if(H5Aclose(attr_out) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed"); /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ if(H5Tclose(ftype_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if(H5Tclose(mtype_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if(H5Sclose(space_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(H5Aclose(attr_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed"); } /* for(u = 0; u < (unsigned)oinfo.num_attrs; u++) */ - return 0; + return ret_value; -error: - if(refbuf) - HDfree(refbuf); - if(buf) - HDfree(buf); +done: + if(refbuf) + HDfree(refbuf); + if(buf) + HDfree(buf); if (ref_comp_index) HDfree(ref_comp_index); @@ -795,7 +795,7 @@ error: H5Aclose(attr_out); } H5E_END_TRY; - return -1; + return ret_value; } /*------------------------------------------------------------------------- @@ -845,30 +845,26 @@ out: static herr_t update_ref_value(hid_t obj_id, H5R_type_t ref_type, void *ref_in, hid_t fid_out, void *ref_out, trav_table_t *travt) { - herr_t ret = -1; - const char* ref_obj_name; - hid_t space_id=-1, ref_obj_id=-1; - - ref_obj_id = H5Rdereference(obj_id, ref_type, ref_in); - if (ref_obj_id<0) - goto done; - - ref_obj_name = MapIdToName(ref_obj_id, travt); - if (ref_obj_name == NULL) - goto done; + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + const char* ref_obj_name; + hid_t space_id=-1, ref_obj_id=-1; - if (ref_type == H5R_DATASET_REGION) { - space_id = H5Rget_region(obj_id, H5R_DATASET_REGION, ref_in); - if (space_id < 0) - goto done; - } + ref_obj_id = H5Rdereference2(obj_id, H5P_DEFAULT, ref_type, ref_in); + if (ref_obj_id < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rdereference2 failed"); - ret = H5Rcreate(ref_out, fid_out, ref_obj_name, ref_type, space_id); + ref_obj_name = MapIdToName(ref_obj_id, travt); + if (ref_obj_name == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "MapIdToName failed"); - if (ret < 0) - goto done; + if (ref_type == H5R_DATASET_REGION) { + space_id = H5Rget_region(obj_id, H5R_DATASET_REGION, ref_in); + if (space_id < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rget_region failed"); + } - ret = 0; + if(H5Rcreate(ref_out, fid_out, ref_obj_name, ref_type, space_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed"); done: H5E_BEGIN_TRY { @@ -876,6 +872,6 @@ done: H5Oclose(ref_obj_id); } H5E_END_TRY; - return ret; + return ret_value; } |