From d4eec753a1de150377773998db4f5035df60b21b Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 4 Oct 2007 12:36:17 -0500 Subject: [svn-r14183] Description: Move H5Aget_num_attrs() into deprecated routines section, replacing all internal usage with H5Oget_info(). Tested on: FreeBSD/32 6.2 (duty) in debug mode FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Mac OS X/32 10.4.10 (amazon) in debug mode --- c++/src/H5Object.cpp | 12 +- examples/h5_attribute.c | 7 +- fortran/src/H5Af.c | 18 +- src/H5Adeprec.c | 2 +- src/H5Apkg.h | 4 +- src/H5Apublic.h | 2 +- src/H5Oattribute.c | 78 +++---- test/objcopy.c | 22 +- test/tattr.c | 465 +++++++++++++++++++++-------------------- tools/h5repack/h5repack_copy.c | 7 +- tools/h5repack/h5repack_refs.c | 7 +- tools/lib/h5diff_attr.c | 26 +-- 12 files changed, 342 insertions(+), 308 deletions(-) diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index 494ee2c..b3b2982 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -235,14 +235,12 @@ int H5Object::iterateAttrs( attr_operator_t user_op, unsigned *_idx, void *op_da //-------------------------------------------------------------------------- int H5Object::getNumAttrs() const { - int num_attrs = H5Aget_num_attrs( id ); - if( num_attrs < 0 ) - { - throw AttributeIException(inMemFunc("getNumAttrs"), - "H5Aget_num_attrs failed - returned negative number of attributes"); - } + H5O_info_t oinfo; /* Object info */ + + if(H5Oget_info(id, ".", &oinfo, H5P_DEFAULT) < 0) + throw AttributeIException(inMemFunc("getNumAttrs"), "H5Oget_info failed"); else - return( num_attrs ); + return( (int)oinfo.num_attrs ); } //-------------------------------------------------------------------------- diff --git a/examples/h5_attribute.c b/examples/h5_attribute.c index 4f55998..d86bbcd 100644 --- a/examples/h5_attribute.c +++ b/examples/h5_attribute.c @@ -62,7 +62,8 @@ main (void) float matrix[ADIM1][ADIM2]; /* Attribute data */ herr_t ret; /* Return value */ - unsigned i,j; /* Counters */ + H5O_info_t oinfo; /* Object info */ + unsigned i, j; /* Counters */ char string_out[80]; /* Buffer to read string attribute back */ int point_out; /* Buffer to read scalar attribute back */ int num_attr; /* Number of attributes */ @@ -191,8 +192,8 @@ main (void) /* * Find string attribute by iterating through all attributes */ - num_attr = H5Aget_num_attrs(dataset); - for(i=0; i < num_attr; i++) { + ret = H5Oget_info(dataset, ".", &oinfo, H5P_DEFAULT); + for(i = 0; i < (unsigned)oinfo.num_attrs; i++) { attr = H5Aopen_idx(dataset, i); atype = H5Aget_type(attr); type_class = H5Tget_class(atype); diff --git a/fortran/src/H5Af.c b/fortran/src/H5Af.c index 6b49624..8253781 100644 --- a/fortran/src/H5Af.c +++ b/fortran/src/H5Af.c @@ -924,7 +924,7 @@ done: /*---------------------------------------------------------------------------- * Name: h5aget_num_attrs_c - * Purpose: Call H5Aget_num_attrs to determine number of + * Purpose: Call H5Oget_info to determine number of * attributes of an object * Inputs: obj_id - object identifier * attr_num - number of attributes @@ -936,13 +936,17 @@ done: int_f nh5aget_num_attrs_c (hid_t_f *obj_id, int_f *attr_num) { - int_f ret_value=0; /* Return value */ + H5O_info_t oinfo; /* Object info */ + int_f ret_value = 0; /* Return value */ - /* - * Call H5Aget_num_attrs function. - */ - if ((*attr_num = (int_f)H5Aget_num_attrs((hid_t)*obj_id)) < 0) - HGOTO_DONE(FAIL); + /* + * Call H5Oget_info function. + */ + if(H5Oget_info((hid_t)*obj_id, ".", &oinfo, H5P_DEFAULT) < 0) + HGOTO_DONE(FAIL); + + /* Set number of attributes */ + *attr_num = (int_f)oinfo.num_attrs; done: return ret_value; diff --git a/src/H5Adeprec.c b/src/H5Adeprec.c index 9ca3d5a..65b876e 100644 --- a/src/H5Adeprec.c +++ b/src/H5Adeprec.c @@ -274,6 +274,7 @@ done: FUNC_LEAVE_API(ret_value) } /* H5Aopen_idx() */ +#ifndef H5_NO_DEPRECATED_SYMBOLS /*-------------------------------------------------------------------------- NAME @@ -334,7 +335,6 @@ done: FUNC_LEAVE_API(ret_value) } /* H5Aget_num_attrs() */ -#ifndef H5_NO_DEPRECATED_SYMBOLS /*------------------------------------------------------------------------- * Function: H5Arename1 diff --git a/src/H5Apkg.h b/src/H5Apkg.h index f72de64..049877e 100644 --- a/src/H5Apkg.h +++ b/src/H5Apkg.h @@ -267,8 +267,10 @@ 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, H5_iter_order_t order, hsize_t n, hid_t dxpl_id); -H5_DLL int H5O_attr_count(const H5O_loc_t *loc, hid_t dxpl_id); H5_DLL htri_t H5O_attr_exists(const H5O_loc_t *loc, const char *name, hid_t dxpl_id); +#ifndef H5_NO_DEPRECATED_SYMBOLS +H5_DLL int H5O_attr_count(const H5O_loc_t *loc, hid_t dxpl_id); +#endif /* H5_NO_DEPRECATED_SYMBOLS */ /* Testing functions */ #ifdef H5A_TESTING diff --git a/src/H5Apublic.h b/src/H5Apublic.h index d20ad8f..76dec27 100644 --- a/src/H5Apublic.h +++ b/src/H5Apublic.h @@ -84,7 +84,6 @@ 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 int H5Aget_num_attrs(hid_t loc_id); /* Symbols defined for compatibility with previous versions of the HDF5 API. * @@ -103,6 +102,7 @@ typedef herr_t (*H5A_operator1_t)(hid_t location_id/*in*/, /* Function prototypes */ +H5_DLL int H5Aget_num_attrs(hid_t loc_id); H5_DLL herr_t H5Adelete1(hid_t loc_id, const char *name); H5_DLL herr_t H5Arename1(hid_t loc_id, const char *old_name, const char *new_name); H5_DLL herr_t H5Aiterate1(hid_t loc_id, unsigned *attr_num, H5A_operator1_t op, diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c index 5050e5c..5c0a91a 100644 --- a/src/H5Oattribute.c +++ b/src/H5Oattribute.c @@ -1550,44 +1550,6 @@ H5O_attr_count_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh) /*------------------------------------------------------------------------- - * Function: H5O_attr_count - * - * Purpose: Determine the # of attributes on an object - * - * Return: Non-negative on success/Negative on failure - * - * Programmer: Quincey Koziol - * Monday, December 11, 2006 - * - *------------------------------------------------------------------------- - */ -int -H5O_attr_count(const H5O_loc_t *loc, hid_t dxpl_id) -{ - H5O_t *oh = NULL; /* Pointer to actual object header */ - int ret_value; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT(H5O_attr_count) - - /* Check arguments */ - HDassert(loc); - - /* Protect the object header to iterate over */ - if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) - HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header") - - /* Retrieve # of attributes on object */ - ret_value = (int)H5O_attr_count_real(loc->file, dxpl_id, oh); - -done: - if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0) - HDONE_ERROR(H5E_ATTR, H5E_PROTECT, FAIL, "unable to release object header") - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_attr_count */ - - -/*------------------------------------------------------------------------- * Function: H5O_attr_exists_cb * * Purpose: Object header iterator callback routine to check for an @@ -1765,3 +1727,43 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* H5O_attr_bh_info() */ +#ifndef H5_NO_DEPRECATED_SYMBOLS + +/*------------------------------------------------------------------------- + * Function: H5O_attr_count + * + * Purpose: Determine the # of attributes on an object + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Monday, December 11, 2006 + * + *------------------------------------------------------------------------- + */ +int +H5O_attr_count(const H5O_loc_t *loc, hid_t dxpl_id) +{ + H5O_t *oh = NULL; /* Pointer to actual object header */ + int ret_value; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5O_attr_count) + + /* Check arguments */ + HDassert(loc); + + /* Protect the object header to iterate over */ + if(NULL == (oh = (H5O_t *)H5AC_protect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, NULL, NULL, H5AC_READ))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTLOAD, FAIL, "unable to load object header") + + /* Retrieve # of attributes on object */ + ret_value = (int)H5O_attr_count_real(loc->file, dxpl_id, oh); + +done: + if(oh && H5AC_unprotect(loc->file, dxpl_id, H5AC_OHDR, loc->addr, oh, H5AC__NO_FLAGS_SET) < 0) + HDONE_ERROR(H5E_ATTR, H5E_PROTECT, FAIL, "unable to release object header") + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5O_attr_count */ +#endif /* H5_NO_DEPRECATED_SYMBOLS */ + diff --git a/test/objcopy.c b/test/objcopy.c index f6d32d1..ff0e4bb 100755 --- a/test/objcopy.c +++ b/test/objcopy.c @@ -760,11 +760,8 @@ static int compare_std_attributes(hid_t oid, hid_t oid2, hid_t pid) { hid_t aid = -1, aid2 = -1; /* Attribute IDs */ - int num_attrs; /* Number of attributes */ - int num_attrs2; /* Number of attributes */ - char attr_name[ATTR_NAME_LEN]; /* Attribute name */ + H5O_info_t oinfo1, oinfo2; /* Object info */ unsigned cpy_flags; /* Object copy flags */ - unsigned i; /* Local index variable */ /* Retrieve the object copy flags from the property list, if it's non-DEFAULT */ if(pid != H5P_DEFAULT) { @@ -774,23 +771,26 @@ compare_std_attributes(hid_t oid, hid_t oid2, hid_t pid) cpy_flags = 0; /* Check the number of attributes on source dataset */ - if((num_attrs = H5Aget_num_attrs(oid)) < 0) TEST_ERROR + if(H5Oget_info(oid, ".", &oinfo1, H5P_DEFAULT) < 0) TEST_ERROR /* Check the number of attributes on destination dataset */ - if((num_attrs2 = H5Aget_num_attrs(oid2)) < 0) TEST_ERROR + if(H5Oget_info(oid2, ".", &oinfo2, H5P_DEFAULT) < 0) TEST_ERROR if(cpy_flags & H5O_COPY_WITHOUT_ATTR_FLAG) { /* Check that the destination has no attributes */ - if(num_attrs2 != 0) TEST_ERROR + if(oinfo2.num_attrs != 0) TEST_ERROR } /* end if */ else { + char attr_name[ATTR_NAME_LEN]; /* Attribute name */ + unsigned i; /* Local index variable */ + /* Compare the number of attributes */ - if(num_attrs != num_attrs2) TEST_ERROR + if(oinfo1.num_attrs != oinfo1.num_attrs) TEST_ERROR /* Check the attributes are equal */ - for(i = 0; i < (unsigned)num_attrs; i++) { - if ( (aid = H5Aopen_idx(oid, i) ) < 0 ) TEST_ERROR - if ( H5Aget_name(aid, ATTR_NAME_LEN, attr_name ) < 0) TEST_ERROR + for(i = 0; i < (unsigned)oinfo1.num_attrs; i++) { + if((aid = H5Aopen_idx(oid, i)) < 0) TEST_ERROR + if(H5Aget_name(aid, ATTR_NAME_LEN, attr_name) < 0) TEST_ERROR if((aid2 = H5Aopen_name(oid2, attr_name)) < 0) TEST_ERROR diff --git a/test/tattr.c b/test/tattr.c index 6800269..53f2c21 100644 --- a/test/tattr.c +++ b/test/tattr.c @@ -388,14 +388,15 @@ test_attr_basic_write(hid_t fapl) static void test_attr_basic_read(hid_t fapl) { - hid_t fid1; /* HDF5 File IDs */ - hid_t dataset; /* Dataset ID */ - hid_t group; /* Group ID */ - hid_t attr; /* Attribute ID */ - int read_data1[ATTR1_DIM1]={0}; /* Buffer for reading 1st attribute */ - int read_data2[ATTR2_DIM1][ATTR2_DIM2]={{0}}; /* Buffer for reading 2nd attribute */ - int i,j; - herr_t ret; /* Generic return value */ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t group; /* Group ID */ + hid_t attr; /* Attribute ID */ + H5O_info_t oinfo; /* Object info */ + int read_data1[ATTR1_DIM1] = {0}; /* Buffer for reading 1st attribute */ + int read_data2[ATTR2_DIM1][ATTR2_DIM2] = {{0}}; /* Buffer for reading 2nd attribute */ + int i, j; /* Local index variables */ + herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Basic Attribute Functions\n")); @@ -405,28 +406,29 @@ test_attr_basic_read(hid_t fapl) CHECK(fid1, FAIL, "H5Fopen"); /* Open the dataset */ - dataset=H5Dopen(fid1,DSET1_NAME); + dataset = H5Dopen(fid1, DSET1_NAME); CHECK(dataset, FAIL, "H5Dopen"); /* Verify the correct number of attributes */ - ret=H5Aget_num_attrs(dataset); - VERIFY(ret, 2, "H5Aget_num_attrs"); + ret = H5Oget_info(dataset, ".", &oinfo, H5P_DEFAULT); + CHECK(ret, FAIL, "H5Oget_info"); + VERIFY(oinfo.num_attrs, 2, "H5Oget_info"); /* Open first attribute for the dataset */ - attr=H5Aopen_name(dataset, ATTR_TMP_NAME); + attr = H5Aopen_name(dataset, ATTR_TMP_NAME); CHECK(attr, FAIL, "H5Aopen_name"); /* Read attribute information */ - ret=H5Aread(attr,H5T_NATIVE_INT,read_data1); + ret = H5Aread(attr, H5T_NATIVE_INT, read_data1); CHECK(ret, FAIL, "H5Aread"); /* Verify values read in */ - for(i=0; i