From 843ccf86dd147e245bab269520741b0f103b4d6b Mon Sep 17 00:00:00 2001 From: Mohamad Chaarawi Date: Fri, 6 Jul 2012 17:44:35 -0500 Subject: [svn-r22523] - rework how IDs for VOL objects are created - change how the vlose routine is registered with VOL IDs - some bug fixes --- src/H5A.c | 48 +++------ src/H5Adeprec.c | 31 ++---- src/H5Aint.c | 12 +-- src/H5D.c | 23 +---- src/H5Ddeprec.c | 18 +--- src/H5Dint.c | 8 +- src/H5Doh.c | 4 +- src/H5F.c | 42 +++----- src/H5Fint.c | 2 +- src/H5G.c | 30 ++---- src/H5Gdeprec.c | 18 +--- src/H5Gint.c | 8 +- src/H5Goh.c | 4 +- src/H5Gtraverse.c | 4 +- src/H5I.c | 284 +++++++++++++++++++++++++++++++++++++++++++++++------- src/H5Iprivate.h | 4 +- src/H5L.c | 8 +- src/H5O.c | 31 ++++-- src/H5T.c | 3 +- src/H5Tcommit.c | 39 +------- src/H5Toh.c | 26 +++-- src/H5VLint.c | 1 + src/H5VLnative.c | 57 +++-------- src/H5VLnative.h | 4 +- 24 files changed, 382 insertions(+), 327 deletions(-) diff --git a/src/H5A.c b/src/H5A.c index b6bfe51..b6b5f90 100644 --- a/src/H5A.c +++ b/src/H5A.c @@ -140,7 +140,8 @@ H5A_init_interface(void) /* * Create attribute ID type. */ - if(H5I_register_type(H5I_ATTR, (size_t)H5I_ATTRID_HASHSIZE, H5A_RESERVED_ATOMS, NULL) < H5I_FILE) + if(H5I_register_type2(H5I_ATTR, (size_t)H5I_ATTRID_HASHSIZE, H5A_RESERVED_ATOMS, + NULL, (H5I_free2_t)H5A_close_attr) < H5I_FILE) HGOTO_ERROR(H5E_INTERNAL, H5E_CANTINIT, FAIL, "unable to initialize interface") done: @@ -267,13 +268,8 @@ H5Acreate2(hid_t loc_id, const char *attr_name, hid_t type_id, hid_t space_id, HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create attribute") /* Get an atom for the attribute */ - if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attribute handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5A_close_attr) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: @@ -371,13 +367,8 @@ H5Acreate_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create attribute") /* Get an atom for the attribute */ - if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attribute handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5A_close_attr) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: @@ -441,13 +432,8 @@ H5Aopen(hid_t loc_id, const char *attr_name, hid_t aapl_id) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open attribute") /* Get an atom for the attribute */ - if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attribute handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5A_close_attr) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: @@ -523,13 +509,8 @@ H5Aopen_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open attribute") /* Get an atom for the attribute */ - if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attribute handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5A_close_attr) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: @@ -614,13 +595,8 @@ H5Aopen_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type, HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open attribute") /* Get an atom for the attribute */ - if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attribute handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5A_close_attr) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: diff --git a/src/H5Adeprec.c b/src/H5Adeprec.c index b239142..92d80bc 100644 --- a/src/H5Adeprec.c +++ b/src/H5Adeprec.c @@ -185,13 +185,8 @@ H5Acreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create attribute") /* Get an atom for the attribute */ - if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attribute handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5A_close_attr) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: @@ -258,13 +253,8 @@ H5Aopen_name(hid_t loc_id, const char *name) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open attribute") /* Get an atom for the attribute */ - if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attribute handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5A_close_attr) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: @@ -333,13 +323,8 @@ H5Aopen_idx(hid_t loc_id, unsigned idx) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open attribute") /* Get an atom for the attribute */ - if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize attribute handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5A_close_attr) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_ATTR, attr, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: @@ -391,8 +376,8 @@ H5Aget_num_attrs(hid_t loc_id) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "ID does not contain VOL information") /* Get the group info through the VOL using the location token */ - if(H5VL_object_get(obj, loc_params, vol_plugin, H5VL_OBJECT_GET_INFO, - H5_REQUEST_NULL, &oinfo) < 0) + if(H5VL_object_get(obj, loc_params, vol_plugin, H5VL_OBJECT_GET_INFO, + H5_REQUEST_NULL, &oinfo) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_CANTGET, FAIL, "unable to get group info") ret_value = oinfo.num_attrs; diff --git a/src/H5Aint.c b/src/H5Aint.c index 5aa0dcd..cfe81dc 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -778,21 +778,15 @@ H5A_get_type(H5A_t *attr) /* If this is a committed datatype, we need to recreate the two level IDs, where the VOL object is a copy of the returned datatype */ - ssize_t nalloc = 0; - size_t size; - unsigned char *buf = NULL; - /* Copy the dataset's datatype */ if(NULL == (type = H5T_copy(dt, H5T_COPY_REOPEN))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to copy datatype") H5T_set_vol_object(type, (void *)dt); - if((ret_value = H5I_register(H5I_DATATYPE, type, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register datatype") - - if (H5VL_native_register_aux(ret_value) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") + /* get an ID for the object */ + if((ret_value = H5VL_native_register(H5I_DATATYPE, type, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") } else { if((ret_value = H5I_register(H5I_DATATYPE, dt, TRUE)) < 0) diff --git a/src/H5D.c b/src/H5D.c index 2101b4a..7be906b 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -90,7 +90,8 @@ H5D__init_pub_interface(void) FUNC_ENTER_STATIC /* Initialize the atom group for the dataset IDs */ - if(H5I_register_type(H5I_DATASET, (size_t)H5I_DATASETID_HASHSIZE, H5D_RESERVED_ATOMS, NULL)nrefs ++; done: @@ -300,13 +297,8 @@ H5Dcreate_anon(hid_t loc_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create dataset") /* Get an atom for the dataset */ - if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) + if((ret_value = H5I_register2(H5I_DATASET, dset, vol_plugin, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5D_close_dataset) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - vol_plugin->nrefs ++; done: @@ -373,13 +365,8 @@ H5Dopen2(hid_t loc_id, const char *name, hid_t dapl_id) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create dataset") /* Get an atom for the dataset */ - if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) + if((ret_value = H5I_register2(H5I_DATASET, dset, vol_plugin, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5D_close_dataset) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - vol_plugin->nrefs ++; done: diff --git a/src/H5Ddeprec.c b/src/H5Ddeprec.c index a0df4cc..c84d440 100644 --- a/src/H5Ddeprec.c +++ b/src/H5Ddeprec.c @@ -186,14 +186,9 @@ H5Dcreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, H5P_DATASET_ACCESS_DEFAULT, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create dataset") - /* Get an atom for the file */ - if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) + /* Get an atom for the dataset */ + if((ret_value = H5I_register2(H5I_DATASET, dset, vol_plugin, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5D_close_dataset) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - vol_plugin->nrefs ++; done: @@ -253,14 +248,9 @@ H5Dopen1(hid_t loc_id, const char *name) if(NULL == (dset = H5VL_dataset_open(obj, loc_params, vol_plugin, name, dapl_id, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create dataset") - /* Get an atom for the file */ - if((ret_value = H5I_register(H5I_DATASET, dset, TRUE)) < 0) + /* Get an atom for the dataset */ + if((ret_value = H5I_register2(H5I_DATASET, dset, vol_plugin, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5D_close_dataset) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - vol_plugin->nrefs ++; done: diff --git a/src/H5Dint.c b/src/H5Dint.c index 780651d..285ee9f 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -2706,9 +2706,6 @@ H5D_get_type(H5D_t *dset) /* If this is a committed datatype, we need to recreate the two level IDs, where the VOL object is a copy of the returned datatype */ - ssize_t nalloc = 0; - size_t size; - unsigned char *buf = NULL; /* Copy the dataset's datatype */ if(NULL == (type = H5T_copy(dt, H5T_COPY_REOPEN))) @@ -2716,11 +2713,8 @@ H5D_get_type(H5D_t *dset) H5T_set_vol_object(type, (void *)dt); - if((ret_value = H5I_register(H5I_DATATYPE, type, TRUE)) < 0) + if((ret_value = H5VL_native_register(H5I_DATATYPE, type, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register datatype") - - if (H5VL_native_register_aux(ret_value) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") } else { if((ret_value = H5I_register(H5I_DATATYPE, dt, TRUE)) < 0) diff --git a/src/H5Doh.c b/src/H5Doh.c index dd0bbb8..da0be62 100644 --- a/src/H5Doh.c +++ b/src/H5Doh.c @@ -250,10 +250,8 @@ H5O__dset_open(const H5G_loc_t *obj_loc, hid_t lapl_id, hid_t dxpl_id, hbool_t a HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, FAIL, "unable to open dataset") /* Register an ID for the dataset */ - if((ret_value = H5I_register(H5I_DATASET, dset, app_ref)) < 0) + if((ret_value = H5VL_native_register(H5I_DATASET, dset, app_ref)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataset") - if(H5VL_native_register_aux(ret_value) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach native vol info to ID") done: if(ret_value < 0) diff --git a/src/H5F.c b/src/H5F.c index b2d56b8..ae3443a 100644 --- a/src/H5F.c +++ b/src/H5F.c @@ -76,7 +76,8 @@ H5F__init_pub_interface(void) /* * Initialize the atom group for the file IDs. */ - if(H5I_register_type(H5I_FILE, (size_t)H5I_FILEID_HASHSIZE, 0, NULL)file_id = ret_value; done: FUNC_LEAVE_API(ret_value) @@ -597,14 +594,10 @@ H5Fopen(const char *filename, unsigned flags, hid_t fapl_id) if(NULL == (file = H5VL_file_open(vol_plugin, filename, flags, fapl_id, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to create file") - /* Get an atom for the file */ - if((ret_value = H5I_register(H5I_FILE, file, TRUE)) < 0) + /* Get an atom for the file with the VOL information as the auxilary struct*/ + if((ret_value = H5I_register2(H5I_FILE, file, vol_plugin, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5F_close_file) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - ((H5F_t *)file)->file_id = ret_value; done: FUNC_LEAVE_API(ret_value) @@ -807,15 +800,11 @@ H5Freopen(hid_t file_id) if (NULL == file) HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "unable to reopen file") - /* Get an atom for the file */ - if((ret_value = H5I_register(H5I_FILE, file, TRUE)) < 0) + /* Get an atom for the file with the VOL information as the auxilary struct*/ + if((ret_value = H5I_register2(H5I_FILE, file, vol_plugin, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5F_close_file) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - vol_plugin->nrefs ++; + ((H5F_t *)file)->file_id = ret_value; done: @@ -1468,8 +1457,9 @@ H5F_get_id(H5F_t *file, hbool_t app_ref) HDassert(file); + /* MSC - Will need to switch to that later */ #if 0 - if (FAIL == (ret_value = H5VL_get_id(file, H5I_FILE))) { + if (FAIL == (ret_value = H5I_get_id(file, H5I_FILE))) { /* resurrect the ID */ /* Get an atom for the file */ if((ret_value = H5I_register(H5I_FILE, file, app_ref)) < 0) @@ -1486,18 +1476,14 @@ H5F_get_id(H5F_t *file, hbool_t app_ref) #endif #if 1 if(file->file_id == -1) { - /* Get an atom for the file */ - if((file->file_id = H5I_register(H5I_FILE, file, app_ref)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file") - /* attach VOL information to the ID */ - if (H5VL_native_register_aux(file->file_id) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") + /* resurrect the ID */ + if((file->file_id = H5VL_native_register(H5I_FILE, file, app_ref)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") } else { /* Increment reference count on atom. */ if(H5I_inc_ref(file->file_id, app_ref) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTSET, FAIL, "incrementing file ID failed") } /* end else */ - ret_value = file->file_id; #endif diff --git a/src/H5Fint.c b/src/H5Fint.c index a948d88..29c6a20 100644 --- a/src/H5Fint.c +++ b/src/H5Fint.c @@ -1291,7 +1291,7 @@ H5F_close(H5F_t *f) f->file_id = -1; /* - if((file_id = H5VL_get_id(f, H5I_FILE)) < 0) + if((file_id = H5I_get_id(f, H5I_FILE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "invalid atom") H5I_remove(file_id); */ diff --git a/src/H5G.c b/src/H5G.c index 1c05e08..2ab15fa 100644 --- a/src/H5G.c +++ b/src/H5G.c @@ -188,7 +188,8 @@ H5G_init_interface(void) FUNC_ENTER_NOAPI_NOINIT /* Initialize the atom group for the group IDs */ - if(H5I_register_type(H5I_GROUP, (size_t)H5I_GROUPID_HASHSIZE, H5G_RESERVED_ATOMS, NULL) < 0) + if(H5I_register_type2(H5I_GROUP, (size_t)H5I_GROUPID_HASHSIZE, H5G_RESERVED_ATOMS, + NULL, (H5I_free2_t)H5G_close_group) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to initialize interface") done: @@ -322,13 +323,8 @@ H5Gcreate2(hid_t loc_id, const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t g HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") /* Get an atom for the group */ - if((ret_value = H5I_register(H5I_GROUP, grp, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize group handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5G_close_group) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_GROUP, grp, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: @@ -416,13 +412,8 @@ H5Gcreate_anon(hid_t loc_id, hid_t gcpl_id, hid_t gapl_id) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") /* Get an atom for the group */ - if((ret_value = H5I_register(H5I_GROUP, grp, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize group handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5G_close_group) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_GROUP, grp, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: @@ -489,13 +480,8 @@ H5Gopen2(hid_t loc_id, const char *name, hid_t gapl_id) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") /* Get an atom for the group */ - if((ret_value = H5I_register(H5I_GROUP, grp, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize group handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5G_close_group) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_GROUP, grp, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: diff --git a/src/H5Gdeprec.c b/src/H5Gdeprec.c index 5235dde..070b969 100644 --- a/src/H5Gdeprec.c +++ b/src/H5Gdeprec.c @@ -267,13 +267,8 @@ H5Gcreate1(hid_t loc_id, const char *name, size_t size_hint) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") /* Get an atom for the group */ - if((ret_value = H5I_register(H5I_GROUP, grp, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize group handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5G_close_group) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_GROUP, grp, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: @@ -337,13 +332,8 @@ H5Gopen1(hid_t loc_id, const char *name) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create group") /* Get an atom for the group */ - if((ret_value = H5I_register(H5I_GROUP, grp, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize group handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5G_close_group) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + if((ret_value = H5I_register2(H5I_GROUP, grp, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") vol_plugin->nrefs ++; done: diff --git a/src/H5Gint.c b/src/H5Gint.c index 7a5e8f4..a38cac3 100644 --- a/src/H5Gint.c +++ b/src/H5Gint.c @@ -829,10 +829,8 @@ H5G_iterate(H5G_loc_t *loc, const char *group_name, */ if(NULL == (grp = H5G__open_name(loc, group_name, lapl_id, dxpl_id))) HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group") - if((gid = H5I_register(H5I_GROUP, grp, TRUE)) < 0) + if((gid = H5VL_native_register(H5I_GROUP, grp, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group") - if(H5VL_native_register_aux(gid) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach native vol info to ID") /* Set up user data for callback */ udata.gid = gid; @@ -1095,10 +1093,8 @@ H5G_visit(H5G_loc_t *loc, const char *group_name, H5_index_t idx_type, HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group") /* Register an ID for the starting group */ - if((gid = H5I_register(H5I_GROUP, grp, TRUE)) < 0) + if((gid = H5VL_native_register(H5I_GROUP, grp, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group") - if(H5VL_native_register_aux(gid) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach native vol info to ID") /* Get the location of the starting group */ if(H5G_loc(gid, &start_loc) < 0) diff --git a/src/H5Goh.c b/src/H5Goh.c index 4109633..30d9763 100644 --- a/src/H5Goh.c +++ b/src/H5Goh.c @@ -225,10 +225,8 @@ H5O_group_open(const H5G_loc_t *obj_loc, hid_t UNUSED lapl_id, hid_t dxpl_id, hb HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group") /* Register an ID for the group */ - if((ret_value = H5I_register(H5I_GROUP, grp, app_ref)) < 0) + if((ret_value = H5VL_native_register(H5I_GROUP, grp, app_ref)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group") - if(H5VL_native_register_aux(ret_value) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach native vol info to ID") done: if(ret_value < 0) diff --git a/src/H5Gtraverse.c b/src/H5Gtraverse.c index ce41d0e..1fd8b1e 100644 --- a/src/H5Gtraverse.c +++ b/src/H5Gtraverse.c @@ -208,10 +208,8 @@ H5G_traverse_ud(const H5G_loc_t *grp_loc/*in,out*/, const H5O_link_t *lnk, /* Create a group ID to pass to the user-defined callback */ if(NULL == (grp = H5G_open(&grp_loc_copy, dxpl_id))) HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group") - if((cur_grp = H5I_register(H5I_GROUP, grp, FALSE)) < 0) + if((cur_grp = H5VL_native_register(H5I_GROUP, grp, FALSE)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTREGISTER, FAIL, "unable to register group") - if(H5VL_native_register_aux(cur_grp) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach native vol info to ID") /* Check for generic default property list and use link access default if so */ if(_lapl_id == H5P_DEFAULT) { diff --git a/src/H5I.c b/src/H5I.c index d1fc439..bf01a4f 100644 --- a/src/H5I.c +++ b/src/H5I.c @@ -96,7 +96,6 @@ typedef struct H5I_id_info_t { unsigned app_count; /* ref. count of application visible atoms */ const void *obj_ptr; /* pointer associated with the atom */ const void *aux_ptr; /* auxilary pointer associated with the atom */ - H5I_free2_t free_aux; /*release auxilary structure method */ struct H5I_id_info_t *next; /* link to next atom (in case of hash-clash)*/ } H5I_id_info_t; @@ -109,6 +108,7 @@ typedef struct { unsigned ids; /*current number of IDs held */ unsigned nextid; /*ID to use for the next atom */ H5I_free_t free_func; /*release object method */ + H5I_free2_t free_aux; /*release auxilary structure method */ H5I_id_info_t **id_list; /*pointer to an array of ptrs to IDs */ } H5I_id_type_t; @@ -342,6 +342,7 @@ H5I_register_type(H5I_type_t type_id, size_t hash_size, unsigned reserved, type_ptr->ids = 0; type_ptr->nextid = reserved; type_ptr->free_func = free_func; + type_ptr->free_aux = NULL; type_ptr->id_list = (H5I_id_info_t **)H5MM_calloc(hash_size * sizeof(H5I_id_info_t *)); if(NULL == type_ptr->id_list) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5I_BADID, "memory allocation failed") @@ -589,7 +590,7 @@ H5I_clear_type(H5I_type_t type, hbool_t force, hbool_t app_ref) /* Check for a 'free' function and call it, if it exists */ /* (Casting away const OK -QAK) */ - if((cur->free_aux && (cur->free_aux)((void *)cur->obj_ptr, (void *)cur->aux_ptr) < 0) || + if((cur->aux_ptr && type_ptr->free_aux && (type_ptr->free_aux)((void *)cur->obj_ptr, (void *)cur->aux_ptr) < 0) || (type_ptr->free_func && (type_ptr->free_func)((void *)cur->obj_ptr) < 0)) { //if(type_ptr->free_func && (type_ptr->free_func)((void *)cur->obj_ptr) < 0) { if(force) { @@ -829,7 +830,6 @@ H5I_register(H5I_type_t type, const void *object, hbool_t app_ref) id_ptr->app_count = !!app_ref; id_ptr->obj_ptr = object; id_ptr->aux_ptr = NULL; - id_ptr->free_aux = NULL; id_ptr->next = NULL; /* hash bucket already full, prepend to front of chain */ @@ -1344,7 +1344,7 @@ H5I_dec_ref(hid_t id) */ if(1 == id_ptr->count) { /* (Casting away const OK -QAK) */ - if((!id_ptr->free_aux || (id_ptr->free_aux)((void *)id_ptr->obj_ptr, (void *)id_ptr->aux_ptr) >= 0) && + if((!id_ptr->aux_ptr || !type_ptr->free_aux || (type_ptr->free_aux)((void *)id_ptr->obj_ptr, (void *)id_ptr->aux_ptr) >= 0) && (!type_ptr->free_func || (type_ptr->free_func)((void *)id_ptr->obj_ptr) >= 0)) { H5I_remove(id); ret_value = 0; @@ -2186,7 +2186,7 @@ H5Iget_name(hid_t id, char *name/*out*/, size_t size) if(NULL == (dt = (H5T_t *)H5VL_get_object(id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a type") - if(H5G_loc_real((void *)type, H5I_DATATYPE, &loc) < 0) + if(H5G_loc_real((void *)dt, H5I_DATATYPE, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") } else { @@ -2288,24 +2288,6 @@ H5I_get_file_id(hid_t obj_id, hbool_t app_ref) if((ret_value = H5F_get_id((H5F_t*)file, TRUE)) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "can't get file ID") - -#if 0 - if (FAIL == (ret_value = H5VL_get_id(file, H5I_FILE))) { - /* Get an atom for the file */ - if((ret_value = H5I_register(H5I_FILE, file, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5F_close_file) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - - vol_plugin->nrefs ++; - } - else { - if(H5I_inc_ref(ret_value, app_ref) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTSET, FAIL, "incrementing file ID failed") - } -#endif } /* end if */ else HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid object ID") @@ -2354,14 +2336,239 @@ done: /*------------------------------------------------------------------------- - * Function: H5I_register_aux + * Function: H5I_register_type2 + * + * Purpose: Creates a new type of ID's to give out. A specific number + * (RESERVED) of type entries may be reserved to enable "constant" + * values to be handed out which are valid IDs in the type, but + * which do not map to any data structures and are not allocated + * dynamically later. TYPE_ID is the H5I_type_t value of the type + * to be initialized. If this value is zero, a new type is created. + * If this value is one of the library types, that type is + * initialized or its reference count is incremented (if it is already + * initialized). HASH_SIZE is the minimum hash table size to + * use for the type. FREE_FUNC is called with an object pointer + * when the object is removed from the type. + * + * Return: Success: Type ID of the new type + * Failure: H5I_BADID + * + * Programmers: Nathaniel Furrer + * James Laird + * Friday, April 30, 2004 + * + *------------------------------------------------------------------------- + */ +H5I_type_t +H5I_register_type2(H5I_type_t type_id, size_t hash_size, unsigned reserved, + H5I_free_t free_func, H5I_free2_t free_aux) +{ + H5I_id_type_t *type_ptr = NULL; /*ptr to the atomic type*/ + H5I_type_t ret_value = H5I_BADID; /* type ID to return */ + + FUNC_ENTER_NOAPI(H5I_BADID) + + /* Check that type_id is either a library type or zero */ + if(type_id < 0 || type_id >= H5I_NTYPES) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, H5I_BADID, "invalid type ID") + + if(type_id == 0) { /* Generate a new H5I_type_t value */ + /* Increment the number of types*/ + if(H5I_next_type < MAX_NUM_TYPES) { + ret_value = H5I_next_type; + H5_INC_ENUM(H5I_type_t, H5I_next_type); + } + else { + hbool_t done; /* Indicate that search was successful */ + int i; /* Local index variable */ + + /* Look for a free type to give out */ + done = FALSE; + for(i = H5I_NTYPES; i < MAX_NUM_TYPES && done == FALSE; i++) { + if(NULL == H5I_id_type_list_g[i]) { + /* Found a free type ID */ + ret_value = (H5I_type_t)i; + done = TRUE; + } /* end if */ + } /* end for */ + + /* Verify that we found a type to give out */ + if(done == FALSE) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5I_BADID, "Maximum number of ID types exceeded.") + } /* end else */ + } /* end if */ + else /* type_id is a library type; use this value. */ + ret_value = type_id; + + /* Initialize the type */ + + /* Check arguments */ +#ifdef HASH_SIZE_POWER_2 + if(!POWER_OF_TWO(hash_size) || hash_size == 1) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, H5I_BADID, "invalid hash size") +#endif /* HASH_SIZE_POWER_2 */ + + if(NULL == H5I_id_type_list_g[ret_value]) { + /* Allocate the type information for new type */ + if(NULL == (type_ptr = (H5I_id_type_t *)H5MM_calloc(sizeof(H5I_id_type_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5I_BADID, "memory allocation failed") + H5I_id_type_list_g[ret_value] = type_ptr; + } /* end if */ + else { + /* Get the pointer to the existing type */ + type_ptr = H5I_id_type_list_g[ret_value]; + } /* end else */ + + if(type_ptr->count == 0) { + /* Initialize the ID type structure for new types */ + type_ptr->hash_size = hash_size; + type_ptr->reserved = reserved; + type_ptr->wrapped = 0; + type_ptr->ids = 0; + type_ptr->nextid = reserved; + type_ptr->free_func = free_func; + type_ptr->free_aux = free_aux; + + type_ptr->id_list = (H5I_id_info_t **)H5MM_calloc(hash_size * sizeof(H5I_id_info_t *)); + if(NULL == type_ptr->id_list) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5I_BADID, "memory allocation failed") + } /* end if */ + + /* Increment the count of the times this type has been initialized */ + type_ptr->count++; + +done: + if(ret_value == H5I_BADID) { /* Clean up on error */ + if(type_ptr != NULL) { + H5MM_xfree(type_ptr->id_list); + H5MM_xfree(type_ptr); + } /* end if */ + } /* end if */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5I_register_type() */ + + +/*------------------------------------------------------------------------- + * Function: H5I_register2 + * + * Purpose: This routine does the same as H5I_register, and additionally + * attaches an auxilary structure to the id + * + * Return: Success: New object id. + * Failure: Negative + * + * Programmer: Mohamad Chaarawi + * + * + *------------------------------------------------------------------------- + */ +hid_t +H5I_register2(H5I_type_t type, const void *object, const void *aux_object, hbool_t app_ref) +{ + H5I_id_type_t *type_ptr; /*ptr to the type */ + H5I_id_info_t *id_ptr; /*ptr to the new ID information */ + hid_t new_id = FAIL; /*new ID */ + unsigned hash_loc; /*new item's hash table location*/ + hid_t next_id; /*next ID to check */ + H5I_id_info_t *curr_id; /*ptr to the current atom */ + unsigned i; /*counter */ + hid_t ret_value = FAIL; /*return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Check arguments */ + if(type <= H5I_BADID || type >= H5I_next_type) + HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "invalid type number") + type_ptr = H5I_id_type_list_g[type]; + if(NULL == type_ptr || type_ptr->count <= 0) + HGOTO_ERROR(H5E_ATOM, H5E_BADGROUP, FAIL, "invalid type") + if(NULL == (id_ptr = H5FL_MALLOC(H5I_id_info_t))) + HGOTO_ERROR(H5E_ATOM, H5E_NOSPACE, FAIL, "memory allocation failed") + + /* Create the struct & it's ID */ + new_id = H5I_MAKE(type, type_ptr->nextid); + id_ptr->id = new_id; + id_ptr->count = 1; /*initial reference count*/ + id_ptr->app_count = !!app_ref; + id_ptr->obj_ptr = object; + id_ptr->aux_ptr = aux_object; + id_ptr->next = NULL; + + /* hash bucket already full, prepend to front of chain */ + hash_loc = type_ptr->nextid % (unsigned)type_ptr->hash_size; + if(type_ptr->id_list[hash_loc] != NULL) + id_ptr->next = type_ptr->id_list[hash_loc]; + + /* Insert into the type */ + type_ptr->id_list[hash_loc] = id_ptr; + type_ptr->ids++; + type_ptr->nextid++; + + /* + * This next section of code checks for the 'nextid' getting too large and + * wrapping around, thus necessitating checking for duplicate IDs being + * handed out. + */ + if(type_ptr->nextid > (unsigned)ID_MASK) { + type_ptr->wrapped = 1; + type_ptr->nextid = type_ptr->reserved; + } /* end if */ + + /* + * If we've wrapped around then we need to check for duplicate id's being + * handed out. + */ + if(type_ptr->wrapped) { + /* + * Make sure we check all available ID's. If we're about at the end + * of the range then wrap around and check the beginning values. If + * we check all possible values and didn't find any free ones *then* + * we can fail. + */ + for(i = type_ptr->reserved; i < ID_MASK; i++) { + /* Handle end of range by wrapping to beginning */ + if(type_ptr->nextid > (unsigned)ID_MASK) + type_ptr->nextid = type_ptr->reserved; + + /* new ID to check for */ + next_id = H5I_MAKE(type, type_ptr->nextid); + hash_loc = (unsigned)H5I_LOC(type_ptr->nextid, type_ptr->hash_size); + curr_id = type_ptr->id_list[hash_loc]; + if(curr_id == NULL) + break; /* Ha! this is not likely... */ + + while(curr_id) { + if(curr_id->id == next_id) + break; + curr_id = curr_id->next; + } /* end while */ + if(!curr_id) + break; /* must not have found a match */ + type_ptr->nextid++; + } /* end for */ + + if(i >= (unsigned)ID_MASK) + /* All the IDs are gone! */ + HGOTO_ERROR(H5E_ATOM, H5E_NOIDS, FAIL, "no IDs available in type") + } /* end if */ + + /* Set return value */ + ret_value = new_id; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5I_register2() */ + +/*------------------------------------------------------------------------- + * Function: H5I_register_aux * * Purpose: increment the ref count on the high level ID given the low level ID * - * Return: Success: postive + * Return: Success: postive * Failure: FAIL * - * Programmer: Mohamad Chaarawi + * Programmer: Mohamad Chaarawi * May 2012 * *------------------------------------------------------------------------- @@ -2369,17 +2576,28 @@ done: herr_t H5I_register_aux(hid_t id, void *aux_ptr, H5I_free2_t free_func) { - H5I_id_info_t *id_ptr = NULL; /*ptr to the new atom */ - herr_t ret_value = SUCCEED; /*return value */ + H5I_id_type_t *type_ptr; /*ptr to the type*/ + H5I_id_info_t *id_ptr = NULL; /*ptr to the id*/ + H5I_type_t type; + herr_t ret_value = SUCCEED; /*return value*/ FUNC_ENTER_NOAPI_NOINIT + /* Check arguments */ + type = H5I_TYPE(id); + if (type <= H5I_BADID || type >= H5I_next_type) + HGOTO_DONE(NULL); + + type_ptr = H5I_id_type_list_g[type]; + if (!type_ptr || type_ptr->count <= 0) + HGOTO_DONE(NULL); + + type_ptr->free_aux = free_func; + if(NULL == (id_ptr = H5I_find_id(id))) HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "Invalid ID") id_ptr->aux_ptr = aux_ptr; - id_ptr->free_aux = free_func; - done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5I_register_aux() */ @@ -2417,7 +2635,7 @@ done: /*------------------------------------------------------------------------- - * Function: H5VL_get_id + * Function: H5I_get_id * * Purpose: return ID of vol object * @@ -2430,7 +2648,7 @@ done: *------------------------------------------------------------------------- */ hid_t -H5VL_get_id(void *object, H5I_type_t type) +H5I_get_id(void *object, H5I_type_t type) { hid_t ret_value = FAIL; /* Return value */ H5I_id_type_t *type_ptr; /*ptr to the type */ @@ -2462,7 +2680,7 @@ H5VL_get_id(void *object, H5I_type_t type) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_get_id() */ +} /* end H5I_get_id() */ /*------------------------------------------------------------------------- diff --git a/src/H5Iprivate.h b/src/H5Iprivate.h index 428b02f..0b240b9 100644 --- a/src/H5Iprivate.h +++ b/src/H5Iprivate.h @@ -54,10 +54,12 @@ /* Private Functions in H5I.c */ H5_DLL H5I_type_t H5I_register_type(H5I_type_t type_id, size_t hash_size, unsigned reserved, H5I_free_t free_func); +H5_DLL H5I_type_t H5I_register_type2(H5I_type_t type_id, size_t hash_size, unsigned reserved, H5I_free_t free_func, H5I_free2_t free_aux); H5_DLL int H5I_nmembers(H5I_type_t type); H5_DLL herr_t H5I_clear_type(H5I_type_t type, hbool_t force, hbool_t app_ref); H5_DLL int H5I_destroy_type(H5I_type_t type); H5_DLL hid_t H5I_register(H5I_type_t type, const void *object, hbool_t app_ref); +H5_DLL hid_t H5I_register2(H5I_type_t type, const void *object, const void* aux_object, hbool_t app_ref); H5_DLL void *H5I_subst(hid_t id, const void *new_object); H5_DLL void *H5I_object(hid_t id); H5_DLL void *H5I_object_verify(hid_t id, H5I_type_t id_type); @@ -76,6 +78,6 @@ H5_DLL herr_t H5I_dec_type_ref(H5I_type_t type); H5_DLL int H5I_get_type_ref(H5I_type_t type); H5_DLL herr_t H5I_register_aux(hid_t id, void *aux_ptr, H5I_free2_t free_func); H5_DLL void *H5I_get_aux(hid_t id); -H5_DLL hid_t H5VL_get_id(void *object, H5I_type_t type); +H5_DLL hid_t H5I_get_id(void *object, H5I_type_t type); #endif /* _H5Iprivate_H */ diff --git a/src/H5L.c b/src/H5L.c index 929c654..c9ceea8 100644 --- a/src/H5L.c +++ b/src/H5L.c @@ -1958,10 +1958,8 @@ H5L_link_cb(H5G_loc_t *grp_loc/*in*/, const char *name, const H5O_link_t UNUSED /* Set up location for user-defined callback */ if((grp = H5G_open(&temp_loc, udata->dxpl_id)) == NULL) HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group") - if((grp_id = H5I_register(H5I_GROUP, grp, TRUE)) < 0) + if((grp_id = H5VL_native_register(H5I_GROUP, grp, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register ID for group") - if(H5VL_native_register_aux(grp_id) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach native vol info to ID") /* Make callback */ if((link_class->create_func)(name, grp_id, udata->lnk->u.ud.udata, udata->lnk->u.ud.size, H5P_DEFAULT) < 0) @@ -2734,10 +2732,8 @@ H5L_move_dest_cb(H5G_loc_t *grp_loc/*in*/, const char *name, /* Set up location for user-defined callback */ if((grp = H5G_open(&temp_loc, udata->dxpl_id)) == NULL) HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group") - if((grp_id = H5I_register(H5I_GROUP, grp, TRUE)) < 0) + if((grp_id = H5VL_native_register(H5I_GROUP, grp, TRUE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register group ID") - if(H5VL_native_register_aux(grp_id) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach native vol info to ID") if(udata->copy) { if((link_class->copy_func)(udata->lnk->name, grp_id, udata->lnk->u.ud.udata, udata->lnk->u.ud.size) < 0) diff --git a/src/H5O.c b/src/H5O.c index 83905a8..88ee231 100644 --- a/src/H5O.c +++ b/src/H5O.c @@ -259,8 +259,13 @@ H5Oopen(hid_t loc_id, const char *name, hid_t lapl_id) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open object") /* Get an atom for the object */ + if((ret_value = H5I_register2(opened_type, opened_obj, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") + vol_plugin->nrefs++; +#if 0 if ((ret_value = H5VL_object_register(opened_obj, opened_type, vol_plugin)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") +#endif done: FUNC_LEAVE_API(ret_value) @@ -337,8 +342,9 @@ H5Oopen_by_idx(hid_t loc_id, const char *group_name, H5_index_t idx_type, HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open object") /* Get an atom for the object */ - if ((ret_value = H5VL_object_register(opened_obj, opened_type, vol_plugin)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") + if((ret_value = H5I_register2(opened_type, opened_obj, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") + vol_plugin->nrefs++; done: FUNC_LEAVE_API(ret_value) @@ -409,8 +415,9 @@ H5Oopen_by_addr(hid_t loc_id, haddr_t addr) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to open object") /* Get an atom for the object */ - if ((ret_value = H5VL_object_register(opened_obj, opened_type, vol_plugin)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") + if((ret_value = H5I_register2(opened_type, opened_obj, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize dataset handle") + vol_plugin->nrefs++; done: FUNC_LEAVE_API(ret_value) @@ -3488,9 +3495,19 @@ H5O_visit(H5G_loc_t *loc, const char *obj_name, H5_index_t idx_type, /* (Takes ownership of the obj_loc information) */ if((obj_id = H5O_open_by_loc(&obj_loc, lapl_id, dxpl_id, TRUE)) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTOPENOBJ, FAIL, "unable to open object") - if(H5VL_native_register_aux(obj_id) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach native vol info to ID") - +#if 0 + { + H5I_type_t opened_type; + void *temp_obj = NULL; + + opened_type = H5I_get_type (obj_id); + if(NULL == (temp_obj = H5I_remove(obj_id))) + HDONE_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to open object") + /* get an ID for the object */ + if((ret_value = H5VL_native_register(opened_type, temp_obj, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") + } +#endif /* Make callback for starting object */ if((ret_value = op(obj_id, ".", &oinfo, op_data)) < 0) HGOTO_ERROR(H5E_OHDR, H5E_BADITER, FAIL, "can't visit objects") diff --git a/src/H5T.c b/src/H5T.c index 87fcbc0..f76b955 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -742,7 +742,8 @@ H5T_init_interface(void) FUNC_ENTER_NOAPI_NOINIT /* Initialize the atom group for the file IDs */ - if(H5I_register_type(H5I_DATATYPE, (size_t)H5I_DATATYPEID_HASHSIZE, H5T_RESERVED_ATOMS, (H5I_free_t)H5T_close)<0) + if(H5I_register_type2(H5I_DATATYPE, (size_t)H5I_DATATYPEID_HASHSIZE, H5T_RESERVED_ATOMS, + (H5I_free_t)H5T_close, (H5I_free2_t)H5T_close_datatype)vol_obj = dt; - - H5MM_free(buf); - - /* Get an atom for the datatype */ - if((ret_value = H5I_register(H5I_DATATYPE, type, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize datatype handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5T_close_datatype) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - - vol_plugin->nrefs ++; -#endif - done: if (ret_value < 0 && dt) if(H5VL_datatype_close (dt, vol_plugin, H5_REQUEST_NULL) < 0) @@ -1006,14 +978,9 @@ H5VL_create_datatype(void *dt_obj, H5VL_t *vol_plugin, hid_t req) H5MM_free(buf); - /* Get an atom for the datatype */ - if((ret_value = H5I_register(H5I_DATATYPE, dt, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize datatype handle") - - /* attach VOL information to the ID */ - if (H5I_register_aux(ret_value, vol_plugin, (H5I_free2_t)H5T_close_datatype) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - + /* Get an atom for the datatype with the VOL information as the auxilary struct*/ + if((ret_value = H5I_register2(H5I_DATATYPE, dt, vol_plugin, TRUE)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") vol_plugin->nrefs ++; done: diff --git a/src/H5Toh.c b/src/H5Toh.c index 8454467..e90d22f 100644 --- a/src/H5Toh.c +++ b/src/H5Toh.c @@ -133,28 +133,34 @@ done: static hid_t H5O_dtype_open(const H5G_loc_t *obj_loc, hid_t UNUSED lapl_id, hid_t dxpl_id, hbool_t app_ref) { - H5T_t *type = NULL; /* Datatype opened */ - hid_t ret_value; /* Return value */ + H5T_t *type = NULL, *dt = NULL; /* Datatype opened */ + hid_t ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT HDassert(obj_loc); /* Open the datatype */ - if(NULL == (type = H5T_open(obj_loc, dxpl_id))) + if(NULL == (dt = H5T_open(obj_loc, dxpl_id))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to open datatype") - /* Register an ID for the datatype */ - if((ret_value = H5I_register(H5I_DATATYPE, type, app_ref)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register datatype") - if(H5VL_native_register_aux(ret_value) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach native vol info to ID") + /* Copy the dataset's datatype */ + if(NULL == (type = H5T_copy(dt, H5T_COPY_REOPEN))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to copy datatype") + + H5T_set_vol_object(type, (void *)dt); + + /* Get an atom for the datatype */ + if((ret_value = H5VL_native_register(H5I_DATATYPE, type, app_ref)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register dataset") done: - if(ret_value < 0) + if(ret_value < 0) { + if(dt && H5T_close(dt) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release datatype") if(type && H5T_close(type) < 0) HDONE_ERROR(H5E_DATATYPE, H5E_CLOSEERROR, FAIL, "unable to release datatype") - + } FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_dtype_open() */ diff --git a/src/H5VLint.c b/src/H5VLint.c index d70acfe..31a0b5a 100644 --- a/src/H5VLint.c +++ b/src/H5VLint.c @@ -387,6 +387,7 @@ H5VL_get_object(hid_t id) if(NULL == (ret_value = (void *)H5I_object(id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "invalid identifier") + /* if this is a datatype, get the VOL object attached to the H5T_t struct */ if (H5I_DATATYPE == H5I_get_type(id)) { if (NULL == (ret_value = H5T_get_named_type((H5T_t *)ret_value))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a named datatype") diff --git a/src/H5VLnative.c b/src/H5VLnative.c index 07d574d..28e8f9d 100644 --- a/src/H5VLnative.c +++ b/src/H5VLnative.c @@ -353,7 +353,7 @@ done: /*--------------------------------------------------------------------------- - * Function: H5VL_native_register_aux + * Function: H5VL_native_register_with_aux * * Purpose: utility routine to register the native VOL plugin to an ID * @@ -364,59 +364,28 @@ done: * *--------------------------------------------------------------------------- */ -herr_t -H5VL_native_register_aux(hid_t obj_id) +hid_t +H5VL_native_register(H5I_type_t type, void *obj, hbool_t app_ref) { H5VL_t *vol_plugin; /* VOL plugin information */ - herr_t ret_value = SUCCEED; + hid_t ret_value = FAIL; FUNC_ENTER_NOAPI_NOINIT + HDassert(obj); + /* Build the vol plugin struct */ if(NULL == (vol_plugin = (H5VL_t *)H5MM_calloc(sizeof(H5VL_t)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") vol_plugin->cls = &H5VL_native_g; vol_plugin->nrefs = 1; - switch(H5I_get_type(obj_id)) { - case H5I_FILE: - if(H5I_register_aux(obj_id, vol_plugin, (H5I_free2_t)H5F_close_file) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - break; - case H5I_GROUP: - if(H5I_register_aux(obj_id, vol_plugin, (H5I_free2_t)H5G_close_group) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - break; - case H5I_DATATYPE: - if(H5I_register_aux(obj_id, vol_plugin, (H5I_free2_t)H5T_close_datatype) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - break; - case H5I_DATASET: - if(H5I_register_aux(obj_id, vol_plugin, (H5I_free2_t)H5D_close_dataset) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - break; - case H5I_ATTR: - if(H5I_register_aux(obj_id, vol_plugin, (H5I_free2_t)H5A_close_attr) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "can't attach vol info to ID") - break; - case H5I_UNINIT: - case H5I_BADID: - case H5I_DATASPACE: - case H5I_REFERENCE: - case H5I_VFL: - case H5I_VOL: - case H5I_GENPROP_CLS: - case H5I_GENPROP_LST: - case H5I_ERROR_CLASS: - case H5I_ERROR_MSG: - case H5I_ERROR_STACK: - case H5I_NTYPES: - default: - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - } /* end switch */ + /* Get an atom for the file with the VOL information as the auxilary struct*/ + if((ret_value = H5I_register2(type, obj, (void *)vol_plugin, app_ref)) < 0) + HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize file handle") done: FUNC_LEAVE_NOAPI(ret_value) -} /* H5VL_native_register_aux */ +} /* H5VL_native_register_with_aux */ /*------------------------------------------------------------------------- @@ -2256,7 +2225,7 @@ H5VL_native_file_close(void *file, hid_t UNUSED req) * disabled by an option/property to improve performance. */ if((f->shared->nrefs > 1) && (H5F_INTENT(f) & H5F_ACC_RDWR)) { /* get the file ID corresponding to the H5F_t struct */ - if((file_id = H5VL_get_id(f, H5I_FILE)) < 0) + if((file_id = H5I_get_id(f, H5I_FILE)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, FAIL, "invalid atom") /* get the number of references outstanding for this file ID */ if((nref = H5I_get_ref(file_id, FALSE)) < 0) @@ -3074,9 +3043,9 @@ H5VL_native_object_open(void *obj, H5VL_loc_params_t loc_params, H5I_type_t *ope } *opened_type = H5I_get_type (temp_id); - if(NULL == (ret_value = H5I_remove(temp_id))) { + if(NULL == (ret_value = H5I_remove(temp_id))) HDONE_ERROR(H5E_SYM, H5E_CANTOPENOBJ, NULL, "unable to open object") - } + done: /* Release the object location if we failed after copying it */ if(temp_id < 0 && loc_found) diff --git a/src/H5VLnative.h b/src/H5VLnative.h index c65e837..37eb93b 100644 --- a/src/H5VLnative.h +++ b/src/H5VLnative.h @@ -30,8 +30,8 @@ extern "C" { H5_DLL H5VL_class_t *H5VL_native_init(void); H5_DLL herr_t H5Pset_fapl_native(hid_t fapl_id); -H5_DLL herr_t H5VL_native_register_aux(hid_t obj_id); - + //H5_DLL herr_t H5VL_native_register_aux(hid_t obj_id); +H5_DLL hid_t H5VL_native_register(H5I_type_t type, void *obj, hbool_t app_ref); #ifdef __cplusplus } #endif -- cgit v0.12