summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-02-20 04:29:08 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-02-20 04:29:08 (GMT)
commit2bcb812832616669fc2b34dba25e32f6304b5c46 (patch)
tree86fe443eb4f925bf5afb6662c1007b10d3b6435f
parent0c39a78927ae1e4b7471f96743a8cf5dd30350b0 (diff)
downloadhdf5-2bcb812832616669fc2b34dba25e32f6304b5c46.zip
hdf5-2bcb812832616669fc2b34dba25e32f6304b5c46.tar.gz
hdf5-2bcb812832616669fc2b34dba25e32f6304b5c46.tar.bz2
[svn-r18302] Description:
Tweak allocation of attribute tables created from densely stored attributes to allow for better cleanup on errors (like when the type of corruption from Bz#1755 is encountered). Also, add some code to h5dump to display an error message when the attribute iteration for an object fails. Tested on: FreeBSD/32 6.3 (duty) in debug mode FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (amani) w/Intel compilers, w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode Mac OS X/32 10.6.2 (amazon) in debug mode Mac OS X/32 10.6.2 (amazon) w/C++ & FORTRAN, w/threadsafe, in production mode
-rw-r--r--src/H5Aint.c23
-rw-r--r--tools/h5dump/h5dump.c112
2 files changed, 93 insertions, 42 deletions
diff --git a/src/H5Aint.c b/src/H5Aint.c
index 2915502..63f7e60 100644
--- a/src/H5Aint.c
+++ b/src/H5Aint.c
@@ -269,6 +269,10 @@ H5A_dense_build_table_cb(const H5A_t *attr, void *_udata)
HDassert(udata);
HDassert(udata->curr_attr < udata->atable->nattrs);
+ /* Allocate attribute for entry in the table */
+ if(NULL == (udata->atable->attrs[udata->curr_attr] = H5FL_CALLOC(H5A_t)))
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTALLOC, H5_ITER_ERROR, "can't allocate attribute")
+
/* Copy attribute information. Share the attribute object in copying. */
if(NULL == H5A_copy(udata->atable->attrs[udata->curr_attr], attr))
HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "can't copy attribute")
@@ -333,17 +337,11 @@ H5A_dense_build_table(H5F_t *f, hid_t dxpl_id, const H5O_ainfo_t *ainfo,
if(atable->nattrs > 0) {
H5A_dense_bt_ud_t udata; /* User data for iteration callback */
H5A_attr_iter_op_t attr_op; /* Attribute operator */
- unsigned i;
/* Allocate the table to store the attributes */
- if((atable->attrs = (H5A_t **)H5FL_SEQ_MALLOC(H5A_t_ptr, atable->nattrs)) == NULL)
+ if((atable->attrs = (H5A_t **)H5FL_SEQ_CALLOC(H5A_t_ptr, atable->nattrs)) == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
- /* Allocate pointers for each entry in the table */
- for(i=0; i<atable->nattrs; i++)
- if((atable->attrs[i] = (H5A_t *)H5FL_CALLOC(H5A_t)) == NULL)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
-
/* Set up user data for iteration */
udata.atable = atable;
udata.curr_attr = 0;
@@ -638,15 +636,11 @@ done:
* Programmer: Quincey Koziol
* Dec 11, 2006
*
- * Modification: Raymond Lu
- * 4 June 2008
- * Changed from H5A_free to H5A_close to release attributes.
*-------------------------------------------------------------------------
*/
herr_t
H5A_attr_release_table(H5A_attr_table_t *atable)
{
- size_t u; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5A_attr_release_table)
@@ -656,11 +650,12 @@ H5A_attr_release_table(H5A_attr_table_t *atable)
/* Release attribute info, if any. */
if(atable->nattrs > 0) {
+ size_t u; /* Local index variable */
+
/* Free attribute message information */
- for(u = 0; u < atable->nattrs; u++) {
- if(H5A_close((atable->attrs[u])) < 0)
+ for(u = 0; u < atable->nattrs; u++)
+ if(atable->attrs[u] && H5A_close(atable->attrs[u]) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "unable to release attribute")
- }
} /* end if */
else
HDassert(atable->attrs == NULL);
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index 3af66ee..3156ba6 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -2005,10 +2005,18 @@ dump_named_datatype(hid_t tid, const char *name)
/* attribute iteration: if there is a request to do H5_INDEX_CRT_ORDER and tracking order is set
in the datatype's create property list for attributes, then, sort by creation order, otherwise by name */
- if( (sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED))
- H5Aiterate2(tid, sort_by, sort_order, NULL, dump_attr_cb, NULL);
- else
- H5Aiterate2(tid, H5_INDEX_NAME, sort_order, NULL, dump_attr_cb, NULL);
+ if( (sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
+ if(H5Aiterate2(tid, sort_by, sort_order, NULL, dump_attr_cb, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end if */
+ else {
+ if(H5Aiterate2(tid, H5_INDEX_NAME, sort_order, NULL, dump_attr_cb, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end else */
indent -= COL;
@@ -2123,10 +2131,18 @@ dump_group(hid_t gid, const char *name)
/* attribute iteration: if there is a request to do H5_INDEX_CRT_ORDER and tracking order is set
in the group for attributes, then, sort by creation order, otherwise by name */
- if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED))
- H5Aiterate2(gid, sort_by, sort_order, NULL, dump_attr_cb, NULL);
- else
- H5Aiterate2(gid, H5_INDEX_NAME, sort_order, NULL, dump_attr_cb, NULL);
+ if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
+ if(H5Aiterate2(gid, sort_by, sort_order, NULL, dump_attr_cb, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end if */
+ else {
+ if(H5Aiterate2(gid, H5_INDEX_NAME, sort_order, NULL, dump_attr_cb, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end else */
/* if there is a request to do H5_INDEX_CRT_ORDER and tracking order is set
in the group, then, sort by creation order, otherwise by name */
@@ -2146,10 +2162,18 @@ dump_group(hid_t gid, const char *name)
/* attribute iteration: if there is a request to do H5_INDEX_CRT_ORDER and tracking order is set
in the group for attributes, then, sort by creation order, otherwise by name */
- if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED))
- H5Aiterate2(gid, sort_by, sort_order, NULL, dump_attr_cb, NULL);
- else
- H5Aiterate2(gid, H5_INDEX_NAME, sort_order, NULL, dump_attr_cb, NULL);
+ if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
+ if(H5Aiterate2(gid, sort_by, sort_order, NULL, dump_attr_cb, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end if */
+ else {
+ if(H5Aiterate2(gid, H5_INDEX_NAME, sort_order, NULL, dump_attr_cb, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end else */
/* if there is a request to do H5_INDEX_CRT_ORDER and tracking order is set
in the group, then, sort by creation order, otherwise by name */
@@ -2254,10 +2278,18 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset)
/* attribute iteration: if there is a request to do H5_INDEX_CRT_ORDER and tracking order is set
in the group for attributes, then, sort by creation order, otherwise by name */
- if( (sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED))
- H5Aiterate2(did, sort_by, sort_order, NULL, dump_attr_cb, NULL);
- else
- H5Aiterate2(did, H5_INDEX_NAME, sort_order, NULL, dump_attr_cb, NULL);
+ if( (sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
+ if(H5Aiterate2(did, sort_by, sort_order, NULL, dump_attr_cb, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end if */
+ else {
+ if(H5Aiterate2(did, H5_INDEX_NAME, sort_order, NULL, dump_attr_cb, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end else */
}
@@ -5876,10 +5908,18 @@ xml_dump_group(hid_t gid, const char *name)
/* 1. do all the attributes of the group */
- if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED))
- H5Aiterate2(gid, sort_by, sort_order, NULL, dump_function_table->dump_attribute_function, NULL);
- else
- H5Aiterate2(gid, H5_INDEX_NAME, sort_order, NULL, dump_function_table->dump_attribute_function, NULL);
+ if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
+ if(H5Aiterate2(gid, sort_by, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end if */
+ else {
+ if(H5Aiterate2(gid, H5_INDEX_NAME, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end else */
if(isRoot && unamedtype) {
unsigned u;
@@ -5940,10 +5980,18 @@ xml_dump_group(hid_t gid, const char *name)
/* 1. do all the attributes of the group */
- if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED))
- H5Aiterate2(gid, sort_by, sort_order, NULL, dump_function_table->dump_attribute_function, NULL);
- else
- H5Aiterate2(gid, H5_INDEX_NAME, sort_order, NULL, dump_function_table->dump_attribute_function, NULL);
+ if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
+ if(H5Aiterate2(gid, sort_by, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end if */
+ else {
+ if(H5Aiterate2(gid, H5_INDEX_NAME, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end else */
if(isRoot && unamedtype) {
@@ -6598,10 +6646,18 @@ xml_dump_dataset(hid_t did, const char *name, struct subset_t UNUSED * sset)
indent += COL;
- if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED))
- H5Aiterate2(did, sort_by, sort_order, NULL, dump_function_table->dump_attribute_function, NULL);
- else
- H5Aiterate2(did, H5_INDEX_NAME, sort_order, NULL, dump_function_table->dump_attribute_function, NULL);
+ if((sort_by == H5_INDEX_CRT_ORDER) && (attr_crt_order_flags & H5P_CRT_ORDER_TRACKED)) {
+ if(H5Aiterate2(did, sort_by, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end if */
+ else {
+ if(H5Aiterate2(did, H5_INDEX_NAME, sort_order, NULL, dump_function_table->dump_attribute_function, NULL) < 0) {
+ error_msg(progname, "error getting attribute information\n");
+ d_status = EXIT_FAILURE;
+ } /* end if */
+ } /* end else */
indent -= COL;
tempi = H5Dget_storage_size(did);