diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5repack/h5repack.c | 86 | ||||
-rw-r--r-- | tools/lib/h5diff_attr.c | 216 |
2 files changed, 133 insertions, 169 deletions
diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c index 0f16e87..8c46638 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -407,7 +407,7 @@ int copy_attr(hid_t loc_in, hid_t ftype_id=-1; /* file type ID */ hid_t wtype_id=-1; /* read/write type ID */ size_t msize; /* size of type */ - void *buf=NULL; /* data buffer */ + void *buf = NULL; /* data buffer */ hsize_t nelmts; /* number of elements in dataset */ int rank; /* rank of dataset */ htri_t is_named; /* Whether the datatype is named */ @@ -424,28 +424,23 @@ int copy_attr(hid_t loc_in, * copy all attributes *------------------------------------------------------------------------- */ - - for ( u = 0; u < (unsigned)oinfo.num_attrs; u++) - { - buf=NULL; - + for(u = 0; u < (unsigned)oinfo.num_attrs; u++) { /* 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; /* get name */ - if (H5Aget_name( attr_id, (size_t)255, name ) < 0) + if(H5Aget_name(attr_id, (size_t)255, name) < 0) goto error; /* get the file datatype */ - if ((ftype_id = H5Aget_type( attr_id )) < 0 ) + if((ftype_id = H5Aget_type(attr_id)) < 0 ) goto error; /* Check if the datatype is committed */ if((is_named = H5Tcommitted(ftype_id)) < 0) goto error; - if(is_named && travt) - { + if(is_named && travt) { hid_t fidout; /* Create out file id */ @@ -462,29 +457,28 @@ int copy_attr(hid_t loc_in, if(H5Fclose(fidout) < 0) goto error; - } - else - { - if (options->use_native==1) + } /* end if */ + else { + if(options->use_native == 1) wtype_id = h5tools_get_native_type(ftype_id); else wtype_id = H5Tcopy(ftype_id); - } /* end if */ + } /* end else */ /* get the dataspace handle */ - if ((space_id = H5Aget_space( attr_id )) < 0 ) + if((space_id = H5Aget_space(attr_id)) < 0) goto error; /* get dimensions */ - if ( (rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0 ) + if((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0) goto error; - nelmts=1; - for (j=0; j<rank; j++) - nelmts*=dims[j]; + nelmts = 1; + for(j = 0; j < rank; j++) + nelmts *= dims[j]; - if ((msize=H5Tget_size(wtype_id))==0) + if((msize = H5Tget_size(wtype_id)) == 0) goto error; /*------------------------------------------------------------------------- @@ -495,23 +489,20 @@ int copy_attr(hid_t loc_in, *------------------------------------------------------------------------- */ - if (H5T_REFERENCE==H5Tget_class(wtype_id)) - { + if(H5T_REFERENCE == H5Tget_class(wtype_id)) { ; } - else - { + else { /*------------------------------------------------------------------------- * read to memory *------------------------------------------------------------------------- */ buf = (void *)HDmalloc((size_t)(nelmts * msize)); - if(buf == NULL) - { + if(buf == NULL) { error_msg("h5repack", "cannot read into memory\n" ); goto error; - } + } /* end if */ if(H5Aread(attr_id, wtype_id, buf) < 0) goto error; @@ -529,10 +520,12 @@ int copy_attr(hid_t loc_in, if(H5Aclose(attr_out) < 0) goto error; - - if(buf) - free(buf); - + /* Check if we have VL data in the attribute's datatype that must + * be reclaimed */ + if(TRUE == H5Tdetect_class(wtype_id, H5T_VLEN)) + H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf); + HDfree(buf); + buf = NULL; } /*H5T_REFERENCE*/ @@ -544,28 +537,39 @@ int copy_attr(hid_t loc_in, *------------------------------------------------------------------------- */ - if (H5Tclose(ftype_id) < 0) goto error; - if (H5Tclose(wtype_id) < 0) goto error; - if (H5Sclose(space_id) < 0) goto error; - if (H5Aclose(attr_id) < 0) goto error; - + if(H5Tclose(ftype_id) < 0) + goto error; + if(H5Tclose(wtype_id) < 0) + goto error; + if(H5Sclose(space_id) < 0) + goto error; + if(H5Aclose(attr_id) < 0) + goto error; } /* u */ - return 0; error: H5E_BEGIN_TRY { + if(buf) { + /* Check if we have VL data in the attribute's datatype that must + * be reclaimed */ + if(TRUE == H5Tdetect_class(wtype_id, H5T_VLEN)) + H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf); + + /* Free buf */ + free(buf); + } /* end if */ + H5Tclose(ftype_id); H5Tclose(wtype_id); H5Sclose(space_id); H5Aclose(attr_id); H5Aclose(attr_out); - if (buf) - free(buf); } H5E_END_TRY; + return -1; -} +} /* end copy_attr() */ /*------------------------------------------------------------------------- * Function: check_options diff --git a/tools/lib/h5diff_attr.c b/tools/lib/h5diff_attr.c index 2cf6539..ad6f45b 100644 --- a/tools/lib/h5diff_attr.c +++ b/tools/lib/h5diff_attr.c @@ -79,8 +79,7 @@ hsize_t diff_attr(hid_t loc1_id, if(oinfo1.num_attrs != oinfo2.num_attrs) return 1; - for( u = 0; u < (unsigned)oinfo1.num_attrs; u++) - { + for(u = 0; u < (unsigned)oinfo1.num_attrs; u++) { /* reset buffers for every attribute, we might goto out and call free */ buf1 = NULL; buf2 = NULL; @@ -104,29 +103,29 @@ hsize_t diff_attr(hid_t loc1_id, goto error; /* get the datatypes */ - if ((ftype1_id = H5Aget_type(attr1_id)) < 0) + if((ftype1_id = H5Aget_type(attr1_id)) < 0) goto error; - if ((ftype2_id = H5Aget_type(attr2_id)) < 0) + if((ftype2_id = H5Aget_type(attr2_id)) < 0) goto error; - if ((mtype1_id = h5tools_get_native_type(ftype1_id))<0) + if((mtype1_id = h5tools_get_native_type(ftype1_id))<0) goto error; - if ((mtype2_id = h5tools_get_native_type(ftype2_id))<0) + if((mtype2_id = h5tools_get_native_type(ftype2_id))<0) goto error; - if ((msize1 = H5Tget_size(mtype1_id))==0) + if((msize1 = H5Tget_size(mtype1_id))==0) goto error; - if ((msize2 = H5Tget_size(mtype2_id))==0) + if((msize2 = H5Tget_size(mtype2_id))==0) goto error; /* get the dataspace */ - if ((space1_id = H5Aget_space(attr1_id)) < 0) + if((space1_id = H5Aget_space(attr1_id)) < 0) goto error; - if ((space2_id = H5Aget_space(attr2_id)) < 0) + if((space2_id = H5Aget_space(attr2_id)) < 0) goto error; /* get dimensions */ - if ( (rank1 = H5Sget_simple_extent_dims(space1_id, dims1, NULL)) < 0 ) + if((rank1 = H5Sget_simple_extent_dims(space1_id, dims1, NULL)) < 0) goto error; - if ( (rank2 = H5Sget_simple_extent_dims(space2_id, dims2, NULL)) < 0 ) + if((rank2 = H5Sget_simple_extent_dims(space2_id, dims2, NULL)) < 0) goto error; @@ -135,43 +134,28 @@ hsize_t diff_attr(hid_t loc1_id, *---------------------------------------------------------------------- */ - if ( msize1 != msize2 - || - diff_can_type(ftype1_id, - ftype2_id, - rank1, - rank2, - dims1, - dims2, - NULL, - NULL, - name1, - name2, - options, - 0)!=1) + if(msize1 != msize2 || + diff_can_type(ftype1_id, ftype2_id, rank1, rank2, dims1, + dims2, NULL, NULL, name1, name2, options, 0) != 1) { - - - if (H5Tclose(ftype1_id)<0) + if(H5Tclose(ftype1_id) < 0) goto error; - if (H5Tclose(ftype2_id)<0) + if(H5Tclose(ftype2_id) < 0) goto error; - if (H5Sclose(space1_id)<0) + if(H5Sclose(space1_id) < 0) goto error; - if (H5Sclose(space2_id)<0) + if(H5Sclose(space2_id) < 0) goto error; - if (H5Aclose(attr1_id)<0) + if(H5Aclose(attr1_id) < 0) goto error; - if (H5Aclose(attr2_id)<0) + if(H5Aclose(attr2_id) < 0) goto error; - if (H5Tclose(mtype1_id)<0) + if(H5Tclose(mtype1_id) < 0) goto error; - if (H5Tclose(mtype2_id)<0) + if(H5Tclose(mtype2_id) < 0) goto error; continue; - - } @@ -179,19 +163,19 @@ hsize_t diff_attr(hid_t loc1_id, * read *---------------------------------------------------------------------- */ - nelmts1=1; - for (j=0; j<rank1; j++) - nelmts1*=dims1[j]; + nelmts1 = 1; + for(j = 0; j < rank1; j++) + nelmts1 *= dims1[j]; - buf1=(void *) HDmalloc((unsigned)(nelmts1*msize1)); - buf2=(void *) HDmalloc((unsigned)(nelmts1*msize2)); - if ( buf1==NULL || buf2==NULL){ + buf1 = (void *)HDmalloc((unsigned)(nelmts1 * msize1)); + buf2 = (void *)HDmalloc((unsigned)(nelmts1 * msize2)); + if(buf1 == NULL || buf2 == NULL) { parallel_print( "cannot read into memory\n" ); goto error; } - if (H5Aread(attr1_id,mtype1_id,buf1)<0) + if(H5Aread(attr1_id,mtype1_id,buf1) < 0) goto error; - if (H5Aread(attr2_id,mtype2_id,buf2)<0) + if(H5Aread(attr2_id,mtype2_id,buf2) < 0) goto error; /* format output string */ @@ -205,63 +189,29 @@ hsize_t diff_attr(hid_t loc1_id, /* always print name */ /* verbose (-v) and report (-r) mode */ - if(options->m_verbose || options->m_report) - { - do_print_objname ("attribute", np1, np2); - nfound = diff_array(buf1, - buf2, - nelmts1, - (hsize_t)0, - rank1, - dims1, - options, - np1, - np2, - mtype1_id, - attr1_id, - attr2_id); - print_found(nfound); + if(options->m_verbose || options->m_report) { + do_print_objname("attribute", np1, np2); + nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, + options, np1, np2, mtype1_id, attr1_id, attr2_id); + print_found(nfound); } /* quiet mode (-q), just count differences */ - else if(options->m_quiet) - { - nfound = diff_array(buf1, - buf2, - nelmts1, - (hsize_t)0, - rank1, - dims1, - options, - np1, - np2, - mtype1_id, - attr1_id, - attr2_id); + else if(options->m_quiet) { + nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, + options, np1, np2, mtype1_id, attr1_id, attr2_id); } /* the rest (-c, none, ...) */ - else - { - nfound = diff_array(buf1, - buf2, - nelmts1, - (hsize_t)0, - rank1, - dims1, - options, - np1, - np2, - mtype1_id, - attr1_id, - attr2_id); + else { + nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, + options, np1, np2, mtype1_id, attr1_id, attr2_id); /* not comparable, no display the different number */ - if (!options->not_cmp && nfound) - { - do_print_objname ("attribute", np1, np2); + if(!options->not_cmp && nfound) { + do_print_objname("attribute", np1, np2); print_found(nfound); - } - } + } /* end if */ + } /* end else */ /*---------------------------------------------------------------------- @@ -269,51 +219,61 @@ hsize_t diff_attr(hid_t loc1_id, *---------------------------------------------------------------------- */ - if (H5Tclose(ftype1_id)<0) + /* Free buf1 and buf2, being careful to reclaim any VL data first */ + if(TRUE == H5Tdetect_class(mtype1_id, H5T_VLEN)) + H5Dvlen_reclaim(mtype1_id, space1_id, H5P_DEFAULT, buf1); + HDfree(buf1); + buf1 = NULL; + if(TRUE == H5Tdetect_class(mtype2_id, H5T_VLEN)) + H5Dvlen_reclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2); + HDfree(buf2); + buf2 = NULL; + + if(H5Tclose(ftype1_id) < 0) goto error; - if (H5Tclose(ftype2_id)<0) + if(H5Tclose(ftype2_id) < 0) goto error; - if (H5Sclose(space1_id)<0) + if(H5Sclose(space1_id) < 0) goto error; - if (H5Sclose(space2_id)<0) + if(H5Sclose(space2_id) < 0) goto error; - if (H5Aclose(attr1_id)<0) + if(H5Aclose(attr1_id) < 0) goto error; - if (H5Aclose(attr2_id)<0) + if(H5Aclose(attr2_id) < 0) goto error; - if (H5Tclose(mtype1_id)<0) + if(H5Tclose(mtype1_id) < 0) goto error; - if (H5Tclose(mtype2_id)<0) + if(H5Tclose(mtype2_id) < 0) goto error; - if (buf1) - HDfree(buf1); - if (buf2) - HDfree(buf2); - nfound_total += nfound; - } /* u */ + } /* u */ - return nfound_total; + return nfound_total; error: - H5E_BEGIN_TRY { - H5Tclose(ftype1_id); - H5Tclose(ftype2_id); - H5Tclose(mtype1_id); - H5Tclose(mtype2_id); - H5Sclose(space1_id); - H5Sclose(space2_id); - H5Aclose(attr1_id); - H5Aclose(attr2_id); - if (buf1) - HDfree(buf1); - if (buf2) - HDfree(buf2); - } H5E_END_TRY; - - options->err_stat=1; - return nfound_total; + H5E_BEGIN_TRY { + if(buf1) { + if(TRUE == H5Tdetect_class(mtype1_id, H5T_VLEN)) + H5Dvlen_reclaim(mtype1_id, space1_id, H5P_DEFAULT, buf1); + HDfree(buf1); + } /* end if */ + if(buf2) { + if(TRUE == H5Tdetect_class(mtype2_id, H5T_VLEN)) + H5Dvlen_reclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2); + HDfree(buf2); + } /* end if */ + H5Tclose(ftype1_id); + H5Tclose(ftype2_id); + H5Tclose(mtype1_id); + H5Tclose(mtype2_id); + H5Sclose(space1_id); + H5Sclose(space2_id); + H5Aclose(attr1_id); + H5Aclose(attr2_id); + } H5E_END_TRY; + + options->err_stat = 1; + return nfound_total; } - |