[svn-r16483] Description:

Clean up (i.e. remove) more internal calls to H5E_clear_stack(), along with
some other minor code cleanups.

Tested on:
    Mac OS X/32 10.5.6 (amazon)
    (too minor to require h5committest)
This commit is contained in:
Quincey Koziol 2009-02-12 17:41:52 -05:00
parent 0bdedf0a39
commit ca0a3e2853
10 changed files with 183 additions and 147 deletions

View File

@ -680,8 +680,8 @@ done:
* Purpose: Retrieves the "attribute info" message for an object. Also * Purpose: Retrieves the "attribute info" message for an object. Also
* sets the number of attributes correctly, if it isn't set up yet. * sets the number of attributes correctly, if it isn't set up yet.
* *
* Return: Success: Ptr to message in native format. * Return: Success: TRUE/FALSE whether message was found & retrieved
* Failure: NULL * Failure: FAIL if error occurred
* *
* Programmer: Quincey Koziol * Programmer: Quincey Koziol
* koziol@hdfgroup.org * 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) 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 */ /* check arguments */
HDassert(f); HDassert(f);
HDassert(oh); 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 */ /* Retrieve the "attribute info" structure */
if((ret_value = (H5O_ainfo_t *)H5O_msg_read_oh(f, dxpl_id, oh, H5O_AINFO_ID, ainfo))) { 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")
/* Check if we don't know how many attributes there are */ /* 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 */ /* 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 */ /* Retrieve # of records in "name" B-tree */
/* (should be same # of records in all indices) */ /* (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") HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "can't retrieve # of records in index")
} /* end if */ } /* end if */
else else
/* Retrieve # of attributes from object header */ /* Retrieve # of attributes from object header */
ret_value->nattrs = oh->attr_msgs_seen; ainfo->nattrs = oh->attr_msgs_seen;
} /* end if */ } /* end if */
} /* end if */ } /* end if */
else
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "attribute info message not present")
done: done:
FUNC_LEAVE_NOAPI(ret_value) FUNC_LEAVE_NOAPI(ret_value)

View File

@ -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_get_info(const H5A_t *attr, H5A_info_t *ainfo);
H5_DLL herr_t H5A_free(H5A_t *attr); H5_DLL herr_t H5A_free(H5A_t *attr);
H5_DLL herr_t H5A_close(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, H5_DLL htri_t H5A_get_ainfo(H5F_t *f, hid_t dxpl_id, H5O_t *oh, H5O_ainfo_t *ainfo);
H5O_ainfo_t *ainfo);
H5_DLL herr_t H5A_set_version(const H5F_t *f, H5A_t *attr); H5_DLL herr_t H5A_set_version(const H5F_t *f, H5A_t *attr);
/* Attribute "dense" storage routines */ /* Attribute "dense" storage routines */

View File

@ -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 * Programmer: Raymond Lu
* Wednesday, Dec 5, 2001 * Wednesday, Dec 5, 2001
* *
* Modification:
*
*--------------------------------------------------------------------------- *---------------------------------------------------------------------------
*/ */
static size_t 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; ret_value = obj_id_count;
FUNC_LEAVE_NOAPI(ret_value) FUNC_LEAVE_NOAPI(ret_value)
} } /* end H5F_get_objects() */
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------

View File

@ -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 * Purpose: Retrieves the "link info" message for an object. Also
* sets the number of links correctly, if it isn't set up yet. * sets the number of links correctly, if it isn't set up yet.
* *
* Return: Success: Ptr to message in native format. * Return: Success: TRUE/FALSE whether message was found & retrieved
* Failure: NULL * Failure: FAIL if error occurred
* *
* Programmer: Quincey Koziol * Programmer: Quincey Koziol
* koziol@hdfgroup.org * koziol@hdfgroup.org

View File

