summaryrefslogtreecommitdiffstats
path: root/src/H5G.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2007-11-24 19:28:15 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2007-11-24 19:28:15 (GMT)
commite4f62217b88a1ad842cd5f226c2729feb3b8c559 (patch)
treeecfb2a8ef1a4106cc32bb4c34aa7074281338c3f /src/H5G.c
parent2f36ea99d4ad1b036d377719e49eaab2dec64444 (diff)
downloadhdf5-e4f62217b88a1ad842cd5f226c2729feb3b8c559.zip
hdf5-e4f62217b88a1ad842cd5f226c2729feb3b8c559.tar.gz
hdf5-e4f62217b88a1ad842cd5f226c2729feb3b8c559.tar.bz2
[svn-r14285] Description:
Add H5Lvisit() API routine. Add explicit regression tests for H5Lvisit_by_name(). Correct error with visiting links when links contain loop to group already encountered. Tested on: FreeBSD/32 6.2 (duty) in debug mode FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Mac OS X/32 10.4.10 (amazon) in debug mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Diffstat (limited to 'src/H5G.c')
-rw-r--r--src/H5G.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/H5G.c b/src/H5G.c
index 116cdf8..675b166 100644
--- a/src/H5G.c
+++ b/src/H5G.c
@@ -1753,9 +1753,7 @@ H5G_visit_cb(const H5O_link_t *lnk, void *_udata)
/* Check for doing more work */
if(ret_value == H5_ITER_CONT && lnk->type == H5L_TYPE_HARD) {
- H5O_type_t otype; /* Basic object type (group, dataset, etc.) */
H5_obj_t obj_pos; /* Object "position" for this object */
- unsigned rc; /* Reference count of object */
/* Set up opened group location to fill in */
obj_loc.oloc = &obj_oloc;
@@ -1774,6 +1772,9 @@ H5G_visit_cb(const H5O_link_t *lnk, void *_udata)
/* Check if we've seen the object the link references before */
if(NULL == H5SL_search(udata->visited, &obj_pos)) {
+ H5O_type_t otype; /* Basic object type (group, dataset, etc.) */
+ unsigned rc; /* Reference count of object */
+
/* Get the object's reference count and type */
if(H5O_get_rc_and_type(&obj_oloc, udata->dxpl_id, &rc, &otype) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTGET, H5_ITER_ERROR, "unable to get object info")
@@ -1888,13 +1889,15 @@ H5G_visit(hid_t loc_id, const char *group_name, H5_index_t idx_type,
H5_iter_order_t order, H5L_iterate_t op, void *op_data, hid_t lapl_id,
hid_t dxpl_id)
{
- H5G_iter_visit_ud_t udata; /* User data for callback */
- H5O_linfo_t linfo; /* Link info message */
- hid_t gid = (-1); /* Group ID */
- H5G_t *grp = NULL; /* Group opened */
- H5G_loc_t loc; /* Location of group passed in */
- H5G_loc_t start_loc; /* Location of starting group */
- herr_t ret_value; /* Return value */
+ H5G_iter_visit_ud_t udata; /* User data for callback */
+ H5O_linfo_t linfo; /* Link info message */
+ hid_t gid = (-1); /* Group ID */
+ H5G_t *grp = NULL; /* Group opened */
+ H5G_loc_t loc; /* Location of group passed in */
+ H5G_loc_t start_loc; /* Location of starting group */
+ H5O_type_t otype; /* Basic object type (group, dataset, etc.) */
+ unsigned rc; /* Reference count of object */
+ herr_t ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5G_visit, FAIL)
@@ -1934,6 +1937,28 @@ H5G_visit(hid_t loc_id, const char *group_name, H5_index_t idx_type,
if((udata.visited = H5SL_create(H5SL_TYPE_OBJ, 0.5, (size_t)16)) == NULL)
HGOTO_ERROR(H5E_SYM, H5E_CANTCREATE, FAIL, "can't create skip list for visited objects")
+ /* Get the group's reference count and type */
+ if(H5O_get_rc_and_type(&grp->oloc, dxpl_id, &rc, &otype) < 0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "unable to get object info")
+
+ /* If its ref count is > 1, we add it to the list of visited objects */
+ /* (because it could come up again during traversal) */
+ if(rc > 1) {
+ H5_obj_t *obj_pos; /* New object node for visited list */
+
+ /* Allocate new object "position" node */
+ if((obj_pos = H5FL_MALLOC(H5_obj_t)) == NULL)
+ HGOTO_ERROR(H5E_SYM, H5E_NOSPACE, FAIL, "can't allocate object node")
+
+ /* Construct unique "position" for this object */
+ H5F_GET_FILENO(grp->oloc.file, obj_pos->fileno);
+ obj_pos->addr = grp->oloc.addr;
+
+ /* Add to list of visited objects */
+ if(H5SL_insert(udata.visited, obj_pos, obj_pos) < 0)
+ HGOTO_ERROR(H5E_SYM, H5E_CANTINSERT, FAIL, "can't insert object node into visited list")
+ } /* end if */
+
/* Attempt to get the link info for this group */
if(H5G_obj_get_linfo(&(grp->oloc), &linfo, dxpl_id)) {
/* Check for creation order tracking, if creation order index lookup requested */