summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5Aint.c31
-rw-r--r--src/H5Apkg.h3
-rw-r--r--src/H5F.c6
-rw-r--r--src/H5Gobj.c4
-rw-r--r--src/H5O.c3
-rw-r--r--src/H5Oattribute.c238
-rw-r--r--src/H5Opkg.h3
-rw-r--r--src/H5Oprivate.h3
-rw-r--r--src/H5Otest.c37
9 files changed, 182 insertions, 146 deletions
diff --git a/src/H5Aint.c b/src/H5Aint.c
index fac0110..c7013a2 100644
--- a/src/H5Aint.c
+++ b/src/H5Aint.c
@@ -680,8 +680,8 @@ done:
* Purpose: Retrieves the "attribute info" message for an object. Also
* sets the number of attributes correctly, if it isn't set up yet.
*
- * Return: Success: Ptr to message in native format.
- * Failure: NULL
+ * Return: Success: TRUE/FALSE whether message was found & retrieved
+ * Failure: FAIL if error occurred
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
@@ -689,35 +689,40 @@ done:
*
*-------------------------------------------------------------------------
*/
-H5O_ainfo_t *
+htri_t
H5A_get_ainfo(H5F_t *f, hid_t dxpl_id, H5O_t *oh, H5O_ainfo_t *ainfo)
{
- H5O_ainfo_t *ret_value; /* Return value */
+ htri_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5A_get_ainfo, NULL)
+ FUNC_ENTER_NOAPI(H5A_get_ainfo, FAIL)
/* check arguments */
HDassert(f);
HDassert(oh);
+ HDassert(ainfo);
+
+ /* Check if the "attribute info" message exists */
+ if((ret_value = H5O_msg_exists_oh(oh, H5O_AINFO_ID)) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "unable to check object header")
+ if(ret_value > 0) {
+ /* Retrieve the "attribute info" structure */
+ if(NULL == H5O_msg_read_oh(f, dxpl_id, oh, H5O_AINFO_ID, ainfo))
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't read AINFO message")
- /* Retrieve the "attribute info" structure */
- if((ret_value = (H5O_ainfo_t *)H5O_msg_read_oh(f, dxpl_id, oh, H5O_AINFO_ID, ainfo))) {
/* Check if we don't know how many attributes there are */
- if(ret_value->nattrs == HSIZET_MAX) {
+ if(ainfo->nattrs == HSIZET_MAX) {
/* Check if we are using "dense" attribute storage */
- if(H5F_addr_defined(ret_value->fheap_addr)) {
+ if(H5F_addr_defined(ainfo->fheap_addr)) {
/* Retrieve # of records in "name" B-tree */
/* (should be same # of records in all indices) */
- if(H5B2_get_nrec(f, dxpl_id, H5A_BT2_NAME, ret_value->name_bt2_addr, &ret_value->nattrs) < 0)
+ if(H5B2_get_nrec(f, dxpl_id, H5A_BT2_NAME, ainfo->name_bt2_addr, &ainfo->nattrs) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "can't retrieve # of records in index")
} /* end if */
else
/* Retrieve # of attributes from object header */
- ret_value->nattrs = oh->attr_msgs_seen;
+ ainfo->nattrs = oh->attr_msgs_seen;
} /* end if */
} /* end if */
- else
- HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "attribute info message not present")
done:
FUNC_LEAVE_NOAPI(ret_value)
diff --git a/src/H5Apkg.h b/src/H5Apkg.h
index afe82b8..b166b06 100644
--- a/src/H5Apkg.h
+++ b/src/H5Apkg.h
@@ -218,8 +218,7 @@ H5_DLL H5A_t *H5A_copy(H5A_t *new_attr, const H5A_t *old_attr);
H5_DLL herr_t H5A_get_info(const H5A_t *attr, H5A_info_t *ainfo);
H5_DLL herr_t H5A_free(H5A_t *attr);
H5_DLL herr_t H5A_close(H5A_t *attr);
-H5_DLL H5O_ainfo_t *H5A_get_ainfo(H5F_t *f, hid_t dxpl_id, H5O_t *oh,
- H5O_ainfo_t *ainfo);
+H5_DLL htri_t H5A_get_ainfo(H5F_t *f, hid_t dxpl_id, H5O_t *oh, H5O_ainfo_t *ainfo);
H5_DLL herr_t H5A_set_version(const H5F_t *f, H5A_t *attr);
/* Attribute "dense" storage routines */
diff --git a/src/H5F.c b/src/H5F.c
index 14efa63..7b9ce79 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -428,7 +428,7 @@ H5F_get_obj_count(const H5F_t *f, unsigned types, hbool_t app_ref)
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_get_obj_count)
/* H5F_get_objects doesn't fail */
- ret_value=H5F_get_objects(f, types, 0, NULL, app_ref);
+ ret_value = H5F_get_objects(f, types, 0, NULL, app_ref);
FUNC_LEAVE_NOAPI(ret_value)
}
@@ -518,8 +518,6 @@ H5F_get_obj_ids(const H5F_t *f, unsigned types, size_t max_objs, hid_t *oid_list
* Programmer: Raymond Lu
* Wednesday, Dec 5, 2001
*
- * Modification:
- *
*---------------------------------------------------------------------------
*/
static size_t
@@ -587,7 +585,7 @@ H5F_get_objects(const H5F_t *f, unsigned types, size_t max_index, hid_t *obj_id_
ret_value = obj_id_count;
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5F_get_objects() */
/*-------------------------------------------------------------------------
diff --git a/src/H5Gobj.c b/src/H5Gobj.c
index a6b2d7f..3220b67 100644
--- a/src/H5Gobj.c
+++ b/src/H5Gobj.c
@@ -317,8 +317,8 @@ H5G_obj_ent_encode(const H5F_t *f, uint8_t **pp, const H5O_loc_t *oloc)
* Purpose: Retrieves the "link info" message for an object. Also
* sets the number of links correctly, if it isn't set up yet.
*
- * Return: Success: Ptr to message in native format.
- * Failure: NULL
+ * Return: Success: TRUE/FALSE whether message was found & retrieved
+ * Failure: FAIL if error occurred
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
diff --git a/src/H5O.c b/src/H5O.c
index 8c8ace0..9b9d0ef 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -2416,7 +2416,8 @@ H5O_get_info(H5O_loc_t *oloc, hid_t dxpl_id, hbool_t want_ih_info, H5O_info_t *o
} /* end for */
/* Retrieve # of attributes */
- oinfo->num_attrs = H5O_attr_count_real(oloc->file, dxpl_id, oh);
+ if(H5O_attr_count_real(oloc->file, dxpl_id, oh, &oinfo->num_attrs) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't retrieve attribute count")
/* Get B-tree & heap metadata storage size, if requested */
if(want_ih_info) {
diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c
index ae016c8..81c2d3b 100644
--- a/src/H5Oattribute.c
+++ b/src/H5Oattribute.c
@@ -239,15 +239,16 @@ H5O_attr_create(const H5O_loc_t *loc, hid_t dxpl_id, H5A_t *attr)
/* Check if this object already has attribute information */
if(oh->version > H5O_VERSION_1) {
- hbool_t new_ainfo = FALSE; /* Flag to indicate that the attribute information is new */
-
- if(NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) {
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ hbool_t new_ainfo = FALSE; /* Flag to indicate that the attribute information is new */
+ htri_t ainfo_exists; /* Whether the attribute info was retrieved */
+ /* Check for (& retrieve if available) attribute info */
+ if((ainfo_exists = H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ if(!ainfo_exists) {
/* Initialize attribute information */
- ainfo.track_corder = (oh->flags & H5O_HDR_ATTR_CRT_ORDER_TRACKED) ? TRUE : FALSE;
- ainfo.index_corder = (oh->flags & H5O_HDR_ATTR_CRT_ORDER_INDEXED) ? TRUE : FALSE;
+ ainfo.track_corder = (hbool_t)((oh->flags & H5O_HDR_ATTR_CRT_ORDER_TRACKED) ? TRUE : FALSE);
+ ainfo.index_corder = (hbool_t)((oh->flags & H5O_HDR_ATTR_CRT_ORDER_INDEXED) ? TRUE : FALSE);
ainfo.max_crt_idx = 0;
ainfo.corder_bt2_addr = HADDR_UNDEF;
ainfo.nattrs = 0;
@@ -491,22 +492,29 @@ H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name, hid_t dxpl_id)
/* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if(H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "can't check for attribute info message")
+ } /* end if */
/* If found the attribute is already opened, make a copy of it to share the
- object information. If not, open attribute as a new object */
+ * object information. If not, open attribute as a new object
+ */
if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr, name)) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "failed in finding opened attribute")
else if(found_open_attr == TRUE) {
if(NULL == (ret_value = H5A_copy(NULL, exist_attr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute")
- } else {
- if(H5F_addr_defined(ainfo.fheap_addr)) { /* open attribute with dense storage */
+ } /* end else if */
+ else {
+ /* Check for attributes in dense storage */
+ if(H5F_addr_defined(ainfo.fheap_addr)) {
+ /* Open attribute with dense storage */
if(NULL == (ret_value = H5A_dense_open(loc->file, dxpl_id, &ainfo, name)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "can't open attribute")
- } else {
+ } /* end if */
+ else {
H5O_iter_opn_t udata; /* User data for callback */
H5O_mesg_operator_t op; /* Wrapper for operator */
@@ -528,7 +536,7 @@ H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name, hid_t dxpl_id)
HDassert(udata.attr);
ret_value = udata.attr;
} /* end else */
- }
+ } /* end else */
done:
if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0)
@@ -595,12 +603,11 @@ H5A_t *
H5O_attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type,
H5_iter_order_t order, hsize_t n, hid_t dxpl_id)
{
+ H5O_t *oh = NULL; /* Object header */
H5A_attr_iter_op_t attr_op; /* Attribute operator */
H5A_t *exist_attr = NULL; /* Opened attribute object */
htri_t found_open_attr = FALSE; /* Whether opened object is found */
H5A_t *ret_value = NULL; /* Return value */
- H5O_t *oh = NULL; /* Object header */
- H5O_ainfo_t ainfo; /* Attribute information for object */
FUNC_ENTER_NOAPI_NOINIT(H5O_attr_open_by_idx)
@@ -615,38 +622,30 @@ H5O_attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type,
if(H5O_attr_iterate_real((hid_t)-1, loc, dxpl_id, idx_type, order, n, NULL, &attr_op, &ret_value) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_BADITER, NULL, "can't locate attribute")
-
/* Protect the object header to iterate over */
if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, NULL, "unable to load object header")
- /* Check for attribute info stored */
- ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
-
/* Find out whether it has already been opened. If it has, close the object
- * and make a copy of the already opened object to share the object info. */
+ * and make a copy of the already opened object to share the object info.
+ */
if(ret_value) {
- if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr,
- ret_value->shared->name)) < 0)
+ if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr, ret_value->shared->name)) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "failed in finding opened attribute")
/* If found that the attribute is already opened, make a copy of it
- and close the object just opened. */
+ * and close the object just opened.
+ */
if(found_open_attr && exist_attr) {
if(H5A_close(ret_value) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, NULL, "can't close attribute")
-
if(NULL == (ret_value = H5A_copy(NULL, exist_attr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute")
- }
- }
+ } /* end if */
+ } /* end if */
done:
- if(oh && H5AC_unprotect(loc->file, H5AC_ind_dxpl_id, H5AC_OHDR, loc->addr, oh,
- H5AC__NO_FLAGS_SET) < 0)
+ if(oh && H5AC_unprotect(loc->file, H5AC_ind_dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_ATTR, H5E_PROTECT, NULL, "unable to release object header")
FUNC_LEAVE_NOAPI(ret_value)
@@ -668,14 +667,13 @@ done:
*
*-------------------------------------------------------------------------
*/
-static
-htri_t H5O_attr_find_opened_attr(const H5O_loc_t *loc, H5A_t **attr, const char* name_to_open)
+static htri_t
+H5O_attr_find_opened_attr(const H5O_loc_t *loc, H5A_t **attr, const char* name_to_open)
{
- htri_t ret_value = FALSE;
- int num_open_attr = 0;
- hid_t *attr_id_list = NULL;
- unsigned long loc_fnum, attr_fnum;
- int i;
+ hid_t *attr_id_list = NULL; /* List of IDs for opened attributes */
+ unsigned long loc_fnum; /* File serial # for object */
+ size_t num_open_attr; /* Number of opened attributes */
+ htri_t ret_value = FALSE; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5O_attr_find_opened_attr)
@@ -684,39 +682,48 @@ htri_t H5O_attr_find_opened_attr(const H5O_loc_t *loc, H5A_t **attr, const char*
HGOTO_ERROR(H5E_ATTR, H5E_BADVALUE, FAIL, "can't get file serial number")
/* Count all opened attributes */
- if((num_open_attr = H5F_get_obj_count(loc->file, H5F_OBJ_ATTR | H5F_OBJ_LOCAL, FALSE)) < 0)
- HGOTO_ERROR(H5E_ATTR, H5E_CANTCOUNT, FAIL, "can't get number of opened attributes")
+ num_open_attr = H5F_get_obj_count(loc->file, H5F_OBJ_ATTR | H5F_OBJ_LOCAL, FALSE);
/* Find out whether the attribute has been opened */
if(num_open_attr) {
- attr_id_list = (hid_t*)H5MM_malloc(num_open_attr*sizeof(hid_t));
+ size_t u; /* Local index variable */
+
+ /* Allocate space for the attribute ID list */
+ if(NULL == (attr_id_list = (hid_t *)H5MM_malloc(num_open_attr * sizeof(hid_t))))
+ HGOTO_ERROR(H5E_ATTR, H5E_NOSPACE, FAIL, "unable to allocate memory for attribute ID list")
/* Retrieve the IDs of all opened attributes */
- if(H5F_get_obj_ids(loc->file, H5F_OBJ_ATTR | H5F_OBJ_LOCAL, num_open_attr, attr_id_list, FALSE) < 0)
- HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't IDs of opened attributes")
+ H5F_get_obj_ids(loc->file, H5F_OBJ_ATTR | H5F_OBJ_LOCAL, num_open_attr, attr_id_list, FALSE);
+
+ /* Iterate over the attributes */
+ for(u = 0; u < num_open_attr; u++) {
+ unsigned long attr_fnum; /* Attributes file serial number */
- for(i=0; i<num_open_attr; i++) {
- if(NULL == (*attr = (H5A_t *)H5I_object_verify(attr_id_list[i], H5I_ATTR)))
+ /* Get pointer to attribute */
+ if(NULL == (*attr = (H5A_t *)H5I_object_verify(attr_id_list[u], H5I_ATTR)))
HGOTO_ERROR(H5E_ATTR, H5E_BADTYPE, FAIL, "not an attribute")
/* Get file serial number for attribute */
if(H5F_get_fileno((*attr)->oloc.file, &attr_fnum) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_BADVALUE, FAIL, "can't get file serial number")
- /* Verify whether it's the right object. The attribute name, object address
- * to which the attribute is attached, and file serial number should all
- * match. */
- if(!strcmp(name_to_open, (*attr)->shared->name) &&
- loc->addr == (*attr)->oloc.addr &&
- loc_fnum == attr_fnum) {
+ /* Verify whether it's the right object. The attribute name, object
+ * address to which the attribute is attached, and file serial
+ * number should all match.
+ */
+ if(!HDstrcmp(name_to_open, (*attr)->shared->name) &&
+ loc->addr == (*attr)->oloc.addr &&
+ loc_fnum == attr_fnum) {
ret_value = TRUE;
break;
- }
- }
- H5MM_free(attr_id_list);
- }
+ } /* end if */
+ } /* end for */
+ } /* end if */
done:
+ if(attr_id_list)
+ H5MM_free(attr_id_list);
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O_attr_find_opened_attr */
@@ -886,9 +893,11 @@ H5O_attr_write(const H5O_loc_t *loc, hid_t dxpl_id, H5A_t *attr)
/* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if(H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ } /* end if */
/* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) {
@@ -1118,9 +1127,11 @@ H5O_attr_rename(const H5O_loc_t *loc, hid_t dxpl_id, const char *old_name,
/* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if(H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ } /* end if */
/* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) {
@@ -1206,15 +1217,16 @@ H5O_attr_iterate_real(hid_t loc_id, const H5O_loc_t *loc, hid_t dxpl_id,
HDassert(attr_op);
/* Protect the object header to iterate over */
- if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr,
- NULL, NULL, H5AC_READ)))
+ if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header")
/* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if(H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ } /* end if */
/* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) {
@@ -1228,8 +1240,7 @@ H5O_attr_iterate_real(hid_t loc_id, const H5O_loc_t *loc, hid_t dxpl_id,
oh = NULL;
/* Iterate over attributes in dense storage */
- if((ret_value = H5A_dense_iterate(loc->file, dxpl_id, loc_id, &ainfo,
- idx_type, order, skip, last_attr, attr_op, op_data)) < 0)
+ if((ret_value = H5A_dense_iterate(loc->file, dxpl_id, loc_id, &ainfo, idx_type, order, skip, last_attr, attr_op, op_data)) < 0)
HERROR(H5E_ATTR, H5E_BADITER, "error iterating over attributes");
} /* end if */
else {
@@ -1491,7 +1502,7 @@ H5O_attr_remove(const H5O_loc_t *loc, const char *name, hid_t dxpl_id)
{
H5O_t *oh = NULL; /* Pointer to actual object header */
H5O_ainfo_t ainfo; /* Attribute information for object */
- H5O_ainfo_t *ainfo_ptr = NULL; /* Pointer to attribute information for object */
+ htri_t ainfo_exists = FALSE; /* Whether the attribute info exists in the file */
unsigned oh_flags = H5AC__NO_FLAGS_SET; /* Metadata cache flags for object header */
herr_t ret_value = SUCCEED; /* Return value */
@@ -1507,9 +1518,11 @@ H5O_attr_remove(const H5O_loc_t *loc, const char *name, hid_t dxpl_id)
/* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if((ainfo_exists = H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ } /* end if */
/* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) {
@@ -1539,7 +1552,7 @@ H5O_attr_remove(const H5O_loc_t *loc, const char *name, hid_t dxpl_id)
} /* end else */
/* Update the attribute information after removing an attribute */
- if(ainfo_ptr)
+ if(ainfo_exists)
if(H5O_attr_remove_update(loc, oh, &ainfo, dxpl_id) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTUPDATE, FAIL, "unable to update attribute info")
@@ -1577,7 +1590,7 @@ H5O_attr_remove_by_idx(const H5O_loc_t *loc, H5_index_t idx_type,
{
H5O_t *oh = NULL; /* Pointer to actual object header */
H5O_ainfo_t ainfo; /* Attribute information for object */
- H5O_ainfo_t *ainfo_ptr = NULL; /* Pointer to attribute information for object */
+ htri_t ainfo_exists = FALSE; /* Whether the attribute info exists in the file */
unsigned oh_flags = H5AC__NO_FLAGS_SET; /* Metadata cache flags for object header */
H5A_attr_table_t atable = {0, NULL}; /* Table of attributes */
herr_t ret_value = SUCCEED; /* Return value */
@@ -1593,9 +1606,11 @@ H5O_attr_remove_by_idx(const H5O_loc_t *loc, H5_index_t idx_type,
/* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if((ainfo_exists = H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ } /* end if */
/* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) {
@@ -1633,7 +1648,7 @@ H5O_attr_remove_by_idx(const H5O_loc_t *loc, H5_index_t idx_type,
} /* end else */
/* Update the attribute information after removing an attribute */
- if(ainfo_ptr)
+ if(ainfo_exists)
if(H5O_attr_remove_update(loc, oh, &ainfo, dxpl_id) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTUPDATE, FAIL, "unable to update attribute info")
@@ -1666,40 +1681,44 @@ done:
*
*-------------------------------------------------------------------------
*/
-hsize_t
-H5O_attr_count_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh)
+herr_t
+H5O_attr_count_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, hsize_t *nattrs)
{
- hsize_t ret_value; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_attr_count_real)
+ FUNC_ENTER_NOAPI_NOINIT(H5O_attr_count_real)
/* Check arguments */
HDassert(f);
HDassert(oh);
+ HDassert(nattrs);
/* Check for attributes stored densely */
if(oh->version > H5O_VERSION_1) {
+ htri_t ainfo_exists = FALSE; /* Whether the attribute info exists in the file */
H5O_ainfo_t ainfo; /* Attribute information for object */
/* Attempt to get the attribute information from the object header */
- if(H5A_get_ainfo(f, dxpl_id, oh, &ainfo))
- ret_value = ainfo.nattrs;
- else {
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
-
- ret_value = 0;
- } /* end else */
+ if((ainfo_exists = H5A_get_ainfo(f, dxpl_id, oh, &ainfo)) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ else if(ainfo_exists > 0)
+ *nattrs = ainfo.nattrs;
+ else
+ *nattrs = 0;
} /* end if */
else {
+ hsize_t attr_count; /* Number of attributes found */
unsigned u; /* Local index variable */
/* Loop over all messages, counting the attributes */
- for(u = ret_value = 0; u < oh->nmesgs; u++)
+ attr_count = 0;
+ for(u = 0; u < oh->nmesgs; u++)
if(oh->mesg[u].type == H5O_MSG_ATTR)
- ret_value++;
+ attr_count++;
+ *nattrs = attr_count;
} /* end else */
+done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O_attr_count_real */
@@ -1775,9 +1794,11 @@ H5O_attr_exists(const H5O_loc_t *loc, const char *name, hid_t dxpl_id)
/* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if(H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ } /* end if */
/* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) {
@@ -1802,7 +1823,7 @@ H5O_attr_exists(const H5O_loc_t *loc, const char *name, hid_t dxpl_id)
HGOTO_ERROR(H5E_ATTR, H5E_BADITER, FAIL, "error checking for existence of attribute")
/* Check that we found the attribute */
- ret_value = udata.found;
+ ret_value = (htri_t)udata.found;
} /* end else */
done:
@@ -1840,12 +1861,12 @@ H5O_attr_bh_info(H5F_t *f, hid_t dxpl_id, H5O_t *oh, H5_ih_info_t *bh_info)
/* Attributes are only stored in fractal heap & indexed w/v2 B-tree in later versions */
if(oh->version > H5O_VERSION_1) {
H5O_ainfo_t ainfo; /* Attribute information for object */
+ htri_t ainfo_exists = FALSE; /* Whether the attribute info exists in the file */
- /* Check for attribute info stored */
- if(NULL == H5A_get_ainfo(f, dxpl_id, oh, &ainfo))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
- else {
+ /* Check for (& retrieve if available) attribute info */
+ if((ainfo_exists = H5A_get_ainfo(f, dxpl_id, oh, &ainfo)) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ else if(ainfo_exists > 0) {
/* Get storage size of creation order index, if it's used */
if(H5F_addr_defined(ainfo.corder_bt2_addr))
if(H5B2_iterate_size(f, dxpl_id, H5A_BT2_CORDER, ainfo.corder_bt2_addr, &(bh_info->index_size)) < 0)
@@ -1899,8 +1920,9 @@ done:
int
H5O_attr_count(const H5O_loc_t *loc, hid_t dxpl_id)
{
- H5O_t *oh = NULL; /* Pointer to actual object header */
- int ret_value; /* Return value */
+ H5O_t *oh = NULL; /* Pointer to actual object header */
+ hsize_t nattrs; /* Number of attributes */
+ int ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5O_attr_count)
@@ -1912,7 +1934,11 @@ H5O_attr_count(const H5O_loc_t *loc, hid_t dxpl_id)
HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header")
/* Retrieve # of attributes on object */
- ret_value = (int)H5O_attr_count_real(loc->file, dxpl_id, oh);
+ if(H5O_attr_count_real(loc->file, dxpl_id, oh, &nattrs) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't retrieve attribute count")
+
+ /* Set return value */
+ ret_value = (int)nattrs;
done:
if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0)
diff --git a/src/H5Opkg.h b/src/H5Opkg.h
index 4bc6d26..9981461 100644
--- a/src/H5Opkg.h
+++ b/src/H5Opkg.h
@@ -534,6 +534,9 @@ H5_DLL herr_t H5O_shared_debug(const H5O_shared_t *mesg, FILE *stream,
H5_DLL herr_t H5O_attr_reset(void *_mesg);
H5_DLL herr_t H5O_attr_delete(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, void *_mesg);
H5_DLL herr_t H5O_attr_link(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, void *_mesg);
+H5_DLL herr_t H5O_attr_count_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh,
+ hsize_t *nattrs);
+
/* These functions operate on object locations */
H5_DLL H5O_loc_t *H5O_get_loc(hid_t id);
diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h
index 00c832a..590da0c 100644
--- a/src/H5Oprivate.h
+++ b/src/H5Oprivate.h
@@ -676,8 +676,5 @@ H5_DLL herr_t H5O_link_delete(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh,
/* Shared message operators */
H5_DLL herr_t H5O_set_shared(H5O_shared_t *dst, const H5O_shared_t *src);
-/* Attribute operators */
-H5_DLL hsize_t H5O_attr_count_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh);
-
#endif /* _H5Oprivate_H */
diff --git a/src/H5Otest.c b/src/H5Otest.c
index 8116ffa..c2b30fa 100644
--- a/src/H5Otest.c
+++ b/src/H5Otest.c
@@ -112,9 +112,11 @@ H5O_is_attr_dense_test(hid_t oid)
/* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if(H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ } /* end if */
/* Check if dense storage is being used */
if(H5F_addr_defined(ainfo.fheap_addr)) {
@@ -157,7 +159,7 @@ H5O_is_attr_empty_test(hid_t oid)
{
H5O_t *oh = NULL; /* Object header */
H5O_ainfo_t ainfo; /* Attribute information for object */
- H5O_ainfo_t *ainfo_ptr = NULL; /* Pointer to attribute information for object */
+ htri_t ainfo_exists = FALSE; /* Whether the attribute info exists in the file */
H5O_loc_t *oloc; /* Pointer to object's location */
hsize_t nattrs; /* Number of attributes */
htri_t ret_value; /* Return value */
@@ -173,17 +175,18 @@ H5O_is_attr_empty_test(hid_t oid)
HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header")
/* Check for attribute info stored */
- ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo)))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if((ainfo_exists = H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo)) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ } /* end if */
/* Retrieve the number of attribute messages in header */
nattrs = H5O_msg_count_real(oh, H5O_MSG_ATTR);
/* Check for later version of object header format & attribute info available */
if(oh->version > H5O_VERSION_1) {
- if(ainfo_ptr) {
+ if(ainfo_exists) {
/* Check for using dense storage */
if(H5F_addr_defined(ainfo.fheap_addr)) {
/* Check for any messages in object header */
@@ -252,9 +255,11 @@ H5O_num_attrs_test(hid_t oid, hsize_t *nattrs)
/* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if(H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ } /* end if */
/* Retrieve the number of attribute messages in header */
obj_nattrs = H5O_msg_count_real(oh, H5O_MSG_ATTR);
@@ -327,9 +332,11 @@ H5O_attr_dense_info_test(hid_t oid, hsize_t *name_count, hsize_t *corder_count)
/* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF;
- if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo))
- /* Clear error stack from not finding attribute info */
- H5E_clear_stack(NULL);
+ if(oh->version > H5O_VERSION_1) {
+ /* Check for (& retrieve if available) attribute info */
+ if(H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
+ } /* end if */
/* Check for 'dense' attribute storage file addresses being defined */
if(!H5F_addr_defined(ainfo.fheap_addr))