summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2007-02-20 19:58:09 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2007-02-20 19:58:09 (GMT)
commitd08fabd66d4625bf387bb2edc9c19432332aed16 (patch)
tree421b336267de887763aa82c820a6fe05c3d9611b
parent8eecc944d7f741afcfd445a6c0f9906df759cdad (diff)
downloadhdf5-d08fabd66d4625bf387bb2edc9c19432332aed16.zip
hdf5-d08fabd66d4625bf387bb2edc9c19432332aed16.tar.gz
hdf5-d08fabd66d4625bf387bb2edc9c19432332aed16.tar.bz2
[svn-r13353] Description:
Checkpoint progress on H5Aiterate2(). Mark H5Aiterate() as deprecated. Various code cleanups. Tested on: Linux/32 2.6 (chicago) Linux/64 2.6 (chicago2)
-rw-r--r--src/H5A.c119
-rw-r--r--src/H5Adense.c17
-rw-r--r--src/H5Adeprec.c68
-rw-r--r--src/H5Aint.c14
-rw-r--r--src/H5Apkg.h11
-rw-r--r--src/H5Apublic.h13
-rw-r--r--src/H5Doh.c4
-rw-r--r--src/H5G.c2
-rw-r--r--src/H5Goh.c4
-rw-r--r--src/H5Gprivate.h2
-rw-r--r--src/H5O.c11
-rw-r--r--src/H5Oattribute.c59
-rw-r--r--src/H5Opkg.h3
-rw-r--r--src/H5Tcommit.c6
-rw-r--r--src/H5Toh.c4
-rw-r--r--src/H5Tprivate.h2
-rw-r--r--test/tattr.c629
17 files changed, 873 insertions, 95 deletions
diff --git a/src/H5A.c b/src/H5A.c
index 742a0e3..71801c3 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -76,7 +76,6 @@ static H5A_t *H5A_open_by_name(const H5G_loc_t *loc, const char *obj_name,
static herr_t H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id);
static herr_t H5A_read(const H5A_t *attr, const H5T_t *mem_type, void *buf, hid_t dxpl_id);
static hsize_t H5A_get_storage_size(const H5A_t *attr);
-static herr_t H5A_get_info(const H5A_t *attr, H5A_info_t *ainfo);
/*********************/
@@ -1503,10 +1502,12 @@ done:
*
*-------------------------------------------------------------------------
*/
-static herr_t
+herr_t
H5A_get_info(const H5A_t *attr, H5A_info_t *ainfo)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5A_get_info)
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(H5A_get_info, FAIL)
/* Check args */
HDassert(attr);
@@ -1524,7 +1525,8 @@ H5A_get_info(const H5A_t *attr, H5A_info_t *ainfo)
ainfo->corder = attr->crt_idx;
} /* end else */
- FUNC_LEAVE_NOAPI(SUCCEED)
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A_get_info() */
@@ -1571,30 +1573,38 @@ done:
/*--------------------------------------------------------------------------
NAME
- H5Aiterate
+ H5Aiterate2
PURPOSE
Calls a user's function for each attribute on an object
USAGE
- herr_t H5Aiterate (loc_id, attr_num, op, data)
- hid_t loc_id; IN: Object (dataset or group) to be iterated over
- unsigned *attr_num; IN/OUT: Starting (IN) & Ending (OUT) attribute number
- H5A_operator_t op; IN: User's function to pass each attribute to
- void *op_data; IN/OUT: User's data to pass through to iterator operator function
+ herr_t H5Aiterate2(loc_id, obj_name, idx_type, order, idx, op, op_data, lapl_id)
+ hid_t loc_id; IN: Base location for object
+ const char *obj_name; IN: Name of object relative to location
+ H5_index_t idx_type; IN: Type of index to use
+ H5_iter_order_t order; IN: Order to iterate over index
+ hsize_t *idx; IN/OUT: Starting (IN) & Ending (OUT) attribute
+ in index & order
+ H5A_operator2_t op; IN: User's function to pass each attribute to
+ void *op_data; IN/OUT: User's data to pass through to iterator
+ operator function
+ hid_t lapl_id; IN: Link access property list
RETURNS
- Returns a negative value if something is wrong, the return value of the
- last operator if it was non-zero, or zero if all attributes were processed.
+ Returns a negative value if an error occurs, the return value of the
+ last operator if it was non-zero (which can be a negative value), or zero
+ if all attributes were processed.
DESCRIPTION
This function interates over the attributes of dataset or group
- specified with 'loc_id'. For each attribute of the object, the
- 'op_data' and some additional information (specified below) are passed
- to the 'op' function. The iteration begins with the '*attr_number'
+ specified with 'loc_id' & 'obj_name'. For each attribute of the object,
+ the 'op_data' and some additional information (specified below) are passed
+ to the 'op' function. The iteration begins with the '*idx'
object in the group and the next attribute to be processed by the operator
- is returned in '*attr_number'.
+ is returned in '*idx'.
The operation receives the ID for the group or dataset being iterated
over ('loc_id'), the name of the current attribute about the object
- ('attr_name') and the pointer to the operator data passed in to H5Aiterate
- ('op_data'). The return values from an operator are:
+ ('attr_name'), the attribute's "info" struct ('ainfo') and the pointer to
+ the operator data passed in to H5Aiterate2 ('op_data'). The return values
+ from an operator are:
A. Zero causes the iterator to continue, returning zero when all
attributes have been processed.
B. Positive causes the iterator to immediately return that positive
@@ -1605,39 +1615,78 @@ done:
attribute.
--------------------------------------------------------------------------*/
herr_t
-H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op, void *op_data)
+H5Aiterate2(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t *idx, H5A_operator2_t op, void *op_data,
+ hid_t lapl_id)
{
- H5G_loc_t loc; /* Object location */
- H5A_attr_iter_op_t attr_op; /* Attribute operator */
- hsize_t start_idx; /* Index of attribute to start iterating at */
- hsize_t last_attr; /* Index of last attribute examined */
- herr_t ret_value; /* Return value */
+ H5G_loc_t loc; /* Object location */
+ 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 */
+ hid_t obj_loc_id = (-1); /* ID for object located */
+ H5A_attr_iter_op_t attr_op; /* Attribute operator */
+ hsize_t start_idx; /* Index of attribute to start iterating at */
+ hsize_t last_attr; /* Index of last attribute examined */
+ herr_t ret_value; /* Return value */
- FUNC_ENTER_API(H5Aiterate, FAIL)
- H5TRACE4("e", "i*Iuxx", loc_id, attr_num, op, op_data);
+ FUNC_ENTER_API(H5Aiterate2, FAIL)
/* check arguments */
if(H5I_ATTR == H5I_get_type(loc_id))
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 object 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")
+
+ /* 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, H5AC_ind_dxpl_id) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "object not found")
+ loc_found = TRUE;
+
+ /* Open the object */
+ if((obj_loc_id = H5O_open_by_loc(&obj_loc, H5AC_ind_dxpl_id)) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open object")
/* Build attribute operator info */
- attr_op.op_type = H5A_ATTR_OP_APP;
- attr_op.u.app_op = op;
+ attr_op.op_type = H5A_ATTR_OP_APP2;
+ attr_op.u.app_op2 = op;
/* Call attribute iteration routine */
- last_attr = start_idx = (hsize_t)(attr_num ? *attr_num : 0);
- if((ret_value = H5O_attr_iterate(loc_id, loc.oloc, H5AC_ind_dxpl_id, H5_INDEX_CRT_ORDER, H5_ITER_INC, start_idx, &last_attr, &attr_op, op_data)) < 0)
+ last_attr = start_idx = (idx ? *idx : 0);
+ if((ret_value = H5O_attr_iterate(obj_loc_id, H5AC_ind_dxpl_id, idx_type, order, start_idx, &last_attr, &attr_op, op_data)) < 0)
HERROR(H5E_ATTR, H5E_BADITER, "error iterating over attributes");
/* Set the last attribute information */
- if(attr_num)
- *attr_num = (unsigned)last_attr;
+ if(idx)
+ *idx = last_attr;
done:
+ /* Release resources */
+ if(obj_loc_id > 0) {
+ if(H5I_dec_ref(obj_loc_id) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "unable to close temporary object")
+ } /* end if */
+ else if(loc_found && H5G_loc_free(&obj_loc) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't free location")
+
FUNC_LEAVE_API(ret_value)
-} /* H5Aiterate() */
+} /* H5Aiterate2() */
/*--------------------------------------------------------------------------
@@ -1646,7 +1695,7 @@ done:
PURPOSE
Deletes an attribute from a location
USAGE
- herr_t H5Adelete (loc_id, name)
+ herr_t H5Adelete2(loc_id, obj_name, attr_name, lapl_id)
hid_t loc_id; IN: Base location for object
const char *obj_name; IN: Name of object relative to location
const char *attr_name; IN: Name of attribute to delete
@@ -1704,7 +1753,7 @@ done:
HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't free location")
FUNC_LEAVE_API(ret_value)
-} /* H5Adelete() */
+} /* H5Adelete2() */
/*--------------------------------------------------------------------------
diff --git a/src/H5Adense.c b/src/H5Adense.c
index d83c3e5..1dc7ad9 100644
--- a/src/H5Adense.c
+++ b/src/H5Adense.c
@@ -986,8 +986,8 @@ H5A_dense_iterate_bt2_cb(const void *_record, void *_bt2_udata)
if(bt2_udata->skip > 0)
--bt2_udata->skip;
else {
- H5A_fh_ud_cp_t fh_udata; /* User data for fractal heap 'op' callback */
- H5HF_t *fheap; /* Fractal heap handle for attribute storage */
+ H5A_fh_ud_cp_t fh_udata; /* User data for fractal heap 'op' callback */
+ H5HF_t *fheap; /* Fractal heap handle for attribute storage */
/* Check for iterating over shared attribute */
if(record->flags & H5O_MSG_FLAG_SHARED)
@@ -1008,6 +1008,19 @@ H5A_dense_iterate_bt2_cb(const void *_record, void *_bt2_udata)
/* Check which type of callback to make */
switch(bt2_udata->attr_op->op_type) {
+ case H5A_ATTR_OP_APP2:
+ {
+ H5A_info_t ainfo; /* Info for attribute */
+
+ /* Get the attribute information */
+ if(H5A_get_info(fh_udata.attr, &ainfo) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, H5_ITER_ERROR, "unable to get attribute info")
+
+ /* Make the application callback */
+ ret_value = (bt2_udata->attr_op->u.app_op2)(bt2_udata->loc_id, fh_udata.attr->name, &ainfo, bt2_udata->op_data);
+ break;
+ }
+
case H5A_ATTR_OP_APP:
/* Make the application callback */
ret_value = (bt2_udata->attr_op->u.app_op)(bt2_udata->loc_id, fh_udata.attr->name, bt2_udata->op_data);
diff --git a/src/H5Adeprec.c b/src/H5Adeprec.c
index 0e1d264..3baca88 100644
--- a/src/H5Adeprec.c
+++ b/src/H5Adeprec.c
@@ -168,6 +168,74 @@ done:
/*--------------------------------------------------------------------------
NAME
+ H5Aiterate
+ PURPOSE
+ Calls a user's function for each attribute on an object
+ USAGE
+ herr_t H5Aiterate (loc_id, attr_num, op, data)
+ hid_t loc_id; IN: Object (dataset or group) to be iterated over
+ unsigned *attr_num; IN/OUT: Starting (IN) & Ending (OUT) attribute number
+ H5A_operator_t op; IN: User's function to pass each attribute to
+ void *op_data; IN/OUT: User's data to pass through to iterator operator function
+ RETURNS
+ Returns a negative value if something is wrong, the return value of the
+ last operator if it was non-zero, or zero if all attributes were processed.
+
+ DESCRIPTION
+ This function interates over the attributes of dataset or group
+ specified with 'loc_id'. For each attribute of the object, the
+ 'op_data' and some additional information (specified below) are passed
+ to the 'op' function. The iteration begins with the '*attr_number'
+ object in the group and the next attribute to be processed by the operator
+ is returned in '*attr_number'.
+ The operation receives the ID for the group or dataset being iterated
+ over ('loc_id'), the name of the current attribute about the object
+ ('attr_name') and the pointer to the operator data passed in to H5Aiterate
+ ('op_data'). The return values from an operator are:
+ A. Zero causes the iterator to continue, returning zero when all
+ attributes have been processed.
+ B. Positive causes the iterator to immediately return that positive
+ value, indicating short-circuit success. The iterator can be
+ restarted at the next attribute.
+ C. Negative causes the iterator to immediately return that value,
+ indicating failure. The iterator can be restarted at the next
+ attribute.
+--------------------------------------------------------------------------*/
+herr_t
+H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op, void *op_data)
+{
+ H5A_attr_iter_op_t attr_op; /* Attribute operator */
+ hsize_t start_idx; /* Index of attribute to start iterating at */
+ hsize_t last_attr; /* Index of last attribute examined */
+ herr_t ret_value; /* Return value */
+
+ FUNC_ENTER_API(H5Aiterate, FAIL)
+ H5TRACE4("e", "i*Iuxx", loc_id, attr_num, op, op_data);
+
+ /* check arguments */
+ if(H5I_ATTR == H5I_get_type(loc_id))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
+
+ /* Build attribute operator info */
+ attr_op.op_type = H5A_ATTR_OP_APP;
+ attr_op.u.app_op = op;
+
+ /* Call attribute iteration routine */
+ last_attr = start_idx = (hsize_t)(attr_num ? *attr_num : 0);
+ if((ret_value = H5O_attr_iterate(loc_id, H5AC_ind_dxpl_id, H5_INDEX_CRT_ORDER, H5_ITER_INC, start_idx, &last_attr, &attr_op, op_data)) < 0)
+ HERROR(H5E_ATTR, H5E_BADITER, "error iterating over attributes");
+
+ /* Set the last attribute information */
+ if(attr_num)
+ *attr_num = (unsigned)last_attr;
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* H5Aiterate() */
+
+
+/*--------------------------------------------------------------------------
+ NAME
H5Adelete
PURPOSE
Deletes an attribute from a location
diff --git a/src/H5Aint.c b/src/H5Aint.c
index 8b4f92a..9d1b5c9 100644
--- a/src/H5Aint.c
+++ b/src/H5Aint.c
@@ -537,6 +537,19 @@ H5A_attr_iterate_table(const H5A_attr_table_t *atable, hsize_t skip,
for(; u < atable->nattrs && !ret_value; u++) {
/* Check which type of callback to make */
switch(attr_op->op_type) {
+ case H5A_ATTR_OP_APP2:
+ {
+ H5A_info_t ainfo; /* Info for attribute */
+
+ /* Get the attribute information */
+ if(H5A_get_info(&atable->attrs[u], &ainfo) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, H5_ITER_ERROR, "unable to get attribute info")
+
+ /* Make the application callback */
+ ret_value = (attr_op->u.app_op2)(loc_id, atable->attrs[u].name, &ainfo, op_data);
+ break;
+ }
+
case H5A_ATTR_OP_APP:
/* Make the application callback */
ret_value = (attr_op->u.app_op)(loc_id, atable->attrs[u].name, op_data);
@@ -556,6 +569,7 @@ H5A_attr_iterate_table(const H5A_attr_table_t *atable, hsize_t skip,
if(ret_value < 0)
HERROR(H5E_ATTR, H5E_CANTNEXT, "iteration operator failed");
+done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A_attr_iterate_table() */
diff --git a/src/H5Apkg.h b/src/H5Apkg.h
index c8d1938..261f7be 100644
--- a/src/H5Apkg.h
+++ b/src/H5Apkg.h
@@ -137,10 +137,12 @@ typedef herr_t (*H5A_lib_iterate_t)(const H5A_t *attr, void *op_data);
struct H5A_attr_iter_op_t {
enum {
H5A_ATTR_OP_APP, /* Application callback */
+ H5A_ATTR_OP_APP2, /* Revised application callback */
H5A_ATTR_OP_LIB /* Library internal callback */
} op_type;
union {
- H5A_operator_t app_op; /* Application callback for each attribute */
+ H5A_operator_t app_op; /* Application callback for each attribute */
+ H5A_operator2_t app_op2; /* Revised application callback for each attribute */
H5A_lib_iterate_t lib_op; /* Library internal callback for each attribute */
} u;
};
@@ -170,6 +172,7 @@ H5_DLLVAR const H5B2_class_t H5A_BT2_CORDER[1];
/* Function prototypes for H5A package scope */
H5_DLL herr_t H5A_init(void);
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);
@@ -218,9 +221,9 @@ H5_DLL herr_t H5O_attr_write(const H5O_loc_t *loc, hid_t dxpl_id,
H5A_t *attr);
H5_DLL herr_t H5O_attr_rename(const H5O_loc_t *loc, hid_t dxpl_id,
const char *old_name, const char *new_name);
-H5_DLL herr_t H5O_attr_iterate(hid_t loc_id, const H5O_loc_t *loc, hid_t dxpl_id,
- H5_index_t idx_type, H5_iter_order_t order, hsize_t skip,
- hsize_t *last_attr, const H5A_attr_iter_op_t *op, void *op_data);
+H5_DLL herr_t H5O_attr_iterate(hid_t loc_id, hid_t dxpl_id, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t skip, hsize_t *last_attr,
+ const H5A_attr_iter_op_t *op, void *op_data);
H5_DLL herr_t H5O_attr_remove(const H5O_loc_t *loc, const char *name,
hid_t dxpl_id);
H5_DLL herr_t H5O_attr_remove_by_idx(const H5O_loc_t *loc, H5_index_t idx_type,
diff --git a/src/H5Apublic.h b/src/H5Apublic.h
index 7268c73..8c97e46 100644
--- a/src/H5Apublic.h
+++ b/src/H5Apublic.h
@@ -36,10 +36,14 @@ typedef struct {
hsize_t data_size; /* Size of raw data */
} H5A_info_t;
-/* Typedef for H5Aiterate() callback */
+/* Typedef for H5Aiterate() callbacks */
typedef herr_t (*H5A_operator_t)(hid_t location_id/*in*/,
const char *attr_name/*in*/, void *operator_data/*in,out*/);
+/* Typedef for H5Aiterate2() callbacks */
+typedef herr_t (*H5A_operator2_t)(hid_t location_id/*in*/,
+ const char *attr_name/*in*/, const H5A_info_t *ainfo/*in*/, void *op_data/*in,out*/);
+
/* Public function prototypes */
H5_DLL hid_t H5Acreate(hid_t loc_id, const char *name, hid_t type_id,
hid_t space_id, hid_t plist_id);
@@ -62,8 +66,9 @@ 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);
+H5_DLL herr_t H5Aiterate2(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t *idx, H5A_operator2_t op, void *op_data,
+ hid_t lapd_id);
H5_DLL herr_t H5Adelete2(hid_t loc_id, const char *obj_name,
const char *attr_name, hid_t lapl_id);
H5_DLL herr_t H5Adelete_by_idx(hid_t loc_id, const char *obj_name,
@@ -75,6 +80,8 @@ H5_DLL herr_t H5Adelete_by_idx(hid_t loc_id, const char *obj_name,
* Use of these functions and variables is deprecated.
*/
H5_DLL int H5Aget_num_attrs(hid_t loc_id);
+H5_DLL herr_t H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op,
+ void *op_data);
H5_DLL herr_t H5Adelete(hid_t loc_id, const char *name);
#ifdef __cplusplus
diff --git a/src/H5Doh.c b/src/H5Doh.c
index 93a49c5..56cb565 100644
--- a/src/H5Doh.c
+++ b/src/H5Doh.c
@@ -43,7 +43,7 @@
static void *H5O_dset_get_copy_file_udata(void);
static void H5O_dset_free_copy_file_udata(void *);
static htri_t H5O_dset_isa(H5O_t *loc);
-static hid_t H5O_dset_open(H5G_loc_t *obj_loc, hid_t dxpl_id);
+static hid_t H5O_dset_open(const H5G_loc_t *obj_loc, hid_t dxpl_id);
static H5O_loc_t *H5O_dset_get_oloc(hid_t obj_id);
/*********************/
@@ -208,7 +208,7 @@ done:
*-------------------------------------------------------------------------
*/
static hid_t
-H5O_dset_open(H5G_loc_t *obj_loc, hid_t dxpl_id)
+H5O_dset_open(const H5G_loc_t *obj_loc, hid_t dxpl_id)
{
H5D_t *dset = NULL; /* Dataset opened */
hid_t ret_value; /* Return value */
diff --git a/src/H5G.c b/src/H5G.c
index 7ed94c4..4159bf2 100644
--- a/src/H5G.c
+++ b/src/H5G.c
@@ -1177,7 +1177,7 @@ done:
*-------------------------------------------------------------------------
*/
H5G_t *
-H5G_open(H5G_loc_t *loc, hid_t dxpl_id)
+H5G_open(const H5G_loc_t *loc, hid_t dxpl_id)
{
H5G_t *grp = NULL;
H5G_shared_t *shared_fo = NULL;
diff --git a/src/H5Goh.c b/src/H5Goh.c
index 49dae84..6ea3a00 100644
--- a/src/H5Goh.c
+++ b/src/H5Goh.c
@@ -42,7 +42,7 @@
/********************/
static htri_t H5O_group_isa(H5O_t *loc);
-static hid_t H5O_group_open(H5G_loc_t *obj_loc, hid_t dxpl_id);
+static hid_t H5O_group_open(const H5G_loc_t *obj_loc, hid_t dxpl_id);
static H5O_loc_t *H5O_group_get_oloc(hid_t obj_id);
/*********************/
@@ -126,7 +126,7 @@ done:
*-------------------------------------------------------------------------
*/
static hid_t
-H5O_group_open(H5G_loc_t *obj_loc, hid_t dxpl_id)
+H5O_group_open(const H5G_loc_t *obj_loc, hid_t dxpl_id)
{
H5G_t *grp = NULL; /* Group opened */
hid_t ret_value; /* Return value */
diff --git a/src/H5Gprivate.h b/src/H5Gprivate.h
index a432c4e..934933e 100644
--- a/src/H5Gprivate.h
+++ b/src/H5Gprivate.h
@@ -150,7 +150,7 @@ H5_DLL H5G_t *H5G_rootof(H5F_t *f);
H5_DLL H5G_name_t * H5G_nameof(H5G_t *grp);
H5_DLL H5F_t *H5G_fileof(H5G_t *grp);
H5_DLL herr_t H5G_free(H5G_t *grp);
-H5_DLL H5G_t *H5G_open(H5G_loc_t *loc, hid_t dxpl_id);
+H5_DLL H5G_t *H5G_open(const H5G_loc_t *loc, hid_t dxpl_id);
H5_DLL herr_t H5G_close(H5G_t *grp);
H5_DLL herr_t H5G_insertion_loc(H5G_loc_t *src_loc, const char *name,
H5G_loc_t *insertion_loc/*out*/, hid_t dxpl_id);
diff --git a/src/H5O.c b/src/H5O.c
index 757337d..a8ff348 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -67,9 +67,8 @@
/* Local Prototypes */
/********************/
-static hid_t H5O_open_by_loc(H5G_loc_t *obj_loc, hid_t dxpl_id);
static herr_t H5O_delete_oh(H5F_t *f, hid_t dxpl_id, H5O_t *oh);
-static const H5O_obj_class_t *H5O_obj_class(H5O_loc_t *loc, hid_t dxpl_id);
+static const H5O_obj_class_t *H5O_obj_class(const H5O_loc_t *loc, hid_t dxpl_id);
static herr_t H5O_obj_type_real(H5O_t *oh, H5O_type_t *obj_type);
@@ -823,13 +822,13 @@ done:
*
*-------------------------------------------------------------------------
*/
-static hid_t
-H5O_open_by_loc(H5G_loc_t *obj_loc, hid_t dxpl_id)
+hid_t
+H5O_open_by_loc(const H5G_loc_t *obj_loc, hid_t dxpl_id)
{
const H5O_obj_class_t *obj_class; /* Class of object for location */
hid_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5O_open_by_loc)
+ FUNC_ENTER_NOAPI(H5O_open_by_loc, FAIL)
HDassert(obj_loc);
@@ -1496,7 +1495,7 @@ done:
*-------------------------------------------------------------------------
*/
static const H5O_obj_class_t *
-H5O_obj_class(H5O_loc_t *loc, hid_t dxpl_id)
+H5O_obj_class(const H5O_loc_t *loc, hid_t dxpl_id)
{
H5O_t *oh = NULL; /* Object header for location */
const H5O_obj_class_t *ret_value; /* Return value */
diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c
index e3140cd..ea0f073 100644
--- a/src/H5Oattribute.c
+++ b/src/H5Oattribute.c
@@ -125,6 +125,9 @@ typedef struct {
/********************/
/* Local Prototypes */
/********************/
+static herr_t H5O_attr_iterate_real(hid_t loc_id, const H5O_loc_t *loc,
+ hid_t dxpl_id, H5_index_t idx_type, H5_iter_order_t order, hsize_t skip,
+ hsize_t *last_attr, const H5A_attr_iter_op_t *attr_op, void *op_data);
/*********************/
@@ -494,7 +497,7 @@ H5O_attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type,
attr_op.u.lib_op = H5O_attr_open_by_idx_cb;
/* Iterate over attributes to locate correct one */
- if(H5O_attr_iterate((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")
done:
@@ -940,9 +943,9 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5O_attr_iterate
+ * Function: H5O_attr_iterate_real
*
- * Purpose: Iterate over attributes for an object.
+ * Purpose: Internal routine to iterate over attributes for an object.
*
* Return: Non-negative on success/Negative on failure
*
@@ -951,20 +954,22 @@ done:
*
*-------------------------------------------------------------------------
*/
-herr_t
-H5O_attr_iterate(hid_t loc_id, const H5O_loc_t *loc, hid_t dxpl_id,
+static herr_t
+H5O_attr_iterate_real(hid_t loc_id, const H5O_loc_t *loc, hid_t dxpl_id,
H5_index_t idx_type, H5_iter_order_t order, hsize_t skip,
hsize_t *last_attr, const H5A_attr_iter_op_t *attr_op, void *op_data)
{
H5O_t *oh = NULL; /* Pointer to actual 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 */
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5O_attr_iterate)
+ FUNC_ENTER_NOAPI_NOINIT(H5O_attr_iterate_real)
/* Check arguments */
HDassert(loc);
+ HDassert(loc->file);
+ HDassert(H5F_addr_defined(loc->addr));
HDassert(attr_op);
/* Protect the object header to iterate over */
@@ -1024,7 +1029,45 @@ done:
HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "unable to release attribute table")
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5O_attr_iterate */
+} /* end H5O_attr_iterate_real() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5O_attr_iterate
+ *
+ * Purpose: Iterate over attributes for an object.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Tuesday, December 5, 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5O_attr_iterate(hid_t loc_id, hid_t dxpl_id,
+ H5_index_t idx_type, H5_iter_order_t order, hsize_t skip,
+ hsize_t *last_attr, const H5A_attr_iter_op_t *attr_op, void *op_data)
+{
+ H5G_loc_t loc; /* Object location */
+ herr_t ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5O_attr_iterate)
+
+ /* Check arguments */
+ HDassert(attr_op);
+
+ /* Look up location for location ID */
+ if(H5G_loc(loc_id, &loc) < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
+
+ /* Iterate over attributes to locate correct one */
+ if((ret_value = H5O_attr_iterate_real(loc_id, loc.oloc, dxpl_id, idx_type, order, skip, last_attr, attr_op, op_data)) < 0)
+ HERROR(H5E_ATTR, H5E_BADITER, "error iterating over attributes");
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5O_attr_iterate() */
/*-------------------------------------------------------------------------
diff --git a/src/H5Opkg.h b/src/H5Opkg.h
index 29c9052..d8e63dc 100644
--- a/src/H5Opkg.h
+++ b/src/H5Opkg.h
@@ -276,7 +276,7 @@ typedef struct H5O_obj_class_t {
void *(*get_copy_file_udata)(void); /*retrieve user data for 'copy file' operation */
void (*free_copy_file_udata)(void *); /*free user data for 'copy file' operation */
htri_t (*isa)(H5O_t *); /*if a header matches an object class */
- hid_t (*open)(H5G_loc_t *, hid_t ); /*open an object of this class */
+ hid_t (*open)(const H5G_loc_t *, hid_t ); /*open an object of this class */
H5O_loc_t *(*get_oloc)(hid_t ); /*get the object header location for an object */
} H5O_obj_class_t;
@@ -427,6 +427,7 @@ H5_DLLVAR const H5O_obj_class_t H5O_OBJ_DATATYPE[1];
/* Package-local function prototypes */
H5_DLL herr_t H5O_flush_msgs(H5F_t *f, H5O_t *oh);
+H5_DLL hid_t H5O_open_by_loc(const H5G_loc_t *obj_loc, hid_t dxpl_id);
H5_DLL herr_t H5O_delete_mesg(H5F_t *f, hid_t dxpl_id, H5O_mesg_t *mesg);
H5_DLL const H5O_obj_class_t *H5O_obj_class_real(H5O_t *oh);
diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c
index fe1d9f3..dd92fd3 100644
--- a/src/H5Tcommit.c
+++ b/src/H5Tcommit.c
@@ -37,7 +37,7 @@
/* Static local functions */
static herr_t H5T_commit(H5F_t *file, H5T_t *type,
hid_t dxpl_id, hid_t tcpl_id, hid_t tapl_id);
-static H5T_t *H5T_open_oid(H5G_loc_t *loc, hid_t dxpl_id);
+static H5T_t *H5T_open_oid(const H5G_loc_t *loc, hid_t dxpl_id);
/*--------------------------------------------------------------------------
@@ -667,7 +667,7 @@ done:
*-------------------------------------------------------------------------
*/
H5T_t *
-H5T_open(H5G_loc_t *loc, hid_t dxpl_id)
+H5T_open(const H5G_loc_t *loc, hid_t dxpl_id)
{
H5T_shared_t *shared_fo = NULL;
H5T_t *dt = NULL;
@@ -776,7 +776,7 @@ done:
*-------------------------------------------------------------------------
*/
static H5T_t *
-H5T_open_oid(H5G_loc_t *loc, hid_t dxpl_id)
+H5T_open_oid(const H5G_loc_t *loc, hid_t dxpl_id)
{
H5T_t *dt = NULL;
H5T_t *ret_value;
diff --git a/src/H5Toh.c b/src/H5Toh.c
index 73e6c24..2c952e1 100644
--- a/src/H5Toh.c
+++ b/src/H5Toh.c
@@ -43,7 +43,7 @@
/********************/
static htri_t H5O_dtype_isa(H5O_t *loc);
-static hid_t H5O_dtype_open(H5G_loc_t *obj_loc, hid_t dxpl_id);
+static hid_t H5O_dtype_open(const H5G_loc_t *obj_loc, hid_t dxpl_id);
static H5O_loc_t *H5O_dtype_get_oloc(hid_t obj_id);
@@ -121,7 +121,7 @@ done:
*-------------------------------------------------------------------------
*/
static hid_t
-H5O_dtype_open(H5G_loc_t *obj_loc, hid_t dxpl_id)
+H5O_dtype_open(const H5G_loc_t *obj_loc, hid_t dxpl_id)
{
H5T_t *type = NULL; /* Datatype opened */
hid_t ret_value; /* Return value */
diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h
index 759f7af..9ab7566 100644
--- a/src/H5Tprivate.h
+++ b/src/H5Tprivate.h
@@ -103,7 +103,7 @@ H5_DLL uint32_t H5T_hash(H5F_t * file, const H5T_t *dt);
H5_DLL H5R_type_t H5T_get_ref_type(const H5T_t *dt);
/* Operations on named datatypes */
-H5_DLL H5T_t *H5T_open(H5G_loc_t *loc, hid_t dxpl_id);
+H5_DLL H5T_t *H5T_open(const H5G_loc_t *loc, hid_t dxpl_id);
H5_DLL htri_t H5T_committed(const H5T_t *type);
H5_DLL int H5T_link(const H5T_t *type, int adjust, hid_t dxpl_id);
diff --git a/test/tattr.c b/test/tattr.c
index 3e5ab19..78e4f90 100644
--- a/test/tattr.c
+++ b/test/tattr.c
@@ -3981,6 +3981,14 @@ test_attr_info_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
sid = H5Screate(H5S_SCALAR);
CHECK(sid, FAIL, "H5Screate");
+ /* Create dataset creation property list */
+ dcpl = H5Pcreate(H5P_DATASET_CREATE);
+ CHECK(dcpl, FAIL, "H5Pcreate");
+
+ /* Query the attribute creation properties */
+ ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
+ CHECK(ret, FAIL, "H5Pget_attr_phase_change");
+
/* Loop over using index for creation order value */
for(use_index = FALSE; use_index <= TRUE; use_index++) {
/* Output message about test being performed */
@@ -3993,18 +4001,10 @@ test_attr_info_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
CHECK(fid, FAIL, "H5Fcreate");
- /* Create dataset creation property list */
- dcpl = H5Pcreate(H5P_DATASET_CREATE);
- CHECK(dcpl, FAIL, "H5Pcreate");
-
/* Set attribute creation order tracking & indexing for object */
ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | (use_index ? H5P_CRT_ORDER_INDEXED : (unsigned)0)));
CHECK(ret, FAIL, "H5Pset_attr_creation_order");
- /* Query the attribute creation properties */
- ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
- CHECK(ret, FAIL, "H5Pget_attr_phase_change");
-
/* Create datasets */
dset1 = H5Dcreate(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, dcpl);
CHECK(dset1, FAIL, "H5Dcreate");
@@ -4013,10 +4013,6 @@ test_attr_info_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
dset3 = H5Dcreate(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, dcpl);
CHECK(dset3, FAIL, "H5Dcreate");
- /* Close property list */
- ret = H5Pclose(dcpl);
- CHECK(ret, FAIL, "H5Pclose");
-
/* Work on all the datasets */
for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
switch(curr_dset) {
@@ -4148,6 +4144,14 @@ test_attr_info_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
} /* end for */
+
+ /* Close property list */
+ ret = H5Pclose(dcpl);
+ CHECK(ret, FAIL, "H5Pclose");
+
+ /* Close dataspace */
+ ret = H5Sclose(sid);
+ CHECK(ret, FAIL, "H5Sclose");
} /* test_attr_info_by_idx() */
/****************************************************************
@@ -4186,6 +4190,14 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
sid = H5Screate(H5S_SCALAR);
CHECK(sid, FAIL, "H5Screate");
+ /* Create dataset creation property list */
+ dcpl = H5Pcreate(H5P_DATASET_CREATE);
+ CHECK(dcpl, FAIL, "H5Pcreate");
+
+ /* Query the attribute creation properties */
+ ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
+ CHECK(ret, FAIL, "H5Pget_attr_phase_change");
+
/* Loop over operating on different indices on link fields */
for(idx_type = H5_INDEX_NAME; idx_type <=H5_INDEX_CRT_ORDER; idx_type++) {
/* Loop over operating in different orders */
@@ -4226,18 +4238,10 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
CHECK(fid, FAIL, "H5Fcreate");
- /* Create dataset creation property list */
- dcpl = H5Pcreate(H5P_DATASET_CREATE);
- CHECK(dcpl, FAIL, "H5Pcreate");
-
/* Set attribute creation order tracking & indexing for object */
ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | (use_index ? H5P_CRT_ORDER_INDEXED : (unsigned)0)));
CHECK(ret, FAIL, "H5Pset_attr_creation_order");
- /* Query the attribute creation properties */
- ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
- CHECK(ret, FAIL, "H5Pget_attr_phase_change");
-
/* Create datasets */
dset1 = H5Dcreate(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, dcpl);
CHECK(dset1, FAIL, "H5Dcreate");
@@ -4246,10 +4250,6 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
dset3 = H5Dcreate(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, dcpl);
CHECK(dset3, FAIL, "H5Dcreate");
- /* Close property list */
- ret = H5Pclose(dcpl);
- CHECK(ret, FAIL, "H5Pclose");
-
/* Work on all the datasets */
for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
switch(curr_dset) {
@@ -4311,6 +4311,26 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
/* Check for out of bound deletions */
ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT);
VERIFY(ret, FAIL, "H5Adelete_by_idx");
+ } /* end for */
+
+ /* Work on all the datasets */
+ for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
+ switch(curr_dset) {
+ case 0:
+ my_dataset = dset1;
+ break;
+
+ case 1:
+ my_dataset = dset2;
+ break;
+
+ case 2:
+ my_dataset = dset3;
+ break;
+
+ default:
+ HDassert(0 && "Too many datasets!");
+ } /* end switch */
/* Delete attributes from compact storage */
for(u = 0; u < (max_compact - 1); u++) {
@@ -4348,6 +4368,26 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
/* Verify state of attribute storage (empty) */
is_empty = H5O_is_attr_empty_test(my_dataset);
VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
+ } /* end for */
+
+ /* Work on all the datasets */
+ for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
+ switch(curr_dset) {
+ case 0:
+ my_dataset = dset1;
+ break;
+
+ case 1:
+ my_dataset = dset2;
+ break;
+
+ case 2:
+ my_dataset = dset3;
+ break;
+
+ default:
+ HDassert(0 && "Too many datasets!");
+ } /* end switch */
/* Create more attributes, to push into dense form */
for(u = 0; u < (max_compact * 2); u++) {
@@ -4396,6 +4436,26 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
/* Check for out of bound deletion */
ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT);
VERIFY(ret, FAIL, "H5Adelete_by_idx");
+ } /* end for */
+
+ /* Work on all the datasets */
+ for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
+ switch(curr_dset) {
+ case 0:
+ my_dataset = dset1;
+ break;
+
+ case 1:
+ my_dataset = dset2;
+ break;
+
+ case 2:
+ my_dataset = dset3;
+ break;
+
+ default:
+ HDassert(0 && "Too many datasets!");
+ } /* end switch */
/* Delete attributes from dense storage */
for(u = 0; u < ((max_compact * 2) - 1); u++) {
@@ -4437,11 +4497,31 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
/* Check for deletion on empty attribute storage again */
ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
VERIFY(ret, FAIL, "H5Adelete_by_idx");
+ } /* end for */
/* Delete attributes in middle */
+ /* Work on all the datasets */
+ for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
+ switch(curr_dset) {
+ case 0:
+ my_dataset = dset1;
+ break;
+
+ case 1:
+ my_dataset = dset2;
+ break;
+
+ case 2:
+ my_dataset = dset3;
+ break;
+
+ default:
+ HDassert(0 && "Too many datasets!");
+ } /* end switch */
+
/* Create attributes, to push into dense form */
for(u = 0; u < (max_compact * 2); u++) {
/* Create attribute */
@@ -4467,6 +4547,26 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
CHECK(ret, FAIL, "attr_info_by_idx_check");
} /* end for */
+ } /* end for */
+
+ /* Work on all the datasets */
+ for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
+ switch(curr_dset) {
+ case 0:
+ my_dataset = dset1;
+ break;
+
+ case 1:
+ my_dataset = dset2;
+ break;
+
+ case 2:
+ my_dataset = dset3;
+ break;
+
+ default:
+ HDassert(0 && "Too many datasets!");
+ } /* end switch */
/* Delete every other attribute from dense storage, in appropriate order */
for(u = 0; u < max_compact; u++) {
@@ -4496,6 +4596,26 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
ret = HDstrcmp(attrname, tmpname);
VERIFY(ret, 0, "H5Aget_name_by_idx");
} /* end for */
+ } /* end for */
+
+ /* Work on all the datasets */
+ for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
+ switch(curr_dset) {
+ case 0:
+ my_dataset = dset1;
+ break;
+
+ case 1:
+ my_dataset = dset2;
+ break;
+
+ case 2:
+ my_dataset = dset3;
+ break;
+
+ default:
+ HDassert(0 && "Too many datasets!");
+ } /* end switch */
/* Delete remaining attributes from dense storage, in appropriate order */
for(u = 0; u < (max_compact - 1); u++) {
@@ -4553,10 +4673,469 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
} /* end for */
} /* end for */
} /* end for */
+
+ /* Close property list */
+ ret = H5Pclose(dcpl);
+ CHECK(ret, FAIL, "H5Pclose");
+
+ /* Close dataspace */
+ ret = H5Sclose(sid);
+ CHECK(ret, FAIL, "H5Sclose");
} /* test_attr_delete_by_idx() */
/****************************************************************
**
+** attr_op2(): Revised attribute operator
+**
+****************************************************************/
+herr_t
+attr_op2(hid_t UNUSED loc_id, const char *name, const H5A_info_t *ainfo, void *op_data)
+{
+ int *count = (int *)op_data;
+ herr_t ret = 0;
+
+#ifdef QAK
+ switch(*count) {
+ case 0:
+ if(HDstrcmp(name,ATTR1_NAME))
+ TestErrPrintf("attribute name different: name=%s, should be %s\n",name,ATTR1_NAME);
+ (*count)++;
+ break;
+
+ case 1:
+ if(HDstrcmp(name,ATTR2_NAME))
+ TestErrPrintf("attribute name different: name=%s, should be %s\n",name,ATTR2_NAME);
+ (*count)++;
+ break;
+
+ case 2:
+ if(HDstrcmp(name,ATTR3_NAME))
+ TestErrPrintf("attribute name different: name=%s, should be %s\n",name,ATTR3_NAME);
+ (*count)++;
+ break;
+
+ default:
+ ret=-1;
+ break;
+ } /* end switch() */
+#endif /* QAK */
+
+ return(ret);
+} /* end attr_op2() */
+
+/****************************************************************
+**
+** test_attr_iterate_by_idx(): Test basic H5A (attribute) code.
+** Tests iterating over attributes by index
+**
+****************************************************************/
+static void
+test_attr_iterate_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
+{
+ hid_t fid; /* HDF5 File ID */
+ hid_t dset1, dset2, dset3; /* Dataset IDs */
+ hid_t my_dataset; /* Current dataset ID */
+ hid_t sid; /* Dataspace ID */
+ hid_t attr; /* Attribute ID */
+ hid_t dcpl; /* Dataset creation property list ID */
+ H5A_info_t ainfo; /* Attribute information */
+ unsigned max_compact; /* Maximum # of links to store in group compactly */
+ unsigned min_dense; /* Minimum # of links to store in group "densely" */
+ htri_t is_empty; /* Are there any attributes? */
+ htri_t is_dense; /* Are attributes stored densely? */
+ hsize_t nattrs; /* Number of attributes on object */
+ hsize_t name_count; /* # of records in name index */
+ hsize_t corder_count; /* # of records in creation order index */
+ H5_index_t idx_type; /* Type of index to operate on */
+ H5_iter_order_t order; /* Order within in the index */
+ hbool_t use_index; /* Use index on creation order values */
+ char attrname[NAME_BUF_SIZE]; /* Name of attribute */
+ char tmpname[NAME_BUF_SIZE]; /* Temporary attribute name */
+ unsigned curr_dset; /* Current dataset to work on */
+ unsigned u; /* Local index variable */
+ herr_t ret; /* Generic return value */
+
+ /* Create dataspace for dataset & attributes */
+ sid = H5Screate(H5S_SCALAR);
+ CHECK(sid, FAIL, "H5Screate");
+
+ /* Create dataset creation property list */
+ dcpl = H5Pcreate(H5P_DATASET_CREATE);
+ CHECK(dcpl, FAIL, "H5Pcreate");
+
+ /* Query the attribute creation properties */
+ ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
+ CHECK(ret, FAIL, "H5Pget_attr_phase_change");
+
+ /* Loop over operating on different indices on link fields */
+ for(idx_type = H5_INDEX_NAME; idx_type <=H5_INDEX_CRT_ORDER; idx_type++) {
+ /* Loop over operating in different orders */
+ for(order = H5_ITER_INC; order <=H5_ITER_DEC; order++) {
+ /* Loop over using index for creation order value */
+ for(use_index = FALSE; use_index <= TRUE; use_index++) {
+ /* Print appropriate test message */
+ if(idx_type == H5_INDEX_CRT_ORDER) {
+ if(order == H5_ITER_INC) {
+ if(use_index)
+ MESSAGE(5, ("Testing Iterating over Attributes By Creation Order Index in Increasing Order w/Creation Order Index\n"))
+ else
+ MESSAGE(5, ("Testing Iterating over Attributes By Creation Order Index in Increasing Order w/o Creation Order Index\n"))
+ } /* end if */
+ else {
+ if(use_index)
+ MESSAGE(5, ("Testing Iterating over Attributes By Creation Order Index in Decreasing Order w/Creation Order Index\n"))
+ else
+ MESSAGE(5, ("Testing Iterating over Attributes By Creation Order Index in Decreasing Order w/o Creation Order Index\n"))
+ } /* end else */
+ } /* end if */
+ else {
+ if(order == H5_ITER_INC) {
+ if(use_index)
+ MESSAGE(5, ("Testing Iterating over Attributes By Name Index in Increasing Order w/Creation Order Index\n"))
+ else
+ MESSAGE(5, ("Testing Iterating over Attributes By Name Index in Increasing Order w/o Creation Order Index\n"))
+ } /* end if */
+ else {
+ if(use_index)
+ MESSAGE(5, ("Testing Iterating over Attributes By Name Index in Decreasing Order w/Creation Order Index\n"))
+ else
+ MESSAGE(5, ("Testing Iterating over Attributes By Name Index in Decreasing Order w/o Creation Order Index\n"))
+ } /* end else */
+ } /* end else */
+
+ /* Create file */
+ fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
+ CHECK(fid, FAIL, "H5Fcreate");
+
+ /* Set attribute creation order tracking & indexing for object */
+ ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | (use_index ? H5P_CRT_ORDER_INDEXED : (unsigned)0)));
+ CHECK(ret, FAIL, "H5Pset_attr_creation_order");
+
+ /* Create datasets */
+ dset1 = H5Dcreate(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, dcpl);
+ CHECK(dset1, FAIL, "H5Dcreate");
+ dset2 = H5Dcreate(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, dcpl);
+ CHECK(dset2, FAIL, "H5Dcreate");
+ dset3 = H5Dcreate(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, dcpl);
+ CHECK(dset3, FAIL, "H5Dcreate");
+
+ /* Work on all the datasets */
+ for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
+ switch(curr_dset) {
+ case 0:
+ my_dataset = dset1;
+ break;
+
+ case 1:
+ my_dataset = dset2;
+ break;
+
+ case 2:
+ my_dataset = dset3;
+ break;
+
+ default:
+ HDassert(0 && "Too many datasets!");
+ } /* end switch */
+
+ /* Check on dataset's attribute storage status */
+ is_empty = H5O_is_attr_empty_test(my_dataset);
+ VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
+ is_dense = H5O_is_attr_dense_test(my_dataset);
+ VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
+
+ /* Check for iterating over object with no attributes (should be OK) */
+ ret = H5Aiterate2(my_dataset, ".", idx_type, order, NULL, attr_op2, NULL, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Aiterate2");
+
+#ifdef NOT_YET
+ /* Create attributes, up to limit of compact form */
+ for(u = 0; u < max_compact; u++) {
+ /* Create attribute */
+ sprintf(attrname, "attr %02u", u);
+ attr = H5Acreate(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT);
+ CHECK(attr, FAIL, "H5Acreate");
+
+ /* Write data into the attribute */
+ ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
+ CHECK(ret, FAIL, "H5Awrite");
+
+ /* Close attribute */
+ ret = H5Aclose(attr);
+ CHECK(ret, FAIL, "H5Aclose");
+
+ /* Verify information for new attribute */
+ ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
+ CHECK(ret, FAIL, "attr_info_by_idx_check");
+ } /* end for */
+
+ /* Verify state of object */
+ ret = H5O_num_attrs_test(my_dataset, &nattrs);
+ CHECK(ret, FAIL, "H5O_num_attrs_test");
+ VERIFY(nattrs, max_compact, "H5O_num_attrs_test");
+ is_empty = H5O_is_attr_empty_test(my_dataset);
+ VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
+ is_dense = H5O_is_attr_dense_test(my_dataset);
+ VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
+
+ /* Check for out of bound deletions */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT);
+ VERIFY(ret, FAIL, "H5Adelete_by_idx");
+
+ /* Delete attributes from compact storage */
+ for(u = 0; u < (max_compact - 1); u++) {
+ /* Delete first attribute in appropriate order */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Adelete_by_idx");
+
+ /* Verify the attribute information for first attribute in appropriate order */
+ HDmemset(&ainfo, 0, sizeof(ainfo));
+ ret = H5Aget_info_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, &ainfo, H5P_DEFAULT);
+ if(new_format) {
+ if(order == H5_ITER_INC) {
+ VERIFY(ainfo.corder, (u + 1), "H5Aget_info_by_idx");
+ } /* end if */
+ else {
+ VERIFY(ainfo.corder, (max_compact - (u + 2)), "H5Aget_info_by_idx");
+ } /* end else */
+ } /* end if */
+
+ /* Verify the name for first attribute in appropriate order */
+ HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
+ ret = H5Aget_name_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
+ if(order == H5_ITER_INC)
+ sprintf(attrname, "attr %02u", (u + 1));
+ else
+ sprintf(attrname, "attr %02u", (max_compact - (u + 2)));
+ ret = HDstrcmp(attrname, tmpname);
+ VERIFY(ret, 0, "H5Aget_name_by_idx");
+ } /* end for */
+
+ /* Delete last attribute */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Adelete_by_idx");
+
+ /* Verify state of attribute storage (empty) */
+ is_empty = H5O_is_attr_empty_test(my_dataset);
+ VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
+
+ /* Create more attributes, to push into dense form */
+ for(u = 0; u < (max_compact * 2); u++) {
+ /* Create attribute */
+ sprintf(attrname, "attr %02u", u);
+ attr = H5Acreate(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT);
+ CHECK(attr, FAIL, "H5Acreate");
+
+ /* Write data into the attribute */
+ ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
+ CHECK(ret, FAIL, "H5Awrite");
+
+ /* Close attribute */
+ ret = H5Aclose(attr);
+ CHECK(ret, FAIL, "H5Aclose");
+
+ /* Verify state of object */
+ if(u >= max_compact) {
+ is_dense = H5O_is_attr_dense_test(my_dataset);
+ VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
+ } /* end if */
+
+ /* Verify information for new attribute */
+ ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
+ CHECK(ret, FAIL, "attr_info_by_idx_check");
+ } /* end for */
+
+ /* Verify state of object */
+ ret = H5O_num_attrs_test(my_dataset, &nattrs);
+ CHECK(ret, FAIL, "H5O_num_attrs_test");
+ VERIFY(nattrs, (max_compact * 2), "H5O_num_attrs_test");
+ is_empty = H5O_is_attr_empty_test(my_dataset);
+ VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
+ is_dense = H5O_is_attr_dense_test(my_dataset);
+ VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
+
+ if(new_format) {
+ /* Retrieve & verify # of records in the name & creation order indices */
+ ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
+ CHECK(ret, FAIL, "H5O_attr_dense_info_test");
+ if(use_index)
+ VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
+ VERIFY(name_count, (max_compact * 2), "H5O_attr_dense_info_test");
+ } /* end if */
+
+ /* Check for out of bound deletion */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT);
+ VERIFY(ret, FAIL, "H5Adelete_by_idx");
+
+ /* Delete attributes from dense storage */
+ for(u = 0; u < ((max_compact * 2) - 1); u++) {
+ /* Delete first attribute in appropriate order */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Adelete_by_idx");
+
+ /* Verify the attribute information for first attribute in appropriate order */
+ HDmemset(&ainfo, 0, sizeof(ainfo));
+ ret = H5Aget_info_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, &ainfo, H5P_DEFAULT);
+ if(new_format) {
+ if(order == H5_ITER_INC) {
+ VERIFY(ainfo.corder, (u + 1), "H5Aget_info_by_idx");
+ } /* end if */
+ else {
+ VERIFY(ainfo.corder, ((max_compact * 2) - (u + 2)), "H5Aget_info_by_idx");
+ } /* end else */
+ } /* end if */
+
+ /* Verify the name for first attribute in appropriate order */
+ HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
+ ret = H5Aget_name_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
+ if(order == H5_ITER_INC)
+ sprintf(attrname, "attr %02u", (u + 1));
+ else
+ sprintf(attrname, "attr %02u", ((max_compact * 2) - (u + 2)));
+ ret = HDstrcmp(attrname, tmpname);
+ VERIFY(ret, 0, "H5Aget_name_by_idx");
+ } /* end for */
+
+ /* Delete last attribute */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Adelete_by_idx");
+
+ /* Verify state of attribute storage (empty) */
+ is_empty = H5O_is_attr_empty_test(my_dataset);
+ VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
+
+ /* Check for deletion on empty attribute storage again */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
+ VERIFY(ret, FAIL, "H5Adelete_by_idx");
+
+
+ /* Delete attributes in middle */
+
+
+ /* Create attributes, to push into dense form */
+ for(u = 0; u < (max_compact * 2); u++) {
+ /* Create attribute */
+ sprintf(attrname, "attr %02u", u);
+ attr = H5Acreate(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT);
+ CHECK(attr, FAIL, "H5Acreate");
+
+ /* Write data into the attribute */
+ ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
+ CHECK(ret, FAIL, "H5Awrite");
+
+ /* Close attribute */
+ ret = H5Aclose(attr);
+ CHECK(ret, FAIL, "H5Aclose");
+
+ /* Verify state of object */
+ if(u >= max_compact) {
+ is_dense = H5O_is_attr_dense_test(my_dataset);
+ VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
+ } /* end if */
+
+ /* Verify information for new attribute */
+ ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
+ CHECK(ret, FAIL, "attr_info_by_idx_check");
+ } /* end for */
+
+ /* Delete every other attribute from dense storage, in appropriate order */
+ for(u = 0; u < max_compact; u++) {
+ /* Delete attribute */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Adelete_by_idx");
+
+ /* Verify the attribute information for first attribute in appropriate order */
+ HDmemset(&ainfo, 0, sizeof(ainfo));
+ ret = H5Aget_info_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, &ainfo, H5P_DEFAULT);
+ if(new_format) {
+ if(order == H5_ITER_INC) {
+ VERIFY(ainfo.corder, ((u * 2) + 1), "H5Aget_info_by_idx");
+ } /* end if */
+ else {
+ VERIFY(ainfo.corder, ((max_compact * 2) - ((u * 2) + 2)), "H5Aget_info_by_idx");
+ } /* end else */
+ } /* end if */
+
+ /* Verify the name for first attribute in appropriate order */
+ HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
+ ret = H5Aget_name_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
+ if(order == H5_ITER_INC)
+ sprintf(attrname, "attr %02u", ((u * 2) + 1));
+ else
+ sprintf(attrname, "attr %02u", ((max_compact * 2) - ((u * 2) + 2)));
+ ret = HDstrcmp(attrname, tmpname);
+ VERIFY(ret, 0, "H5Aget_name_by_idx");
+ } /* end for */
+
+ /* Delete remaining attributes from dense storage, in appropriate order */
+ for(u = 0; u < (max_compact - 1); u++) {
+ /* Delete attribute */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Adelete_by_idx");
+
+ /* Verify the attribute information for first attribute in appropriate order */
+ HDmemset(&ainfo, 0, sizeof(ainfo));
+ ret = H5Aget_info_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, &ainfo, H5P_DEFAULT);
+ if(new_format) {
+ if(order == H5_ITER_INC) {
+ VERIFY(ainfo.corder, ((u * 2) + 3), "H5Aget_info_by_idx");
+ } /* end if */
+ else {
+ VERIFY(ainfo.corder, ((max_compact * 2) - ((u * 2) + 4)), "H5Aget_info_by_idx");
+ } /* end else */
+ } /* end if */
+
+ /* Verify the name for first attribute in appropriate order */
+ HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
+ ret = H5Aget_name_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
+ if(order == H5_ITER_INC)
+ sprintf(attrname, "attr %02u", ((u * 2) + 3));
+ else
+ sprintf(attrname, "attr %02u", ((max_compact * 2) - ((u * 2) + 4)));
+ ret = HDstrcmp(attrname, tmpname);
+ VERIFY(ret, 0, "H5Aget_name_by_idx");
+ } /* end for */
+
+ /* Delete last attribute */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
+ CHECK(ret, FAIL, "H5Adelete_by_idx");
+
+ /* Verify state of attribute storage (empty) */
+ is_empty = H5O_is_attr_empty_test(my_dataset);
+ VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
+
+ /* Check for deletion on empty attribute storage again */
+ ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
+ VERIFY(ret, FAIL, "H5Adelete_by_idx");
+#endif /* NOT_YET */
+ } /* end for */
+
+ /* Close Datasets */
+ ret = H5Dclose(dset1);
+ CHECK(ret, FAIL, "H5Dclose");
+ ret = H5Dclose(dset2);
+ CHECK(ret, FAIL, "H5Dclose");
+ ret = H5Dclose(dset3);
+ CHECK(ret, FAIL, "H5Dclose");
+
+ /* Close file */
+ ret = H5Fclose(fid);
+ CHECK(ret, FAIL, "H5Fclose");
+ } /* end for */
+ } /* end for */
+ } /* end for */
+
+ /* Close property list */
+ ret = H5Pclose(dcpl);
+ CHECK(ret, FAIL, "H5Pclose");
+
+ /* Close dataspace */
+ ret = H5Sclose(sid);
+ CHECK(ret, FAIL, "H5Sclose");
+} /* test_attr_iterate_by_idx() */
+
+/****************************************************************
+**
** test_attr_shared_write(): Test basic H5A (attribute) code.
** Tests writing mix of shared & un-shared attributes in "compact" & "dense" storage
**
@@ -6168,6 +6747,7 @@ test_attr(void)
/* New attribute API routine tests */
test_attr_info_by_idx(new_format, my_fcpl, my_fapl); /* Test querying attribute info by index */
test_attr_delete_by_idx(new_format, my_fcpl, my_fapl); /* Test deleting attribute by index */
+ test_attr_iterate_by_idx(new_format, my_fcpl, my_fapl); /* Test iterating over attributes by index */
/* More complex tests with both "new format" and "shared" attributes */
if(use_shared == TRUE) {
@@ -6182,6 +6762,7 @@ test_attr(void)
/* New attribute API routine tests, on old-format storage */
test_attr_info_by_idx(new_format, fcpl, my_fapl); /* Test querying attribute info by index */
test_attr_delete_by_idx(new_format, fcpl, my_fapl); /* Test deleting attribute by index */
+ test_attr_iterate_by_idx(new_format, fcpl, my_fapl); /* Test iterating over attributes by index */
} /* end else */
} /* end for */