diff options
Diffstat (limited to 'src')
50 files changed, 1139 insertions, 509 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 070cf62..3f7d73a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.10) +cmake_minimum_required (VERSION 3.12) project (HDF5_SRC C) #----------------------------------------------------------------------------- @@ -1137,6 +1137,9 @@ if (NOT ONLY_SHARED_LIBS) PRIVATE "${HDF5_SRC_DIR};${HDF5_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>" INTERFACE "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>" ) + target_compile_options(${HDF5_LIB_TARGET} + PRIVATE "${HDF5_CMAKE_C_FLAGS}" + ) target_compile_definitions(${HDF5_LIB_TARGET} PUBLIC ${HDF_EXTRA_C_FLAGS} @@ -1173,6 +1176,9 @@ if (BUILD_SHARED_LIBS) PUBLIC "$<$<BOOL:${HDF5_ENABLE_HDFS}>:${HDFS_INCLUDE_DIR}>" INTERFACE "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>" ) + target_compile_options(${HDF5_LIBSH_TARGET} + PRIVATE "${HDF5_CMAKE_C_FLAGS}" + ) target_compile_definitions(${HDF5_LIBSH_TARGET} PUBLIC "H5_BUILT_AS_DYNAMIC_LIB" @@ -355,7 +355,9 @@ H5_term_library(void) pending += DOWN(Z); pending += DOWN(FD); pending += DOWN(VL); - pending += DOWN(PL); + /* Don't shut down the plugin code until all "pluggable" interfaces (Z, FD, PL) are shut down */ + if(pending == 0) + pending += DOWN(PL); /* Don't shut down the error code until other APIs which use it are shut down */ if(pending == 0) pending += DOWN(E); @@ -556,6 +558,87 @@ done: /*------------------------------------------------------------------------- + * Function: H5get_free_list_sizes + * + * Purpose: Gets the current size of the different kinds of free lists that + * the library uses to manage memory. The free list sizes can be set with + * H5set_free_list_limits and garbage collected with H5garbage_collect. + * These lists are global for the entire library. + * + * Parameters: + * size_t *reg_size; OUT: The current size of all "regular" free list memory used + * size_t *arr_size; OUT: The current size of all "array" free list memory used + * size_t *blk_size; OUT: The current size of all "block" free list memory used + * size_t *fac_size; OUT: The current size of all "factory" free list memory used + * + * Return: Success: non-negative + * Failure: negative + * + * Programmer: Quincey Koziol + * Friday, March 6, 2020 + * + *------------------------------------------------------------------------- + */ +herr_t +H5get_free_list_sizes(size_t *reg_size, size_t *arr_size, size_t *blk_size, + size_t *fac_size) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE4("e", "*z*z*z*z", reg_size, arr_size, blk_size, fac_size); + + /* Call the free list function to actually get the sizes */ + if(H5FL_get_free_list_sizes(reg_size, arr_size, blk_size, fac_size) < 0) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGET, FAIL, "can't get garbage collection sizes") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5get_free_list_sizes() */ + + +/*------------------------------------------------------------------------- + * Function: H5get_alloc_stats + * + * Purpose: Gets the memory allocation statistics for the library, if the + * --enable-memory-alloc-sanity-check option was given when building the + * library. Applications can check whether this option was enabled by + * detecting if the 'H5_MEMORY_ALLOC_SANITY_CHECK' macro is defined. This + * option is enabled by default for debug builds of the library and + * disabled by default for non-debug builds. If the option is not enabled, + * all the values returned with be 0. These statistics are global for the + * entire library, but don't include allocations from chunked dataset I/O + * filters or non-native VOL connectors. + * + * Parameters: + * H5_alloc_stats_t *stats; OUT: Memory allocation statistics + * + * Return: Success: non-negative + * Failure: negative + * + * Programmer: Quincey Koziol + * Saturday, March 7, 2020 + * + *------------------------------------------------------------------------- + */ +herr_t +H5get_alloc_stats(H5_alloc_stats_t *stats) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "*x", stats); + + /* Call the internal allocation stat routine to get the values */ + if(H5MM_get_alloc_stats(stats) < 0) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGET, FAIL, "can't get allocation stats") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5get_alloc_stats() */ + + +/*------------------------------------------------------------------------- * Function: H5_debug_mask * * Purpose: Set runtime debugging flags according to the string S. The diff --git a/src/H5Aint.c b/src/H5Aint.c index fc5ea34..1a74abe 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -224,7 +224,7 @@ H5A__create(const H5G_loc_t *loc, const char *attr_name, const H5T_t *type, HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, NULL, "can't set version of dataspace") /* Copy the object header information */ - if(H5O_loc_copy(&(attr->oloc), loc->oloc, H5_COPY_DEEP) < 0) + if(H5O_loc_copy_deep(&(attr->oloc), loc->oloc) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "unable to copy entry") /* Deep copy of the group hierarchy path */ @@ -390,7 +390,7 @@ H5A__open_common(const H5G_loc_t *loc, H5A_t *attr) HGOTO_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't release group hier. path") /* Deep copy of the symbol table entry */ - if(H5O_loc_copy(&(attr->oloc), loc->oloc, H5_COPY_DEEP) < 0) + if(H5O_loc_copy_deep(&(attr->oloc), loc->oloc) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to copy entry") /* Deep copy of the group hier. path */ @@ -909,7 +909,7 @@ H5A__get_type(H5A_t *attr) * reopen the type before returning it to the user. Make the type * read-only. */ - if (NULL == (dt = H5T_copy(attr->shared->dt, H5T_COPY_REOPEN))) + if (NULL == (dt = H5T_copy_reopen(attr->shared->dt))) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5I_INVALID_HID, "unable to copy datatype") /* Mark any datatypes as being in memory now */ diff --git a/src/H5B2leaf.c b/src/H5B2leaf.c index 7ed0468..c1221ba 100644 --- a/src/H5B2leaf.c +++ b/src/H5B2leaf.c @@ -1051,7 +1051,7 @@ H5B2__assert_leaf(const H5B2_hdr_t H5_ATTR_NDEBUG_UNUSED *hdr, *------------------------------------------------------------------------- */ H5_ATTR_PURE herr_t -H5B2__assert_leaf2(const H5B2_hdr_t *hdr, const H5B2_leaf_t *leaf, const H5B2_leaf_t H5_ATTR_UNUSED *leaf2) +H5B2__assert_leaf2(const H5B2_hdr_t H5_ATTR_NDEBUG_UNUSED *hdr, const H5B2_leaf_t H5_ATTR_NDEBUG_UNUSED *leaf, const H5B2_leaf_t H5_ATTR_UNUSED *leaf2) { /* General sanity checking on node */ HDassert(leaf->nrec <= hdr->node_info->split_nrec); @@ -598,7 +598,7 @@ H5Dget_offset(hid_t dset_id) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, HADDR_UNDEF, "invalid dataset identifier") /* Get the offset */ - if(H5VL_dataset_get(vol_obj, H5VL_DATASET_GET_OFFSET, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &ret_value) < 0) + if(H5VL_dataset_optional(vol_obj, H5VL_NATIVE_DATASET_GET_OFFSET, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, &ret_value) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, HADDR_UNDEF, "unable to get offset") done: diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index 556e367..e760f63 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -323,6 +323,7 @@ static herr_t H5D__chunk_prune_fill(H5D_chunk_it_ud1_t *udata, hbool_t new_unfil #ifdef H5_HAVE_PARALLEL static herr_t H5D__chunk_collective_fill(const H5D_t *dset, H5D_chunk_coll_info_t *chunk_info, size_t chunk_size, const void *fill_buf); +static int H5D__chunk_cmp_addr(const void *addr1, const void *addr2); #endif /* H5_HAVE_PARALLEL */ static int @@ -4958,6 +4959,7 @@ H5D__chunk_collective_fill(const H5D_t *dset, H5D_chunk_coll_info_t *chunk_info, MPI_Datatype mem_type, file_type; H5FD_mpio_xfer_t prev_xfer_mode; /* Previous data xfer mode */ hbool_t have_xfer_mode = FALSE; /* Whether the previous xffer mode has been retrieved */ + hbool_t need_addr_sort = FALSE; int i; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ @@ -5006,19 +5008,28 @@ H5D__chunk_collective_fill(const H5D_t *dset, H5D_chunk_coll_info_t *chunk_info, /* make sure that the addresses in the datatype are monotonically non decreasing */ - if(i) - HDassert(chunk_disp_array[i] > chunk_disp_array[i - 1]); - } /* end if */ + if(i && (chunk_disp_array[i] < chunk_disp_array[i - 1])) + need_addr_sort = TRUE; + } /* end for */ /* calculate if there are any leftover blocks after evenly distributing. If there are, then round robin the distribution to processes 0 -> leftover. */ if(leftover && leftover > mpi_rank) { chunk_disp_array[blocks] = (MPI_Aint)chunk_info->addr[blocks*mpi_size + mpi_rank]; + if(blocks && (chunk_disp_array[blocks] < chunk_disp_array[blocks - 1])) + need_addr_sort = TRUE; block_lens[blocks] = block_len; blocks++; } + /* + * Ensure that the blocks are sorted in monotonically non-decreasing + * order of offset in the file. + */ + if(need_addr_sort) + HDqsort(chunk_disp_array, blocks, sizeof(MPI_Aint), H5D__chunk_cmp_addr); + /* MSC - should use this if MPI_type_create_hindexed block is working: * mpi_code = MPI_Type_create_hindexed_block(blocks, block_len, chunk_disp_array, MPI_BYTE, &file_type); */ @@ -5073,6 +5084,36 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5D__chunk_collective_fill() */ + + +static int +H5D__chunk_cmp_addr(const void *addr1, const void *addr2) +{ + MPI_Aint _addr1 = (MPI_Aint)0, _addr2 = (MPI_Aint)0; + int ret_value = 0; + + FUNC_ENTER_STATIC_NOERR + + _addr1 = *((const MPI_Aint *) addr1); + _addr2 = *((const MPI_Aint *) addr2); + +#if MPI_VERSION >= 3 && MPI_SUBVERSION >= 1 + { + MPI_Aint diff = MPI_Aint_diff(_addr1, _addr2); + + if(diff < (MPI_Aint)0) + ret_value = -1; + else if(diff > (MPI_Aint)0) + ret_value = 1; + else + ret_value = 0; + } +#else + ret_value = (_addr1 > _addr2) - (_addr1 < _addr2); +#endif + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D__chunk_cmp_addr() */ #endif /* H5_HAVE_PARALLEL */ @@ -7162,7 +7203,7 @@ H5D__get_num_chunks(const H5D_t *dset, const H5S_t H5_ATTR_UNUSED *space, hsize_ } /* end else */ done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI_TAG(ret_value) } /* end H5D__get_num_chunks() */ @@ -7300,7 +7341,7 @@ H5D__get_chunk_info(const H5D_t *dset, const H5S_t H5_ATTR_UNUSED *space, hsize_ } /* end if H5F_addr_defined */ done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI_TAG(ret_value) } /* end H5D__get_chunk_info() */ diff --git a/src/H5Dint.c b/src/H5Dint.c index 0d67fd0..1624f7b 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -1534,7 +1534,7 @@ H5D_open(const H5G_loc_t *loc, hid_t dapl_id) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Shallow copy (take ownership) of the object location object */ - if(H5O_loc_copy(&(dataset->oloc), loc->oloc, H5_COPY_SHALLOW) < 0) + if(H5O_loc_copy_shallow(&(dataset->oloc), loc->oloc) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, NULL, "can't copy object location") /* Shallow copy (take ownership) of the group hier. path */ @@ -3881,7 +3881,7 @@ H5D__get_type(const H5D_t *dset) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to patch datatype's file pointer") /* Copy the dataset's datatype */ - if(NULL == (dt = H5T_copy(dset->shared->type, H5T_COPY_REOPEN))) + if(NULL == (dt = H5T_copy_reopen(dset->shared->type))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to copy datatype") /* Mark any datatypes as being in memory now */ diff --git a/src/H5FDs3comms.c b/src/H5FDs3comms.c index f08e9d5..d9d4c88 100644 --- a/src/H5FDs3comms.c +++ b/src/H5FDs3comms.c @@ -1202,7 +1202,7 @@ H5FD_s3comms_s3r_open(const char *url, if ((region != NULL && *region != '\0') || (id != NULL && *id != '\0') || - (signing_key != NULL && *signing_key != '\0')) + (signing_key != NULL)) { /* if one exists, all three must exist */ @@ -1214,7 +1214,7 @@ H5FD_s3comms_s3r_open(const char *url, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "secret id cannot be null.\n"); } - if (signing_key == NULL || signing_key[0] == '\0') { + if (signing_key == NULL) { HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "signing key cannot be null.\n"); } @@ -130,17 +130,23 @@ static H5FL_track_t *H5FL_out_head_g = NULL; #endif /* H5FL_TRACK */ /* Forward declarations of local static functions */ +static void * H5FL__malloc(size_t mem_size); +static herr_t H5FL__reg_init(H5FL_reg_head_t *head); static herr_t H5FL__reg_gc(void); static herr_t H5FL__reg_gc_list(H5FL_reg_head_t *head); static int H5FL__reg_term(void); -static herr_t H5FL__arr_gc(void); -static herr_t H5FL__arr_gc_list(H5FL_arr_head_t *head); -static int H5FL__arr_term(void); -static herr_t H5FL__blk_gc(void); +static H5FL_blk_node_t *H5FL__blk_find_list(H5FL_blk_node_t **head, size_t size); +static H5FL_blk_node_t *H5FL__blk_create_list(H5FL_blk_node_t **head, size_t size); +static herr_t H5FL__blk_init(H5FL_blk_head_t *head); static herr_t H5FL__blk_gc_list(H5FL_blk_head_t *head); +static herr_t H5FL__blk_gc(void); static int H5FL__blk_term(void); -static herr_t H5FL__fac_gc(void); +static herr_t H5FL__arr_init(H5FL_arr_head_t *head); +static herr_t H5FL__arr_gc_list(H5FL_arr_head_t *head); +static herr_t H5FL__arr_gc(void); +static int H5FL__arr_term(void); static herr_t H5FL__fac_gc_list(H5FL_fac_head_t *head); +static herr_t H5FL__fac_gc(void); static int H5FL__fac_term_all(void); /* Declare a free list to manage the H5FL_blk_node_t struct */ @@ -217,7 +223,7 @@ H5FL_term_package(void) /*------------------------------------------------------------------------- - * Function: H5FL_malloc + * Function: H5FL__malloc * * Purpose: Attempt to allocate space using malloc. If malloc fails, garbage * collect and try again. If malloc fails again, then return NULL. @@ -228,16 +234,14 @@ H5FL_term_package(void) * Programmer: Quincey Koziol * Tuesday, August 1, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ static void * -H5FL_malloc(size_t mem_size) +H5FL__malloc(size_t mem_size) { void *ret_value = NULL; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* Attempt to allocate the memory requested */ if(NULL==(ret_value=H5MM_malloc(mem_size))) { @@ -252,11 +256,11 @@ H5FL_malloc(size_t mem_size) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FL_malloc() */ +} /* end H5FL__malloc() */ /*------------------------------------------------------------------------- - * Function: H5FL_reg_init + * Function: H5FL__reg_init * * Purpose: Initialize a free list for a certain type. Right now, this just * adds the free list to the list of things to garbage collect. @@ -267,17 +271,15 @@ done: * Programmer: Quincey Koziol * Friday, March 24, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5FL_reg_init(H5FL_reg_head_t *head) +H5FL__reg_init(H5FL_reg_head_t *head) { H5FL_reg_gc_node_t *new_node; /* Pointer to the node for the new list to garbage collect */ herr_t ret_value=SUCCEED; /* return value*/ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* Allocate a new garbage collection node */ if(NULL == (new_node = (H5FL_reg_gc_node_t *)H5MM_malloc(sizeof(H5FL_reg_gc_node_t)))) @@ -304,7 +306,7 @@ H5FL_reg_init(H5FL_reg_head_t *head) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FL_reg_init() */ +} /* end H5FL__reg_init() */ /*------------------------------------------------------------------------- @@ -317,8 +319,6 @@ done: * Programmer: Quincey Koziol * Friday, March 24, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -403,8 +403,6 @@ done: * Programmer: Quincey Koziol * Friday, March 24, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -419,7 +417,7 @@ H5FL_reg_malloc(H5FL_reg_head_t *head H5FL_TRACK_PARAMS) /* Make certain the list is initialized first */ if(!head->init) - if(H5FL_reg_init(head)<0) + if(H5FL__reg_init(head) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'regular' blocks") /* Check for nodes available on the free list first */ @@ -438,7 +436,7 @@ H5FL_reg_malloc(H5FL_reg_head_t *head H5FL_TRACK_PARAMS) } /* end if */ /* Otherwise allocate a node */ else { - if (NULL==(ret_value = H5FL_malloc(head->size))) + if(NULL == (ret_value = H5FL__malloc(head->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Increment the number of blocks allocated in list */ @@ -480,8 +478,6 @@ done: * Programmer: Quincey Koziol * Monday, December 23, 2002 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -524,35 +520,34 @@ static herr_t H5FL__reg_gc_list(H5FL_reg_head_t *head) { H5FL_reg_node_t *free_list; /* Pointer to nodes in free list being garbage collected */ - size_t total_mem; /* Total memory used on list */ FUNC_ENTER_STATIC_NOERR - /* Calculate the total memory used on this list */ - total_mem = head->onlist * head->size; - /* For each free list being garbage collected, walk through the nodes and free them */ free_list = head->list; while(free_list != NULL) { - void *tmp; /* Temporary node pointer */ + H5FL_reg_node_t *tmp; /* Temporary node pointer */ + /* Get the pointer to the next node */ tmp = free_list->next; - /* Decrement the count of nodes allocated and free the node */ - head->allocated--; - + /* Free the block */ H5MM_free(free_list); - free_list = (H5FL_reg_node_t *)tmp; + /* Advance to the next node */ + free_list = tmp; } /* end while */ + /* Decrement the count of nodes allocated and free the node */ + head->allocated -= head->onlist; + + /* Decrement global count of free memory on "regular" lists */ + H5FL_reg_gc_head.mem_freed -= (head->onlist * head->size); + /* Indicate no free nodes on the free list */ head->list = NULL; head->onlist = 0; - /* Decrement global count of free memory on "regular" lists */ - H5FL_reg_gc_head.mem_freed -= total_mem; - FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5FL__reg_gc_list() */ @@ -568,10 +563,6 @@ H5FL__reg_gc_list(H5FL_reg_head_t *head) * Programmer: Quincey Koziol * Friday, March 24, 2000 * - * Modifications: - * Broke into two parts, one for looping over all the free lists and - * another for freeing each list - QAK 7/25/00 - * *------------------------------------------------------------------------- */ static herr_t @@ -670,7 +661,7 @@ HDprintf("%s: head->name = %s, head->allocated = %d\n", FUNC, H5FL_reg_gc_head.f /*------------------------------------------------------------------------- - * Function: H5FL_blk_find_list + * Function: H5FL__blk_find_list * * Purpose: Finds the free list for blocks of a given size. Also moves that * free list node to the head of the priority queue (if it isn't there @@ -684,16 +675,14 @@ HDprintf("%s: head->name = %s, head->allocated = %d\n", FUNC, H5FL_reg_gc_head.f * Programmer: Quincey Koziol * Thursday, March 23, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ static H5FL_blk_node_t * -H5FL_blk_find_list(H5FL_blk_node_t **head, size_t size) +H5FL__blk_find_list(H5FL_blk_node_t **head, size_t size) { H5FL_blk_node_t *temp = NULL; /* Temp. pointer to node in the native list */ - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR /* Find the correct free list */ temp=*head; @@ -729,11 +718,11 @@ H5FL_blk_find_list(H5FL_blk_node_t **head, size_t size) } /* end if */ FUNC_LEAVE_NOAPI(temp) -} /* end H5FL_blk_find_list() */ +} /* end H5FL__blk_find_list() */ /*------------------------------------------------------------------------- - * Function: H5FL_blk_create_list + * Function: H5FL__blk_create_list * * Purpose: Creates a new free list for blocks of the given size at the * head of the priority queue. @@ -745,47 +734,38 @@ H5FL_blk_find_list(H5FL_blk_node_t **head, size_t size) * Programmer: Quincey Koziol * Thursday, March 23, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ static H5FL_blk_node_t * -H5FL_blk_create_list(H5FL_blk_node_t **head, size_t size) +H5FL__blk_create_list(H5FL_blk_node_t **head, size_t size) { - H5FL_blk_node_t *temp; /* Temp. pointer to node in the list */ H5FL_blk_node_t *ret_value = NULL; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* Allocate room for the new free list node */ - if(NULL==(temp=H5FL_MALLOC(H5FL_blk_node_t))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for chunk info") + if(NULL == (ret_value = H5FL_CALLOC(H5FL_blk_node_t))) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "memory allocation failed for chunk info") /* Set the correct values for the new free list */ - temp->size=size; - temp->list=NULL; + ret_value->size = size; /* Attach to head of priority queue */ - if(*head==NULL) { - *head=temp; - temp->next=temp->prev=NULL; - } /* end if */ + if(NULL == *head) + *head = ret_value; else { - temp->next=*head; - (*head)->prev=temp; - temp->prev=NULL; - *head=temp; + ret_value->next = *head; + (*head)->prev = ret_value; + *head = ret_value; } /* end else */ - ret_value=temp; - done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FL_blk_create_list() */ +} /* end H5FL__blk_create_list() */ /*------------------------------------------------------------------------- - * Function: H5FL_blk_init + * Function: H5FL__blk_init * * Purpose: Initialize a priority queue of a certain type. Right now, this just * adds the PQ to the list of things to garbage collect. @@ -796,17 +776,15 @@ done: * Programmer: Quincey Koziol * Saturday, March 25, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5FL_blk_init(H5FL_blk_head_t *head) +H5FL__blk_init(H5FL_blk_head_t *head) { H5FL_blk_gc_node_t *new_node; /* Pointer to the node for the new list to garbage collect */ herr_t ret_value=SUCCEED; /* return value*/ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* Allocate a new garbage collection node */ if(NULL == (new_node = (H5FL_blk_gc_node_t *)H5MM_malloc(sizeof(H5FL_blk_gc_node_t)))) @@ -824,7 +802,7 @@ H5FL_blk_init(H5FL_blk_head_t *head) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FL_blk_init() */ +} /* end H5FL__blk_init() */ /*------------------------------------------------------------------------- @@ -839,8 +817,6 @@ done: * Programmer: Quincey Koziol * Monday, December 16, 2002 * - * Modifications: - * *------------------------------------------------------------------------- */ htri_t @@ -856,10 +832,11 @@ H5FL_blk_free_block_avail(H5FL_blk_head_t *head, size_t size) /* check if there is a free list for blocks of this size */ /* and if there are any blocks available on the list */ - if((free_list = H5FL_blk_find_list(&(head->head), size)) != NULL && free_list->list != NULL) + if((free_list = H5FL__blk_find_list(&(head->head), size)) != NULL && free_list->list != NULL) ret_value = TRUE; else ret_value = FALSE; + FUNC_LEAVE_NOAPI(ret_value) } /* end H5FL_blk_free_block_avail() */ @@ -878,8 +855,6 @@ H5FL_blk_free_block_avail(H5FL_blk_head_t *head, size_t size) * Programmer: Quincey Koziol * Thursday, March 23, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -897,31 +872,40 @@ H5FL_blk_malloc(H5FL_blk_head_t *head, size_t size H5FL_TRACK_PARAMS) /* Make certain the list is initialized first */ if(!head->init) - if(H5FL_blk_init(head)<0) + if(H5FL__blk_init(head) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'block' list") /* check if there is a free list for blocks of this size */ /* and if there are any blocks available on the list */ - if((free_list=H5FL_blk_find_list(&(head->head),size))!=NULL && free_list->list!=NULL) { + if(NULL != (free_list = H5FL__blk_find_list(&(head->head), size)) && NULL != free_list->list) { /* Remove the first node from the free list */ temp=free_list->list; free_list->list=free_list->list->next; /* Decrement the number of blocks & memory used on free list */ + free_list->onlist--; head->onlist--; head->list_mem-=size; /* Decrement the amount of global "block" free list memory in use */ H5FL_blk_gc_head.mem_freed-=size; - } /* end if */ /* No free list available, or there are no nodes on the list, allocate a new node to give to the user */ else { + /* Check if there was no free list for native blocks of this size */ + if(NULL == free_list) + /* Create a new list node and insert it to the queue */ + free_list = H5FL__blk_create_list(&(head->head), size); + HDassert(free_list); + /* Allocate new node, with room for the page info header and the actual page data */ - if(NULL == (temp = (H5FL_blk_list_t *)H5FL_malloc(sizeof(H5FL_blk_list_t) + H5FL_TRACK_SIZE + size))) + if(NULL == (temp = (H5FL_blk_list_t *)H5FL__malloc(sizeof(H5FL_blk_list_t) + H5FL_TRACK_SIZE + size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for chunk") - /* Increment the number of blocks allocated */ + /* Increment the number of blocks of this size */ + free_list->allocated++; + + /* Increment the total number of blocks allocated */ head->allocated++; } /* end else */ @@ -970,8 +954,6 @@ done: * Programmer: Quincey Koziol * Monday, December 23, 2002 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1011,8 +993,6 @@ done: * Programmer: Quincey Koziol * Thursday, March 23, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1055,7 +1035,7 @@ H5FL_blk_free(H5FL_blk_head_t *head, void *block) #endif /* H5FL_TRACK */ /* Get the pointer to the native block info header in front of the native block to free */ - temp = (H5FL_blk_list_t *)((void *)((unsigned char *)block - sizeof(H5FL_blk_list_t))); /*lint !e826 Pointer-to-pointer cast is appropriate here */ + temp = (H5FL_blk_list_t *)((void *)((unsigned char *)block - (sizeof(H5FL_blk_list_t) + H5FL_TRACK_SIZE))); /*lint !e826 Pointer-to-pointer cast is appropriate here */ /* Save the block's size for later */ free_size=temp->size; @@ -1064,20 +1044,18 @@ H5FL_blk_free(H5FL_blk_head_t *head, void *block) HDmemset(temp,255,free_size + sizeof(H5FL_blk_list_t) + H5FL_TRACK_SIZE); #endif /* H5FL_DEBUG */ - /* check if there is a free list for native blocks of this size */ - if((free_list=H5FL_blk_find_list(&(head->head),free_size))==NULL) { + /* Check if there is a free list for native blocks of this size */ + if(NULL == (free_list = H5FL__blk_find_list(&(head->head), free_size))) /* No free list available, create a new list node and insert it to the queue */ - free_list=H5FL_blk_create_list(&(head->head),free_size); - HDassert(free_list); - } /* end if */ + free_list = H5FL__blk_create_list(&(head->head), free_size); + HDassert(free_list); /* Prepend the free'd native block to the front of the free list */ - if(free_list!=NULL) { - temp->next=free_list->list; /* Overwrites the size field in union */ - free_list->list=temp; - } /* end if */ + temp->next = free_list->list; /* Note: Overwrites the size field in union */ + free_list->list = temp; /* Increment the number of blocks on free list */ + free_list->onlist++; head->onlist++; head->list_mem += free_size; @@ -1113,8 +1091,6 @@ done: * Programmer: Quincey Koziol * Thursday, March 23, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1191,44 +1167,70 @@ done: static herr_t H5FL__blk_gc_list(H5FL_blk_head_t *head) { + H5FL_blk_node_t *blk_head; /* Temp. ptr to the free list page node */ + FUNC_ENTER_STATIC_NOERR /* Loop through all the nodes in the block free list queue */ - while(head->head != NULL) { - H5FL_blk_list_t *list; /* The free list of native nodes of a particular size */ - void *temp; /* Temp. ptr to the free list page node */ + blk_head = head->head; + while(blk_head != NULL) { + H5FL_blk_node_t *blk_next; /* Temp. ptr to the next free list node */ + H5FL_blk_list_t *list; /* The free list of native nodes of a particular size */ - temp = head->head->next; + /* Sanity check */ + HDassert((blk_head->onlist && blk_head->list) || (0 == blk_head->onlist && NULL == blk_head->list)); /* Loop through all the blocks in the free list, freeing them */ - list = head->head->list; + list = blk_head->list; while(list != NULL) { - void *next; /* Temp. ptr to the free list list node */ + H5FL_blk_list_t *next; /* Temp. ptr to the free list list node */ + /* Get the pointer to the next node */ next = list->next; - /* Decrement the number of blocks & memory allocated from this PQ */ - head->allocated--; - head->list_mem -= head->head->size; - - /* Decrement global count of free memory on "block" lists */ - H5FL_blk_gc_head.mem_freed -= head->head->size; - /* Free the block */ H5MM_free(list); - list = (H5FL_blk_list_t *)next; + /* Advance to the next node */ + list = next; } /* end while */ - /* Free the free list node */ - head->head = H5FL_FREE(H5FL_blk_node_t, head->head); + /* Decrement the number of blocks allocated from this list */ + blk_head->allocated -= blk_head->onlist; + head->allocated -= blk_head->onlist; + + /* Decrement count of free memory on this "block" list */ + head->list_mem -= (blk_head->onlist * blk_head->size); + + /* Decrement global count of free memory on "block" lists */ + H5FL_blk_gc_head.mem_freed -= (blk_head->onlist * blk_head->size); + + /* Indicate no free nodes on the free list */ + blk_head->list = NULL; + blk_head->onlist = 0; - /* Advance to the next free list */ - head->head = (H5FL_blk_node_t *)temp; + /* Get pointer to next node */ + blk_next = blk_head->next; + + /* Check for list completely unused now */ + if(0 == blk_head->allocated) { + /* Patch this node out of the PQ */ + if(head->head == blk_head) + head->head = blk_head->next; + if(blk_head->prev) + blk_head->prev->next = blk_head->next; + if(blk_head->next) + blk_head->next->prev = blk_head->prev; + + /* Free the free list node */ + H5FL_FREE(H5FL_blk_node_t, blk_head); + } /* end if */ + + /* Advance to the next node */ + blk_head = blk_next; } /* end while */ /* Indicate no free nodes on the free list */ - head->head = NULL; head->onlist = 0; /* Double check that all the memory on this list is recycled */ @@ -1257,7 +1259,7 @@ H5FL__blk_gc(void) H5FL_blk_gc_node_t *gc_node; /* Pointer into the list of things to garbage collect */ herr_t ret_value = SUCCEED; /* return value*/ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* Walk through all the free lists, free()'ing the nodes */ gc_node = H5FL_blk_gc_head.first; @@ -1341,7 +1343,7 @@ HDprintf("%s: head->name = %s, head->allocated = %d\n", FUNC, H5FL_blk_gc_head.f /*------------------------------------------------------------------------- - * Function: H5FL_arr_init + * Function: H5FL__arr_init * * Purpose: Initialize a free list for a arrays of certain type. Right now, * this just adds the free list to the list of things to garbage collect. @@ -1352,18 +1354,16 @@ HDprintf("%s: head->name = %s, head->allocated = %d\n", FUNC, H5FL_blk_gc_head.f * Programmer: Quincey Koziol * Saturday, March 25, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t -H5FL_arr_init(H5FL_arr_head_t *head) +H5FL__arr_init(H5FL_arr_head_t *head) { H5FL_gc_arr_node_t *new_node; /* Pointer to the node for the new list to garbage collect */ size_t u; /* Local index variable */ herr_t ret_value=SUCCEED; /* return value*/ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC /* Allocate a new garbage collection node */ if(NULL == (new_node = (H5FL_gc_arr_node_t *)H5MM_malloc(sizeof(H5FL_gc_arr_node_t)))) @@ -1389,7 +1389,7 @@ H5FL_arr_init(H5FL_arr_head_t *head) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5FL_arr_init() */ +} /* end H5FL__arr_init() */ /*------------------------------------------------------------------------- @@ -1403,8 +1403,6 @@ done: * Programmer: Quincey Koziol * Friday, March 24, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1481,8 +1479,6 @@ done: * Programmer: Quincey Koziol * Saturday, March 25, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1500,7 +1496,7 @@ H5FL_arr_malloc(H5FL_arr_head_t *head, size_t elem) /* Make certain the list is initialized first */ if(!head->init) - if(H5FL_arr_init(head)<0) + if(H5FL__arr_init(head) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'array' blocks") /* Sanity check that the number of elements is supported */ @@ -1527,10 +1523,13 @@ H5FL_arr_malloc(H5FL_arr_head_t *head, size_t elem) } /* end if */ /* Otherwise allocate a node */ else { - if(NULL == (new_obj = (H5FL_arr_list_t *)H5FL_malloc(sizeof(H5FL_arr_list_t)+mem_size))) + if(NULL == (new_obj = (H5FL_arr_list_t *)H5FL__malloc(sizeof(H5FL_arr_list_t)+mem_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") - /* Increment the number of blocks allocated in list */ + /* Increment the number of blocks of this size */ + head->list_arr[elem].allocated++; + + /* Increment the number of blocks allocated in list, of all sizes */ head->allocated++; } /* end else */ @@ -1556,8 +1555,6 @@ done: * Programmer: Quincey Koziol * Monday, December 23, 2002 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1594,8 +1591,6 @@ done: * Programmer: Quincey Koziol * Saturday, March 25, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1667,34 +1662,35 @@ H5FL__arr_gc_list(H5FL_arr_head_t *head) for(u = 0; u < (unsigned)head->maxelem; u++) { if(head->list_arr[u].onlist > 0) { H5FL_arr_list_t *arr_free_list; /* Pointer to nodes in free list being garbage collected */ - size_t total_mem; /* Total memory used on list */ - - /* Calculate the total memory used on this list */ - total_mem = head->list_arr[u].onlist * head->list_arr[u].size; /* For each free list being garbage collected, walk through the nodes and free them */ arr_free_list = head->list_arr[u].list; while(arr_free_list != NULL) { - void *tmp; /* Temporary node pointer */ + H5FL_arr_list_t *tmp; /* Temporary node pointer */ + /* Get the pointer to the next node */ tmp = arr_free_list->next; - /* Decrement the count of nodes allocated and free the node */ - head->allocated--; + /* Free the node */ H5MM_free(arr_free_list); - arr_free_list = (H5FL_arr_list_t *)tmp; + /* Advance to the next node */ + arr_free_list = tmp; } /* end while */ - /* Indicate no free nodes on the free list */ - head->list_arr[u].list = NULL; - head->list_arr[u].onlist = 0; + /* Decrement the count of nodes allocated */ + head->list_arr[u].allocated -= head->list_arr[u].onlist; + head->allocated -= head->list_arr[u].onlist; /* Decrement count of free memory on this "array" list */ - head->list_mem -= total_mem; + head->list_mem -= (head->list_arr[u].onlist * head->list_arr[u].size); /* Decrement global count of free memory on "array" lists */ - H5FL_arr_gc_head.mem_freed -= total_mem; + H5FL_arr_gc_head.mem_freed -= (head->list_arr[u].onlist * head->list_arr[u].size); + + /* Indicate no free nodes on the free list */ + head->list_arr[u].list = NULL; + head->list_arr[u].onlist = 0; } /* end if */ } /* end for */ @@ -1820,8 +1816,6 @@ HDprintf("%s: head->name = %s, head->allocated = %d\n", FUNC, H5FL_arr_gc_head.f * Programmer: Quincey Koziol * Saturday, April 3, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1856,8 +1850,6 @@ H5FL_seq_free(H5FL_seq_head_t *head, void *obj) * Programmer: Quincey Koziol * Saturday, April 3, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1889,8 +1881,6 @@ H5FL_seq_malloc(H5FL_seq_head_t *head, size_t elem H5FL_TRACK_PARAMS) * Programmer: Quincey Koziol * Saturday, April 3, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1922,8 +1912,6 @@ H5FL_seq_calloc(H5FL_seq_head_t *head, size_t elem H5FL_TRACK_PARAMS) * Programmer: Quincey Koziol * Saturday, April 3, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ void * @@ -1955,11 +1943,6 @@ H5FL_seq_realloc(H5FL_seq_head_t *head, void * obj, size_t new_elem H5FL_TRACK_P * Programmer: Quincey Koziol * Wednesday, February 2, 2005 * - * Modifications: - * Neil Fortner - * Friday, December 19, 2008 - * Totally rewritten to support new factory implementation - * *------------------------------------------------------------------------- */ H5FL_fac_head_t * @@ -2032,11 +2015,6 @@ done: * Programmer: Quincey Koziol * Wednesday, February 2, 2005 * - * Modifications: - * Neil Fortner - * Friday, December 19, 2008 - * Totally rewritten to support new factory implementation - * *------------------------------------------------------------------------- */ void * @@ -2120,11 +2098,6 @@ done: * Programmer: Quincey Koziol * Wednesday, February 2, 2005 * - * Modifications: - * Neil Fortner - * Friday, December 19, 2008 - * Totally rewritten to support new factory implementation - * *------------------------------------------------------------------------- */ void * @@ -2155,7 +2128,7 @@ H5FL_fac_malloc(H5FL_fac_head_t *head H5FL_TRACK_PARAMS) } /* end if */ /* Otherwise allocate a node */ else { - if (NULL==(ret_value = H5FL_malloc(head->size))) + if(NULL == (ret_value = H5FL__malloc(head->size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Increment the number of blocks allocated in list */ @@ -2197,11 +2170,6 @@ done: * Programmer: Quincey Koziol * Wednesday, February 2, 2005 * - * Modifications: - * Neil Fortner - * Friday, December 19, 2008 - * Totally rewritten to support new factory implementation - * *------------------------------------------------------------------------- */ void * @@ -2245,35 +2213,34 @@ static herr_t H5FL__fac_gc_list(H5FL_fac_head_t *head) { H5FL_fac_node_t *free_list; /* Pointer to nodes in free list being garbage collected */ - size_t total_mem; /* Total memory used on list */ FUNC_ENTER_STATIC_NOERR - /* Calculate the total memory used on this list */ - total_mem = head->onlist * head->size; - /* For each free list being garbage collected, walk through the nodes and free them */ free_list = head->list; while(free_list != NULL) { - void *tmp; /* Temporary node pointer */ + H5FL_fac_node_t *tmp; /* Temporary node pointer */ + /* Get the pointer to the next node */ tmp = free_list->next; - /* Decrement the count of nodes allocated and free the node */ - head->allocated--; - + /* Free the block */ H5MM_free(free_list); - free_list = (H5FL_fac_node_t *)tmp; + /* Advance to the next node */ + free_list = tmp; } /* end while */ + /* Decrement the count of nodes allocated and free the node */ + head->allocated -= head->onlist; + + /* Decrement global count of free memory on "factory" lists */ + H5FL_fac_gc_head.mem_freed -= (head->onlist * head->size); + /* Indicate no free nodes on the free list */ head->list = NULL; head->onlist = 0; - /* Decrement global count of free memory on "factory" lists */ - H5FL_fac_gc_head.mem_freed -= total_mem; - FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5FL__fac_gc_list() */ @@ -2329,11 +2296,6 @@ done: * Programmer: Quincey Koziol * Wednesday, February 2, 2005 * - * Modifications: - * Neil Fortner - * Friday, December 19, 2008 - * Totally rewritten to support new factory implementation - * *------------------------------------------------------------------------- */ herr_t @@ -2438,8 +2400,6 @@ HDprintf("%s: head->size = %d, head->allocated = %d\n", FUNC, (int)H5FL_fac_gc_h * Programmer: Quincey Koziol * Friday, March 24, 2000 * - * Modifications: - * *------------------------------------------------------------------------- */ herr_t @@ -2495,10 +2455,6 @@ done: * Programmer: Quincey Koziol * Wednesday, August 2, 2000 * - * Modifications: Neil Fortner - * Wednesday, April 8, 2009 - * Added support for factory free lists - * *------------------------------------------------------------------------- */ herr_t @@ -2531,3 +2487,127 @@ H5FL_set_free_list_limits(int reg_global_lim, int reg_list_lim, int arr_global_l FUNC_LEAVE_NOAPI(ret_value) } /* end H5FL_set_free_list_limits() */ + +/*------------------------------------------------------------------------- + * Function: H5FL_get_free_list_sizes + * + * Purpose: Gets the current size of the different kinds of free lists. + * These lists are global for the entire library. The size returned + * included nodes that are freed and awaiting garbage collection / + * reallocation. + * + * Parameters: + * size_t *reg_size; OUT: The current size of all "regular" free list memory used + * size_t *arr_size; OUT: The current size of all "array" free list memory used + * size_t *blk_size; OUT: The current size of all "block" free list memory used + * size_t *fac_size; OUT: The current size of all "factory" free list memory used + * + * Return: Success: non-negative + * Failure: negative + * + * Programmer: Quincey Koziol + * Friday, March 6, 2020 + * + *------------------------------------------------------------------------- + */ +herr_t +H5FL_get_free_list_sizes(size_t *reg_size, size_t *arr_size, size_t *blk_size, + size_t *fac_size) +{ + FUNC_ENTER_NOAPI_NOERR + + /* Retrieve the amount of "regular" memory used */ + if(reg_size) { + H5FL_reg_gc_node_t *gc_node; /* Pointer into the list of lists */ + + /* Walk through all the free lists, counting the amount of memory */ + *reg_size = 0; + gc_node = H5FL_reg_gc_head.first; + while(gc_node != NULL) { + H5FL_reg_head_t *reg_list = gc_node->list; /* Head of list */ + + /* Sanity check */ + HDassert(reg_list->init); + + /* Add the amount of memory for this list */ + *reg_size += (reg_list->size * reg_list->allocated); + + /* Go on to the next free list */ + gc_node = gc_node->next; + } /* end while */ + } /* end if */ + + /* Retrieve the amount of "array" memory used */ + if(arr_size) { + H5FL_gc_arr_node_t *gc_arr_node; /* Pointer into the list of things to garbage collect */ + + /* Walk through all the free lists, counting the amount of memory */ + *arr_size = 0; + gc_arr_node = H5FL_arr_gc_head.first; + while(gc_arr_node != NULL) { + H5FL_arr_head_t *head = gc_arr_node->list; /* Head of array list elements */ + + /* Sanity check */ + HDassert(head->init); + + /* Check for any allocated elements in this list */ + if(head->allocated > 0) { + unsigned u; + + /* Walk through the free lists for array sizes */ + for(u = 0; u < (unsigned)head->maxelem; u++) + /* Add the amount of memory for this size */ + *arr_size += head->list_arr[u].allocated * head->list_arr[u].size; + } /* end if */ + + /* Go on to the next free list */ + gc_arr_node = gc_arr_node->next; + } /* end while */ + } /* end if */ + + /* Retrieve the amount of "block" memory used */ + if(blk_size) { + H5FL_blk_gc_node_t *gc_blk_node; /* Pointer into the list of things */ + + /* Walk through all the free lists */ + gc_blk_node = H5FL_blk_gc_head.first; + *blk_size = 0; + while(gc_blk_node != NULL) { + H5FL_blk_node_t *blk_head; /* Temp. ptr to the free list block node */ + + /* Loop through all the nodes in the block free list queue */ + blk_head = gc_blk_node->pq->head; + while(blk_head != NULL) { + /* Add size of blocks on this list */ + *blk_size += (blk_head->allocated * blk_head->size); + + /* Get pointer to next node */ + blk_head = blk_head->next; + } /* end while */ + + /* Go on to the next free list */ + gc_blk_node = gc_blk_node->next; + } /* end while */ + } /* end if */ + + /* Retrieve the amount of "factory" memory used */ + if(fac_size) { + H5FL_fac_gc_node_t *gc_fac_node; /* Pointer into the list of things to garbage collect */ + + /* Walk through all the free lists */ + gc_fac_node = H5FL_fac_gc_head.first; + *fac_size = 0; + while(gc_fac_node != NULL) { + H5FL_fac_head_t *fac_head = gc_fac_node->list; /* Head node for factory list */ + + /* Add size of blocks on this list */ + *fac_size += (fac_head->allocated * fac_head->size); + + /* Go on to the next free list to garbage collect */ + gc_fac_node = gc_fac_node->next; + } /* end while */ + } /* end if */ + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5FL_get_free_list_sizes() */ + diff --git a/src/H5FLprivate.h b/src/H5FLprivate.h index d5a68d7..94a51e5 100644 --- a/src/H5FLprivate.h +++ b/src/H5FLprivate.h @@ -157,6 +157,8 @@ typedef union H5FL_blk_list_t { /* Data structure for priority queue node of block free lists */ typedef struct H5FL_blk_node_t { size_t size; /* Size of the blocks in the list */ + unsigned allocated; /* Number of blocks of this size allocated */ + unsigned onlist; /* Number of blocks on free list */ H5FL_blk_list_t *list; /* List of free blocks */ struct H5FL_blk_node_t *next; /* Pointer to next free list in queue */ struct H5FL_blk_node_t *prev; /* Pointer to previous free list in queue */ @@ -165,9 +167,9 @@ typedef struct H5FL_blk_node_t { /* Data structure for priority queue of native block free lists */ typedef struct H5FL_blk_head_t { hbool_t init; /* Whether the free list has been initialized */ - unsigned allocated; /* Number of blocks allocated */ - unsigned onlist; /* Number of blocks on free list */ - size_t list_mem; /* Amount of memory in block on free list */ + unsigned allocated; /* Total number of blocks allocated */ + unsigned onlist; /* Total number of blocks on free list */ + size_t list_mem; /* Total amount of memory in blocks on free list */ const char *name; /* Name of the type */ H5FL_blk_node_t *head; /* Pointer to first free list in queue */ } H5FL_blk_head_t; @@ -228,7 +230,9 @@ typedef union H5FL_arr_list_t { /* Data structure for each size of array element */ typedef struct H5FL_arr_node_t { - size_t size; /* Size of the blocks in the list */ + size_t size; /* Size of the blocks in the list (in bytes) */ + /* (Note: base_size + <# of elem> * elem_size) */ + unsigned allocated; /* Number of blocks allocated of this element size */ unsigned onlist; /* Number of blocks on free list */ H5FL_arr_list_t *list; /* List of free blocks */ } H5FL_arr_node_t; @@ -236,7 +240,7 @@ typedef struct H5FL_arr_node_t { /* Data structure for free list of array blocks */ typedef struct H5FL_arr_head_t { hbool_t init; /* Whether the free list has been initialized */ - unsigned allocated; /* Number of blocks allocated */ + unsigned allocated; /* Total number of blocks allocated */ size_t list_mem; /* Amount of memory in block on free list */ const char *name; /* Name of the type */ int maxelem; /* Maximum number of elements in an array */ @@ -423,6 +427,8 @@ H5_DLL herr_t H5FL_garbage_coll(void); H5_DLL herr_t H5FL_set_free_list_limits(int reg_global_lim, int reg_list_lim, int arr_global_lim, int arr_list_lim, int blk_global_lim, int blk_list_lim, int fac_global_lim, int fac_list_lim); +H5_DLL herr_t H5FL_get_free_list_sizes(size_t *reg_size, size_t *arr_size, + size_t *blk_size, size_t *fac_size); H5_DLL int H5FL_term_interface(void); #endif diff --git a/src/H5FSsection.c b/src/H5FSsection.c index df67bd9..cf4a587 100644 --- a/src/H5FSsection.c +++ b/src/H5FSsection.c @@ -371,10 +371,10 @@ HDfprintf(stderr, "%s: fspace->alloc_sect_size = %Hu, fspace->sect_size = %Hu\n" /* Check if section info lock count dropped to zero */ if(fspace->sinfo_lock_count == 0) { hbool_t release_sinfo_space = FALSE; /* Flag to indicate section info space in file should be released */ - hbool_t flush_in_progress = FALSE; /* Is flushing in progress */ + hbool_t closing_or_flushing = f->shared->closing; /* Is closing or flushing in progress */ - /* Check whether cache is flush_in_progress */ - if(H5AC_get_cache_flush_in_progress(f->shared->cache, &flush_in_progress) < 0) + /* Check whether cache-flush is in progress if closing is not. */ + if(!closing_or_flushing && H5AC_get_cache_flush_in_progress(f->shared->cache, &closing_or_flushing) < 0) HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Can't get flush_in_progress") /* Check if we actually protected the section info */ @@ -390,7 +390,7 @@ HDfprintf(stderr, "%s: fspace->alloc_sect_size = %Hu, fspace->sect_size = %Hu\n" cache_flags |= H5AC__DIRTIED_FLAG; /* On file close or flushing, does not allow section info to shrink in size */ - if(f->shared->closing || flush_in_progress) { + if(closing_or_flushing) { if(fspace->sect_size > fspace->alloc_sect_size) cache_flags |= H5AC__DELETED_FLAG | H5AC__TAKE_OWNERSHIP_FLAG; else @@ -441,7 +441,7 @@ HDfprintf(stderr, "%s: Relinquishing section info ownership\n", FUNC); /* Set flag to release section info space in file */ /* On file close or flushing, only need to release section info with size bigger than previous section */ - if(f->shared->closing || flush_in_progress) { + if(closing_or_flushing) { if(fspace->sect_size > fspace->alloc_sect_size) release_sinfo_space = TRUE; else diff --git a/src/H5Fmount.c b/src/H5Fmount.c index 13d95aa..5e6b899 100644 --- a/src/H5Fmount.c +++ b/src/H5Fmount.c @@ -766,7 +766,7 @@ H5F_traverse_mount(H5O_loc_t *oloc/*in,out*/) HGOTO_ERROR(H5E_FILE, H5E_CANTFREE, FAIL, "unable to free object location") /* Copy the entry for the root group */ - if(H5O_loc_copy(oloc, mnt_oloc, H5_COPY_DEEP) < 0) + if(H5O_loc_copy_deep(oloc, mnt_oloc) < 0) HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, FAIL, "unable to copy object location") /* In case the shared root group info points to a different file handle diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index f0c28ca..fbb164d 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -432,7 +432,7 @@ typedef struct H5F_t H5F_t; default: HDassert("bad sizeof size" && 0); \ } -#define H5F_DECODE_LENGTH(f,p,l) H5F_DECODE_LENGTH_LEN(p,l,H5F_SIZEOF_SIZE(f)) +#define H5F_DECODE_LENGTH(f,p,l) DECODE_VAR(p,l,H5F_SIZEOF_SIZE(f)) /* * Macros that check for overflows. These are somewhat dangerous to fiddle diff --git a/src/H5Gint.c b/src/H5Gint.c index e0b8bd7..a3849a6 100644 --- a/src/H5Gint.c +++ b/src/H5Gint.c @@ -336,7 +336,7 @@ H5G_open(const H5G_loc_t *loc) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate space for group") /* Shallow copy (take ownership) of the group location object */ - if(H5O_loc_copy(&(grp->oloc), loc->oloc, H5_COPY_SHALLOW) < 0) + if(H5O_loc_copy_shallow(&(grp->oloc), loc->oloc) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTCOPY, NULL, "can't copy object location") if(H5G_name_copy(&(grp->path), loc->path, H5_COPY_SHALLOW) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTCOPY, NULL, "can't copy path") diff --git a/src/H5Gobj.c b/src/H5Gobj.c index 15dbd79..1892182 100644 --- a/src/H5Gobj.c +++ b/src/H5Gobj.c @@ -738,7 +738,7 @@ H5G__obj_info(const H5O_loc_t *oloc, H5G_info_t *grp_info) H5G_loc_reset(&grp_loc); /* Deep copy (duplicate) of the group location object */ - if(H5O_loc_copy(&grp_oloc, (H5O_loc_t *)oloc, H5_COPY_DEEP) < 0) /* (Casting away const OK - QAK) */ + if(H5O_loc_copy_deep(&grp_oloc, oloc) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTCOPY, FAIL, "can't copy object location") /* Open the group */ diff --git a/src/H5Gtraverse.c b/src/H5Gtraverse.c index 7482e27..0f27880 100644 --- a/src/H5Gtraverse.c +++ b/src/H5Gtraverse.c @@ -132,7 +132,7 @@ H5G__traverse_slink_cb(H5G_loc_t H5_ATTR_UNUSED *grp_loc, const char H5_ATTR_UNU } /* end if */ else { /* Copy new location information for resolved object */ - H5O_loc_copy(udata->obj_loc->oloc, obj_loc->oloc, H5_COPY_DEEP); + H5O_loc_copy_deep(udata->obj_loc->oloc, obj_loc->oloc); /* Indicate that the object exists */ udata->exists = TRUE; @@ -215,7 +215,8 @@ H5I_term_package(void) *------------------------------------------------------------------------- */ H5I_type_t -H5Iregister_type(size_t hash_size, unsigned reserved, H5I_free_t free_func) +H5Iregister_type(size_t H5_ATTR_DEBUG_API_USED hash_size, unsigned reserved, + H5I_free_t free_func) { H5I_class_t *cls = NULL; /* New ID class */ H5I_type_t new_type; /* New ID type value */ @@ -1910,7 +1910,7 @@ H5L__link_cb(H5G_loc_t *grp_loc/*in*/, const char *name, const H5O_link_t H5_ATT * copy and wipe out grp_loc) */ H5G_name_reset(&temp_path); - if(H5O_loc_copy(&temp_oloc, grp_loc->oloc, H5_COPY_DEEP) < 0) + if(H5O_loc_copy_deep(&temp_oloc, grp_loc->oloc) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTCOPY, FAIL, "unable to copy object location") temp_loc.oloc = &temp_oloc; @@ -2695,7 +2695,7 @@ H5L__move_dest_cb(H5G_loc_t *grp_loc/*in*/, const char *name, * copy and wipe out grp_loc) */ H5G_name_reset(&temp_path); - if(H5O_loc_copy(&temp_oloc, grp_loc->oloc, H5_COPY_DEEP) < 0) + if(H5O_loc_copy_deep(&temp_oloc, grp_loc->oloc) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTCOPY, FAIL, "unable to copy object location") temp_loc.oloc = &temp_oloc; @@ -108,8 +108,8 @@ static H5MM_block_t H5MM_block_head_s; /* Statistics about block allocations */ static unsigned long long H5MM_total_alloc_bytes_s = 0; -static unsigned long long H5MM_curr_alloc_bytes_s = 0; -static unsigned long long H5MM_peak_alloc_bytes_s = 0; +static size_t H5MM_curr_alloc_bytes_s = 0; +static size_t H5MM_peak_alloc_bytes_s = 0; static size_t H5MM_max_block_size_s = 0; static size_t H5MM_total_alloc_blocks_count_s = 0; static size_t H5MM_curr_alloc_blocks_count_s = 0; @@ -235,7 +235,7 @@ H5MM_final_sanity_check(void) HDassert(H5MM_block_head_s.prev == &H5MM_block_head_s); #ifdef H5MM_PRINT_MEMORY_STATS HDfprintf(stderr, "%s: H5MM_total_alloc_bytes_s = %llu\n", __func__, H5MM_total_alloc_bytes_s); - HDfprintf(stderr, "%s: H5MM_peak_alloc_bytes_s = %llu\n", __func__, H5MM_peak_alloc_bytes_s); + HDfprintf(stderr, "%s: H5MM_peak_alloc_bytes_s = %zu\n", __func__, H5MM_peak_alloc_bytes_s); HDfprintf(stderr, "%s: H5MM_max_block_size_s = %zu\n", __func__, H5MM_max_block_size_s); HDfprintf(stderr, "%s: H5MM_total_alloc_blocks_count_s = %zu\n", __func__, H5MM_total_alloc_blocks_count_s); HDfprintf(stderr, "%s: H5MM_peak_alloc_blocks_count_s = %zu\n", __func__, H5MM_peak_alloc_blocks_count_s); @@ -625,3 +625,46 @@ H5MM_memcpy(void *dest, const void *src, size_t n) } /* end H5MM_memcpy() */ + +/*------------------------------------------------------------------------- + * Function: H5MM_get_alloc_stats + * + * Purpose: Gets the memory allocation statistics for the library, if the + * H5_MEMORY_ALLOC_SANITY_CHECK macro is defined. If the macro is not + * defined, zeros are returned. These statistics are global for the + * entire library. + * + * Parameters: + * H5_alloc_stats_t *stats; OUT: Memory allocation statistics + * + * Return: Success: non-negative + * Failure: negative + * + * Programmer: Quincey Koziol + * Saturday, March 7, 2020 + * + *------------------------------------------------------------------------- + */ +herr_t +H5MM_get_alloc_stats(H5_alloc_stats_t *stats) +{ + FUNC_ENTER_NOAPI_NOERR + +#if defined H5_MEMORY_ALLOC_SANITY_CHECK + if(stats) { + stats->total_alloc_bytes = H5MM_total_alloc_bytes_s; + stats->curr_alloc_bytes = H5MM_curr_alloc_bytes_s; + stats->peak_alloc_bytes = H5MM_peak_alloc_bytes_s; + stats->max_block_size = H5MM_max_block_size_s; + stats->total_alloc_blocks_count = H5MM_total_alloc_blocks_count_s; + stats->curr_alloc_blocks_count = H5MM_curr_alloc_blocks_count_s; + stats->peak_alloc_blocks_count = H5MM_peak_alloc_blocks_count_s; + } /* end if */ +#else /* H5_MEMORY_ALLOC_SANITY_CHECK */ + if(stats) + HDmemset(stats, 0, sizeof(H5_alloc_stats_t)); +#endif /* H5_MEMORY_ALLOC_SANITY_CHECK */ + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5MM_get_alloc_stats() */ + diff --git a/src/H5MMprivate.h b/src/H5MMprivate.h index 240b931..0787eb2 100644 --- a/src/H5MMprivate.h +++ b/src/H5MMprivate.h @@ -47,6 +47,7 @@ H5_DLL char *H5MM_strdup(const char *s); H5_DLL void *H5MM_xfree(void *mem); H5_DLL void *H5MM_xfree_const(const void *mem); H5_DLL void *H5MM_memcpy(void *dest, const void *src, size_t n); +H5_DLL herr_t H5MM_get_alloc_stats(H5_alloc_stats_t *stats); #if defined H5_MEMORY_ALLOC_SANITY_CHECK H5_DLL void H5MM_sanity_check_all(void); H5_DLL void H5MM_final_sanity_check(void); diff --git a/src/H5Ochunk.c b/src/H5Ochunk.c index 9ce5a46..72402e4 100644 --- a/src/H5Ochunk.c +++ b/src/H5Ochunk.c @@ -358,7 +358,7 @@ H5O__chunk_update_idx(H5F_t *f, H5O_t *oh, unsigned idx) HGOTO_ERROR(H5E_OHDR, H5E_CANTUNPROTECT, FAIL, "unable to release object header chunk") done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI_TAG(ret_value) } /* end H5O__chunk_update_idx() */ diff --git a/src/H5Odbg.c b/src/H5Odbg.c index b8190ae..3c91cae 100644 --- a/src/H5Odbg.c +++ b/src/H5Odbg.c @@ -153,7 +153,7 @@ H5O__assert(const H5O_t *oh) /* Loop over all messages in object header */ for(u = 0, curr_msg = &oh->mesg[0]; u < oh->nmesgs; u++, curr_msg++) { - uint8_t *curr_hdr; /* Start of current message header */ + uint8_t H5_ATTR_NDEBUG_UNUSED *curr_hdr; /* Start of current message header */ size_t curr_tot_size; /* Total size of current message (including header) */ curr_hdr = curr_msg->raw - H5O_SIZEOF_MSGHDR_OH(oh); @@ -164,7 +164,7 @@ H5O__assert(const H5O_t *oh) free_space += curr_tot_size; else if(H5O_CONT_ID == curr_msg->type->id) { H5O_cont_t *cont = (H5O_cont_t *)curr_msg->native; - hbool_t found_chunk = FALSE; /* Found a chunk that matches */ + hbool_t H5_ATTR_NDEBUG_UNUSED found_chunk = FALSE; /* Found a chunk that matches */ HDassert(cont); diff --git a/src/H5Oint.c b/src/H5Oint.c index d5a3a71..04220af 100644 --- a/src/H5Oint.c +++ b/src/H5Oint.c @@ -1913,27 +1913,19 @@ H5O_loc_reset(H5O_loc_t *loc) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5O_loc_reset() */ - + /*------------------------------------------------------------------------- * Function: H5O_loc_copy * - * Purpose: Copy object location information + * Purpose: Copy object location information, according to the depth. * * Return: Success: Non-negative - * Failure: Negative + * Failure: Negative * * Programmer: Quincey Koziol * koziol@ncsa.uiuc.edu * Monday, September 19, 2005 * - * Notes: 'depth' parameter determines how much of the group entry - * structure we want to copy. The values are: - * H5_COPY_SHALLOW - Copy all the field values from the source - * to the destination, but not copying objects pointed to. - * (Destination "takes ownership" of objects pointed to) - * H5_COPY_DEEP - Copy all the fields from the source to - * the destination, deep copying objects pointed to. - * *------------------------------------------------------------------------- */ herr_t @@ -1946,25 +1938,88 @@ H5O_loc_copy(H5O_loc_t *dst, H5O_loc_t *src, H5_copy_depth_t depth) HDassert(dst); HDassert(depth == H5_COPY_SHALLOW || depth == H5_COPY_DEEP); + /* Invoke correct routine */ + if(depth == H5_COPY_SHALLOW) + H5O_loc_copy_shallow(dst, src); + else + H5O_loc_copy_deep(dst, src); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5O_loc_copy() */ + + +/*------------------------------------------------------------------------- + * Function: H5O_loc_copy_shallow + * + * Purpose: Shallow copy object location information. Copies all the field + * values from the source to the destination, but not copying + * objects pointed to. (i.e. destination "takes ownership" of + * objects pointed to) + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: Quincey Koziol + * January 18, 2020 + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_loc_copy_shallow(H5O_loc_t *dst, H5O_loc_t *src) +{ + FUNC_ENTER_NOAPI_NOINIT_NOERR + + /* Check arguments */ + HDassert(src); + HDassert(dst); + /* Copy the top level information */ H5MM_memcpy(dst, src, sizeof(H5O_loc_t)); - /* Deep copy the names */ - if(depth == H5_COPY_DEEP) { - /* If the original entry was holding open the file, this one should - * hold it open, too. - */ - if(src->holding_file) - H5F_INCR_NOPEN_OBJS(dst->file); - } - else if(depth == H5_COPY_SHALLOW) { - H5O_loc_reset(src); - } + /* Reset the source location, as the destination 'owns' it now */ + H5O_loc_reset(src); FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5O_loc_copy() */ +} /* end H5O_loc_copy_shallow() */ + +/*------------------------------------------------------------------------- + * Function: H5O_loc_copy_deep + * + * Purpose: Deep copy object location information. Copies all the fields + * from the source to the destination, deep copying objects + * pointed to. + * + * Return: Success: Non-negative + * Failure: Negative + * + * Programmer: David Young + * January 18, 2020 + * + *------------------------------------------------------------------------- + */ +herr_t +H5O_loc_copy_deep(H5O_loc_t *dst, const H5O_loc_t *src) +{ + FUNC_ENTER_NOAPI_NOINIT_NOERR + + /* Check arguments */ + HDassert(src); + HDassert(dst); + + /* Copy the top level information */ + H5MM_memcpy(dst, src, sizeof(H5O_loc_t)); + + /* If the original entry was holding open the file, this one should + * hold it open, too. + */ + if(src->holding_file) + H5F_INCR_NOPEN_OBJS(dst->file); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5O_loc_copy_deep() */ + /*------------------------------------------------------------------------- * Function: H5O_loc_hold_file * diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index 52a72b2..ceaa96d 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -997,6 +997,8 @@ H5_DLL herr_t H5O_debug(H5F_t *f, haddr_t addr, FILE * stream, int indent, /* These functions operate on object locations */ H5_DLL herr_t H5O_loc_reset(H5O_loc_t *loc); H5_DLL herr_t H5O_loc_copy(H5O_loc_t *dst, H5O_loc_t *src, H5_copy_depth_t depth); +H5_DLL herr_t H5O_loc_copy_shallow(H5O_loc_t *dst, H5O_loc_t *src); +H5_DLL herr_t H5O_loc_copy_deep(H5O_loc_t *dst, const H5O_loc_t *src); H5_DLL herr_t H5O_loc_hold_file(H5O_loc_t *loc); H5_DLL herr_t H5O_loc_free(H5O_loc_t *loc); H5_DLL H5O_loc_t *H5O_get_loc(hid_t id); diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c index 9a04c3e..7866464 100644 --- a/src/H5Pfapl.c +++ b/src/H5Pfapl.c @@ -4479,7 +4479,8 @@ H5P_facc_mdc_log_location_close(const char H5_ATTR_UNUSED *name, size_t H5_ATTR_ *------------------------------------------------------------------------- */ herr_t -H5Pset_evict_on_close(hid_t fapl_id, hbool_t evict_on_close) +H5Pset_evict_on_close(hid_t fapl_id, + hbool_t H5_ATTR_PARALLEL_UNUSED evict_on_close) { H5P_genplist_t *plist; /* property list pointer */ herr_t ret_value = SUCCEED; /* return value */ diff --git a/src/H5Rint.c b/src/H5Rint.c index 1df8a20..30f3dbb 100644 --- a/src/H5Rint.c +++ b/src/H5Rint.c @@ -1768,6 +1768,7 @@ H5R__decode_token_region_compat(H5F_t *f, const unsigned char *buf, H5O_token_t token = { 0 }; size_t data_size; const uint8_t *p; + H5S_t *space = NULL; herr_t ret_value = SUCCEED; FUNC_ENTER_PACKAGE @@ -1788,7 +1789,6 @@ H5R__decode_token_region_compat(H5F_t *f, const unsigned char *buf, if(space_ptr) { H5O_loc_t oloc; /* Object location */ - H5S_t *space = NULL; /* Initialize the object location */ H5O_loc_reset(&oloc); @@ -1812,6 +1812,12 @@ H5R__decode_token_region_compat(H5F_t *f, const unsigned char *buf, done: H5MM_free(data); + + if(ret_value < 0) { + if(space && H5S_close(space) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataspace") + } + FUNC_LEAVE_NOAPI(ret_value) } /* end H5R__decode_token_region_compat() */ diff --git a/src/H5Sall.c b/src/H5Sall.c index 4a4245d..77fb582 100644 --- a/src/H5Sall.c +++ b/src/H5Sall.c @@ -690,6 +690,9 @@ H5S__all_deserialize(H5S_t **space, const uint8_t **p) /* Decode version */ UINT32DECODE(*p, version); + if(version < H5S_ALL_VERSION_1 || version > H5S_ALL_VERSION_LATEST) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "bad version number for all selection") + /* Skip over the remainder of the header */ *p += 8; diff --git a/src/H5Snone.c b/src/H5Snone.c index 0949b2a..630d1d5 100644 --- a/src/H5Snone.c +++ b/src/H5Snone.c @@ -648,6 +648,9 @@ H5S__none_deserialize(H5S_t **space, const uint8_t **p) /* Decode version */ UINT32DECODE(*p, version); + if(version < H5S_NONE_VERSION_1 || version > H5S_NONE_VERSION_LATEST) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "bad version number for none selection") + /* Skip over the remainder of the header */ *p += 8; diff --git a/src/H5Spkg.h b/src/H5Spkg.h index e139bce..da2dd4a 100644 --- a/src/H5Spkg.h +++ b/src/H5Spkg.h @@ -47,14 +47,17 @@ #define H5S_HYPER_VERSION_LATEST H5S_HYPER_VERSION_3 /* Versions for H5S_SEL_POINTS selection info */ -#define H5S_POINT_VERSION_1 1 -#define H5S_POINT_VERSION_2 2 +#define H5S_POINT_VERSION_1 1 +#define H5S_POINT_VERSION_2 2 +#define H5S_POINT_VERSION_LATEST H5S_POINT_VERSION_2 /* Versions for H5S_SEL_NONE selection info */ -#define H5S_NONE_VERSION_1 1 +#define H5S_NONE_VERSION_1 1 +#define H5S_NONE_VERSION_LATEST H5S_NONE_VERSION_1 /* Versions for H5S_SEL_ALL selection info */ -#define H5S_ALL_VERSION_1 1 +#define H5S_ALL_VERSION_1 1 +#define H5S_ALL_VERSION_LATEST H5S_ALL_VERSION_1 /* Encoded size of selection info for H5S_SEL_POINTS/H5S_SEL_HYPER */ #define H5S_SELECT_INFO_ENC_SIZE_2 0x02 /* 2 bytes: 16 bits */ diff --git a/src/H5Spoint.c b/src/H5Spoint.c index 721211e..6948125 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -1413,6 +1413,9 @@ H5S__point_deserialize(H5S_t **space, const uint8_t **p) /* Decode version */ UINT32DECODE(pp, version); + if(version < H5S_POINT_VERSION_1 || version > H5S_POINT_VERSION_LATEST) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL, "bad version number for point selection") + if(version >= (uint32_t)H5S_POINT_VERSION_2) /* Decode size of point info */ enc_size = *(pp)++; @@ -301,6 +301,9 @@ /* Local Typedefs */ /******************/ +/* Typedef for recursive const-correct datatype copying routines */ +typedef H5T_t *(*H5T_copy_func_t)(H5T_t *old_dt); + /********************/ /* Local Prototypes */ @@ -313,6 +316,11 @@ static herr_t H5T__set_size(H5T_t *dt, size_t size); static herr_t H5T__close_cb(H5T_t *dt); static H5T_path_t *H5T__path_find_real(const H5T_t *src, const H5T_t *dst, const char *name, H5T_conv_func_t *conv); static hbool_t H5T__detect_vlen_ref(const H5T_t *dt); +static H5T_t *H5T__initiate_copy(const H5T_t *old_dt); +static H5T_t *H5T__copy_transient(H5T_t *old_dt); +static H5T_t *H5T__copy_all(H5T_t *old_dt); +static herr_t H5T__complete_copy(H5T_t *new_dt, const H5T_t *old_dt, + H5T_shared_t *reopened_fo, hbool_t set_memory_type, H5T_copy_func_t copyfn); /*****************************/ @@ -3304,132 +3312,152 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__create() */ - + /*------------------------------------------------------------------------- - * Function: H5T_copy + * Function: H5T__initiate_copy * - * Purpose: Copies datatype OLD_DT. The resulting data type is not - * locked and is a transient type. + * Purpose: Allocates datatype structures, copies core fields, and initializes + * VOL fields. * * Return: Success: Pointer to a new copy of the OLD_DT argument. - * * Failure: NULL * - * Programmer: Robb Matzke - * Thursday, December 4, 1997 + * Note: Common code for both H5T_copy and H5T_copy_reopen, as part of + * the const-correct datatype copying routines. + * + * Programmer: David Young + * January 18, 2020 * *------------------------------------------------------------------------- */ -H5T_t * -H5T_copy(H5T_t *old_dt, H5T_copy_t method) +static H5T_t * +H5T__initiate_copy(const H5T_t *old_dt) { - H5T_t *new_dt = NULL, *tmp = NULL; - H5T_shared_t *reopened_fo = NULL; - unsigned i; - char *s; - H5T_t *ret_value = NULL; /* Return value */ - - FUNC_ENTER_NOAPI(NULL) + H5T_t *new_dt = NULL; /* Copy of datatype */ + H5T_t *ret_value = NULL; /* Return value */ - /* check args */ - HDassert(old_dt); + FUNC_ENTER_STATIC /* Allocate space */ if(NULL == (new_dt = H5FL_MALLOC(H5T_t))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "H5T_t memory allocation failed") if(NULL == (new_dt->shared = H5FL_MALLOC(H5T_shared_t))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "H5T_shared_t memory allocation failed") - /* Copy shared information (entry information is copied last) */ + /* Copy shared information */ *(new_dt->shared) = *(old_dt->shared); - /* No VOL object */ + /* Reset VOL fields */ new_dt->vol_obj = NULL; - - /* No owned VOL object */ new_dt->shared->owned_vol_obj = NULL; - /* Check what sort of copy we are making */ - switch (method) { - case H5T_COPY_TRANSIENT: - /* - * Return an unlocked transient type. - */ - new_dt->shared->state = H5T_STATE_TRANSIENT; - break; + /* Set return value */ + ret_value = new_dt; - case H5T_COPY_ALL: - /* - * Return a transient type (locked or unlocked) or an unopened named - * type. Immutable transient types are degraded to read-only. - */ - if(H5T_STATE_OPEN==old_dt->shared->state) - new_dt->shared->state = H5T_STATE_NAMED; - else if(H5T_STATE_IMMUTABLE==old_dt->shared->state) - new_dt->shared->state = H5T_STATE_RDONLY; - break; +done: + if(ret_value == NULL) + if(new_dt) { + if(new_dt->shared) + new_dt->shared = H5FL_FREE(H5T_shared_t, new_dt->shared); + new_dt = H5FL_FREE(H5T_t, new_dt); + } /* end if */ - case H5T_COPY_REOPEN: - /* - * Return a transient type (locked or unlocked) or an opened named - * type. Immutable transient types are degraded to read-only. - */ - if(old_dt->sh_loc.type == H5O_SHARE_TYPE_COMMITTED) { - /* Check if the object is already open */ - if(NULL == (reopened_fo = (H5T_shared_t *)H5FO_opened(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr))) { - /* Clear any errors from H5FO_opened() */ - H5E_clear_stack(NULL); + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__initiate_copy() */ - /* Open named datatype again */ - if(H5O_open(&old_dt->oloc) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to reopen named data type") + +/*------------------------------------------------------------------------- + * Function: H5T__copy_transient + * + * Purpose: Part of recursive framework for const-correct datatype copying. + * + * Return: Success: Pointer to a new copy of the OLD_DT argument. + * Failure: NULL + * + * Programmer: David Young + * January 18, 2020 + * + *------------------------------------------------------------------------- + */ +static H5T_t * +H5T__copy_transient(H5T_t *old_dt) +{ + H5T_t *ret_value = NULL; /* Return value */ - /* Insert opened named datatype into opened object list for the file */ - if(H5FO_insert(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr, new_dt->shared, FALSE)<0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, NULL, "can't insert datatype into list of open objects") + FUNC_ENTER_STATIC - /* Increment object count for the object in the top file */ - if(H5FO_top_incr(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, NULL, "can't increment object count") + /* Copy datatype, with correct method */ + if(NULL == (ret_value = H5T_copy(old_dt, H5T_COPY_TRANSIENT))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't make 'transient' copy of datatype") - new_dt->shared->fo_count = 1; - } /* end if */ - else { - /* The object is already open. Free the H5T_shared_t struct - * we had been using and use the one that already exists. - * Not terribly efficient. */ - new_dt->shared = H5FL_FREE(H5T_shared_t, new_dt->shared); - new_dt->shared = reopened_fo; - - reopened_fo->fo_count++; - - /* Check if the object has been opened through the top file yet */ - if(H5FO_top_count(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr) == 0) { - /* Open the object through this top file */ - if(H5O_open(&old_dt->oloc) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to open object header") - } /* end if */ +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__copy_transient() */ - /* Increment object count for the object in the top file */ - if(H5FO_top_incr(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, NULL, "can't increment object count") - } /* end else */ - new_dt->shared->state = H5T_STATE_OPEN; - } - else if(H5T_STATE_IMMUTABLE == old_dt->shared->state) { - new_dt->shared->state = H5T_STATE_RDONLY; - } - break; - default: - HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, NULL, "invalid copy method type") - } /* end switch */ + +/*------------------------------------------------------------------------- + * Function: H5T__copy_all + * + * Purpose: Part of recursive framework for const-correct datatype copying. + * + * Return: Success: Pointer to a new copy of the OLD_DT argument. + * Failure: NULL + * + * Programmer: David Young + * January 18, 2020 + * + *------------------------------------------------------------------------- + */ +static H5T_t * +H5T__copy_all(H5T_t *old_dt) +{ + H5T_t *ret_value = NULL; /* Return value */ + + FUNC_ENTER_STATIC + + /* Copy datatype, with correct method */ + if(NULL == (ret_value = H5T_copy(old_dt, H5T_COPY_ALL))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't make 'all' copy of datatype") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__copy_transient() */ + + +/*------------------------------------------------------------------------- + * Function: H5T__complete_copy + * + * Purpose: Completes copying datatype fields, as part of the recursive + * const-correct datatype copy routines. + * + * Return: Success: non-negative + * Failure: negative + * + * Note: Common code for both H5T_copy and H5T_copy_reopen. + * + * Programmer: David Young + * January 18, 2020 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5T__complete_copy(H5T_t *new_dt, const H5T_t *old_dt, H5T_shared_t *reopened_fo, + hbool_t set_memory_type, H5T_copy_func_t copyfn) +{ + H5T_t *tmp = NULL; /* Temporary copy of compound field's datatype */ + char *s; /* Temporary copy of compound field name / enum value name */ + unsigned i; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC /* Update fields in the new struct, if we aren't sharing an already opened * committed datatype */ if(!reopened_fo) { /* Copy parent information */ if(old_dt->shared->parent) - new_dt->shared->parent = H5T_copy(old_dt->shared->parent, method); + if(NULL == (new_dt->shared->parent = (*copyfn)(old_dt->shared->parent))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy datatype's parent type") switch(new_dt->shared->type) { case H5T_COMPOUND: @@ -3443,10 +3471,8 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) */ /* Only malloc if space has been allocated for members - NAF */ if(new_dt->shared->u.compnd.nalloc > 0) { - new_dt->shared->u.compnd.memb = - (H5T_cmemb_t *)H5MM_malloc(new_dt->shared->u.compnd.nalloc * sizeof(H5T_cmemb_t)); - if (NULL == new_dt->shared->u.compnd.memb) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if(NULL == (new_dt->shared->u.compnd.memb = H5MM_malloc(new_dt->shared->u.compnd.nalloc * sizeof(H5T_cmemb_t)))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "memory allocation failed") H5MM_memcpy(new_dt->shared->u.compnd.memb, old_dt->shared->u.compnd.memb, new_dt->shared->u.compnd.nmembs * sizeof(H5T_cmemb_t)); @@ -3456,15 +3482,17 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) unsigned j; int old_match; - s = new_dt->shared->u.compnd.memb[i].name; - new_dt->shared->u.compnd.memb[i].name = H5MM_xstrdup(s); - tmp = H5T_copy (old_dt->shared->u.compnd.memb[i].type, method); + if(NULL == (s = H5MM_xstrdup(new_dt->shared->u.compnd.memb[i].name))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy string for compound field's name") + new_dt->shared->u.compnd.memb[i].name = s; + if(NULL == (tmp = (*copyfn)(old_dt->shared->u.compnd.memb[i].type))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy compound field's datatype") new_dt->shared->u.compnd.memb[i].type = tmp; HDassert(tmp != NULL); /* Range check against compound member's offset */ - if ((accum_change < 0) && ((ssize_t) new_dt->shared->u.compnd.memb[i].offset < accum_change)) - HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, NULL, "invalid field size in datatype") + if((accum_change < 0) && ((ssize_t) new_dt->shared->u.compnd.memb[i].offset < accum_change)) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "invalid field size in datatype") /* Apply the accumulated size change to the offset of the field */ new_dt->shared->u.compnd.memb[i].offset += (size_t) accum_change; @@ -3479,7 +3507,7 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) /* check if we couldn't find a match */ if(old_match < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "fields in datatype corrupted") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "fields in datatype corrupted") } /* end if */ else old_match = (int) i; @@ -3494,8 +3522,8 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) } /* end for */ /* Range check against datatype size */ - if ((accum_change < 0) && ((ssize_t) new_dt->shared->size < accum_change)) - HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, NULL, "invalid field size in datatype") + if((accum_change < 0) && ((ssize_t) new_dt->shared->size < accum_change)) + HGOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "invalid field size in datatype") /* Apply the accumulated size change to the size of the compound struct */ new_dt->shared->size += (size_t) accum_change; @@ -3508,27 +3536,25 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) * of each new member with copied values. That is, H5T_copy() is a * deep copy. */ - new_dt->shared->u.enumer.name = - (char **)H5MM_malloc(new_dt->shared->u.enumer.nalloc * sizeof(char*)); - new_dt->shared->u.enumer.value = - (uint8_t *)H5MM_malloc(new_dt->shared->u.enumer.nalloc * new_dt->shared->size); - if(NULL == new_dt->shared->u.enumer.value) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + if(NULL == (new_dt->shared->u.enumer.name = H5MM_malloc(new_dt->shared->u.enumer.nalloc * sizeof(char*)))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "enam name array memory allocation failed") + if(NULL == (new_dt->shared->u.enumer.value = H5MM_malloc(new_dt->shared->u.enumer.nalloc * new_dt->shared->size))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "enam value array memory allocation failed") H5MM_memcpy(new_dt->shared->u.enumer.value, old_dt->shared->u.enumer.value, new_dt->shared->u.enumer.nmembs * new_dt->shared->size); for(i = 0; i < new_dt->shared->u.enumer.nmembs; i++) { - s = old_dt->shared->u.enumer.name[i]; - new_dt->shared->u.enumer.name[i] = H5MM_xstrdup(s); + if(NULL == (s = H5MM_xstrdup(old_dt->shared->u.enumer.name[i]))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy string for enum value's name") + new_dt->shared->u.enumer.name[i] = s; } /* end for */ break; case H5T_VLEN: case H5T_REFERENCE: - if(method == H5T_COPY_TRANSIENT || method == H5T_COPY_REOPEN) { + if(set_memory_type) /* H5T_copy converts any type into a memory type */ if(H5T_set_loc(new_dt, NULL, H5T_LOC_MEMORY) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid datatype location") - } /* end if */ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid datatype location") break; case H5T_OPAQUE: @@ -3540,7 +3566,7 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) case H5T_ARRAY: /* Re-compute the array's size, in case it's base type changed size */ - new_dt->shared->size=new_dt->shared->u.array.nelem*new_dt->shared->parent->shared->size; + new_dt->shared->size = new_dt->shared->u.array.nelem * new_dt->shared->parent->shared->size; break; case H5T_NO_CLASS: @@ -3559,15 +3585,15 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) * type and the new type is also named. */ if(H5O_loc_reset(&new_dt->oloc) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRESET, NULL, "unable to initialize location") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRESET, FAIL, "unable to initialize location") if(H5G_name_reset(&new_dt->path) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to reset path") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to reset path") if(new_dt->shared->state == H5T_STATE_NAMED || new_dt->shared->state == H5T_STATE_OPEN) { - if(H5O_loc_copy(&(new_dt->oloc), &(old_dt->oloc), H5_COPY_DEEP) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy object location") + if(H5O_loc_copy_deep(&(new_dt->oloc), &(old_dt->oloc)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy object location") if(H5G_name_copy(&(new_dt->path), &(old_dt->path), H5_COPY_DEEP) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to copy path") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to copy path") } /* end if */ /* Copy shared location information if the new type is named or if it is @@ -3576,28 +3602,194 @@ H5T_copy(H5T_t *old_dt, H5T_copy_t method) if((old_dt->sh_loc.type == H5O_SHARE_TYPE_SOHM || old_dt->sh_loc.type == H5O_SHARE_TYPE_HERE) || new_dt->shared->state == H5T_STATE_NAMED || new_dt->shared->state == H5T_STATE_OPEN) { if(H5O_set_shared(&(new_dt->sh_loc), &(old_dt->sh_loc)) < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy shared information") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, "can't copy shared information") } /* end if */ else /* Reset shared component info */ H5O_msg_reset_share(H5O_DTYPE_ID, new_dt); +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__complete_copy() */ + + +/*------------------------------------------------------------------------- + * Function: H5T_copy + * + * Purpose: Copies datatype OLD_DT. The resulting data type is not + * locked and is a transient type. + * + * Return: Success: Pointer to a new copy of the OLD_DT argument. + * Failure: NULL + * + * Programmer: Robb Matzke + * Thursday, December 4, 1997 + * + *------------------------------------------------------------------------- + */ +H5T_t * +H5T_copy(const H5T_t *old_dt, H5T_copy_t method) +{ + H5T_t *new_dt = NULL; /* New datatype */ + H5T_copy_func_t copyfn; /* Pointer to correct copy routine */ + H5T_t *ret_value = NULL; /* Return value */ + + FUNC_ENTER_NOAPI(NULL) + + /* check args */ + HDassert(old_dt); + + /* Allocate and copy core datatype information */ + if(NULL == (new_dt = H5T__initiate_copy(old_dt))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy core datatype info") + + /* Check what sort of copy we are making */ + switch (method) { + case H5T_COPY_TRANSIENT: + /* + * Return an unlocked transient type. + */ + new_dt->shared->state = H5T_STATE_TRANSIENT; + copyfn = H5T__copy_transient; + break; + + case H5T_COPY_ALL: + /* + * Return a transient type (locked or unlocked) or an unopened named + * type. Immutable transient types are degraded to read-only. + */ + if(H5T_STATE_OPEN==old_dt->shared->state) + new_dt->shared->state = H5T_STATE_NAMED; + else if(H5T_STATE_IMMUTABLE==old_dt->shared->state) + new_dt->shared->state = H5T_STATE_RDONLY; + copyfn = H5T__copy_all; + break; + + default: + HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, NULL, "invalid copy method type") + } /* end switch */ + + /* Finish making the copy of the datatype */ + if(H5T__complete_copy(new_dt, old_dt, NULL, (method == H5T_COPY_TRANSIENT), copyfn) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "can't complete datatype initialization") + /* Set return value */ ret_value = new_dt; done: - if(ret_value == NULL) { + if(ret_value == NULL) if(new_dt) { - if(new_dt->shared) - new_dt->shared = H5FL_FREE(H5T_shared_t, new_dt->shared); + HDassert(new_dt->shared); + new_dt->shared = H5FL_FREE(H5T_shared_t, new_dt->shared); new_dt = H5FL_FREE(H5T_t, new_dt); } /* end if */ - } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5T_copy() */ + +/*------------------------------------------------------------------------- + * Function: H5T_copy_reopen + * + * Purpose: Copy a datatype, possibly reopening a named datatype, as part + * the const-correct datatype copying routines. + * + * Return: Success: Pointer to a new copy of the OLD_DT argument. + * Failure: NULL + * + * Programmer: David Young + * January 18, 2020 + * + *------------------------------------------------------------------------- + */ +H5T_t * +H5T_copy_reopen(H5T_t *old_dt) +{ + H5T_t *new_dt = NULL; /* New datatype */ + H5T_shared_t *reopened_fo = NULL; /* Pointer to reopened existing named datatype */ + H5T_t *ret_value = NULL; /* Return value */ + + FUNC_ENTER_NOAPI(NULL) + + /* check args */ + HDassert(old_dt); + + /* Allocate and copy core datatype information */ + if(NULL == (new_dt = H5T__initiate_copy(old_dt))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy core datatype info") + + /* + * Return a transient type (locked or unlocked) or an opened named + * type. Immutable transient types are degraded to read-only. + */ + if(old_dt->sh_loc.type == H5O_SHARE_TYPE_COMMITTED) { + /* Check if the object is already open */ + if(NULL == (reopened_fo = (H5T_shared_t *)H5FO_opened(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr))) { + /* Clear any errors from H5FO_opened() */ + H5E_clear_stack(NULL); + + /* Open named datatype again */ + if(H5O_open(&old_dt->oloc) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to reopen named data type") + + /* Insert opened named datatype into opened object list for the file */ + if(H5FO_insert(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr, new_dt->shared, FALSE)<0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, NULL, "can't insert datatype into list of open objects") + + /* Increment object count for the object in the top file */ + if(H5FO_top_incr(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, NULL, "can't increment object count") + + new_dt->shared->fo_count = 1; + } /* end if */ + else { + /* The object is already open. Free the H5T_shared_t struct + * we had been using and use the one that already exists. + * Not terribly efficient. */ + new_dt->shared = H5FL_FREE(H5T_shared_t, new_dt->shared); + new_dt->shared = reopened_fo; + + reopened_fo->fo_count++; + + /* Check if the object has been opened through the top file yet */ + if(H5FO_top_count(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr) == 0) { + /* Open the object through this top file */ + if(H5O_open(&old_dt->oloc) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, NULL, "unable to open object header") + } /* end if */ + + /* Increment object count for the object in the top file */ + if(H5FO_top_incr(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINC, NULL, "can't increment object count") + } /* end else */ + + /* Set state for new datatype */ + new_dt->shared->state = H5T_STATE_OPEN; + } /* end if */ + else + /* Downgrade immutable datatypes to read-only */ + if(H5T_STATE_IMMUTABLE == old_dt->shared->state) + new_dt->shared->state = H5T_STATE_RDONLY; + + /* Finish making the copy of the datatype */ + if(H5T__complete_copy(new_dt, old_dt, reopened_fo, TRUE, H5T_copy_reopen) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "can't complete datatype initialization") + + /* Set return value */ + ret_value = new_dt; + +done: + if(ret_value == NULL) + if(new_dt) { + HDassert(new_dt->shared); + new_dt->shared = H5FL_FREE(H5T_shared_t, new_dt->shared); + new_dt = H5FL_FREE(H5T_t, new_dt); + } /* end if */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T_copy_reopen() */ + /*------------------------------------------------------------------------- * Function: H5T_lock * @@ -300,7 +300,7 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) if (ret_value) return ret_value; - if(mutex->lock_count && pthread_equal(HDpthread_self(), mutex->owner_thread)) { + if(mutex->lock_count && pthread_equal(pthread_self(), mutex->owner_thread)) { /* already owned by self - increment count */ mutex->lock_count++; } else { @@ -309,7 +309,7 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex) pthread_cond_wait(&mutex->cond_var, &mutex->atomic_lock); /* After we've received the signal, take ownership of the mutex */ - mutex->owner_thread = HDpthread_self(); + mutex->owner_thread = pthread_self(); mutex->lock_count = 1; } @@ -677,13 +677,4 @@ H5TS_create_thread(void *(*func)(void *), H5TS_attr_t *attr, void *udata) } /* H5TS_create_thread */ -#else /* H5_HAVE_THREADSAFE */ - -uint64_t -H5TS_thread_id(void) -{ - return 0; -} - #endif /* H5_HAVE_THREADSAFE */ - diff --git a/src/H5Tcommit.c b/src/H5Tcommit.c index 1b922d5..7d26af3 100644 --- a/src/H5Tcommit.c +++ b/src/H5Tcommit.c @@ -446,7 +446,7 @@ H5T__commit(H5F_t *file, H5T_t *type, hid_t tcpl_id) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to update type header message") /* Copy the new object header's location into the datatype, taking ownership of it */ - if(H5O_loc_copy(&(type->oloc), &temp_oloc, H5_COPY_SHALLOW) < 0) + if(H5O_loc_copy_shallow(&(type->oloc), &temp_oloc) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy datatype location") if(H5G_name_copy(&(type->path), &temp_path, H5_COPY_SHALLOW) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy datatype location") @@ -943,7 +943,7 @@ H5T_open(const H5G_loc_t *loc) #endif /* H5_USING_MEMCHECKER */ /* Shallow copy (take ownership) of the object location object */ - if(H5O_loc_copy(&dt->oloc, loc->oloc, H5_COPY_SHALLOW) < 0) + if(H5O_loc_copy_shallow(&dt->oloc, loc->oloc) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy object location") /* Shallow copy (take ownership) of the group hier. path */ @@ -1033,7 +1033,7 @@ H5T__open_oid(const H5G_loc_t *loc) dt->shared->state = H5T_STATE_OPEN; /* Shallow copy (take ownership) of the object location object */ - if(H5O_loc_copy(&dt->oloc, loc->oloc, H5_COPY_SHALLOW) < 0) + if(H5O_loc_copy_shallow(&dt->oloc, loc->oloc) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy object location") /* Shallow copy (take ownership) of the group hier. path */ diff --git a/src/H5Tcompound.c b/src/H5Tcompound.c index d4f1008..f4a9e04 100644 --- a/src/H5Tcompound.c +++ b/src/H5Tcompound.c @@ -51,8 +51,9 @@ /********************/ /* Local Prototypes */ /********************/ -static herr_t H5T_pack(const H5T_t *dt); -static htri_t H5T_is_packed(const H5T_t *dt); +static herr_t H5T__pack(const H5T_t *dt); +static htri_t H5T__is_packed(const H5T_t *dt); +static H5T_t *H5T__reopen_member_type(const H5T_t *dt, unsigned membno); /*********************/ @@ -226,7 +227,7 @@ H5Tget_member_type(hid_t type_id, unsigned membno) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5I_INVALID_HID, "invalid member number") /* Retrieve the datatype for the member */ - if(NULL == (memb_dt = H5T_get_member_type(dt, membno, H5T_COPY_REOPEN))) + if(NULL == (memb_dt = H5T__reopen_member_type(dt, membno))) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, H5I_INVALID_HID, "unable to retrieve member type") /* Get an ID for the datatype */ @@ -245,8 +246,7 @@ done: /*------------------------------------------------------------------------- * Function: H5T_get_member_type * - * Purpose: Private function for H5Tget_member_type. Returns the data - * type of the specified member. + * Purpose: Returns a copy of the data type of the specified member. * * Return: Success: A copy of the member datatype; * modifying the returned datatype does not @@ -260,18 +260,19 @@ done: *------------------------------------------------------------------------- */ H5T_t * -H5T_get_member_type(const H5T_t *dt, unsigned membno, H5T_copy_t method) +H5T_get_member_type(const H5T_t *dt, unsigned membno) { H5T_t *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI(NULL) + /* Sanity checks */ HDassert(dt); HDassert(membno < dt->shared->u.compnd.nmembs); - /* Copy datatype into an atom */ - if(NULL == (ret_value = H5T_copy(dt->shared->u.compnd.memb[membno].type, method))) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy member datatype") + /* Copy datatype */ + if(NULL == (ret_value = H5T_copy(dt->shared->u.compnd.memb[membno].type, H5T_COPY_TRANSIENT))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "unable to copy member datatype") done: FUNC_LEAVE_NOAPI(ret_value) @@ -279,6 +280,43 @@ done: /*------------------------------------------------------------------------- + * Function: H5T__reopen_member_type + * + * Purpose: Private function for H5Tget_member_type. Returns a re-opened + * copy of the data type of the specified member. + * + * Return: Success: A copy of the member datatype; + * modifying the returned datatype does not + * modify the member type. + * + * Failure: NULL + * + * Programmer: David Young + * January 18, 2020 + * + *------------------------------------------------------------------------- + */ +static H5T_t * +H5T__reopen_member_type(const H5T_t *dt, unsigned membno) +{ + H5T_t *ret_value = NULL; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity checks */ + HDassert(dt); + HDassert(membno < dt->shared->u.compnd.nmembs); + + /* Copy datatype, possibly re-opening it */ + if(NULL == (ret_value = H5T_copy_reopen(dt->shared->u.compnd.memb[membno].type))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "unable to reopen member datatype") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T__reopen_member_type() */ + + +/*------------------------------------------------------------------------- * Function: H5T__get_member_size * * Purpose: Returns the size of the specified member. @@ -387,7 +425,7 @@ H5Tpack(hid_t type_id) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound datatype") /* Pack */ - if(H5T_pack(dt) < 0) + if(H5T__pack(dt) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack compound datatype") done: @@ -493,7 +531,7 @@ done: /*------------------------------------------------------------------------- - * Function: H5T_pack + * Function: H5T__pack * * Purpose: Recursively packs a compound datatype by removing padding * bytes. This is done in place (that is, destructively). @@ -506,17 +544,17 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5T_pack(const H5T_t *dt) +H5T__pack(const H5T_t *dt) { herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_STATIC HDassert(dt); if(H5T_detect_class(dt, H5T_COMPOUND, FALSE) > 0) { /* If datatype has been packed, skip packing it and indicate success */ - if(TRUE == H5T_is_packed(dt)) + if(TRUE == H5T__is_packed(dt)) HGOTO_DONE(SUCCEED) /* Check for packing unmodifiable datatype */ @@ -524,7 +562,7 @@ H5T_pack(const H5T_t *dt) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "datatype is read-only") if(dt->shared->parent) { - if (H5T_pack(dt->shared->parent) < 0) + if(H5T__pack(dt->shared->parent) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack parent of datatype") /* Adjust size of datatype appropriately */ @@ -539,7 +577,7 @@ H5T_pack(const H5T_t *dt) /* Recursively pack the members */ for(i = 0; i < dt->shared->u.compnd.nmembs; i++) { - if(H5T_pack(dt->shared->u.compnd.memb[i].type) < 0) + if(H5T__pack(dt->shared->u.compnd.memb[i].type) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack part of a compound datatype") /* Update the member size */ @@ -552,7 +590,7 @@ H5T_pack(const H5T_t *dt) for(i = 0, offset = 0; i < dt->shared->u.compnd.nmembs; i++) { dt->shared->u.compnd.memb[i].offset = offset; offset += dt->shared->u.compnd.memb[i].size; - } + } /* end for */ /* Change total size */ dt->shared->size = MAX(1, offset); @@ -564,11 +602,11 @@ H5T_pack(const H5T_t *dt) done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_pack() */ +} /* end H5T__pack() */ /*------------------------------------------------------------------------- - * Function: H5T_is_packed + * Function: H5T__is_packed * * Purpose: Checks whether a datatype which is compound (or has compound * components) is packed. @@ -583,11 +621,11 @@ done: *------------------------------------------------------------------------- */ static htri_t -H5T_is_packed(const H5T_t *dt) +H5T__is_packed(const H5T_t *dt) { htri_t ret_value = TRUE; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT_NOERR + FUNC_ENTER_STATIC_NOERR HDassert(dt); @@ -596,12 +634,11 @@ H5T_is_packed(const H5T_t *dt) dt = dt->shared->parent; /* If this is a compound datatype, check if it is packed */ - if(dt->shared->type == H5T_COMPOUND) { + if(dt->shared->type == H5T_COMPOUND) ret_value = (htri_t)(dt->shared->u.compnd.packed); - } /* end if */ FUNC_LEAVE_NOAPI(ret_value) -} /* end H5T_is_packed() */ +} /* end H5T__is_packed() */ /*------------------------------------------------------------------------- @@ -638,7 +675,7 @@ H5T__update_packed(const H5T_t *dt) /* Now check if all members are packed */ for(i = 0; i < dt->shared->u.compnd.nmembs; i++) - if(!H5T_is_packed(dt->shared->u.compnd.memb[i].type)) { + if(!H5T__is_packed(dt->shared->u.compnd.memb[i].type)) { dt->shared->u.compnd.packed = FALSE; break; } /* end if */ diff --git a/src/H5Tconv.c b/src/H5Tconv.c index 29fd582..2b1283e 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -3213,7 +3213,7 @@ H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, * necessary. If the SEQ_LEN is 0, allocate a minimal size buffer. */ if(!seq_len && !conv_buf) { - conv_buf_size = ((1 / H5T_VLEN_MIN_CONF_BUF_SIZE) + 1) * H5T_VLEN_MIN_CONF_BUF_SIZE; + conv_buf_size = H5T_VLEN_MIN_CONF_BUF_SIZE; if(NULL == (conv_buf = H5FL_BLK_CALLOC(vlen_seq, conv_buf_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion") } /* end if */ diff --git a/src/H5Tnative.c b/src/H5Tnative.c index 8859102..357bb08 100644 --- a/src/H5Tnative.c +++ b/src/H5Tnative.c @@ -272,7 +272,7 @@ H5T__get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_ali /* Construct child compound type and retrieve a list of their IDs, offsets, total size, and alignment for compound type. */ for(u = 0; u < nmemb; u++) { - if(NULL == (memb_type = H5T_get_member_type(dtype, u, H5T_COPY_TRANSIENT))) + if(NULL == (memb_type = H5T_get_member_type(dtype, u))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "member type retrieval failed") if(NULL == (comp_mname[u] = H5T__get_member_name(dtype, u))) diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h index d8e98af..e05bb4e 100644 --- a/src/H5Tprivate.h +++ b/src/H5Tprivate.h @@ -59,7 +59,6 @@ struct H5S_t; typedef enum H5T_copy_t { H5T_COPY_TRANSIENT, H5T_COPY_ALL, - H5T_COPY_REOPEN } H5T_copy_t; /* Location of datatype information */ @@ -109,7 +108,8 @@ H5_DLLVAR H5T_order_t H5T_native_order_g; /* Private functions */ H5_DLL herr_t H5T_init(void); -H5_DLL H5T_t *H5T_copy(H5T_t *old_dt, H5T_copy_t method); +H5_DLL H5T_t *H5T_copy(const H5T_t *old_dt, H5T_copy_t method); +H5_DLL H5T_t *H5T_copy_reopen(H5T_t *old_dt); H5_DLL herr_t H5T_lock(H5T_t *dt, hbool_t immutable); H5_DLL herr_t H5T_close(H5T_t *dt); H5_DLL herr_t H5T_close_real(H5T_t *dt); @@ -164,7 +164,7 @@ H5_DLL herr_t H5T_update_shared(H5T_t *type); /* Field functions (for both compound & enumerated types) */ H5_DLL int H5T_get_nmembers(const H5T_t *dt); -H5_DLL H5T_t *H5T_get_member_type(const H5T_t *dt, unsigned membno, H5T_copy_t method); +H5_DLL H5T_t *H5T_get_member_type(const H5T_t *dt, unsigned membno); H5_DLL size_t H5T_get_member_offset(const H5T_t *dt, unsigned membno); /* Atomic functions */ diff --git a/src/H5VLconnector.h b/src/H5VLconnector.h index baa4cca..7951a32 100644 --- a/src/H5VLconnector.h +++ b/src/H5VLconnector.h @@ -91,7 +91,6 @@ typedef int H5VL_attr_optional_t; typedef enum H5VL_dataset_get_t { H5VL_DATASET_GET_DAPL, /* access property list */ H5VL_DATASET_GET_DCPL, /* creation property list */ - H5VL_DATASET_GET_OFFSET, /* offset */ H5VL_DATASET_GET_SPACE, /* dataspace */ H5VL_DATASET_GET_SPACE_STATUS, /* space status */ H5VL_DATASET_GET_STORAGE_SIZE, /* storage size */ @@ -195,7 +194,7 @@ typedef enum H5VL_object_get_t { H5VL_OBJECT_GET_FILE, /* object file */ H5VL_OBJECT_GET_NAME, /* object name */ H5VL_OBJECT_GET_TYPE, /* object type */ - H5VL_OBJECT_GET_INFO /* H5Oget_info(_by_idx|name)3 */ + H5VL_OBJECT_GET_INFO /* H5Oget_info(_by_idx|name) */ } H5VL_object_get_t; /* types for object SPECIFIC callback */ diff --git a/src/H5VLint.c b/src/H5VLint.c index 6572faa..861629f 100644 --- a/src/H5VLint.c +++ b/src/H5VLint.c @@ -273,7 +273,7 @@ H5VL_term_package(void) else { if(H5I_nmembers(H5I_VOL) > 0) { /* Unregister all VOL connectors */ - (void)H5I_clear_type(H5I_VOL, FALSE, FALSE); + (void)H5I_clear_type(H5I_VOL, TRUE, FALSE); n++; } /* end if */ else { diff --git a/src/H5VLnative.h b/src/H5VLnative.h index e1f3f93..b607abc 100644 --- a/src/H5VLnative.h +++ b/src/H5VLnative.h @@ -48,6 +48,7 @@ #define H5VL_NATIVE_DATASET_CHUNK_READ 6 /* H5Dchunk_read */ #define H5VL_NATIVE_DATASET_CHUNK_WRITE 7 /* H5Dchunk_write */ #define H5VL_NATIVE_DATASET_GET_VLEN_BUF_SIZE 8 /* H5Dvlen_get_buf_size */ +#define H5VL_NATIVE_DATASET_GET_OFFSET 9 /* H5Dget_offset */ /* Values for native VOL connector file optional VOL operations */ #define H5VL_NATIVE_FILE_CLEAR_ELINK_CACHE 0 /* H5Fclear_elink_file_cache */ diff --git a/src/H5VLnative_attr.c b/src/H5VLnative_attr.c index e54c49f..8072cd5 100644 --- a/src/H5VLnative_attr.c +++ b/src/H5VLnative_attr.c @@ -525,7 +525,8 @@ done: */ herr_t H5VL__native_attr_optional(void H5_ATTR_UNUSED *obj, H5VL_attr_optional_t opt_type, - hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req, va_list arguments) + hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req, + va_list H5_ATTR_DEPRECATED_USED arguments) { herr_t ret_value = SUCCEED; /* Return value */ diff --git a/src/H5VLnative_dataset.c b/src/H5VLnative_dataset.c index bea2c50..8660e80 100644 --- a/src/H5VLnative_dataset.c +++ b/src/H5VLnative_dataset.c @@ -297,18 +297,6 @@ H5VL__native_dataset_get(void *obj, H5VL_dataset_get_t get_type, break; } - /* H5Dget_offset */ - case H5VL_DATASET_GET_OFFSET: - { - haddr_t *ret = HDva_arg(arguments, haddr_t *); - - /* Set return value */ - *ret = H5D__get_offset(dset); - if(!H5F_addr_defined(*ret)) - *ret = HADDR_UNDEF; - break; - } - default: HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from dataset") } /* end switch */ @@ -391,16 +379,17 @@ herr_t H5VL__native_dataset_optional(void *obj, H5VL_dataset_optional_t optional_type, hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req, va_list arguments) { - H5D_t *dset = NULL; /* Dataset */ - herr_t ret_value = SUCCEED; /* Return value */ + H5D_t *dset = (H5D_t *)obj; /* Dataset */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE + /* Sanity checks */ + HDassert(dset); + switch(optional_type) { case H5VL_NATIVE_DATASET_FORMAT_CONVERT: { /* H5Dformat_convert */ - dset = (H5D_t *)obj; - switch(dset->shared->layout.type) { case H5D_CHUNKED: /* Convert the chunk indexing type to version 1 B-tree if not */ @@ -436,8 +425,6 @@ H5VL__native_dataset_optional(void *obj, H5VL_dataset_optional_t optional_type, { /* H5Dget_chunk_index_type */ H5D_chunk_index_t *idx_type = HDva_arg(arguments, H5D_chunk_index_t *); - dset = (H5D_t *)obj; - /* Make sure the dataset is chunked */ if(H5D_CHUNKED != dset->shared->layout.type) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset") @@ -453,8 +440,6 @@ H5VL__native_dataset_optional(void *obj, H5VL_dataset_optional_t optional_type, hsize_t *offset = HDva_arg(arguments, hsize_t *); hsize_t *chunk_nbytes = HDva_arg(arguments, hsize_t *); - dset = (H5D_t *)obj; - /* Make sure the dataset is chunked */ if(H5D_CHUNKED != dset->shared->layout.type) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset") @@ -472,8 +457,6 @@ H5VL__native_dataset_optional(void *obj, H5VL_dataset_optional_t optional_type, hid_t space_id = HDva_arg(arguments, hid_t); hsize_t *nchunks = HDva_arg(arguments, hsize_t *); - dset = (H5D_t *)obj; - HDassert(dset); HDassert(dset->shared); HDassert(dset->shared->space); @@ -505,8 +488,6 @@ H5VL__native_dataset_optional(void *obj, H5VL_dataset_optional_t optional_type, haddr_t *addr = HDva_arg(arguments, haddr_t *); hsize_t *size = HDva_arg(arguments, hsize_t *); - dset = (H5D_t *)obj; - HDassert(dset); HDassert(dset->shared); HDassert(dset->shared->space); @@ -534,8 +515,6 @@ H5VL__native_dataset_optional(void *obj, H5VL_dataset_optional_t optional_type, haddr_t *addr = HDva_arg(arguments, haddr_t *); hsize_t *size = HDva_arg(arguments, hsize_t *); - dset = (H5D_t *)obj; - HDassert(dset); HDassert(dset->shared); /* Make sure the dataset is chunked */ @@ -556,8 +535,6 @@ H5VL__native_dataset_optional(void *obj, H5VL_dataset_optional_t optional_type, void *buf = HDva_arg(arguments, void *); hsize_t offset_copy[H5O_LAYOUT_NDIMS]; /* Internal copy of chunk offset */ - dset = (H5D_t *)obj; - /* Check arguments */ if(NULL == dset->oloc.file) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dataset is not associated with a file") @@ -585,8 +562,6 @@ H5VL__native_dataset_optional(void *obj, H5VL_dataset_optional_t optional_type, const void *buf = HDva_arg(arguments, const void *); hsize_t offset_copy[H5O_LAYOUT_NDIMS]; /* Internal copy of chunk offset */ - dset = (H5D_t *)obj; - /* Check arguments */ if(NULL == dset->oloc.file) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dataset is not associated with a file") @@ -612,13 +587,22 @@ H5VL__native_dataset_optional(void *obj, H5VL_dataset_optional_t optional_type, hid_t space_id = HDva_arg(arguments, hid_t); hsize_t *size = HDva_arg(arguments, hsize_t *); - dset = (H5D_t *)obj; - if(H5D__vlen_get_buf_size(dset, type_id, space_id, size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get size of vlen buf needed") break; } + /* H5Dget_offset */ + case H5VL_NATIVE_DATASET_GET_OFFSET: + { + haddr_t *ret = HDva_arg(arguments, haddr_t *); + + /* Set return value */ + *ret = H5D__get_offset(dset); + if(!H5F_addr_defined(*ret)) + *ret = HADDR_UNDEF; + break; + } default: HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid optional operation") diff --git a/src/H5VLnative_group.c b/src/H5VLnative_group.c index 3fdb2d9..236ee9d 100644 --- a/src/H5VLnative_group.c +++ b/src/H5VLnative_group.c @@ -266,8 +266,9 @@ done: *------------------------------------------------------------------------- */ herr_t -H5VL__native_group_optional(void *obj, H5VL_group_optional_t optional_type, - hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req, va_list arguments) +H5VL__native_group_optional(void H5_ATTR_UNUSED *obj, + H5VL_group_optional_t optional_type, hid_t H5_ATTR_UNUSED dxpl_id, + void H5_ATTR_UNUSED **req, va_list H5_ATTR_DEPRECATED_USED arguments) { herr_t ret_value = SUCCEED; /* Return value */ diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c index 8b3dc62..2cf470e 100644 --- a/src/H5VLpassthru.c +++ b/src/H5VLpassthru.c @@ -1591,6 +1591,10 @@ H5VL_pass_through_file_create(const char *name, unsigned flags, hid_t fcpl_id, /* Get copy of our VOL info from FAPL */ H5Pget_vol_info(fapl_id, (void **)&info); + /* Make sure we have info about the underlying VOL to be used */ + if (!info) + return NULL; + /* Copy the FAPL */ under_fapl_id = H5Pcopy(fapl_id); @@ -1645,6 +1649,10 @@ H5VL_pass_through_file_open(const char *name, unsigned flags, hid_t fapl_id, /* Get copy of our VOL info from FAPL */ H5Pget_vol_info(fapl_id, (void **)&info); + /* Make sure we have info about the underlying VOL to be used */ + if (!info) + return NULL; + /* Copy the FAPL */ under_fapl_id = H5Pcopy(fapl_id); @@ -1785,6 +1793,10 @@ H5VL_pass_through_file_specific(void *file, H5VL_file_specific_t specific_type, /* Get copy of our VOL info from FAPL */ H5Pget_vol_info(fapl_id, (void **)&info); + /* Make sure we have info about the underlying VOL to be used */ + if (!info) + return (-1); + /* Copy the FAPL */ under_fapl_id = H5Pcopy(fapl_id); @@ -585,7 +585,8 @@ done: *------------------------------------------------------------------------- */ static int -H5Z__flush_file_cb(void *obj_ptr, hid_t H5_ATTR_UNUSED obj_id, void *key) +H5Z__flush_file_cb(void *obj_ptr, hid_t H5_ATTR_UNUSED obj_id, + void *key H5_ATTR_PARALLEL_USED) { H5F_t *f = (H5F_t *)obj_ptr; /* File object for operations */ #ifdef H5_HAVE_PARALLEL diff --git a/src/H5Znbit.c b/src/H5Znbit.c index fe0041c..2f79725 100644 --- a/src/H5Znbit.c +++ b/src/H5Znbit.c @@ -338,7 +338,7 @@ H5Z_calc_parms_compound(const H5T_t *type, size_t *cd_values_actual_nparms) H5T_class_t dtype_member_class; /* Compound datatype's member datatype's class */ /* Get member datatype */ - if(NULL == (dtype_member = H5T_get_member_type(type, u, H5T_COPY_TRANSIENT))) + if(NULL == (dtype_member = H5T_get_member_type(type, u))) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad member datatype") /* Get member datatype's class */ @@ -695,7 +695,7 @@ H5Z_set_parms_compound(const H5T_t *type, unsigned *cd_values_index, /* For each member, set parameters */ for(u = 0; u < nmembers; u++) { /* Get member datatype */ - if(NULL == (dtype_member = H5T_get_member_type(type, u, H5T_COPY_TRANSIENT))) + if(NULL == (dtype_member = H5T_get_member_type(type, u))) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad member datatype") /* Get member datatype's class */ diff --git a/src/H5private.h b/src/H5private.h index f0f3687..f570723 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -304,17 +304,38 @@ * file). Be sure to update that file if the #ifdefs change here. */ #ifdef __cplusplus -# define H5_ATTR_FORMAT(X,Y,Z) /*void*/ -# define H5_ATTR_UNUSED /*void*/ -# define H5_ATTR_NDEBUG_UNUSED /*void*/ -# define H5_ATTR_NORETURN /*void*/ -# define H5_ATTR_CONST /*void*/ -# define H5_ATTR_PURE /*void*/ -# define H5_ATTR_FALLTHROUGH /*void*/ +# define H5_ATTR_FORMAT(X,Y,Z) /*void*/ +# define H5_ATTR_UNUSED /*void*/ +# define H5_ATTR_DEPRECATED_USED /*void*/ +# define H5_ATTR_NDEBUG_UNUSED /*void*/ +# define H5_ATTR_DEBUG_API_USED /*void*/ +# define H5_ATTR_PARALLEL_UNUSED /*void*/ +# define H5_ATTR_PARALLEL_USED /*void*/ +# define H5_ATTR_NORETURN /*void*/ +# define H5_ATTR_CONST /*void*/ +# define H5_ATTR_PURE /*void*/ +# define H5_ATTR_FALLTHROUGH /*void*/ #else /* __cplusplus */ #if defined(H5_HAVE_ATTRIBUTE) && !defined(__SUNPRO_C) # define H5_ATTR_FORMAT(X,Y,Z) __attribute__((format(X, Y, Z))) # define H5_ATTR_UNUSED __attribute__((unused)) +#ifdef H5_HAVE_PARALLEL +# define H5_ATTR_PARALLEL_UNUSED __attribute__((unused)) +# define H5_ATTR_PARALLEL_USED /*void*/ +#else +# define H5_ATTR_PARALLEL_UNUSED /*void*/ +# define H5_ATTR_PARALLEL_USED __attribute__((unused)) +#endif +#ifdef H5_NO_DEPRECATED_SYMBOLS +#define H5_ATTR_DEPRECATED_USED H5_ATTR_UNUSED +#else /* H5_NO_DEPRECATED_SYMBOLS */ +#define H5_ATTR_DEPRECATED_USED /*void*/ +#endif /* H5_NO_DEPRECATED_SYMBOLS */ +#ifdef H5_DEBUG_API +#define H5_ATTR_DEBUG_API_USED /*void*/ +#else /* H5_DEBUG_API */ +#define H5_ATTR_DEBUG_API_USED H5_ATTR_UNUSED +#endif /* H5_DEBUG_API */ #ifndef NDEBUG #define H5_ATTR_NDEBUG_UNUSED /*void*/ #else /* NDEBUG */ @@ -329,13 +350,17 @@ # define H5_ATTR_FALLTHROUGH /*void*/ #endif #else -# define H5_ATTR_FORMAT(X,Y,Z) /*void*/ -# define H5_ATTR_UNUSED /*void*/ -# define H5_ATTR_NDEBUG_UNUSED /*void*/ -# define H5_ATTR_NORETURN /*void*/ -# define H5_ATTR_CONST /*void*/ -# define H5_ATTR_PURE /*void*/ -# define H5_ATTR_FALLTHROUGH /*void*/ +# define H5_ATTR_FORMAT(X,Y,Z) /*void*/ +# define H5_ATTR_UNUSED /*void*/ +# define H5_ATTR_NDEBUG_UNUSED /*void*/ +# define H5_ATTR_DEBUG_API_USED /*void*/ +# define H5_ATTR_DEPRECATED_USED /*void*/ +# define H5_ATTR_PARALLEL_UNUSED /*void*/ +# define H5_ATTR_PARALLEL_USED /*void*/ +# define H5_ATTR_NORETURN /*void*/ +# define H5_ATTR_CONST /*void*/ +# define H5_ATTR_PURE /*void*/ +# define H5_ATTR_FALLTHROUGH /*void*/ #endif #endif /* __cplusplus */ @@ -1545,10 +1570,6 @@ extern char *strdup(const char *s); #define HDstrdup(S) strdup(S) #endif /* HDstrdup */ -#ifndef HDpthread_self - #define HDpthread_self() pthread_self() -#endif /* HDpthread_self */ - /* Macro for "stringizing" an integer in the C preprocessor (use H5_TOSTRING) */ /* (use H5_TOSTRING, H5_STRINGIZE is just part of the implementation) */ #define H5_STRINGIZE(x) #x @@ -1897,12 +1918,11 @@ H5_DLL double H5_trace(const double *calltime, const char *func, const char *typ /* global library version information string */ extern char H5_lib_vers_info_g[]; +#include "H5TSprivate.h" + /* Lock headers */ #ifdef H5_HAVE_THREADSAFE -/* Include required thread-safety header */ -#include "H5TSprivate.h" - /* replacement structure for original global variable */ typedef struct H5_api_struct { H5TS_mutex_t init_lock; /* API entrance mutex */ diff --git a/src/H5public.h b/src/H5public.h index 86a1fbb..f592ab9 100644 --- a/src/H5public.h +++ b/src/H5public.h @@ -51,7 +51,45 @@ # endif #endif #ifdef H5_HAVE_INTTYPES_H -# include <inttypes.h> /* For uint64_t on some platforms */ +# include <inttypes.h> /* C99/POSIX.1 header for uint64_t, PRIu64 */ +#else /* H5_HAVE_INTTYPES_H */ +/* The following definitions should be suitable for 64-bit Windows, which is + * LLP64, and for 32-bit Windows, which is ILP32. Those are the only + * platforms where <inttypes.h> is likely to be missing. VS2015 and later + * *may* provide these definitions. + */ +#ifdef _WIN64 +# define PRIdPTR "lld" +# define PRIoPTR "llo" +# define PRIuPTR "llu" +# define PRIxPTR "llx" +#else /* _WIN64 */ +# define PRIdPTR "ld" +# define PRIoPTR "lo" +# define PRIuPTR "lu" +# define PRIxPTR "lx" +#endif /* _WIN64 */ + +# define PRId8 "d" +# define PRIo8 "o" +# define PRIu8 "u" +# define PRIx8 "x" +# define PRId16 "d" +# define PRIo16 "o" +# define PRIu16 "u" +# define PRIx16 "x" +# define PRId32 "d" +# define PRIo32 "o" +# define PRIu32 "u" +# define PRIx32 "x" +# define PRId64 "lld" +# define PRIo64 "llo" +# define PRIu64 "llu" +# define PRIx64 "llx" +# define PRIdMAX "lld" +# define PRIoMAX "llo" +# define PRIuMAX "llu" +# define PRIxMAX "llx" #endif #ifdef H5_HAVE_STDDEF_H # include <stddef.h> @@ -340,6 +378,19 @@ typedef struct H5O_token_t { uint8_t __data[H5O_MAX_TOKEN_SIZE]; } H5O_token_t; +/* + * Allocation statistics info struct + */ +typedef struct H5_alloc_stats_t { + unsigned long long total_alloc_bytes; /* Running count of total # of bytes allocated */ + size_t curr_alloc_bytes; /* Current # of bytes allocated */ + size_t peak_alloc_bytes; /* Peak # of bytes allocated */ + size_t max_block_size; /* Largest block allocated */ + size_t total_alloc_blocks_count; /* Running count of total # of blocks allocated */ + size_t curr_alloc_blocks_count; /* Current # of blocks allocated */ + size_t peak_alloc_blocks_count; /* Peak # of blocks allocated */ +} H5_alloc_stats_t; + /* Functions in H5.c */ H5_DLL herr_t H5open(void); H5_DLL herr_t H5close(void); @@ -348,6 +399,9 @@ H5_DLL herr_t H5garbage_collect(void); H5_DLL herr_t H5set_free_list_limits (int reg_global_lim, int reg_list_lim, int arr_global_lim, int arr_list_lim, int blk_global_lim, int blk_list_lim); +H5_DLL herr_t H5get_free_list_sizes(size_t *reg_size, size_t *arr_size, + size_t *blk_size, size_t *fac_size); +H5_DLL herr_t H5get_alloc_stats(H5_alloc_stats_t *stats); H5_DLL herr_t H5get_libversion(unsigned *majnum, unsigned *minnum, unsigned *relnum); H5_DLL herr_t H5check_version(unsigned majnum, unsigned minnum, diff --git a/src/H5trace.c b/src/H5trace.c index ec5c6a2..03d9e7c 100644 --- a/src/H5trace.c +++ b/src/H5trace.c @@ -155,7 +155,7 @@ H5_trace(const double *returning, const char *func, const char *type, ...) } /* end if */ /* Get time for event */ - if(H5_DBL_ABS_EQUAL(first_time.etime, 0.0)) + if(H5_DBL_ABS_EQUAL(first_time.etime, (double)0.0f)) H5_timer_begin(&first_time); if(H5_debug_g.ttimes) H5_timer_begin(&event_time); @@ -2746,9 +2746,6 @@ H5_trace(const double *returning, const char *func, const char *type, ...) case H5VL_DATASET_GET_STORAGE_SIZE: HDfprintf(out, "H5VL_DATASET_GET_STORAGE_SIZE"); break; - case H5VL_DATASET_GET_OFFSET: - HDfprintf(out, "H5VL_DATASET_GET_OFFSET"); - break; default: HDfprintf(out, "%ld", (long)get); break; @@ -3276,6 +3273,9 @@ H5_trace(const double *returning, const char *func, const char *type, ...) case H5VL_NATIVE_DATASET_GET_VLEN_BUF_SIZE: HDfprintf(out, "H5VL_NATIVE_DATASET_GET_VLEN_BUF_SIZE"); break; + case H5VL_NATIVE_DATASET_GET_OFFSET: + HDfprintf(out, "H5VL_NATIVE_DATASET_GET_OFFSET"); + break; default: HDfprintf(out, "%ld", (long)optional); break; diff --git a/src/libhdf5.settings.in b/src/libhdf5.settings.in index 1591bed..0c2be75 100644 --- a/src/libhdf5.settings.in +++ b/src/libhdf5.settings.in @@ -39,7 +39,7 @@ Languages: H5_CPPFLAGS: @H5_CPPFLAGS@ AM_CPPFLAGS: @AM_CPPFLAGS@ C Flags: @CFLAGS@ - H5 C Flags: @H5_CFLAGS@ + H5 C Flags: @H5_CFLAGS@ @H5_ECFLAGS@ AM C Flags: @AM_CFLAGS@ Shared C Library: @enable_shared@ Static C Library: @enable_static@ |