summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/H5G.c43
-rw-r--r--src/H5L.c58
-rw-r--r--src/H5Lpublic.h2
3 files changed, 94 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 */
diff --git a/src/H5L.c b/src/H5L.c
index 9917fe7..d50ae19 100644
--- a/src/H5L.c
+++ b/src/H5L.c
@@ -1259,6 +1259,64 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5Lvisit
+ *
+ * Purpose: Recursively visit all the links in a group and all
+ * the groups that are linked to from that group. Links within
+ * each group are visited according to the order within the
+ * specified index (unless the specified index does not exist for
+ * a particular group, then the "name" index is used).
+ *
+ * NOTE: Each _link_ reachable from the initial group will only be
+ * visited once. However, because an object may be reached from
+ * more than one link, the visitation may call the application's
+ * callback with more than one link that points to a particular
+ * _object_.
+ *
+ * Return: Success: The return value of the first operator that
+ * returns non-zero, or zero if all members were
+ * processed with no operator returning non-zero.
+ *
+ * Failure: Negative if something goes wrong within the
+ * library, or the negative value returned by one
+ * of the operators.
+ *
+ * Programmer: Quincey Koziol
+ * November 24 2007
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5Lvisit(hid_t grp_id, H5_index_t idx_type, H5_iter_order_t order,
+ H5L_iterate_t op, void *op_data)
+{
+ H5I_type_t id_type; /* Type of ID */
+ herr_t ret_value; /* Return value */
+
+ FUNC_ENTER_API(H5Lvisit, FAIL)
+ H5TRACE5("e", "iIiIox*x", grp_id, idx_type, order, op, op_data);
+
+ /* Check args */
+ id_type = H5I_get_type(grp_id);
+ if(!(H5I_GROUP == id_type || H5I_FILE == id_type))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid argument")
+ if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified")
+ if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid iteration order specified")
+ if(!op)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no callback operator specified")
+
+ /* Call internal group visitation routine */
+ if((ret_value = H5G_visit(grp_id, ".", idx_type, order, op, op_data, H5P_DEFAULT, H5AC_ind_dxpl_id)) < 0)
+ HGOTO_ERROR(H5E_SYM, H5E_BADITER, FAIL, "link visitation failed")
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* end H5Lvisit() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5Lvisit_by_name
*
* Purpose: Recursively visit all the links in a group and all
diff --git a/src/H5Lpublic.h b/src/H5Lpublic.h
index 0dc3f65..823b046 100644
--- a/src/H5Lpublic.h
+++ b/src/H5Lpublic.h
@@ -170,6 +170,8 @@ H5_DLL herr_t H5Literate(hid_t grp_id, H5_index_t idx_type,
H5_DLL herr_t H5Literate_by_name(hid_t loc_id, const char *group_name,
H5_index_t idx_type, H5_iter_order_t order, hsize_t *idx,
H5L_iterate_t op, void *op_data, hid_t lapl_id);
+H5_DLL herr_t H5Lvisit(hid_t grp_id, H5_index_t idx_type, H5_iter_order_t order,
+ H5L_iterate_t op, void *op_data);
H5_DLL herr_t H5Lvisit_by_name(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);