From 287b1fe70f219ab383d61672afc654eba6a792ce Mon Sep 17 00:00:00 2001 From: Vailin Choi Date: Sat, 6 Jun 2015 17:42:54 -0500 Subject: [svn-r27156] Bring revisions #27003 - #27058 from trunk to revise_chunks. h5committested. --- CMakeLists.txt | 12 +- config/cmake/scripts/HDF518config.cmake | 19 +- src/H5Adense.c | 2 +- src/H5Aint.c | 14 +- src/H5B2hdr.c | 8 +- src/H5B2int.c | 14 +- src/H5B2pkg.h | 6 +- src/H5Bprivate.h | 1 + src/H5Dbtree.c | 228 ++++++++++++----- src/H5Dbtree2.c | 77 ++++-- src/H5Dchunk.c | 440 ++++++++++++++++---------------- src/H5Dcompact.c | 2 +- src/H5Dcontig.c | 30 ++- src/H5Ddeprec.c | 60 +++-- src/H5Dearray.c | 164 +++++++----- src/H5Defl.c | 2 +- src/H5Dfarray.c | 14 +- src/H5Dint.c | 39 ++- src/H5Dio.c | 4 +- src/H5Dmpio.c | 16 +- src/H5Dnone.c | 13 +- src/H5Dpkg.h | 18 +- src/H5Dprivate.h | 2 +- src/H5EA.c | 55 ++++ src/H5EAprivate.h | 4 + src/H5FAdblock.c | 2 +- src/H5FD.c | 6 +- src/H5FDcore.c | 4 +- src/H5FDdirect.c | 2 +- src/H5FDfamily.c | 4 +- src/H5FDlog.c | 2 +- src/H5FDprivate.h | 2 +- src/H5FDsec2.c | 2 +- src/H5FScache.c | 4 +- src/H5Faccum.c | 14 +- src/H5Fprivate.h | 1 - src/H5Fsuper.c | 2 +- src/H5Fsuper_cache.c | 6 +- src/H5Gdeprec.c | 2 +- src/H5Glink.c | 2 +- src/H5HFdbg.c | 6 +- src/H5HFdblock.c | 4 +- src/H5HFdtable.c | 4 +- src/H5HFhdr.c | 2 +- src/H5HFhuge.c | 6 +- src/H5HLcache.c | 4 +- src/H5I.c | 6 +- src/H5MF.c | 2 +- src/H5O.c | 4 +- src/H5Oattr.c | 2 +- src/H5Ocache.c | 2 +- src/H5Ofill.c | 2 +- src/H5Omessage.c | 4 +- src/H5PL.c | 3 +- src/H5Pencdec.c | 4 +- src/H5Pgcpl.c | 2 +- src/H5S.c | 2 +- src/H5Shyper.c | 20 +- src/H5Smpio.c | 6 +- src/H5Sselect.c | 4 +- src/H5Tarray.c | 2 +- src/H5Tconv.c | 18 +- src/H5Tfloat.c | 2 +- src/H5Tnative.c | 6 +- src/H5VM.c | 60 +---- src/H5VMprivate.h | 2 - src/H5Zdeflate.c | 6 +- src/H5Znbit.c | 2 +- src/H5Zscaleoffset.c | 2 +- src/H5Zszip.c | 12 +- src/H5detect.c | 303 +++++++++++----------- src/H5private.h | 7 +- tools/misc/h5debug.c | 39 ++- 73 files changed, 1056 insertions(+), 793 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cacc5d..a3d537c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -472,7 +472,7 @@ endif (HDF5_DISABLE_COMPILER_WARNINGS) # CDash is configured to only allow 3000 warnings, so # break into groups (from the config/gnu-flags file) #----------------------------------------------------------------------------- -if (NOT MSVC) +if (NOT MSVC AND CMAKE_COMPILER_IS_GNUCC) if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline") else (NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") @@ -535,7 +535,7 @@ if (NOT MSVC) # Append more extra warning flags that only gcc 4.7+ know about set (H5_CFLAGS5 "${H5_CFLAGS5} -Wstack-usage=8192 -Wvector-operation-performance -Wsuggest-attribute=pure -Wsuggest-attribute=noreturn") -endif (NOT MSVC) +endif (NOT MSVC AND CMAKE_COMPILER_IS_GNUCC) #----------------------------------------------------------------------------- # Option to allow the user to enable all warnings @@ -548,7 +548,9 @@ if (HDF5_ENABLE_ALL_WARNINGS) string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall") else (MSVC) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic ${H5_CFLAGS1} ${H5_CFLAGS2} ${H5_CFLAGS3} ${H5_CFLAGS4}") + if (CMAKE_COMPILER_IS_GNUCC) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic ${H5_CFLAGS1} ${H5_CFLAGS2} ${H5_CFLAGS3} ${H5_CFLAGS4}") + endif (CMAKE_COMPILER_IS_GNUCC) endif (MSVC) endif (HDF5_ENABLE_ALL_WARNINGS) @@ -563,7 +565,9 @@ if (HDF5_ENABLE_GROUPZERO_WARNINGS) string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W1") else (MSVC) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic") + if (CMAKE_COMPILER_IS_GNUCC) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic") + endif (CMAKE_COMPILER_IS_GNUCC) endif (MSVC) endif (HDF5_ENABLE_GROUPZERO_WARNINGS) diff --git a/config/cmake/scripts/HDF518config.cmake b/config/cmake/scripts/HDF518config.cmake index 9766b1c..f0aceea 100755 --- a/config/cmake/scripts/HDF518config.cmake +++ b/config/cmake/scripts/HDF518config.cmake @@ -1,11 +1,14 @@ -######################################################################### -### For Windows ${CTEST_SCRIPT_ARG} is one of ### -### [64-VS2013, 32-VS2013, 64-VS2012, 32-VS2012] ### -### ctest -S HDF518config.cmake,32-VS2012 -C Release -V -O hdf518.log ### -######################################################################### +########################################################################## +### For Windows ${CTEST_SCRIPT_ARG} is one of ### +### [64-VS2013, 32-VS2013, 64-VS2012, 32-VS2012] ### +### ctest -S HDF518config.cmake,32-VS2012 -C Release -VV -O hdf518.log ### +### ### +### Other platforms do not use ${CTEST_SCRIPT_ARG} ### +### ctest -S HDF518config.cmake -C Release -VV -O hdf518.log ### +########################################################################## cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) -set(CTEST_SOURCE_VERSION 1.8.15-pre7) +set(CTEST_SOURCE_VERSION 1.8.15) set(CTEST_SOURCE_NAME hdf5-${CTEST_SOURCE_VERSION}) set(CTEST_BINARY_NAME "build") set(CTEST_DASHBOARD_ROOT "${CTEST_SCRIPT_DIRECTORY}") @@ -90,14 +93,14 @@ set(REPOSITORY_URL "http://svn.hdfgroup.uiuc.edu/hdf5/branches/hdf5_1_8") #### Change default configuration of options in config/cmake/cacheinit.cmake file ### #### format: set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DXXX:YY=ZZZZ") -### uncomment/comment and change the following lines for configuration options +### uncomment/comment or change the following lines for configuration options ### comment the following line or change OFF to ON in order to build shared libraries set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_SHARED_LIBS:BOOL=OFF") #### ext libraries #### ### ext libs from tgz -set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ -DTGZPATH:PATH=${CTEST_SCRIPT_DIRECTORY}") +set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ -DTGZPATH:PATH=\"${CTEST_SCRIPT_DIRECTORY}\"") ### ext libs from svn #set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=SVN") ### ext libs on system diff --git a/src/H5Adense.c b/src/H5Adense.c index 4429616..8edacc9 100644 --- a/src/H5Adense.c +++ b/src/H5Adense.c @@ -548,7 +548,7 @@ H5A_dense_insert(H5F_t *f, hid_t dxpl_id, const H5O_ainfo_t *ainfo, H5A_t *attr) udata.common.shared_fheap = shared_fheap; udata.common.name = attr->shared->name; udata.common.name_hash = H5_checksum_lookup3(attr->shared->name, HDstrlen(attr->shared->name), 0); - H5_ASSIGN_OVERFLOW(udata.common.flags, mesg_flags, unsigned, uint8_t); + H5_CHECKED_ASSIGN(udata.common.flags, uint8_t, mesg_flags, unsigned); udata.common.corder = attr->shared->crt_idx; udata.common.found_op = NULL; udata.common.found_op_data = NULL; diff --git a/src/H5Aint.c b/src/H5Aint.c index f6f13d0..be16da5 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -255,7 +255,7 @@ H5A_create(const H5G_loc_t *loc, const char *name, const H5T_t *type, /* Get # of elements for attribute's dataspace */ if((snelmts = H5S_GET_EXTENT_NPOINTS(attr->shared->ds)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOUNT, NULL, "dataspace is invalid") - H5_ASSIGN_OVERFLOW(nelmts, snelmts, hssize_t, size_t); + H5_CHECKED_ASSIGN(nelmts, size_t, snelmts, hssize_t); HDassert(attr->shared->dt_size > 0); HDassert(attr->shared->ds_size > 0); @@ -508,7 +508,7 @@ H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id) /* Get # of elements for attribute's dataspace */ if((snelmts = H5S_GET_EXTENT_NPOINTS(attr->shared->ds)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOUNT, FAIL, "dataspace is invalid") - H5_ASSIGN_OVERFLOW(nelmts, snelmts, hssize_t, size_t); + H5_CHECKED_ASSIGN(nelmts, size_t, snelmts, hssize_t); /* If there's actually data elements for the attribute, make a copy of the data passed in */ if(nelmts > 0) { @@ -621,7 +621,7 @@ H5A_read(const H5A_t *attr, const H5T_t *mem_type, void *buf, hid_t dxpl_id) /* Create buffer for data to store on disk */ if((snelmts = H5S_GET_EXTENT_NPOINTS(attr->shared->ds)) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOUNT, FAIL, "dataspace is invalid") - H5_ASSIGN_OVERFLOW(nelmts, snelmts, hssize_t, size_t); + H5_CHECKED_ASSIGN(nelmts, size_t, snelmts, hssize_t); if(nelmts > 0) { /* Get the memory and file datatype sizes */ @@ -1681,7 +1681,7 @@ H5A_attr_iterate_table(const H5A_attr_table_t *atable, hsize_t skip, *last_attr = skip; /* Iterate over attribute messages */ - H5_ASSIGN_OVERFLOW(/* To: */ u, /* From: */ skip, /* From: */ hsize_t, /* To: */ size_t) + H5_CHECKED_ASSIGN(u, size_t, skip, hsize_t) for(; u < atable->nattrs && !ret_value; u++) { /* Check which type of callback to make */ switch(attr_op->op_type) { @@ -2022,7 +2022,11 @@ H5A_attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_si *recompute_size = TRUE; /* Compute the size of the data */ - H5_ASSIGN_OVERFLOW(attr_dst->shared->data_size, H5S_GET_EXTENT_NPOINTS(attr_dst->shared->ds) * H5T_get_size(attr_dst->shared->dt), hssize_t, size_t); + /* NOTE: This raises warnings. If we are going to be serious about + * expecting overflow here, we should implement testing similar to + * that described in CERT bulletins INT30-C and INT32-C. + */ + H5_CHECKED_ASSIGN(attr_dst->shared->data_size, size_t, H5S_GET_EXTENT_NPOINTS(attr_dst->shared->ds) * H5T_get_size(attr_dst->shared->dt), hssize_t); /* Copy (& convert) the data, if necessary */ if(attr_src->shared->data) { diff --git a/src/H5B2hdr.c b/src/H5B2hdr.c index 5e00139..aaabf04 100644 --- a/src/H5B2hdr.c +++ b/src/H5B2hdr.c @@ -161,7 +161,7 @@ HDmemset(hdr->page, 0, hdr->node_size); /* Initialize leaf node info */ sz_max_nrec = H5B2_NUM_LEAF_REC(hdr->node_size, hdr->rrec_size); - H5_ASSIGN_OVERFLOW(/* To: */ hdr->node_info[0].max_nrec, /* From: */ sz_max_nrec, /* From: */ size_t, /* To: */ unsigned) + H5_CHECKED_ASSIGN(hdr->node_info[0].max_nrec, unsigned, sz_max_nrec, size_t) hdr->node_info[0].split_nrec = (hdr->node_info[0].max_nrec * hdr->split_percent) / 100; hdr->node_info[0].merge_nrec = (hdr->node_info[0].max_nrec * hdr->merge_percent) / 100; hdr->node_info[0].cum_max_nrec = hdr->node_info[0].max_nrec; @@ -183,14 +183,14 @@ HDmemset(hdr->page, 0, hdr->node_size); /* Compute size to store # of records in each node */ /* (uses leaf # of records because its the largest) */ u_max_nrec_size = H5VM_limit_enc_size((uint64_t)hdr->node_info[0].max_nrec); - H5_ASSIGN_OVERFLOW(/* To: */ hdr->max_nrec_size, /* From: */ u_max_nrec_size, /* From: */ unsigned, /* To: */ uint8_t) + H5_CHECKED_ASSIGN(hdr->max_nrec_size, uint8_t, u_max_nrec_size, unsigned) HDassert(hdr->max_nrec_size <= H5B2_SIZEOF_RECORDS_PER_NODE); /* Initialize internal node info */ if(depth > 0) { for(u = 1; u < (unsigned)(depth + 1); u++) { sz_max_nrec = H5B2_NUM_INT_REC(hdr, u); - H5_ASSIGN_OVERFLOW(/* To: */ hdr->node_info[u].max_nrec, /* From: */ sz_max_nrec, /* From: */ size_t, /* To: */ unsigned) + H5_CHECKED_ASSIGN(hdr->node_info[u].max_nrec, unsigned, sz_max_nrec, size_t) HDassert(hdr->node_info[u].max_nrec <= hdr->node_info[u - 1].max_nrec); hdr->node_info[u].split_nrec = (hdr->node_info[u].max_nrec * hdr->split_percent) / 100; @@ -199,7 +199,7 @@ HDmemset(hdr->page, 0, hdr->node_size); hdr->node_info[u].cum_max_nrec = ((hdr->node_info[u].max_nrec + 1) * hdr->node_info[u - 1].cum_max_nrec) + hdr->node_info[u].max_nrec; u_max_nrec_size = H5VM_limit_enc_size((uint64_t)hdr->node_info[u].cum_max_nrec); - H5_ASSIGN_OVERFLOW(/* To: */ hdr->node_info[u].cum_max_nrec_size, /* From: */ u_max_nrec_size, /* From: */ unsigned, /* To: */ uint8_t) + H5_CHECKED_ASSIGN(hdr->node_info[u].cum_max_nrec_size, uint8_t, u_max_nrec_size, unsigned) if(NULL == (hdr->node_info[u].nat_rec_fac = H5FL_fac_init(hdr->cls->nrec_size * hdr->node_info[u].max_nrec))) HGOTO_ERROR(H5E_BTREE, H5E_CANTINIT, FAIL, "can't create node native key block factory") diff --git a/src/H5B2int.c b/src/H5B2int.c index eea1ca7..79d6ea1 100644 --- a/src/H5B2int.c +++ b/src/H5B2int.c @@ -473,13 +473,13 @@ H5B2_split_root(H5B2_hdr_t *hdr, hid_t dxpl_id) /* Update node info for new depth of tree */ sz_max_nrec = H5B2_NUM_INT_REC(hdr, hdr->depth); - H5_ASSIGN_OVERFLOW(/* To: */ hdr->node_info[hdr->depth].max_nrec, /* From: */ sz_max_nrec, /* From: */ size_t, /* To: */ unsigned) + H5_CHECKED_ASSIGN(hdr->node_info[hdr->depth].max_nrec, unsigned, sz_max_nrec, size_t) hdr->node_info[hdr->depth].split_nrec = (hdr->node_info[hdr->depth].max_nrec * hdr->split_percent) / 100; hdr->node_info[hdr->depth].merge_nrec = (hdr->node_info[hdr->depth].max_nrec * hdr->merge_percent) / 100; hdr->node_info[hdr->depth].cum_max_nrec = ((hdr->node_info[hdr->depth].max_nrec + 1) * hdr->node_info[hdr->depth - 1].cum_max_nrec) + hdr->node_info[hdr->depth].max_nrec; u_max_nrec_size = H5VM_limit_enc_size((uint64_t)hdr->node_info[hdr->depth].cum_max_nrec); - H5_ASSIGN_OVERFLOW(/* To: */ hdr->node_info[hdr->depth].cum_max_nrec_size, /* From: */ u_max_nrec_size, /* From: */ unsigned, /* To: */ uint8_t) + H5_CHECKED_ASSIGN(hdr->node_info[hdr->depth].cum_max_nrec_size, uint8_t, u_max_nrec_size, unsigned) if(NULL == (hdr->node_info[hdr->depth].nat_rec_fac = H5FL_fac_init(hdr->cls->nrec_size * hdr->node_info[hdr->depth].max_nrec))) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, FAIL, "can't create node native key block factory") if(NULL == (hdr->node_info[hdr->depth].node_ptr_fac = H5FL_fac_init(sizeof(H5B2_node_ptr_t) * (hdr->node_info[hdr->depth].max_nrec + 1)))) @@ -660,7 +660,7 @@ H5B2_redistribute2(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, /* Count the number of records being moved */ for(u = 0; u < move_nrec; u++) moved_nrec += right_node_ptrs[u].all_nrec; - H5_ASSIGN_OVERFLOW(/* To: */ left_moved_nrec, /* From: */ moved_nrec, /* From: */ hsize_t, /* To: */ hssize_t) + H5_CHECKED_ASSIGN(left_moved_nrec, hssize_t, moved_nrec, hsize_t) right_moved_nrec -= (hssize_t)moved_nrec; /* Copy node pointers from right node to left */ @@ -774,7 +774,7 @@ H5B2_redistribute2(H5B2_hdr_t *hdr, hid_t dxpl_id, unsigned depth, for(u = 0; u < move_nrec; u++) moved_nrec += right_node_ptrs[u].all_nrec; left_moved_nrec -= (hssize_t)moved_nrec; - H5_ASSIGN_OVERFLOW(/* To: */ right_moved_nrec, /* From: */ moved_nrec, /* From: */ hsize_t, /* To: */ hssize_t) + H5_CHECKED_ASSIGN(right_moved_nrec, hssize_t, moved_nrec, hsize_t) } /* end if */ /* Update flush dependencies */ @@ -2615,7 +2615,7 @@ H5B2_protect_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, haddr_t addr, void *parent, udata.f = hdr->f; udata.hdr = hdr; udata.parent = parent; - H5_ASSIGN_OVERFLOW(/* To: */ udata.nrec, /* From: */ nrec, /* From: */ unsigned, /* To: */ uint16_t) + H5_CHECKED_ASSIGN(udata.nrec, uint16_t, nrec, unsigned) /* Protect the leaf node */ if(NULL == (ret_value = (H5B2_leaf_t *)H5AC_protect(hdr->f, dxpl_id, H5AC_BT2_LEAF, addr, &udata, rw))) @@ -2743,8 +2743,8 @@ H5B2_protect_internal(H5B2_hdr_t *hdr, hid_t dxpl_id, haddr_t addr, udata.f = hdr->f; udata.hdr = hdr; udata.parent = parent; - H5_ASSIGN_OVERFLOW(/* To: */ udata.nrec, /* From: */ nrec, /* From: */ unsigned, /* To: */ uint16_t) - H5_ASSIGN_OVERFLOW(/* To: */ udata.depth, /* From: */ depth, /* From: */ unsigned, /* To: */ uint16_t) + H5_CHECKED_ASSIGN(udata.nrec, uint16_t, nrec, unsigned) + H5_CHECKED_ASSIGN(udata.depth, uint16_t, depth, unsigned) /* Protect the internal node */ if(NULL == (ret_value = (H5B2_internal_t *)H5AC_protect(hdr->f, dxpl_id, H5AC_BT2_INT, addr, &udata, rw))) diff --git a/src/H5B2pkg.h b/src/H5B2pkg.h index 55e00d9..557a53b 100644 --- a/src/H5B2pkg.h +++ b/src/H5B2pkg.h @@ -358,7 +358,7 @@ H5_DLL herr_t H5B2_neighbor_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, /* Routines for removing records */ H5_DLL herr_t H5B2_remove_internal(H5B2_hdr_t *hdr, hid_t dxpl_id, hbool_t *depth_decreased, void *swap_loc, void *swap_parent, unsigned depth, - H5AC_info_t *parent_cache_info, hbool_t * parent_cache_info_dirtied_ptr, + H5AC_info_t *parent_cache_info, unsigned *parent_cache_info_flags_ptr, H5B2_nodepos_t curr_pos, H5B2_node_ptr_t *curr_node_ptr, void *udata, H5B2_remove_t op, void *op_data); H5_DLL herr_t H5B2_remove_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, @@ -366,8 +366,8 @@ H5_DLL herr_t H5B2_remove_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, void *udata, H5B2_remove_t op, void *op_data); H5_DLL herr_t H5B2_remove_internal_by_idx(H5B2_hdr_t *hdr, hid_t dxpl_id, hbool_t *depth_decreased, void *swap_loc, void *swap_parent, unsigned depth, - H5AC_info_t *parent_cache_info, hbool_t * parent_cache_info_dirtied_ptr, - H5B2_node_ptr_t *curr_node_ptr, H5B2_nodepos_t curr_pos, hsize_t idx, + H5AC_info_t *parent_cache_info, unsigned *parent_cache_info_flags_ptr, + H5B2_node_ptr_t *curr_node_ptr, H5B2_nodepos_t curr_pos, hsize_t n, void *udata, H5B2_remove_t op, void *op_data); H5_DLL herr_t H5B2_remove_leaf_by_idx(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_ptr, H5B2_nodepos_t curr_pos, void *parent, diff --git a/src/H5Bprivate.h b/src/H5Bprivate.h index 1549d57..3251a47 100644 --- a/src/H5Bprivate.h +++ b/src/H5Bprivate.h @@ -100,6 +100,7 @@ typedef struct H5B_shared_t { size_t sizeof_len; /* Size of file lengths (in bytes) */ uint8_t *page; /* Disk page */ size_t *nkey; /* Offsets of each native key in native key buffer */ + void *udata; /* 'Local' info for a B-tree */ } H5B_shared_t; /* diff --git a/src/H5Dbtree.c b/src/H5Dbtree.c index 328795e..66c1b86 100644 --- a/src/H5Dbtree.c +++ b/src/H5Dbtree.c @@ -49,11 +49,6 @@ /* Local Macros */ /****************/ -/* - * Given a B-tree node return the dimensionality of the chunks pointed to by - * that node. - */ -#define H5D_BTREE_NDIMS(X) (((X)->sizeof_rkey-8)/8) /******************/ /* Local Typedefs */ @@ -74,7 +69,7 @@ * The chunk's file address is part of the B-tree and not part of the key. */ typedef struct H5D_btree_key_t { - hsize_t offset[H5O_LAYOUT_NDIMS]; /*logical offset to start*/ + hsize_t scaled[H5O_LAYOUT_NDIMS]; /*logical offset to start*/ uint32_t nbytes; /*size of stored data */ unsigned filter_mask; /*excluded filters */ } H5D_btree_key_t; @@ -97,8 +92,9 @@ typedef struct H5D_btree_dbg_t { /* Local Prototypes */ /********************/ +static herr_t H5D__btree_shared_free(void *_shared); static herr_t H5D__btree_shared_create(const H5F_t *f, H5O_storage_chunk_t *store, - unsigned ndims); + const H5O_layout_chunk_t *layout); /* B-tree iterator callbacks */ static int H5D__btree_idx_iterate_cb(H5F_t *f, hid_t dxpl_id, const void *left_key, @@ -204,6 +200,10 @@ H5B_class_t H5B_BTREE[1] = {{ /* Local Variables */ /*******************/ +/* Declare a free list to manage H5O_layout_chunk_t objects */ +H5FL_DEFINE_STATIC(H5O_layout_chunk_t); + + /*------------------------------------------------------------------------- * Function: H5D__btree_get_shared @@ -285,10 +285,10 @@ H5D__btree_new_node(H5F_t *f, hid_t UNUSED dxpl_id, H5B_ins_t op, * The left key describes the storage of the UDATA chunk being * inserted into the tree. */ - H5_ASSIGN_OVERFLOW(lt_key->nbytes, udata->chunk_block.length, hsize_t, uint32_t); + H5_CHECKED_ASSIGN(lt_key->nbytes, uint32_t, udata->chunk_block.length, hsize_t); lt_key->filter_mask = udata->filter_mask; for(u = 0; u < udata->common.layout->ndims; u++) - lt_key->offset[u] = udata->common.offset[u]; + lt_key->scaled[u] = udata->common.scaled[u]; /* * The right key might already be present. If not, then add a zero-width @@ -298,9 +298,8 @@ H5D__btree_new_node(H5F_t *f, hid_t UNUSED dxpl_id, H5B_ins_t op, rt_key->nbytes = 0; rt_key->filter_mask = 0; for(u = 0; u < udata->common.layout->ndims; u++) { - HDassert(udata->common.offset[u] + udata->common.layout->dim[u] > - udata->common.offset[u]); - rt_key->offset[u] = udata->common.offset[u] + udata->common.layout->dim[u]; + HDassert(udata->common.scaled[u] + 1 > udata->common.scaled[u]); + rt_key->scaled[u] = udata->common.scaled[u] + 1; } /* end if */ } /* end if */ @@ -343,7 +342,7 @@ H5D__btree_cmp2(void *_lt_key, void *_udata, void *_rt_key) HDassert(udata->layout->ndims > 0 && udata->layout->ndims <= H5O_LAYOUT_NDIMS); /* Compare the offsets but ignore the other fields */ - ret_value = H5VM_vector_cmp_u(udata->layout->ndims, lt_key->offset, rt_key->offset); + ret_value = H5VM_vector_cmp_u(udata->layout->ndims, lt_key->scaled, rt_key->scaled); FUNC_LEAVE_NOAPI(ret_value) } /* end H5D__btree_cmp2() */ @@ -398,18 +397,18 @@ H5D__btree_cmp3(void *_lt_key, void *_udata, void *_rt_key) /* indexed storage B-tree... */ /* (Dump the B-tree with h5debug to look at it) -QAK */ if(udata->layout->ndims == 2) { - if(udata->offset[0] > rt_key->offset[0]) + if(udata->scaled[0] > rt_key->scaled[0]) ret_value = 1; - else if(udata->offset[0] == rt_key->offset[0] && - udata->offset[1] >= rt_key->offset[1]) + else if(udata->scaled[0] == rt_key->scaled[0] && + udata->scaled[1] >= rt_key->scaled[1]) ret_value = 1; - else if(udata->offset[0] < lt_key->offset[0]) + else if(udata->scaled[0] < lt_key->scaled[0]) ret_value = (-1); } /* end if */ else { - if(H5VM_vector_ge_u(udata->layout->ndims, udata->offset, rt_key->offset)) + if(H5VM_vector_ge_u(udata->layout->ndims, udata->scaled, rt_key->scaled)) ret_value = 1; - else if(H5VM_vector_lt_u(udata->layout->ndims, udata->offset, lt_key->offset)) + else if(H5VM_vector_lt_u(udata->layout->ndims, udata->scaled, lt_key->scaled)) ret_value = (-1); } /* end else */ @@ -461,7 +460,7 @@ H5D__btree_found(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, haddr_t addr, const void /* Is this *really* the requested chunk? */ for(u = 0; u < udata->common.layout->ndims; u++) - if(udata->common.offset[u] >= lt_key->offset[u] + udata->common.layout->dim[u]) + if(udata->common.scaled[u] >= (lt_key->scaled[u] + 1)) HGOTO_DONE(FALSE) /* Initialize return values */ @@ -476,6 +475,44 @@ done: /*------------------------------------------------------------------------- + * Function: H5D__chunk_disjoint + * + * Purpose: Determines if two chunks are disjoint. + * + * Return: Success: FALSE if they are not disjoint. + * TRUE if they are disjoint. + * + * Programmer: Quincey Koziol + * Wednesday, May 6, 2015 + * + * Note: Assumes that the chunk offsets are scaled coordinates + * + *------------------------------------------------------------------------- + */ +static hbool_t +H5D__chunk_disjoint(unsigned n, const hsize_t *scaled1, const hsize_t *scaled2) +{ + unsigned u; /* Local index variable */ + hbool_t ret_value = FALSE; /* Return value */ + + FUNC_ENTER_STATIC_NOERR + + /* Sanity checks */ + HDassert(n); + HDassert(scaled1); + HDassert(scaled2); + + /* Loop over two chunks, detecting disjointness and getting out quickly */ + for(u = 0; u < n; u++) + if((scaled1[u] + 1) <= scaled2[u] || (scaled2[u] + 1) <= scaled1[u]) + HGOTO_DONE(TRUE) + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D__chunk_disjoint() */ + + +/*------------------------------------------------------------------------- * Function: H5D__btree_insert * * Purpose: This function is called when the B-tree insert engine finds @@ -539,8 +576,7 @@ H5D__btree_insert(H5F_t *f, hid_t UNUSED dxpl_id, haddr_t addr, void *_lt_key, HGOTO_ERROR(H5E_STORAGE, H5E_UNSUPPORTED, H5B_INS_ERROR, "internal error") } else if(H5VM_vector_eq_u(udata->common.layout->ndims, - udata->common.offset, lt_key->offset) && - lt_key->nbytes > 0) { + udata->common.scaled, lt_key->scaled) && lt_key->nbytes > 0) { /* * Already exists. If the new size is not the same as the old size * then we should reallocate storage. @@ -549,7 +585,7 @@ H5D__btree_insert(H5F_t *f, hid_t UNUSED dxpl_id, haddr_t addr, void *_lt_key, /* Set node's address (already re-allocated by main chunk routines) */ HDassert(H5F_addr_defined(udata->chunk_block.offset)); *new_node_p = udata->chunk_block.offset; - H5_ASSIGN_OVERFLOW(lt_key->nbytes, udata->chunk_block.length, hsize_t, uint32_t); + H5_CHECKED_ASSIGN(lt_key->nbytes, uint32_t, udata->chunk_block.length, hsize_t); lt_key->filter_mask = udata->filter_mask; *lt_key_changed = TRUE; ret_value = H5B_INS_CHANGE; @@ -559,22 +595,18 @@ H5D__btree_insert(H5F_t *f, hid_t UNUSED dxpl_id, haddr_t addr, void *_lt_key, ret_value = H5B_INS_NOOP; } - } else if (H5VM_hyper_disjointp(udata->common.layout->ndims, - lt_key->offset, udata->common.layout->dim, - udata->common.offset, udata->common.layout->dim)) { - HDassert(H5VM_hyper_disjointp(udata->common.layout->ndims, - rt_key->offset, udata->common.layout->dim, - udata->common.offset, udata->common.layout->dim)); + } else if (H5D__chunk_disjoint(udata->common.layout->ndims, + lt_key->scaled, udata->common.scaled)) { + HDassert(H5D__chunk_disjoint(udata->common.layout->ndims, + rt_key->scaled, udata->common.scaled)); /* * Split this node, inserting the new new node to the right of the * current node. The MD_KEY is where the split occurs. */ - H5_ASSIGN_OVERFLOW(md_key->nbytes, udata->chunk_block.length, hsize_t, uint32_t); + H5_CHECKED_ASSIGN(md_key->nbytes, uint32_t, udata->chunk_block.length, hsize_t); md_key->filter_mask = udata->filter_mask; - for(u = 0; u < udata->common.layout->ndims; u++) { - HDassert(0 == udata->common.offset[u] % udata->common.layout->dim[u]); - md_key->offset[u] = udata->common.offset[u]; - } /* end for */ + for(u = 0; u < udata->common.layout->ndims; u++) + md_key->scaled[u] = udata->common.scaled[u]; HDassert(H5F_addr_defined(udata->chunk_block.offset)); *new_node_p = udata->chunk_block.offset; @@ -644,9 +676,10 @@ done: static herr_t H5D__btree_decode_key(const H5B_shared_t *shared, const uint8_t *raw, void *_key) { - H5D_btree_key_t *key = (H5D_btree_key_t *) _key; - size_t ndims; - unsigned u; + const H5O_layout_chunk_t *layout; /* Chunk layout description */ + H5D_btree_key_t *key = (H5D_btree_key_t *) _key; /* Pointer to decoded key */ + hsize_t tmp_offset; /* Temporary coordinate offset, from file */ + unsigned u; /* Local index variable */ FUNC_ENTER_STATIC_NOERR @@ -654,14 +687,21 @@ H5D__btree_decode_key(const H5B_shared_t *shared, const uint8_t *raw, void *_key HDassert(shared); HDassert(raw); HDassert(key); - ndims = H5D_BTREE_NDIMS(shared); - HDassert(ndims <= H5O_LAYOUT_NDIMS); + layout = (const H5O_layout_chunk_t *)shared->udata; + HDassert(layout); + HDassert(layout->ndims > 0 && layout->ndims <= H5O_LAYOUT_NDIMS); /* decode */ UINT32DECODE(raw, key->nbytes); UINT32DECODE(raw, key->filter_mask); - for(u = 0; u < ndims; u++) - UINT64DECODE(raw, key->offset[u]); + for(u = 0; u < layout->ndims; u++) { + /* Retrieve coordinate offset */ + UINT64DECODE(raw, tmp_offset); + HDassert(0 == (tmp_offset % layout->dim[u])); + + /* Convert to a scaled offset */ + key->scaled[u] = tmp_offset / layout->dim[u]; + } /* end for */ FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5D__btree_decode_key() */ @@ -682,9 +722,10 @@ H5D__btree_decode_key(const H5B_shared_t *shared, const uint8_t *raw, void *_key static herr_t H5D__btree_encode_key(const H5B_shared_t *shared, uint8_t *raw, const void *_key) { + const H5O_layout_chunk_t *layout; /* Chunk layout description */ const H5D_btree_key_t *key = (const H5D_btree_key_t *)_key; - size_t ndims; - unsigned u; + hsize_t tmp_offset; /* Temporary coordinate offset, from file */ + unsigned u; /* Local index variable */ FUNC_ENTER_STATIC_NOERR @@ -692,14 +733,18 @@ H5D__btree_encode_key(const H5B_shared_t *shared, uint8_t *raw, const void *_key HDassert(shared); HDassert(raw); HDassert(key); - ndims = H5D_BTREE_NDIMS(shared); - HDassert(ndims <= H5O_LAYOUT_NDIMS); + layout = (const H5O_layout_chunk_t *)shared->udata; + HDassert(layout); + HDassert(layout->ndims > 0 && layout->ndims <= H5O_LAYOUT_NDIMS); /* encode */ UINT32ENCODE(raw, key->nbytes); UINT32ENCODE(raw, key->filter_mask); - for(u = 0; u < ndims; u++) - UINT64ENCODE(raw, key->offset[u]); + for(u = 0; u < layout->ndims; u++) { + /* Compute coordinate offset from scaled offset */ + tmp_offset = key->scaled[u] * layout->dim[u]; + UINT64ENCODE(raw, tmp_offset); + } /* end for */ FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5D__btree_encode_key() */ @@ -734,7 +779,7 @@ H5D__btree_debug_key(FILE *stream, int indent, int fwidth, const void *_key, HDfprintf(stream, "%*s%-*s 0x%08x\n", indent, "", fwidth, "Filter mask:", key->filter_mask); HDfprintf(stream, "%*s%-*s {", indent, "", fwidth, "Logical offset:"); for(u = 0; u < udata->ndims; u++) - HDfprintf(stream, "%s%Hd", u?", ":"", key->offset[u]); + HDfprintf(stream, "%s%Hd", u?", ":"", (key->scaled[u] * udata->common.layout->dim[u])); HDfputs("}\n", stream); FUNC_LEAVE_NOAPI(SUCCEED) @@ -742,6 +787,38 @@ H5D__btree_debug_key(FILE *stream, int indent, int fwidth, const void *_key, /*------------------------------------------------------------------------- + * Function: H5D__btree_shared_free + * + * Purpose: Free "local" B-tree shared info + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Thursday, May 7, 2015 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5D__btree_shared_free(void *_shared) +{ + H5B_shared_t *shared = (H5B_shared_t *)_shared; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Free the chunk layout information */ + shared->udata = H5FL_FREE(H5O_layout_chunk_t, shared->udata); + + /* Chain up to the generic B-tree shared info free routine */ + if(H5B_shared_free(shared) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "can't free shared B-tree info") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D__btree_shared_free() */ + + +/*------------------------------------------------------------------------- * Function: H5D__btree_shared_create * * Purpose: Create & initialize B-tree shared info @@ -754,9 +831,11 @@ H5D__btree_debug_key(FILE *stream, int indent, int fwidth, const void *_key, *------------------------------------------------------------------------- */ static herr_t -H5D__btree_shared_create(const H5F_t *f, H5O_storage_chunk_t *store, unsigned ndims) +H5D__btree_shared_create(const H5F_t *f, H5O_storage_chunk_t *store, + const H5O_layout_chunk_t *layout) { H5B_shared_t *shared; /* Shared B-tree node info */ + H5O_layout_chunk_t *my_layout = NULL; /* Pointer to copy of layout info */ size_t sizeof_rkey; /* Size of raw (disk) key */ herr_t ret_value = SUCCEED; /* Return value */ @@ -765,20 +844,27 @@ H5D__btree_shared_create(const H5F_t *f, H5O_storage_chunk_t *store, unsigned nd /* Set the raw key size */ sizeof_rkey = 4 + /*storage size */ 4 + /*filter mask */ - ndims * 8; /*dimension indices */ + layout->ndims * 8; /*dimension indices */ /* Allocate & initialize global info for the shared structure */ if(NULL == (shared = H5B_shared_new(f, H5B_BTREE, sizeof_rkey))) - HGOTO_ERROR(H5E_BTREE, H5E_NOSPACE, FAIL, "memory allocation failed for shared B-tree info") + HGOTO_ERROR(H5E_DATASET, H5E_NOSPACE, FAIL, "memory allocation failed for shared B-tree info") /* Set up the "local" information for this dataset's chunks */ - /* */ + if(NULL == (my_layout = H5FL_MALLOC(H5O_layout_chunk_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate chunk layout") + HDmemcpy(my_layout, layout, sizeof(H5O_layout_chunk_t)); + shared->udata = my_layout; HDassert(!store->u.btree.shared); /* Make shared B-tree info reference counted */ - if(NULL == (store->u.btree.shared = H5UC_create(shared, H5B_shared_free))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create ref-count wrapper for shared B-tree info") + if(NULL == (store->u.btree.shared = H5UC_create(shared, H5D__btree_shared_free))) + HGOTO_ERROR(H5E_DATASET, H5E_NOSPACE, FAIL, "can't create ref-count wrapper for shared B-tree info") done: + if(ret_value < 0) + if(my_layout) + my_layout = H5FL_FREE(H5O_layout_chunk_t, my_layout); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5D__btree_shared_create() */ @@ -814,7 +900,7 @@ H5D__btree_idx_init(const H5D_chk_idx_info_t *idx_info, const H5S_t UNUSED *spac idx_info->storage->u.btree.dset_ohdr_addr = dset_ohdr_addr; /* Allocate the shared structure */ - if(H5D__btree_shared_create(idx_info->f, idx_info->storage, idx_info->layout->ndims) < 0) + if(H5D__btree_shared_create(idx_info->f, idx_info->storage, idx_info->layout) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, FAIL, "can't create wrapper for shared B-tree info") done: @@ -1008,8 +1094,8 @@ H5D__btree_idx_iterate_cb(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, /* Sanity check for memcpy() */ HDcompile_assert(offsetof(H5D_chunk_rec_t, nbytes) == offsetof(H5D_btree_key_t, nbytes)); HDcompile_assert(sizeof(chunk_rec.nbytes) == sizeof(lt_key->nbytes)); - HDcompile_assert(offsetof(H5D_chunk_rec_t, offset) == offsetof(H5D_btree_key_t, offset)); - HDcompile_assert(sizeof(chunk_rec.offset) == sizeof(lt_key->offset)); + HDcompile_assert(offsetof(H5D_chunk_rec_t, scaled) == offsetof(H5D_btree_key_t, scaled)); + HDcompile_assert(sizeof(chunk_rec.scaled) == sizeof(lt_key->scaled)); HDcompile_assert(offsetof(H5D_chunk_rec_t, filter_mask) == offsetof(H5D_btree_key_t, filter_mask)); HDcompile_assert(sizeof(chunk_rec.filter_mask) == sizeof(lt_key->filter_mask)); @@ -1148,7 +1234,7 @@ H5D__btree_idx_delete(const H5D_chk_idx_info_t *idx_info) tmp_storage = *idx_info->storage; /* Set up the shared structure */ - if(H5D__btree_shared_create(idx_info->f, &tmp_storage, idx_info->layout->ndims) < 0) + if(H5D__btree_shared_create(idx_info->f, &tmp_storage, idx_info->layout) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't create wrapper for shared B-tree info") /* Set up B-tree user data */ @@ -1205,9 +1291,9 @@ H5D__btree_idx_copy_setup(const H5D_chk_idx_info_t *idx_info_src, HDassert(!H5F_addr_defined(idx_info_dst->storage->idx_addr)); /* Create shared B-tree info for each file */ - if(H5D__btree_shared_create(idx_info_src->f, idx_info_src->storage, idx_info_src->layout->ndims) < 0) + if(H5D__btree_shared_create(idx_info_src->f, idx_info_src->storage, idx_info_src->layout) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, FAIL, "can't create wrapper for source shared B-tree info") - if(H5D__btree_shared_create(idx_info_dst->f, idx_info_dst->storage, idx_info_dst->layout->ndims) < 0) + if(H5D__btree_shared_create(idx_info_dst->f, idx_info_dst->storage, idx_info_dst->layout) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, FAIL, "can't create wrapper for destination shared B-tree info") /* Create the root of the B-tree that describes chunked storage in the dest. file */ @@ -1287,7 +1373,7 @@ H5D__btree_idx_size(const H5D_chk_idx_info_t *idx_info, hsize_t *index_size) HDassert(index_size); /* Initialize the shared info for the B-tree traversal */ - if(H5D__btree_shared_create(idx_info->f, idx_info->storage, idx_info->layout->ndims) < 0) + if(H5D__btree_shared_create(idx_info->f, idx_info->storage, idx_info->layout) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, FAIL, "can't create wrapper for shared B-tree info") shared_init = TRUE; @@ -1419,11 +1505,13 @@ done: */ herr_t H5D_btree_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, - int fwidth, unsigned ndims) + int fwidth, unsigned ndims, const uint32_t *dim) { H5D_btree_dbg_t udata; /* User data for B-tree callback */ H5O_storage_chunk_t storage; /* Storage information for B-tree callback */ + H5O_layout_chunk_t layout; /* Layout information for B-tree callback */ hbool_t shared_init = FALSE; /* Whether B-tree shared info is initialized */ + unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -1432,15 +1520,21 @@ H5D_btree_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent HDmemset(&storage, 0, sizeof(storage)); storage.idx_type = H5D_CHUNK_IDX_BTREE; + /* Reset "fake" layout info */ + HDmemset(&layout, 0, sizeof(layout)); + layout.ndims = ndims; + for(u = 0; u < ndims; u++) + layout.dim[u] = dim[u]; + /* Allocate the shared structure */ - if(H5D__btree_shared_create(f, &storage, ndims) < 0) + if(H5D__btree_shared_create(f, &storage, &layout) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, FAIL, "can't create wrapper for shared B-tree info") shared_init = TRUE; /* Set up user data for callback */ - udata.common.layout = NULL; + udata.common.layout = &layout; udata.common.storage = &storage; - udata.common.offset = NULL; + udata.common.scaled = NULL; udata.ndims = ndims; /* Dump the records for the B-tree */ @@ -1450,10 +1544,10 @@ done: if(shared_init) { /* Free the raw B-tree node buffer */ if(NULL == storage.u.btree.shared) - HDONE_ERROR(H5E_IO, H5E_CANTFREE, FAIL, "ref-counted page nil") + HDONE_ERROR(H5E_IO, H5E_CANTFREE, FAIL, "ref-counted shared info nil") else if(H5UC_DEC(storage.u.btree.shared) < 0) - HDONE_ERROR(H5E_IO, H5E_CANTFREE, FAIL, "unable to decrement ref-counted page") + HDONE_ERROR(H5E_IO, H5E_CANTFREE, FAIL, "unable to decrement ref-counted shared info") } /* end if */ FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5Dbtree2.c b/src/H5Dbtree2.c index fb79046..9f24d32 100644 --- a/src/H5Dbtree2.c +++ b/src/H5Dbtree2.c @@ -49,7 +49,7 @@ /* Typedef for non-filtered object's records in v2 B-tree */ typedef struct H5D_bt2_rec_t { haddr_t addr; /* Address of the chunk in the file */ - hsize_t offset[H5O_LAYOUT_NDIMS]; /* logical offset to start*/ + hsize_t scaled[H5O_LAYOUT_NDIMS]; /* logical offset to start*/ } H5D_bt2_rec_t; /* Typedef for filtered object's records in v2 B-tree */ @@ -57,7 +57,7 @@ typedef struct H5D_bt2_filt_rec_t { haddr_t addr; /* Address of the filtered object in the file */ uint32_t nbytes; /* Length of the filtered object in the file */ uint32_t filter_mask; /* I/O pipeline filter mask for filtered object in the file */ - hsize_t offset[H5O_LAYOUT_NDIMS]; /* logical offset to start*/ + hsize_t scaled[H5O_LAYOUT_NDIMS]; /* logical offset to start*/ } H5D_bt2_filt_rec_t; /* User data for creating callback context */ @@ -65,13 +65,15 @@ typedef struct H5D_bt2_ctx_ud_t { const H5F_t *f; /* Pointer to file info */ uint32_t chunk_size; /* Size of chunk (bytes; for filtered object) */ unsigned ndims; /* Number of dimensions */ + uint32_t *dim; /* Size of chunk in elements */ } H5D_bt2_ctx_ud_t; /* The callback context */ typedef struct H5D_bt2_ctx_t { size_t sizeof_addr; /* Size of file addresses in the file (bytes) */ size_t chunk_size_len; /* Size of chunk sizes in the file (bytes) */ - unsigned ndims; /* Number of dimensions */ + unsigned ndims; /* Number of dimensions in chunk */ + uint32_t *dim; /* Size of chunk in elements */ } H5D_bt2_ctx_t; /* User data for the chunk's removal callback routine */ @@ -242,6 +244,9 @@ const H5B2_class_t H5D_BT2_FILT[1] = {{ /* B-tree class information */ H5FL_DEFINE_STATIC(H5D_bt2_ctx_t); /* Declare a free list to manage the H5D_bt2_ctx_ud_t struct */ H5FL_DEFINE_STATIC(H5D_bt2_ctx_ud_t); +/* Declare a free list to manage the page elements */ +H5FL_BLK_DEFINE(chunk_dim); + @@ -262,6 +267,7 @@ H5D_bt2_crt_context(void *_udata) { H5D_bt2_ctx_ud_t *udata = (H5D_bt2_ctx_ud_t *)_udata; /* User data for building callback context */ H5D_bt2_ctx_t *ctx; /* Callback context structure */ + uint32_t *my_dim = NULL; /* Pointer to copy of chunk dimension size */ void *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -279,6 +285,12 @@ H5D_bt2_crt_context(void *_udata) ctx->sizeof_addr = H5F_SIZEOF_ADDR(udata->f); ctx->ndims = udata->ndims; + /* Set up the "local" information for this dataset's chunk dimension sizes */ + if(NULL == (my_dim = (uint32_t *)H5FL_BLK_MALLOC(chunk_dim, H5O_LAYOUT_NDIMS * sizeof(uint32_t)))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, NULL, "can't allocate chunk dims") + HDmemcpy(my_dim, udata->dim, H5O_LAYOUT_NDIMS * sizeof(uint32_t)); + ctx->dim = my_dim; + /* * Compute the size required for encoding the size of a chunk, * allowing for an extra byte, in case the filter makes the chunk larger. @@ -317,6 +329,10 @@ H5D_bt2_dst_context(void *_ctx) /* Sanity check */ HDassert(ctx); + if(ctx->dim) { + /* Free array for chunk dimension sizes */ + (void)H5FL_BLK_FREE(chunk_dim, ctx->dim); + } /* Release callback context */ ctx = H5FL_FREE(H5D_bt2_ctx_t, ctx); @@ -379,7 +395,7 @@ H5D_bt2_compare(const void *_udata, const void *_rec2) HDassert(rec2); /* Compare the offsets but ignore the other fields */ - ret_value = H5VM_vector_cmp_u(udata->ndims, rec1->offset, rec2->offset); + ret_value = H5VM_vector_cmp_u(udata->ndims, rec1->scaled, rec2->scaled); FUNC_LEAVE_NOAPI(ret_value) } /* H5D_bt2_compare() */ @@ -403,7 +419,8 @@ H5D_bt2_encode(uint8_t *raw, const void *_record, void *_ctx) { H5D_bt2_ctx_t *ctx = (H5D_bt2_ctx_t *)_ctx; /* Callback context structure */ const H5D_bt2_rec_t *record = (const H5D_bt2_rec_t *)_record; /* The native record */ - unsigned i; /* Local index varible */ + hsize_t tmp_offset; /* Temporary coordinate offset, from file */ + unsigned i; /* Local index varible */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -412,8 +429,11 @@ H5D_bt2_encode(uint8_t *raw, const void *_record, void *_ctx) /* Encode the record's fields */ H5F_addr_encode_len(ctx->sizeof_addr, &raw, record->addr); - for(i = 0; i < ctx->ndims; i++) - UINT64ENCODE(raw, record->offset[i]); + for(i = 0; i < ctx->ndims; i++) { + /* Compute coordinate offset from scaled offset */ + tmp_offset = record->scaled[i] * ctx->dim[i]; + UINT64ENCODE(raw, tmp_offset); + } FUNC_LEAVE_NOAPI(SUCCEED) } /* H5D_bt2_encode() */ @@ -437,7 +457,8 @@ H5D_bt2_decode(const uint8_t *raw, void *_record, void *_ctx) { H5D_bt2_ctx_t *ctx = (H5D_bt2_ctx_t *)_ctx; /* Callback context structure */ H5D_bt2_rec_t *record = (H5D_bt2_rec_t *)_record; /* The native record */ - unsigned i; /* Local index variable */ + hsize_t tmp_offset; /* Temporary coordinate offset, from file */ + unsigned i; /* Local index variable */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -446,8 +467,15 @@ H5D_bt2_decode(const uint8_t *raw, void *_record, void *_ctx) /* Decode the record's fields */ H5F_addr_decode_len(ctx->sizeof_addr, &raw, &record->addr); - for(i = 0; i < ctx->ndims; i++) - UINT64DECODE(raw, record->offset[i]); + for(i = 0; i < ctx->ndims; i++) { + + /* Retrieve coordinate offset */ + UINT64DECODE(raw, tmp_offset); + HDassert(0 == (tmp_offset % ctx->dim[i])); + + /* Convert to a scaled offset */ + record->scaled[i] = tmp_offset / ctx->dim[i]; + } FUNC_LEAVE_NOAPI(SUCCEED) } /* H5D_bt2_decode() */ @@ -480,7 +508,7 @@ H5D_bt2_debug(FILE *stream, const H5F_t UNUSED *f, hid_t UNUSED dxpl_id, HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Chunk address:", (unsigned)record->addr); HDfprintf(stream, "%*s%-*s {", indent, "", fwidth, "Logical offset:"); for(u = 0; u < u_ctx->ndims; u++) - HDfprintf(stream, "%s%Hd", u?", ":"", record->offset[u]); + HDfprintf(stream, "%s%Hd", u?", ":"", record->scaled[u] * u_ctx->dim[u]); HDfputs("}\n", stream); FUNC_LEAVE_NOAPI(SUCCEED) @@ -542,7 +570,7 @@ H5D_bt2_filt_compare(const void *_udata, const void *_rec2) HDassert(rec2); /* Compare the offsets but ignore the other fields */ - ret_value = H5VM_vector_cmp_u(udata->ndims, rec1->offset, rec2->offset); + ret_value = H5VM_vector_cmp_u(udata->ndims, rec1->scaled, rec2->scaled); FUNC_LEAVE_NOAPI(ret_value) } /* H5D_bt2_filt_compare() */ @@ -578,7 +606,7 @@ H5D_bt2_filt_encode(uint8_t *raw, const void *_record, void *_ctx) UINT64ENCODE_VAR(raw, record->nbytes, ctx->chunk_size_len); UINT32ENCODE(raw, record->filter_mask); for(i = 0; i < ctx->ndims; i++) - UINT64ENCODE(raw, record->offset[i]); + UINT64ENCODE(raw, record->scaled[i]); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5D_bt2_filt_encode() */ @@ -614,7 +642,7 @@ H5D_bt2_filt_decode(const uint8_t *raw, void *_record, void *_ctx) UINT64DECODE_VAR(raw, record->nbytes, ctx->chunk_size_len); UINT32DECODE(raw, record->filter_mask); for(i = 0; i < ctx->ndims; i++) - UINT64DECODE(raw, record->offset[i]); + UINT64DECODE(raw, record->scaled[i]); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5D_bt2_filt_decode() */ @@ -650,7 +678,7 @@ H5D_bt2_filt_debug(FILE *stream, const H5F_t UNUSED *f, hid_t UNUSED dxpl_id, HDfprintf(stream, "%*s%-*s {", indent, "", fwidth, "Logical offset:"); for(u = 0; u < u_ctx->ndims; u++) - HDfprintf(stream, "%s%Hd", u?", ":"", record->offset[u]); + HDfprintf(stream, "%s%Hd", u?", ":"", record->scaled[u] * u_ctx->dim[u]); HDfputs("}\n", stream); FUNC_LEAVE_NOAPI(SUCCEED) @@ -829,6 +857,7 @@ H5D_bt2_idx_open(const H5D_chk_idx_info_t *idx_info) u_ctx.f = idx_info->f; u_ctx.ndims = idx_info->layout->ndims - 1; u_ctx.chunk_size = idx_info->layout->size; + u_ctx.dim = idx_info->layout->dim; /* Check for SWMR writes to the file */ if(H5F_INTENT(idx_info->f) & H5F_ACC_SWMR_WRITE) { @@ -912,6 +941,7 @@ H5D_bt2_idx_create(const H5D_chk_idx_info_t *idx_info) u_ctx.f = idx_info->f; u_ctx.ndims = idx_info->layout->ndims - 1; u_ctx.chunk_size = idx_info->layout->size; + u_ctx.dim = idx_info->layout->dim; /* Check for SWMR writes to the file */ if(H5F_INTENT(idx_info->f) & H5F_ACC_SWMR_WRITE) { @@ -1057,13 +1087,13 @@ H5D_bt2_idx_insert_addr(const H5D_chk_idx_info_t *idx_info, H5D_chunk_ud_t *udat filt_rec.nbytes = udata->chunk_block.length; filt_rec.filter_mask = udata->filter_mask; for(u = 0; u < (idx_info->layout->ndims - 1); u++) - filt_rec.offset[u] = udata->common.offset[u]; + filt_rec.scaled[u] = udata->common.scaled[u]; } else { /* non-filtered chunk */ bt2_udata.rec = &rec; rec.addr = udata->chunk_block.offset; for(u = 0; u < (idx_info->layout->ndims - 1); u++) - rec.offset[u] = udata->common.offset[u]; + rec.scaled[u] = udata->common.scaled[u]; } if(udata->need_modify) { @@ -1185,7 +1215,7 @@ H5D_bt2_idx_get_addr(const H5D_chk_idx_info_t *idx_info, H5D_chunk_ud_t *udata) /* Set the chunk offset to be searched for */ for(u = 0; u < (idx_info->layout->ndims - 1); u++) - search_rec.offset[u] = udata->common.offset[u]; + search_rec.scaled[u] = udata->common.scaled[u]; found_rec.addr = HADDR_UNDEF; found_rec.nbytes = 0; @@ -1212,7 +1242,7 @@ H5D_bt2_idx_get_addr(const H5D_chk_idx_info_t *idx_info, H5D_chunk_ud_t *udata) /* Set the chunk offset to be searched for */ for(u = 0; u < (idx_info->layout->ndims - 1); u++) - search_rec.offset[u] = udata->common.offset[u]; + search_rec.scaled[u] = udata->common.scaled[u]; search_rec.addr = HADDR_UNDEF; found_rec.addr = HADDR_UNDEF; @@ -1275,7 +1305,7 @@ H5D_bt2_idx_iterate_cb(const void *_record, void *_udata) udata->chunk_rec.nbytes = filt_rec->nbytes; udata->chunk_rec.filter_mask = filt_rec->filter_mask; for(u = 0; u < (udata->common.layout->ndims - 1); u++) - udata->chunk_rec.offset[u] = filt_rec->offset[u]; + udata->chunk_rec.scaled[u] = filt_rec->scaled[u]; } /* end if */ else { /* non-filtered record */ const H5D_bt2_rec_t *rec = (const H5D_bt2_rec_t *)_record; @@ -1284,7 +1314,7 @@ H5D_bt2_idx_iterate_cb(const void *_record, void *_udata) udata->chunk_rec.nbytes = udata->common.layout->size; udata->chunk_rec.filter_mask = 0; for(u = 0; u < (udata->common.layout->ndims - 1); u++) - udata->chunk_rec.offset[u] = rec->offset[u]; + udata->chunk_rec.scaled[u] = rec->scaled[u]; } /* end else */ /* Make "generic chunk" callback */ @@ -1475,7 +1505,7 @@ H5D_bt2_idx_remove(const H5D_chk_idx_info_t *idx_info, H5D_chunk_common_ud_t *ud /* Initialize the record to search for */ for(u = 0; u < (idx_info->layout->ndims - 1); u++) - search_rec.offset[u] = udata->offset[u]; + search_rec.scaled[u] = udata->scaled[u]; bt2_udata.rec = &search_rec; bt2_udata.ndims = idx_info->layout->ndims - 1; @@ -1492,7 +1522,7 @@ H5D_bt2_idx_remove(const H5D_chk_idx_info_t *idx_info, H5D_chunk_common_ud_t *ud /* Initialize the record to search for */ for(u = 0; u < (idx_info->layout->ndims - 1); u++) - search_rec.offset[u] = udata->offset[u]; + search_rec.scaled[u] = udata->scaled[u]; bt2_udata.rec = &search_rec; bt2_udata.ndims = idx_info->layout->ndims - 1; @@ -1553,6 +1583,7 @@ H5D_bt2_idx_delete(const H5D_chk_idx_info_t *idx_info) u_ctx.f = idx_info->f; u_ctx.ndims = idx_info->layout->ndims - 1; u_ctx.chunk_size = idx_info->layout->size; + u_ctx.dim = idx_info->layout->dim; /* Initialize user data for removal callback */ remove_udata.f = idx_info->f; diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index 2f0be65..3e03e86 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -162,6 +162,7 @@ typedef struct H5D_chunk_it_ud4_t { FILE *stream; /* Output stream */ hbool_t header_displayed; /* Node's header is displayed? */ unsigned ndims; /* Number of dimensions for chunk/dataset */ + uint32_t *chunk_dim; /* Chunk dimensions */ } H5D_chunk_it_ud4_t; /* Callback info for nonexistent readvv operation */ @@ -233,10 +234,10 @@ static herr_t H5D__chunk_file_cb(void *elem, hid_t type_id, unsigned ndims, const hsize_t *coords, void *fm); static herr_t H5D__chunk_mem_cb(void *elem, hid_t type_id, unsigned ndims, const hsize_t *coords, void *fm); -static size_t H5D__chunk_hash_val(const H5D_shared_t *shared, const hsize_t *scaled); +static unsigned H5D__chunk_hash_val(const H5D_shared_t *shared, const hsize_t *scaled); static herr_t H5D__chunk_cache_evict(const H5D_t *dset, hid_t dxpl_id, const H5D_dxpl_cache_t *dxpl_cache, H5D_rdcc_ent_t *ent, hbool_t flush); -static hbool_t H5D__chunk_is_partial_edge_chunk(const hsize_t *chunk_offset, +static hbool_t H5D__chunk_is_partial_edge_chunk(const hsize_t *chunk_scaled, unsigned dset_ndims, const hsize_t *dset_dims, const uint32_t *chunk_dims); static herr_t H5D__chunk_cache_prune(const H5D_t *dset, hid_t dxpl_id, const H5D_dxpl_cache_t *dxpl_cache, size_t size); @@ -326,12 +327,9 @@ H5D__chunk_direct_write(const H5D_t *dset, hid_t dxpl_id, uint32_t filters, hsiz { const H5O_layout_t *layout = &(dset->shared->layout); /* Dataset layout */ H5D_chunk_ud_t udata; /* User data for querying chunk info */ - H5D_dxpl_cache_t _dxpl_cache; /* Data transfer property cache buffer */ - H5D_dxpl_cache_t *dxpl_cache = &_dxpl_cache; /* Data transfer property cache */ - const H5D_rdcc_t *rdcc = &(dset->shared->cache.chunk); /*raw data chunk cache */ + H5F_block_t old_chunk; /* Offset/length of old chunk */ H5D_chk_idx_info_t idx_info; /* Chunked index info */ hsize_t scaled[H5S_MAX_RANK]; /* Scaled coordinates for this chunk */ - H5F_block_t old_chunk; /* Offset/length of old chunk */ hbool_t need_insert = FALSE; /* Whether the chunk needs to be inserted into the index */ herr_t ret_value = SUCCEED; /* Return value */ @@ -345,9 +343,10 @@ H5D__chunk_direct_write(const H5D_t *dset, hid_t dxpl_id, uint32_t filters, hsiz /* Calculate the index of this chunk */ H5VM_chunk_scaled(dset->shared->ndims, offset, layout->u.chunk.dim, scaled); + scaled[dset->shared->ndims] = 0; /* Find out the file address of the chunk (if any) */ - if(H5D__chunk_lookup(dset, dxpl_id, offset, scaled, &udata) < 0) + if(H5D__chunk_lookup(dset, dxpl_id, scaled, &udata) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "error looking up chunk address") /* Sanity check */ @@ -569,7 +568,7 @@ H5D__chunk_construct(H5F_t UNUSED *f, H5D_t *dset) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "chunk size must be < 4GB") /* Retain computed chunk size */ - H5_ASSIGN_OVERFLOW(dset->shared->layout.u.chunk.size, chunk_size, uint64_t, uint32_t); + H5_CHECKED_ASSIGN(dset->shared->layout.u.chunk.size, uint32_t, chunk_size, uint64_t); /* Reset address and pointer of the array struct for the chunked storage index */ if(H5D_chunk_idx_reset(&dset->shared->layout.storage.u.chunk, TRUE) < 0) @@ -648,6 +647,22 @@ H5D__chunk_init(H5F_t *f, hid_t dxpl_id, const H5D_t *dset, hid_t dapl_id) H5D__chunk_cinfo_cache_reset(&(rdcc->last)); } /* end else */ + /* Compute scaled dimension info, if dataset dims > 1 */ + if(dset->shared->ndims > 1) { + unsigned u; /* Local index value */ + + for(u = 0; u < dset->shared->ndims; u++) { + /* Initial scaled dimension sizes */ + rdcc->scaled_dims[u] = dset->shared->curr_dims[u] / dset->shared->layout.u.chunk.dim[u]; + + /* Inital 'power2up' values for scaled dimensions */ + rdcc->scaled_power2up[u] = H5VM_power2up(rdcc->scaled_dims[u]); + + /* Number of bits required to encode scaled dimension size */ + rdcc->scaled_encode_bits[u] = H5VM_log2_gen(rdcc->scaled_power2up[u]); + } /* end for */ + } /* end if */ + /* Compose chunked index info struct */ idx_info.f = f; idx_info.dxpl_id = dxpl_id; @@ -749,7 +764,7 @@ H5D__chunk_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf if((sm_ndims = H5S_GET_EXTENT_NDIMS(mem_space)) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "unable to get dimension number") /* Set the number of dimensions for the memory dataspace */ - H5_ASSIGN_OVERFLOW(fm->m_ndims, sm_ndims, int, unsigned); + H5_CHECKED_ASSIGN(fm->m_ndims, unsigned, sm_ndims, int); /* Get rank for file dataspace */ fm->f_ndims = f_ndims = dataset->shared->layout.u.chunk.ndims - 1; @@ -1156,6 +1171,7 @@ H5D__create_chunk_map_single(H5D_chunk_map_t *fm, const H5D_io_info_t *io_info) { H5D_chunk_info_t *chunk_info; /* Chunk information to insert into skip list */ + hsize_t coords[H5O_LAYOUT_NDIMS]; /* Coordinates of chunk */ hsize_t sel_start[H5O_LAYOUT_NDIMS]; /* Offset of low bound of file selection */ hsize_t sel_end[H5O_LAYOUT_NDIMS]; /* Offset of high bound of file selection */ unsigned u; /* Local index variable */ @@ -1177,19 +1193,20 @@ H5D__create_chunk_map_single(H5D_chunk_map_t *fm, const H5D_io_info_t /* Set chunk location & hyperslab size */ for(u = 0; u < fm->f_ndims; u++) { HDassert(sel_start[u] == sel_end[u]); - chunk_info->coords[u] = (sel_start[u] / fm->layout->u.chunk.dim[u]) * fm->layout->u.chunk.dim[u]; + chunk_info->scaled[u] = sel_start[u] / fm->layout->u.chunk.dim[u]; + coords[u] = chunk_info->scaled[u] * fm->layout->u.chunk.dim[u]; } /* end for */ - chunk_info->coords[fm->f_ndims] = 0; + chunk_info->scaled[fm->f_ndims] = 0; /* Calculate the index of this chunk */ - chunk_info->index = H5VM_chunk_index_scaled(fm->f_ndims, chunk_info->coords, fm->layout->u.chunk.dim, fm->layout->u.chunk.down_chunks, chunk_info->scaled); + chunk_info->index = H5VM_array_offset_pre(fm->f_ndims, fm->layout->u.chunk.down_chunks, chunk_info->scaled); /* Copy selection for file's dataspace into chunk dataspace */ if(H5S_select_copy(fm->single_space, fm->file_space, FALSE) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy file selection") /* Move selection back to have correct offset in chunk */ - if(H5S_SELECT_ADJUST_U(fm->single_space, chunk_info->coords) < 0) + if(H5S_SELECT_ADJUST_U(fm->single_space, coords) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't adjust chunk selection") #ifdef H5_HAVE_PARALLEL @@ -1242,6 +1259,7 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t hsize_t coords[H5O_LAYOUT_NDIMS]; /* Current coordinates of chunk */ hsize_t end[H5O_LAYOUT_NDIMS]; /* Final coordinates of chunk */ hsize_t chunk_index; /* Index of chunk */ + hsize_t start_scaled[H5S_MAX_RANK]; /* Starting scaled coordinates of selection */ hsize_t scaled[H5S_MAX_RANK]; /* Scaled coordinates for this chunk */ int curr_dim; /* Current dimension to increment */ unsigned u; /* Local index variable */ @@ -1261,13 +1279,13 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t /* Set initial chunk location & hyperslab size */ for(u = 0; u < fm->f_ndims; u++) { - start_coords[u] = (sel_start[u] / fm->layout->u.chunk.dim[u]) * fm->layout->u.chunk.dim[u]; - coords[u] = start_coords[u]; + scaled[u] = start_scaled[u] = sel_start[u] / fm->layout->u.chunk.dim[u]; + coords[u] = start_coords[u] = scaled[u] * fm->layout->u.chunk.dim[u]; end[u] = (coords[u] + fm->chunk_dim[u]) - 1; } /* end for */ /* Calculate the index of this chunk */ - chunk_index = H5VM_chunk_index_scaled(fm->f_ndims, coords, fm->layout->u.chunk.dim, fm->layout->u.chunk.down_chunks, scaled); + chunk_index = H5VM_array_offset_pre(fm->f_ndims, fm->layout->u.chunk.down_chunks, scaled); /* Iterate through each chunk in the dataset */ while(sel_points) { @@ -1333,9 +1351,9 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t new_chunk_info->mspace=NULL; new_chunk_info->mspace_shared = FALSE; - /* Copy the chunk's coordinates */ - HDmemcpy(new_chunk_info->coords, coords, sizeof(hsize_t) * fm->f_ndims); - new_chunk_info->coords[fm->f_ndims] = 0; + /* Copy the chunk's scaled coordinates */ + HDmemcpy(new_chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); + new_chunk_info->scaled[fm->f_ndims] = 0; /* Copy the chunk's scaled coordinates */ HDmemcpy(new_chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); @@ -1349,7 +1367,7 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t /* Get number of elements selected in chunk */ if((schunk_points = H5S_GET_SELECT_NPOINTS(tmp_fchunk)) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get file selection # of elements") - H5_ASSIGN_OVERFLOW(new_chunk_info->chunk_points, schunk_points, hssize_t, uint32_t); + H5_CHECKED_ASSIGN(new_chunk_info->chunk_points, uint32_t, schunk_points, hssize_t); /* Decrement # of points left in file selection */ sel_points -= (hsize_t)schunk_points; @@ -1375,6 +1393,7 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t if(coords[curr_dim] > sel_end[curr_dim]) { do { /* Reset current dimension's location to 0 */ + scaled[curr_dim] = start_scaled[curr_dim]; coords[curr_dim] = start_coords[curr_dim]; /*lint !e771 The start_coords will always be initialized */ end[curr_dim] = (coords[curr_dim] + fm->chunk_dim[curr_dim]) - 1; @@ -1382,13 +1401,13 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t curr_dim--; /* Increment chunk location in current dimension */ + scaled[curr_dim]++; coords[curr_dim] += fm->chunk_dim[curr_dim]; end[curr_dim] = (coords[curr_dim] + fm->chunk_dim[curr_dim]) - 1; } while(coords[curr_dim] > sel_end[curr_dim]); /* Re-calculate the index of this chunk */ - /* (Technically, adjusting the scaled[] values could be moved inside loop above -QAK) */ - chunk_index = H5VM_chunk_index_scaled(fm->f_ndims, coords, fm->layout->u.chunk.dim, fm->layout->u.chunk.down_chunks, scaled); + chunk_index = H5VM_array_offset_pre(fm->f_ndims, fm->layout->u.chunk.down_chunks, scaled); } /* end if */ } /* end while */ @@ -1489,10 +1508,16 @@ H5D__create_chunk_mem_map_hyper(const H5D_chunk_map_t *fm) if(H5S_select_copy(chunk_info->mspace,chunk_info->fspace,FALSE) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy selection") - /* Compensate for the chunk offset */ - for(u=0; uf_ndims; u++) { - H5_CHECK_OVERFLOW(chunk_info->coords[u],hsize_t,hssize_t); - chunk_adjust[u]=adjust[u]-(hssize_t)chunk_info->coords[u]; /*lint !e771 The adjust array will always be initialized */ + /* Compute the adjustment for this chunk */ + for(u = 0; u < fm->f_ndims; u++) { + hsize_t coords[H5O_LAYOUT_NDIMS]; /* Current coordinates of chunk */ + + /* Compute the chunk coordinates from the scaled coordinates */ + coords[u] = chunk_info->scaled[u] * fm->layout->u.chunk.dim[u]; + + /* Compensate for the chunk offset */ + H5_CHECK_OVERFLOW(coords[u], hsize_t, hssize_t); + chunk_adjust[u] = adjust[u] - (hssize_t)coords[u]; /*lint !e771 The adjust array will always be initialized */ } /* end for */ /* Adjust the selection */ @@ -1587,12 +1612,9 @@ H5D__chunk_file_cb(void UNUSED *elem, hid_t UNUSED type_id, unsigned ndims, cons /* Set the number of selected elements in chunk to zero */ chunk_info->chunk_points = 0; - /* Compute the chunk's coordinates */ - for(u = 0; u < fm->f_ndims; u++) { - H5_CHECK_OVERFLOW(fm->layout->u.chunk.dim[u], hsize_t, hssize_t); - chunk_info->coords[u] = scaled[u] * (hssize_t)fm->layout->u.chunk.dim[u]; - } /* end for */ - chunk_info->coords[fm->f_ndims] = 0; + /* Set the chunk's scaled coordinates */ + HDmemcpy(chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); + chunk_info->scaled[fm->f_ndims] = 0; HDmemcpy(chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); /* Insert the new chunk into the skip list */ @@ -1615,7 +1637,7 @@ H5D__chunk_file_cb(void UNUSED *elem, hid_t UNUSED type_id, unsigned ndims, cons /* Get the offset of the element within the chunk */ for(u = 0; u < fm->f_ndims; u++) - coords_in_chunk[u] = coords[u] - chunk_info->coords[u]; + coords_in_chunk[u] = coords[u] - (scaled[u] * fm->layout->u.chunk.dim[u]); /* Add point to file selection for chunk */ if(H5S_select_elements(chunk_info->fspace, H5S_SELECT_APPEND, (size_t)1, coords_in_chunk) < 0) @@ -1739,7 +1761,7 @@ H5D__chunk_cacheable(const H5D_io_info_t *io_info, haddr_t caddr, hbool_t write_ if(dataset->shared->layout.u.chunk.flags & H5O_LAYOUT_CHUNK_DONT_FILTER_PARTIAL_BOUND_CHUNKS) { no_filters = H5D__chunk_is_partial_edge_chunk( - io_info->store->chunk.offset, io_info->dset->shared->ndims, + io_info->store->chunk.scaled, io_info->dset->shared->ndims, io_info->dset->shared->curr_dims, io_info->dset->shared->layout.u.chunk.dim); } /* end if */ @@ -1843,7 +1865,7 @@ H5D__chunk_read(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, ctg_io_info.layout_ops = *H5D_LOPS_CONTIG; /* Initialize temporary contiguous storage info */ - H5_ASSIGN_OVERFLOW(ctg_store.contig.dset_size, io_info->dset->shared->layout.u.chunk.size, uint32_t, hsize_t); + H5_CHECKED_ASSIGN(ctg_store.contig.dset_size, hsize_t, io_info->dset->shared->layout.u.chunk.size, uint32_t); /* Set up compact I/O info object */ HDmemcpy(&cpt_io_info, io_info, sizeof(cpt_io_info)); @@ -1881,7 +1903,7 @@ H5D__chunk_read(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, chunk_info = H5D_CHUNK_GET_NODE_INFO(fm, chunk_node); /* Get the info for the chunk in the file */ - if(H5D__chunk_lookup(io_info->dset, io_info->dxpl_id, chunk_info->coords, chunk_info->scaled, &udata) < 0) + if(H5D__chunk_lookup(io_info->dset, io_info->dxpl_id, chunk_info->scaled, &udata) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "error looking up chunk address") /* Sanity check */ @@ -1895,9 +1917,8 @@ H5D__chunk_read(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, void *chunk = NULL; /* Pointer to locked chunk buffer */ htri_t cacheable; /* Whether the chunk is cacheable */ - /* Pass in chunk's coordinates in a union. */ - io_info->store->chunk.offset = chunk_info->coords; - io_info->store->chunk.index = chunk_info->index; + /* Set chunk's [scaled] coordinates */ + io_info->store->chunk.scaled = chunk_info->scaled; /* Load the chunk into cache and lock it. */ /* Determine if we should use the chunk cache */ @@ -1905,6 +1926,7 @@ H5D__chunk_read(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't tell if chunk is cacheable") if(cacheable) { + /* Load the chunk into cache and lock it. */ /* Compute # of bytes accessed in chunk */ H5_CHECK_OVERFLOW(type_info->src_type_size, /*From:*/ size_t, /*To:*/ uint32_t); @@ -1991,7 +2013,7 @@ H5D__chunk_write(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, ctg_io_info.layout_ops = *H5D_LOPS_CONTIG; /* Initialize temporary contiguous storage info */ - H5_ASSIGN_OVERFLOW(ctg_store.contig.dset_size, io_info->dset->shared->layout.u.chunk.size, uint32_t, hsize_t); + H5_CHECKED_ASSIGN(ctg_store.contig.dset_size, hsize_t, io_info->dset->shared->layout.u.chunk.size, uint32_t); /* Set up compact I/O info object */ HDmemcpy(&cpt_io_info, io_info, sizeof(cpt_io_info)); @@ -2016,16 +2038,15 @@ H5D__chunk_write(H5D_io_info_t *io_info, const H5D_type_info_t *type_info, chunk_info = H5D_CHUNK_GET_NODE_INFO(fm, chunk_node); /* Look up the chunk */ - if(H5D__chunk_lookup(io_info->dset, io_info->dxpl_id, chunk_info->coords, chunk_info->scaled, &udata) < 0) + if(H5D__chunk_lookup(io_info->dset, io_info->dxpl_id, chunk_info->scaled, &udata) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "error looking up chunk address") /* Sanity check */ HDassert((H5F_addr_defined(udata.chunk_block.offset) && udata.chunk_block.length > 0) || (!H5F_addr_defined(udata.chunk_block.offset) && udata.chunk_block.length == 0)); - /* Pass in chunk's coordinates in a union. */ - io_info->store->chunk.offset = &chunk_info->coords[0]; - io_info->store->chunk.index = chunk_info->index; + /* Set chunk's [scaled] coordinates */ + io_info->store->chunk.scaled = chunk_info->scaled; /* Determine if we should use the chunk cache */ if((cacheable = H5D__chunk_cacheable(io_info, udata.chunk_block.offset, TRUE)) < 0) @@ -2305,13 +2326,12 @@ H5D__chunk_cinfo_cache_update(H5D_chunk_cached_t *last, const H5D_chunk_ud_t *ud HDassert(last); HDassert(udata); HDassert(udata->common.layout); - HDassert(udata->common.storage); - HDassert(udata->common.offset); + HDassert(udata->common.scaled); /* Stored the information to cache */ - HDmemcpy(last->offset, udata->common.offset, sizeof(hsize_t) * udata->common.layout->ndims); + HDmemcpy(last->scaled, udata->common.scaled, sizeof(hsize_t) * udata->common.layout->ndims); last->addr = udata->chunk_block.offset; - H5_ASSIGN_OVERFLOW(last->nbytes, udata->chunk_block.length, hsize_t, uint32_t); + H5_CHECKED_ASSIGN(last->nbytes, uint32_t, udata->chunk_block.length, hsize_t); last->chunk_idx = udata->chunk_idx; last->filter_mask = udata->filter_mask; @@ -2345,16 +2365,15 @@ H5D__chunk_cinfo_cache_found(const H5D_chunk_cached_t *last, H5D_chunk_ud_t *uda HDassert(last); HDassert(udata); HDassert(udata->common.layout); - HDassert(udata->common.storage); - HDassert(udata->common.offset); + HDassert(udata->common.scaled); /* Check if the cached information is what is desired */ if(last->valid) { unsigned u; /* Local index variable */ - /* Check that the offset is the same */ + /* Check that the scaled offset is the same */ for(u = 0; u < udata->common.layout->ndims; u++) - if(last->offset[u] != udata->common.offset[u]) + if(last->scaled[u] != udata->common.scaled[u]) HGOTO_DONE(FALSE) /* Retrieve the information from the cache */ @@ -2433,6 +2452,7 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5D__chunk_create() */ + /*------------------------------------------------------------------------- * Function: H5D__chunk_hash_val @@ -2446,12 +2466,12 @@ done: * *------------------------------------------------------------------------- */ -static size_t +static unsigned H5D__chunk_hash_val(const H5D_shared_t *shared, const hsize_t *scaled) { - hsize_t val; /* Intermediate value */ - size_t ret; /* Value to return */ - unsigned ndims = shared->layout.u.chunk.ndims - 1; /* Rank of dataset */ + hsize_t val; /* Intermediate value */ + unsigned ndims = shared->ndims; /* Rank of dataset */ + unsigned ret; /* Value to return */ FUNC_ENTER_STATIC_NOERR @@ -2462,12 +2482,12 @@ H5D__chunk_hash_val(const H5D_shared_t *shared, const hsize_t *scaled) /* If the fastest changing dimension doesn't have enough entropy, use * other dimensions too */ - if(ndims > 1 && shared->curr_dims[ndims - 1] <= shared->cache.chunk.nslots) { + if(ndims > 1 && shared->cache.chunk.scaled_dims[ndims - 1] <= shared->cache.chunk.nslots) { unsigned u; /* Local index variable */ val = scaled[0]; for(u = 1; u < ndims; u++) { - val <<= H5VM_log2_gen(H5VM_power2up(shared->curr_dims[u])); + val <<= shared->cache.chunk.scaled_encode_bits[u]; val ^= scaled[u]; } /* end for */ } /* end if */ @@ -2475,7 +2495,7 @@ H5D__chunk_hash_val(const H5D_shared_t *shared, const hsize_t *scaled) val = scaled[ndims - 1]; /* Modulo value against the number of array slots */ - ret = val % shared->cache.chunk.nslots; + ret = (unsigned)(val % shared->cache.chunk.nslots); FUNC_LEAVE_NOAPI(ret) } /* H5D__chunk_hash_val() */ @@ -2495,8 +2515,8 @@ H5D__chunk_hash_val(const H5D_shared_t *shared, const hsize_t *scaled) *------------------------------------------------------------------------- */ herr_t -H5D__chunk_lookup(const H5D_t *dset, hid_t dxpl_id, const hsize_t *chunk_offset, - const hsize_t *scaled, H5D_chunk_ud_t *udata) +H5D__chunk_lookup(const H5D_t *dset, hid_t dxpl_id, const hsize_t *scaled, + H5D_chunk_ud_t *udata) { H5D_rdcc_ent_t *ent = NULL; /* Cache entry */ hbool_t found = FALSE; /* In cache? */ @@ -2517,14 +2537,12 @@ H5D__chunk_lookup(const H5D_t *dset, hid_t dxpl_id, const hsize_t *chunk_offset, H5D_COPS_BTREE == dset->shared->layout.storage.u.chunk.ops) || (H5D_CHUNK_IDX_NONE == dset->shared->layout.storage.u.chunk.idx_type && H5D_COPS_NONE == dset->shared->layout.storage.u.chunk.ops)); - HDassert(chunk_offset); + HDassert(scaled); HDassert(udata); /* Initialize the query information about the chunk we are looking for */ udata->common.layout = &(dset->shared->layout.u.chunk); udata->common.storage = &(dset->shared->layout.storage.u.chunk); - udata->common.offset = chunk_offset; - udata->common.space_dim = dset->shared->curr_dims; udata->common.scaled = scaled; /* Reset information about the chunk we are looking for */ @@ -2541,7 +2559,7 @@ H5D__chunk_lookup(const H5D_t *dset, hid_t dxpl_id, const hsize_t *chunk_offset, if(ent) for(u = 0, found = TRUE; u < dset->shared->ndims; u++) - if(chunk_offset[u] != ent->offset[u]) { + if(scaled[u] != ent->scaled[u]) { found = FALSE; break; } /* end if */ @@ -2633,7 +2651,6 @@ H5D__chunk_flush_entry(const H5D_t *dset, hid_t dxpl_id, const H5D_dxpl_cache_t /* Set up user data for index callbacks */ udata.common.layout = &dset->shared->layout.u.chunk; udata.common.storage = &dset->shared->layout.storage.u.chunk; - udata.common.offset = ent->offset; udata.common.scaled = ent->scaled; udata.chunk_block.offset = ent->chunk_block.offset; udata.chunk_block.length = dset->shared->layout.u.chunk.size; @@ -2668,7 +2685,7 @@ H5D__chunk_flush_entry(const H5D_t *dset, hid_t dxpl_id, const H5D_dxpl_cache_t point_of_no_return = TRUE; ent->chunk = NULL; } /* end else */ - H5_ASSIGN_OVERFLOW(nbytes, udata.chunk_block.length, hsize_t, size_t); + H5_CHECKED_ASSIGN(nbytes, size_t, udata.chunk_block.length, hsize_t); if(H5Z_pipeline(&(dset->shared->dcpl_cache.pline), 0, &(udata.filter_mask), dxpl_cache->err_detect, dxpl_cache->filter_cb, &nbytes, &alloc, &buf) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTFILTER, FAIL, "output pipeline failed") @@ -2677,7 +2694,7 @@ H5D__chunk_flush_entry(const H5D_t *dset, hid_t dxpl_id, const H5D_dxpl_cache_t if(nbytes > ((size_t)0xffffffff)) HGOTO_ERROR(H5E_DATASET, H5E_BADRANGE, FAIL, "chunk too large for 32-bit length") #endif /* H5_SIZEOF_SIZE_T > 4 */ - H5_ASSIGN_OVERFLOW(udata.chunk_block.length, nbytes, size_t, hsize_t); + H5_CHECKED_ASSIGN(udata.chunk_block.length, hsize_t, nbytes, size_t); /* Indicate that the chunk must be allocated */ must_alloc = TRUE; @@ -3024,7 +3041,7 @@ H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, /* Get the chunk's size */ HDassert(layout->u.chunk.size > 0); - H5_ASSIGN_OVERFLOW(chunk_size, layout->u.chunk.size, uint32_t, size_t); + H5_CHECKED_ASSIGN(chunk_size, size_t, layout->u.chunk.size, uint32_t); /* Check if the chunk is in the cache */ if(UINT_MAX != udata->idx_hint) { @@ -3040,8 +3057,8 @@ H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, unsigned u; /*counters */ /* Make sure this is the right chunk */ - for(u = 0; u < layout->u.chunk.ndims; u++) - HDassert(io_info->store->chunk.offset[u] == ent->offset[u]); + for(u = 0; u < layout->u.chunk.ndims - 1; u++) + HDassert(io_info->store->chunk.scaled[u] == ent->scaled[u]); } #endif /* NDEBUG */ @@ -3161,7 +3178,7 @@ H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, & H5O_LAYOUT_CHUNK_DONT_FILTER_PARTIAL_BOUND_CHUNKS) { /* Check if this is an edge chunk */ if(H5D__chunk_is_partial_edge_chunk( - io_info->store->chunk.offset, io_info->dset->shared->ndims, + io_info->store->chunk.scaled, io_info->dset->shared->ndims, io_info->dset->shared->curr_dims, layout->u.chunk.dim)) { /* Disable the filters for both writing and reading */ disable_filters = TRUE; @@ -3279,7 +3296,7 @@ H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, /* See if the chunk can be cached */ if(rdcc->nslots > 0 && chunk_size <= rdcc->nbytes_max) { /* Calculate the index */ - udata->idx_hint = H5D__chunk_hash_val(io_info->dset->shared, udata->common.scaled); + udata->idx_hint = H5D__chunk_hash_val(io_info->dset->shared, udata->common.scaled); /* Add the chunk to the cache only if the slot is not already locked */ ent = rdcc->slot[udata->idx_hint]; @@ -3307,11 +3324,9 @@ H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, ent->chunk_block.offset = chunk_addr; ent->chunk_block.length = chunk_alloc; ent->chunk_idx = udata->chunk_idx; - HDmemcpy(ent->offset, io_info->store->chunk.offset, sizeof(hsize_t) * layout->u.chunk.ndims); - HDmemcpy(ent->scaled, udata->common.scaled, sizeof(hsize_t) * layout->u.chunk.ndims); - - H5_ASSIGN_OVERFLOW(ent->rd_count, chunk_size, size_t, uint32_t); - H5_ASSIGN_OVERFLOW(ent->wr_count, chunk_size, size_t, uint32_t); + HDmemcpy(ent->scaled, udata->common.scaled, sizeof(hsize_t) * layout->u.chunk.ndims); + H5_CHECKED_ASSIGN(ent->rd_count, uint32_t, chunk_size, size_t); + H5_CHECKED_ASSIGN(ent->wr_count, uint32_t, chunk_size, size_t); ent->chunk = (uint8_t *)chunk; /* Add it to the cache */ @@ -3427,7 +3442,7 @@ H5D__chunk_unlock(const H5D_io_info_t *io_info, const H5D_chunk_ud_t *udata, & H5O_LAYOUT_CHUNK_DONT_FILTER_PARTIAL_BOUND_CHUNKS) { /* Check if the chunk is an edge chunk, and disable filters if so */ is_unfiltered_edge_chunk = H5D__chunk_is_partial_edge_chunk( - io_info->store->chunk.offset, io_info->dset->shared->ndims, + io_info->store->chunk.scaled, io_info->dset->shared->ndims, io_info->dset->shared->curr_dims, layout->u.chunk.dim); } /* end if */ @@ -3440,7 +3455,7 @@ H5D__chunk_unlock(const H5D_io_info_t *io_info, const H5D_chunk_ud_t *udata, fake_ent.edge_chunk_state = H5D_RDCC_DISABLE_FILTERS; if(udata->new_unfilt_chunk) fake_ent.edge_chunk_state |= H5D_RDCC_NEWLY_DISABLED_FILTERS; - HDmemcpy(fake_ent.offset, io_info->store->chunk.offset, layout->u.chunk.ndims * sizeof(fake_ent.offset[0])); + HDmemcpy(fake_ent.scaled, udata->common.scaled, sizeof(hsize_t) * layout->u.chunk.ndims); HDmemcpy(fake_ent.scaled, udata->common.scaled, sizeof(hsize_t) * layout->u.chunk.ndims); HDassert(layout->u.chunk.size > 0); fake_ent.chunk_idx = udata->chunk_idx; @@ -3601,9 +3616,9 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, { H5D_chk_idx_info_t idx_info; /* Chunked index info */ const H5D_chunk_ops_t *ops = dset->shared->layout.storage.u.chunk.ops; /* Chunk operations */ - hsize_t min_unalloc[H5O_LAYOUT_NDIMS]; /* First chunk in each dimension that is unallocated */ - hsize_t max_unalloc[H5O_LAYOUT_NDIMS]; /* Last chunk in each dimension that is unallocated */ - hsize_t chunk_offset[H5O_LAYOUT_NDIMS]; /* Offset of current chunk */ + hsize_t min_unalloc[H5O_LAYOUT_NDIMS]; /* First chunk in each dimension that is unallocated (in scaled coordinates) */ + hsize_t max_unalloc[H5O_LAYOUT_NDIMS]; /* Last chunk in each dimension that is unallocated (in scaled coordinates) */ + hsize_t scaled[H5O_LAYOUT_NDIMS]; /* Offset of current chunk (in scaled coordinates) */ size_t orig_chunk_size; /* Original size of chunk in bytes */ size_t chunk_size; /* Actual size of chunk in bytes, possibly filtered */ unsigned filter_mask = 0; /* Filter mask for chunks that have them */ @@ -3631,7 +3646,7 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, hbool_t fb_info_init = FALSE; /* Whether the fill value buffer has been initialized */ hbool_t has_unfilt_edge_chunks = FALSE; /* Whether there are partial edge chunks with disabled filters */ hbool_t unfilt_edge_chunk_dim[H5O_LAYOUT_NDIMS]; /* Whether there are unfiltered edge chunks at the edge of each dimension */ - hsize_t edge_chunk_offset[H5O_LAYOUT_NDIMS]; /* Offset of the unfiltered edge chunks at the edge of each dimension */ + hsize_t edge_chunk_scaled[H5O_LAYOUT_NDIMS]; /* Offset of the unfiltered edge chunks at the edge of each dimension */ unsigned nunfilt_edge_chunk_dims = 0; /* Number of dimensions on an edge */ herr_t ret_value = SUCCEED; /* Return value */ @@ -3656,8 +3671,8 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, space_dim = dset->shared->curr_dims; space_ndims = dset->shared->ndims; - /* The last dimension in chunk_offset is always 0 */ - chunk_offset[space_ndims] = (hsize_t)0; + /* The last dimension in scaled chunk coordinates is always 0 */ + scaled[space_ndims] = (hsize_t)0; /* Check if any space dimensions are 0, if so we do not have to do anything */ @@ -3689,13 +3704,11 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, * assume here that all elements of space_dim are > 0. This is checked at * the top of this function. */ for(op_dim=0; op_dimu.chunk.flags & H5O_LAYOUT_CHUNK_DONT_FILTER_PARTIAL_BOUND_CHUNKS) @@ -3703,14 +3716,14 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, && space_dim[op_dim] % chunk_dim[op_dim] != 0) { has_unfilt_edge_chunks = TRUE; unfilt_edge_chunk_dim[op_dim] = TRUE; - edge_chunk_offset[op_dim] = max_unalloc[op_dim]; + edge_chunk_scaled[op_dim] = max_unalloc[op_dim]; } /* end if */ else unfilt_edge_chunk_dim[op_dim] = FALSE; } /* end for */ /* Get original chunk size */ - H5_ASSIGN_OVERFLOW(orig_chunk_size, layout->u.chunk.size, uint32_t, size_t); + H5_CHECKED_ASSIGN(orig_chunk_size, size_t, layout->u.chunk.size, uint32_t); /* Check the dataset's fill-value status */ if(H5P_is_fill_value_defined(fill, &fill_status) < 0) @@ -3795,6 +3808,9 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, * Every time the algorithm finishes allocating chunks allocated beyond a * certain dimension, max_unalloc is updated in order to avoid allocating * those chunks again. + * + * Note that min_unalloc & max_unalloc are in scaled coordinates. + * */ chunk_size = orig_chunk_size; for(op_dim = 0; op_dim < space_ndims; op_dim++) { @@ -3807,15 +3823,15 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, continue; else { /* Reset the chunk offset indices */ - HDmemset(chunk_offset, 0, (space_ndims * sizeof(chunk_offset[0]))); - chunk_offset[op_dim] = min_unalloc[op_dim]; + HDmemset(scaled, 0, (space_ndims * sizeof(scaled[0]))); + scaled[op_dim] = min_unalloc[op_dim]; if(has_unfilt_edge_chunks) { /* Initialize nunfilt_edge_chunk_dims */ nunfilt_edge_chunk_dims = 0; for(u = 0; u < space_ndims; u++) - if(unfilt_edge_chunk_dim[u] && chunk_offset[u] - == edge_chunk_offset[u]) + if(unfilt_edge_chunk_dim[u] && scaled[u] + == edge_chunk_scaled[u]) nunfilt_edge_chunk_dims++; /* Initialize chunk_size and fill_buf */ @@ -3838,18 +3854,15 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, while(!carry) { /* None of the chunks should be allocated */ - hsize_t scaled[H5O_LAYOUT_NDIMS]; /* Scaled coordinates for this chunk */ hbool_t need_insert = FALSE; /* Whether the chunk needs to be inserted into the index */ /* Reset size of chunk in bytes, in case filtered size changes */ /* chunk_size = orig_chunk_size; */ /* Look up this chunk */ - H5VM_chunk_scaled(space_ndims, chunk_offset, layout->u.chunk.dim, scaled); - if(H5D__chunk_lookup(dset, dxpl_id, chunk_offset, scaled, &udata) < 0) + if(H5D__chunk_lookup(dset, dxpl_id, scaled, &udata) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "error looking up chunk address") #ifndef NDEBUG - if(H5D_CHUNK_IDX_NONE != layout->storage.u.chunk.idx_type) HDassert(!H5F_addr_defined(udata.chunk_block.offset)); @@ -3859,8 +3872,8 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, unsigned u; /* Local index variable */ hbool_t outside_orig = FALSE; for(u = 0; u < space_ndims; u++) { - HDassert(chunk_offset[u] < space_dim[u]); - if(chunk_offset[u] >= old_dim[u]) + HDassert((scaled[u] * chunk_dim[u]) < space_dim[u]); + if((scaled[u] * chunk_dim[u]) >= old_dim[u]) outside_orig = TRUE; } /* end for */ HDassert(outside_orig); @@ -3915,10 +3928,10 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, /* Initialize the chunk information */ udata.common.layout = &layout->u.chunk; udata.common.storage = &layout->storage.u.chunk; - udata.common.offset = chunk_offset; + udata.common.scaled = scaled; udata.common.rdcc = &dset->shared->cache.chunk; udata.chunk_block.offset = HADDR_UNDEF; - H5_ASSIGN_OVERFLOW(udata.chunk_block.length, chunk_size, size_t, uint32_t); + H5_CHECKED_ASSIGN(udata.chunk_block.length, uint32_t, chunk_size, size_t); udata.filter_mask = filter_mask; udata.need_modify = FALSE; @@ -3970,22 +3983,21 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, /* Increment indices and adjust the edge chunk state */ carry = TRUE; for(i = ((int)space_ndims - 1); i >= 0; --i) { - chunk_offset[i] += chunk_dim[i]; - if(chunk_offset[i] > max_unalloc[i]) { + scaled[i]++; + if(scaled[i] > max_unalloc[i]) { if((unsigned)i == op_dim) - chunk_offset[i] = min_unalloc[i]; + scaled[i] = min_unalloc[i]; else - chunk_offset[i] = 0; + scaled[i] = 0; /* Check if we just left the edge in this dimension */ if(unfilt_edge_chunk_dim[i] - && edge_chunk_offset[i] == max_unalloc[i] - && chunk_offset[i] < edge_chunk_offset[i]) { + && edge_chunk_scaled[i] == max_unalloc[i] + && scaled[i] < edge_chunk_scaled[i]) { nunfilt_edge_chunk_dims--; if(should_fill && nunfilt_edge_chunk_dims == 0 && !fb_info.has_vlen_fill_type) { - HDassert(!H5D__chunk_is_partial_edge_chunk( - chunk_offset, space_ndims, + HDassert(!H5D__chunk_is_partial_edge_chunk(scaled, space_ndims, space_dim, chunk_dim)); fill_buf = &fb_info.fill_buf; chunk_size = orig_chunk_size; @@ -3994,14 +4006,13 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, } /* end if */ else { /* Check if we just entered the edge in this dimension */ - if(unfilt_edge_chunk_dim[i] && chunk_offset[i] - == edge_chunk_offset[i]) { - HDassert(edge_chunk_offset[i] == max_unalloc[i]); + if(unfilt_edge_chunk_dim[i] && scaled[i] + == edge_chunk_scaled[i]) { + HDassert(edge_chunk_scaled[i] == max_unalloc[i]); nunfilt_edge_chunk_dims++; if(should_fill && nunfilt_edge_chunk_dims == 1 && !fb_info.has_vlen_fill_type) { - HDassert(H5D__chunk_is_partial_edge_chunk( - chunk_offset, space_ndims, + HDassert(H5D__chunk_is_partial_edge_chunk(scaled, space_ndims, space_dim, chunk_dim)); fill_buf = &unfilt_fill_buf; chunk_size = layout->u.chunk.size; @@ -4020,7 +4031,7 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite, if(min_unalloc[op_dim] == 0) break; else - max_unalloc[op_dim] = min_unalloc[op_dim] - chunk_dim[op_dim]; + max_unalloc[op_dim] = min_unalloc[op_dim] - 1; } /* end for(op_dim=0...) */ #ifdef H5_HAVE_PARALLEL @@ -4069,12 +4080,12 @@ done: herr_t H5D__chunk_update_old_edge_chunks(H5D_t *dset, hid_t dxpl_id, hsize_t old_dim[]) { - hsize_t old_edge_chunk_off[H5O_LAYOUT_NDIMS]; /* Offset of first previously incomplete chunk in each dimension */ - hsize_t max_edge_chunk_off[H5O_LAYOUT_NDIMS]; /* largest offset of chunks that might need to be modified in each dimension */ + hsize_t old_edge_chunk_sc[H5O_LAYOUT_NDIMS]; /* Offset of first previously incomplete chunk in each dimension */ + hsize_t max_edge_chunk_sc[H5O_LAYOUT_NDIMS]; /* largest offset of chunks that might need to be modified in each dimension */ hbool_t new_full_dim[H5O_LAYOUT_NDIMS]; /* Whether the plane of chunks in this dimension needs to be modified */ const H5O_layout_t *layout = &(dset->shared->layout); /* Dataset layout */ const H5O_pline_t *pline = &(dset->shared->dcpl_cache.pline); /* I/O pipeline info */ - hsize_t chunk_offset[H5O_LAYOUT_NDIMS]; /* Offset of current chunk */ + hsize_t chunk_sc[H5O_LAYOUT_NDIMS]; /* Offset of current chunk */ const uint32_t *chunk_dim = layout->u.chunk.dim; /* Convenience pointer to chunk dimensions */ unsigned space_ndims; /* Dataset's space rank */ const hsize_t *space_dim; /* Dataset's dataspace dimensions */ @@ -4113,7 +4124,7 @@ H5D__chunk_update_old_edge_chunks(H5D_t *dset, hid_t dxpl_id, hsize_t old_dim[]) space_ndims = dset->shared->ndims; /* The last dimension in chunk_offset is always 0 */ - chunk_offset[space_ndims] = (hsize_t)0; + chunk_sc[space_ndims] = (hsize_t)0; /* Check if any current dimensions are smaller than the chunk size, or if * any old dimensions are 0. If so we do not have to do anything. */ @@ -4134,7 +4145,7 @@ H5D__chunk_update_old_edge_chunks(H5D_t *dset, hid_t dxpl_id, hsize_t old_dim[]) /* Set up chunked I/O info object, for operations on chunks (in callback). * Note that we only need to set chunk_offset once, as the array's address * will never change. */ - chk_store.chunk.offset = chunk_offset; + chk_store.chunk.scaled = chunk_sc; H5D_BUILD_IO_INFO_RD(&chk_io_info, dset, dxpl_cache, dxpl_id, &chk_store, NULL); /* @@ -4146,14 +4157,12 @@ H5D__chunk_update_old_edge_chunks(H5D_t *dset, hid_t dxpl_id, hsize_t old_dim[]) /* Calulate offset of first previously incomplete chunk in this * dimension */ - old_edge_chunk_off[op_dim] = (old_dim[op_dim] / chunk_dim[op_dim]) - * chunk_dim[op_dim]; + old_edge_chunk_sc[op_dim] = (old_dim[op_dim] / chunk_dim[op_dim]); /* Calculate the largest offset of chunks that might need to be * modified in this dimension */ - max_edge_chunk_off[op_dim] = chunk_dim[op_dim] - * MIN((old_dim[op_dim] - 1) / chunk_dim[op_dim], - MAX((space_dim[op_dim] / chunk_dim[op_dim]), 1) - 1); + max_edge_chunk_sc[op_dim] = MIN((old_dim[op_dim] - 1) / chunk_dim[op_dim], + MAX((space_dim[op_dim] / chunk_dim[op_dim]), 1) - 1); /* Check for old_dim aligned with chunk boundary in this dimension, if * so we do not need to modify chunks along the edge in this dimension @@ -4163,7 +4172,7 @@ H5D__chunk_update_old_edge_chunks(H5D_t *dset, hid_t dxpl_id, hsize_t old_dim[]) /* Check if the dataspace expanded enough to cause the old edge chunks * in this dimension to become full */ - if(space_dim[op_dim] >= old_edge_chunk_off[op_dim] + chunk_dim[op_dim]) + if((space_dim[op_dim]/chunk_dim[op_dim]) >= (old_edge_chunk_sc[op_dim] + 1)) new_full_dim[op_dim] = TRUE; } /* end for */ @@ -4173,28 +4182,24 @@ H5D__chunk_update_old_edge_chunks(H5D_t *dset, hid_t dxpl_id, hsize_t old_dim[]) if(!new_full_dim[op_dim]) continue; else { - HDassert(max_edge_chunk_off[op_dim] == old_edge_chunk_off[op_dim]); + HDassert(max_edge_chunk_sc[op_dim] == old_edge_chunk_sc[op_dim]); /* Reset the chunk offset indices */ - HDmemset(chunk_offset, 0, (space_ndims * sizeof(chunk_offset[0]))); - chunk_offset[op_dim] = old_edge_chunk_off[op_dim]; + HDmemset(chunk_sc, 0, (space_ndims * sizeof(chunk_sc[0]))); + chunk_sc[op_dim] = old_edge_chunk_sc[op_dim]; carry = FALSE; } /* end if */ while(!carry) { - hsize_t scaled[H5O_LAYOUT_NDIMS]; /* Scaled coordinates for this chunk */ int i; /* Local index variable */ /* Make sure the chunk is really a former edge chunk */ - HDassert(H5D__chunk_is_partial_edge_chunk(chunk_offset, space_ndims, old_dim, chunk_dim) - && !H5D__chunk_is_partial_edge_chunk(chunk_offset, space_ndims, space_dim, chunk_dim)); - - /* Compute the scaled coordinates */ - H5VM_chunk_scaled(space_ndims, chunk_offset, chunk_dim, scaled); + HDassert(H5D__chunk_is_partial_edge_chunk(chunk_sc, space_ndims, old_dim, chunk_dim) + && !H5D__chunk_is_partial_edge_chunk(chunk_sc, space_ndims, space_dim, chunk_dim)); /* Lookup the chunk */ - if(H5D__chunk_lookup(dset, dxpl_id, chunk_offset, scaled, &chk_udata) < 0) + if(H5D__chunk_lookup(dset, dxpl_id, chunk_sc, &chk_udata) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "error looking up chunk address") /* If this chunk does not exist in cache or on disk, no need to do @@ -4215,9 +4220,9 @@ H5D__chunk_update_old_edge_chunks(H5D_t *dset, hid_t dxpl_id, hsize_t old_dim[]) carry = TRUE; for(i = ((int)space_ndims - 1); i >= 0; --i) { if((unsigned)i != op_dim) { - chunk_offset[i] += chunk_dim[i]; - if(chunk_offset[i] > (hsize_t) max_edge_chunk_off[i]) - chunk_offset[i] = 0; + ++chunk_sc[i]; + if(chunk_sc[i] > (hsize_t) max_edge_chunk_sc[i]) + chunk_sc[i] = 0; else { carry = FALSE; break; @@ -4226,13 +4231,13 @@ H5D__chunk_update_old_edge_chunks(H5D_t *dset, hid_t dxpl_id, hsize_t old_dim[]) } /* end for */ } /* end while(!carry) */ - /* Adjust max_edge_chunk_off so we don't modify the same chunk twice. + /* Adjust max_edge_chunk_sc so we don't modify the same chunk twice. * Also check if this dimension started from 0 (and hence modified all * of the old edge chunks. */ - if(old_edge_chunk_off[op_dim] == 0) + if(old_edge_chunk_sc[op_dim] == 0) break; else - --max_edge_chunk_off[op_dim]; + --max_edge_chunk_sc[op_dim]; } /* end for(op_dim=0...) */ /* Reset any cached chunk info for this dataset */ @@ -4303,9 +4308,9 @@ H5D__chunk_collective_fill(const H5D_t *dset, hid_t dxpl_id, leftover_blocks = chunk_info->num_io % mpi_size; /* Cast values to types needed by MPI */ - H5_ASSIGN_OVERFLOW(blocks, num_blocks, size_t, int); - H5_ASSIGN_OVERFLOW(leftover, leftover_blocks, size_t, int); - H5_ASSIGN_OVERFLOW(block_len, chunk_size, size_t, int); + H5_CHECKED_ASSIGN(blocks, int, num_blocks, size_t); + H5_CHECKED_ASSIGN(leftover, int, leftover_blocks, size_t); + H5_CHECKED_ASSIGN(block_len, int, chunk_size, size_t); /* Allocate buffers */ /* (MSC - should not need block_lens if MPI_type_create_hindexed_block is working) */ @@ -4418,7 +4423,7 @@ H5D__chunk_prune_fill(H5D_chunk_it_ud1_t *udata, hbool_t new_unfilt_chunk) const H5D_t *dset = io_info->dset; /* Local pointer to the dataset info */ const H5O_layout_t *layout = &(dset->shared->layout); /* Dataset's layout */ unsigned rank = udata->common.layout->ndims - 1; /* Dataset rank */ - const hsize_t *chunk_offset = io_info->store->chunk.offset; /* Chunk offset */ + const hsize_t *scaled = udata->common.scaled; /* Scaled chunk offset */ H5S_sel_iter_t chunk_iter; /* Memory selection iteration info */ hssize_t sel_nelmts; /* Number of elements in selection */ hsize_t count[H5O_LAYOUT_NDIMS]; /* Element count of hyperslab */ @@ -4434,10 +4439,10 @@ H5D__chunk_prune_fill(H5D_chunk_it_ud1_t *udata, hbool_t new_unfilt_chunk) /* Get the chunk's size */ HDassert(layout->u.chunk.size > 0); - H5_ASSIGN_OVERFLOW(chunk_size, layout->u.chunk.size, uint32_t, size_t); + H5_CHECKED_ASSIGN(chunk_size, size_t, layout->u.chunk.size, uint32_t); /* Get the info for the chunk in the file */ - if(H5D__chunk_lookup(dset, io_info->dxpl_id, chunk_offset, udata->common.scaled, &chk_udata) < 0) + if(H5D__chunk_lookup(dset, io_info->dxpl_id, scaled, &chk_udata) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "error looking up chunk address") chk_udata.new_unfilt_chunk = new_unfilt_chunk; @@ -4458,7 +4463,7 @@ H5D__chunk_prune_fill(H5D_chunk_it_ud1_t *udata, hbool_t new_unfilt_chunk) /* Compute the # of elements to leave with existing value, in each dimension */ for(u = 0; u < rank; u++) { - count[u] = MIN(layout->u.chunk.dim[u], (udata->space_dim[u] - chunk_offset[u])); + count[u] = MIN(layout->u.chunk.dim[u], (udata->space_dim[u] - (scaled[u] * layout->u.chunk.dim[u]))); HDassert(count[u] > 0); } /* end for */ @@ -4621,13 +4626,13 @@ done: herr_t H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) { - hsize_t min_mod_chunk_off[H5O_LAYOUT_NDIMS]; /* Offset of first chunk to modify in each dimension */ - hsize_t max_mod_chunk_off[H5O_LAYOUT_NDIMS]; /* Offset of last chunk to modify in each dimension */ - hssize_t max_fill_chunk_off[H5O_LAYOUT_NDIMS]; /* Offset of last chunk that might be filled in each dimension */ + hsize_t min_mod_chunk_sc[H5O_LAYOUT_NDIMS]; /* Scaled offset of first chunk to modify in each dimension */ + hsize_t max_mod_chunk_sc[H5O_LAYOUT_NDIMS]; /* Scaled offset of last chunk to modify in each dimension */ + hssize_t max_fill_chunk_sc[H5O_LAYOUT_NDIMS]; /* Scaled offset of last chunk that might be filled in each dimension */ hbool_t fill_dim[H5O_LAYOUT_NDIMS]; /* Whether the plane of edge chunks in this dimension needs to be filled */ hbool_t dims_outside_fill[H5O_LAYOUT_NDIMS]; /* Dimensions in chunk offset outside fill dimensions */ int ndims_outside_fill = 0; /* Number of dimensions in chunk offset outside fill dimensions */ - hsize_t min_partial_chunk_off[H5O_LAYOUT_NDIMS]; /* Offset of first partial (or empty) chunk in each dimension */ + hsize_t min_partial_chunk_sc[H5O_LAYOUT_NDIMS]; /* Offset of first partial (or empty) chunk in each dimension */ hbool_t new_unfilt_dim[H5O_LAYOUT_NDIMS]; /* Whether the plane of edge chunks in this dimension are newly unfiltered */ hbool_t has_fill = FALSE; /* Whether there are chunks that must be filled */ H5D_chk_idx_info_t idx_info; /* Chunked index info */ @@ -4637,7 +4642,6 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) H5D_dxpl_cache_t *dxpl_cache = &_dxpl_cache; /* Data transfer property cache */ const H5O_layout_t *layout = &(dset->shared->layout); /* Dataset's layout */ const H5D_rdcc_t *rdcc = &(dset->shared->cache.chunk); /*raw data chunk cache */ - H5D_rdcc_ent_t *ent = NULL; /* Cache entry */ unsigned space_ndims; /* Dataset's space rank */ const hsize_t *space_dim; /* Current dataspace dimensions */ unsigned op_dim; /* Current operationg dimension */ @@ -4647,7 +4651,7 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) H5D_chunk_common_ud_t idx_udata; /* User data for index removal routine */ H5S_t *chunk_space = NULL; /* Dataspace for a chunk */ hsize_t chunk_dim[H5O_LAYOUT_NDIMS]; /* Chunk dimensions */ - hsize_t chunk_offset[H5O_LAYOUT_NDIMS]; /* Offset of current chunk */ + hsize_t scaled[H5O_LAYOUT_NDIMS]; /* Scaled offset of current chunk */ hsize_t hyper_start[H5O_LAYOUT_NDIMS]; /* Starting location of hyperslab */ uint32_t elmts_per_chunk; /* Elements in chunk */ hbool_t disable_edge_filters = FALSE; /* Whether to disable filters on partial edge chunks */ @@ -4681,8 +4685,8 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) space_dim = dset->shared->curr_dims; space_ndims = dset->shared->ndims; - /* The last dimension in chunk_offset is always 0 */ - chunk_offset[space_ndims] = (hsize_t)0; + /* The last dimension in scaled is always 0 */ + scaled[space_ndims] = (hsize_t)0; /* Check if any old dimensions are 0, if so we do not have to do anything */ for(op_dim = 0; op_dim < (unsigned)space_ndims; op_dim++) @@ -4701,7 +4705,7 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) for(u = 0; u < space_ndims; u++) { elmts_per_chunk *= layout->u.chunk.dim[u]; chunk_dim[u] = layout->u.chunk.dim[u]; - shrunk_dim[u] = space_dim[u] < old_dim[u]; + shrunk_dim[u] = (space_dim[u] < old_dim[u]); } /* end for */ /* Create a dataspace for a chunk & set the extent */ @@ -4713,9 +4717,9 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) HDmemset(hyper_start, 0, sizeof(hyper_start)); /* Set up chunked I/O info object, for operations on chunks (in callback) - * Note that we only need to set chunk_offset once, as the array's address + * Note that we only need to set scaled once, as the array's address * will never change. */ - chk_store.chunk.offset = chunk_offset; + chk_store.chunk.scaled = scaled; H5D_BUILD_IO_INFO_RD(&chk_io_info, dset, dxpl_cache, dxpl_id, &chk_store, NULL); /* Compose chunked index info struct */ @@ -4729,6 +4733,7 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) HDmemset(&udata, 0, sizeof udata); udata.common.layout = &layout->u.chunk; udata.common.storage = &layout->storage.u.chunk; + udata.common.scaled = scaled; udata.io_info = &chk_io_info; udata.idx_info = &idx_info; udata.space_dim = space_dim; @@ -4751,21 +4756,19 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) /* * Determine the chunks which need to be filled or removed */ - HDmemset(min_mod_chunk_off, 0, sizeof(min_mod_chunk_off)); - HDmemset(max_mod_chunk_off, 0, sizeof(max_mod_chunk_off)); + HDmemset(min_mod_chunk_sc, 0, sizeof(min_mod_chunk_sc)); + HDmemset(max_mod_chunk_sc, 0, sizeof(max_mod_chunk_sc)); for(op_dim = 0; op_dim < (unsigned)space_ndims; op_dim++) { /* Calculate the largest offset of chunks that might need to be * modified in this dimension */ - max_mod_chunk_off[op_dim] = chunk_dim[op_dim] * ((old_dim[op_dim] - 1) - / chunk_dim[op_dim]); + max_mod_chunk_sc[op_dim] = (old_dim[op_dim] - 1) / chunk_dim[op_dim]; /* Calculate the largest offset of chunks that might need to be * filled in this dimension */ if(0 == space_dim[op_dim]) - max_fill_chunk_off[op_dim] = -1; + max_fill_chunk_sc[op_dim] = -1; else - max_fill_chunk_off[op_dim] = (hssize_t)(chunk_dim[op_dim] - * ((MIN(space_dim[op_dim], old_dim[op_dim]) - 1) + max_fill_chunk_sc[op_dim] = (hssize_t)(((MIN(space_dim[op_dim], old_dim[op_dim]) - 1) / chunk_dim[op_dim])); if(shrunk_dim[op_dim]) { @@ -4773,18 +4776,17 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) * modified in this dimension. Note that this array contains * garbage for all dimensions which are not shrunk. These locations * must not be read from! */ - min_mod_chunk_off[op_dim] = chunk_dim[op_dim] * (space_dim[op_dim] - / chunk_dim[op_dim]); + min_mod_chunk_sc[op_dim] = space_dim[op_dim] / chunk_dim[op_dim]; /* Determine if we need to fill chunks in this dimension */ - if((hssize_t)min_mod_chunk_off[op_dim] == max_fill_chunk_off[op_dim]) { + if((hssize_t)min_mod_chunk_sc[op_dim] == max_fill_chunk_sc[op_dim]) { fill_dim[op_dim] = TRUE; has_fill = TRUE; /* If necessary, check if chunks in this dimension that need to * be filled are new partial edge chunks */ if(disable_edge_filters && old_dim[op_dim] - >= (min_mod_chunk_off[op_dim] + chunk_dim[op_dim])) + >= (min_mod_chunk_sc[op_dim] + 1)) new_unfilt_dim[op_dim] = TRUE; else new_unfilt_dim[op_dim] = FALSE; @@ -4803,56 +4805,55 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) * chunks in this dimension, so we know these chunks were previously * unfiltered */ if(disable_edge_filters) - min_partial_chunk_off[op_dim] = chunk_dim[op_dim] * (old_dim[op_dim] - / chunk_dim[op_dim]); + min_partial_chunk_sc[op_dim] = old_dim[op_dim] / chunk_dim[op_dim]; } /* end for */ /* Main loop: fill or remove chunks */ for(op_dim = 0; op_dim < (unsigned)space_ndims; op_dim++) { + hbool_t dims_outside_fill[H5O_LAYOUT_NDIMS]; /* Dimensions in chunk offset outside fill dimensions */ + int ndims_outside_fill; /* Number of dimensions in chunk offset outside fill dimensions */ + hbool_t carry; /* Flag to indicate that chunk increment carrys to higher dimension (sorta) */ + /* Check if modification along this dimension is really necessary */ if(!shrunk_dim[op_dim]) continue; else { - HDassert((hsize_t) max_mod_chunk_off[op_dim] >= min_mod_chunk_off[op_dim]); + HDassert(max_mod_chunk_sc[op_dim] >= min_mod_chunk_sc[op_dim]); /* Reset the chunk offset indices */ - HDmemset(chunk_offset, 0, (space_ndims * sizeof(chunk_offset[0]))); - chunk_offset[op_dim] = min_mod_chunk_off[op_dim]; + HDmemset(scaled, 0, (space_ndims * sizeof(scaled[0]))); + scaled[op_dim] = min_mod_chunk_sc[op_dim]; /* Initialize "dims_outside_fill" array */ ndims_outside_fill = 0; for(u = 0; u < space_ndims; u++) - if((hssize_t)chunk_offset[u] > max_fill_chunk_off[u]) { + if((hssize_t)scaled[u] > max_fill_chunk_sc[u]) { dims_outside_fill[u] = TRUE; ndims_outside_fill++; } /* end if */ else dims_outside_fill[u] = FALSE; - - carry = FALSE; } /* end if */ + carry = FALSE; while(!carry) { - hsize_t scaled[H5S_MAX_RANK]; /* Scaled coordinates for the current chunk */ int i; /* Local index variable */ - /* Compute the scaled coordinates */ - H5VM_chunk_scaled(space_ndims, chunk_offset, layout->u.chunk.dim, scaled); udata.common.scaled = scaled; if(0 == ndims_outside_fill) { HDassert(fill_dim[op_dim]); - HDassert(chunk_offset[op_dim] == min_mod_chunk_off[op_dim]); + HDassert(scaled[op_dim] == min_mod_chunk_sc[op_dim]); /* Make sure this is an edge chunk */ - HDassert(H5D__chunk_is_partial_edge_chunk(chunk_offset, + HDassert(H5D__chunk_is_partial_edge_chunk(scaled, space_ndims, space_dim, layout->u.chunk.dim)); /* Determine if the chunk just became an unfiltered chunk */ if(new_unfilt_dim[op_dim]) { new_unfilt_chunk = TRUE; for(u = 0; u < space_ndims; u++) - if(chunk_offset[u] == min_partial_chunk_off[u]) { + if(scaled[u] == min_partial_chunk_sc[u]) { new_unfilt_chunk = FALSE; break; } /* end if */ @@ -4861,7 +4862,7 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) /* Make sure that, if we think this is a new unfiltered chunk, * it was previously not an edge chunk */ HDassert(!new_unfilt_dim[op_dim] || (!new_unfilt_chunk != - !H5D__chunk_is_partial_edge_chunk(chunk_offset, + !H5D__chunk_is_partial_edge_chunk(scaled, space_ndims, old_dim, layout->u.chunk.dim))); HDassert(!new_unfilt_chunk || new_unfilt_dim[op_dim]); @@ -4878,7 +4879,7 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) hbool_t outside_dim = FALSE; for(u = 0; u < space_ndims; u++) - if(chunk_offset[u] >= space_dim[u]) { + if((scaled[u] * chunk_dim[u]) >= space_dim[u]) { outside_dim = TRUE; break; } /* end if */ @@ -4887,7 +4888,7 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) #endif /* NDEBUG */ /* Check if the chunk exists in cache or on disk */ - if(H5D__chunk_lookup(dset, dxpl_id, chunk_offset, udata.common.scaled, &chk_udata) < 0) + if(H5D__chunk_lookup(dset, dxpl_id, scaled, &chk_udata) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "error looking up chunk") /* Evict the entry from the cache if present, but do not flush @@ -4899,7 +4900,6 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) /* Remove the chunk from disk, if present */ if(H5F_addr_defined(chk_udata.chunk_block.offset)) { /* Update the offset in idx_udata */ - idx_udata.offset = chunk_offset; idx_udata.scaled = udata.common.scaled; /* Remove the chunk from disk */ @@ -4911,20 +4911,20 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) /* Increment indices */ carry = TRUE; for(i = (int)(space_ndims - 1); i >= 0; --i) { - chunk_offset[i] += chunk_dim[i]; - if(chunk_offset[i] > (hsize_t) max_mod_chunk_off[i]) { + scaled[i]++; + if(scaled[i] > max_mod_chunk_sc[i]) { /* Left maximum dimensions, "wrap around" and check if this * dimension is no longer outside the fill dimension */ if((unsigned)i == op_dim) { - chunk_offset[i] = min_mod_chunk_off[i]; + scaled[i] = min_mod_chunk_sc[i]; if(dims_outside_fill[i] && fill_dim[i]) { dims_outside_fill[i] = FALSE; ndims_outside_fill--; } /* end if */ } /* end if */ else { - chunk_offset[i] = 0; - if(dims_outside_fill[i] && max_fill_chunk_off[i] >= 0) { + scaled[i] = 0; + if(dims_outside_fill[i] && max_fill_chunk_sc[i] >= 0) { dims_outside_fill[i] = FALSE; ndims_outside_fill--; } /* end if */ @@ -4932,7 +4932,7 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) } /* end if */ else { /* Check if we just went outside the fill dimension */ - if(!dims_outside_fill[i] && (hssize_t)chunk_offset[i] > max_fill_chunk_off[i]) { + if(!dims_outside_fill[i] && (hssize_t)scaled[i] > max_fill_chunk_sc[i]) { dims_outside_fill[i] = TRUE; ndims_outside_fill++; } /* end if */ @@ -4944,13 +4944,13 @@ H5D__chunk_prune_by_extent(H5D_t *dset, hid_t dxpl_id, const hsize_t *old_dim) } /* end for */ } /* end while(!carry) */ - /* Adjust max_mod_chunk_off so we don't modify the same chunk twice. + /* Adjust max_mod_chunk_sc so we don't modify the same chunk twice. * Also check if this dimension started from 0 (and hence removed all * of the chunks). */ - if(min_mod_chunk_off[op_dim] == 0) + if(min_mod_chunk_sc[op_dim] == 0) break; else - max_mod_chunk_off[op_dim] = min_mod_chunk_off[op_dim] - chunk_dim[op_dim]; + max_mod_chunk_sc[op_dim] = min_mod_chunk_sc[op_dim] - 1; } /* end for(op_dim=0...) */ /* Reset any cached chunk info for this dataset */ @@ -4993,7 +4993,7 @@ H5D__chunk_addrmap_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) FUNC_ENTER_STATIC /* Compute the index for this chunk */ - chunk_index = H5VM_chunk_index(rank, chunk_rec->offset, udata->common.layout->dim, udata->common.layout->down_chunks); + chunk_index = H5VM_array_offset_pre(rank, udata->common.layout->down_chunks, chunk_rec->scaled); /* Set it in the userdata to return */ udata->chunk_addr[chunk_index] = chunk_rec->chunk_addr; @@ -5173,7 +5173,6 @@ H5D__chunk_update_cache(H5D_t *dset, hid_t dxpl_id) H5D_rdcc_ent_t *tmp_tail; /* Tail pointer for temporary entry list */ H5D_dxpl_cache_t _dxpl_cache; /* Data transfer property cache buffer */ H5D_dxpl_cache_t *dxpl_cache = &_dxpl_cache; /* Data transfer property cache */ - unsigned rank; /* Current # of dimensions */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -5182,9 +5181,8 @@ H5D__chunk_update_cache(H5D_t *dset, hid_t dxpl_id) HDassert(dset && H5D_CHUNKED == dset->shared->layout.type); HDassert(dset->shared->layout.u.chunk.ndims > 0 && dset->shared->layout.u.chunk.ndims <= H5O_LAYOUT_NDIMS); - /* Get the rank */ - rank = dset->shared->layout.u.chunk.ndims - 1; - HDassert(rank > 1); + /* Check the rank */ + HDassert((dset->shared->layout.u.chunk.ndims - 1) > 1); /* Fill the DXPL cache values for later use */ if(H5D__get_dxpl_cache(dxpl_id, &dxpl_cache) < 0) @@ -5310,7 +5308,7 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) FUNC_ENTER_STATIC /* Get 'size_t' local value for number of bytes in chunk */ - H5_ASSIGN_OVERFLOW(nbytes, chunk_rec->nbytes, uint32_t, size_t); + H5_CHECKED_ASSIGN(nbytes, size_t, chunk_rec->nbytes, uint32_t); /* Check parameter for type conversion */ if(udata->do_convert) { @@ -5328,7 +5326,7 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) if(udata->common.layout->flags & H5O_LAYOUT_CHUNK_DONT_FILTER_PARTIAL_BOUND_CHUNKS) { /* Check if the chunk is an edge chunk, and disable filters if so */ - if(!H5D__chunk_is_partial_edge_chunk(chunk_rec->offset, udata->dset_ndims, + if(!H5D__chunk_is_partial_edge_chunk(chunk_rec->scaled, udata->dset_ndims, udata->dset_dims, udata->common.layout->dim)) must_filter = TRUE; } /* end if */ @@ -5422,7 +5420,7 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) /* Set up destination chunk callback information for insertion */ udata_dst.common.layout = udata->idx_info_dst->layout; udata_dst.common.storage = udata->idx_info_dst->storage; - udata_dst.common.offset = chunk_rec->offset; + udata_dst.common.scaled = chunk_rec->scaled; udata_dst.chunk_block.offset = HADDR_UNDEF; udata_dst.chunk_block.length = chunk_rec->nbytes; udata_dst.filter_mask = chunk_rec->filter_mask; @@ -5436,17 +5434,16 @@ H5D__chunk_copy_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) if(nbytes > ((size_t)0xffffffff)) HGOTO_ERROR(H5E_DATASET, H5E_BADRANGE, H5_ITER_ERROR, "chunk too large for 32-bit length") #endif /* H5_SIZEOF_SIZE_T > 4 */ - H5_ASSIGN_OVERFLOW(udata_dst.chunk_block.length, nbytes, size_t, uint32_t); + H5_CHECKED_ASSIGN(udata_dst.chunk_block.length, uint32_t, nbytes, size_t); udata->buf = buf; udata->buf_size = buf_size; } /* end if */ - /* Compute the index and scaled coordinates for this chunk */ - udata_dst.chunk_idx = H5VM_chunk_index_scaled(udata_dst.common.layout->ndims - 1, chunk_rec->offset, udata_dst.common.layout->dim, udata_dst.common.layout->down_chunks, scaled); - udata_dst.common.scaled = scaled; + udata_dst.chunk_idx = H5VM_array_offset_pre(udata_dst.common.layout->ndims - 1, + udata_dst.common.layout->down_chunks, udata_dst.common.scaled); /* Allocate chunk in the file */ - if(H5D__chunk_file_alloc(udata->idx_info_dst, NULL, &udata_dst.chunk_block, &need_insert, &udata_dst.need_modify, scaled) < 0) + if(H5D__chunk_file_alloc(udata->idx_info_dst, NULL, &udata_dst.chunk_block, &need_insert, &udata_dst.need_modify, udata_dst.common.scaled) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "unable to insert/resize chunk on chunk level") /* Write chunk data to destination file */ @@ -5566,7 +5563,7 @@ H5D__chunk_copy(H5F_t *f_src, H5O_storage_chunk_t *storage_src, /* Get the dim info for dataset */ if((sndims = H5S_extent_get_dims(ds_extent_src, curr_dims, max_dims)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get dataspace dimensions") - H5_ASSIGN_OVERFLOW(ndims, sndims, int, unsigned); + H5_CHECKED_ASSIGN(ndims, unsigned, sndims, int); /* Set the source layout chunk information */ if(H5D__chunk_set_info_real(layout_src, ndims, curr_dims, max_dims) < 0) @@ -5674,7 +5671,7 @@ H5D__chunk_copy(H5F_t *f_src, H5O_storage_chunk_t *storage_src, do_convert = TRUE; } /* end if */ - H5_ASSIGN_OVERFLOW(buf_size, layout_src->size, uint32_t, size_t); + H5_CHECKED_ASSIGN(buf_size, size_t, layout_src->size, uint32_t); reclaim_buf_size = 0; } /* end else */ @@ -5845,7 +5842,7 @@ H5D__chunk_dump_index_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata) /* Print information about this chunk */ HDfprintf(udata->stream, " 0x%08x %8Zu %10a [", chunk_rec->filter_mask, chunk_rec->nbytes, chunk_rec->chunk_addr); for(u = 0; u < udata->ndims; u++) - HDfprintf(udata->stream, "%s%Hd", (u ? ", " : ""), chunk_rec->offset[u]); + HDfprintf(udata->stream, "%s%Hu", (u ? ", " : ""), (chunk_rec->scaled[u] * udata->chunk_dim[u])); HDfputs("]\n", udata->stream); } /* end if */ @@ -5907,6 +5904,7 @@ H5D__chunk_dump_index(H5D_t *dset, hid_t dxpl_id, FILE *stream) udata.stream = stream; udata.header_displayed = FALSE; udata.ndims = dset->shared->layout.u.chunk.ndims; + udata.chunk_dim = dset->shared->layout.u.chunk.dim; /* Iterate over index and dump chunk info */ if((dset->shared->layout.storage.u.chunk.ops->iterate)(&idx_info, H5D__chunk_dump_index_cb, &udata) < 0) @@ -6177,7 +6175,7 @@ done: *------------------------------------------------------------------------- */ static hbool_t -H5D__chunk_is_partial_edge_chunk(const hsize_t offset[], unsigned dset_ndims, +H5D__chunk_is_partial_edge_chunk(const hsize_t scaled[], unsigned dset_ndims, const hsize_t *dset_dims, const uint32_t *chunk_dims) { unsigned u; /* Local index variable */ @@ -6186,14 +6184,14 @@ H5D__chunk_is_partial_edge_chunk(const hsize_t offset[], unsigned dset_ndims, FUNC_ENTER_STATIC_NOERR /* Check args */ - HDassert(offset); + HDassert(scaled); HDassert(dset_ndims > 0); HDassert(dset_dims); HDassert(chunk_dims); /* check if this is a partial edge chunk */ for(u = 0; u < dset_ndims; u++) - if((offset[u] + chunk_dims[u]) > dset_dims[u]) + if(((scaled[u] + 1) * chunk_dims[u]) > dset_dims[u]) HGOTO_DONE(TRUE); done: diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c index c053a68..2f9c5b6 100644 --- a/src/H5Dcompact.c +++ b/src/H5Dcompact.c @@ -197,7 +197,7 @@ H5D__compact_construct(H5F_t *f, H5D_t *dset) tmp_size = H5T_get_size(dset->shared->type); HDassert(tmp_size > 0); tmp_size = tmp_size * (hsize_t)stmp_size; - H5_ASSIGN_OVERFLOW(dset->shared->layout.storage.u.compact.size, tmp_size, hssize_t, size_t); + H5_CHECKED_ASSIGN(dset->shared->layout.storage.u.compact.size, size_t, tmp_size, hssize_t); /* Verify data size is smaller than maximum header message size * (64KB) minus other layout message fields. diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c index e913a3f..898b46d 100644 --- a/src/H5Dcontig.c +++ b/src/H5Dcontig.c @@ -259,7 +259,7 @@ H5D__contig_fill(const H5D_t *dset, hid_t dxpl_id) /* Get the number of elements in the dataset's dataspace */ if((snpoints = H5S_GET_EXTENT_NPOINTS(dset->shared->space)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "dataset has negative number of elements") - H5_ASSIGN_OVERFLOW(npoints, snpoints, hssize_t, size_t); + H5_CHECKED_ASSIGN(npoints, size_t, snpoints, hssize_t); /* Initialize the fill value buffer */ if(H5D__fill_init(&fb_info, NULL, NULL, NULL, NULL, NULL, @@ -644,6 +644,7 @@ H5D__contig_readvv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, size_t sieve_size = (size_t)-1; /* Size of sieve buffer */ haddr_t rel_eoa; /* Relative end of file address */ hsize_t max_data; /* Actual maximum size of data to cache */ + hsize_t min; /* temporary minimum value (avoids some ugly macro nesting) */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -684,7 +685,8 @@ H5D__contig_readvv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, max_data = store_contig->dset_size - dst_off; /* Compute the size of the sieve buffer */ - H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); + min = MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size); + H5_CHECKED_ASSIGN(dset_contig->sieve_size, size_t, min, hsize_t); /* Read the new sieve buffer */ if(H5F_block_read(file, H5FD_MEM_DRAW, dset_contig->sieve_loc, dset_contig->sieve_size, udata->dxpl_id, dset_contig->sieve_buf) < 0) @@ -757,9 +759,13 @@ H5D__contig_readvv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, /* Only need this when resizing sieve buffer */ max_data = store_contig->dset_size - dst_off; - /* Compute the size of the sieve buffer */ - /* Don't read off the end of the file, don't read past the end of the data element and don't read more than the buffer size */ - H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); + /* Compute the size of the sieve buffer. + * Don't read off the end of the file, don't read past + * the end of the data element, and don't read more than + * the buffer size. + */ + min = MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size); + H5_CHECKED_ASSIGN(dset_contig->sieve_size, size_t, min, hsize_t); /* Update local copies of sieve information */ sieve_start = dset_contig->sieve_loc; @@ -915,6 +921,7 @@ H5D__contig_writevv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, size_t sieve_size = (size_t)-1; /* size of sieve buffer */ haddr_t rel_eoa; /* Relative end of file address */ hsize_t max_data; /* Actual maximum size of data to cache */ + hsize_t min; /* temporary minimum value (avoids some ugly macro nesting) */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -960,7 +967,8 @@ if(dset_contig->sieve_size > len) max_data = store_contig->dset_size - dst_off; /* Compute the size of the sieve buffer */ - H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); + min = MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size); + H5_CHECKED_ASSIGN(dset_contig->sieve_size, size_t, min, hsize_t); /* Check if there is any point in reading the data from the file */ if(dset_contig->sieve_size > len) { @@ -1075,9 +1083,13 @@ if(dset_contig->sieve_size > len) /* Only need this when resizing sieve buffer */ max_data = store_contig->dset_size - dst_off; - /* Compute the size of the sieve buffer */ - /* Don't read off the end of the file, don't read past the end of the data element and don't read more than the buffer size */ - H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); + /* Compute the size of the sieve buffer. + * Don't read off the end of the file, don't read past + * the end of the data element, and don't read more than + * the buffer size. + */ + min = MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size); + H5_CHECKED_ASSIGN(dset_contig->sieve_size, size_t, min, hsize_t); /* Update local copies of sieve information */ sieve_start = dset_contig->sieve_loc; diff --git a/src/H5Ddeprec.c b/src/H5Ddeprec.c index 4bd6240..3da6b95 100644 --- a/src/H5Ddeprec.c +++ b/src/H5Ddeprec.c @@ -382,26 +382,56 @@ H5D__extend(H5D_t *dataset, const hsize_t *size, hid_t dxpl_id) /* Update the index values for the cached chunks for this dataset */ if(H5D_CHUNKED == dataset->shared->layout.type) { - unsigned u; + hbool_t update_chunks = FALSE; /* Flag to indicate chunk cache update is needed */ + + /* Check if we need to track & update scaled dimension information */ + if(dataset->shared->ndims > 1) { + unsigned u; /* Local indicate variable */ + + /* Update scaled chunk information */ + for(u = 0; u < dataset->shared->ndims; u++) { + hsize_t scaled; /* Scaled value */ + + /* Compute the scaled dimension size value */ + scaled = size[u] / dataset->shared->layout.u.chunk.dim[u]; + + /* Check if scaled dimension size changed */ + if(scaled != dataset->shared->cache.chunk.scaled_dims[u]) { + hsize_t scaled_power2up; /* New size value, rounded to next power of 2 */ + + /* Update the scaled dimension size value for the current dimension */ + dataset->shared->cache.chunk.scaled_dims[u] = scaled; + + /* Check if algorithm for computing hash values will change */ + if((scaled > dataset->shared->cache.chunk.nslots && + dataset->shared->cache.chunk.scaled_dims[u] <= dataset->shared->cache.chunk.nslots) + || (scaled <= dataset->shared->cache.chunk.nslots && + dataset->shared->cache.chunk.scaled_dims[u] > dataset->shared->cache.chunk.nslots)) + update_chunks = TRUE; + + /* Check if the number of bits required to encode the scaled size value changed */ + if(dataset->shared->cache.chunk.scaled_power2up[u] != (scaled_power2up = H5VM_power2up(scaled))) { + /* Update the 'power2up' & 'encode_bits' values for the current dimension */ + dataset->shared->cache.chunk.scaled_power2up[u] = scaled_power2up; + dataset->shared->cache.chunk.scaled_encode_bits[u] = H5VM_log2_gen(scaled_power2up); + + /* Indicate that the chunk cache indices should be updated */ + update_chunks = TRUE; + } /* end if */ + } /* end if */ + } /* end for */ + } /* end if */ /* Update general information for chunks */ if(H5D__chunk_set_info(dataset) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "unable to update # of chunks") - for(u = 1; u < dataset->shared->ndims; u++) { - hsize_t size_power2up; /* New size value, rounded to next power of 2 */ - - if((size_power2up = H5VM_power2up(dataset->shared->curr_dims[u])) != dataset->shared->curr_power2up[u]) { - /* Update the 'power2up' value for the current dimension */ - dataset->shared->curr_power2up[u] = size_power2up; - - /* Update the chunk cache indices */ - if(H5D__chunk_update_cache(dataset, dxpl_id) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "unable to update cached chunk indices") - break; - } /* end if */ - } /* end for */ - + /* Check for updating chunk cache indices */ + if(update_chunks) { + /* Update the chunk cache indices */ + if(H5D__chunk_update_cache(dataset, dxpl_id) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "unable to update cached chunk indices") + } /* end if */ } /* end if */ /* Allocate space for the new parts of the dataset, if appropriate */ diff --git a/src/H5Dearray.c b/src/H5Dearray.c index a6c6535..116b3bf 100644 --- a/src/H5Dearray.c +++ b/src/H5Dearray.c @@ -73,6 +73,15 @@ typedef struct H5D_earray_ud_t { hid_t dxpl_id; /* DXPL ID for operation */ } H5D_earray_ud_t; +/* Extensible Array callback info for iteration over chunks */ +typedef struct H5D_earray_it_ud_t { + H5D_chunk_common_ud_t common; /* Common info for Fixed Array user data (must be first) */ + H5D_chunk_rec_t chunk_rec; /* Generic chunk record for callback */ + hbool_t filtered; /* Whether the chunks are filtered */ + H5D_chunk_cb_func_t cb; /* Chunk callback routine */ + void *udata; /* User data for chunk callback routine */ +} H5D_earray_it_ud_t; + /* Native extensible array element for chunks w/filters */ typedef struct H5D_earray_filt_elmt_t { haddr_t addr; /* Address of chunk */ @@ -240,7 +249,7 @@ H5D_earray_crt_context(void *_udata) /* Compute the size required for encoding the size of a chunk, allowing * for an extra byte, in case the filter makes the chunk larger. */ - ctx->chunk_size_len = 1 + ((H5VM_log2_gen(udata->chunk_size) + 8) / 8); + ctx->chunk_size_len = 1 + ((H5VM_log2_gen((uint64_t)udata->chunk_size) + 8) / 8); if(ctx->chunk_size_len > 8) ctx->chunk_size_len = 8; @@ -903,7 +912,7 @@ H5D_earray_idx_init(const H5D_chk_idx_info_t *idx_info, const H5S_t *space, /* Get the dim info for dataset */ if((sndims = H5S_get_simple_extent_dims(space, NULL, max_dims)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get dataspace dimensions") - H5_ASSIGN_OVERFLOW(ndims, sndims, int, unsigned); + H5_CHECKED_ASSIGN(ndims, unsigned, sndims, int); /* Find the rank of the unlimited dimension */ unlim_dim = (-1); @@ -977,7 +986,7 @@ H5D_earray_idx_create(const H5D_chk_idx_info_t *idx_info) /* Compute the size required for encoding the size of a chunk, allowing * for an extra byte, in case the filter makes the chunk larger. */ - chunk_size_len = 1 + ((H5VM_log2_gen(idx_info->layout->size) + 8) / 8); + chunk_size_len = 1 + ((H5VM_log2_gen((uint64_t)idx_info->layout->size) + 8) / 8); if(chunk_size_len > 8) chunk_size_len = 8; @@ -1159,9 +1168,12 @@ H5D_earray_idx_get_addr(const H5D_chk_idx_info_t *idx_info, H5D_chunk_ud_t *udat if(idx_info->layout->u.earray.unlim_dim > 0) { hsize_t swizzled_coords[H5O_LAYOUT_NDIMS]; /* swizzled chunk coordinates */ unsigned ndims = (idx_info->layout->ndims - 1); /* Number of dimensions */ + unsigned u; + + /* Compute coordinate offset from scaled offset */ + for(u = 0; u < ndims; u++) + swizzled_coords[u] = udata->common.scaled[u] * idx_info->layout->dim[u]; - /* Set up the swizzled chunk coordinates */ - HDmemcpy(swizzled_coords, udata->common.offset, ndims * sizeof(udata->common.offset[0])); H5VM_swizzle_coords(hsize_t, swizzled_coords, idx_info->layout->u.earray.unlim_dim); /* Calculate the index of this chunk */ @@ -1250,6 +1262,64 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5D_earray_idx_resize() */ +/*------------------------------------------------------------------------- + * Function: H5D_earray_idx_iterate_cb + * + * Purpose: Callback routine for extensible array element iteration. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Vailin Choi; Feb 2015 + * + *------------------------------------------------------------------------- + */ +static int +H5D_earray_idx_iterate_cb(hsize_t UNUSED idx, const void *_elmt, void *_udata) +{ + H5D_earray_it_ud_t *udata = (H5D_earray_it_ud_t *)_udata; /* User data */ + unsigned ndims; /* Rank of chunk */ + int curr_dim; /* Current dimension */ + int ret_value = H5_ITER_CONT; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT_NOERR + + /* Compose generic chunk record for callback */ + if(udata->filtered) { + const H5D_earray_filt_elmt_t *filt_elmt = (const H5D_earray_filt_elmt_t *)_elmt; + + udata->chunk_rec.chunk_addr = filt_elmt->addr; + udata->chunk_rec.nbytes = filt_elmt->nbytes; + udata->chunk_rec.filter_mask = filt_elmt->filter_mask; + } /* end if */ + else + udata->chunk_rec.chunk_addr = *(const haddr_t *)_elmt; + + /* Make "generic chunk" callback */ + if(H5F_addr_defined(udata->chunk_rec.chunk_addr)) { + if((ret_value = (udata->cb)(&udata->chunk_rec, udata->udata)) < 0) + HERROR(H5E_DATASET, H5E_CALLBACK, "failure in generic chunk iterator callback"); + } + + /* Update coordinates of chunk in dataset */ + ndims = udata->common.layout->ndims - 1; + HDassert(ndims > 0); + curr_dim = (int)(ndims - 1); + while(curr_dim >= 0) { + /* Increment coordinate in current dimension */ + udata->chunk_rec.scaled[curr_dim]++; + /* Check if we went off the end of the current dimension */ + if(udata->chunk_rec.scaled[curr_dim] >= udata->common.layout->chunks[curr_dim]) { + /* Reset coordinate & move to next faster dimension */ + udata->chunk_rec.scaled[curr_dim] = 0; + curr_dim--; + } /* end if */ + else + break; + } /* end while */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* H5D_earray_idx_iterate_cb() */ + /*------------------------------------------------------------------------- * Function: H5D_earray_idx_iterate @@ -1301,65 +1371,28 @@ H5D_earray_idx_iterate(const H5D_chk_idx_info_t *idx_info, if(H5EA_get_stats(ea, &ea_stat) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't query extensible array statistics") - /* Check if there are any array elements */ if(ea_stat.stored.max_idx_set > 0) { - H5D_chunk_rec_t chunk_rec; /* Generic chunk record for callback */ - hsize_t u; /* Local index variable */ - - /* Check for filters on chunks */ - if(idx_info->pline->nused > 0) { - /* Prepare common fields of chunk record for callback */ - HDmemset(&chunk_rec, 0, sizeof(chunk_rec)); - - /* Loop over array elements */ - /* (Note: this may be too simple for datasets with >1 dimension) */ - for(u = 0; u < ea_stat.stored.max_idx_set; u++, chunk_rec.offset[0] += idx_info->layout->dim[0]) { - H5D_earray_filt_elmt_t elmt; /* Extensible array element */ - - /* Get the info about the chunk for the index */ - if(H5EA_get(ea, idx_info->dxpl_id, u, &elmt) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get chunk info") - - /* Check if chunk exists */ - if(H5F_addr_defined(elmt.addr)) { - /* Set chunk info for callback record */ - chunk_rec.chunk_addr = elmt.addr; - chunk_rec.nbytes = elmt.nbytes; - chunk_rec.filter_mask = elmt.filter_mask; - - /* Make chunk callback */ - if((ret_value = (*chunk_cb)(&chunk_rec, chunk_udata)) < 0) - HERROR(H5E_DATASET, H5E_CALLBACK, "failure in generic chunk iterator callback"); - } /* end if */ - } /* end for */ + + H5D_earray_it_ud_t udata; /* User data for iteration callback */ + + /* Initialize userdata */ + HDmemset(&udata, 0, sizeof udata); + udata.common.layout = idx_info->layout; + udata.common.storage = idx_info->storage; + udata.common.rdcc = NULL; + HDmemset(&udata.chunk_rec, 0, sizeof(udata.chunk_rec)); + udata.filtered = (idx_info->pline->nused > 0); + if(!udata.filtered) { + udata.chunk_rec.nbytes = idx_info->layout->size; + udata.chunk_rec.filter_mask = 0; } /* end if */ - else { - /* Prepare common fields of chunk record for callback */ - HDmemset(&chunk_rec, 0, sizeof(chunk_rec)); - chunk_rec.nbytes = idx_info->layout->size; - chunk_rec.filter_mask = 0; - - /* Loop over array elements */ - /* (Note: this may be too simple for datasets with >1 dimension) */ - for(u = 0; u < ea_stat.stored.max_idx_set; u++, chunk_rec.offset[0] += idx_info->layout->dim[0]) { - haddr_t addr; /* Chunk address */ - - /* Get the address of the chunk for the index */ - if(H5EA_get(ea, idx_info->dxpl_id, u, &addr) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get chunk address") - - /* Check if chunk exists */ - if(H5F_addr_defined(addr)) { - /* Set chunk address for callback record */ - chunk_rec.chunk_addr = addr; - - /* Make chunk callback */ - if((ret_value = (*chunk_cb)(&chunk_rec, chunk_udata)) < 0) - HERROR(H5E_DATASET, H5E_CALLBACK, "failure in generic chunk iterator callback"); - } /* end if */ - } /* end for */ - } /* end else */ - } /* end if */ + udata.cb = chunk_cb; + udata.udata = chunk_udata; + + /* Iterate over the extensible array elements */ + if((ret_value = H5EA_iterate(ea, idx_info->dxpl_id, H5D_earray_idx_iterate_cb, &udata)) < 0) + HERROR(H5E_DATASET, H5E_BADITER, "unable to iterate over fixed array chunk index"); + } done: FUNC_LEAVE_NOAPI(ret_value) @@ -1409,9 +1442,12 @@ H5D_earray_idx_remove(const H5D_chk_idx_info_t *idx_info, H5D_chunk_common_ud_t if(idx_info->layout->u.earray.unlim_dim > 0) { hsize_t swizzled_coords[H5O_LAYOUT_NDIMS]; /* swizzled chunk coordinates */ unsigned ndims = (idx_info->layout->ndims - 1); /* Number of dimensions */ + unsigned u; + + /* Compute coordinate offset from scaled offset */ + for(u = 0; u < ndims; u++) + swizzled_coords[u] = udata->scaled[u] * idx_info->layout->dim[u]; - /* Set up the swizzled chunk coordinates */ - HDmemcpy(swizzled_coords, udata->offset, ndims * sizeof(udata->offset[0])); H5VM_swizzle_coords(hsize_t, swizzled_coords, idx_info->layout->u.earray.unlim_dim); /* Calculate the index of this chunk */ diff --git a/src/H5Defl.c b/src/H5Defl.c index 355492f..6707568 100644 --- a/src/H5Defl.c +++ b/src/H5Defl.c @@ -170,7 +170,7 @@ H5D__efl_construct(H5F_t *f, H5D_t *dset) stmp_size = H5S_GET_EXTENT_NPOINTS(dset->shared->space); HDassert(stmp_size >= 0); tmp_size = (hsize_t)stmp_size * dt_size; - H5_ASSIGN_OVERFLOW(dset->shared->layout.storage.u.contig.size, tmp_size, hssize_t, hsize_t); + H5_CHECKED_ASSIGN(dset->shared->layout.storage.u.contig.size, hsize_t, tmp_size, hssize_t); /* Get the sieve buffer size for this dataset */ dset->shared->cache.contig.sieve_buf_size = H5F_SIEVE_BUF_SIZE(f); diff --git a/src/H5Dfarray.c b/src/H5Dfarray.c index de184ea..dc79bd8 100644 --- a/src/H5Dfarray.c +++ b/src/H5Dfarray.c @@ -78,7 +78,6 @@ typedef struct H5D_farray_del_ud_t { typedef struct H5D_farray_it_ud_t { H5D_chunk_common_ud_t common; /* Common info for Fixed Array user data (must be first) */ H5D_chunk_rec_t chunk_rec; /* Generic chunk record for callback */ - hsize_t chunk_offset[H5O_LAYOUT_NDIMS]; /* Chunk offset for max dim */ hbool_t filtered; /* Whether the chunks are filtered */ H5D_chunk_cb_func_t cb; /* Chunk callback routine */ void *udata; /* User data for chunk callback routine */ @@ -256,7 +255,7 @@ H5D_farray_crt_context(void *_udata) /* Compute the size required for encoding the size of a chunk, allowing * for an extra byte, in case the filter makes the chunk larger. */ - ctx->chunk_size_len = 1 + ((H5VM_log2_gen(udata->chunk_size) + 8) / 8); + ctx->chunk_size_len = 1 + ((H5VM_log2_gen((uint64_t)udata->chunk_size) + 8) / 8); if(ctx->chunk_size_len > 8) ctx->chunk_size_len = 8; @@ -954,7 +953,7 @@ H5D_farray_idx_create(const H5D_chk_idx_info_t *idx_info) /* Compute the size required for encoding the size of a chunk, allowing * for an extra byte, in case the filter makes the chunk larger. */ - chunk_size_len = 1 + ((H5VM_log2_gen(idx_info->layout->size) + 8) / 8); + chunk_size_len = 1 + ((H5VM_log2_gen((uint64_t)idx_info->layout->size) + 8) / 8); if(chunk_size_len > 8) chunk_size_len = 8; @@ -1218,14 +1217,12 @@ H5D_farray_idx_iterate_cb(hsize_t UNUSED idx, const void *_elmt, void *_udata) curr_dim = (int)(ndims - 1); while(curr_dim >= 0) { /* Increment coordinate in current dimension */ - udata->chunk_offset[curr_dim]++; - udata->chunk_rec.offset[curr_dim] += udata->common.layout->dim[curr_dim]; + udata->chunk_rec.scaled[curr_dim]++; /* Check if we went off the end of the current dimension */ - if(udata->chunk_offset[curr_dim] >= udata->common.layout->max_chunks[curr_dim]) { + if(udata->chunk_rec.scaled[curr_dim] >= udata->common.layout->chunks[curr_dim]) { /* Reset coordinate & move to next faster dimension */ - udata->chunk_offset[curr_dim] = 0; - udata->chunk_rec.offset[curr_dim] = 0; + udata->chunk_rec.scaled[curr_dim] = 0; curr_dim--; } /* end if */ else @@ -1292,7 +1289,6 @@ H5D_farray_idx_iterate(const H5D_chk_idx_info_t *idx_info, udata.common.storage = idx_info->storage; udata.common.rdcc = NULL; HDmemset(&udata.chunk_rec, 0, sizeof(udata.chunk_rec)); - HDmemset(&udata.chunk_offset, 0, sizeof(udata.chunk_offset)); udata.filtered = (idx_info->pline->nused > 0); if(!udata.filtered) { udata.chunk_rec.nbytes = idx_info->layout->size; diff --git a/src/H5Dint.c b/src/H5Dint.c index 40a2be6..0df7bb8 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -2373,20 +2373,43 @@ H5D__set_extent(H5D_t *dset, const hsize_t *size, hid_t dxpl_id) /* Determine if we are shrinking and/or expanding any dimensions */ for(u = 0; u < dset->shared->ndims; u++) { - hsize_t size_power2up; /* Size value, rounded to next power of 2 */ - /* Check for various status changes */ if(size[u] < curr_dims[u]) shrink = TRUE; if(size[u] > curr_dims[u]) expand = TRUE; - if(dset->shared->curr_power2up[u] != (size_power2up = H5VM_power2up(size[u]))) { - /* Update the 'power2up' value for the current dimension */ - dset->shared->curr_power2up[u] = size_power2up; - /* Only need to update the chunk indices if >1 dimension */ - if(u > 0) - update_chunks = TRUE; + /* Chunked storage specific checks */ + if(H5D_CHUNKED == dset->shared->layout.type && dset->shared->ndims > 1) { + hsize_t scaled; /* Scaled value */ + + /* Compute the scaled dimension size value */ + scaled = size[u] / dset->shared->layout.u.chunk.dim[u]; + + /* Check if scaled dimension size changed */ + if(scaled != dset->shared->cache.chunk.scaled_dims[u]) { + hsize_t scaled_power2up; /* Scaled value, rounded to next power of 2 */ + + /* Update the scaled dimension size value for the current dimension */ + dset->shared->cache.chunk.scaled_dims[u] = scaled; + + /* Check if algorithm for computing hash values will change */ + if((scaled > dset->shared->cache.chunk.nslots && + dset->shared->cache.chunk.scaled_dims[u] <= dset->shared->cache.chunk.nslots) + || (scaled <= dset->shared->cache.chunk.nslots && + dset->shared->cache.chunk.scaled_dims[u] > dset->shared->cache.chunk.nslots)) + update_chunks = TRUE; + + /* Check if the number of bits required to encode the scaled size value changed */ + if(dset->shared->cache.chunk.scaled_power2up[u] != (scaled_power2up = H5VM_power2up(scaled))) { + /* Update the 'power2up' & 'encode_bits' values for the current dimension */ + dset->shared->cache.chunk.scaled_power2up[u] = scaled_power2up; + dset->shared->cache.chunk.scaled_encode_bits[u] = H5VM_log2_gen(scaled_power2up); + + /* Indicate that the cached chunk indices need to be updated */ + update_chunks = TRUE; + } /* end if */ + } /* end if */ } /* end if */ /* Update the cached copy of the dataset's dimensions */ diff --git a/src/H5Dio.c b/src/H5Dio.c index 44080dc..f9e8f37 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -409,7 +409,7 @@ H5D__read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, mem_space = file_space; if((snelmts = H5S_GET_SELECT_NPOINTS(mem_space)) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "dst dataspace has invalid selection") - H5_ASSIGN_OVERFLOW(nelmts,snelmts,hssize_t,hsize_t); + H5_CHECKED_ASSIGN(nelmts, hsize_t, snelmts, hssize_t); /* Fill the DXPL cache values for later use */ if(H5D__get_dxpl_cache(dxpl_id, &dxpl_cache) < 0) @@ -679,7 +679,7 @@ H5D__write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, if((snelmts = H5S_GET_SELECT_NPOINTS(mem_space)) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "src dataspace has invalid selection") - H5_ASSIGN_OVERFLOW(nelmts, snelmts, hssize_t, hsize_t); + H5_CHECKED_ASSIGN(nelmts, hsize_t, snelmts, hssize_t); /* Make certain that the number of elements in each selection is the same */ if(nelmts != (hsize_t)H5S_GET_SELECT_NPOINTS(file_space)) diff --git a/src/H5Dmpio.c b/src/H5Dmpio.c index e94d2fa..63faa5d 100644 --- a/src/H5Dmpio.c +++ b/src/H5Dmpio.c @@ -438,7 +438,7 @@ H5D__mpio_get_sum_chunk(const H5D_io_info_t *io_info, const H5D_chunk_map_t *fm, /* Get the number of chunks to perform I/O on */ num_chunkf = 0; ori_num_chunkf = H5SL_count(fm->sel_chunks); - H5_ASSIGN_OVERFLOW(num_chunkf, ori_num_chunkf, size_t, int); + H5_CHECKED_ASSIGN(num_chunkf, int, ori_num_chunkf, size_t); /* Determine the summation of number of chunks for all processes */ if(MPI_SUCCESS != (mpi_code = MPI_Allreduce(&num_chunkf, sum_chunkf, 1, MPI_INT, MPI_SUM, io_info->comm))) @@ -826,7 +826,7 @@ H5D__link_chunk_collective_io(H5D_io_info_t *io_info, const H5D_type_info_t *typ } /* end if */ /* Retrieve total # of chunks in dataset */ - H5_ASSIGN_OVERFLOW(total_chunks, fm->layout->u.chunk.nchunks, hsize_t, size_t); + H5_CHECKED_ASSIGN(total_chunks, size_t, fm->layout->u.chunk.nchunks, hsize_t); /* Handle special case when dataspace dimensions only allow one chunk in * the dataset. [This sometimes is used by developers who want the @@ -860,8 +860,7 @@ H5D__link_chunk_collective_io(H5D_io_info_t *io_info, const H5D_type_info_t *typ mspace = chunk_info->mspace; /* Look up address of chunk */ - if(H5D__chunk_lookup(io_info->dset, io_info->dxpl_id, chunk_info->coords, - chunk_info->scaled, &udata) < 0) + if(H5D__chunk_lookup(io_info->dset, io_info->dxpl_id, chunk_info->scaled, &udata) < 0) HGOTO_ERROR(H5E_STORAGE, H5E_CANTGET, FAIL, "couldn't get chunk address") ctg_store.contig.dset_addr = udata.chunk_block.offset; } /* end else */ @@ -1149,7 +1148,7 @@ H5D__multi_chunk_collective_io(H5D_io_info_t *io_info, const H5D_type_info_t *ty #endif /* Retrieve total # of chunks in dataset */ - H5_ASSIGN_OVERFLOW(total_chunk, fm->layout->u.chunk.nchunks, hsize_t, size_t); + H5_CHECKED_ASSIGN(total_chunk, size_t, fm->layout->u.chunk.nchunks, hsize_t); HDassert(total_chunk != 0); /* Allocate memories */ @@ -1201,7 +1200,7 @@ if(H5DEBUG(D)) HDassert(chunk_info->index == u); /* Pass in chunk's coordinates in a union. */ - store.chunk.offset = chunk_info->coords; + store.chunk.scaled = chunk_info->scaled; } /* end if */ /* Collective IO for this chunk, @@ -1588,8 +1587,7 @@ if(H5DEBUG(D)) H5D_chunk_ud_t udata; /* User data for querying chunk info */ /* Get address of chunk */ - if(H5D__chunk_lookup(io_info->dset, io_info->dxpl_id, - chunk_info->coords, chunk_info->scaled, &udata) < 0) + if(H5D__chunk_lookup(io_info->dset, io_info->dxpl_id, chunk_info->scaled, &udata) < 0) HGOTO_ERROR(H5E_STORAGE, H5E_CANTGET, FAIL, "couldn't get chunk info from skipped list") chunk_addr = udata.chunk_block.offset; } /* end if */ @@ -1699,7 +1697,7 @@ H5D__obtain_mpio_mode(H5D_io_info_t* io_info, H5D_chunk_map_t *fm, HGOTO_ERROR(H5E_IO, H5E_MPI, FAIL, "unable to obtain mpi size") /* Setup parameters */ - H5_ASSIGN_OVERFLOW(total_chunks, fm->layout->u.chunk.nchunks, hsize_t, int); + H5_CHECKED_ASSIGN(total_chunks, int, fm->layout->u.chunk.nchunks, hsize_t); percent_nproc_per_chunk = H5P_peek_unsigned(dx_plist, H5D_XFER_MPIO_CHUNK_OPT_RATIO_NAME); /* if ratio is 0, perform collective io */ if(0 == percent_nproc_per_chunk) { diff --git a/src/H5Dnone.c b/src/H5Dnone.c index 1bea20a..b6a6967 100644 --- a/src/H5Dnone.c +++ b/src/H5Dnone.c @@ -234,7 +234,6 @@ H5D_none_iterate(const H5D_chk_idx_info_t *idx_info, H5D_chunk_cb_func_t chunk_cb, void *chunk_udata) { H5D_chunk_rec_t chunk_rec; /* generic chunk record */ - hsize_t chunk_offset[H5O_LAYOUT_NDIMS]; /* Offset for the chunk */ unsigned ndims; /* Rank of chunk */ unsigned u; /* Local index variable */ int curr_dim; /* Current rank */ @@ -258,15 +257,13 @@ H5D_none_iterate(const H5D_chk_idx_info_t *idx_info, chunk_rec.nbytes = idx_info->layout->size; chunk_rec.filter_mask = 0; - HDmemset(&chunk_offset, 0, sizeof(chunk_offset)); - ndims = idx_info->layout->ndims - 1; HDassert(ndims > 0); /* Iterate over all the chunks in the dataset's dataspace */ for(u = 0; u < idx_info->layout->nchunks; u++) { /* Calculate the index of this chunk */ - idx = H5VM_chunk_index(ndims, chunk_rec.offset, idx_info->layout->dim, idx_info->layout->max_down_chunks); + idx = H5VM_array_offset_pre(ndims, idx_info->layout->max_down_chunks, chunk_rec.scaled); /* Calculate the address of the chunk */ chunk_rec.chunk_addr = idx_info->storage->idx_addr + idx * idx_info->layout->size; @@ -279,14 +276,12 @@ H5D_none_iterate(const H5D_chk_idx_info_t *idx_info, curr_dim = (int)(ndims - 1); while(curr_dim >= 0) { /* Increment coordinate in current dimension */ - chunk_offset[curr_dim]++; - chunk_rec.offset[curr_dim] += idx_info->layout->dim[curr_dim]; + chunk_rec.scaled[curr_dim]++; /* Check if we went off the end of the current dimension */ - if(chunk_offset[curr_dim] >= idx_info->layout->chunks[curr_dim]) { + if(chunk_rec.scaled[curr_dim] >= idx_info->layout->chunks[curr_dim]) { /* Reset coordinate & move to next faster dimension */ - chunk_offset[curr_dim] = 0; - chunk_rec.offset[curr_dim] = 0; + chunk_rec.scaled[curr_dim] = 0; curr_dim--; } /* end if */ else diff --git a/src/H5Dpkg.h b/src/H5Dpkg.h index 8c0f806..a29bd79 100644 --- a/src/H5Dpkg.h +++ b/src/H5Dpkg.h @@ -185,8 +185,7 @@ typedef struct { } H5D_contig_storage_t; typedef struct { - hsize_t index; /* "Index" of chunk in dataset (must be first for TBBT routines) */ - hsize_t *offset; /* Chunk's coordinates in elements */ + hsize_t *scaled; /* Scaled coordinates for a chunk */ } H5D_chunk_storage_t; typedef struct { @@ -259,7 +258,7 @@ typedef struct H5D_chk_idx_info_t { * The chunk's file address, filter mask and size on disk are not key values. */ typedef struct H5D_chunk_rec_t { - hsize_t offset[H5O_LAYOUT_NDIMS]; /* Logical offset to start */ + hsize_t scaled[H5O_LAYOUT_NDIMS]; /* Logical offset to start */ uint32_t nbytes; /* Size of stored data */ unsigned filter_mask; /* Excluded filters */ haddr_t chunk_addr; /* Address of chunk in file */ @@ -274,8 +273,6 @@ typedef struct H5D_chunk_common_ud_t { /* downward */ const H5O_layout_chunk_t *layout; /* Chunk layout description */ const H5O_storage_chunk_t *storage; /* Chunk storage description */ - const hsize_t *offset; /* Logical offset of chunk */ - const hsize_t *space_dim; /* Dataset dimension sizes */ const hsize_t *scaled; /* Scaled coordinates for a chunk */ const struct H5D_rdcc_t *rdcc; /* Chunk cache. Only necessary if the index may * be modified, and if any chunks in the dset @@ -349,7 +346,6 @@ typedef struct H5D_chunk_ops_t { typedef struct H5D_chunk_info_t { hsize_t index; /* "Index" of chunk in dataset */ uint32_t chunk_points; /* Number of elements selected in chunk */ - hsize_t coords[H5O_LAYOUT_NDIMS]; /* Coordinates of chunk in file dataset's dataspace */ hsize_t scaled[H5O_LAYOUT_NDIMS]; /* Scaled coordinates of chunk (in file dataset's dataspace) */ H5S_t *fspace; /* Dataspace describing chunk & selection in it */ hbool_t fspace_shared; /* Indicate that the file space for a chunk is shared and shouldn't be freed */ @@ -390,7 +386,7 @@ typedef struct H5D_chunk_map_t { /* Cached information about a particular chunk */ typedef struct H5D_chunk_cached_t { hbool_t valid; /*whether cache info is valid*/ - hsize_t offset[H5O_LAYOUT_NDIMS]; /*logical offset to start*/ + hsize_t scaled[H5O_LAYOUT_NDIMS]; /*scaled offset of chunk*/ haddr_t addr; /*file address of chunk */ uint32_t nbytes; /*size of stored data */ hsize_t chunk_idx; /*index of chunk in dataset */ @@ -418,6 +414,11 @@ typedef struct H5D_rdcc_t { H5SL_t *sel_chunks; /* Skip list containing information for each chunk selected */ H5S_t *single_space; /* Dataspace for single element I/O on chunks */ H5D_chunk_info_t *single_chunk_info; /* Pointer to single chunk's info */ + + /* Cached information about scaled dataspace dimensions */ + hsize_t scaled_dims[H5S_MAX_RANK]; /* The scaled dim sizes */ + hsize_t scaled_power2up[H5S_MAX_RANK]; /* The scaled dim sizes, rounded up to next power of 2 */ + unsigned scaled_encode_bits[H5S_MAX_RANK]; /* The number of bits needed to encode the scaled dim sizes */ } H5D_rdcc_t; /* The raw data contiguous data cache */ @@ -535,7 +536,6 @@ typedef struct H5D_rdcc_ent_t { hbool_t dirty; /*needs to be written to disk? */ hbool_t deleted; /*chunk about to be deleted */ unsigned edge_chunk_state; /*states related to edge chunks (see above) */ - hsize_t offset[H5O_LAYOUT_NDIMS]; /*chunk name */ hsize_t scaled[H5O_LAYOUT_NDIMS]; /*scaled chunk 'name' (coordinates) */ uint32_t rd_count; /*bytes remaining to be read */ uint32_t wr_count; /*bytes remaining to be written */ @@ -669,7 +669,7 @@ H5_DLL herr_t H5D__chunk_init(H5F_t *f, hid_t dxpl_id, const H5D_t *dset, hid_t dapl_id); H5_DLL hbool_t H5D__chunk_is_space_alloc(const H5O_storage_t *storage); H5_DLL herr_t H5D__chunk_lookup(const H5D_t *dset, hid_t dxpl_id, - const hsize_t *chunk_offset, const hsize_t *scaled, H5D_chunk_ud_t *udata); + const hsize_t *scaled, H5D_chunk_ud_t *udata); H5_DLL void *H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, hbool_t relax, hbool_t prev_unfilt_chunk); H5_DLL herr_t H5D__chunk_unlock(const H5D_io_info_t *io_info, diff --git a/src/H5Dprivate.h b/src/H5Dprivate.h index cfb8763..64a94b7 100644 --- a/src/H5Dprivate.h +++ b/src/H5Dprivate.h @@ -177,7 +177,7 @@ H5_DLL herr_t H5D_chunk_idx_reset(H5O_storage_chunk_t *storage, hbool_t reset_ad /* Functions that operate on indexed storage */ H5_DLL herr_t H5D_btree_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, - int indent, int fwidth, unsigned ndims); + int indent, int fwidth, unsigned ndims, const uint32_t *dim); #endif /* _H5Dprivate_H */ diff --git a/src/H5EA.c b/src/H5EA.c index ac6d1be..0146cfd 100644 --- a/src/H5EA.c +++ b/src/H5EA.c @@ -103,6 +103,8 @@ const H5EA_class_t *const H5EA_client_class_g[] = { /* Declare a free list to manage the H5EA_t struct */ H5FL_DEFINE_STATIC(H5EA_t); +/* Declare a PQ free list to manage the element */ +H5FL_BLK_DEFINE(ea_native_elmt); /*------------------------------------------------------------------------- @@ -1029,3 +1031,56 @@ CATCH END_FUNC(PRIV) /* end H5EA_delete() */ + +/*------------------------------------------------------------------------- + * Function: H5EA_iterate + * + * Purpose: Iterate over the elements of an extensible array + * (copied and modified from FA_iterate() in H5FA.c) + * + * Return: SUCCEED/FAIL + * + * Programmer: Vailin Choi; Feb 2015 + * + *------------------------------------------------------------------------- + */ +BEGIN_FUNC(PRIV, ERR, +herr_t, SUCCEED, FAIL, +H5EA_iterate(H5EA_t *ea, hid_t dxpl_id, H5EA_operator_t op, void *udata)) + + /* Local variables */ + uint8_t *elmt = NULL; + hsize_t u; + + /* + * Check arguments. + */ + HDassert(ea); + HDassert(op); + HDassert(udata); + + /* Allocate space for a native array element */ + if(NULL == (elmt = H5FL_BLK_MALLOC(ea_native_elmt, ea->hdr->cparam.cls->nat_elmt_size))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array element") + + /* Iterate over all elements in array */ + for(u = 0; u < ea->hdr->stats.stored.max_idx_set; u++) { + int cb_ret; /* Return value from callback */ + + /* Get array element */ + if(H5EA_get(ea, dxpl_id, u, elmt) < 0) + H5E_THROW(H5E_CANTGET, "unable to delete fixed array") + + /* Make callback */ + if((cb_ret = (*op)(u, elmt, udata)) < 0) { + H5E_PRINTF(H5E_BADITER, "iterator function failed"); + H5_LEAVE(cb_ret) + } /* end if */ + } /* end for */ + +CATCH + + if(elmt) + elmt = H5FL_BLK_FREE(ea_native_elmt, elmt); + +END_FUNC(PRIV) /* end H5EA_iterate() */ diff --git a/src/H5EAprivate.h b/src/H5EAprivate.h index b770881..92c2849 100644 --- a/src/H5EAprivate.h +++ b/src/H5EAprivate.h @@ -115,6 +115,9 @@ typedef struct H5EA_stat_t { /* Extensible array info (forward decl - defined in H5EApkg.h) */ typedef struct H5EA_t H5EA_t; +/* Define the operator callback function pointer for H5EA_iterate() */ +typedef int (*H5EA_operator_t)(hsize_t idx, const void *_elmt, void *_udata); + /*****************************/ /* Library-private Variables */ @@ -141,6 +144,7 @@ H5_DLL herr_t H5EA_set(const H5EA_t *ea, hid_t dxpl_id, hsize_t idx, const void H5_DLL herr_t H5EA_get(const H5EA_t *ea, hid_t dxpl_id, hsize_t idx, void *elmt); H5_DLL herr_t H5EA_depend(H5AC_info_t *parent_entry, H5EA_t *ea); H5_DLL herr_t H5EA_undepend(H5AC_info_t *parent_entry, H5EA_t *ea); +H5_DLL herr_t H5EA_iterate(H5EA_t *ea, hid_t dxpl_id, H5EA_operator_t op, void *udata); H5_DLL herr_t H5EA_close(H5EA_t *ea, hid_t dxpl_id); H5_DLL herr_t H5EA_delete(H5F_t *f, hid_t dxpl_id, haddr_t ea_addr, void *ctx_udata); diff --git a/src/H5FAdblock.c b/src/H5FAdblock.c index ea24d27..9e9e3ea 100644 --- a/src/H5FAdblock.c +++ b/src/H5FAdblock.c @@ -129,7 +129,7 @@ H5FA__dblock_alloc(H5FA_hdr_t *hdr, hsize_t nelmts)) hsize_t npages = ((nelmts + dblock->dblk_page_nelmts) - 1) / dblock->dblk_page_nelmts; /* Safely assign the number of pages */ - H5_ASSIGN_OVERFLOW(/* To: */ dblock->npages, /* From: */ npages, /* From: */ hsize_t, /* To: */ size_t); + H5_CHECKED_ASSIGN(dblock->npages, size_t, npages, hsize_t); /* Sanity check that we have at least 1 page */ HDassert(dblock->npages > 0); diff --git a/src/H5FD.c b/src/H5FD.c index b5cb8df..049a6e7 100644 --- a/src/H5FD.c +++ b/src/H5FD.c @@ -1844,12 +1844,12 @@ done: *------------------------------------------------------------------------- */ herr_t -H5FDtruncate(H5FD_t *file, hid_t dxpl_id, unsigned closing) +H5FDtruncate(H5FD_t *file, hid_t dxpl_id, hbool_t closing) { herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) - H5TRACE3("e", "*xiIu", file, dxpl_id, closing); + H5TRACE3("e", "*xib", file, dxpl_id, closing); /* Check args */ if(!file || !file->cls) @@ -1883,7 +1883,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5FD_truncate(H5FD_t *file, hid_t dxpl_id, unsigned closing) +H5FD_truncate(H5FD_t *file, hid_t dxpl_id, hbool_t closing) { herr_t ret_value = SUCCEED; /* Return value */ diff --git a/src/H5FDcore.c b/src/H5FDcore.c index 8a4c8d1..189a0ed 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -1301,7 +1301,7 @@ H5FD_core_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, had size_t new_eof; /* Determine new size of memory buffer */ - H5_ASSIGN_OVERFLOW(new_eof, file->increment * ((addr + size) / file->increment), hsize_t, size_t); + H5_CHECKED_ASSIGN(new_eof, size_t, file->increment * ((addr + size) / file->increment), hsize_t); if((addr + size) % file->increment) new_eof += file->increment; @@ -1470,7 +1470,7 @@ H5FD_core_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, hbool_t closing) new_eof = file->eoa; else { /* set eof to smallest multiple of increment that exceeds eoa */ /* Determine new size of memory buffer */ - H5_ASSIGN_OVERFLOW(new_eof, file->increment * (file->eoa / file->increment), hsize_t, size_t); + H5_CHECKED_ASSIGN(new_eof, size_t, file->increment * (file->eoa / file->increment), hsize_t); if(file->eoa % file->increment) new_eof += file->increment; } /* end else */ diff --git a/src/H5FDdirect.c b/src/H5FDdirect.c index 65c2691..0525a2b 100644 --- a/src/H5FDdirect.c +++ b/src/H5FDdirect.c @@ -516,7 +516,7 @@ H5FD_direct_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxadd HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, NULL, "bad VFL driver info") file->fd = fd; - H5_ASSIGN_OVERFLOW(file->eof,sb.st_size,h5_stat_size_t,haddr_t); + H5_CHECKED_ASSIGN(file->eof, haddr_t, sb.st_size, h5_stat_size_t); file->pos = HADDR_UNDEF; file->op = OP_UNKNOWN; #ifdef H5_HAVE_WIN32_API diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c index ad703ef..e79e1cf 100644 --- a/src/H5FDfamily.c +++ b/src/H5FDfamily.c @@ -1170,7 +1170,7 @@ H5FD_family_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, si /* Read from each member */ while(size > 0) { - H5_ASSIGN_OVERFLOW(u,addr /file->memb_size,hsize_t,unsigned); + H5_CHECKED_ASSIGN(u, unsigned, addr / file->memb_size, hsize_t); sub = addr % file->memb_size; @@ -1239,7 +1239,7 @@ H5FD_family_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, s /* Write to each member */ while (size>0) { - H5_ASSIGN_OVERFLOW(u,addr /file->memb_size,hsize_t,unsigned); + H5_CHECKED_ASSIGN(u, unsigned, addr / file->memb_size, hsize_t); sub = addr % file->memb_size; diff --git a/src/H5FDlog.c b/src/H5FDlog.c index a2284dd..cc0caa4 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -571,7 +571,7 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate file struct") file->fd = fd; - H5_ASSIGN_OVERFLOW(file->eof, sb.st_size, h5_stat_size_t, haddr_t); + H5_CHECKED_ASSIGN(file->eof, haddr_t, sb.st_size, h5_stat_size_t); file->pos = HADDR_UNDEF; file->op = OP_UNKNOWN; #ifdef H5_HAVE_WIN32_API diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h index e98f0f4..20e9a79 100644 --- a/src/H5FDprivate.h +++ b/src/H5FDprivate.h @@ -134,7 +134,7 @@ H5_DLL herr_t H5FD_read(H5FD_t *file, const H5P_genplist_t *dxpl, H5FD_mem_t typ haddr_t addr, size_t size, void *buf/*out*/); H5_DLL herr_t H5FD_write(H5FD_t *file, const H5P_genplist_t *dxpl, H5FD_mem_t type, haddr_t addr, size_t size, const void *buf); -H5_DLL herr_t H5FD_flush(H5FD_t *file, hid_t dxpl_id, hbool_t closing); +H5_DLL herr_t H5FD_flush(H5FD_t *file, hid_t dxpl_id, unsigned closing); H5_DLL herr_t H5FD_truncate(H5FD_t *file, hid_t dxpl_id, hbool_t closing); H5_DLL herr_t H5FD_get_fileno(const H5FD_t *file, unsigned long *filenum); H5_DLL herr_t H5FD_get_vfd_handle(H5FD_t *file, hid_t fapl, void** file_handle); diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index 49a363e..1a548f1 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -359,7 +359,7 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate file struct") file->fd = fd; - H5_ASSIGN_OVERFLOW(file->eof, sb.st_size, h5_stat_size_t, haddr_t); + H5_CHECKED_ASSIGN(file->eof, haddr_t, sb.st_size, h5_stat_size_t); file->pos = HADDR_UNDEF; file->op = OP_UNKNOWN; #ifdef H5_HAVE_WIN32_API diff --git a/src/H5FScache.c b/src/H5FScache.c index 7c1c642..27feb63 100644 --- a/src/H5FScache.c +++ b/src/H5FScache.c @@ -573,7 +573,7 @@ H5FS_cache_sinfo_load(H5F_t *f, hid_t dxpl_id, haddr_t UNUSED addr, void *_udata HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Allocate space for the buffer to serialize the sections into */ - H5_ASSIGN_OVERFLOW(/* To: */ old_sect_size, /* From: */ udata->fspace->sect_size, /* From: */ hsize_t, /* To: */ size_t); + H5_CHECKED_ASSIGN(old_sect_size, size_t, udata->fspace->sect_size, hsize_t); if(NULL == (buf = H5FL_BLK_MALLOC(sect_block, (size_t)udata->fspace->sect_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") @@ -1078,7 +1078,7 @@ H5FS_cache_sinfo_size(const H5F_t UNUSED *f, const H5FS_sinfo_t *sinfo, size_t * HDassert(size_ptr); /* Set size value */ - H5_ASSIGN_OVERFLOW(/* To: */ *size_ptr, /* From: */ sinfo->fspace->alloc_sect_size, /* From: */ hsize_t, /* To: */ size_t); + H5_CHECKED_ASSIGN(*size_ptr, size_t, sinfo->fspace->alloc_sect_size, hsize_t); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5FS_cache_sinfo_size() */ diff --git a/src/H5Faccum.c b/src/H5Faccum.c index f84bef5..51dd82a 100644 --- a/src/H5Faccum.c +++ b/src/H5Faccum.c @@ -172,7 +172,7 @@ H5F__accum_read(const H5F_io_info_t *fio_info, H5FD_mem_t type, haddr_t addr, /* Read the part before the metadata accumulator */ if(addr < accum->loc) { /* Set the amount to read */ - H5_ASSIGN_OVERFLOW(amount_before, (accum->loc - addr), hsize_t, size_t); + H5_CHECKED_ASSIGN(amount_before, size_t, (accum->loc - addr), hsize_t); /* Make room for the metadata to read in */ HDmemmove(accum->buf + amount_before, accum->buf, accum->size); @@ -193,7 +193,7 @@ H5F__accum_read(const H5F_io_info_t *fio_info, H5FD_mem_t type, haddr_t addr, size_t amount_after; /* Amount to read at a time */ /* Set the amount to read */ - H5_ASSIGN_OVERFLOW(amount_after, ((addr + size) - (accum->loc + accum->size)), hsize_t, size_t); + H5_CHECKED_ASSIGN(amount_after, size_t, ((addr + size) - (accum->loc + accum->size)), hsize_t); /* Dispatch to driver */ if(H5FD_read(fio_info->f->shared->lf, fio_info->dxpl, map_type, (accum->loc + accum->size), amount_after, (accum->buf + accum->size + amount_before)) < 0) @@ -541,14 +541,14 @@ H5F__accum_write(const H5F_io_info_t *fio_info, H5FD_mem_t type, haddr_t addr, size_t old_offset; /* Offset of old data within the accumulator buffer */ /* Calculate the amount we will need to add to the accumulator size, based on the amount of overlap */ - H5_ASSIGN_OVERFLOW(add_size, (accum->loc - addr), hsize_t, size_t); + H5_CHECKED_ASSIGN(add_size, size_t, (accum->loc - addr), hsize_t); /* Check if we need to adjust accumulator size */ if(H5F__accum_adjust(accum, fio_info, H5F_ACCUM_PREPEND, add_size) < 0) HGOTO_ERROR(H5E_IO, H5E_CANTRESIZE, FAIL, "can't adjust metadata accumulator") /* Calculate the proper offset of the existing metadata */ - H5_ASSIGN_OVERFLOW(old_offset, (addr + size) - accum->loc, hsize_t, size_t); + H5_CHECKED_ASSIGN(old_offset, size_t, (addr + size) - accum->loc, hsize_t); /* Move the existing metadata to the proper location */ HDmemmove(accum->buf + size, accum->buf + old_offset, (accum->size - old_offset)); @@ -581,7 +581,7 @@ H5F__accum_write(const H5F_io_info_t *fio_info, H5FD_mem_t type, haddr_t addr, size_t dirty_off; /* Offset of dirty region */ /* Calculate the amount we will need to add to the accumulator size, based on the amount of overlap */ - H5_ASSIGN_OVERFLOW(add_size, (addr + size) - (accum->loc + accum->size), hsize_t, size_t); + H5_CHECKED_ASSIGN(add_size, size_t, (addr + size) - (accum->loc + accum->size), hsize_t); /* Check if we need to adjust accumulator size */ if(H5F__accum_adjust(accum, fio_info, H5F_ACCUM_APPEND, add_size) < 0) @@ -896,7 +896,7 @@ H5F__accum_free(const H5F_io_info_t *fio_info, H5FD_mem_t UNUSED type, haddr_t a size_t new_accum_size; /* Size of new accumulator buffer */ /* Calculate the size of the overlap with the accumulator, etc. */ - H5_ASSIGN_OVERFLOW(overlap_size, (addr + size) - accum->loc, haddr_t, size_t); + H5_CHECKED_ASSIGN(overlap_size, size_t, (addr + size) - accum->loc, haddr_t); new_accum_size = accum->size - overlap_size; /* Move the accumulator buffer information to eliminate the freed block */ @@ -930,7 +930,7 @@ H5F__accum_free(const H5F_io_info_t *fio_info, H5FD_mem_t UNUSED type, haddr_t a haddr_t dirty_start = accum->loc + accum->dirty_off; /* Calculate the size of the overlap with the accumulator */ - H5_ASSIGN_OVERFLOW(overlap_size, (accum->loc + accum->size) - addr, haddr_t, size_t); + H5_CHECKED_ASSIGN(overlap_size, size_t, (accum->loc + accum->size) - addr, haddr_t); /* Check if block to free begins before end of dirty region */ if(accum->dirty && H5F_addr_lt(addr, dirty_end)) { diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 725812f..e59e643 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -244,7 +244,6 @@ #define H5F_addr_overflow(X,Z) (HADDR_UNDEF==(X) || \ HADDR_UNDEF==(X)+(haddr_t)(Z) || \ (X)+(haddr_t)(Z)<(X)) -#define H5F_addr_hash(X,M) ((unsigned)((X)%(M))) #define H5F_addr_defined(X) ((X)!=HADDR_UNDEF) /* The H5F_addr_eq() macro guarantees that Y is not HADDR_UNDEF by making * certain that X is not HADDR_UNDEF and then checking that X equals Y diff --git a/src/H5Fsuper.c b/src/H5Fsuper.c index dd80a46..845ab8c 100644 --- a/src/H5Fsuper.c +++ b/src/H5Fsuper.c @@ -434,7 +434,7 @@ H5F_super_init(H5F_t *f, hid_t dxpl_id) superblock_size = (hsize_t)H5F_SUPERBLOCK_SIZE(super_vers, f); /* Compute the size of the driver information block */ - H5_ASSIGN_OVERFLOW(driver_size, H5FD_sb_size(f->shared->lf), hsize_t, size_t); + H5_CHECKED_ASSIGN(driver_size, size_t, H5FD_sb_size(f->shared->lf), hsize_t); if(driver_size > 0) { driver_size += H5F_DRVINFOBLOCK_HDR_SIZE; diff --git a/src/H5Fsuper_cache.c b/src/H5Fsuper_cache.c index 5fc1c7c..15cd648 100644 --- a/src/H5Fsuper_cache.c +++ b/src/H5Fsuper_cache.c @@ -727,7 +727,7 @@ H5F_sblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t UNUSED addr, HGOTO_ERROR(H5E_FILE, H5E_CANTENCODE, FAIL, "can't encode root group symbol table entry") /* Encode the driver information block. */ - H5_ASSIGN_OVERFLOW(driver_size, H5FD_sb_size(f->shared->lf), hsize_t, size_t); + H5_CHECKED_ASSIGN(driver_size, size_t, H5FD_sb_size(f->shared->lf), hsize_t); /* Checking whether driver block address is defined here is to handle backward * compatibility. If the file was created with v1.6 library or earlier and no @@ -803,7 +803,7 @@ H5F_sblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t UNUSED addr, } /* end else */ /* Retrieve the total size of the superblock info */ - H5_ASSIGN_OVERFLOW(superblock_size, (p - buf), ptrdiff_t, size_t); + H5_CHECKED_ASSIGN(superblock_size, size_t, (p - buf), ptrdiff_t); /* Double check we didn't overrun the block (unlikely) */ HDassert(superblock_size <= sizeof(buf)); @@ -828,7 +828,7 @@ H5F_sblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t UNUSED addr, /* Check for ignoring the driver info for this file */ if(!H5F_HAS_FEATURE(f, H5FD_FEAT_IGNORE_DRVRINFO)) { /* Check for driver info message */ - H5_ASSIGN_OVERFLOW(driver_size, H5FD_sb_size(f->shared->lf), hsize_t, size_t); + H5_CHECKED_ASSIGN(driver_size, size_t, H5FD_sb_size(f->shared->lf), hsize_t); if(driver_size > 0) { H5O_drvinfo_t drvinfo; /* Driver info */ uint8_t dbuf[H5F_MAX_DRVINFOBLOCK_SIZE]; /* Driver info block encoding buffer */ diff --git a/src/H5Gdeprec.c b/src/H5Gdeprec.c index ca9e7fd..8f2fe54 100644 --- a/src/H5Gdeprec.c +++ b/src/H5Gdeprec.c @@ -261,7 +261,7 @@ H5Gcreate1(hid_t loc_id, const char *name, size_t size_hint) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get group info") /* Set the non-default local heap size hint */ - H5_ASSIGN_OVERFLOW(ginfo.lheap_size_hint, size_hint, size_t, uint32_t); + H5_CHECKED_ASSIGN(ginfo.lheap_size_hint, uint32_t, size_hint, size_t); if(H5P_set(gc_plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set group info") } /* end if */ diff --git a/src/H5Glink.c b/src/H5Glink.c index f934052..8b258b5 100644 --- a/src/H5Glink.c +++ b/src/H5Glink.c @@ -467,7 +467,7 @@ H5G__link_iterate_table(const H5G_link_table_t *ltable, hsize_t skip, *last_lnk += skip; /* Iterate over link messages */ - H5_ASSIGN_OVERFLOW(/* To: */ u, /* From: */ skip, /* From: */ hsize_t, /* To: */ size_t) + H5_CHECKED_ASSIGN(u, size_t, skip, hsize_t) for(; u < ltable->nlinks && !ret_value; u++) { /* Make the callback */ ret_value = (op)(&(ltable->lnks[u]), op_data); diff --git a/src/H5HFdbg.c b/src/H5HFdbg.c index 7d22ddd..8620f6f 100644 --- a/src/H5HFdbg.c +++ b/src/H5HFdbg.c @@ -387,11 +387,11 @@ H5HF_dblock_debug_cb(H5FS_section_info_t *_sect, void *_udata) if(sect_start < dblock_start) start = 0; else - H5_ASSIGN_OVERFLOW(/* To: */ start, /* From: */ (sect_start - dblock_start), /* From: */ hsize_t, /* To: */ size_t) + H5_CHECKED_ASSIGN(start, size_t, (sect_start - dblock_start), hsize_t) if(sect_end > dblock_end) - H5_ASSIGN_OVERFLOW(/* To: */ end, /* From: */ udata->dblock_size, /* From: */ hsize_t, /* To: */ size_t) + H5_CHECKED_ASSIGN(end, size_t, udata->dblock_size, hsize_t) else - H5_ASSIGN_OVERFLOW(/* To: */ end, /* From: */ ((sect_end - dblock_start) + 1), /* From: */ hsize_t, /* To: */ size_t) + H5_CHECKED_ASSIGN(end, size_t, ((sect_end - dblock_start) + 1), hsize_t) /* Calculate the length */ len = end - start; diff --git a/src/H5HFdblock.c b/src/H5HFdblock.c index 02890ab..3a54bb9 100644 --- a/src/H5HFdblock.c +++ b/src/H5HFdblock.c @@ -131,7 +131,7 @@ H5HF_man_dblock_create(hid_t dxpl_id, H5HF_hdr_t *hdr, H5HF_indirect_t *par_iblo dblock->block_off = par_iblock->block_off; dblock->block_off += hdr->man_dtable.row_block_off[par_row]; dblock->block_off += hdr->man_dtable.row_block_size[par_row] * (par_entry % hdr->man_dtable.cparam.width); - H5_ASSIGN_OVERFLOW(/* To: */ dblock->size, /* From: */ hdr->man_dtable.row_block_size[par_row], /* From: */ hsize_t, /* To: */ size_t); + H5_CHECKED_ASSIGN(dblock->size, size_t, hdr->man_dtable.row_block_size[par_row], hsize_t); } /* end if */ else { /* Must be the root direct block */ @@ -397,7 +397,7 @@ H5HF_man_dblock_new(H5HF_hdr_t *hdr, hid_t dxpl_id, size_t request, if(H5HF_man_iter_curr(&hdr->next_block, &next_row, NULL, &next_entry, &iblock) < 0) HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "unable to retrieve current block iterator location") HDassert(next_row < iblock->nrows); - H5_ASSIGN_OVERFLOW(/* To: */ next_size, /* From: */ hdr->man_dtable.row_block_size[next_row], /* From: */ hsize_t, /* To: */ size_t); + H5_CHECKED_ASSIGN(next_size, size_t, hdr->man_dtable.row_block_size[next_row], hsize_t); /* Check for skipping over blocks */ if(min_dblock_size > next_size) { diff --git a/src/H5HFdtable.c b/src/H5HFdtable.c index 607862a..c523396 100644 --- a/src/H5HFdtable.c +++ b/src/H5HFdtable.c @@ -168,7 +168,7 @@ HDfprintf(stderr, "%s: off = %Hu\n", "H5HF_dtable_lookup", off); /* Check for offset in first row */ if(off < dtable->num_id_first_row) { *row = 0; - H5_ASSIGN_OVERFLOW(/* To: */ *col, /* From: */ (off / dtable->cparam.start_block_size), /* From: */ hsize_t, /* To: */ unsigned); + H5_CHECKED_ASSIGN(*col, unsigned, (off / dtable->cparam.start_block_size), hsize_t); } /* end if */ else { unsigned high_bit = H5VM_log2_gen(off); /* Determine the high bit in the offset */ @@ -178,7 +178,7 @@ HDfprintf(stderr, "%s: off = %Hu\n", "H5HF_dtable_lookup", off); HDfprintf(stderr, "%s: high_bit = %u, off_mask = %Hu\n", "H5HF_dtable_lookup", high_bit, off_mask); #endif /* QAK */ *row = (high_bit - dtable->first_row_bits) + 1; - H5_ASSIGN_OVERFLOW(/* To: */ *col, /* From: */ ((off - off_mask) / dtable->row_block_size[*row]), /* From: */ hsize_t, /* To: */ unsigned); + H5_CHECKED_ASSIGN(*col, unsigned, ((off - off_mask) / dtable->row_block_size[*row]), hsize_t); } /* end else */ FUNC_LEAVE_NOAPI(SUCCEED) diff --git a/src/H5HFhdr.c b/src/H5HFhdr.c index 583029d..bfc8fc6 100644 --- a/src/H5HFhdr.c +++ b/src/H5HFhdr.c @@ -263,7 +263,7 @@ H5HF_hdr_finish_init_phase2(H5HF_hdr_t *hdr) if(u < hdr->man_dtable.max_direct_rows) { hdr->man_dtable.row_tot_dblock_free[u] = hdr->man_dtable.row_block_size[u] - H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr); - H5_ASSIGN_OVERFLOW(/* To: */ hdr->man_dtable.row_max_dblock_free[u], /* From: */ hdr->man_dtable.row_tot_dblock_free[u], /* From: */ hsize_t, /* To: */ size_t); + H5_CHECKED_ASSIGN(hdr->man_dtable.row_max_dblock_free[u], size_t, hdr->man_dtable.row_tot_dblock_free[u], hsize_t); } /* end if */ else if(H5HF_hdr_compute_free_space(hdr, u) < 0) diff --git a/src/H5HFhuge.c b/src/H5HFhuge.c index 1fe1468..7c3b5f9 100644 --- a/src/H5HFhuge.c +++ b/src/H5HFhuge.c @@ -656,7 +656,7 @@ H5HF_huge_op_real(H5HF_hdr_t *hdr, hid_t dxpl_id, const uint8_t *id, /* Retrieve the object's address & length */ obj_addr = found_rec.addr; - H5_ASSIGN_OVERFLOW(/* To: */ obj_size, /* From: */ found_rec.len, /* From: */ hsize_t, /* To: */ size_t); + H5_CHECKED_ASSIGN(obj_size, size_t, found_rec.len, hsize_t); filter_mask = found_rec.filter_mask; } /* end if */ else { @@ -672,7 +672,7 @@ H5HF_huge_op_real(H5HF_hdr_t *hdr, hid_t dxpl_id, const uint8_t *id, /* Retrieve the object's address & length */ obj_addr = found_rec.addr; - H5_ASSIGN_OVERFLOW(/* To: */ obj_size, /* From: */ found_rec.len, /* From: */ hsize_t, /* To: */ size_t); + H5_CHECKED_ASSIGN(obj_size, size_t, found_rec.len, hsize_t); } /* end else */ } /* end else */ @@ -800,7 +800,7 @@ H5HF_huge_write(H5HF_hdr_t *hdr, hid_t dxpl_id, const uint8_t *id, /* Retrieve the object's address & length */ obj_addr = found_rec.addr; - H5_ASSIGN_OVERFLOW(/* To: */ obj_size, /* From: */ found_rec.len, /* From: */ hsize_t, /* To: */ size_t); + H5_CHECKED_ASSIGN(obj_size, size_t, found_rec.len, hsize_t); } /* end else */ /* Write the object's data to the file */ diff --git a/src/H5HLcache.c b/src/H5HLcache.c index 0ca3b67..ab6ab2c 100644 --- a/src/H5HLcache.c +++ b/src/H5HLcache.c @@ -257,6 +257,7 @@ H5HL__prefix_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) size_t spec_read_size; /* Size of buffer to speculatively read in */ const uint8_t *p; /* Pointer into decoding buffer */ haddr_t eoa; /* Relative end of file address */ + hsize_t min; /* temp min value to avoid macro nesting */ /* check arguments */ HDassert(f); @@ -272,7 +273,8 @@ H5HL__prefix_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)) H5E_THROW(H5E_CANTGET, "unable to determine file size"); /* Compute the size of the speculative local heap prefix buffer */ - H5_ASSIGN_OVERFLOW(spec_read_size, MIN(eoa - addr, H5HL_SPEC_READ_SIZE), /* From: */ hsize_t, /* To: */ size_t); + min = MIN(eoa - addr, H5HL_SPEC_READ_SIZE); + H5_CHECKED_ASSIGN(spec_read_size, size_t, min, hsize_t); HDassert(spec_read_size >= udata->sizeof_prfx); /* Attempt to speculatively read both local heap prefix and heap data */ diff --git a/src/H5I.c b/src/H5I.c index 4924e5f..0122eb6 100644 --- a/src/H5I.c +++ b/src/H5I.c @@ -433,7 +433,7 @@ H5Inmembers(H5I_type_t type, hsize_t *num_members) if((members = H5I_nmembers(type)) < 0) HGOTO_ERROR(H5E_ATOM, H5E_CANTCOUNT, FAIL, "can't compute number of members") - H5_ASSIGN_OVERFLOW(*num_members, members, int64_t, hsize_t); + H5_CHECKED_ASSIGN(*num_members, hsize_t, members, int64_t); } /* end if */ done: @@ -460,7 +460,7 @@ int64_t H5I_nmembers(H5I_type_t type) { H5I_id_type_t *type_ptr = NULL; - int ret_value; + int64_t ret_value; FUNC_ENTER_NOAPI(FAIL) @@ -470,7 +470,7 @@ H5I_nmembers(H5I_type_t type) HGOTO_DONE(0); /* Set return value */ - H5_ASSIGN_OVERFLOW(ret_value, type_ptr->id_count, uint64_t, int64_t); + H5_CHECKED_ASSIGN(ret_value, int64_t, type_ptr->id_count, uint64_t); done: FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5MF.c b/src/H5MF.c index 29e9ece..eecd724 100644 --- a/src/H5MF.c +++ b/src/H5MF.c @@ -1383,7 +1383,7 @@ H5MF_get_free_sections(H5F_t *f, hid_t dxpl_id, H5FD_mem_t type, size_t nsects, /* Query how many sections of this type */ if(H5FS_sect_stats(f->shared->fs_man[ty], NULL, &hnums) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGET, FAIL, "can't query free space stats") - H5_ASSIGN_OVERFLOW(nums, hnums, hsize_t, size_t); + H5_CHECKED_ASSIGN(nums, size_t, hnums, hsize_t); /* Increment total # of sections */ total_sects += nums; diff --git a/src/H5O.c b/src/H5O.c index dcb1a6d..e069236 100644 --- a/src/H5O.c +++ b/src/H5O.c @@ -2726,8 +2726,8 @@ H5O_get_hdr_info_real(const H5O_t *oh, H5O_hdr_info_t *hdr) hdr->version = oh->version; /* Set the number of messages & chunks */ - H5_ASSIGN_OVERFLOW(hdr->nmesgs, oh->nmesgs, size_t, unsigned); - H5_ASSIGN_OVERFLOW(hdr->nchunks, oh->nchunks, size_t, unsigned); + H5_CHECKED_ASSIGN(hdr->nmesgs, unsigned, oh->nmesgs, size_t); + H5_CHECKED_ASSIGN(hdr->nchunks, unsigned, oh->nchunks, size_t); /* Set the status flags */ hdr->flags = oh->flags; diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 2269bd3..9710f5d 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -218,7 +218,7 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, unsigned UNUSED mesg_fl p += attr->shared->ds_size; /* Compute the size of the data */ - H5_ASSIGN_OVERFLOW(attr->shared->data_size, H5S_GET_EXTENT_NPOINTS(attr->shared->ds) * H5T_get_size(attr->shared->dt), hsize_t, size_t); + H5_CHECKED_ASSIGN(attr->shared->data_size, size_t, H5S_GET_EXTENT_NPOINTS(attr->shared->ds) * H5T_get_size(attr->shared->dt), hsize_t); /* Go get the data */ if(attr->shared->data_size) { diff --git a/src/H5Ocache.c b/src/H5Ocache.c index eef577c..03b0ac5 100644 --- a/src/H5Ocache.c +++ b/src/H5Ocache.c @@ -339,7 +339,7 @@ H5O_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata) HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "unable to determine file size") /* Compute the size of the speculative object header buffer */ - H5_ASSIGN_OVERFLOW(spec_read_size, MIN(eoa - addr, H5O_SPEC_READ_SIZE), /* From: */ hsize_t, /* To: */ size_t); + H5_CHECKED_ASSIGN(spec_read_size, size_t, MIN(eoa - addr, H5O_SPEC_READ_SIZE), hsize_t); /* Attempt to speculatively read both object header prefix and first chunk */ if(H5F_block_read(f, H5FD_MEM_OHDR, addr, spec_read_size, dxpl_id, read_buf) < 0) diff --git a/src/H5Ofill.c b/src/H5Ofill.c index a0fc42e..33022fc 100644 --- a/src/H5Ofill.c +++ b/src/H5Ofill.c @@ -977,7 +977,7 @@ H5O_fill_convert(H5O_fill_t *fill, H5T_t *dset_type, hbool_t *fill_changed, hid_ } /* end if */ H5T_close(fill->type); fill->type = NULL; - H5_ASSIGN_OVERFLOW(fill->size, H5T_get_size(dset_type), size_t, ssize_t); + H5_CHECKED_ASSIGN(fill->size, ssize_t, H5T_get_size(dset_type), size_t); /* Note that the fill value info has changed */ *fill_changed = TRUE; diff --git a/src/H5Omessage.c b/src/H5Omessage.c index 1369583..f70fa72 100644 --- a/src/H5Omessage.c +++ b/src/H5Omessage.c @@ -807,7 +807,7 @@ H5O_msg_count(const H5O_loc_t *loc, unsigned type_id, hid_t dxpl_id) /* Count the messages of the correct type */ msg_count = H5O_msg_count_real(oh, type); - H5_ASSIGN_OVERFLOW(ret_value, msg_count, unsigned, int); + H5_CHECKED_ASSIGN(ret_value, int, msg_count, unsigned); done: if(oh && H5O_unprotect(loc, dxpl_id, oh, H5AC__NO_FLAGS_SET) < 0) @@ -2300,7 +2300,7 @@ H5O_msg_get_chunkno(const H5O_loc_t *loc, unsigned type_id, hid_t dxpl_id) HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL, "message type not found") /* Set return value */ - H5_ASSIGN_OVERFLOW(ret_value, idx_msg->chunkno, unsigned, int); + H5_CHECKED_ASSIGN(ret_value, int, idx_msg->chunkno, unsigned); done: if(oh && H5O_unprotect(loc, dxpl_id, oh, H5AC__NO_FLAGS_SET) < 0) diff --git a/src/H5PL.c b/src/H5PL.c index 619dd84..f4cd3e7 100644 --- a/src/H5PL.c +++ b/src/H5PL.c @@ -237,10 +237,11 @@ done: *------------------------------------------------------------------------- */ herr_t -H5PLget_loading_state(unsigned int* plugin_type) +H5PLget_loading_state(unsigned int *plugin_type) { herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) + H5TRACE1("e", "*Iu", plugin_type); if(plugin_type) *plugin_type = H5PL_plugin_g; diff --git a/src/H5Pencdec.c b/src/H5Pencdec.c index 3285ae3..bd0a260 100644 --- a/src/H5Pencdec.c +++ b/src/H5Pencdec.c @@ -509,7 +509,7 @@ H5P__decode_size_t(const void **_pp, void *_value) /* Decode the value */ UINT64DECODE_VAR(*pp, enc_value, enc_size); - H5_ASSIGN_OVERFLOW(*value, enc_value, uint64_t, size_t); + H5_CHECKED_ASSIGN(*value, size_t, enc_value, uint64_t); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__decode_size_t() */ @@ -550,7 +550,7 @@ H5P__decode_hsize_t(const void **_pp, void *_value) /* Decode the value */ UINT64DECODE_VAR(*pp, enc_value, enc_size); - H5_ASSIGN_OVERFLOW(*value, enc_value, uint64_t, hsize_t); + H5_CHECKED_ASSIGN(*value, hsize_t, enc_value, uint64_t); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5P__decode_hsize_t() */ diff --git a/src/H5Pgcpl.c b/src/H5Pgcpl.c index b7d5106..1e3a278 100644 --- a/src/H5Pgcpl.c +++ b/src/H5Pgcpl.c @@ -179,7 +179,7 @@ H5Pset_local_heap_size_hint(hid_t plist_id, size_t size_hint) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get group info") /* Update field */ - H5_ASSIGN_OVERFLOW(ginfo.lheap_size_hint, size_hint, size_t, uint32_t); + H5_CHECKED_ASSIGN(ginfo.lheap_size_hint, uint32_t, size_hint, size_t); /* Set value */ if(H5P_set(plist, H5G_CRT_GROUP_INFO_NAME, &ginfo) < 0) diff --git a/src/H5S.c b/src/H5S.c index dd2bb0a..9b37797 100644 --- a/src/H5S.c +++ b/src/H5S.c @@ -1521,7 +1521,7 @@ H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc) /* Find out the size of buffer needed for selection */ if((sselect_size = H5S_SELECT_SERIAL_SIZE(obj)) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_BADSIZE, FAIL, "can't find dataspace selection size") - H5_ASSIGN_OVERFLOW(select_size, sselect_size, hssize_t, size_t); + H5_CHECKED_ASSIGN(select_size, size_t, sselect_size, hssize_t); /* Verify the size of buffer. If it's not big enough, simply return the * right size without filling the buffer. */ diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 9b1562f..0d5e630 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -7635,7 +7635,7 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, /* Finish the span in the fastest changing dimension */ /* Compute the number of bytes to attempt in this span */ - H5_ASSIGN_OVERFLOW(span_size,((curr_span->high-abs_arr[fast_dim])+1)*elem_size,hsize_t,size_t); + H5_CHECKED_ASSIGN(span_size, size_t, ((curr_span->high-abs_arr[fast_dim])+1)*elem_size, hsize_t); /* Check number of bytes against upper bounds allowed */ if(span_size>io_bytes_left) @@ -7778,7 +7778,7 @@ H5S_hyper_get_seq_list_gen(const H5S_t *space,H5S_sel_iter_t *iter, loc_off += curr_span->pstride; /* Compute the number of elements to attempt in this span */ - H5_ASSIGN_OVERFLOW(span_size, curr_span->nelem, hsize_t, size_t); + H5_CHECKED_ASSIGN(span_size, size_t, curr_span->nelem, hsize_t); /* Check number of elements against upper bounds allowed */ if(span_size >= io_bytes_left) { @@ -8108,7 +8108,7 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space, H5S_sel_iter_t *iter, loc += offset[u] * slab[u]; /* Set the number of elements to write each time */ - H5_ASSIGN_OVERFLOW(actual_elem, tdiminfo[fast_dim].block, hsize_t, size_t); + H5_CHECKED_ASSIGN(actual_elem, size_t, tdiminfo[fast_dim].block, hsize_t); /* Set the number of actual bytes */ actual_bytes = actual_elem * elem_size; @@ -8117,7 +8117,7 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space, H5S_sel_iter_t *iter, fast_dim_start = tdiminfo[fast_dim].start; fast_dim_stride = tdiminfo[fast_dim].stride; fast_dim_block = tdiminfo[fast_dim].block; - H5_ASSIGN_OVERFLOW(fast_dim_buf_off, slab[fast_dim] * fast_dim_stride, hsize_t, size_t); + H5_CHECKED_ASSIGN(fast_dim_buf_off, size_t, slab[fast_dim] * fast_dim_stride, hsize_t); fast_dim_offset = (hsize_t)((hssize_t)fast_dim_start + sel_off[fast_dim]); /* Compute the number of blocks which would fit into the buffer */ @@ -8138,7 +8138,7 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space, H5S_sel_iter_t *iter, /* Check if there is a partial row left (with full blocks) */ if(tmp_count[fast_dim] > 0) { /* Get number of blocks in fastest dimension */ - H5_ASSIGN_OVERFLOW(fast_dim_count, tdiminfo[fast_dim].count - tmp_count[fast_dim], hsize_t, size_t); + H5_CHECKED_ASSIGN(fast_dim_count, size_t, tdiminfo[fast_dim].count - tmp_count[fast_dim], hsize_t); /* Make certain this entire row will fit into buffer */ fast_dim_count = MIN(fast_dim_count, tot_blk_count); @@ -8223,7 +8223,7 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space, H5S_sel_iter_t *iter, curr_rows = total_rows = (size_t)(tot_blk_count / tdiminfo[fast_dim].count); /* Reset copy of number of blocks in fastest dimension */ - H5_ASSIGN_OVERFLOW(fast_dim_count, tdiminfo[fast_dim].count, hsize_t, size_t); + H5_CHECKED_ASSIGN(fast_dim_count, size_t, tdiminfo[fast_dim].count, hsize_t); /* Read in data until an entire sequence can't be written out any longer */ while(curr_rows > 0) { @@ -8528,7 +8528,7 @@ H5S_hyper_get_seq_list_single(const H5S_t *space, H5S_sel_iter_t *iter, tot_blk_count = MIN(tot_blk_count, maxseq); /* Set the number of elements to write each time */ - H5_ASSIGN_OVERFLOW(actual_elem, fast_dim_block, hsize_t, size_t); + H5_CHECKED_ASSIGN(actual_elem, size_t, fast_dim_block, hsize_t); /* Check for blocks to operate on */ if(tot_blk_count > 0) { @@ -8785,10 +8785,10 @@ H5S_hyper_get_seq_list(const H5S_t *space, unsigned UNUSED flags, H5S_sel_iter_t /* Calculate the number of elements left in the sequence */ if(tdiminfo[fast_dim].count == 1) { - H5_ASSIGN_OVERFLOW(leftover, tdiminfo[fast_dim].block - (iter->u.hyp.off[fast_dim] - tdiminfo[fast_dim].start), hsize_t, size_t); + H5_CHECKED_ASSIGN(leftover, size_t, tdiminfo[fast_dim].block - (iter->u.hyp.off[fast_dim] - tdiminfo[fast_dim].start), hsize_t); } /* end if */ else { - H5_ASSIGN_OVERFLOW(leftover, tdiminfo[fast_dim].block - ((iter->u.hyp.off[fast_dim] - tdiminfo[fast_dim].start) % tdiminfo[fast_dim].stride), hsize_t, size_t); + H5_CHECKED_ASSIGN(leftover, size_t, tdiminfo[fast_dim].block - ((iter->u.hyp.off[fast_dim] - tdiminfo[fast_dim].start) % tdiminfo[fast_dim].stride), hsize_t); } /* end else */ /* Make certain that we don't write too many */ @@ -8807,7 +8807,7 @@ H5S_hyper_get_seq_list(const H5S_t *space, unsigned UNUSED flags, H5S_sel_iter_t /* Add a new sequence */ off[0] = loc; - H5_ASSIGN_OVERFLOW(len[0], actual_elem * elem_size, hsize_t, size_t); + H5_CHECKED_ASSIGN(len[0], size_t, actual_elem * elem_size, hsize_t); /* Increment sequence array locations */ off++; diff --git a/src/H5Smpio.c b/src/H5Smpio.c index def7598..c2190b4 100644 --- a/src/H5Smpio.c +++ b/src/H5Smpio.c @@ -94,13 +94,13 @@ H5S_mpio_all_type(const H5S_t *space, size_t elmt_size, /* Just treat the entire extent as a block of bytes */ if((snelmts = (hssize_t)H5S_GET_EXTENT_NPOINTS(space)) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "src dataspace has invalid selection") - H5_ASSIGN_OVERFLOW(nelmts, snelmts, hssize_t, hsize_t); + H5_CHECKED_ASSIGN(nelmts, hsize_t, snelmts, hssize_t); total_bytes = (hsize_t)elmt_size * nelmts; /* fill in the return values */ *new_type = MPI_BYTE; - H5_ASSIGN_OVERFLOW(*count, total_bytes, hsize_t, int); + H5_CHECKED_ASSIGN(*count, int, total_bytes, hsize_t); *is_derived_type = FALSE; done: @@ -388,7 +388,7 @@ H5S_mpio_permute_type(const H5S_t *space, size_t elmt_size, hsize_t **permute, sel_iter_init = TRUE; /* Selection iteration info has been initialized */ /* Set the number of elements to iterate over */ - H5_ASSIGN_OVERFLOW(max_elem, num_points, hsize_t, size_t); + H5_CHECKED_ASSIGN(max_elem, size_t, num_points, hsize_t); /* Loop, while elements left in selection */ u = 0; diff --git a/src/H5Sselect.c b/src/H5Sselect.c index a4f13d7..e04ae16 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -1304,7 +1304,7 @@ H5S_select_iterate(void *buf, hid_t type_id, const H5S_t *space, H5D_operator_t space_size[ndims] = elmt_size; /* Compute the maximum number of bytes required */ - H5_ASSIGN_OVERFLOW(max_elem, nelmts, hssize_t, size_t); + H5_CHECKED_ASSIGN(max_elem, size_t, nelmts, hssize_t); /* Loop, while elements left in selection */ while(max_elem > 0 && user_ret == 0) { @@ -2063,7 +2063,7 @@ H5S_select_fill(const void *fill, size_t fill_size, const H5S_t *space, void *_b HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOUNT, FAIL, "can't get number of elements selected") /* Compute the number of bytes to process */ - H5_ASSIGN_OVERFLOW(max_elem, nelmts, hssize_t, size_t); + H5_CHECKED_ASSIGN(max_elem, size_t, nelmts, hssize_t); /* Loop, while elements left in selection */ while(max_elem > 0) { diff --git a/src/H5Tarray.c b/src/H5Tarray.c index c73b934..2e9dec0 100644 --- a/src/H5Tarray.c +++ b/src/H5Tarray.c @@ -202,7 +202,7 @@ H5T__array_create(H5T_t *base, unsigned ndims, const hsize_t dim[/* ndims */]) /* Copy the array dimensions & compute the # of elements in the array */ for(u = 0, ret_value->shared->u.array.nelem = 1; u < ndims; u++) { - H5_ASSIGN_OVERFLOW(ret_value->shared->u.array.dim[u], dim[u], hsize_t, size_t); + H5_CHECKED_ASSIGN(ret_value->shared->u.array.dim[u], size_t, dim[u], hsize_t); ret_value->shared->u.array.nelem *= (size_t)dim[u]; } /* end for */ diff --git a/src/H5Tconv.c b/src/H5Tconv.c index df85553..1c51b69 100644 --- a/src/H5Tconv.c +++ b/src/H5Tconv.c @@ -1952,7 +1952,7 @@ H5T_conv_struct_init(H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata, hid_t dxpl_id) src2dst[i] = -1; for(j = 0; j < dst_nmembs; j++) { if(!HDstrcmp(src->shared->u.compnd.memb[i].name, dst->shared->u.compnd.memb[j].name)) { - H5_ASSIGN_OVERFLOW(src2dst[i],j,unsigned,int); + H5_CHECKED_ASSIGN(src2dst[i], int, j, unsigned); break; } /* end if */ } /* end for */ @@ -2187,16 +2187,16 @@ H5T__conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, * Direction of conversion and striding through background. */ if(buf_stride) { - H5_ASSIGN_OVERFLOW(src_delta, buf_stride, size_t, ssize_t); + H5_CHECKED_ASSIGN(src_delta, ssize_t, buf_stride, size_t); if(!bkg_stride) { - H5_ASSIGN_OVERFLOW(bkg_delta, dst->shared->size, size_t, ssize_t); + H5_CHECKED_ASSIGN(bkg_delta, ssize_t, dst->shared->size, size_t); } /* end if */ else - H5_ASSIGN_OVERFLOW(bkg_delta, bkg_stride, size_t, ssize_t); + H5_CHECKED_ASSIGN(bkg_delta, ssize_t, bkg_stride, size_t); } /* end if */ else if(dst->shared->size <= src->shared->size) { - H5_ASSIGN_OVERFLOW(src_delta, src->shared->size, size_t, ssize_t); - H5_ASSIGN_OVERFLOW(bkg_delta, dst->shared->size, size_t, ssize_t); + H5_CHECKED_ASSIGN(src_delta, ssize_t, src->shared->size, size_t); + H5_CHECKED_ASSIGN(bkg_delta, ssize_t, dst->shared->size, size_t); } /* end else-if */ else { H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t); @@ -2278,7 +2278,7 @@ H5T__conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, /* If the bkg_delta was set to -(dst->shared->size), make it positive now */ if(buf_stride == 0 && dst->shared->size > src->shared->size) - H5_ASSIGN_OVERFLOW(bkg_delta, dst->shared->size, size_t, ssize_t); + H5_CHECKED_ASSIGN(bkg_delta, ssize_t, dst->shared->size, size_t); /* * Copy the background buffer back into the in-place conversion @@ -2833,8 +2833,8 @@ H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts, src_delta = dst_delta = (ssize_t)buf_stride; s = d = buf; } else if(dst->shared->size <= src->shared->size) { - H5_ASSIGN_OVERFLOW(src_delta, src->shared->size, size_t, ssize_t); - H5_ASSIGN_OVERFLOW(dst_delta, dst->shared->size, size_t, ssize_t); + H5_CHECKED_ASSIGN(src_delta, ssize_t, src->shared->size, size_t); + H5_CHECKED_ASSIGN(dst_delta, ssize_t, dst->shared->size, size_t); s = d = buf; } else { H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t); diff --git a/src/H5Tfloat.c b/src/H5Tfloat.c index 7d08d62..fff413d 100644 --- a/src/H5Tfloat.c +++ b/src/H5Tfloat.c @@ -203,7 +203,7 @@ H5Tget_ebias(hid_t type_id) HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, 0, "operation not defined for datatype class") /* bias */ - H5_ASSIGN_OVERFLOW(ret_value, dt->shared->u.atomic.u.f.ebias, uint64_t, size_t); + H5_CHECKED_ASSIGN(ret_value, size_t, dt->shared->u.atomic.u.f.ebias, uint64_t); done: FUNC_LEAVE_API(ret_value) diff --git a/src/H5Tnative.c b/src/H5Tnative.c index 960a811..bf6ba08 100644 --- a/src/H5Tnative.c +++ b/src/H5Tnative.c @@ -276,7 +276,7 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig if((snmemb = H5T_get_nmembers(dtype)) <= 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "compound data type doesn't have any member") - H5_ASSIGN_OVERFLOW(nmemb, snmemb, int, unsigned); + H5_CHECKED_ASSIGN(nmemb, unsigned, snmemb, int); if(NULL == (memb_list = (H5T_t **)H5MM_calloc(nmemb * sizeof(H5T_t *)))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot allocate memory") @@ -388,7 +388,7 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig /* Retrieve member info and insert members into new enum type */ if((snmemb = H5T_get_nmembers(dtype)) <= 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "enumerate data type doesn't have any member") - H5_ASSIGN_OVERFLOW(nmemb, snmemb, int, unsigned); + H5_CHECKED_ASSIGN(nmemb, unsigned, snmemb, int); for(u = 0; u < nmemb; u++) { if(NULL == (memb_name = H5T__get_member_name(dtype, u))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get member name") @@ -429,7 +429,7 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig /* Retrieve dimension information for array data type */ if((sarray_rank = H5T__get_array_ndims(dtype)) <= 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot get dimension rank") - H5_ASSIGN_OVERFLOW(array_rank, sarray_rank, int, unsigned); + H5_CHECKED_ASSIGN(array_rank, unsigned, sarray_rank, int); if(NULL == (dims = (hsize_t*)H5MM_malloc(array_rank * sizeof(hsize_t)))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot allocate memory") if(H5T__get_array_dims(dtype, dims) < 0) diff --git a/src/H5VM.c b/src/H5VM.c index 10ea511..43963cd 100644 --- a/src/H5VM.c +++ b/src/H5VM.c @@ -386,55 +386,6 @@ done: /*------------------------------------------------------------------------- - * Function: H5VM_hyper_disjointp - * - * Purpose: Determines if two hyperslabs are disjoint. - * - * Return: Success: FALSE if they are not disjoint. - * TRUE if they are disjoint. - * - * Failure: A hyperslab of zero size is disjoint from all - * other hyperslabs. - * - * Programmer: Robb Matzke - * Thursday, October 16, 1997 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -htri_t -H5VM_hyper_disjointp(unsigned n, - const hsize_t *offset1, const uint32_t *size1, - const hsize_t *offset2, const uint32_t *size2) -{ - unsigned u; - htri_t ret_value = FALSE; /* Return value */ - - /* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */ - FUNC_ENTER_NOAPI_NOINIT_NOERR - - if(!n || !size1 || !size2) - HGOTO_DONE(TRUE) - - for(u = 0; u < n; u++) { - HDcompile_assert(sizeof(uint32_t) <= sizeof(hsize_t)); - - if(0 == size1[u] || 0 == size2[u]) - HGOTO_DONE(TRUE) - if(((offset1 ? offset1[u] : 0) < (offset2 ? offset2[u] : 0) && - ((offset1 ? offset1[u] : 0) + size1[u] <= (offset2 ? offset2[u] : 0))) || - ((offset2 ? offset2[u] : 0) < (offset1 ? offset1[u] : 0) && - ((offset2 ? offset2[u] : 0) + size2[u] <= (offset1 ? offset1[u] : 0)))) - HGOTO_DONE(TRUE) - } /* end for */ - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VM_hyper_disjointp() */ - - -/*------------------------------------------------------------------------- * Function: H5VM_hyper_fill * * Purpose: Similar to memset() except it operates on hyperslabs... @@ -1068,17 +1019,12 @@ H5VM_array_down(unsigned n, const hsize_t *total_size, hsize_t *down) * Programmer: Quincey Koziol * Tuesday, June 22, 1999 * - * Modifications: - * Use precomputed accumulator array - * Quincey Koziol - * Saturday, April 26, 2003 - * *------------------------------------------------------------------------- */ hsize_t H5VM_array_offset_pre(unsigned n, const hsize_t *acc, const hsize_t *offset) { - int i; /*counter */ + unsigned u; /* Local index variable */ hsize_t ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -1088,8 +1034,8 @@ H5VM_array_offset_pre(unsigned n, const hsize_t *acc, const hsize_t *offset) HDassert(offset); /* Compute offset in array */ - for(i = (int)(n - 1), ret_value = 0; i >= 0; --i) - ret_value += acc[i] * offset[i]; + for(u = 0, ret_value = 0; u < n; u++) + ret_value += acc[u] * offset[u]; FUNC_LEAVE_NOAPI(ret_value) } /* end H5VM_array_offset_pre() */ diff --git a/src/H5VMprivate.h b/src/H5VMprivate.h index 7f654e1..5ed4e3d 100644 --- a/src/H5VMprivate.h +++ b/src/H5VMprivate.h @@ -89,8 +89,6 @@ H5_DLL hsize_t H5VM_hyper_stride(unsigned n, const hsize_t *size, const hsize_t *total_size, const hsize_t *offset, hsize_t *stride); -H5_DLL htri_t H5VM_hyper_disjointp(unsigned n, const hsize_t *offset1, - const uint32_t *size1, const hsize_t *offset2, const uint32_t *size2); H5_DLL htri_t H5VM_hyper_eq(unsigned n, const hsize_t *offset1, const hsize_t *size1, const hsize_t *offset2, const hsize_t *size2); diff --git a/src/H5Zdeflate.c b/src/H5Zdeflate.c index 82ad1ba..06d9866 100644 --- a/src/H5Zdeflate.c +++ b/src/H5Zdeflate.c @@ -102,9 +102,9 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, /* Set the uncompression parameters */ HDmemset(&z_strm, 0, sizeof(z_strm)); z_strm.next_in = (Bytef *)*buf; - H5_ASSIGN_OVERFLOW(z_strm.avail_in,nbytes,size_t,unsigned); + H5_CHECKED_ASSIGN(z_strm.avail_in, unsigned, nbytes, size_t); z_strm.next_out = (Bytef *)outbuf; - H5_ASSIGN_OVERFLOW(z_strm.avail_out,nalloc,size_t,unsigned); + H5_CHECKED_ASSIGN(z_strm.avail_out, unsigned, nalloc, size_t); /* Initialize the uncompression routines */ if (Z_OK!=inflateInit(&z_strm)) @@ -169,7 +169,7 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, int aggression; /* Compression aggression setting */ /* Set the compression aggression level */ - H5_ASSIGN_OVERFLOW(aggression,cd_values[0],unsigned,int); + H5_CHECKED_ASSIGN(aggression, int, cd_values[0], unsigned); /* Allocate output (compressed) buffer */ if(NULL == (outbuf = H5MM_malloc(z_dst_nbytes))) diff --git a/src/H5Znbit.c b/src/H5Znbit.c index 9506ace..ff3ead2 100644 --- a/src/H5Znbit.c +++ b/src/H5Znbit.c @@ -803,7 +803,7 @@ H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id) cd_values_index = 2; /* Set "local" parameter for number of elements in the chunk */ - H5_ASSIGN_OVERFLOW(cd_values[cd_values_index++], npoints, hssize_t, unsigned); + H5_CHECKED_ASSIGN(cd_values[cd_values_index++], unsigned, npoints, hssize_t); /* Assume no need to compress now, will be changed to FALSE later if not */ need_not_compress = TRUE; diff --git a/src/H5Zscaleoffset.c b/src/H5Zscaleoffset.c index 38e2986..cda0a11 100644 --- a/src/H5Zscaleoffset.c +++ b/src/H5Zscaleoffset.c @@ -901,7 +901,7 @@ H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id) HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "unable to get number of points in the dataspace") /* Set "local" parameter for this dataset's number of elements */ - H5_ASSIGN_OVERFLOW(cd_values[H5Z_SCALEOFFSET_PARM_NELMTS],npoints,hssize_t,unsigned); + H5_CHECKED_ASSIGN(cd_values[H5Z_SCALEOFFSET_PARM_NELMTS], unsigned, npoints, hssize_t); /* Get datatype's class */ if((dtype_class = H5T_get_class(type, TRUE)) == H5T_NO_CLASS) diff --git a/src/H5Zszip.c b/src/H5Zszip.c index 4544ec3..631667b 100644 --- a/src/H5Zszip.c +++ b/src/H5Zszip.c @@ -225,7 +225,7 @@ H5Z_set_local_szip(hid_t dcpl_id, hid_t type_id, hid_t space_id) } /* end else */ /* Assign the final value to the scanline */ - H5_ASSIGN_OVERFLOW(cd_values[H5Z_SZIP_PARM_PPS],scanline,hsize_t,unsigned); + H5_CHECKED_ASSIGN(cd_values[H5Z_SZIP_PARM_PPS], unsigned, scanline, hsize_t); /* Get datatype's endianness order */ if((dtype_order = H5T_get_order(type)) == H5T_ORDER_ERROR) @@ -301,10 +301,10 @@ H5Z_filter_szip (unsigned flags, size_t cd_nelmts, const unsigned cd_values[], HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid deflate aggression level") /* Copy the filter parameters into the szip parameter block */ - H5_ASSIGN_OVERFLOW(sz_param.options_mask,cd_values[H5Z_SZIP_PARM_MASK],unsigned,int); - H5_ASSIGN_OVERFLOW(sz_param.bits_per_pixel,cd_values[H5Z_SZIP_PARM_BPP],unsigned,int); - H5_ASSIGN_OVERFLOW(sz_param.pixels_per_block,cd_values[H5Z_SZIP_PARM_PPB],unsigned,int); - H5_ASSIGN_OVERFLOW(sz_param.pixels_per_scanline,cd_values[H5Z_SZIP_PARM_PPS],unsigned,int); + H5_CHECKED_ASSIGN(sz_param.options_mask, int, cd_values[H5Z_SZIP_PARM_MASK], unsigned); + H5_CHECKED_ASSIGN(sz_param.bits_per_pixel, int, cd_values[H5Z_SZIP_PARM_BPP], unsigned); + H5_CHECKED_ASSIGN(sz_param.pixels_per_block, int, cd_values[H5Z_SZIP_PARM_PPB], unsigned); + H5_CHECKED_ASSIGN(sz_param.pixels_per_scanline, int, cd_values[H5Z_SZIP_PARM_PPS], unsigned); /* Input; uncompress */ if (flags & H5Z_FLAG_REVERSE) { @@ -314,7 +314,7 @@ H5Z_filter_szip (unsigned flags, size_t cd_nelmts, const unsigned cd_values[], /* Get the size of the uncompressed buffer */ newbuf = *buf; UINT32DECODE(newbuf,stored_nalloc); - H5_ASSIGN_OVERFLOW(nalloc,stored_nalloc,uint32_t,size_t); + H5_CHECKED_ASSIGN(nalloc, size_t, stored_nalloc, uint32_t); /* Allocate space for the uncompressed buffer */ if(NULL==(outbuf = H5MM_malloc(nalloc))) diff --git a/src/H5detect.c b/src/H5detect.c index fc0570c..15736bd 100644 --- a/src/H5detect.c +++ b/src/H5detect.c @@ -73,7 +73,7 @@ static const char *FileHeader = "\n\ #define H5JMP_BUF sigjmp_buf #define H5SETJMP(buf) HDsigsetjmp(buf, 1) #define H5LONGJMP(buf, val) HDsiglongjmp(buf, val) -#define H5HAVE_SIGJMP # sigsetjmp/siglongjmp are supported. +#define H5HAVE_SIGJMP /* sigsetjmp/siglongjmp are supported. */ #elif defined(H5_HAVE_LONGJMP) #define H5JMP_BUF jmp_buf #define H5SETJMP(buf) HDsetjmp(buf) @@ -90,41 +90,41 @@ static const char *FileHeader = "\n\ * was detected. */ typedef struct detected_t { - const char *varname; - int size; /*total byte size */ - int precision; /*meaningful bits */ - int offset; /*bit offset to meaningful bits */ - int perm[32]; /*for detection of byte order */ - int is_vax; /*for vax (float & double) only */ - int sign; /*location of sign bit */ - int mpos, msize, imp;/*information about mantissa */ - int epos, esize; /*information about exponent */ - unsigned long bias; /*exponent bias for floating pt.*/ - size_t align; /*required byte alignment */ - size_t comp_align; /*alignment for structure */ + const char *varname; + unsigned int size; /* total byte size */ + unsigned int precision; /* meaningful bits */ + unsigned int offset; /* bit offset to meaningful bits */ + int perm[32]; /* for detection of byte order */ + hbool_t is_vax; /* for vax (float & double) only */ + unsigned int sign; /* location of sign bit */ + unsigned int mpos, msize, imp; /* information about mantissa */ + unsigned int epos, esize; /* information about exponent */ + unsigned long bias; /* exponent bias for floating pt */ + unsigned int align; /* required byte alignment */ + unsigned int comp_align; /* alignment for structure */ } detected_t; /* This structure holds structure alignment for pointers, hvl_t, hobj_ref_t, * hdset_reg_ref_t */ typedef struct malign_t { const char *name; - size_t comp_align; /*alignment for structure */ + unsigned int comp_align; /* alignment for structure */ } malign_t; /* global variables types detection code */ -static detected_t d_g[MAXDETECT]; -static malign_t m_g[MAXDETECT]; -static volatile int nd_g = 0, na_g = 0; +H5_GCC_DIAG_OFF(larger-than=) +static detected_t d_g[MAXDETECT]; +H5_GCC_DIAG_ON(larger-than=) +static malign_t m_g[MAXDETECT]; +static volatile int nd_g = 0, na_g = 0; static void print_results(int nd, detected_t *d, int na, malign_t *m); static void iprint(detected_t *); static int byte_cmp(int, const void *, const void *, const unsigned char *); -static int bit_cmp(int, int *, volatile void *, volatile void *, - const unsigned char *); +static unsigned int bit_cmp(unsigned int, int *, void *, void *, const unsigned char *); static void fix_order(int, int, int *, const char **); -static int imp_bit(int, int *, volatile void *, volatile void *, - const unsigned char *); -static unsigned long find_bias(int, int, int *, volatile void *); +static unsigned int imp_bit(unsigned int, int *, void *, void *, const unsigned char *); +static unsigned int find_bias(unsigned int, unsigned int, int *, void *); static void precision (detected_t*); static void print_header(void); static void detect_C89_integers(void); @@ -136,7 +136,7 @@ static void detect_C99_integers16(void); static void detect_C99_integers32(void); static void detect_C99_integers64(void); static void detect_alignments(void); -static size_t align_g[] = {1, 2, 4, 8, 16}; +static unsigned int align_g[] = {1, 2, 4, 8, 16}; static int align_status_g = 0; /* ALIGNMENT Signal Status */ static int sigbus_handler_called_g = 0; /* how many times called */ static int sigsegv_handler_called_g = 0;/* how many times called */ @@ -167,39 +167,41 @@ static H5JMP_BUF jbuf_g; static void precision (detected_t *d) { - int n; + unsigned int n; - if (0==d->msize) { - /* - * An integer. The permutation can have negative values at the - * beginning or end which represent padding of bytes. We must adjust - * the precision and offset accordingly. - */ - if (d->perm[0] < 0) { - /* - * Lower addresses are padded. - */ - for (n=0; nsize && d->perm[n]<0; n++) /*void*/; - d->precision = 8*(d->size-n); - d->offset = 0; - } else if (d->perm[d->size - 1] < 0) { - /* - * Higher addresses are padded. - */ - for (n=0; nsize && d->perm[d->size-(n+1)]; n++) /*void*/; - d->precision = 8*(d->size-n); - d->offset = 8*n; - } else { - /* - * No padding. - */ - d->precision = 8*d->size; - d->offset = 0; - } + if (0 == d->msize) { + /* + * An integer. The permutation can have negative values at the + * beginning or end which represent padding of bytes. We must adjust + * the precision and offset accordingly. + */ + if (d->perm[0] < 0) { + /* + * Lower addresses are padded. + */ + for (n = 0; n < d->size && d->perm[n] < 0; n++) + /*void*/; + d->precision = 8 * (d->size - n); + d->offset = 0; + } else if (d->perm[d->size - 1] < 0) { + /* + * Higher addresses are padded. + */ + for (n = 0; n < d->size && d->perm[d->size - (n + 1)]; n++) + /*void*/; + d->precision = 8 * (d->size - n); + d->offset = 8 * n; + } else { + /* + * No padding. + */ + d->precision = 8 * d->size; + d->offset = 0; + } } else { - /* A floating point */ - d->offset = MIN3 (d->mpos, d->epos, d->sign); - d->precision = d->msize + d->esize + 1; + /* A floating point */ + d->offset = MIN3(d->mpos, d->epos, d->sign); + d->precision = d->msize + d->esize + 1; } } @@ -251,7 +253,8 @@ precision (detected_t *d) INFO.size = sizeof(TYPE); \ \ for(_i = sizeof(DETECT_TYPE), _v = 0; _i > 0; --_i) \ - _v = (_v << 8) + _i; \ + _v = (DETECT_TYPE) ((DETECT_TYPE) (_v << 8) + (DETECT_TYPE) _i); \ + \ for(_i = 0, _x = (unsigned char *)&_v; _i < (signed)sizeof(DETECT_TYPE); _i++) { \ _j = (*_x++) - 1; \ HDassert(_j < (signed)sizeof(DETECT_TYPE)); \ @@ -290,9 +293,6 @@ precision (detected_t *d) * absence of implicit mantissa bit, and exponent bias and * initializes a detected_t structure with those properties. * - * Note: 'volatile' is used for the variables below to prevent the - * compiler from optimizing them away. - * * Return: void * * Programmer: Robb Matzke @@ -302,12 +302,12 @@ precision (detected_t *d) *------------------------------------------------------------------------- */ #define DETECT_F(TYPE,VAR,INFO) { \ - volatile TYPE _v1, _v2, _v3; \ + TYPE _v1, _v2, _v3; \ unsigned char _buf1[sizeof(TYPE)], _buf3[sizeof(TYPE)]; \ unsigned char _pad_mask[sizeof(TYPE)]; \ unsigned char _byte_mask; \ int _i, _j, _last = (-1); \ - char *_mesg; \ + const char *_mesg; \ \ HDmemset(&INFO, 0, sizeof(INFO)); \ INFO.varname = #VAR; \ @@ -326,11 +326,13 @@ precision (detected_t *d) _v1 = (TYPE)4.0L; \ HDmemcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \ for(_i = 0; _i < (int)sizeof(TYPE); _i++) \ - for(_byte_mask = (unsigned char)1; _byte_mask; _byte_mask <<= 1) { \ + for(_byte_mask = (unsigned char)1; _byte_mask; _byte_mask = (unsigned char) (_byte_mask << 1)) { \ _buf1[_i] ^= _byte_mask; \ HDmemcpy((void *)&_v2, (const void *)_buf1, sizeof(TYPE)); \ + H5_GCC_DIAG_OFF(float-equal) \ if(_v1 != _v2) \ _pad_mask[_i] |= _byte_mask; \ + H5_GCC_DIAG_ON(float-equal) \ _buf1[_i] ^= _byte_mask; \ } /* end for */ \ \ @@ -368,7 +370,7 @@ precision (detected_t *d) _v1 = (TYPE)1.0L; \ _v2 = (TYPE)1.5L; \ INFO.msize = bit_cmp (sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ - INFO.msize += 1 + (INFO.imp?0:1) - INFO.mpos; \ + INFO.msize += 1 + (unsigned int) (INFO.imp ? 0 : 1) - INFO.mpos; \ \ /* Exponent */ \ INFO.epos = INFO.mpos + INFO.msize; \ @@ -415,14 +417,13 @@ precision (detected_t *d) TYPE x; \ } s; \ \ - COMP_ALIGN = (size_t)((char*)(&(s.x)) - (char*)(&s)); \ + COMP_ALIGN = (unsigned int)((char*)(&(s.x)) - (char*)(&s)); \ } #if defined(H5SETJMP) && defined(H5_HAVE_SIGNAL) #define ALIGNMENT(TYPE,INFO) { \ - char *volatile _buf = NULL; \ - volatile TYPE _val = 1; \ - volatile TYPE _val2; \ + char *volatile _buf = NULL; \ + TYPE _val = 1, _val2; \ volatile size_t _ano = 0; \ void (*_handler)(int) = HDsignal(SIGBUS, sigbus_handler); \ void (*_handler2)(int) = HDsignal(SIGSEGV, sigsegv_handler);\ @@ -445,8 +446,10 @@ precision (detected_t *d) else /* Little-Endian */ \ HDmemcpy(_buf+align_g[_ano]+(INFO.offset/8),((char *)&_val)+(INFO.offset/8),(size_t)(INFO.precision/8)); \ _val2 = *((TYPE*)(_buf+align_g[_ano])); \ + H5_GCC_DIAG_OFF(float-equal) \ if(_val!=_val2) \ H5LONGJMP(jbuf_g, 1); \ + H5_GCC_DIAG_ON(float-equal) \ /* End Cray Check */ \ (INFO.align)=align_g[_ano]; \ } else { \ @@ -881,63 +884,69 @@ done:\n\ static void iprint(detected_t *d) { - int i, j, k, pass; + unsigned int pass; - for (pass=(d->size-1)/4; pass>=0; --pass) { - /* - * Print the byte ordering above the bit fields. - */ - printf(" * "); - for (i=MIN(pass*4+3,d->size-1); i>=pass*4; --i) { - printf ("%4d", d->perm[i]); - if (i>pass*4) HDfputs (" ", stdout); - } + for (pass = (d->size - 1) / 4; ; --pass) { + unsigned int i, k; + /* + * Print the byte ordering above the bit fields. + */ + printf(" * "); + for (i = MIN(pass * 4 + 3, d->size - 1); i >= pass * 4; --i) { + printf("%4d", d->perm[i]); + if (i > pass * 4) HDfputs(" ", stdout); + if (!i) break; + } - /* - * Print the bit fields - */ - printf("\n * "); - for (i=MIN(pass*4+3,d->size-1), - k=MIN(pass*32+31,8*d->size-1); - i>=pass*4; --i) { - for (j=7; j>=0; --j) { - if (k==d->sign && d->msize) { - HDputchar('S'); - } else if (k>=d->epos && kepos+d->esize) { - HDputchar('E'); - } else if (k>=d->mpos && kmpos+d->msize) { - HDputchar('M'); - } else if (d->msize) { - HDputchar('?'); /*unknown floating point bit */ - } else if (d->sign) { - HDputchar('I'); - } else { - HDputchar('U'); - } - --k; - } - if (i>pass*4) HDputchar(' '); - } - HDputchar('\n'); + /* + * Print the bit fields + */ + printf("\n * "); + for (i = MIN(pass * 4 + 3, d->size - 1), k = MIN(pass * 32 + 31, + 8 * d->size - 1); i >= pass * 4; --i) { + unsigned int j; + + for (j = 8; j > 0; --j) { + if (k == d->sign && d->msize) { + HDputchar('S'); + } else if (k >= d->epos && k < d->epos + d->esize) { + HDputchar('E'); + } else if (k >= d->mpos && k < d->mpos + d->msize) { + HDputchar('M'); + } else if (d->msize) { + HDputchar('?'); /*unknown floating point bit */ + } else if (d->sign) { + HDputchar('I'); + } else { + HDputchar('U'); + } + --k; + } + if (i > pass * 4) HDputchar(' '); + if (!i) break; + } + HDputchar('\n'); + if (!pass) break; } /* * Is there an implicit bit in the mantissa. */ if (d->msize) { - printf(" * Implicit bit? %s\n", d->imp ? "yes" : "no"); + printf(" * Implicit bit? %s\n", d->imp ? "yes" : "no"); } /* * Alignment */ - if (0==d->align) { - printf(" * Alignment: NOT CALCULATED\n"); - } else if (1==d->align) { - printf(" * Alignment: none\n"); + if (0 == d->align) { + printf(" * Alignment: NOT CALCULATED\n"); + } else if (1 == d->align) { + printf(" * Alignment: none\n"); } else { - printf(" * Alignment: %lu\n", (unsigned long)(d->align)); + printf(" * Alignment: %lu\n", (unsigned long) (d->align)); } + } @@ -985,31 +994,25 @@ byte_cmp(int n, const void *_a, const void *_b, const unsigned char *pad_mask) * actual order to little endian. Ignores differences where * the corresponding bit in pad_mask is set to 0. * - * Return: Success: Index of first differing bit. - * - * Failure: -1 - * - * Programmer: Robb Matzke - * matzke@llnl.gov - * Jun 13, 1996 - * - * Modifications: + * Return: Index of first differing bit. * *------------------------------------------------------------------------- */ -static int -bit_cmp(int nbytes, int *perm, volatile void *_a, volatile void *_b, - const unsigned char *pad_mask) +static unsigned int +bit_cmp(unsigned int nbytes, int *perm, void *_a, void *_b, + const unsigned char *pad_mask) { - int i, j; - volatile unsigned char *a = (volatile unsigned char *) _a; - volatile unsigned char *b = (volatile unsigned char *) _b; - unsigned char aa, bb; + unsigned int i; + unsigned char *a = (unsigned char *) _a; + unsigned char *b = (unsigned char *) _b; + unsigned char aa, bb; for (i = 0; i < nbytes; i++) { - HDassert(perm[i] < nbytes); - if ((aa = a[perm[i]] & pad_mask[perm[i]]) - != (bb = b[perm[i]] & pad_mask[perm[i]])) { + HDassert(perm[i] < (int) nbytes); + if ((aa = (unsigned char) (a[perm[i]] & pad_mask[perm[i]])) + != (bb = (unsigned char) (b[perm[i]] & pad_mask[perm[i]]))) { + unsigned int j; + for (j = 0; j < 8; j++, aa >>= 1, bb >>= 1) { if ((aa & 1) != (bb & 1)) return i * 8 + j; } @@ -1017,7 +1020,9 @@ bit_cmp(int nbytes, int *perm, volatile void *_a, volatile void *_b, HDabort(); } } - return -1; + fprintf(stderr, "INTERNAL ERROR"); + HDabort(); + return 0; } @@ -1123,21 +1128,19 @@ fix_order(int n, int last, int *perm, const char **mesg) * *------------------------------------------------------------------------- */ -static int -imp_bit(int n, int *perm, volatile void *_a, volatile void *_b, - const unsigned char *pad_mask) +static unsigned int +imp_bit(unsigned int n, int *perm, void *_a, void *_b, const unsigned char *pad_mask) { - volatile unsigned char *a = (volatile unsigned char *) _a; - volatile unsigned char *b = (volatile unsigned char *) _b; - int changed, major, minor; - int msmb; /*most significant mantissa bit */ + unsigned char *a = (unsigned char *) _a; + unsigned char *b = (unsigned char *) _b; + unsigned int changed, major, minor; + unsigned int msmb; /* most significant mantissa bit */ /* * Look for the least significant bit that has changed between * A and B. This is the least significant bit of the exponent. */ changed = bit_cmp(n, perm, a, b, pad_mask); - HDassert(changed >= 0); /* * The bit to the right (less significant) of the changed bit should @@ -1174,22 +1177,22 @@ imp_bit(int n, int *perm, volatile void *_a, volatile void *_b, * *------------------------------------------------------------------------- */ -static unsigned long -find_bias(int epos, int esize, int *perm, volatile void *_a) +static unsigned int +find_bias(unsigned int epos, unsigned int esize, int *perm, void *_a) { - unsigned char *a = (unsigned char *) _a; - unsigned char mask; - unsigned long b, shift = 0, nbits, bias = 0; + unsigned char *a = (unsigned char *) _a; + unsigned char mask; + unsigned int b, shift = 0, nbits, bias = 0; while (esize > 0) { - nbits = MIN(esize, (8 - epos % 8)); - mask = (1 << nbits) - 1; - b = (a[perm[epos / 8]] >> (epos % 8)) & mask; - bias |= b << shift; - - shift += nbits; - esize -= nbits; - epos += nbits; + nbits = MIN(esize, (8 - epos % 8)); + mask = (unsigned char) ((1 << nbits) - 1); + b = (unsigned int) (a[perm[epos / 8]] >> (epos % 8)) & mask; + bias |= b << shift; + + shift += nbits; + esize -= nbits; + epos += nbits; } return bias; } @@ -1667,7 +1670,7 @@ detect_alignments(void) static int verify_signal_handlers(int signum, void (*handler)(int)) { void (*save_handler)(int) = HDsignal(signum, handler); - int i, val; + volatile int i, val; int ntries=5; volatile int nfailures=0; volatile int nsuccesses=0; diff --git a/src/H5private.h b/src/H5private.h index f4dbe53..2fee118 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1526,11 +1526,14 @@ extern char *strdup(const char *s); /* Include the generated overflow header file */ #include "H5overflow.h" -#define H5_ASSIGN_OVERFLOW(dst, src, srctype, dsttype) \ +/* Assign a variable to one of a different size (think safer dst = (dsttype)src"). + * The code generated by the macro checks for overflows. + */ +#define H5_CHECKED_ASSIGN(dst, dsttype, src, srctype) \ H5_GLUE4(ASSIGN_,srctype,_TO_,dsttype)(dst,dsttype,src,srctype)\ #else /* NDEBUG */ -#define H5_ASSIGN_OVERFLOW(dst, src, srctype, dsttype) \ +#define H5_CHECKED_ASSIGN(dst, dsttype, src, srctype) \ (dst) = (dsttype)(src); #endif /* NDEBUG */ diff --git a/tools/misc/h5debug.c b/tools/misc/h5debug.c index a320054..01ad24e 100644 --- a/tools/misc/h5debug.c +++ b/tools/misc/h5debug.c @@ -353,6 +353,7 @@ main(int argc, char *argv[]) */ H5B_subid_t subtype = (H5B_subid_t)sig[H5_SIZEOF_MAGIC]; unsigned ndims; + uint32_t dim[H5O_LAYOUT_NDIMS]; switch(subtype) { case H5B_SNODE_ID: @@ -361,6 +362,7 @@ main(int argc, char *argv[]) HDfprintf(stderr, "\nWarning: Providing the group's local heap address will give more information\n"); HDfprintf(stderr, "B-tree symbol table node usage:\n"); HDfprintf(stderr, "\th5debug
\n\n"); + HDexit(4); } /* end if */ status = H5G_node_debug(f, H5P_DATASET_XFER_DEFAULT, addr, stdout, 0, VCOL, extra); @@ -371,12 +373,37 @@ main(int argc, char *argv[]) if(extra == 0) { HDfprintf(stderr, "ERROR: Need number of dimensions of chunk in order to dump chunk B-tree node\n"); HDfprintf(stderr, "B-tree chunked storage node usage:\n"); - HDfprintf(stderr, "\th5debug <# of dimensions>\n"); + HDfprintf(stderr, "\th5debug <# of dimensions> ...\n"); HDexit(4); } /* end if */ + /* Build array of chunk dimensions */ ndims = (unsigned)extra; - status = H5D_btree_debug(f, H5P_DATASET_XFER_DEFAULT, addr, stdout, 0, VCOL, ndims); + dim[0] = extra2; + if(ndims > 1) + dim[1] = extra3; + if(ndims > 2) + dim[2] = extra4; + + /* Check for dimension error */ + if(ndims > 3) { + HDfprintf(stderr, "ERROR: Only 3 dimensions support currently (fix h5debug)\n"); + HDfprintf(stderr, "B-tree chunked storage node usage:\n"); + HDfprintf(stderr, "\th5debug <# of dimensions> ...\n"); + HDexit(4); + } /* end for */ + for(u = 0; u < ndims; u++) + if(0 == dim[u]) { + HDfprintf(stderr, "ERROR: Chunk dimensions should be >0\n"); + HDfprintf(stderr, "B-tree chunked storage node usage:\n"); + HDfprintf(stderr, "\th5debug <# of dimensions> ...\n"); + HDexit(4); + } /* end if */ + + /* Set the last dimension (the element size) to zero */ + dim[ndims] = 0; + + status = H5D_btree_debug(f, H5P_DATASET_XFER_DEFAULT, addr, stdout, 0, VCOL, ndims, dim); break; default: @@ -539,7 +566,7 @@ main(int argc, char *argv[]) const H5EA_class_t *cls = get_H5EA_class(sig); HDassert(cls); - /* Check for enough valid parameters */ + /* Check for enough valid parameters */ if(extra == 0) { HDfprintf(stderr, "ERROR: Need object header address containing the layout message in order to dump header\n"); HDfprintf(stderr, "Extensible array header block usage:\n"); @@ -607,11 +634,11 @@ main(int argc, char *argv[]) const H5FA_class_t *cls = get_H5FA_class(sig); HDassert(cls); - /* Check for enough valid parameters */ + /* Check for enough valid parameters */ if(extra == 0) { - HDfprintf(stderr, "ERROR: Need object header address containing the layout message in order to dump header\n"); + HDfprintf(stderr, "ERROR: Need object header address containing the layout message in order to dump header\n"); HDfprintf(stderr, "Fixed array header block usage:\n"); - HDfprintf(stderr, "\th5debug \n"); + HDfprintf(stderr, "\th5debug \n"); HDexit(4); } /* end if */ -- cgit v0.12