diff options
Diffstat (limited to 'src/H5I.c')
-rw-r--r-- | src/H5I.c | 185 |
1 files changed, 83 insertions, 102 deletions
@@ -33,8 +33,9 @@ #include "H5ACprivate.h" /* Metadata cache */ #include "H5CXprivate.h" /* API Contexts */ #include "H5Dprivate.h" /* Datasets */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5FLprivate.h" /* Free Lists */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Fprivate.h" /* File access */ +#include "H5FLprivate.h" /* Free Lists */ #include "H5Gprivate.h" /* Groups */ #include "H5Ipkg.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ @@ -130,6 +131,7 @@ H5FL_DEFINE_STATIC(H5I_class_t); H5FL_EXTERN(H5VL_object_t); /*--------------------- Local function prototypes ---------------------------*/ +static void *H5I__unwrap(void *obj_ptr, H5I_type_t type); static htri_t H5I__clear_type_cb(void *_id, void *key, void *udata); static int H5I__destroy_type(H5I_type_t type); static void *H5I__remove_verify(hid_t id, H5I_type_t id_type); @@ -139,7 +141,6 @@ static int H5I__get_type_ref(H5I_type_t type); static int H5I__search_cb(void *obj, hid_t id, void *_udata); static H5I_id_info_t *H5I__find_id(hid_t id); static int H5I__iterate_pub_cb(void *obj, hid_t id, void *udata); -static hid_t H5I__get_file_id(hid_t obj_id, H5I_type_t id_type); static int H5I__find_id_cb(void *_item, void *_key, void *_udata); static int H5I__id_dump_cb(void *_item, void *_key, void *_udata); @@ -452,6 +453,50 @@ done: /*------------------------------------------------------------------------- + * Function: H5I__unwrap + * + * Purpose: Unwraps the object pointer for the 'item' that corresponds + * to an ID. + * + * Return: Pointer to the unwrapped pointer (can't fail) + * + * Programmer: Quincey Koziol + * Friday, October 19, 2018 + * + *------------------------------------------------------------------------- + */ +static void * +H5I__unwrap(void *obj_ptr, H5I_type_t type) +{ + void *ret_value = NULL; /* Return value */ + + FUNC_ENTER_STATIC_NOERR + + /* Sanity checks */ + HDassert(obj_ptr); + + /* The stored object pointer might be an H5VL_object_t, in which + * case we'll need to get the wrapped object struct (H5F_t *, etc.). + */ + if(H5I_FILE == type || H5I_GROUP == type || H5I_DATASET == type || H5I_ATTR == type) { + const H5VL_object_t *vol_obj; + + vol_obj = (const H5VL_object_t *)obj_ptr; + ret_value = H5VL_object_data(vol_obj); + } /* end if */ + else if(H5I_DATATYPE == type) { + H5T_t *dt = (H5T_t *)obj_ptr; + + ret_value = (void *)H5T_get_actual_type(dt); + } /* end if */ + else + ret_value = obj_ptr; + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5I__unwrap() */ + + +/*------------------------------------------------------------------------- * Function: H5Iclear_type * * Purpose: Removes all objects from the type, calling the free @@ -547,6 +592,7 @@ H5I__clear_type_cb(void *_id, void H5_ATTR_UNUSED *key, void *_udata) FUNC_ENTER_STATIC_NOERR + /* Sanity checks */ HDassert(id); HDassert(udata); HDassert(udata->type_ptr); @@ -556,8 +602,7 @@ H5I__clear_type_cb(void *_id, void H5_ATTR_UNUSED *key, void *_udata) */ if(udata->force || (id->count - (!udata->app_ref * id->app_count)) <= 1) { /* Check for a 'free' function and call it, if it exists */ - /* (Casting away const OK -QAK) */ - if(udata->type_ptr->cls->free_func && (udata->type_ptr->cls->free_func)((void *)id->obj_ptr) < 0) { + if(udata->type_ptr->cls->free_func && (udata->type_ptr->cls->free_func)((void *)id->obj_ptr) < 0) { /* (Casting away const OK -QAK) */ if(udata->force) { #ifdef H5I_DEBUG if(H5DEBUG(I)) { @@ -858,8 +903,7 @@ H5I_subst(hid_t id, const void *new_object) HGOTO_ERROR(H5E_ATOM, H5E_NOTFOUND, NULL, "can't get ID ref count") /* Get the old object pointer to return */ - /* (Casting away const OK -QAK) */ - ret_value = (void *)id_ptr->obj_ptr; + ret_value = (void *)id_ptr->obj_ptr; /* (Casting away const OK -QAK) */ /* Set the new object pointer for the ID */ id_ptr->obj_ptr = new_object; @@ -1980,16 +2024,7 @@ H5I__iterate_cb(void *_item, void H5_ATTR_UNUSED *_key, void *_udata) /* The stored object pointer might be an H5VL_object_t, in which * case we'll need to get the wrapped object struct (H5F_t *, etc.). */ - if(H5I_FILE == type || H5I_GROUP == type || H5I_DATASET == type || H5I_ATTR == type) { - const H5VL_object_t *vol_obj = (const H5VL_object_t *)item->obj_ptr; - obj_ptr = vol_obj->data; - } - else if(H5I_DATATYPE == type) { - const H5T_t *dt = (const H5T_t *)item->obj_ptr; - obj_ptr = (void *)H5T_get_actual_type(dt); - } - else - obj_ptr = item->obj_ptr; + obj_ptr = H5I__unwrap((void *)item->obj_ptr, type); /* Invoke callback function */ cb_ret_val = (*udata->user_func)((void *)obj_ptr, item->id, udata->user_udata); /* (Casting away const OK) */ @@ -1999,7 +2034,7 @@ H5I__iterate_cb(void *_item, void H5_ATTR_UNUSED *_key, void *_udata) ret_value = H5_ITER_STOP; /* terminate iteration early */ else if(cb_ret_val < 0) ret_value = H5_ITER_ERROR; /* indicate failure (which terminates iteration) */ - } + } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5I__iterate_cb() */ @@ -2057,7 +2092,7 @@ H5I_iterate(H5I_type_t type, H5I_search_func_t func, void *udata, hbool_t app_re /* Iterate over IDs */ if ((iter_status = H5SL_iterate(type_ptr->ids, H5I__iterate_cb, &iter_udata)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_BADITER, FAIL, "iteration failed") - } + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -2111,7 +2146,7 @@ done: * * Failure: -1 * - * NOTE: Not safe for arbitrary VOL drivers as it relies on + * NOTE: Not safe for arbitrary VOL connectors as it relies on * private H5G calls. * * Comments: Public function @@ -2129,18 +2164,24 @@ done: ssize_t H5Iget_name(hid_t id, char *name/*out*/, size_t size) { + H5VL_object_t *vol_obj; /* Object token of loc_id */ + H5VL_loc_params_t loc_params; H5G_loc_t loc; /* Object location */ ssize_t ret_value; /* Return value */ FUNC_ENTER_API((-1)) H5TRACE3("Zs", "ixz", id, name, size); - /* Get object location */ - if(H5G_loc(id, &loc) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, (-1), "can't retrieve object location") + /* Get the object pointer */ + if(NULL == (vol_obj = H5VL_vol_object(id))) + HGOTO_ERROR(H5E_ATOM, H5E_BADTYPE, (-1), "invalid identifier") + + /* Set location parameters */ + loc_params.type = H5VL_OBJECT_BY_SELF; + loc_params.obj_type = H5I_get_type(id); /* Retrieve object's name */ - if((ret_value = H5G_get_name(&loc, name, size, NULL)) < 0) + if(H5VL_object_get(vol_obj, &loc_params, H5VL_ID_GET_NAME, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &ret_value, name, size) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, (-1), "can't retrieve object name") done: @@ -2174,9 +2215,9 @@ H5Iget_file_id(hid_t obj_id) /* Call internal function */ if (H5I_FILE == type || H5I_DATATYPE == type || H5I_GROUP == type || H5I_DATASET == type || H5I_ATTR == type) { - if ((ret_value = H5I__get_file_id(obj_id, type)) < 0) + if ((ret_value = H5F_get_file_id(obj_id, type)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, H5I_INVALID_HID, "can't retrieve file ID") - } + } /* end if */ else HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, H5I_INVALID_HID, "not an ID of a file object") @@ -2186,56 +2227,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5I__get_file_id - * - * Purpose: The private version of H5Iget_file_id(), obtains the file - * ID given an object ID. - * - * Return: Success: The file ID associated with the object - * Failure: H5I_INVALID_HID - * - *------------------------------------------------------------------------- - */ -static hid_t -H5I__get_file_id(hid_t obj_id, H5I_type_t type) -{ - H5VL_object_t *vol_obj = NULL; - void *file = NULL; - hid_t ret_value = H5I_INVALID_HID; /* Return value */ - - FUNC_ENTER_STATIC - - /* Get the object pointer */ - if (NULL == (vol_obj = H5VL_vol_object(obj_id))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid identifier") - - /* Get the file through the VOL */ - if (H5VL_file_get(vol_obj->data, vol_obj->driver->cls, H5VL_OBJECT_GET_FILE, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, type, &file) < 0) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, H5I_INVALID_HID, "unable to get file") - if (NULL == file) - HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, H5I_INVALID_HID, "unable to get the file through the VOL") - - /* Check if the file's ID already exists */ - if (H5I_find_id(file, H5I_FILE, &ret_value) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTGET, H5I_INVALID_HID, "getting file ID failed") - - /* If the ID does not exist, register it with the VOL driver */ - if (H5I_INVALID_HID == ret_value) { - if ((ret_value = H5VL_register(H5I_FILE, file, vol_obj->driver, TRUE)) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize file handle") - } - else { - /* Increment ref count on existing ID */ - if (H5I_inc_ref(ret_value, TRUE) < 0) - HGOTO_ERROR(H5E_ATOM, H5E_CANTSET, H5I_INVALID_HID, "incrementing file ID failed") - } - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5I__get_file_id() */ - - -/*------------------------------------------------------------------------- * Function: H5I__find_id_cb * * Purpose: Callback for searching for an ID with a specific pointer @@ -2260,23 +2251,14 @@ H5I__find_id_cb(void *_item, void H5_ATTR_UNUSED *_key, void *_udata) HDassert(item); HDassert(udata); - /* Get a pointer to the VOL driver's data */ - if (H5I_FILE == type || H5I_GROUP == type || H5I_DATASET == type || H5I_ATTR == type) { - const H5VL_object_t *vol_obj = (const H5VL_object_t *)item->obj_ptr; - obj_ptr = vol_obj->data; - } - else if (H5I_DATATYPE == type) { - const H5T_t *dt = (const H5T_t *)item->obj_ptr; - obj_ptr = (void *)H5T_get_actual_type(dt); - } - else - obj_ptr = item->obj_ptr; + /* Get a pointer to the VOL connector's data */ + obj_ptr = H5I__unwrap(item->obj_ptr, type); /* Check for a match */ if (obj_ptr == udata->object) { udata->ret_id = item->id; ret_value = H5_ITER_STOP; - } + } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5I__find_id_cb() */ @@ -2324,7 +2306,7 @@ H5I_find_id(const void *object, H5I_type_t type, hid_t *id) HGOTO_ERROR(H5E_ATOM, H5E_BADITER, FAIL, "iteration failed") *id = udata.ret_id; - } + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -2346,7 +2328,7 @@ H5I__id_dump_cb(void *_item, void H5_ATTR_UNUSED *_key, void *_udata) H5I_id_info_t *item = (H5I_id_info_t *)_item; /* Pointer to the ID node */ H5I_type_t type = *(H5I_type_t *)_udata; /* User data */ H5G_name_t *path = NULL; /* Path to file object */ - const void *obj_ptr = NULL; /* Pointer to VOL driver object */ + const void *obj_ptr = NULL; /* Pointer to VOL connector object */ FUNC_ENTER_STATIC_NOERR @@ -2360,37 +2342,36 @@ H5I__id_dump_cb(void *_item, void H5_ATTR_UNUSED *_key, void *_udata) { const H5VL_object_t *vol_obj = (const H5VL_object_t *)item->obj_ptr; - obj_ptr = vol_obj->data; - - if(H5_VOL_NATIVE == vol_obj->driver->cls->value) - path = H5G_nameof((H5G_t *)obj_ptr); + obj_ptr = H5VL_object_data(vol_obj); + if(H5_VOL_NATIVE == vol_obj->connector->cls->value) + path = H5G_nameof((const H5G_t *)obj_ptr); break; } + case H5I_DATASET: { const H5VL_object_t *vol_obj = (const H5VL_object_t *)item->obj_ptr; - obj_ptr = vol_obj->data; - - if(H5_VOL_NATIVE == vol_obj->driver->cls->value) - path = H5D_nameof((H5D_t *)obj_ptr); + obj_ptr = H5VL_object_data(vol_obj); + if(H5_VOL_NATIVE == vol_obj->connector->cls->value) + path = H5D_nameof((const H5D_t *)obj_ptr); break; } + case H5I_DATATYPE: { const H5T_t *dt = (const H5T_t *)item->obj_ptr; - obj_ptr = (void *)H5T_get_actual_type(dt); - - path = H5T_nameof((H5T_t *)obj_ptr); + obj_ptr = (void *)H5T_get_actual_type((H5T_t *)dt); /* Casting away const OK - QAK */ + path = H5T_nameof((const H5T_t *)obj_ptr); break; } + case H5I_UNINIT: case H5I_BADID: case H5I_FILE: case H5I_DATASPACE: case H5I_ATTR: - case H5I_REFERENCE: case H5I_VFL: case H5I_VOL: case H5I_GENPROP_CLS: |