summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2007-02-14 19:32:01 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2007-02-14 19:32:01 (GMT)
commit37a57858d5cf90799a637b80c5bf5d63dcc40fc7 (patch)
tree2b050d1679475077d814439aa7e5e25fe547e68c /src
parentefc45d5aab2fbdbad1f7bf494db91f9257a3285e (diff)
downloadhdf5-37a57858d5cf90799a637b80c5bf5d63dcc40fc7.zip
hdf5-37a57858d5cf90799a637b80c5bf5d63dcc40fc7.tar.gz
hdf5-37a57858d5cf90799a637b80c5bf5d63dcc40fc7.tar.bz2
[svn-r13304] Description:
Fix new API routines to use same pattern of arguments for specifying an object as the new H5G/L/O API routines. Tested on: Linux/32 2.6 (chicago)
Diffstat (limited to 'src')
-rw-r--r--src/H5A.c100
-rw-r--r--src/H5Apublic.h9
-rw-r--r--src/H5Gloc.c2
-rw-r--r--src/H5Gprivate.h2
4 files changed, 74 insertions, 39 deletions
diff --git a/src/H5A.c b/src/H5A.c
index 0c42dc6..4fd4a87 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -69,8 +69,8 @@ typedef struct H5A_iter_cb1 {
static hid_t H5A_create(const H5G_loc_t *loc, const char *name,
const H5T_t *type, const H5S_t *space, hid_t acpl_id, hid_t dxpl_id);
static herr_t H5A_open_common(const H5G_loc_t *loc, H5A_t *attr);
-static H5A_t *H5A_open_by_idx(H5G_loc_t *loc, H5_index_t idx_type,
- H5_iter_order_t order, hsize_t n, hid_t dxpl_id);
+static H5A_t *H5A_open_by_idx(const H5G_loc_t *loc, const char *obj_name,
+ H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t lapl_id, hid_t dxpl_id);
static H5A_t *H5A_open_by_name(const H5G_loc_t *loc, const char *name,
hid_t dxpl_id);
static herr_t H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id);
@@ -409,8 +409,9 @@ H5A_create(const H5G_loc_t *loc, const char *name, const H5T_t *type,
done:
/* Cleanup on failure */
- if(ret_value < 0 && attr)
- (void)H5A_close(attr);
+ if(ret_value < 0)
+ if(attr && H5A_close(attr) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
FUNC_LEAVE_NOAPI(ret_value)
} /* H5A_create() */
@@ -464,8 +465,9 @@ H5Aopen_name(hid_t loc_id, const char *name)
done:
/* Cleanup on failure */
- if(ret_value < 0 && attr)
- (void)H5A_close(attr);
+ if(ret_value < 0)
+ if(attr && H5A_close(attr) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
FUNC_LEAVE_API(ret_value)
} /* H5Aopen_name() */
@@ -478,7 +480,7 @@ done:
Opens the n'th attribute for an object
USAGE
hid_t H5Aopen_idx (loc_id, idx)
- hid_t loc_id; IN: Object (dataset or group) to be attached to
+ hid_t loc_id; IN: Object that attribute is attached to
unsigned idx; IN: Index (0-based) attribute to open
RETURNS
ID of attribute on success, negative on failure
@@ -508,7 +510,7 @@ H5Aopen_idx(hid_t loc_id, unsigned idx)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
/* Open the attribute in the object header */
- if(NULL == (attr = H5A_open_by_idx(&loc, H5_INDEX_NAME, H5_ITER_INC, (hsize_t)idx, H5AC_ind_dxpl_id)))
+ if(NULL == (attr = H5A_open_by_idx(&loc, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)idx, H5P_LINK_ACCESS_DEFAULT, H5AC_ind_dxpl_id)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open attribute")
/* Register the attribute and get an ID for it */
@@ -517,8 +519,9 @@ H5Aopen_idx(hid_t loc_id, unsigned idx)
done:
/* Cleanup on failure */
- if(ret_value < 0 && attr)
- (void)H5A_close(attr);
+ if(ret_value < 0)
+ if(attr && H5A_close(attr) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
FUNC_LEAVE_API(ret_value)
} /* H5Aopen_idx() */
@@ -584,14 +587,9 @@ done:
/*-------------------------------------------------------------------------
* Function: H5A_open_by_idx
*
- * Purpose:
- * Open an attribute according to its index order
- * Usage:
- * herr_t H5A_open (loc, idx)
- * const H5G_loc_t *loc; IN: Pointer to group location for object to open attribute
- * unsigned idx; IN: index of attribute to open (0-based)
+ * Purpose: Open an attribute according to its index order
*
- * Return: Non-negative on success/Negative on failure
+ * Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* April 2, 1998
@@ -599,9 +597,13 @@ done:
*-------------------------------------------------------------------------
*/
static H5A_t *
-H5A_open_by_idx(H5G_loc_t *loc, H5_index_t idx_type, H5_iter_order_t order,
- hsize_t n, hid_t dxpl_id)
+H5A_open_by_idx(const H5G_loc_t *loc, const char *obj_name, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t n, hid_t lapl_id, hid_t dxpl_id)
{
+ H5G_loc_t obj_loc; /* Location used to open group */
+ H5G_name_t obj_path; /* Opened object group hier. path */
+ H5O_loc_t obj_oloc; /* Opened object object location */
+ hbool_t loc_found = FALSE; /* Entry at 'obj_name' found */
H5A_t *attr = NULL;
H5A_t *ret_value; /* Return value */
@@ -609,23 +611,39 @@ H5A_open_by_idx(H5G_loc_t *loc, H5_index_t idx_type, H5_iter_order_t order,
/* check args */
HDassert(loc);
+ HDassert(obj_name);
+
+ /* Set up opened group location to fill in */
+ obj_loc.oloc = &obj_oloc;
+ obj_loc.path = &obj_path;
+ H5G_loc_reset(&obj_loc);
+
+ /* Find the object's location */
+ if(H5G_loc_find(loc, obj_name, &obj_loc/*out*/, lapl_id, dxpl_id) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, NULL, "object not found")
+ loc_found = TRUE;
/* Read in attribute from object header */
- if(NULL == (attr = H5O_attr_open_by_idx(loc->oloc, idx_type, order, n, dxpl_id)))
+ if(NULL == (attr = H5O_attr_open_by_idx(obj_loc.oloc, idx_type, order, n, dxpl_id)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "unable to load attribute info from object header")
attr->initialized = TRUE;
/* Finish initializing attribute */
- if(H5A_open_common(loc, attr) < 0)
+ if(H5A_open_common(&obj_loc, attr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, NULL, "unable to initialize attribute")
/* Set return value */
ret_value = attr;
done:
+ /* Release resources */
+ if(loc_found && H5G_loc_free(&obj_loc) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, NULL, "can't free location")
+
/* Cleanup on failure */
- if(ret_value == NULL && attr)
- (void)H5A_close(attr);
+ if(ret_value == NULL)
+ if(attr && H5A_close(attr) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, NULL, "can't close attribute")
FUNC_LEAVE_NOAPI(ret_value)
} /* H5A_open_by_idx() */
@@ -676,8 +694,9 @@ H5A_open_by_name(const H5G_loc_t *loc, const char *name, hid_t dxpl_id)
done:
/* Cleanup on failure */
- if(ret_value == NULL && attr)
- (void)H5A_close(attr);
+ if(ret_value == NULL)
+ if(attr && H5A_close(attr) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, NULL, "can't close attribute")
FUNC_LEAVE_NOAPI(ret_value)
} /* H5A_open_by_name() */
@@ -1221,8 +1240,9 @@ done:
*-------------------------------------------------------------------------
*/
ssize_t
-H5Aget_name_by_idx(hid_t loc_id, H5_index_t idx_type, H5_iter_order_t order,
- hsize_t n, char *name /*out*/, size_t size)
+H5Aget_name_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t n, char *name /*out*/, size_t size,
+ hid_t lapl_id)
{
H5G_loc_t loc; /* Object location */
H5A_t *attr = NULL; /* Attribute object for name */
@@ -1235,13 +1255,20 @@ H5Aget_name_by_idx(hid_t loc_id, H5_index_t idx_type, H5_iter_order_t order,
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
if(H5G_loc(loc_id, &loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
+ if(!obj_name || !*obj_name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
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(H5P_DEFAULT == lapl_id)
+ lapl_id = H5P_LINK_ACCESS_DEFAULT;
+ else
+ if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID")
/* Open the attribute on the object header */
- if(NULL == (attr = H5A_open_by_idx(&loc, idx_type, order, n, H5AC_ind_dxpl_id)))
+ if(NULL == (attr = H5A_open_by_idx(&loc, obj_name, idx_type, order, n, lapl_id, H5AC_ind_dxpl_id)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute")
/* Get the length of the name */
@@ -1397,8 +1424,8 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5Aget_info_by_idx(hid_t loc_id, H5_index_t idx_type, H5_iter_order_t order,
- hsize_t n, H5A_info_t *ainfo)
+H5Aget_info_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t n, H5A_info_t *ainfo, hid_t lapl_id)
{
H5G_loc_t loc; /* Object location */
H5A_t *attr = NULL; /* Attribute object for name */
@@ -1411,15 +1438,22 @@ H5Aget_info_by_idx(hid_t loc_id, H5_index_t idx_type, H5_iter_order_t order,
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
if(H5G_loc(loc_id, &loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
+ if(!obj_name || !*obj_name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
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(NULL == ainfo)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid info pointer")
+ if(H5P_DEFAULT == lapl_id)
+ lapl_id = H5P_LINK_ACCESS_DEFAULT;
+ else
+ if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID")
/* Open the attribute on the object header */
- if(NULL == (attr = H5A_open_by_idx(&loc, idx_type, order, n, H5AC_ind_dxpl_id)))
+ if(NULL == (attr = H5A_open_by_idx(&loc, obj_name, idx_type, order, n, lapl_id, H5AC_ind_dxpl_id)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute")
/* Get the attribute information */
@@ -1730,8 +1764,8 @@ H5A_copy(H5A_t *_new_attr, const H5A_t *old_attr)
done:
if(ret_value == NULL)
- if(new_attr != NULL && allocated_attr)
- (void)H5A_close(new_attr);
+ if(allocated_attr && new_attr && H5A_close(new_attr) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, NULL, "can't close attribute")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A_copy() */
diff --git a/src/H5Apublic.h b/src/H5Apublic.h
index bec794c..757f320 100644
--- a/src/H5Apublic.h
+++ b/src/H5Apublic.h
@@ -54,11 +54,12 @@ H5_DLL hid_t H5Aget_create_plist(hid_t attr_id);
H5_DLL ssize_t H5Aget_name(hid_t attr_id, size_t buf_size, char *buf);
H5_DLL hsize_t H5Aget_storage_size(hid_t attr_id);
H5_DLL herr_t H5Aget_info(hid_t loc_id, const char *name, H5A_info_t *ainfo /*out*/);
-H5_DLL herr_t H5Aget_info_by_idx(hid_t loc_id, H5_index_t idx_type,
- H5_iter_order_t order, hsize_t n, H5A_info_t *ainfo /*out*/);
-H5_DLL ssize_t H5Aget_name_by_idx(hid_t loc_id,
+H5_DLL herr_t H5Aget_info_by_idx(hid_t loc_id, const char *obj_name,
H5_index_t idx_type, H5_iter_order_t order, hsize_t n,
- char *name /*out*/, size_t size);
+ H5A_info_t *ainfo /*out*/, hid_t lapl_id);
+H5_DLL ssize_t H5Aget_name_by_idx(hid_t loc_id, const char *obj_name,
+ H5_index_t idx_type, H5_iter_order_t order, hsize_t n,
+ char *name /*out*/, size_t size, hid_t lapl_id);
H5_DLL herr_t H5Arename(hid_t loc_id, const char *old_name, const char *new_name);
H5_DLL herr_t H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op,
void *op_data);
diff --git a/src/H5Gloc.c b/src/H5Gloc.c
index d2a64e0..d447d20 100644
--- a/src/H5Gloc.c
+++ b/src/H5Gloc.c
@@ -379,7 +379,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5G_loc_find(H5G_loc_t *loc, const char *name, H5G_loc_t *obj_loc/*out*/,
+H5G_loc_find(const H5G_loc_t *loc, const char *name, H5G_loc_t *obj_loc/*out*/,
hid_t lapl_id, hid_t dxpl_id)
{
H5G_loc_fnd_t udata; /* User data for traversal callback */
diff --git a/src/H5Gprivate.h b/src/H5Gprivate.h
index 5d8a110..a432c4e 100644
--- a/src/H5Gprivate.h
+++ b/src/H5Gprivate.h
@@ -192,7 +192,7 @@ H5_DLL ssize_t H5G_get_refobj_name(hid_t fid, hid_t dxpl_id,
* These functions operate on group "locations"
*/
H5_DLL herr_t H5G_loc(hid_t loc_id, H5G_loc_t *loc);
-H5_DLL herr_t H5G_loc_find(H5G_loc_t *loc, const char *name,
+H5_DLL herr_t H5G_loc_find(const H5G_loc_t *loc, const char *name,
H5G_loc_t *obj_loc/*out*/, hid_t lapl_id, hid_t dxpl_id);
H5_DLL herr_t H5G_loc_find_by_idx(H5G_loc_t *loc, const char *group_name,
H5_index_t idx_type, H5_iter_order_t order, hsize_t n,