@ -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 */ } /* end for */
/* Retrieve # of attributes */ /* 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 */ /* Get B-tree & heap metadata storage size, if requested */
if(want_ih_info) { if(want_ih_info) {

View File

@ -240,14 +240,15 @@ H5O_attr_create(const H5O_loc_t *loc, hid_t dxpl_id, H5A_t *attr)
/* Check if this object already has attribute information */ /* Check if this object already has attribute information */
if(oh->version > H5O_VERSION_1) { if(oh->version > H5O_VERSION_1) {
hbool_t new_ainfo = FALSE; /* Flag to indicate that the attribute information is new */ hbool_t new_ainfo = FALSE; /* Flag to indicate that the attribute information is new */
htri_t ainfo_exists; /* Whether the attribute info was retrieved */
if(NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) { /* Check for (& retrieve if available) attribute info */
/* Clear error stack from not finding attribute info */ if((ainfo_exists = H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) < 0)
H5E_clear_stack(NULL); HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
if(!ainfo_exists) {
/* Initialize attribute information */ /* Initialize attribute information */
ainfo.track_corder = (oh->flags & H5O_HDR_ATTR_CRT_ORDER_TRACKED) ? TRUE : FALSE; ainfo.track_corder = (hbool_t)((oh->flags & H5O_HDR_ATTR_CRT_ORDER_TRACKED) ? TRUE : FALSE);
ainfo.index_corder = (oh->flags & H5O_HDR_ATTR_CRT_ORDER_INDEXED) ? TRUE : FALSE; ainfo.index_corder = (hbool_t)((oh->flags & H5O_HDR_ATTR_CRT_ORDER_INDEXED) ? TRUE : FALSE);
ainfo.max_crt_idx = 0; ainfo.max_crt_idx = 0;
ainfo.corder_bt2_addr = HADDR_UNDEF; ainfo.corder_bt2_addr = HADDR_UNDEF;
ainfo.nattrs = 0; 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 */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; ainfo.fheap_addr = HADDR_UNDEF;
if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) if(oh->version > H5O_VERSION_1) {
/* Clear error stack from not finding attribute info */ /* Check for (& retrieve if available) attribute info */
H5E_clear_stack(NULL); 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 /* 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) 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") HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "failed in finding opened attribute")
else if(found_open_attr == TRUE) { else if(found_open_attr == TRUE) {
if(NULL == (ret_value = H5A_copy(NULL, exist_attr))) if(NULL == (ret_value = H5A_copy(NULL, exist_attr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute") HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute")
} else { } /* end else if */
if(H5F_addr_defined(ainfo.fheap_addr)) { /* open attribute with dense storage */ 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))) if(NULL == (ret_value = H5A_dense_open(loc->file, dxpl_id, &ainfo, name)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "can't open attribute") 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_iter_opn_t udata; /* User data for callback */
H5O_mesg_operator_t op; /* Wrapper for operator */ 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); HDassert(udata.attr);
ret_value = udata.attr; ret_value = udata.attr;
} /* end else */ } /* end else */
} } /* end else */
done: done:
if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0) 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, 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) 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_attr_iter_op_t attr_op; /* Attribute operator */
H5A_t *exist_attr = NULL; /* Opened attribute object */ H5A_t *exist_attr = NULL; /* Opened attribute object */
htri_t found_open_attr = FALSE; /* Whether opened object is found */ htri_t found_open_attr = FALSE; /* Whether opened object is found */
H5A_t *ret_value = NULL; /* Return value */ 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) 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) 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") HGOTO_ERROR(H5E_ATTR, H5E_BADITER, NULL, "can't locate attribute")
/* Protect the object header to iterate over */ /* 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, NULL, "unable to load object header") 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 /* 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(ret_value) {
if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr, if((found_open_attr = H5O_attr_find_opened_attr(loc, &exist_attr, ret_value->shared->name)) < 0)
ret_value->shared->name)) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "failed in finding opened attribute") 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 /* 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(found_open_attr && exist_attr) {
if(H5A_close(ret_value) < 0) if(H5A_close(ret_value) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, NULL, "can't close attribute") HGOTO_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, NULL, "can't close attribute")
if(NULL == (ret_value = H5A_copy(NULL, exist_attr))) if(NULL == (ret_value = H5A_copy(NULL, exist_attr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute") HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, NULL, "can't copy existing attribute")
} } /* end if */
} } /* end if */
done: done:
if(oh && H5AC_unprotect(loc->file, H5AC_ind_dxpl_id, H5AC_OHDR, loc->addr, oh, if(oh && H5AC_unprotect(loc->file, H5AC_ind_dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0)
H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_ATTR, H5E_PROTECT, NULL, "unable to release object header") HDONE_ERROR(H5E_ATTR, H5E_PROTECT, NULL, "unable to release object header")
FUNC_LEAVE_NOAPI(ret_value) FUNC_LEAVE_NOAPI(ret_value)
@ -668,14 +667,13 @@ done:
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
static static htri_t
htri_t H5O_attr_find_opened_attr(const H5O_loc_t *loc, H5A_t **attr, const char* name_to_open) H5O_attr_find_opened_attr(const H5O_loc_t *loc, H5A_t **attr, const char* name_to_open)
{ {
htri_t ret_value = FALSE; hid_t *attr_id_list = NULL; /* List of IDs for opened attributes */
int num_open_attr = 0; unsigned long loc_fnum; /* File serial # for object */
hid_t *attr_id_list = NULL; size_t num_open_attr; /* Number of opened attributes */
unsigned long loc_fnum, attr_fnum; htri_t ret_value = FALSE; /* Return value */
int i;
FUNC_ENTER_NOAPI_NOINIT(H5O_attr_find_opened_attr) 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") HGOTO_ERROR(H5E_ATTR, H5E_BADVALUE, FAIL, "can't get file serial number")
/* Count all opened attributes */ /* Count all opened attributes */
if((num_open_attr = H5F_get_obj_count(loc->file, H5F_OBJ_ATTR | H5F_OBJ_LOCAL, FALSE)) < 0) num_open_attr = H5F_get_obj_count(loc->file, H5F_OBJ_ATTR | H5F_OBJ_LOCAL, FALSE);
HGOTO_ERROR(H5E_ATTR, H5E_CANTCOUNT, FAIL, "can't get number of opened attributes")
/* Find out whether the attribute has been opened */ /* Find out whether the attribute has been opened */
if(num_open_attr) { 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 */ /* 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) H5F_get_obj_ids(loc->file, H5F_OBJ_ATTR | H5F_OBJ_LOCAL, num_open_attr, attr_id_list, FALSE);
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't IDs of opened attributes")
for(i=0; i<num_open_attr; i++) { /* Iterate over the attributes */
if(NULL == (*attr = (H5A_t *)H5I_object_verify(attr_id_list[i], H5I_ATTR))) for(u = 0; u < num_open_attr; u++) {
unsigned long attr_fnum; /* Attributes file serial number */
/* 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") HGOTO_ERROR(H5E_ATTR, H5E_BADTYPE, FAIL, "not an attribute")
/* Get file serial number for attribute */ /* Get file serial number for attribute */
if(H5F_get_fileno((*attr)->oloc.file, &attr_fnum) < 0) if(H5F_get_fileno((*attr)->oloc.file, &attr_fnum) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_BADVALUE, FAIL, "can't get file serial number") 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 /* Verify whether it's the right object. The attribute name, object
* to which the attribute is attached, and file serial number should all * address to which the attribute is attached, and file serial
* match. */ * number should all match.
if(!strcmp(name_to_open, (*attr)->shared->name) && */
if(!HDstrcmp(name_to_open, (*attr)->shared->name) &&
loc->addr == (*attr)->oloc.addr && loc->addr == (*attr)->oloc.addr &&
loc_fnum == attr_fnum) { loc_fnum == attr_fnum) {
ret_value = TRUE; ret_value = TRUE;
break; break;
} } /* end if */
} } /* end for */
H5MM_free(attr_id_list); } /* end if */
}
done: done:
if(attr_id_list)
H5MM_free(attr_id_list);
FUNC_LEAVE_NOAPI(ret_value) FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O_attr_find_opened_attr */ } /* 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 */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; ainfo.fheap_addr = HADDR_UNDEF;
if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) if(oh->version > H5O_VERSION_1) {
/* Clear error stack from not finding attribute info */ /* Check for (& retrieve if available) attribute info */
H5E_clear_stack(NULL); 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 */ /* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) { 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 */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; ainfo.fheap_addr = HADDR_UNDEF;
if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) if(oh->version > H5O_VERSION_1) {
/* Clear error stack from not finding attribute info */ /* Check for (& retrieve if available) attribute info */
H5E_clear_stack(NULL); 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 */ /* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) { 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); HDassert(attr_op);
/* Protect the object header to iterate over */ /* Protect the object header to iterate over */
if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ)))
NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header") HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header")
/* Check for attribute info stored */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; ainfo.fheap_addr = HADDR_UNDEF;
if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) if(oh->version > H5O_VERSION_1) {
/* Clear error stack from not finding attribute info */ /* Check for (& retrieve if available) attribute info */
H5E_clear_stack(NULL); 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 */ /* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) { 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; oh = NULL;
/* Iterate over attributes in dense storage */ /* Iterate over attributes in dense storage */
if((ret_value = H5A_dense_iterate(loc->file, dxpl_id, loc_id, &ainfo, if((ret_value = H5A_dense_iterate(loc->file, dxpl_id, loc_id, &ainfo, idx_type, order, skip, last_attr, attr_op, op_data)) < 0)
idx_type, order, skip, last_attr, attr_op, op_data)) < 0)
HERROR(H5E_ATTR, H5E_BADITER, "error iterating over attributes"); HERROR(H5E_ATTR, H5E_BADITER, "error iterating over attributes");
} /* end if */ } /* end if */
else { 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_t *oh = NULL; /* Pointer to actual object header */
H5O_ainfo_t ainfo; /* Attribute information for object */ 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 */ unsigned oh_flags = H5AC__NO_FLAGS_SET; /* Metadata cache flags for object header */
herr_t ret_value = SUCCEED; /* Return value */ 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 */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; ainfo.fheap_addr = HADDR_UNDEF;
if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo))) if(oh->version > H5O_VERSION_1) {
/* Clear error stack from not finding attribute info */ /* Check for (& retrieve if available) attribute info */
H5E_clear_stack(NULL); 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 */ /* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) { 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 */ } /* end else */
/* Update the attribute information after removing an attribute */ /* 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) if(H5O_attr_remove_update(loc, oh, &ainfo, dxpl_id) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTUPDATE, FAIL, "unable to update attribute info") 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_t *oh = NULL; /* Pointer to actual object header */
H5O_ainfo_t ainfo; /* Attribute information for object */ 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 */ unsigned oh_flags = H5AC__NO_FLAGS_SET; /* Metadata cache flags for object header */
H5A_attr_table_t atable = {0, NULL}; /* Table of attributes */ H5A_attr_table_t atable = {0, NULL}; /* Table of attributes */
herr_t ret_value = SUCCEED; /* Return value */ 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 */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; ainfo.fheap_addr = HADDR_UNDEF;
if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo))) if(oh->version > H5O_VERSION_1) {
/* Clear error stack from not finding attribute info */ /* Check for (& retrieve if available) attribute info */
H5E_clear_stack(NULL); 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 */ /* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) { 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 */ } /* end else */
/* Update the attribute information after removing an attribute */ /* 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) if(H5O_attr_remove_update(loc, oh, &ainfo, dxpl_id) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTUPDATE, FAIL, "unable to update attribute info") HGOTO_ERROR(H5E_ATTR, H5E_CANTUPDATE, FAIL, "unable to update attribute info")
@ -1666,40 +1681,44 @@ done:
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
hsize_t herr_t
H5O_attr_count_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh) 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 */ /* Check arguments */
HDassert(f); HDassert(f);
HDassert(oh); HDassert(oh);
HDassert(nattrs);
/* Check for attributes stored densely */ /* Check for attributes stored densely */
if(oh->version > H5O_VERSION_1) { 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 */ H5O_ainfo_t ainfo; /* Attribute information for object */
/* Attempt to get the attribute information from the object header */ /* Attempt to get the attribute information from the object header */
if(H5A_get_ainfo(f, dxpl_id, oh, &ainfo)) if((ainfo_exists = H5A_get_ainfo(f, dxpl_id, oh, &ainfo)) < 0)
ret_value = ainfo.nattrs; HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
else { else if(ainfo_exists > 0)
/* Clear error stack from not finding attribute info */ *nattrs = ainfo.nattrs;
H5E_clear_stack(NULL); else
*nattrs = 0;
ret_value = 0;
} /* end else */
} /* end if */ } /* end if */
else { else {
hsize_t attr_count; /* Number of attributes found */
unsigned u; /* Local index variable */ unsigned u; /* Local index variable */
/* Loop over all messages, counting the attributes */ /* 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) if(oh->mesg[u].type == H5O_MSG_ATTR)
ret_value++; attr_count++;
*nattrs = attr_count;
} /* end else */ } /* end else */
done:
FUNC_LEAVE_NOAPI(ret_value) FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O_attr_count_real */ } /* 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 */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; ainfo.fheap_addr = HADDR_UNDEF;
if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(loc->file, dxpl_id, oh, &ainfo)) if(oh->version > H5O_VERSION_1) {
/* Clear error stack from not finding attribute info */ /* Check for (& retrieve if available) attribute info */
H5E_clear_stack(NULL); 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 */ /* Check for attributes stored densely */
if(H5F_addr_defined(ainfo.fheap_addr)) { 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") HGOTO_ERROR(H5E_ATTR, H5E_BADITER, FAIL, "error checking for existence of attribute")
/* Check that we found the attribute */ /* Check that we found the attribute */
ret_value = udata.found; ret_value = (htri_t)udata.found;
} /* end else */ } /* end else */
done: 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 */ /* Attributes are only stored in fractal heap & indexed w/v2 B-tree in later versions */
if(oh->version > H5O_VERSION_1) { if(oh->version > H5O_VERSION_1) {
H5O_ainfo_t ainfo; /* Attribute information for object */ 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 */ /* Check for (& retrieve if available) attribute info */
if(NULL == H5A_get_ainfo(f, dxpl_id, oh, &ainfo)) if((ainfo_exists = H5A_get_ainfo(f, dxpl_id, oh, &ainfo)) < 0)
/* Clear error stack from not finding attribute info */ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
H5E_clear_stack(NULL); else if(ainfo_exists > 0) {
else {
/* Get storage size of creation order index, if it's used */ /* Get storage size of creation order index, if it's used */
if(H5F_addr_defined(ainfo.corder_bt2_addr)) 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) if(H5B2_iterate_size(f, dxpl_id, H5A_BT2_CORDER, ainfo.corder_bt2_addr, &(bh_info->index_size)) < 0)
@ -1900,6 +1921,7 @@ int
H5O_attr_count(const H5O_loc_t *loc, hid_t dxpl_id) H5O_attr_count(const H5O_loc_t *loc, hid_t dxpl_id)
{ {
H5O_t *oh = NULL; /* Pointer to actual object header */ H5O_t *oh = NULL; /* Pointer to actual object header */
hsize_t nattrs; /* Number of attributes */
int ret_value; /* Return value */ int ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5O_attr_count) 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") HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header")
/* Retrieve # of attributes on object */ /* 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: done:
if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0) if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0)

View File

@ -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_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_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_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 */ /* These functions operate on object locations */
H5_DLL H5O_loc_t *H5O_get_loc(hid_t id); H5_DLL H5O_loc_t *H5O_get_loc(hid_t id);

View File

@ -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 */ /* Shared message operators */
H5_DLL herr_t H5O_set_shared(H5O_shared_t *dst, const H5O_shared_t *src); 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 */ #endif /* _H5Oprivate_H */

View File

@ -112,9 +112,11 @@ H5O_is_attr_dense_test(hid_t oid)
/* Check for attribute info stored */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; ainfo.fheap_addr = HADDR_UNDEF;
if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo)) if(oh->version > H5O_VERSION_1) {
/* Clear error stack from not finding attribute info */ /* Check for (& retrieve if available) attribute info */
H5E_clear_stack(NULL); 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 */ /* Check if dense storage is being used */
if(H5F_addr_defined(ainfo.fheap_addr)) { 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_t *oh = NULL; /* Object header */
H5O_ainfo_t ainfo; /* Attribute information for object */ 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 */ H5O_loc_t *oloc; /* Pointer to object's location */
hsize_t nattrs; /* Number of attributes */ hsize_t nattrs; /* Number of attributes */
htri_t ret_value; /* Return value */ 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") HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to load object header")
/* Check for attribute info stored */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; if(oh->version > H5O_VERSION_1) {
if(oh->version > H5O_VERSION_1 && NULL == (ainfo_ptr = H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo))) /* Check for (& retrieve if available) attribute info */
/* Clear error stack from not finding attribute info */ if((ainfo_exists = H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo)) < 0)
H5E_clear_stack(NULL); HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't check for attribute info message")
} /* end if */
/* Retrieve the number of attribute messages in header */ /* Retrieve the number of attribute messages in header */
nattrs = H5O_msg_count_real(oh, H5O_MSG_ATTR); nattrs = H5O_msg_count_real(oh, H5O_MSG_ATTR);
/* Check for later version of object header format & attribute info available */ /* Check for later version of object header format & attribute info available */
if(oh->version > H5O_VERSION_1) { if(oh->version > H5O_VERSION_1) {
if(ainfo_ptr) { if(ainfo_exists) {
/* Check for using dense storage */ /* Check for using dense storage */
if(H5F_addr_defined(ainfo.fheap_addr)) { if(H5F_addr_defined(ainfo.fheap_addr)) {
/* Check for any messages in object header */ /* 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 */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; ainfo.fheap_addr = HADDR_UNDEF;
if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo)) if(oh->version > H5O_VERSION_1) {
/* Clear error stack from not finding attribute info */ /* Check for (& retrieve if available) attribute info */
H5E_clear_stack(NULL); 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 */ /* Retrieve the number of attribute messages in header */
obj_nattrs = H5O_msg_count_real(oh, H5O_MSG_ATTR); 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 */ /* Check for attribute info stored */
ainfo.fheap_addr = HADDR_UNDEF; ainfo.fheap_addr = HADDR_UNDEF;
if(oh->version > H5O_VERSION_1 && NULL == H5A_get_ainfo(oloc->file, H5AC_ind_dxpl_id, oh, &ainfo)) if(oh->version > H5O_VERSION_1) {
/* Clear error stack from not finding attribute info */ /* Check for (& retrieve if available) attribute info */
H5E_clear_stack(NULL); 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 */ /* Check for 'dense' attribute storage file addresses being defined */
if(!H5F_addr_defined(ainfo.fheap_addr)) if(!H5F_addr_defined(ainfo.fheap_addr))

View File

@ -4882,7 +4882,7 @@ test_misc28(void)
hsize_t count[] = {MISC28_SIZE, 1}; hsize_t count[] = {MISC28_SIZE, 1};
size_t nbytes_used; size_t nbytes_used;
int nused; int nused;
char buf[10]; char buf[MISC28_SIZE];
int i; int i;
herr_t ret; /* Generic return value */ herr_t ret; /* Generic return value */