diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2008-09-26 21:50:36 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2008-09-26 21:50:36 (GMT) |
commit | f11d4727554c852a9deff20ae73971bd73e8077a (patch) | |
tree | 52a0b1fa142f3d8b1f6f7753e450fe569848f82a | |
parent | 0d6737c3d11b407f7ba5647d0f2080507fd28e0e (diff) | |
download | hdf5-f11d4727554c852a9deff20ae73971bd73e8077a.zip hdf5-f11d4727554c852a9deff20ae73971bd73e8077a.tar.gz hdf5-f11d4727554c852a9deff20ae73971bd73e8077a.tar.bz2 |
[svn-r15708] I changed the return values of H5Fget_obj_ids and H5Fget_obj_count to ssize_t and modified
C++ and Fortran API functions. This is for bug #1245.
Tested on kagiso - I've tested the same change for the trunk using h5committest.
-rw-r--r-- | c++/src/H5File.cpp | 12 | ||||
-rw-r--r-- | c++/src/H5File.h | 6 | ||||
-rw-r--r-- | fortran/src/H5Ff.c | 54 | ||||
-rw-r--r-- | fortran/src/H5Fff.f90 | 30 | ||||
-rw-r--r-- | fortran/src/H5f90proto.h | 4 | ||||
-rw-r--r-- | fortran/test/tH5F.f90 | 4 | ||||
-rw-r--r-- | release_docs/RELEASE.txt | 4 | ||||
-rw-r--r-- | src/H5F.c | 98 | ||||
-rw-r--r-- | src/H5Fprivate.h | 4 | ||||
-rw-r--r-- | src/H5Fpublic.h | 4 | ||||
-rw-r--r-- | test/mount.c | 2 | ||||
-rw-r--r-- | test/tfile.c | 8 |
12 files changed, 143 insertions, 87 deletions
diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index 4a48e38..0737a06 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -378,9 +378,9 @@ hssize_t H5File::getFreeSpace() const /// Multiple object types can be combined with the logical OR operator (|). // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -int H5File::getObjCount(unsigned types) const +ssize_t H5File::getObjCount(unsigned types) const { - int num_objs = H5Fget_obj_count(id, types); + ssize_t num_objs = H5Fget_obj_count(id, types); if( num_objs < 0 ) { throw FileIException("H5File::getObjCount", "H5Fget_obj_count failed"); @@ -397,9 +397,9 @@ int H5File::getObjCount(unsigned types) const ///\exception H5::FileIException // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -int H5File::getObjCount() const +ssize_t H5File::getObjCount() const { - int num_objs = H5Fget_obj_count(id, H5F_OBJ_ALL); + ssize_t num_objs = H5Fget_obj_count(id, H5F_OBJ_ALL); if( num_objs < 0 ) { throw FileIException("H5File::getObjCount", "H5Fget_obj_count failed"); @@ -432,9 +432,9 @@ int H5File::getObjCount() const // Notes: will do the overload for this one after hearing from Quincey??? // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -void H5File::getObjIDs(unsigned types, int max_objs, hid_t *oid_list) const +void H5File::getObjIDs(unsigned types, size_t max_objs, hid_t *oid_list) const { - herr_t ret_value = H5Fget_obj_ids(id, types, max_objs, oid_list); + ssize_t ret_value = H5Fget_obj_ids(id, types, max_objs, oid_list); if( ret_value < 0 ) { throw FileIException("H5File::getObjIDs", "H5Fget_obj_ids failed"); diff --git a/c++/src/H5File.h b/c++/src/H5File.h index f5d8dea..f022d66 100644 --- a/c++/src/H5File.h +++ b/c++/src/H5File.h @@ -60,12 +60,12 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { // Returns the number of opened object IDs (files, datasets, groups // and datatypes) in the same file. - int getObjCount(unsigned types) const; - int getObjCount() const; + ssize_t getObjCount(unsigned types) const; + ssize_t getObjCount() const; // Retrieves a list of opened object IDs (files, datasets, groups // and datatypes) in the same file. - void getObjIDs(unsigned types, int max_objs, hid_t *oid_list) const; + void getObjIDs(unsigned types, size_t max_objs, hid_t *oid_list) const; // Retrieves the type of object that an object reference points to. H5G_obj_t getRefObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; diff --git a/fortran/src/H5Ff.c b/fortran/src/H5Ff.c index cdbb695..6b76ba0 100644 --- a/fortran/src/H5Ff.c +++ b/fortran/src/H5Ff.c @@ -37,7 +37,7 @@ nh5fcreate_c(_fcd name, int_f *namelen, int_f *access_flags, hid_t_f* crt_prp, h { int ret_value = -1; char *c_name; - int c_namelen; + int_f c_namelen; hid_t c_file_id; unsigned c_access_flags; hid_t c_crt_prp; @@ -66,7 +66,7 @@ nh5fcreate_c(_fcd name, int_f *namelen, int_f *access_flags, hid_t_f* crt_prp, h * Convert FORTRAN name to C name */ c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); + c_name = (char *)HD5f2cstring(name, (size_t)c_namelen); if (c_name == NULL) return ret_value; /* @@ -184,7 +184,7 @@ nh5funmount_c (hid_t_f *loc_id, _fcd dsetname, int_f *namelen) { int ret_value = -1; char *c_name; - int c_namelen; + int_f c_namelen; hid_t c_loc_id; htri_t status; @@ -194,7 +194,7 @@ nh5funmount_c (hid_t_f *loc_id, _fcd dsetname, int_f *namelen) * Convert FORTRAN name to C name */ c_namelen = *namelen; - c_name = (char *)HD5f2cstring(dsetname, c_namelen); + c_name = (char *)HD5f2cstring(dsetname, (size_t)c_namelen); if (c_name == NULL) return ret_value; /* @@ -228,7 +228,7 @@ nh5fopen_c (_fcd name, int_f *namelen, int_f *access_flags, hid_t_f *acc_prp, hi { int ret_value = -1; char *c_name; - int c_namelen; + int_f c_namelen; hid_t c_file_id; unsigned c_access_flags; hid_t c_acc_prp; @@ -250,7 +250,7 @@ nh5fopen_c (_fcd name, int_f *namelen, int_f *access_flags, hid_t_f *acc_prp, hi * Convert FORTRAN name to C name */ c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); + c_name = (char *)HD5f2cstring(name, (size_t)c_namelen); if (c_name == NULL) return ret_value; /* @@ -361,14 +361,14 @@ nh5fis_hdf5_c (_fcd name, int_f *namelen, int_f *flag) { int ret_value = -1; char *c_name; - int c_namelen; + int_f c_namelen; htri_t status; /* * Convert FORTRAN name to C name */ c_namelen = *namelen; - c_name = (char *)HD5f2cstring(name, c_namelen); + c_name = (char *)HD5f2cstring(name, (size_t)c_namelen); if (c_name == NULL) return ret_value; /* @@ -397,7 +397,7 @@ nh5fclose_c ( hid_t_f *file_id ) int ret_value = 0; hid_t c_file_id; - c_file_id = *file_id; + c_file_id = (hid_t*)*file_id; if ( H5Fclose(c_file_id) < 0 ) ret_value = -1; return ret_value; } @@ -411,21 +411,23 @@ nh5fclose_c ( hid_t_f *file_id ) * Programmer: Elena Pourmal * Monday, September 30, 2002 * Modifications: + * Changed type of obj_count to size_t_f + * Thursday, September 25, 2008 *---------------------------------------------------------------------------*/ int_f -nh5fget_obj_count_c ( hid_t_f *file_id , int_f *obj_type, int_f * obj_count) +nh5fget_obj_count_c ( hid_t_f *file_id , int_f *obj_type, size_t_f * obj_count) { int ret_value = 0; hid_t c_file_id; unsigned c_obj_type; - int c_obj_count; + ssize_t c_obj_count; c_file_id = (hid_t)*file_id; c_obj_type = (unsigned) *obj_type; if ( (c_obj_count=H5Fget_obj_count(c_file_id, c_obj_type)) < 0 ) ret_value = -1; - *obj_count = (int_f)c_obj_count; + *obj_count = (size_t_f)c_obj_count; return ret_value; } /*---------------------------------------------------------------------------- @@ -438,20 +440,34 @@ nh5fget_obj_count_c ( hid_t_f *file_id , int_f *obj_type, int_f * obj_count) * Programmer: Elena Pourmal * Monday, September 30, 2002 * Modifications: + * Changed type of max_obj to size_t_f; added parameter for the + * number of open objects + * Thursday, September 25, 2008 EIP *---------------------------------------------------------------------------*/ - int_f -nh5fget_obj_ids_c ( hid_t_f *file_id , int_f *obj_type, int_f *max_objs, hid_t_f *obj_ids) +nh5fget_obj_ids_c ( hid_t_f *file_id , int_f *obj_type, size_t_f *max_objs, hid_t_f *obj_ids, +size_t_f *num_objs) { int ret_value = 0; hid_t c_file_id; unsigned c_obj_type; - int c_max_objs; + int i; + size_t c_max_objs; + ssize_t c_num_objs; + hid_t *c_obj_ids; c_file_id = (hid_t)*file_id; c_obj_type = (unsigned) *obj_type; - c_max_objs = (int)*max_objs; - if ( H5Fget_obj_ids(c_file_id, c_obj_type, c_max_objs, (hid_t *)obj_ids) < 0 ) ret_value = -1; + c_max_objs = (size_t)*max_objs; + c_obj_ids = (hid_t *)HDmalloc(sizeof(hid_t)*c_max_objs); + + c_num_objs = H5Fget_obj_ids(c_file_id, c_obj_type, c_max_objs, c_obj_ids); + if ( c_num_objs < 0 ) ret_value = -1; + for (i=0; i< c_max_objs; i++) obj_ids[i] = (hid_t_f)c_obj_ids[i]; + + HDfree(c_obj_ids); + *num_objs = (size_t_f)c_num_objs; + return ret_value; } /*---------------------------------------------------------------------------- @@ -494,7 +510,7 @@ int_f nh5fget_name_c(hid_t_f *obj_id, size_t_f *size, _fcd buf, size_t_f *buflen) { char *c_buf=NULL; /* Buffer to hold C string */ - ssize_t size_c; + ssize_t size_c = -1; int_f ret_value=0; /* Return value */ /* @@ -504,7 +520,7 @@ nh5fget_name_c(hid_t_f *obj_id, size_t_f *size, _fcd buf, size_t_f *buflen) HGOTO_DONE(FAIL); /* - * Call H5Aget_name function + * Call H5Fget_name function */ if ((size_c = (size_t_f)H5Fget_name((hid_t)*obj_id, c_buf, (size_t)*buflen)) < 0) HGOTO_DONE(FAIL); diff --git a/fortran/src/H5Fff.f90 b/fortran/src/H5Fff.f90 index ac03517..433336c 100644 --- a/fortran/src/H5Fff.f90 +++ b/fortran/src/H5Fff.f90 @@ -708,7 +708,8 @@ ! September 30, 2002 ! ! Modifications: -! +! Changed the type of obj_count to INTEGER(SIZE_T) +! September 25, 2008 EIP ! Comment: !---------------------------------------------------------------------- @@ -723,7 +724,8 @@ IMPLICIT NONE INTEGER(HID_T), INTENT(IN) :: file_id ! File identifier INTEGER, INTENT(IN) :: obj_type ! Object type - INTEGER, INTENT(OUT) :: obj_count ! Number of open objects + INTEGER(SIZE_T), INTENT(OUT) :: obj_count + ! Number of open objects INTEGER, INTENT(OUT) :: hdferr ! Error code INTERFACE @@ -734,7 +736,8 @@ !DEC$ ENDIF INTEGER(HID_T), INTENT(IN) :: file_id INTEGER, INTENT(IN) :: obj_type ! Object type - INTEGER, INTENT(OUT) :: obj_count ! Number of open objects + INTEGER(SIZE_T), INTENT(OUT) :: obj_count + ! Number of open objects END FUNCTION h5fget_obj_count_c END INTERFACE @@ -767,11 +770,15 @@ ! September 30, 2002 ! ! Modifications: +! Added optional parameter num_objs for number of open objects +! of the specified type and changed type of max_obj to +! INTEGER(SIZE_T) +! September 25, 2008 EIP ! ! Comment: !---------------------------------------------------------------------- - SUBROUTINE h5fget_obj_ids_f(file_id, obj_type, max_objs, obj_ids, hdferr) + SUBROUTINE h5fget_obj_ids_f(file_id, obj_type, max_objs, obj_ids, hdferr, num_objs) ! !This definition is needed for Windows DLLs !DEC$if defined(BUILD_HDF5_DLL) @@ -782,25 +789,30 @@ IMPLICIT NONE INTEGER(HID_T), INTENT(IN) :: file_id ! File identifier INTEGER, INTENT(IN) :: obj_type ! Object type - INTEGER, INTENT(IN) :: max_objs ! Maximum # of objects to retrieve + INTEGER(SIZE_T), INTENT(IN) :: max_objs ! Maximum # of objects to retrieve INTEGER(HID_T), DIMENSION(*), INTENT(INOUT) :: obj_ids ! Array of open objects iidentifiers - INTEGER, INTENT(OUT) :: hdferr ! Error code + INTEGER, INTENT(OUT) :: hdferr ! Error code + INTEGER(SIZE_T), INTENT(OUT), OPTIONAL :: num_objs + INTEGER(SIZE_T) :: c_num_objs + ! Number of open objects of the specified type INTERFACE - INTEGER FUNCTION h5fget_obj_ids_c(file_id, obj_type, max_objs, obj_ids) + INTEGER FUNCTION h5fget_obj_ids_c(file_id, obj_type, max_objs, obj_ids, c_num_objs) USE H5GLOBAL !DEC$ IF DEFINED(HDF5F90_WINDOWS) !MS$ATTRIBUTES C,reference,alias:'_H5FGET_OBJ_IDS_C':: h5fget_obj_ids_c !DEC$ ENDIF INTEGER(HID_T), INTENT(IN) :: file_id INTEGER, INTENT(IN) :: obj_type - INTEGER, INTENT(IN) :: max_objs + INTEGER(SIZE_T), INTENT(IN) :: max_objs INTEGER(HID_T), DIMENSION(*), INTENT(INOUT) :: obj_ids + INTEGER(SIZE_T), INTENT(OUT) :: c_num_objs END FUNCTION h5fget_obj_ids_c END INTERFACE - hdferr = h5fget_obj_ids_c(file_id, obj_type, max_objs, obj_ids) + hdferr = h5fget_obj_ids_c(file_id, obj_type, max_objs, obj_ids, c_num_objs) + if (present(num_objs)) num_objs= c_num_objs END SUBROUTINE h5fget_obj_ids_f diff --git a/fortran/src/H5f90proto.h b/fortran/src/H5f90proto.h index e43b063..a506496 100644 --- a/fortran/src/H5f90proto.h +++ b/fortran/src/H5f90proto.h @@ -69,8 +69,8 @@ H5_FCDLL int_f nh5funmount_c (hid_t_f *loc_id, _fcd dsetname, int_f *namelen); H5_FCDLL int_f nh5freopen_c (hid_t_f *file_id1, hid_t_f *file_id2); H5_FCDLL int_f nh5fget_create_plist_c (hid_t_f *file_id, hid_t_f *prop_id); H5_FCDLL int_f nh5fget_access_plist_c (hid_t_f *file_id, hid_t_f *access_id); -H5_FCDLL int_f nh5fget_obj_count_c (hid_t_f *file_id, int_f *obj_type, int_f *obj_count); -H5_FCDLL int_f nh5fget_obj_ids_c (hid_t_f *file_id, int_f *obj_type, int_f *max_objs, int_f *obj_ids); +H5_FCDLL int_f nh5fget_obj_count_c (hid_t_f *file_id, int_f *obj_type, size_t_f *obj_count); +H5_FCDLL int_f nh5fget_obj_ids_c (hid_t_f *file_id, int_f *obj_type, size_t_f *max_objs, hid_t_f *obj_ids, size_t_f *num_objs); H5_FCDLL int_f nh5fget_freespace_c (hid_t_f *file_id, hssize_t_f *free_space); H5_FCDLL int_f nh5fflush_c (hid_t_f *obj_id, int_f *scope); H5_FCDLL int_f nh5fget_name_c(hid_t_f *obj_id, size_t_f *size, _fcd buf, size_t_f *buflen); diff --git a/fortran/test/tH5F.f90 b/fortran/test/tH5F.f90 index 00619fe..e36a7d8 100644 --- a/fortran/test/tH5F.f90 +++ b/fortran/test/tH5F.f90 @@ -578,7 +578,7 @@ INTEGER(HID_T) :: fapl, fapl1, fapl2, fapl3 ! File access identifiers INTEGER(HID_T) :: fid_d_fapl, fid1_fapl ! File access identifiers LOGICAL :: flag - INTEGER :: obj_count, obj_countf + INTEGER(SIZE_T) :: obj_count, obj_countf INTEGER(HID_T), ALLOCATABLE, DIMENSION(:) :: obj_ids INTEGER :: i @@ -654,7 +654,7 @@ write(*,*) "Wrong number of open objects reported, error" endif allocate(obj_ids(obj_countf), stat = error) - CALL h5fget_obj_ids_f(fid, H5F_OBJ_FILE_F, -1, obj_ids, error) + CALL h5fget_obj_ids_f(fid, H5F_OBJ_FILE_F, obj_countf, obj_ids, error) CALL check("h5fget_obj_ids_f",error,total_error) if(error .eq. 0) then do i = 1, obj_countf diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 21f08cf..82d60a2 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -110,7 +110,9 @@ Bug Fixes since HDF5-1.6.7 Release Library ------- - None + - Changed the return value of H5Fget_obj_count from INT to SSIZE_T. Also + changed the return value of H5Fget_obj_ids from HERR_T to SSIZE_T and + the type of the parameter MAX_OBJS from INT to SIZE_T. (SLU - 2008/09/26) Configuration ------------- @@ -49,7 +49,7 @@ typedef struct H5F_olist_t { H5I_type_t obj_type; /* Type of object to look for */ hid_t *obj_id_list; /* Pointer to the list of open IDs to return */ - unsigned *obj_id_count; /* Number of open IDs */ + size_t *obj_id_count; /* Number of open IDs */ struct { hbool_t local; /* Set flag for "local" file searches */ union { @@ -57,15 +57,15 @@ typedef struct H5F_olist_t { const H5F_t *file; /* Pointer to file to look inside */ } ptr; } file_info; - unsigned list_index; /* Current index in open ID array */ - int max_index; /* Maximum # of IDs to put into array */ + size_t list_index; /* Current index in open ID array */ + size_t max_index; /* Maximum # of IDs to put into array */ } H5F_olist_t; /* PRIVATE PROTOTYPES */ #ifdef NOT_YET static int H5F_flush_all_cb(void *f, hid_t fid, void *_invalidate); #endif /* NOT_YET */ -static unsigned H5F_get_objects(const H5F_t *f, unsigned types, int max_objs, hid_t *obj_id_list); +static size_t H5F_get_objects(const H5F_t *f, unsigned types, size_t max_objs, hid_t *obj_id_list); static int H5F_get_objects_cb(void *obj_ptr, hid_t obj_id, void *key); static herr_t H5F_get_vfd_handle(const H5F_t *file, hid_t fapl, void** file_handle); static H5F_t *H5F_new(H5F_file_t *shared, hid_t fcpl_id, hid_t fapl_id); @@ -854,25 +854,29 @@ done: * Wednesday, Dec 5, 2001 * * Modification: + * Raymond Lu + * 24 September 2008 + * Changed the return value to ssize_t to accommadate + * potential large number of objects. * *------------------------------------------------------------------------- */ -int +ssize_t H5Fget_obj_count(hid_t file_id, unsigned types) { H5F_t *f=NULL; - int ret_value; /* Return value */ + ssize_t ret_value; /* Return value */ FUNC_ENTER_API(H5Fget_obj_count, FAIL) - H5TRACE2("Is","iIu",file_id,types); + H5TRACE2("Zs","iIu",file_id,types); if( file_id != (hid_t)H5F_OBJ_ALL && (NULL==(f=H5I_object_verify(file_id,H5I_FILE))) ) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file id") if( (types&H5F_OBJ_ALL)==0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not an object type") - if((ret_value = H5F_get_obj_count(f, types))<0) - HGOTO_ERROR(H5E_FILE, H5E_CANTCOUNT, FAIL, "can't get object count") + /* H5F_get_obj_count doesn't fail */ + ret_value = H5F_get_obj_count(f, types); done: FUNC_LEAVE_API(ret_value) @@ -885,7 +889,7 @@ done: * Purpose: Private function return the number of opened object IDs * (files, datasets, groups, datatypes) in the same file. * - * Return: Non-negative on success; negative on failure. + * Return: Non-negative on success; can't fail. * * Programmer: Raymond Lu * Wednesday, Dec 5, 2001 @@ -894,14 +898,15 @@ done: * *------------------------------------------------------------------------- */ -unsigned +size_t H5F_get_obj_count(const H5F_t *f, unsigned types) { - unsigned ret_value; /* Return value */ + size_t ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_get_obj_count) - ret_value=H5F_get_objects(f, types, -1, NULL); + /* H5F_get_objects doesn't fail */ + ret_value=H5F_get_objects(f, types, 0, NULL); FUNC_LEAVE_NOAPI(ret_value) } @@ -918,17 +923,21 @@ H5F_get_obj_count(const H5F_t *f, unsigned types) * Wednesday, Dec 5, 2001 * * Modification: + * Raymond Lu + * 24 September 2008 + * Changed the return value to ssize_t and MAX_OBJTS to size_t to + * accommadate potential large number of objects. * *------------------------------------------------------------------------- */ -herr_t -H5Fget_obj_ids(hid_t file_id, unsigned types, int max_objs, hid_t *oid_list) +ssize_t +H5Fget_obj_ids(hid_t file_id, unsigned types, size_t max_objs, hid_t *oid_list) { - herr_t ret_value; + ssize_t ret_value; H5F_t *f=NULL; FUNC_ENTER_API(H5Fget_obj_ids, FAIL) - H5TRACE4("e","iIuIs*i",file_id,types,max_objs,oid_list); + H5TRACE4("Zs","iIuz*i",file_id,types,max_objs,oid_list); if( file_id != (hid_t)H5F_OBJ_ALL && (NULL==(f=H5I_object_verify(file_id,H5I_FILE))) ) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not a file id") @@ -936,6 +945,7 @@ H5Fget_obj_ids(hid_t file_id, unsigned types, int max_objs, hid_t *oid_list) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "not an object type") assert(oid_list); + /* H5F_get_objects doesn't fail */ ret_value = H5F_get_obj_ids(f, types, max_objs, oid_list); done: @@ -948,22 +958,27 @@ done: * * Purpose: Private function to return a list of opened object IDs. * - * Return: Non-negative on success; negative on failure. + * Return: Non-negative on success; can't fail. * * Programmer: Raymond Lu * Wednesday, Dec 5, 2001 * * Modification: + * Raymond Lu + * 24 September 2008 + * Changed the return value and MAX_OBJTS to size_t to accommadate + * potential large number of objects. * *------------------------------------------------------------------------- */ -unsigned -H5F_get_obj_ids(const H5F_t *f, unsigned types, int max_objs, hid_t *oid_list) +size_t +H5F_get_obj_ids(const H5F_t *f, unsigned types, size_t max_objs, hid_t *oid_list) { - unsigned ret_value; /* Return value */ + size_t ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_get_obj_ids) + /* H5F_get_objects doesn't fail */ ret_value = H5F_get_objects(f, types, max_objs, oid_list); FUNC_LEAVE_NOAPI(ret_value) @@ -976,7 +991,8 @@ H5F_get_obj_ids(const H5F_t *f, unsigned types, int max_objs, hid_t *oid_list) * Purpose: This function is called by H5F_get_obj_count or * H5F_get_obj_ids to get number of object IDs and/or a * list of opened object IDs (in return value). - * Return: Non-negative on success; negative on failure. + * + * Return: Non-negative on success; Can't fail. * * Programmer: Raymond Lu * Wednesday, Dec 5, 2001 @@ -985,12 +1001,12 @@ H5F_get_obj_ids(const H5F_t *f, unsigned types, int max_objs, hid_t *oid_list) * *--------------------------------------------------------------------------- */ -static unsigned -H5F_get_objects(const H5F_t *f, unsigned types, int max_index, hid_t *obj_id_list) +static size_t +H5F_get_objects(const H5F_t *f, unsigned types, size_t max_index, hid_t *obj_id_list) { - unsigned obj_id_count=0; /* Number of open IDs */ + size_t obj_id_count=0; /* Number of open IDs */ H5F_olist_t olist; /* Structure to hold search results */ - unsigned ret_value; /* Return value */ + size_t ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_get_objects) @@ -1001,7 +1017,7 @@ H5F_get_objects(const H5F_t *f, unsigned types, int max_index, hid_t *obj_id_lis olist.max_index = max_index; /* Determine if we are searching for local or global objects */ - if(types&H5F_OBJ_LOCAL) { + if(types & H5F_OBJ_LOCAL) { olist.file_info.local = TRUE; olist.file_info.ptr.file = f; } /* end if */ @@ -1011,7 +1027,8 @@ H5F_get_objects(const H5F_t *f, unsigned types, int max_index, hid_t *obj_id_lis } /* end else */ /* Search through file IDs to count the number, and put their - * IDs on the object list */ + * IDs on the object list. H5I_search returns NULL if no object + * is found, so don't return failure in this function. */ if(types & H5F_OBJ_FILE) { olist.obj_type = H5I_FILE; (void)H5I_search(H5I_FILE, H5F_get_objects_cb, &olist); @@ -1019,28 +1036,28 @@ H5F_get_objects(const H5F_t *f, unsigned types, int max_index, hid_t *obj_id_lis /* Search through dataset IDs to count number of datasets, and put their * IDs on the object list */ - if( (max_index < 0 || (int)olist.list_index < max_index) && (types & H5F_OBJ_DATASET) ) { + if(types & H5F_OBJ_DATASET) { olist.obj_type = H5I_DATASET; (void)H5I_search(H5I_DATASET, H5F_get_objects_cb, &olist); } /* Search through group IDs to count number of groups, and put their * IDs on the object list */ - if( (max_index < 0 || (int)olist.list_index < max_index) && (types & H5F_OBJ_GROUP) ) { + if(types & H5F_OBJ_GROUP) { olist.obj_type = H5I_GROUP; (void)H5I_search(H5I_GROUP, H5F_get_objects_cb, &olist); } /* Search through datatype IDs to count number of named datatypes, and put their * IDs on the object list */ - if( (max_index < 0 || (int)olist.list_index < max_index) && (types & H5F_OBJ_DATATYPE) ) { + if(types & H5F_OBJ_DATATYPE) { olist.obj_type = H5I_DATATYPE; (void)H5I_search(H5I_DATATYPE, H5F_get_objects_cb, &olist); } /* Search through attribute IDs to count number of attributes, and put their * IDs on the object list */ - if( (max_index < 0 || (int)olist.list_index < max_index) && (types & H5F_OBJ_ATTR) ) { + if(types & H5F_OBJ_ATTR) { olist.obj_type = H5I_ATTR; (void)H5I_search(H5I_ATTR, H5F_get_objects_cb, &olist); } @@ -1059,6 +1076,9 @@ H5F_get_objects(const H5F_t *f, unsigned types, int max_index, hid_t *obj_id_lis * object is in the file, and either count it or put its ID * on the list. * + * Return: TRUE if the array of object IDs is filled up. + * FALSE otherwise. + * * Programmer: Raymond Lu * Wednesday, Dec 5, 2001 * @@ -1093,8 +1113,11 @@ H5F_get_objects_cb(void *obj_ptr, hid_t obj_id, void *key) if(olist->obj_id_count) (*olist->obj_id_count)++; - /* Check if we've filled up the array */ - if(olist->max_index>=0 && (int)olist->list_index>=olist->max_index) + /* Check if we've filled up the array. Return TRUE only if + * we have filled up the array. Otherwise return FALSE(RET_VALUE is + * preset to FALSE) because H5I_search needs the return value of FALSE + * to continue searching. */ + if(olist->max_index>0 && (int)olist->list_index>=olist->max_index) HGOTO_DONE(TRUE) /* Indicate that the iterator should stop */ } } else { /* either count opened object IDs or put the IDs on the list */ @@ -1138,8 +1161,11 @@ H5F_get_objects_cb(void *obj_ptr, hid_t obj_id, void *key) if(olist->obj_id_count) (*olist->obj_id_count)++; - /* Check if we've filled up the array */ - if(olist->max_index>=0 && (int)olist->list_index>=olist->max_index) + /* Check if we've filled up the array. Return TRUE only if + * we have filled up the array. Otherwise return FALSE(RET_VALUE is + * preset to FALSE) because H5I_search needs the return value of FALSE + * to continue searching. */ + if(olist->max_index>0 && (int)olist->list_index>=olist->max_index) HGOTO_DONE(TRUE) /* Indicate that the iterator should stop */ } } diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 24b7080..bc59597 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -424,8 +424,8 @@ H5_DLL hid_t H5F_get_driver_id(const H5F_t *f); H5_DLL unsigned H5F_get_intent(const H5F_t *f); H5_DLL herr_t H5F_get_fileno(const H5F_t *f, unsigned long *filenum); H5_DLL hid_t H5F_get_id(H5F_t *file); -H5_DLL unsigned H5F_get_obj_count(const H5F_t *f, unsigned types); -H5_DLL unsigned H5F_get_obj_ids(const H5F_t *f, unsigned types, int max_objs, hid_t *obj_id_list); +H5_DLL size_t H5F_get_obj_count(const H5F_t *f, unsigned types); +H5_DLL size_t H5F_get_obj_ids(const H5F_t *f, unsigned types, size_t max_objs, hid_t *obj_id_list); H5_DLL haddr_t H5F_get_base_addr(const H5F_t *f); H5_DLL haddr_t H5F_get_eoa(const H5F_t *f); #ifdef H5_HAVE_PARALLEL diff --git a/src/H5Fpublic.h b/src/H5Fpublic.h index 9bbe69f..8927484 100644 --- a/src/H5Fpublic.h +++ b/src/H5Fpublic.h @@ -111,8 +111,8 @@ H5_DLL herr_t H5Fflush(hid_t object_id, H5F_scope_t scope); H5_DLL herr_t H5Fclose (hid_t file_id); H5_DLL hid_t H5Fget_create_plist (hid_t file_id); H5_DLL hid_t H5Fget_access_plist (hid_t file_id); -H5_DLL int H5Fget_obj_count(hid_t file_id, unsigned types); -H5_DLL int H5Fget_obj_ids(hid_t file_id, unsigned types, int max_objs, hid_t *obj_id_list); +H5_DLL ssize_t H5Fget_obj_count(hid_t file_id, unsigned types); +H5_DLL ssize_t H5Fget_obj_ids(hid_t file_id, unsigned types, size_t max_objs, hid_t *obj_id_list); H5_DLL herr_t H5Fget_vfd_handle(hid_t file_id, hid_t fapl, void** file_handle); H5_DLL herr_t H5Fmount(hid_t loc, const char *name, hid_t child, hid_t plist); H5_DLL herr_t H5Funmount(hid_t loc, const char *name); diff --git a/test/mount.c b/test/mount.c index 4a62a05..3d89449 100644 --- a/test/mount.c +++ b/test/mount.c @@ -3266,7 +3266,7 @@ test_cut_graph(hid_t fapl) hid_t gidQ = -1; /* Group IDs in file #7 */ char name[NAME_BUF_SIZE]; /* Buffer for filename retrieved */ ssize_t name_len; /* Filename length */ - int obj_count; /* Number of objects open */ + ssize_t obj_count; /* Number of objects open */ char filename1[NAME_BUF_SIZE], filename2[NAME_BUF_SIZE], filename3[NAME_BUF_SIZE], diff --git a/test/tfile.c b/test/tfile.c index f04e116..86d70f9 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -747,7 +747,7 @@ static void create_objects(hid_t fid1, hid_t fid2, hid_t *ret_did, hid_t *ret_gid1, hid_t *ret_gid2, hid_t *ret_gid3) { - int oid_count; + ssize_t oid_count; herr_t ret; /* Check reference counts of file IDs and opened object IDs. @@ -1011,7 +1011,7 @@ test_obj_count_and_id(hid_t fid1, hid_t fid2, hid_t did, hid_t gid1, hid_t gid2, hid_t gid3) { hid_t fid3, fid4; - int oid_count; + ssize_t oid_count, ret_count; herr_t ret; /* Create two new files */ @@ -1057,8 +1057,8 @@ test_obj_count_and_id(hid_t fid1, hid_t fid2, hid_t did, hid_t gid1, oid_list = (hid_t*)calloc((size_t)oid_count, sizeof(hid_t)); if(oid_list != NULL) { - ret = H5Fget_obj_ids(H5F_OBJ_ALL, H5F_OBJ_ALL, oid_count, oid_list); - CHECK(ret, FAIL, "H5Fget_obj_ids"); + ret_count = H5Fget_obj_ids(H5F_OBJ_ALL, H5F_OBJ_ALL, (size_t)oid_count, oid_list); + CHECK(ret_count, FAIL, "H5Fget_obj_ids"); } for(i=0; i<oid_count; i++) { |