From 4d93574a8fe2103af882c87e12856a9cc1bcb3f4 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 20 Feb 2007 21:24:25 -0500 Subject: [svn-r13360] Description: Finish H5Aiterate2() Add H5Arename2() and mark H5Arename as deprecated. Started on H5Oopen_by_idx(). Tested on: Mac OS X/32 10.4.8 (amazon) FreeBSD/32 6.2 (duty) --- src/H5A.c | 99 +++++-- src/H5Adeprec.c | 95 +++++++ src/H5Apkg.h | 2 + src/H5Apublic.h | 16 +- src/H5Oattribute.c | 8 +- test/links.c | 6 - test/tattr.c | 773 ++++++++++++++++++++++++++++++++++++++++------------- 7 files changed, 772 insertions(+), 227 deletions(-) diff --git a/src/H5A.c b/src/H5A.c index f93f7a5..3484d45e 100644 --- a/src/H5A.c +++ b/src/H5A.c @@ -69,8 +69,6 @@ typedef struct H5A_iter_cb1 { static hid_t H5A_create(const H5G_loc_t *loc, const char *name, const H5T_t *type, const H5S_t *space, hid_t acpl_id, hid_t dxpl_id); static herr_t H5A_open_common(const H5G_loc_t *loc, H5A_t *attr); -static H5A_t *H5A_open_by_idx(const H5G_loc_t *loc, const char *obj_name, - H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t lapl_id, hid_t dxpl_id); static H5A_t *H5A_open_by_name(const H5G_loc_t *loc, const char *obj_name, const char *attr_name, hid_t lapl_id, hid_t dxpl_id); static herr_t H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id); @@ -474,13 +472,19 @@ done: /*-------------------------------------------------------------------------- NAME - H5Aopen_idx + H5Aopen_by_idx PURPOSE - Opens the n'th attribute for an object + Opens the n'th attribute for an object, according to the order within + an index USAGE - hid_t H5Aopen_idx (loc_id, idx) - hid_t loc_id; IN: Object that attribute is attached to - unsigned idx; IN: Index (0-based) attribute to open + hid_t H5Aopen_by_idx(loc_id, obj_ame, idx_type, order, n, aapl_id, lapl_id) + hid_t loc_id; IN: Object that attribute is attached to + 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 n; IN: Index (0-based) attribute to open + hid_t aapl_id; IN: Attribute access property list + hid_t lapl_id; IN: Link access property list RETURNS ID of attribute on success, negative on failure @@ -489,27 +493,36 @@ done: index specified is used to look up the corresponding attribute for the object. The attribute ID returned from this function must be released with H5Aclose or resource leaks will develop. - The location object may be either a group or a dataset, both of - which may have any sort of attribute. --------------------------------------------------------------------------*/ hid_t -H5Aopen_idx(hid_t loc_id, unsigned idx) +H5Aopen_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, + H5_iter_order_t order, hsize_t n, hid_t UNUSED aapl_id, hid_t lapl_id) { - H5G_loc_t loc; /* Object location */ H5A_t *attr = NULL; /* Attribute opened */ - hid_t ret_value; + H5G_loc_t loc; /* Object location */ + hid_t ret_value; /* Return value */ - FUNC_ENTER_API(H5Aopen_idx, FAIL) - H5TRACE2("i", "iIu", loc_id, idx); + FUNC_ENTER_API(H5Aopen_by_idx, 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") /* Open the attribute in the object header */ - if(NULL == (attr = H5A_open_by_idx(&loc, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)idx, H5P_LINK_ACCESS_DEFAULT, H5AC_ind_dxpl_id))) + if(NULL == (attr = H5A_open_by_idx(&loc, obj_name, idx_type, order, n, lapl_id, H5AC_ind_dxpl_id))) HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open attribute") /* Register the attribute and get an ID for it */ @@ -523,7 +536,7 @@ done: HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute") FUNC_LEAVE_API(ret_value) -} /* H5Aopen_idx() */ +} /* H5Aopen_by_idx() */ /*------------------------------------------------------------------------- @@ -595,7 +608,7 @@ done: * *------------------------------------------------------------------------- */ -static H5A_t * +H5A_t * H5A_open_by_idx(const H5G_loc_t *loc, const char *obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t lapl_id, hid_t dxpl_id) { @@ -1533,44 +1546,72 @@ done: /*------------------------------------------------------------------------- - * Function: H5Arename + * Function: H5Arename2 * * Purpose: Rename an attribute * * Return: Success: Non-negative * Failure: Negative * - * Programmer: Raymond Lu - * October 23, 2002 + * Programmer: Quincey Koziol + * February 20, 2007 * *------------------------------------------------------------------------- */ herr_t -H5Arename(hid_t loc_id, const char *old_name, const char *new_name) +H5Arename2(hid_t loc_id, const char *obj_name, const char *old_attr_name, + const char *new_attr_name, hid_t lapl_id) { 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 */ herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_API(H5Arename, FAIL) - H5TRACE3("e", "iss", loc_id, old_name, new_name); + FUNC_ENTER_API(H5Arename2, FAIL) /* check arguments */ - if(!old_name || !new_name) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "name is nil") 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) + 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(!old_attr_name || !*old_attr_name) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no old attribute name") + if(!new_attr_name || !*new_attr_name) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no new attribute name") + 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") /* Avoid thrashing things if the names are the same */ - if(HDstrcmp(old_name, new_name)) + if(HDstrcmp(old_attr_name, new_attr_name)) { + /* Set up opened group location to fill in */ + obj_loc.oloc = &obj_oloc; + obj_loc.path = &obj_path; + H5G_loc_reset(&obj_loc); + + /* Find the object's location */ + if(H5G_loc_find(&loc, obj_name, &obj_loc/*out*/, lapl_id, H5AC_ind_dxpl_id) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "object not found") + loc_found = TRUE; + /* Call attribute rename routine */ - if(H5O_attr_rename(loc.oloc, H5AC_dxpl_id, old_name, new_name) < 0) + if(H5O_attr_rename(obj_loc.oloc, H5AC_dxpl_id, old_attr_name, new_attr_name) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTRENAME, FAIL, "can't rename attribute") + } /* end if */ done: + /* Release resources */ + 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) -} /* H5Arename() */ +} /* H5Arename2() */ /*-------------------------------------------------------------------------- diff --git a/src/H5Adeprec.c b/src/H5Adeprec.c index 3baca88..9b49b81 100644 --- a/src/H5Adeprec.c +++ b/src/H5Adeprec.c @@ -108,6 +108,60 @@ H5A_init_deprec_interface(void) /*-------------------------------------------------------------------------- NAME + H5Aopen_idx + PURPOSE + Opens the n'th attribute for an object + USAGE + hid_t H5Aopen_idx (loc_id, idx) + hid_t loc_id; IN: Object that attribute is attached to + unsigned idx; IN: Index (0-based) attribute to open + RETURNS + ID of attribute on success, negative on failure + + DESCRIPTION + This function opens an existing attribute for access. The attribute + index specified is used to look up the corresponding attribute for the + object. The attribute ID returned from this function must be released with + H5Aclose or resource leaks will develop. + The location object may be either a group or a dataset, both of + which may have any sort of attribute. +--------------------------------------------------------------------------*/ +hid_t +H5Aopen_idx(hid_t loc_id, unsigned idx) +{ + H5G_loc_t loc; /* Object location */ + H5A_t *attr = NULL; /* Attribute opened */ + hid_t ret_value; + + FUNC_ENTER_API(H5Aopen_idx, FAIL) + H5TRACE2("i", "iIu", loc_id, idx); + + /* 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") + + /* Open the attribute in the object header */ + if(NULL == (attr = H5A_open_by_idx(&loc, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)idx, H5P_LINK_ACCESS_DEFAULT, H5AC_ind_dxpl_id))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open attribute") + + /* Register the attribute and get an ID for it */ + if((ret_value = H5I_register(H5I_ATTR, attr)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID") + +done: + /* Cleanup on failure */ + if(ret_value < 0) + if(attr && H5A_close(attr) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute") + + FUNC_LEAVE_API(ret_value) +} /* H5Aopen_idx() */ + + +/*-------------------------------------------------------------------------- + NAME H5Aget_num_attrs PURPOSE Determines the number of attributes attached to an object @@ -166,6 +220,47 @@ done: } /* H5Aget_num_attrs() */ +/*------------------------------------------------------------------------- + * Function: H5Arename + * + * Purpose: Rename an attribute + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Raymond Lu + * October 23, 2002 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Arename(hid_t loc_id, const char *old_name, const char *new_name) +{ + H5G_loc_t loc; /* Object location */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(H5Arename, FAIL) + H5TRACE3("e", "iss", loc_id, old_name, new_name); + + /* check arguments */ + if(!old_name || !new_name) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "name is nil") + 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") + + /* Avoid thrashing things if the names are the same */ + if(HDstrcmp(old_name, new_name)) + /* Call attribute rename routine */ + if(H5O_attr_rename(loc.oloc, H5AC_dxpl_id, old_name, new_name) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTRENAME, FAIL, "can't rename attribute") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Arename() */ + + /*-------------------------------------------------------------------------- NAME H5Aiterate diff --git a/src/H5Apkg.h b/src/H5Apkg.h index 261f7be..c7d5ba3 100644 --- a/src/H5Apkg.h +++ b/src/H5Apkg.h @@ -171,6 +171,8 @@ 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_open_by_idx(const H5G_loc_t *loc, const char *obj_name, + H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t lapl_id, hid_t dxpl_id); 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); diff --git a/src/H5Apublic.h b/src/H5Apublic.h index 8c97e46..cde9bc6 100644 --- a/src/H5Apublic.h +++ b/src/H5Apublic.h @@ -48,7 +48,9 @@ typedef herr_t (*H5A_operator2_t)(hid_t location_id/*in*/, H5_DLL hid_t H5Acreate(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t plist_id); H5_DLL hid_t H5Aopen_name(hid_t loc_id, const char *name); -H5_DLL hid_t H5Aopen_idx(hid_t loc_id, unsigned idx); +H5_DLL hid_t H5Aopen_by_idx(hid_t loc_id, const char *obj_name, + H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t aapl_id, + hid_t lapl_id); H5_DLL herr_t H5Awrite(hid_t attr_id, hid_t type_id, const void *buf); H5_DLL herr_t H5Aread(hid_t attr_id, hid_t type_id, void *buf); H5_DLL herr_t H5Aclose(hid_t attr_id); @@ -56,16 +58,17 @@ H5_DLL hid_t H5Aget_space(hid_t attr_id); H5_DLL hid_t H5Aget_type(hid_t attr_id); H5_DLL hid_t H5Aget_create_plist(hid_t attr_id); H5_DLL ssize_t H5Aget_name(hid_t attr_id, size_t buf_size, char *buf); +H5_DLL 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 hsize_t H5Aget_storage_size(hid_t attr_id); H5_DLL herr_t H5Aget_info(hid_t loc_id, const char *obj_name, const char *attr_name, H5A_info_t *ainfo /*out*/, hid_t lapl_id); H5_DLL herr_t H5Aget_info_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, H5A_info_t *ainfo /*out*/, hid_t lapl_id); -H5_DLL ssize_t H5Aget_name_by_idx(hid_t loc_id, const char *obj_name, - H5_index_t idx_type, H5_iter_order_t order, hsize_t n, - char *name /*out*/, size_t size, hid_t lapl_id); -H5_DLL herr_t H5Arename(hid_t loc_id, const char *old_name, const char *new_name); +H5_DLL herr_t H5Arename2(hid_t loc_id, const char *obj_name, + const char *old_attr_name, const char *new_attr_name, hid_t lapl_id); 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); @@ -79,7 +82,9 @@ 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 hid_t H5Aopen_idx(hid_t loc_id, unsigned idx); H5_DLL int H5Aget_num_attrs(hid_t loc_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 H5Adelete(hid_t loc_id, const char *name); @@ -89,3 +94,4 @@ H5_DLL herr_t H5Adelete(hid_t loc_id, const char *name); #endif #endif /* _H5Apublic_H */ + diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c index ea0f073..3d3ae2c 100644 --- a/src/H5Oattribute.c +++ b/src/H5Oattribute.c @@ -337,8 +337,8 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5O_attr_open_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, - unsigned UNUSED sequence, unsigned UNUSED *oh_flags_ptr, void *_udata/*in,out*/) +H5O_attr_open_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, unsigned sequence, + unsigned UNUSED *oh_flags_ptr, void *_udata/*in,out*/) { H5O_iter_opn_t *udata = (H5O_iter_opn_t *)_udata; /* Operator user data */ herr_t ret_value = H5_ITER_CONT; /* Return value */ @@ -356,6 +356,10 @@ H5O_attr_open_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, if(NULL == (udata->attr = H5A_copy(NULL, (H5A_t *)mesg->native))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "unable to copy attribute") + /* Assign [somewhat arbitrary] creation order value, for older versions of the format */ + if(oh->version == H5O_VERSION_1) + udata->attr->crt_idx = sequence; + /* Stop iterating */ ret_value = H5_ITER_STOP; } /* end if */ diff --git a/test/links.c b/test/links.c index 7696309..f2ce9c3 100644 --- a/test/links.c +++ b/test/links.c @@ -91,7 +91,6 @@ typedef struct { hbool_t *visited; /* Pointer to array of "visited link" flags */ } link_iter_info_t; -#ifndef QAK /*------------------------------------------------------------------------- * Function: mklinks @@ -8791,7 +8790,6 @@ error: return -1; } /* end object_info_old() */ -#endif /* QAK */ /*------------------------------------------------------------------------- @@ -9347,7 +9345,6 @@ main(void) /* Set the "use the latest version of the format" flag for creating objects in the file */ if(H5Pset_latest_format(fapl2, TRUE) < 0) TEST_ERROR -#ifndef QAK /* Loop over using new group format */ for(new_format = FALSE; new_format <= TRUE; new_format++) { /* General tests... (on both old & new format groups */ @@ -9431,9 +9428,6 @@ main(void) nerrors += group_info_old(fapl) < 0 ? 1 : 0; } } /* end for */ -#else /* QAK */ -HDfprintf(stderr, "Uncomment tests!\n"); -#endif /* QAK */ /* Close 2nd FAPL */ H5Pclose(fapl2); diff --git a/test/tattr.c b/test/tattr.c index 78e4f90..26c2597 100644 --- a/test/tattr.c +++ b/test/tattr.c @@ -54,6 +54,7 @@ #define ATTR_NAME_LEN 16 #define ATTR_MAX_DIMS 7 #define ATTR_TMP_NAME "a really long temp_name" +#define CORDER_ITER_STOP 3 /* 3-D dataset with fixed dimensions */ #define SPACE1_NAME "Space1" @@ -118,9 +119,21 @@ struct attr4_struct { #define ATTR5_RANK 0 float attr_data5=(float)-5.123; /* Test data for 5th attribute */ -herr_t attr_op1(hid_t loc_id, const char *name, void *op_data); +/* Attribute iteration struct */ +typedef struct { + H5_iter_order_t order; /* Direction of iteration */ + unsigned ncalled; /* # of times callback is entered */ + unsigned nskipped; /* # of attributes skipped */ + int stop; /* # of iterations to stop after */ + int64_t curr; /* Current creation order value */ + size_t max_visit; /* Size of "visited attribute" flag array */ + hbool_t *visited; /* Pointer to array of "visited attribute" flags */ +} attr_iter_info_t; +static herr_t attr_op1(hid_t loc_id, const char *name, void *op_data); + + /**************************************************************** ** ** test_attr_basic_write(): Test basic H5A (attribute) code. @@ -353,6 +366,7 @@ test_attr_basic_write(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_basic_write() */ + /**************************************************************** ** ** test_attr_basic_read(): Test basic H5A (attribute) code. @@ -440,6 +454,7 @@ test_attr_basic_read(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_basic_read() */ + /**************************************************************** ** ** test_attr_flush(): Test H5A (attribute) code for performing @@ -506,6 +521,7 @@ test_attr_flush(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_flush() */ + /**************************************************************** ** ** test_attr_plist(): Test Attribute Creation Property Lists @@ -618,6 +634,7 @@ test_attr_plist(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_plist() */ + /**************************************************************** ** ** test_attr_compound_write(): Test H5A (attribute) code. @@ -706,6 +723,7 @@ test_attr_compound_write(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_compound_write() */ + /**************************************************************** ** ** test_attr_compound_read(): Test basic H5A (attribute) code. @@ -853,6 +871,7 @@ test_attr_compound_read(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_compound_read() */ + /**************************************************************** ** ** test_attr_scalar_write(): Test scalar H5A (attribute) writing code. @@ -917,6 +936,7 @@ test_attr_scalar_write(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_scalar_write() */ + /**************************************************************** ** ** test_attr_scalar_read(): Test scalar H5A (attribute) reading code. @@ -981,6 +1001,7 @@ test_attr_scalar_read(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_scalar_read() */ + /**************************************************************** ** ** test_attr_mult_write(): Test basic H5A (attribute) code. @@ -1100,6 +1121,7 @@ test_attr_mult_write(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_mult_write() */ + /**************************************************************** ** ** test_attr_mult_read(): Test basic H5A (attribute) code. @@ -1319,6 +1341,7 @@ test_attr_mult_read(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_mult_read() */ + /**************************************************************** ** ** attr_op1(): Attribute operator @@ -1356,6 +1379,7 @@ herr_t attr_op1(hid_t UNUSED loc_id, const char *name, void *op_data) return(ret); } /* end attr_op1() */ + /**************************************************************** ** ** test_attr_iterate(): Test H5A (attribute) iterator code. @@ -1427,6 +1451,7 @@ test_attr_iterate(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_iterate() */ + /**************************************************************** ** ** test_attr_delete(): Test H5A (attribute) code for deleting objects. @@ -1540,6 +1565,7 @@ test_attr_delete(hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_delete() */ + /**************************************************************** ** ** test_attr_dtype_shared(): Test H5A (attribute) code for using @@ -1715,6 +1741,7 @@ test_attr_dtype_shared(hid_t fapl) VERIFY(filesize, empty_filesize, "h5_get_file_size"); } /* test_attr_dtype_shared() */ + /**************************************************************** ** ** test_attr_dense_verify(): Test basic H5A (attribute) code. @@ -1774,6 +1801,7 @@ test_attr_dense_verify(hid_t loc_id, unsigned max_attr) } /* end for */ } /* test_attr_dense_verify() */ + /**************************************************************** ** ** test_attr_dense_create(): Test basic H5A (attribute) code. @@ -1904,6 +1932,7 @@ test_attr_dense_create(hid_t fcpl, hid_t fapl) VERIFY(filesize, empty_filesize, "h5_get_file_size"); } /* test_attr_dense_create() */ + /**************************************************************** ** ** test_attr_dense_open(): Test basic H5A (attribute) code. @@ -2036,6 +2065,7 @@ test_attr_dense_open(hid_t fcpl, hid_t fapl) VERIFY(filesize, empty_filesize, "h5_get_file_size"); } /* test_attr_dense_open() */ + /**************************************************************** ** ** test_attr_dense_delete(): Test basic H5A (attribute) code. @@ -2206,6 +2236,7 @@ test_attr_dense_delete(hid_t fcpl, hid_t fapl) VERIFY(filesize, empty_filesize, "h5_get_file_size"); } /* test_attr_dense_delete() */ + /**************************************************************** ** ** test_attr_dense_rename(): Test basic H5A (attribute) code. @@ -2294,8 +2325,8 @@ test_attr_dense_rename(hid_t fcpl, hid_t fapl) sprintf(new_attrname, "new attr %02u", u); /* Rename attribute */ - ret = H5Arename(dataset, attrname, new_attrname); - CHECK(ret, FAIL, "H5Arename"); + ret = H5Arename2(fid, DSET1_NAME, attrname, new_attrname, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Arename2"); /* Check # of attributes */ attr_count = H5Aget_num_attrs(dataset); @@ -2364,6 +2395,7 @@ test_attr_dense_rename(hid_t fcpl, hid_t fapl) VERIFY(filesize, empty_filesize, "h5_get_file_size"); } /* test_attr_dense_rename() */ + /**************************************************************** ** ** test_attr_dense_unlink(): Test basic H5A (attribute) code. @@ -2493,6 +2525,7 @@ test_attr_dense_unlink(hid_t fcpl, hid_t fapl) VERIFY(filesize, empty_filesize, "h5_get_file_size"); } /* test_attr_dense_unlink() */ + /**************************************************************** ** ** test_attr_dense_limits(): Test basic H5A (attribute) code. @@ -2657,6 +2690,7 @@ test_attr_dense_limits(hid_t fcpl, hid_t fapl) VERIFY(filesize, empty_filesize, "h5_get_file_size"); } /* test_attr_dense_limits() */ + /**************************************************************** ** ** test_attr_corder_create_empty(): Test basic H5A (attribute) code. @@ -2772,6 +2806,7 @@ test_attr_corder_create_basic(hid_t fcpl, hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_corder_create_basic() */ + /**************************************************************** ** ** test_attr_corder_create_compact(): Test basic H5A (attribute) code. @@ -2969,6 +3004,7 @@ test_attr_corder_create_compact(hid_t fcpl, hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_corder_create_compact() */ + /**************************************************************** ** ** test_attr_corder_create_dense(): Test basic H5A (attribute) code. @@ -3195,6 +3231,7 @@ test_attr_corder_create_dense(hid_t fcpl, hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_corder_create_dense() */ + /**************************************************************** ** ** test_attr_corder_transition(): Test basic H5A (attribute) code. @@ -3600,6 +3637,7 @@ test_attr_corder_transition(hid_t fcpl, hid_t fapl) CHECK(ret, FAIL, "H5Fclose"); } /* test_attr_corder_transition() */ + /**************************************************************** ** ** test_attr_corder_delete(): Test basic H5A (attribute) code. @@ -3947,6 +3985,7 @@ attr_info_by_idx_check(hid_t obj_id, const char *attrname, hsize_t n, return(-1); } /* end attr_info_by_idx_check() */ + /**************************************************************** ** ** test_attr_info_by_idx(): Test basic H5A (attribute) code. @@ -4154,6 +4193,7 @@ test_attr_info_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl) CHECK(ret, FAIL, "H5Sclose"); } /* test_attr_info_by_idx() */ + /**************************************************************** ** ** test_attr_delete_by_idx(): Test basic H5A (attribute) code. @@ -4683,54 +4723,282 @@ test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl) CHECK(ret, FAIL, "H5Sclose"); } /* test_attr_delete_by_idx() */ + /**************************************************************** ** -** attr_op2(): Revised attribute operator +** attr_iterate2_cb(): Revised attribute operator ** ****************************************************************/ -herr_t -attr_op2(hid_t UNUSED loc_id, const char *name, const H5A_info_t *ainfo, void *op_data) +static herr_t +attr_iterate2_cb(hid_t loc_id, const char *attr_name, const H5A_info_t *info, + void *_op_data) { - int *count = (int *)op_data; - herr_t ret = 0; + attr_iter_info_t *op_data = (attr_iter_info_t *)_op_data; /* User data */ + char attrname[NAME_BUF_SIZE]; /* Object name */ + H5A_info_t my_info; /* Local attribute info */ #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; +HDfprintf(stderr, "attr_name = '%s'\n", attr_name); +if(info) + HDfprintf(stderr, "info->corder = %u\n", (unsigned)info->corder); +HDfprintf(stderr, "op_data->curr = %Hd\n", op_data->curr); +#endif /* QAK */ - case 1: - if(HDstrcmp(name,ATTR2_NAME)) - TestErrPrintf("attribute name different: name=%s, should be %s\n",name,ATTR2_NAME); - (*count)++; - break; + /* Increment # of times the callback was called */ + op_data->ncalled++; + + /* Get the attribute information directly to compare */ + if(H5Aget_info(loc_id, ".", attr_name, &my_info, H5P_DEFAULT) < 0) + return(H5_ITER_ERROR); + + /* Check more things for revised attribute iteration (vs. older attribute iteration) */ + if(info) { + /* Check for correct order of iteration */ + /* (if we are operating in increasing or decreasing order) */ + if(op_data->order != H5_ITER_NATIVE) + if(info->corder != op_data->curr) + return(H5_ITER_ERROR); + + /* Compare attribute info structs */ + if(info->corder_valid != my_info.corder_valid) + return(H5_ITER_ERROR); + if(info->corder != my_info.corder) + return(H5_ITER_ERROR); + if(info->cset != my_info.cset) + return(H5_ITER_ERROR); + if(info->data_size != my_info.data_size) + return(H5_ITER_ERROR); + } /* end if */ - case 2: - if(HDstrcmp(name,ATTR3_NAME)) - TestErrPrintf("attribute name different: name=%s, should be %s\n",name,ATTR3_NAME); - (*count)++; - break; + /* Verify name of link */ + sprintf(attrname, "attr %02u", (unsigned)my_info.corder); + if(HDstrcmp(attr_name, attrname)) + return(H5_ITER_ERROR); + + /* Check if we've visited this link before */ + if((size_t)op_data->curr >= op_data->max_visit) + return(H5_ITER_ERROR); + if(op_data->visited[op_data->curr]) + return(H5_ITER_ERROR); + op_data->visited[op_data->curr] = TRUE; + + /* Advance to next value, in correct direction */ + if(op_data->order != H5_ITER_DEC) + op_data->curr++; + else + op_data->curr--; - default: - ret=-1; - break; - } /* end switch() */ -#endif /* QAK */ + /* Check for stopping in the middle of iterating */ + if(op_data->stop > 0) + if(--op_data->stop == 0) + return(CORDER_ITER_STOP); - return(ret); -} /* end attr_op2() */ + return(H5_ITER_CONT); +} /* end attr_iterate2_cb() */ + + +/**************************************************************** +** +** attr_iterate_cb(): Attribute operator +** +****************************************************************/ +static herr_t +attr_iterate_cb(hid_t loc_id, const char *attr_name, void *_op_data) +{ + return(attr_iterate2_cb(loc_id, attr_name, NULL, _op_data)); +} /* end attr_iterate_cb() */ + + +/*------------------------------------------------------------------------- + * Function: attr_iterate2_fail_cb + * + * Purpose: Callback routine for iterating over attributes on object that + * always returns failure + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Quincey Koziol + * Tuesday, February 20, 2007 + * + *------------------------------------------------------------------------- + */ +static int +attr_iterate2_fail_cb(hid_t UNUSED group_id, const char UNUSED *attr_name, + const H5A_info_t UNUSED *info, void UNUSED *_op_data) +{ + return(H5_ITER_ERROR); +} /* end attr_iterate2_fail_cb() */ + + +/*------------------------------------------------------------------------- + * Function: attr_iterate_check + * + * Purpose: Check iteration over attributes on an object + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Quincey Koziol + * Tuesday, February 20, 2007 + * + *------------------------------------------------------------------------- + */ +static int +attr_iterate_check(hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order, + unsigned max_attrs, attr_iter_info_t *iter_info) +{ + unsigned v; /* Local index variable */ + hsize_t skip; /* # of attributes to skip on object */ + unsigned oskip; /* # of attributes to skip on object, with H5Aiterate */ + int old_nerrs; /* Number of errors when entering this check */ + herr_t ret; /* Generic return value */ + + /* Retrieve the current # of reported errors */ + old_nerrs = GetTestNumErrs(); + + /* Iterate over attributes on object */ + iter_info->nskipped = (unsigned)(skip = 0); + iter_info->order = order; + iter_info->stop = -1; + iter_info->ncalled = 0; + iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1); + HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit); + ret = H5Aiterate2(obj_id, ".", idx_type, order, &skip, attr_iterate2_cb, iter_info, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Aiterate2"); + + /* Verify that we visited all the attributes */ + VERIFY(skip, max_attrs, "H5Aiterate2"); + for(v = 0; v < max_attrs; v++) + VERIFY(iter_info->visited[v], TRUE, "H5Aiterate2"); + + + /* Iterate over attributes on object, with H5Aiterate */ + iter_info->nskipped = oskip = 0; + iter_info->order = order; + iter_info->stop = -1; + iter_info->ncalled = 0; + iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1); + HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit); + ret = H5Aiterate(obj_id, &oskip, attr_iterate_cb, iter_info); + CHECK(ret, FAIL, "H5Aiterate"); + + /* Verify that we visited all the attributes */ + VERIFY(skip, max_attrs, "H5Aiterate"); + for(v = 0; v < max_attrs; v++) + VERIFY(iter_info->visited[v], TRUE, "H5Aiterate"); + + + /* Skip over some attributes on object */ + iter_info->nskipped = (unsigned)(skip = max_attrs / 2); + iter_info->order = order; + iter_info->stop = -1; + iter_info->ncalled = 0; + iter_info->curr = order != H5_ITER_DEC ? skip : ((max_attrs - 1) - skip); + HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit); + ret = H5Aiterate2(obj_id, ".", idx_type, order, &skip, attr_iterate2_cb, iter_info, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Aiterate2"); + + /* Verify that we visited all the attributes */ + VERIFY(skip, max_attrs, "H5Aiterate2"); + if(order == H5_ITER_INC) { + for(v = 0; v < (max_attrs / 2); v++) + VERIFY(iter_info->visited[v + (max_attrs / 2)], TRUE, "H5Aiterate2"); + } /* end if */ + else if(order == H5_ITER_DEC) { + for(v = 0; v < (max_attrs / 2); v++) + VERIFY(iter_info->visited[v], TRUE, "H5Aiterate2"); + } /* end if */ + else { + unsigned nvisit = 0; /* # of links visited */ + + HDassert(order == H5_ITER_NATIVE); + for(v = 0; v < max_attrs; v++) + if(iter_info->visited[v] == TRUE) + nvisit++; + + VERIFY(skip, (max_attrs / 2), "H5Aiterate2"); + } /* end else */ + + + /* Skip over some attributes on object, with H5Aiterate */ + iter_info->nskipped = oskip = max_attrs / 2; + iter_info->order = order; + iter_info->stop = -1; + iter_info->ncalled = 0; + iter_info->curr = order != H5_ITER_DEC ? (unsigned)oskip : ((max_attrs - 1) - oskip); + HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit); + ret = H5Aiterate(obj_id, &oskip, attr_iterate_cb, iter_info); + CHECK(ret, FAIL, "H5Aiterate"); + + /* Verify that we visited all the links */ + VERIFY(oskip, max_attrs, "H5Aiterate"); + if(order == H5_ITER_INC) { + for(v = 0; v < (max_attrs / 2); v++) + VERIFY(iter_info->visited[v + (max_attrs / 2)], TRUE, "H5Aiterate"); + } /* end if */ + else if(order == H5_ITER_DEC) { + for(v = 0; v < (max_attrs / 2); v++) + VERIFY(iter_info->visited[v], TRUE, "H5Aiterate"); + } /* end if */ + else { + unsigned nvisit = 0; /* # of links visited */ + + HDassert(order == H5_ITER_NATIVE); + for(v = 0; v < max_attrs; v++) + if(iter_info->visited[v] == TRUE) + nvisit++; + + VERIFY(skip, (max_attrs / 2), "H5Aiterate"); + } /* end else */ + + + /* Iterate over attributes on object, stopping in the middle */ + iter_info->nskipped = (unsigned)(skip = 0); + iter_info->order = order; + iter_info->stop = 3; + iter_info->ncalled = 0; + iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1); + HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit); + ret = H5Aiterate2(obj_id, ".", idx_type, order, &skip, attr_iterate2_cb, iter_info, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Aiterate2"); + VERIFY(ret, CORDER_ITER_STOP, "H5Aiterate2"); + VERIFY(iter_info->ncalled, 3, "H5Aiterate2"); + + + /* Iterate over attributes on object, stopping in the middle, with H5Aiterate() */ + iter_info->nskipped = oskip = 0; + iter_info->order = order; + iter_info->stop = 3; + iter_info->ncalled = 0; + iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1); + HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit); + ret = H5Aiterate(obj_id, &oskip, attr_iterate_cb, iter_info); + CHECK(ret, FAIL, "H5Aiterate"); + VERIFY(ret, CORDER_ITER_STOP, "H5Aiterate2"); + VERIFY(iter_info->ncalled, 3, "H5Aiterate2"); + + + /* Check for iteration routine indicating failure */ + skip = 0; + ret = H5Aiterate2(obj_id, ".", idx_type, order, &skip, attr_iterate2_fail_cb, NULL, H5P_DEFAULT); + VERIFY(ret, FAIL, "H5Aiterate2"); + + /* Retrieve current # of errors */ + if(old_nerrs == GetTestNumErrs()) + return(0); + else + return(-1); +} /* end attr_iterate_check() */ /**************************************************************** ** -** test_attr_iterate_by_idx(): Test basic H5A (attribute) code. +** test_attr_iterate2(): 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) +test_attr_iterate2(hbool_t new_format, hid_t fcpl, hid_t fapl) { hid_t fid; /* HDF5 File ID */ hid_t dset1, dset2, dset3; /* Dataset IDs */ @@ -4738,7 +5006,6 @@ test_attr_iterate_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl) 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? */ @@ -4748,9 +5015,11 @@ test_attr_iterate_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl) 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 */ + attr_iter_info_t iter_info; /* Iterator info */ + hbool_t *visited = NULL; /* Array of flags for visiting links */ + hsize_t idx; /* Start index for iteration */ 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 */ @@ -4767,6 +5036,12 @@ test_attr_iterate_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl) ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense); CHECK(ret, FAIL, "H5Pget_attr_phase_change"); + /* Allocate the "visited link" array */ + iter_info.max_visit = max_compact * 2; + visited = HDmalloc(sizeof(hbool_t) * iter_info.max_visit); + CHECK(visited, NULL, "HDmalloc"); + iter_info.visited = visited; + /* 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 */ @@ -4845,10 +5120,9 @@ test_attr_iterate_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl) 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); + ret = H5Aiterate2(my_dataset, ".", idx_type, order, NULL, attr_iterate2_cb, 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 */ @@ -4878,49 +5152,38 @@ test_attr_iterate_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl) 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"); + /* Check for out of bound iteration */ + idx = u; + ret = H5Aiterate2(my_dataset, ".", idx_type, order, &idx, attr_iterate2_cb, NULL, H5P_DEFAULT); + VERIFY(ret, FAIL, "H5Aiterate2"); - /* 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"); + /* Test iteration over attributes stored compactly */ + ret = attr_iterate_check(my_dataset, idx_type, order, u, &iter_info); + CHECK(ret, FAIL, "attr_iterate_check"); + } /* end for */ - /* 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 */ + /* Work on all the datasets */ + for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) { + switch(curr_dset) { + case 0: + my_dataset = dset1; + break; - /* Delete last attribute */ - ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT); - CHECK(ret, FAIL, "H5Adelete_by_idx"); + case 1: + my_dataset = dset2; + break; - /* Verify state of attribute storage (empty) */ - is_empty = H5O_is_attr_empty_test(my_dataset); - VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test"); + 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++) { + for(u = max_compact; u < (max_compact * 2); u++) { /* Create attribute */ sprintf(attrname, "attr %02u", u); attr = H5Acreate(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT); @@ -4963,57 +5226,233 @@ test_attr_iterate_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl) 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"); + /* Check for out of bound iteration */ + idx = u; + ret = H5Aiterate2(my_dataset, ".", idx_type, order, &idx, attr_iterate2_cb, NULL, H5P_DEFAULT); + VERIFY(ret, FAIL, "H5Aiterate2"); - /* 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"); + /* Test iteration over attributes stored densely */ + ret = attr_iterate_check(my_dataset, idx_type, order, u, &iter_info); + CHECK(ret, FAIL, "attr_iterate_check"); + } /* end for */ - /* 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 */ + /* Close Datasets */ + ret = H5Dclose(dset1); + CHECK(ret, FAIL, "H5Dclose"); + ret = H5Dclose(dset2); + CHECK(ret, FAIL, "H5Dclose"); + ret = H5Dclose(dset3); + CHECK(ret, FAIL, "H5Dclose"); - /* 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)); + /* 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_iterate2() */ + +/**************************************************************** +** +** test_attr_open_by_idx(): Test basic H5A (attribute) code. +** Tests opening attributes by index +** +****************************************************************/ +static void +test_attr_open_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 */ + 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 */ + attr_iter_info_t iter_info; /* Iterator info */ + hbool_t *visited = NULL; /* Array of flags for visiting links */ + hsize_t idx; /* Start index for iteration */ + hbool_t use_index; /* Use index on creation order values */ + char attrname[NAME_BUF_SIZE]; /* Name of attribute */ + 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"); + + /* Allocate the "visited link" array */ + iter_info.max_visit = max_compact * 2; + visited = HDmalloc(sizeof(hbool_t) * iter_info.max_visit); + CHECK(visited, NULL, "HDmalloc"); + iter_info.visited = visited; + + /* 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 - sprintf(attrname, "attr %02u", ((max_compact * 2) - (u + 2))); - ret = HDstrcmp(attrname, tmpname); - VERIFY(ret, 0, "H5Aget_name_by_idx"); - } /* end for */ + 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 */ - /* Delete last attribute */ - ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT); - CHECK(ret, FAIL, "H5Adelete_by_idx"); + /* Create file */ + fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl); + CHECK(fid, FAIL, "H5Fcreate"); - /* Verify state of attribute storage (empty) */ + /* 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 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"); + /* Check for iterating over object with no attributes (should be OK) */ + ret = H5Aiterate2(my_dataset, ".", idx_type, order, NULL, attr_iterate2_cb, NULL, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Aiterate2"); + /* 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"); - /* Delete attributes in middle */ + /* 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"); - /* Create attributes, to push into dense form */ - for(u = 0; u < (max_compact * 2); u++) { + /* 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 iteration */ + idx = u; + ret = H5Aiterate2(my_dataset, ".", idx_type, order, &idx, attr_iterate2_cb, NULL, H5P_DEFAULT); + VERIFY(ret, FAIL, "H5Aiterate2"); + + /* Test iteration over attributes stored compactly */ + ret = attr_iterate_check(my_dataset, idx_type, order, u, &iter_info); + CHECK(ret, FAIL, "attr_iterate_check"); + } /* 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 = max_compact; u < (max_compact * 2); u++) { /* Create attribute */ sprintf(attrname, "attr %02u", u); attr = H5Acreate(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT); @@ -5038,76 +5477,32 @@ test_attr_iterate_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl) 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 */ + /* 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"); - /* Delete last attribute */ - ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT); - CHECK(ret, FAIL, "H5Adelete_by_idx"); + 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 */ - /* 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 out of bound iteration */ + idx = u; + ret = H5Aiterate2(my_dataset, ".", idx_type, order, &idx, attr_iterate2_cb, NULL, H5P_DEFAULT); + VERIFY(ret, FAIL, "H5Aiterate2"); - /* 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 */ + /* Test iteration over attributes stored densely */ + ret = attr_iterate_check(my_dataset, idx_type, order, u, &iter_info); + CHECK(ret, FAIL, "attr_iterate_check"); } /* end for */ /* Close Datasets */ @@ -5132,7 +5527,7 @@ test_attr_iterate_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl) /* Close dataspace */ ret = H5Sclose(sid); CHECK(ret, FAIL, "H5Sclose"); -} /* test_attr_iterate_by_idx() */ +} /* test_attr_open_by_idx() */ /**************************************************************** ** @@ -5731,8 +6126,8 @@ test_attr_shared_rename(hid_t fcpl, hid_t fapl) sprintf(attrname2, "new attr %02u", u); /* Change second dataset's attribute's name */ - ret = H5Arename(dataset2, attrname, attrname2); - CHECK(ret, FAIL, "H5Arename"); + ret = H5Arename2(fid, DSET2_NAME, attrname, attrname2, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Arename2"); /* Check refcount on attributes now */ @@ -5787,8 +6182,8 @@ test_attr_shared_rename(hid_t fcpl, hid_t fapl) /* Change second dataset's attribute's name back to original */ - ret = H5Arename(dataset2, attrname2, attrname); - CHECK(ret, FAIL, "H5Arename"); + ret = H5Arename2(fid, DSET2_NAME, attrname2, attrname, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Arename2"); /* Check refcount on attributes now */ @@ -6747,7 +7142,12 @@ 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 */ + test_attr_iterate2(new_format, my_fcpl, my_fapl); /* Test iterating over attributes by index */ +#ifdef NOT_YET + test_attr_open_by_idx(new_format, my_fcpl, my_fapl); /* Test opening attributes by index */ +#else /* NOT_YET */ +HDfprintf(stderr, "Finish H5Aopen_by_idx() test!\n"); +#endif /* NOT_YET */ /* More complex tests with both "new format" and "shared" attributes */ if(use_shared == TRUE) { @@ -6762,7 +7162,10 @@ 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 */ + test_attr_iterate2(new_format, fcpl, my_fapl); /* Test iterating over attributes by index */ +#ifdef NOT_YET + test_attr_open_by_idx(new_format, fcpl, my_fapl); /* Test opening attributes by index */ +#endif /* NOT_YET */ } /* end else */ } /* end for */ -- cgit v0.12