From bbe23c026f974be06e2aa86cff55cd255b33e2d0 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 29 Oct 2003 13:27:37 -0500 Subject: [svn-r7786] Purpose: Code cleanup & add a feature Description: Added support for querying the file ID of named datatypes to new H5Iget_file_id function. Platforms tested: FreeBSD 4.9 (sleipnir) too minor to require h5committest --- src/H5F.c | 1 - src/H5Gprivate.h | 1 - src/H5I.c | 40 ++++++++++++++++++++++------------------ src/H5Iprivate.h | 1 - test/Makefile.in | 2 +- test/tfile.c | 22 +++++++++++++++++++++- 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/H5F.c b/src/H5F.c index dd9a3d6..b095ace 100644 --- a/src/H5F.c +++ b/src/H5F.c @@ -4191,7 +4191,6 @@ H5F_get_id(H5F_t *file) assert(file); ret_value = file->file_id; -done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5F_get_id() */ diff --git a/src/H5Gprivate.h b/src/H5Gprivate.h index b2bff6c..2bf2c3f 100644 --- a/src/H5Gprivate.h +++ b/src/H5Gprivate.h @@ -38,7 +38,6 @@ #include "H5private.h" /* Generic Functions */ #include "H5Bprivate.h" /* B-trees */ #include "H5Fprivate.h" /* File access */ -#include "H5Gprivate.h" /* Group */ #include "H5RSprivate.h" /* Reference-counted strings */ /* diff --git a/src/H5I.c b/src/H5I.c index 627b605..4af50a1 100644 --- a/src/H5I.c +++ b/src/H5I.c @@ -117,6 +117,7 @@ H5FL_DEFINE_STATIC(H5I_id_info_t); /*--------------------- Local function prototypes ---------------------------*/ static herr_t H5I_init_interface(void); static H5I_id_info_t *H5I_find_id(hid_t id); +static hid_t H5I_get_file_id(hid_t obj_id); #ifdef H5I_DEBUG_OUTPUT static herr_t H5I_debug(H5I_type_t grp); #endif /* H5I_DEBUG_OUTPUT */ @@ -812,12 +813,13 @@ done: hid_t H5Iget_file_id(hid_t obj_id) { - hid_t ret_value = FAIL; + hid_t ret_value; FUNC_ENTER_API(H5Iget_file_id, FAIL); H5TRACE1("i","i",obj_id); - ret_value = H5I_get_file_id(obj_id); + if((ret_value = H5I_get_file_id(obj_id))<0) + HGOTO_ERROR (H5E_ATOM, H5E_CANTGET, FAIL, "can't retrieve file ID"); done: FUNC_LEAVE_API(ret_value); @@ -841,39 +843,41 @@ done: * *------------------------------------------------------------------------- */ -hid_t +static hid_t H5I_get_file_id(hid_t obj_id) { - hid_t ret_value = FAIL; - H5I_type_t obj_type = H5I_BADID; H5G_entry_t *ent; + hid_t ret_value; - FUNC_ENTER_NOAPI(H5I_get_file_id, FAIL); + FUNC_ENTER_NOINIT(H5I_get_file_id); /* Get object type */ - obj_type = H5I_GRP(obj_id); - - switch(obj_type) { + switch(H5I_GRP(obj_id)) { case H5I_FILE: ret_value = obj_id; - /* Increment reference count on atom. */ - if (H5I_inc_ref(ret_value)<0) - HGOTO_ERROR (H5E_ATOM, H5E_CANTGET, FAIL, "incrementing file ID failed"); - break; + + case H5I_DATATYPE: + if((ent = H5G_loc(obj_id))==NULL) + HGOTO_ERROR (H5E_ATOM, H5E_CANTGET, FAIL, "not a named datatype"); + ret_value = H5F_get_id(ent->file); + break; + case H5I_GROUP: case H5I_DATASET: case H5I_ATTR: - ent = H5G_loc(obj_id); + if((ent = H5G_loc(obj_id))==NULL) + HGOTO_ERROR (H5E_ATOM, H5E_CANTGET, FAIL, "can't get symbol table info"); ret_value = H5F_get_id(ent->file); - /* Increment reference count on atom. */ - if (H5I_inc_ref(ret_value)<0) - HGOTO_ERROR (H5E_ATOM, H5E_CANTGET, FAIL, "incrementing file ID failed"); - break; + default: HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid object ID"); } + + /* Increment reference count on atom. */ + if (H5I_inc_ref(ret_value)<0) + HGOTO_ERROR (H5E_ATOM, H5E_CANTSET, FAIL, "incrementing file ID failed"); done: FUNC_LEAVE_NOAPI(ret_value); diff --git a/src/H5Iprivate.h b/src/H5Iprivate.h index 42369e3..79819a5 100644 --- a/src/H5Iprivate.h +++ b/src/H5Iprivate.h @@ -67,7 +67,6 @@ H5_DLL hid_t H5I_register(H5I_type_t grp, void *object); H5_DLL void *H5I_object(hid_t id); H5_DLL void *H5I_object_verify(hid_t id, H5I_type_t id_type); H5_DLL H5I_type_t H5I_get_type(hid_t id); -H5_DLL hid_t H5I_get_file_id(hid_t obj_id); H5_DLL void *H5I_remove(hid_t id); H5_DLL void *H5I_search(H5I_type_t grp, H5I_search_func_t func, void *key); H5_DLL int H5I_inc_ref(hid_t id); diff --git a/test/Makefile.in b/test/Makefile.in index 022c58c..823c088 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -54,7 +54,7 @@ PUB_LIB= ## prefix or low-level driver with environment variables will influence ## the temporary file name in ways that the makefile is not aware of. MOSTLYCLEAN=cmpd_dset.h5 compact_dataset.h5 dataset.h5 extend.h5 istore.h5 \ - tfile1.h5 tfile2.h5 tfile3.h5 th5s1.h5 lheap.h5 ohdr.h5 stab1.h5 \ + tfile[1-4].h5 th5s1.h5 lheap.h5 ohdr.h5 stab1.h5 \ stab2.h5 extern_[1-3].h5 extern_[1-4][ab].raw gheap[0-4].h5 \ links.h5 links[1-3].h5 big.data big[0-9][0-9][0-9][0-9][0-9].h5 \ dtypes[1-3].h5 tattr.h5 tselect.h5 mtime.h5 unlink.h5 \ diff --git a/test/tfile.c b/test/tfile.c index 91ecf18..a5ec702 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -54,6 +54,7 @@ #define FILE3 "tfile3.h5" #define ATTR_NAME "attr" +#define TYPE_NAME "type" #define FILE4 "tfile4.h5" #define OBJ_ID_COUNT_0 0 @@ -827,7 +828,7 @@ static void test_get_file_id(void) { hid_t fid1, fid2; - hid_t dataset_id, dataspace_id, group_id, attr_id; + hid_t datatype_id, dataset_id, dataspace_id, group_id, attr_id; hid_t plist; hsize_t dims[F2_RANK]; herr_t ret; @@ -891,6 +892,22 @@ test_get_file_id(void) ret = H5Fclose(fid2); CHECK(ret, FAIL, "H5Fclose"); + /* Create a named datatype. Make a duplicated file ID from + * this attribute. And close it. + */ + datatype_id=H5Tcopy(H5T_NATIVE_INT); + CHECK(ret, FAIL, "H5Acreate"); + + ret = H5Tcommit(fid1, TYPE_NAME, datatype_id); + CHECK(ret, FAIL, "H5Tcommit"); + + fid2 = H5Iget_file_id(datatype_id); + CHECK(fid2, FAIL, "H5Iget_file_id"); + VERIFY(fid2, fid1, "H5Iget_file_id"); + + ret = H5Fclose(fid2); + CHECK(ret, FAIL, "H5Fclose"); + /* Create a property list and try to get file ID from it. * Supposed to fail. */ @@ -903,6 +920,9 @@ test_get_file_id(void) VERIFY(fid2, FAIL, "H5Iget_file_id"); /* Close objects */ + ret = H5Tclose(datatype_id); + CHECK(ret, FAIL, "H5Tclose"); + ret = H5Aclose(attr_id); CHECK(ret, FAIL, "H5Aclose"); -- cgit v0.12