diff options
Diffstat (limited to 'src/H5I.c')
-rw-r--r-- | src/H5I.c | 76 |
1 files changed, 32 insertions, 44 deletions
@@ -12,25 +12,17 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* - * FILE: H5I.c - Internal storage routines for handling "IDs" + * FILE: H5I.c - Internal storage routines for handling "IDs" * - * REMARKS: ID's which allow objects (void *'s currently) to be bundled - * into "types" for more general storage. + * REMARKS: IDs which allow objects (void * currently) to be bundled + * into "types" for more general storage. * - * DESIGN: The types are stored in an array of pointers to store each - * type in an element. Each "type" node contains a link to a - * hash table to manage the IDs in each type. Allowed types are - * values within the range 1 to H5I_MAX_NUM_TYPES and are given out - * at run-time. Types used by the library are stored in global - * variables defined in H5Ipublic.h. - * - * AUTHOR: Quincey Koziol - * - * MODIFICATIONS: - * 1/3/96 - Starting writing specs & coding prototype - * 1/7/96 - Finished coding prototype - * 6/10/97 - Moved into HDF5 library - * 5/18/04 - Expanded to allow registration of new types at run-time + * DESIGN: The types are stored in an array of pointers to store each + * type in an element. Each "type" node contains a link to a + * hash table to manage the IDs in each type. Allowed types are + * values within the range 1 to H5I_MAX_NUM_TYPES and are given out + * at run-time. Types used by the library are stored in global + * variables defined in H5Ipublic.h. */ #include "H5Imodule.h" /* This source code file is part of the H5I module */ @@ -724,58 +716,54 @@ done: /*------------------------------------------------------------------------- - * Function: H5I_register - * - * Purpose: Registers an OBJECT in a TYPE and returns an ID for it. - * This routine does _not_ check for unique-ness of the objects, - * if you register an object twice, you will get two different - * IDs for it. This routine does make certain that each ID in a - * type is unique. IDs are created by getting a unique number - * for the type the ID is in and incorporating the type into - * the ID which is returned to the user. + * Function: H5I_register * - * Return: Success: New object id. - * Failure: Negative + * Purpose: Registers an OBJECT in a TYPE and returns an ID for it. + * This routine does _not_ check for unique-ness of the objects, + * if you register an object twice, you will get two different + * IDs for it. This routine does make certain that each ID in a + * type is unique. IDs are created by getting a unique number + * for the type the ID is in and incorporating the type into + * the ID which is returned to the user. * - * Programmer: Unknown + * Return: Success: New object id + * Failure: Negative * *------------------------------------------------------------------------- */ hid_t H5I_register(H5I_type_t type, const void *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; /*new ID */ - hid_t ret_value = SUCCEED; /*return value */ + H5I_id_type_t *type_ptr = NULL; /* ptr to the type */ + H5I_id_info_t *id_ptr = NULL; /* ptr to the new ID information */ + hid_t new_id = -1; /* new ID */ + hid_t ret_value = SUCCEED; /* 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") + 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->init_count <= 0) - HGOTO_ERROR(H5E_ATOM, H5E_BADGROUP, FAIL, "invalid type") - if(NULL == (id_ptr = H5FL_MALLOC(H5I_id_info_t))) + if ((NULL == type_ptr) || (type_ptr->init_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 */ + /* Create the struct & its ID */ new_id = H5I_MAKE(type, type_ptr->nextid); id_ptr->id = new_id; - id_ptr->count = 1; /*initial reference count*/ + id_ptr->count = 1; /* initial reference count */ id_ptr->app_count = !!app_ref; id_ptr->obj_ptr = object; /* Insert into the type */ - if(H5SL_insert(type_ptr->ids, id_ptr, &id_ptr->id) < 0) + if (H5SL_insert(type_ptr->ids, id_ptr, &id_ptr->id) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTINSERT, FAIL, "can't insert ID node into skip list") type_ptr->id_count++; type_ptr->nextid++; - /* - * Sanity check for the 'nextid' getting too large and wrapping around. - */ + /* Sanity check for the 'nextid' getting too large and wrapping around */ HDassert(type_ptr->nextid <= ID_MASK); /* Set return value */ |