diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2016-09-14 21:02:43 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2016-09-14 21:02:43 (GMT) |
commit | 7f817fea7c50cea4305bc14fcaf4d80fb3dc42e4 (patch) | |
tree | e18b6cefc2cc51c58ebacec1d6a9051742754f71 /src | |
parent | c1c384878ba58193120c3da804d761542c47bd7d (diff) | |
parent | 052efd9bde06ea2427beffd3ea493cbc53a17608 (diff) | |
download | hdf5-7f817fea7c50cea4305bc14fcaf4d80fb3dc42e4.zip hdf5-7f817fea7c50cea4305bc14fcaf4d80fb3dc42e4.tar.gz hdf5-7f817fea7c50cea4305bc14fcaf4d80fb3dc42e4.tar.bz2 |
Merge branch 'develop' into evict_on_close
Diffstat (limited to 'src')
45 files changed, 948 insertions, 518 deletions
@@ -183,8 +183,10 @@ done: herr_t H5AC__init_package(void) { -#ifdef H5_DEBUG_BUILD +#if defined H5_DEBUG_BUILD | defined H5_HAVE_PARALLEL H5P_genplist_t *xfer_plist; /* Dataset transfer property list object */ +#endif /* defined H5_DEBUG_BUILD | defined H5_HAVE_PARALLEL */ +#ifdef H5_DEBUG_BUILD H5FD_dxpl_type_t dxpl_type; /* Property indicating the type of the internal dxpl */ #endif /* H5_DEBUG_BUILD */ #ifdef H5_HAVE_PARALLEL diff --git a/src/H5Aint.c b/src/H5Aint.c index ffb8667..ea90118 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -202,6 +202,11 @@ H5A_create(const H5G_loc_t *loc, const char *name, const H5T_t *type, if(NULL == (attr->shared->dt = H5T_copy(type, H5T_COPY_ALL))) HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "can't get shared datatype info") + /* Convert a datatype (if committed) to a transient type if the committed datatype's file + location is different from the file location where the attribute will be created */ + if(H5T_convert_committed_datatype(attr->shared->dt, loc->oloc->file) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "can't get shared datatype info") + /* Mark datatype as being on disk now */ if(H5T_set_loc(attr->shared->dt, loc->oloc->file, H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid datatype location") @@ -1915,15 +1920,17 @@ H5A_t * H5A_attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_size, H5O_copy_t *cpy_info, hid_t dxpl_id) { - H5A_t *attr_dst = NULL; - - /* for dataype conversion */ + H5A_t *attr_dst = NULL; /* Destination attribute */ hid_t tid_src = -1; /* Datatype ID for source datatype */ hid_t tid_dst = -1; /* Datatype ID for destination datatype */ hid_t tid_mem = -1; /* Datatype ID for memory datatype */ void *buf = NULL; /* Buffer for copying data */ void *reclaim_buf = NULL; /* Buffer for reclaiming data */ + void *bkg_buf = NULL; /* Background buffer */ hid_t buf_sid = -1; /* ID for buffer dataspace */ + hssize_t sdst_nelmts; /* # of elements in destination attribute (signed) */ + size_t dst_nelmts; /* # of elements in destination attribute */ + size_t dst_dt_size; /* Size of destination attribute datatype */ H5A_t *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -2009,12 +2016,17 @@ H5A_attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_si if(attr_dst->shared->dt_size != attr_src->shared->dt_size || attr_dst->shared->ds_size != attr_src->shared->ds_size) *recompute_size = TRUE; + /* Get # of elements for destination attribute's dataspace */ + if((sdst_nelmts = H5S_GET_EXTENT_NPOINTS(attr_dst->shared->ds)) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTCOUNT, NULL, "dataspace is invalid") + H5_CHECKED_ASSIGN(dst_nelmts, size_t, sdst_nelmts, hssize_t); + + /* Get size of destination attribute's datatype */ + if(0 == (dst_dt_size = H5T_get_size(attr_dst->shared->dt))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to determine datatype size") + /* Compute the size of the data */ - /* 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); + attr_dst->shared->data_size = dst_nelmts * dst_dt_size; /* Copy (& convert) the data, if necessary */ if(attr_src->shared->data) { @@ -2093,14 +2105,24 @@ H5A_attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_si HDmemcpy(buf, attr_src->shared->data, attr_src->shared->data_size); + /* Allocate background memory */ + if(H5T_path_bkg(tpath_src_mem) || H5T_path_bkg(tpath_mem_dst)) { + if(NULL == (bkg_buf = H5FL_BLK_CALLOC(attr_buf, buf_size))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTALLOC, FAIL, "memory allocation failed") + } + /* Convert from source file to memory */ - if(H5T_convert(tpath_src_mem, tid_src, tid_mem, nelmts, (size_t)0, (size_t)0, buf, NULL, dxpl_id) < 0) + if(H5T_convert(tpath_src_mem, tid_src, tid_mem, nelmts, (size_t)0, (size_t)0, buf, bkg_buf, dxpl_id) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "datatype conversion NULLed") HDmemcpy(reclaim_buf, buf, buf_size); + /* Set background buffer to all zeros */ + if(bkg_buf) + HDmemset(bkg_buf, 0, buf_size); + /* Convert from memory to destination file */ - if(H5T_convert(tpath_mem_dst, tid_mem, tid_dst, nelmts, (size_t)0, (size_t)0, buf, NULL, dxpl_id) < 0) + if(H5T_convert(tpath_mem_dst, tid_mem, tid_dst, nelmts, (size_t)0, (size_t)0, buf, bkg_buf, dxpl_id) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "datatype conversion NULLed") HDmemcpy(attr_dst->shared->data, buf, attr_dst->shared->data_size); @@ -2147,6 +2169,8 @@ done: buf = H5FL_BLK_FREE(attr_buf, buf); if(reclaim_buf) reclaim_buf = H5FL_BLK_FREE(attr_buf, reclaim_buf); + if(bkg_buf) + bkg_buf = H5FL_BLK_FREE(attr_buf, bkg_buf); /* Release destination attribute information on failure */ if(!ret_value && attr_dst && H5A_close(attr_dst) < 0) diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index 8cf86ac..dde83fe 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -364,6 +364,9 @@ H5FL_DEFINE(H5D_chunk_info_t); /* Declare a free list to manage the chunk sequence information */ H5FL_BLK_DEFINE_STATIC(chunk); +/* Declare extern free list to manage the H5S_sel_iter_t struct */ +H5FL_EXTERN(H5S_sel_iter_t); + /*------------------------------------------------------------------------- * Function: H5D__chunk_direct_write @@ -4557,14 +4560,14 @@ H5D__chunk_prune_fill(H5D_chunk_it_ud1_t *udata, hbool_t new_unfilt_chunk) const H5O_layout_t *layout = &(dset->shared->layout); /* Dataset's layout */ unsigned rank = udata->common.layout->ndims - 1; /* Dataset rank */ const hsize_t *scaled = udata->common.scaled; /* Scaled chunk offset */ - H5S_sel_iter_t chunk_iter; /* Memory selection iteration info */ + H5S_sel_iter_t *chunk_iter = NULL; /* Memory selection iteration info */ + hbool_t chunk_iter_init = FALSE; /* Whether the chunk iterator has been initialized */ hssize_t sel_nelmts; /* Number of elements in selection */ hsize_t count[H5O_LAYOUT_NDIMS]; /* Element count of hyperslab */ size_t chunk_size; /*size of a chunk */ void *chunk; /* The file chunk */ H5D_chunk_ud_t chk_udata; /* User data for locking chunk */ uint32_t bytes_accessed; /* Bytes accessed in chunk */ - hbool_t chunk_iter_init = FALSE; /* Whether the chunk iterator has been initialized */ unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ @@ -4629,13 +4632,17 @@ H5D__chunk_prune_fill(H5D_chunk_it_ud1_t *udata, hbool_t new_unfilt_chunk) if(H5D__fill_refill_vl(&udata->fb_info, (size_t)sel_nelmts, io_info->md_dxpl_id) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "can't refill fill value buffer") + /* Allocate the chunk selection iterator */ + if(NULL == (chunk_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate chunk selection iterator") + /* Create a selection iterator for scattering the elements to memory buffer */ - if(H5S_select_iter_init(&chunk_iter, udata->chunk_space, layout->u.chunk.dim[rank]) < 0) + if(H5S_select_iter_init(chunk_iter, udata->chunk_space, layout->u.chunk.dim[rank]) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize chunk selection information") chunk_iter_init = TRUE; /* Scatter the data into memory */ - if(H5D__scatter_mem(udata->fb_info.fill_buf, udata->chunk_space, &chunk_iter, (size_t)sel_nelmts, io_info->dxpl_cache, chunk/*out*/) < 0) + if(H5D__scatter_mem(udata->fb_info.fill_buf, udata->chunk_space, chunk_iter, (size_t)sel_nelmts, io_info->dxpl_cache, chunk/*out*/) < 0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "scatter failed") @@ -4650,8 +4657,10 @@ H5D__chunk_prune_fill(H5D_chunk_it_ud1_t *udata, hbool_t new_unfilt_chunk) done: /* Release the selection iterator */ - if(chunk_iter_init && H5S_SELECT_ITER_RELEASE(&chunk_iter) < 0) + if(chunk_iter_init && H5S_SELECT_ITER_RELEASE(chunk_iter) < 0) HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") + if(chunk_iter) + chunk_iter = H5FL_FREE(H5S_sel_iter_t, chunk_iter); FUNC_LEAVE_NOAPI(ret_value) } /* H5D__chunk_prune_fill */ diff --git a/src/H5Defl.c b/src/H5Defl.c index cf1b36c..387cbe3 100644 --- a/src/H5Defl.c +++ b/src/H5Defl.c @@ -286,13 +286,13 @@ H5D__efl_read(const H5O_efl_t *efl, const H5D_t *dset, haddr_t addr, size_t size HDassert(buf); if(u >= efl->nused) HGOTO_ERROR(H5E_EFL, H5E_OVERFLOW, FAIL, "read past logical end of file") - if(H5F_OVERFLOW_HSIZET2OFFT(efl->slot[u].offset + skip)) + if(H5F_OVERFLOW_HSIZET2OFFT((hsize_t)efl->slot[u].offset + skip)) HGOTO_ERROR(H5E_EFL, H5E_OVERFLOW, FAIL, "external file address overflowed") if(H5_combine_path(dset->shared->extfile_prefix, efl->slot[u].name, &full_name) < 0) HGOTO_ERROR(H5E_EFL, H5E_NOSPACE, FAIL, "can't build external file name") if((fd = HDopen(full_name, O_RDONLY, 0)) < 0) HGOTO_ERROR(H5E_EFL, H5E_CANTOPENFILE, FAIL, "unable to open external raw data file") - if(HDlseek(fd, (HDoff_t)(efl->slot[u].offset + skip), SEEK_SET) < 0) + if(HDlseek(fd, (HDoff_t)(efl->slot[u].offset + (HDoff_t)skip), SEEK_SET) < 0) HGOTO_ERROR(H5E_EFL, H5E_SEEKERROR, FAIL, "unable to seek in external raw data file") #ifndef NDEBUG tempto_read = MIN((size_t)(efl->slot[u].size-skip), (hsize_t)size); @@ -378,7 +378,7 @@ H5D__efl_write(const H5O_efl_t *efl, const H5D_t *dset, haddr_t addr, size_t siz HDassert(buf); if(u >= efl->nused) HGOTO_ERROR(H5E_EFL, H5E_OVERFLOW, FAIL, "write past logical end of file") - if(H5F_OVERFLOW_HSIZET2OFFT(efl->slot[u].offset + skip)) + if(H5F_OVERFLOW_HSIZET2OFFT((hsize_t)efl->slot[u].offset + skip)) HGOTO_ERROR(H5E_EFL, H5E_OVERFLOW, FAIL, "external file address overflowed") if(H5_combine_path(dset->shared->extfile_prefix, efl->slot[u].name, &full_name) < 0) HGOTO_ERROR(H5E_EFL, H5E_NOSPACE, FAIL, "can't build external file name") @@ -388,7 +388,7 @@ H5D__efl_write(const H5O_efl_t *efl, const H5D_t *dset, haddr_t addr, size_t siz else HGOTO_ERROR(H5E_EFL, H5E_CANTOPENFILE, FAIL, "unable to open external raw data file") } /* end if */ - if(HDlseek(fd, (HDoff_t)(efl->slot[u].offset + skip), SEEK_SET) < 0) + if(HDlseek(fd, (HDoff_t)(efl->slot[u].offset + (HDoff_t)skip), SEEK_SET) < 0) HGOTO_ERROR(H5E_EFL, H5E_SEEKERROR, FAIL, "unable to seek in external raw data file") #ifndef NDEBUG tempto_write = MIN(efl->slot[u].size - skip, (hsize_t)size); diff --git a/src/H5Dfill.c b/src/H5Dfill.c index e5b2161..50c964b 100644 --- a/src/H5Dfill.c +++ b/src/H5Dfill.c @@ -88,6 +88,9 @@ H5FL_BLK_DEFINE_STATIC(non_zero_fill); /* Declare the free list to manage blocks of zero fill-value data */ H5FL_BLK_DEFINE_STATIC(zero_fill); +/* Declare extern free list to manage the H5S_sel_iter_t struct */ +H5FL_EXTERN(H5S_sel_iter_t); + /*-------------------------------------------------------------------------- NAME @@ -174,6 +177,8 @@ herr_t H5D__fill(const void *fill, const H5T_t *fill_type, void *buf, const H5T_t *buf_type, const H5S_t *space, hid_t dxpl_id) { + H5S_sel_iter_t *mem_iter = NULL; /* Memory selection iteration info */ + hbool_t mem_iter_init = FALSE; /* Whether the memory selection iterator has been initialized */ H5WB_t *elem_wb = NULL; /* Wrapped buffer for element data */ uint8_t elem_buf[H5T_ELEM_BUF_SIZE]; /* Buffer for element data */ H5WB_t *bkg_elem_wb = NULL; /* Wrapped buffer for background data */ @@ -246,7 +251,6 @@ H5D__fill(const void *fill, const H5T_t *fill_type, void *buf, if(TRUE == H5T_detect_class(fill_type, H5T_VLEN, FALSE)) { H5D_dxpl_cache_t _dxpl_cache; /* Data transfer property cache buffer */ H5D_dxpl_cache_t *dxpl_cache = &_dxpl_cache; /* Data transfer property cache */ - H5S_sel_iter_t mem_iter; /* Memory selection iteration info */ hssize_t nelmts; /* Number of data elements */ /* Get the number of elements in the selection */ @@ -273,19 +277,18 @@ H5D__fill(const void *fill, const H5T_t *fill_type, void *buf, if(H5D__get_dxpl_cache(dxpl_id, &dxpl_cache) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't fill dxpl cache") + /* Allocate the chunk selection iterator */ + if(NULL == (mem_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate memory selection iterator") + /* Create a selection iterator for scattering the elements to memory buffer */ - if(H5S_select_iter_init(&mem_iter, space, dst_type_size) < 0) + if(H5S_select_iter_init(mem_iter, space, dst_type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize memory selection information") + mem_iter_init = TRUE; /* Scatter the data into memory */ - if(H5D__scatter_mem(tmp_buf, space, &mem_iter, (size_t)nelmts, dxpl_cache, buf/*out*/) < 0) { - H5S_SELECT_ITER_RELEASE(&mem_iter); + if(H5D__scatter_mem(tmp_buf, space, mem_iter, (size_t)nelmts, dxpl_cache, buf/*out*/) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "scatter failed") - } /* end if */ - - /* Release the selection iterator */ - if(H5S_SELECT_ITER_RELEASE(&mem_iter) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") } /* end if */ else { const uint8_t *fill_buf; /* Buffer to use for writing fill values */ @@ -335,6 +338,10 @@ H5D__fill(const void *fill, const H5T_t *fill_type, void *buf, } /* end else */ done: + if(mem_iter_init && H5S_SELECT_ITER_RELEASE(mem_iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") + if(mem_iter) + mem_iter = H5FL_FREE(H5S_sel_iter_t, mem_iter); if(src_id != (-1) && H5I_dec_ref(src_id) < 0) HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't decrement temporary datatype ID") if(dst_id != (-1) && H5I_dec_ref(dst_id) < 0) diff --git a/src/H5Dint.c b/src/H5Dint.c index bbe16cf..5ae3bd3 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -683,6 +683,11 @@ H5D__init_type(H5F_t *file, const H5D_t *dset, hid_t type_id, const H5T_t *type) if((dset->shared->type = H5T_copy(type, H5T_COPY_ALL)) == NULL) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "can't copy datatype") + /* Convert a datatype (if committed) to a transient type if the committed datatype's file + location is different from the file location where the dataset will be created */ + if(H5T_convert_committed_datatype(dset->shared->type, file) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't get shared datatype info") + /* Mark any datatypes as being on disk now */ if(H5T_set_loc(dset->shared->type, file, H5T_LOC_DISK) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't set datatype location") diff --git a/src/H5Dio.c b/src/H5Dio.c index 5004132..f5087da 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -87,6 +87,9 @@ static herr_t H5D__typeinfo_term(const H5D_type_info_t *type_info); /* Declare a free list to manage blocks of type conversion data */ H5FL_BLK_DEFINE(type_conv); +/* Declare a free list to manage the H5D_chunk_map_t struct */ +H5FL_DEFINE(H5D_chunk_map_t); + /*------------------------------------------------------------------------- @@ -366,7 +369,7 @@ herr_t H5D__read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, const H5S_t *file_space, hid_t dxpl_id, void *buf/*out*/) { - H5D_chunk_map_t fm; /* Chunk file<->memory mapping */ + H5D_chunk_map_t *fm = NULL; /* Chunk file<->memory mapping */ H5D_io_info_t io_info; /* Dataset I/O info */ H5D_type_info_t type_info; /* Datatype info for operation */ hbool_t type_info_init = FALSE; /* Whether the datatype info has been initialized */ @@ -523,26 +526,31 @@ H5D__read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, || dataset->shared->dcpl_cache.efl.nused > 0 || dataset->shared->layout.type == H5D_COMPACT); + /* Allocate the chunk map */ + if(NULL == (fm = H5FL_CALLOC(H5D_chunk_map_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate chunk map") + /* Call storage method's I/O initialization routine */ - HDmemset(&fm, 0, sizeof(H5D_chunk_map_t)); - if(io_info.layout_ops.io_init && (*io_info.layout_ops.io_init)(&io_info, &type_info, nelmts, file_space, mem_space, &fm) < 0) + if(io_info.layout_ops.io_init && (*io_info.layout_ops.io_init)(&io_info, &type_info, nelmts, file_space, mem_space, fm) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't initialize I/O info") io_op_init = TRUE; #ifdef H5_HAVE_PARALLEL /* Adjust I/O info for any parallel I/O */ - if(H5D__ioinfo_adjust(&io_info, dataset, dxpl_id, file_space, mem_space, &type_info, &fm) < 0) + if(H5D__ioinfo_adjust(&io_info, dataset, dxpl_id, file_space, mem_space, &type_info, fm) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to adjust I/O info for parallel I/O") #endif /*H5_HAVE_PARALLEL*/ /* Invoke correct "high level" I/O routine */ - if((*io_info.io_ops.multi_read)(&io_info, &type_info, nelmts, file_space, mem_space, &fm) < 0) + if((*io_info.io_ops.multi_read)(&io_info, &type_info, nelmts, file_space, mem_space, fm) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data") done: /* Shut down the I/O op information */ - if(io_op_init && io_info.layout_ops.io_term && (*io_info.layout_ops.io_term)(&fm) < 0) + if(io_op_init && io_info.layout_ops.io_term && (*io_info.layout_ops.io_term)(fm) < 0) HDONE_ERROR(H5E_DATASET, H5E_CANTCLOSEOBJ, FAIL, "unable to shut down I/O op info") + if(fm) + fm = H5FL_FREE(H5D_chunk_map_t, fm); if(io_info_init) { #ifdef H5_DEBUG_BUILD @@ -587,7 +595,7 @@ herr_t H5D__write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, const H5S_t *file_space, hid_t dxpl_id, const void *buf) { - H5D_chunk_map_t fm; /* Chunk file<->memory mapping */ + H5D_chunk_map_t *fm = NULL; /* Chunk file<->memory mapping */ H5D_io_info_t io_info; /* Dataset I/O info */ H5D_type_info_t type_info; /* Datatype info for operation */ hbool_t type_info_init = FALSE; /* Whether the datatype info has been initialized */ @@ -765,20 +773,23 @@ H5D__write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize storage") } /* end if */ + /* Allocate the chunk map */ + if(NULL == (fm = H5FL_CALLOC(H5D_chunk_map_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate chunk map") + /* Call storage method's I/O initialization routine */ - HDmemset(&fm, 0, sizeof(H5D_chunk_map_t)); - if(io_info.layout_ops.io_init && (*io_info.layout_ops.io_init)(&io_info, &type_info, nelmts, file_space, mem_space, &fm) < 0) + if(io_info.layout_ops.io_init && (*io_info.layout_ops.io_init)(&io_info, &type_info, nelmts, file_space, mem_space, fm) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't initialize I/O info") io_op_init = TRUE; #ifdef H5_HAVE_PARALLEL /* Adjust I/O info for any parallel I/O */ - if(H5D__ioinfo_adjust(&io_info, dataset, dxpl_id, file_space, mem_space, &type_info, &fm) < 0) + if(H5D__ioinfo_adjust(&io_info, dataset, dxpl_id, file_space, mem_space, &type_info, fm) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to adjust I/O info for parallel I/O") #endif /*H5_HAVE_PARALLEL*/ /* Invoke correct "high level" I/O routine */ - if((*io_info.io_ops.multi_write)(&io_info, &type_info, nelmts, file_space, mem_space, &fm) < 0) + if((*io_info.io_ops.multi_write)(&io_info, &type_info, nelmts, file_space, mem_space, fm) < 0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data") #ifdef OLD_WAY @@ -801,8 +812,10 @@ H5D__write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, done: /* Shut down the I/O op information */ - if(io_op_init && io_info.layout_ops.io_term && (*io_info.layout_ops.io_term)(&fm) < 0) + if(io_op_init && io_info.layout_ops.io_term && (*io_info.layout_ops.io_term)(fm) < 0) HDONE_ERROR(H5E_DATASET, H5E_CANTCLOSEOBJ, FAIL, "unable to shut down I/O op info") + if(fm) + fm = H5FL_FREE(H5D_chunk_map_t, fm); if(io_info_init) { #ifdef H5_DEBUG_BUILD diff --git a/src/H5Dscatgath.c b/src/H5Dscatgath.c index 7c1abca..55111f0 100644 --- a/src/H5Dscatgath.c +++ b/src/H5Dscatgath.c @@ -67,10 +67,13 @@ static herr_t H5D__compound_opt_write(size_t nelmts, const H5D_type_info_t *type /* Local Variables */ /*******************/ -/* Declare a free list to manage sequences of size_t */ +/* Declare extern free list to manage the H5S_sel_iter_t struct */ +H5FL_EXTERN(H5S_sel_iter_t); + +/* Declare extern free list to manage sequences of size_t */ H5FL_SEQ_EXTERN(size_t); -/* Declare a free list to manage sequences of hsize_t */ +/* Declare extern free list to manage sequences of hsize_t */ H5FL_SEQ_EXTERN(hsize_t); @@ -97,17 +100,16 @@ H5D__scatter_file(const H5D_io_info_t *_io_info, const void *_buf) { H5D_io_info_t tmp_io_info; /* Temporary I/O info object */ - hsize_t _off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets */ hsize_t *off = NULL; /* Pointer to sequence offsets */ hsize_t mem_off; /* Offset in memory */ size_t mem_curr_seq; /* "Current sequence" in memory */ size_t dset_curr_seq; /* "Current sequence" in dataset */ - size_t _len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths */ size_t *len = NULL; /* Array to store sequence lengths */ size_t orig_mem_len, mem_len; /* Length of sequence in memory */ - size_t nseq; /* Number of sequences generated */ - size_t nelem; /* Number of elements used in sequences */ - herr_t ret_value = SUCCEED; /* Return value */ + size_t nseq; /* Number of sequences generated */ + size_t nelem; /* Number of elements used in sequences */ + size_t vec_size; /* Vector length */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -124,21 +126,19 @@ H5D__scatter_file(const H5D_io_info_t *_io_info, tmp_io_info.u.wbuf = _buf; /* Allocate the vector I/O arrays */ - if(tmp_io_info.dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) { - if(NULL == (len = H5FL_SEQ_MALLOC(size_t, tmp_io_info.dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate I/O length vector array") - if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, tmp_io_info.dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate I/O offset vector array") - } /* end if */ - else { - len = _len; - off = _off; - } /* end else */ + if(tmp_io_info.dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) + vec_size = tmp_io_info.dxpl_cache->vec_size; + else + vec_size = H5D_IO_VECTOR_SIZE; + if(NULL == (len = H5FL_SEQ_MALLOC(size_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate I/O length vector array") + if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate I/O offset vector array") /* Loop until all elements are written */ while(nelmts > 0) { /* Get list of sequences for selection to write */ - if(H5S_SELECT_GET_SEQ_LIST(space, H5S_GET_SEQ_LIST_SORTED, iter, tmp_io_info.dxpl_cache->vec_size, nelmts, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(space, H5S_GET_SEQ_LIST_SORTED, iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Reset the current sequence information */ @@ -160,9 +160,9 @@ H5D__scatter_file(const H5D_io_info_t *_io_info, done: /* Release resources, if allocated */ - if(len && len != _len) + if(len) len = H5FL_SEQ_FREE(size_t, len); - if(off && off != _off) + if(off) off = H5FL_SEQ_FREE(hsize_t, off); FUNC_LEAVE_NOAPI(ret_value) @@ -196,16 +196,15 @@ H5D__gather_file(const H5D_io_info_t *_io_info, void *_buf/*out*/) { H5D_io_info_t tmp_io_info; /* Temporary I/O info object */ - hsize_t _off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets */ hsize_t *off = NULL; /* Pointer to sequence offsets */ hsize_t mem_off; /* Offset in memory */ size_t mem_curr_seq; /* "Current sequence" in memory */ size_t dset_curr_seq; /* "Current sequence" in dataset */ - size_t _len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths */ size_t *len = NULL; /* Pointer to sequence lengths */ size_t orig_mem_len, mem_len; /* Length of sequence in memory */ size_t nseq; /* Number of sequences generated */ size_t nelem; /* Number of elements used in sequences */ + size_t vec_size; /* Vector length */ size_t ret_value = nelmts; /* Return value */ FUNC_ENTER_STATIC @@ -225,21 +224,19 @@ H5D__gather_file(const H5D_io_info_t *_io_info, tmp_io_info.u.rbuf = _buf; /* Allocate the vector I/O arrays */ - if(tmp_io_info.dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) { - if(NULL == (len = H5FL_SEQ_MALLOC(size_t, tmp_io_info.dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "can't allocate I/O length vector array") - if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, tmp_io_info.dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "can't allocate I/O offset vector array") - } /* end if */ - else { - len = _len; - off = _off; - } /* end else */ + if(tmp_io_info.dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) + vec_size = tmp_io_info.dxpl_cache->vec_size; + else + vec_size = H5D_IO_VECTOR_SIZE; + if(NULL == (len = H5FL_SEQ_MALLOC(size_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, 0, "can't allocate I/O length vector array") + if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, 0, "can't allocate I/O offset vector array") /* Loop until all elements are read */ while(nelmts > 0) { /* Get list of sequences for selection to read */ - if(H5S_SELECT_GET_SEQ_LIST(space, H5S_GET_SEQ_LIST_SORTED, iter, tmp_io_info.dxpl_cache->vec_size, nelmts, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(space, H5S_GET_SEQ_LIST_SORTED, iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, 0, "sequence length generation failed") /* Reset the current sequence information */ @@ -261,9 +258,9 @@ H5D__gather_file(const H5D_io_info_t *_io_info, done: /* Release resources, if allocated */ - if(len && len != _len) + if(len) len = H5FL_SEQ_FREE(size_t, len); - if(off && off != _off) + if(off) off = H5FL_SEQ_FREE(hsize_t, off); FUNC_LEAVE_NOAPI(ret_value) @@ -292,15 +289,14 @@ H5D__scatter_mem (const void *_tscat_buf, const H5S_t *space, { uint8_t *buf = (uint8_t *)_buf; /* Get local copies for address arithmetic */ const uint8_t *tscat_buf = (const uint8_t *)_tscat_buf; - hsize_t _off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets */ - hsize_t *off = NULL; /* Pointer to sequence offsets */ - size_t _len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths */ - size_t *len = NULL; /* Pointer to sequence lengths */ + hsize_t *off = NULL; /* Pointer to sequence offsets */ + size_t *len = NULL; /* Pointer to sequence lengths */ size_t curr_len; /* Length of bytes left to process in sequence */ size_t nseq; /* Number of sequences generated */ size_t curr_seq; /* Current sequence being processed */ size_t nelem; /* Number of elements used in sequences */ - herr_t ret_value = SUCCEED; /* Number of elements scattered */ + size_t vec_size; /* Vector length */ + herr_t ret_value = SUCCEED; /* Number of elements scattered */ FUNC_ENTER_PACKAGE @@ -312,21 +308,19 @@ H5D__scatter_mem (const void *_tscat_buf, const H5S_t *space, HDassert(buf); /* Allocate the vector I/O arrays */ - if(dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) { - if(NULL == (len = H5FL_SEQ_MALLOC(size_t, dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate I/O length vector array") - if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate I/O offset vector array") - } /* end if */ - else { - len = _len; - off = _off; - } /* end else */ + if(dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) + vec_size = dxpl_cache->vec_size; + else + vec_size = H5D_IO_VECTOR_SIZE; + if(NULL == (len = H5FL_SEQ_MALLOC(size_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate I/O length vector array") + if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate I/O offset vector array") /* Loop until all elements are written */ while(nelmts > 0) { /* Get list of sequences for selection to write */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, dxpl_cache->vec_size, nelmts, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) HGOTO_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, 0, "sequence length generation failed") /* Loop, while sequences left to process */ @@ -346,9 +340,9 @@ H5D__scatter_mem (const void *_tscat_buf, const H5S_t *space, done: /* Release resources, if allocated */ - if(len && len != _len) + if(len) len = H5FL_SEQ_FREE(size_t, len); - if(off && off != _off) + if(off) off = H5FL_SEQ_FREE(hsize_t, off); FUNC_LEAVE_NOAPI(ret_value) @@ -379,15 +373,14 @@ H5D__gather_mem(const void *_buf, const H5S_t *space, { const uint8_t *buf = (const uint8_t *)_buf; /* Get local copies for address arithmetic */ uint8_t *tgath_buf = (uint8_t *)_tgath_buf; - hsize_t _off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets */ hsize_t *off = NULL; /* Pointer to sequence offsets */ - size_t _len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths */ - size_t *len = NULL; /* Pointer to sequence lengths */ + size_t *len = NULL; /* Pointer to sequence lengths */ size_t curr_len; /* Length of bytes left to process in sequence */ size_t nseq; /* Number of sequences generated */ size_t curr_seq; /* Current sequence being processed */ size_t nelem; /* Number of elements used in sequences */ - size_t ret_value = nelmts; /* Number of elements gathered */ + size_t vec_size; /* Vector length */ + size_t ret_value = nelmts; /* Number of elements gathered */ FUNC_ENTER_STATIC @@ -399,21 +392,19 @@ H5D__gather_mem(const void *_buf, const H5S_t *space, HDassert(tgath_buf); /* Allocate the vector I/O arrays */ - if(dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) { - if(NULL == (len = H5FL_SEQ_MALLOC(size_t, dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "can't allocate I/O length vector array") - if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "can't allocate I/O offset vector array") - } /* end if */ - else { - len = _len; - off = _off; - } /* end else */ + if(dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) + vec_size = dxpl_cache->vec_size; + else + vec_size = H5D_IO_VECTOR_SIZE; + if(NULL == (len = H5FL_SEQ_MALLOC(size_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, 0, "can't allocate I/O length vector array") + if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, 0, "can't allocate I/O offset vector array") /* Loop until all elements are written */ while(nelmts > 0) { /* Get list of sequences for selection to write */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, dxpl_cache->vec_size, nelmts, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) HGOTO_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, 0, "sequence length generation failed") /* Loop, while sequences left to process */ @@ -433,9 +424,9 @@ H5D__gather_mem(const void *_buf, const H5S_t *space, done: /* Release resources, if allocated */ - if(len && len != _len) + if(len) len = H5FL_SEQ_FREE(size_t, len); - if(off && off != _off) + if(off) off = H5FL_SEQ_FREE(hsize_t, off); FUNC_LEAVE_NOAPI(ret_value) @@ -460,15 +451,15 @@ H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf { const H5D_dxpl_cache_t *dxpl_cache = io_info->dxpl_cache; /* Local pointer to dataset transfer info */ void *buf = io_info->u.rbuf; /* Local pointer to application buffer */ - H5S_sel_iter_t mem_iter; /*memory selection iteration info*/ - hbool_t mem_iter_init = FALSE; /*memory selection iteration info has been initialized */ - H5S_sel_iter_t bkg_iter; /*background iteration info*/ - hbool_t bkg_iter_init = FALSE; /*background iteration info has been initialized */ - H5S_sel_iter_t file_iter; /*file selection iteration info*/ - hbool_t file_iter_init = FALSE; /*file selection iteration info has been initialized */ - hsize_t smine_start; /*strip mine start loc */ - size_t smine_nelmts; /*elements per strip */ - herr_t ret_value = SUCCEED; /*return value */ + H5S_sel_iter_t *mem_iter = NULL; /* Memory selection iteration info*/ + hbool_t mem_iter_init = FALSE; /* Memory selection iteration info has been initialized */ + H5S_sel_iter_t *bkg_iter = NULL; /* Background iteration info*/ + hbool_t bkg_iter_init = FALSE; /* Background iteration info has been initialized */ + H5S_sel_iter_t *file_iter = NULL; /* File selection iteration info*/ + hbool_t file_iter_init = FALSE; /* File selection iteration info has been initialized */ + hsize_t smine_start; /* Strip mine start loc */ + size_t smine_nelmts; /* Elements per strip */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -483,14 +474,22 @@ H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf if(nelmts == 0) HGOTO_DONE(SUCCEED) + /* Allocate the iterators */ + if(NULL == (mem_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate memory iterator") + if(NULL == (bkg_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate background iterator") + if(NULL == (file_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate file iterator") + /* Figure out the strip mine size. */ - if(H5S_select_iter_init(&file_iter, file_space, type_info->src_type_size) < 0) + if(H5S_select_iter_init(file_iter, file_space, type_info->src_type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize file selection information") file_iter_init = TRUE; /*file selection iteration info has been initialized */ - if(H5S_select_iter_init(&mem_iter, mem_space, type_info->dst_type_size) < 0) + if(H5S_select_iter_init(mem_iter, mem_space, type_info->dst_type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize memory selection information") mem_iter_init = TRUE; /*file selection iteration info has been initialized */ - if(H5S_select_iter_init(&bkg_iter, mem_space, type_info->dst_type_size) < 0) + if(H5S_select_iter_init(bkg_iter, mem_space, type_info->dst_type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize background selection information") bkg_iter_init = TRUE; /*file selection iteration info has been initialized */ @@ -499,7 +498,7 @@ H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf size_t n; /* Elements operated on */ /* Go figure out how many elements to read from the file */ - HDassert(H5S_SELECT_ITER_NELMTS(&file_iter) == (nelmts - smine_start)); + HDassert(H5S_SELECT_ITER_NELMTS(file_iter) == (nelmts - smine_start)); smine_nelmts = (size_t)MIN(type_info->request_nelmts, (nelmts - smine_start)); /* @@ -511,8 +510,7 @@ H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf /* * Gather data */ - n = H5D__gather_file(io_info, file_space, &file_iter, smine_nelmts, - type_info->tconv_buf/*out*/); + n = H5D__gather_file(io_info, file_space, file_iter, smine_nelmts, type_info->tconv_buf/*out*/); if(n != smine_nelmts) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file gather failed") @@ -521,14 +519,12 @@ H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf * bypass the rest of steps. */ if(type_info->cmpd_subset && H5T_SUBSET_FALSE != type_info->cmpd_subset->subset) { - if(H5D__compound_opt_read(smine_nelmts, mem_space, &mem_iter, dxpl_cache, - type_info, buf /*out*/) < 0) + if(H5D__compound_opt_read(smine_nelmts, mem_space, mem_iter, dxpl_cache, type_info, buf /*out*/) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "datatype conversion failed") } /* end if */ else { if(H5T_BKG_YES == type_info->need_bkg) { - n = H5D__gather_mem(buf, mem_space, &bkg_iter, smine_nelmts, - dxpl_cache, type_info->bkg_buf/*out*/); + n = H5D__gather_mem(buf, mem_space, bkg_iter, smine_nelmts, dxpl_cache, type_info->bkg_buf/*out*/); if(n != smine_nelmts) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "mem gather failed") } /* end if */ @@ -549,26 +545,25 @@ H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf /* * Scatter the data into memory. */ - if(H5D__scatter_mem(type_info->tconv_buf, mem_space, &mem_iter, - smine_nelmts, dxpl_cache, buf/*out*/) < 0) + if(H5D__scatter_mem(type_info->tconv_buf, mem_space, mem_iter, smine_nelmts, dxpl_cache, buf/*out*/) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "scatter failed") } /* end else */ } /* end for */ done: /* Release selection iterators */ - if(file_iter_init) { - if(H5S_SELECT_ITER_RELEASE(&file_iter) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") - } /* end if */ - if(mem_iter_init) { - if(H5S_SELECT_ITER_RELEASE(&mem_iter) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") - } /* end if */ - if(bkg_iter_init) { - if(H5S_SELECT_ITER_RELEASE(&bkg_iter) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") - } /* end if */ + if(file_iter_init && H5S_SELECT_ITER_RELEASE(file_iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") + if(file_iter) + file_iter = H5FL_FREE(H5S_sel_iter_t, file_iter); + if(mem_iter_init && H5S_SELECT_ITER_RELEASE(mem_iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") + if(mem_iter) + mem_iter = H5FL_FREE(H5S_sel_iter_t, mem_iter); + if(bkg_iter_init && H5S_SELECT_ITER_RELEASE(bkg_iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") + if(bkg_iter) + bkg_iter = H5FL_FREE(H5S_sel_iter_t, bkg_iter); FUNC_LEAVE_NOAPI(ret_value) } /* end H5D__scatgath_read() */ @@ -592,15 +587,15 @@ H5D__scatgath_write(const H5D_io_info_t *io_info, const H5D_type_info_t *type_in { const H5D_dxpl_cache_t *dxpl_cache = io_info->dxpl_cache; /* Local pointer to dataset transfer info */ const void *buf = io_info->u.wbuf; /* Local pointer to application buffer */ - H5S_sel_iter_t mem_iter; /*memory selection iteration info*/ - hbool_t mem_iter_init = FALSE; /*memory selection iteration info has been initialized */ - H5S_sel_iter_t bkg_iter; /*background iteration info*/ - hbool_t bkg_iter_init = FALSE; /*background iteration info has been initialized */ - H5S_sel_iter_t file_iter; /*file selection iteration info*/ - hbool_t file_iter_init = FALSE; /*file selection iteration info has been initialized */ - hsize_t smine_start; /*strip mine start loc */ - size_t smine_nelmts; /*elements per strip */ - herr_t ret_value = SUCCEED; /*return value */ + H5S_sel_iter_t *mem_iter = NULL; /* Memory selection iteration info*/ + hbool_t mem_iter_init = FALSE; /* Memory selection iteration info has been initialized */ + H5S_sel_iter_t *bkg_iter = NULL; /* Background iteration info*/ + hbool_t bkg_iter_init = FALSE; /* Background iteration info has been initialized */ + H5S_sel_iter_t *file_iter = NULL; /* File selection iteration info*/ + hbool_t file_iter_init = FALSE; /* File selection iteration info has been initialized */ + hsize_t smine_start; /* Strip mine start loc */ + size_t smine_nelmts; /* Elements per strip */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -615,14 +610,22 @@ H5D__scatgath_write(const H5D_io_info_t *io_info, const H5D_type_info_t *type_in if(nelmts == 0) HGOTO_DONE(SUCCEED) + /* Allocate the iterators */ + if(NULL == (mem_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate memory iterator") + if(NULL == (bkg_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate background iterator") + if(NULL == (file_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate file iterator") + /* Figure out the strip mine size. */ - if(H5S_select_iter_init(&file_iter, file_space, type_info->dst_type_size) < 0) + if(H5S_select_iter_init(file_iter, file_space, type_info->dst_type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize file selection information") file_iter_init = TRUE; /*file selection iteration info has been initialized */ - if(H5S_select_iter_init(&mem_iter, mem_space, type_info->src_type_size) < 0) + if(H5S_select_iter_init(mem_iter, mem_space, type_info->src_type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize memory selection information") mem_iter_init = TRUE; /*file selection iteration info has been initialized */ - if(H5S_select_iter_init(&bkg_iter, file_space, type_info->dst_type_size) < 0) + if(H5S_select_iter_init(bkg_iter, file_space, type_info->dst_type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize background selection information") bkg_iter_init = TRUE; /*file selection iteration info has been initialized */ @@ -631,7 +634,7 @@ H5D__scatgath_write(const H5D_io_info_t *io_info, const H5D_type_info_t *type_in size_t n; /* Elements operated on */ /* Go figure out how many elements to read from the file */ - HDassert(H5S_SELECT_ITER_NELMTS(&file_iter) == (nelmts - smine_start)); + HDassert(H5S_SELECT_ITER_NELMTS(file_iter) == (nelmts - smine_start)); smine_nelmts = (size_t)MIN(type_info->request_nelmts, (nelmts - smine_start)); /* @@ -639,8 +642,7 @@ H5D__scatgath_write(const H5D_io_info_t *io_info, const H5D_type_info_t *type_in * buffer. Also gather data from the file into the background buffer * if necessary. */ - n = H5D__gather_mem(buf, mem_space, &mem_iter, smine_nelmts, - dxpl_cache, type_info->tconv_buf/*out*/); + n = H5D__gather_mem(buf, mem_space, mem_iter, smine_nelmts, dxpl_cache, type_info->tconv_buf/*out*/); if(n != smine_nelmts) HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "mem gather failed") @@ -657,8 +659,7 @@ H5D__scatgath_write(const H5D_io_info_t *io_info, const H5D_type_info_t *type_in } /* end if */ else { if(H5T_BKG_YES == type_info->need_bkg) { - n = H5D__gather_file(io_info, file_space, &bkg_iter, smine_nelmts, - type_info->bkg_buf/*out*/); + n = H5D__gather_file(io_info, file_space, bkg_iter, smine_nelmts, type_info->bkg_buf/*out*/); if(n != smine_nelmts) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file gather failed") } /* end if */ @@ -681,25 +682,24 @@ H5D__scatgath_write(const H5D_io_info_t *io_info, const H5D_type_info_t *type_in /* * Scatter the data out to the file. */ - if(H5D__scatter_file(io_info, file_space, &file_iter, smine_nelmts, - type_info->tconv_buf) < 0) + if(H5D__scatter_file(io_info, file_space, file_iter, smine_nelmts, type_info->tconv_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "scatter failed") } /* end for */ done: /* Release selection iterators */ - if(file_iter_init) { - if(H5S_SELECT_ITER_RELEASE(&file_iter) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") - } /* end if */ - if(mem_iter_init) { - if(H5S_SELECT_ITER_RELEASE(&mem_iter) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") - } /* end if */ - if(bkg_iter_init) { - if(H5S_SELECT_ITER_RELEASE(&bkg_iter) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") - } /* end if */ + if(file_iter_init && H5S_SELECT_ITER_RELEASE(file_iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") + if(file_iter) + file_iter = H5FL_FREE(H5S_sel_iter_t, file_iter); + if(mem_iter_init && H5S_SELECT_ITER_RELEASE(mem_iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") + if(mem_iter) + mem_iter = H5FL_FREE(H5S_sel_iter_t, mem_iter); + if(bkg_iter_init && H5S_SELECT_ITER_RELEASE(bkg_iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") + if(bkg_iter) + bkg_iter = H5FL_FREE(H5S_sel_iter_t, bkg_iter); FUNC_LEAVE_NOAPI(ret_value) } /* end H5D__scatgath_write() */ @@ -744,12 +744,11 @@ H5D__compound_opt_read(size_t nelmts, const H5S_t *space, { uint8_t *ubuf = (uint8_t *)user_buf; /* Cast for pointer arithmetic */ uint8_t *xdbuf; /* Pointer into dataset buffer */ - hsize_t _off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets */ hsize_t *off = NULL; /* Pointer to sequence offsets */ - size_t _len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths */ size_t *len = NULL; /* Pointer to sequence lengths */ size_t src_stride, dst_stride, copy_size; - herr_t ret_value = SUCCEED; /*return value */ + size_t vec_size; /* Vector length */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -765,16 +764,14 @@ H5D__compound_opt_read(size_t nelmts, const H5S_t *space, HDassert(user_buf); /* Allocate the vector I/O arrays */ - if(dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) { - if(NULL == (len = H5FL_SEQ_MALLOC(size_t, dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate I/O length vector array") - if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate I/O offset vector array") - } /* end if */ - else { - len = _len; - off = _off; - } /* end else */ + if(dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) + vec_size = dxpl_cache->vec_size; + else + vec_size = H5D_IO_VECTOR_SIZE; + if(NULL == (len = H5FL_SEQ_MALLOC(size_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate I/O length vector array") + if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate I/O offset vector array") /* Get source & destination strides */ src_stride = type_info->src_type_size; @@ -791,7 +788,7 @@ H5D__compound_opt_read(size_t nelmts, const H5S_t *space, size_t elmtno; /* Element counter */ /* Get list of sequences for selection to write */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, dxpl_cache->vec_size, nelmts, &nseq, &elmtno, off, len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, vec_size, nelmts, &nseq, &elmtno, off, len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, 0, "sequence length generation failed") /* Loop, while sequences left to process */ @@ -827,9 +824,9 @@ H5D__compound_opt_read(size_t nelmts, const H5S_t *space, done: /* Release resources, if allocated */ - if(len && len != _len) + if(len) len = H5FL_SEQ_FREE(size_t, len); - if(off && off != _off) + if(off) off = H5FL_SEQ_FREE(hsize_t, off); FUNC_LEAVE_NOAPI(ret_value) @@ -923,7 +920,7 @@ H5Dscatter(H5D_scatter_func_t op, void *op_data, hid_t type_id, { H5T_t *type; /* Datatype */ H5S_t *dst_space; /* Dataspace */ - H5S_sel_iter_t iter; /* Selection iteration info*/ + H5S_sel_iter_t *iter = NULL; /* Selection iteration info*/ hbool_t iter_init = FALSE; /* Selection iteration info has been initialized */ const void *src_buf = NULL; /* Source (contiguous) data buffer */ size_t src_buf_nbytes = 0; /* Size of src_buf */ @@ -959,8 +956,12 @@ H5Dscatter(H5D_scatter_func_t op, void *op_data, hid_t type_id, if((nelmts = (hssize_t)H5S_GET_SELECT_NPOINTS(dst_space)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOUNT, FAIL, "unable to get number of elements in selection") + /* Allocate the selection iterator */ + if(NULL == (iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate selection iterator") + /* Initialize selection iterator */ - if(H5S_select_iter_init(&iter, dst_space, type_size) < 0) + if(H5S_select_iter_init(iter, dst_space, type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize selection iterator information") iter_init = TRUE; @@ -984,7 +985,7 @@ H5Dscatter(H5D_scatter_func_t op, void *op_data, hid_t type_id, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "callback returned more elements than in selection") /* Scatter data */ - if(H5D__scatter_mem(src_buf, dst_space, &iter, nelmts_scatter, dxpl_cache, dst_buf) < 0) + if(H5D__scatter_mem(src_buf, dst_space, iter, nelmts_scatter, dxpl_cache, dst_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "scatter failed") nelmts -= (hssize_t)nelmts_scatter; @@ -992,10 +993,10 @@ H5Dscatter(H5D_scatter_func_t op, void *op_data, hid_t type_id, done: /* Release selection iterator */ - if(iter_init) { - if(H5S_SELECT_ITER_RELEASE(&iter) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") - } /* end if */ + if(iter_init && H5S_SELECT_ITER_RELEASE(iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") + if(iter) + iter = H5FL_FREE(H5S_sel_iter_t, iter); FUNC_LEAVE_API(ret_value) } /* H5Dscatter() */ @@ -1023,7 +1024,7 @@ H5Dgather(hid_t src_space_id, const void *src_buf, hid_t type_id, { H5T_t *type; /* Datatype */ H5S_t *src_space; /* Dataspace */ - H5S_sel_iter_t iter; /* Selection iteration info*/ + H5S_sel_iter_t *iter = NULL; /* Selection iteration info*/ hbool_t iter_init = FALSE; /* Selection iteration info has been initialized */ size_t type_size; /* Datatype element size */ hssize_t nelmts; /* Number of remaining elements in selection */ @@ -1071,15 +1072,19 @@ H5Dgather(hid_t src_space_id, const void *src_buf, hid_t type_id, if(((size_t)nelmts > dst_buf_nelmts) && (op == NULL)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no callback supplied and destination buffer too small") + /* Allocate the selection iterator */ + if(NULL == (iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate selection iterator") + /* Initialize selection iterator */ - if(H5S_select_iter_init(&iter, src_space, type_size) < 0) + if(H5S_select_iter_init(iter, src_space, type_size) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize selection iterator information") iter_init = TRUE; /* Loop until all data has been scattered */ while(nelmts > 0) { /* Gather data */ - if(0 == (nelmts_gathered = H5D__gather_mem(src_buf, src_space, &iter, MIN(dst_buf_nelmts, (size_t)nelmts), dxpl_cache, dst_buf))) + if(0 == (nelmts_gathered = H5D__gather_mem(src_buf, src_space, iter, MIN(dst_buf_nelmts, (size_t)nelmts), dxpl_cache, dst_buf))) HGOTO_ERROR(H5E_IO, H5E_CANTCOPY, FAIL, "gather failed") HDassert(nelmts_gathered == MIN(dst_buf_nelmts, (size_t)nelmts)); @@ -1093,10 +1098,10 @@ H5Dgather(hid_t src_space_id, const void *src_buf, hid_t type_id, done: /* Release selection iterator */ - if(iter_init) { - if(H5S_SELECT_ITER_RELEASE(&iter) < 0) - HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") - } /* end if */ + if(iter_init && H5S_SELECT_ITER_RELEASE(iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "Can't release selection iterator") + if(iter) + iter = H5FL_FREE(H5S_sel_iter_t, iter); FUNC_LEAVE_API(ret_value) } /* H5Dgather() */ diff --git a/src/H5Dselect.c b/src/H5Dselect.c index 312beba..53829e5 100644 --- a/src/H5Dselect.c +++ b/src/H5Dselect.c @@ -68,6 +68,9 @@ H5FL_SEQ_DEFINE(size_t); /* Declare a free list to manage sequences of hsize_t */ H5FL_SEQ_DEFINE(hsize_t); +/* Declare extern free list to manage the H5S_sel_iter_t struct */ +H5FL_EXTERN(H5S_sel_iter_t); + /*------------------------------------------------------------------------- @@ -86,22 +89,19 @@ static herr_t H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, size_t nelmts, const H5S_t *file_space, const H5S_t *mem_space) { - H5S_sel_iter_t mem_iter; /* Memory selection iteration info */ - hbool_t mem_iter_init = 0; /* Memory selection iteration info has been initialized */ - H5S_sel_iter_t file_iter; /* File selection iteration info */ - hbool_t file_iter_init = 0; /* File selection iteration info has been initialized */ - hsize_t _mem_off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets in memory */ + H5S_sel_iter_t *mem_iter = NULL; /* Memory selection iteration info */ + hbool_t mem_iter_init = FALSE; /* Memory selection iteration info has been initialized */ + H5S_sel_iter_t *file_iter = NULL; /* File selection iteration info */ + hbool_t file_iter_init = FALSE; /* File selection iteration info has been initialized */ hsize_t *mem_off = NULL; /* Pointer to sequence offsets in memory */ - hsize_t _file_off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets in the file */ hsize_t *file_off = NULL; /* Pointer to sequence offsets in the file */ - size_t _mem_len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths in memory */ size_t *mem_len = NULL; /* Pointer to sequence lengths in memory */ - size_t _file_len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths in the file */ size_t *file_len = NULL; /* Pointer to sequence lengths in the file */ size_t curr_mem_seq; /* Current memory sequence to operate on */ size_t curr_file_seq; /* Current file sequence to operate on */ size_t mem_nseq; /* Number of sequences generated in the file */ size_t file_nseq; /* Number of sequences generated in memory */ + size_t vec_size; /* Vector length */ ssize_t tmp_file_len; /* Temporary number of bytes in file sequence */ herr_t ret_value = SUCCEED; /* Return value */ @@ -115,22 +115,18 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, HDassert(io_info->u.rbuf); /* Allocate the vector I/O arrays */ - if(io_info->dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) { - if(NULL == (mem_len = H5FL_SEQ_MALLOC(size_t,io_info->dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate I/O length vector array") - if(NULL == (mem_off = H5FL_SEQ_MALLOC(hsize_t,io_info->dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate I/O offset vector array") - if(NULL == (file_len = H5FL_SEQ_MALLOC(size_t,io_info->dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate I/O length vector array") - if(NULL == (file_off = H5FL_SEQ_MALLOC(hsize_t,io_info->dxpl_cache->vec_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate I/O offset vector array") - } /* end if */ - else { - mem_len = _mem_len; - mem_off = _mem_off; - file_len = _file_len; - file_off = _file_off; - } /* end else */ + if(io_info->dxpl_cache->vec_size > H5D_IO_VECTOR_SIZE) + vec_size = io_info->dxpl_cache->vec_size; + else + vec_size = H5D_IO_VECTOR_SIZE; + if(NULL == (mem_len = H5FL_SEQ_MALLOC(size_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate I/O length vector array") + if(NULL == (mem_off = H5FL_SEQ_MALLOC(hsize_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate I/O offset vector array") + if(NULL == (file_len = H5FL_SEQ_MALLOC(size_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate I/O length vector array") + if(NULL == (file_off = H5FL_SEQ_MALLOC(hsize_t, vec_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate I/O offset vector array") /* Check for only one element in selection */ if(nelmts == 1) { @@ -169,13 +165,19 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, size_t mem_nelem; /* Number of elements used in memory sequences */ size_t file_nelem; /* Number of elements used in file sequences */ + /* Allocate the iterators */ + if(NULL == (mem_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate memory iterator") + if(NULL == (file_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate file iterator") + /* Initialize file iterator */ - if(H5S_select_iter_init(&file_iter, file_space, elmt_size) < 0) + if(H5S_select_iter_init(file_iter, file_space, elmt_size) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") file_iter_init = 1; /* File selection iteration info has been initialized */ /* Initialize memory iterator */ - if(H5S_select_iter_init(&mem_iter, mem_space, elmt_size) < 0) + if(H5S_select_iter_init(mem_iter, mem_space, elmt_size) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") mem_iter_init = 1; /* Memory selection iteration info has been initialized */ @@ -188,7 +190,7 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, /* Check if more file sequences are needed */ if(curr_file_seq >= file_nseq) { /* Get sequences for file selection */ - if(H5S_SELECT_GET_SEQ_LIST(file_space, H5S_GET_SEQ_LIST_SORTED, &file_iter, io_info->dxpl_cache->vec_size, nelmts, &file_nseq, &file_nelem, file_off, file_len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(file_space, H5S_GET_SEQ_LIST_SORTED, file_iter, vec_size, nelmts, &file_nseq, &file_nelem, file_off, file_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Start at the beginning of the sequences again */ @@ -198,7 +200,7 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, /* Check if more memory sequences are needed */ if(curr_mem_seq >= mem_nseq) { /* Get sequences for memory selection */ - if(H5S_SELECT_GET_SEQ_LIST(mem_space, 0, &mem_iter, io_info->dxpl_cache->vec_size, nelmts, &mem_nseq, &mem_nelem, mem_off, mem_len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(mem_space, 0, mem_iter, vec_size, nelmts, &mem_nseq, &mem_nelem, mem_off, mem_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Start at the beginning of the sequences again */ @@ -227,24 +229,24 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, } /* end else */ done: - /* Release file selection iterator */ - if(file_iter_init) - if(H5S_SELECT_ITER_RELEASE(&file_iter) < 0) - HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") - - /* Release memory selection iterator */ - if(mem_iter_init) - if(H5S_SELECT_ITER_RELEASE(&mem_iter) < 0) - HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + /* Release selection iterators */ + if(file_iter_init && H5S_SELECT_ITER_RELEASE(file_iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + if(file_iter) + file_iter = H5FL_FREE(H5S_sel_iter_t, file_iter); + if(mem_iter_init && H5S_SELECT_ITER_RELEASE(mem_iter) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + if(mem_iter) + mem_iter = H5FL_FREE(H5S_sel_iter_t, mem_iter); /* Release vector arrays, if allocated */ - if(file_len && file_len != _file_len) + if(file_len) file_len = H5FL_SEQ_FREE(size_t, file_len); - if(file_off && file_off != _file_off) + if(file_off) file_off = H5FL_SEQ_FREE(hsize_t, file_off); - if(mem_len && mem_len != _mem_len) + if(mem_len) mem_len = H5FL_SEQ_FREE(size_t, mem_len); - if(mem_off && mem_off != _mem_off) + if(mem_off) mem_off = H5FL_SEQ_FREE(hsize_t, mem_off); FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5FDcore.c b/src/H5FDcore.c index 5ce6560..f29e231 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -203,9 +203,6 @@ H5FD__core_add_dirty_region(H5FD_core_t *file, haddr_t start, haddr_t end) haddr_t a_addr = 0; hbool_t create_new_node = TRUE; herr_t ret_value = SUCCEED; -#ifdef DER - hbool_t was_adjusted = FALSE; -#endif FUNC_ENTER_STATIC @@ -213,34 +210,15 @@ H5FD__core_add_dirty_region(H5FD_core_t *file, haddr_t start, haddr_t end) HDassert(file->dirty_list); HDassert(start <= end); -#ifdef DER -fprintf(stderr, "Add region: (%llu, %llu)\n", start, end); -#endif - /* Adjust the dirty region to the nearest block boundaries */ - if(start % file->bstore_page_size != 0) { + if(start % file->bstore_page_size != 0) start = (start / file->bstore_page_size) * file->bstore_page_size; -#ifdef DER - was_adjusted = TRUE; -#endif - } + if(end % file->bstore_page_size != (file->bstore_page_size - 1)) { end = (((end / file->bstore_page_size) + 1) * file->bstore_page_size) - 1; - if(end > file->eof){ -#ifdef DER -fprintf(stderr, "Adjusted to EOF\n"); -#endif + if(end > file->eof) end = file->eof - 1; - } -#ifdef DER - was_adjusted = TRUE; -#endif - } - -#ifdef DER -if(was_adjusted) - fprintf(stderr, "Adjusted region: (%llu, %llu)\n", start, end); -#endif + } /* end if */ /* Get the regions before and after the intended insertion point */ b_addr = start +1; @@ -249,15 +227,13 @@ if(was_adjusted) a_item = (H5FD_core_region_t *)H5SL_less(file->dirty_list, &a_addr); /* Check to see if we need to extend the upper end of the NEW region */ - if(a_item) { + if(a_item) if(start < a_item->start && end < a_item->end) { - /* Extend the end of the NEW region to match the existing AFTER region */ end = a_item->end; - } - } + } /* end if */ /* Attempt to extend the PREV region */ - if(b_item) { + if(b_item) if(start <= b_item->end + 1) { /* Need to set this for the delete algorithm */ @@ -267,8 +243,7 @@ if(was_adjusted) * just update an existing one instead. */ create_new_node = FALSE; - } - } + } /* end if */ /* Remove any old nodes that are no longer needed */ while(a_item && a_item->start > start) { @@ -286,7 +261,7 @@ if(was_adjusted) /* Set up to check the next node */ if(less) a_item = less; - } + } /* end while */ /* Insert the new node */ if(create_new_node) { @@ -297,17 +272,17 @@ if(was_adjusted) item->end = end; if(H5SL_insert(file->dirty_list, item, &item->start) < 0) HGOTO_ERROR(H5E_SLIST, H5E_CANTINSERT, FAIL, "can't insert new dirty region: (%llu, %llu)\n", (unsigned long long)start, (unsigned long long)end) - } + } /* end if */ else { /* Store the new item endpoint if it's bigger */ item->end = (item->end < end) ? end : item->end; - } - } + } /* end else */ + } /* end if */ else { /* Update the size of the before region */ if(b_item->end < end) b_item->end = end; - } + } /* end else */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -336,20 +311,13 @@ H5FD__core_destroy_dirty_list(H5FD_core_t *file) if(file->dirty_list) { H5FD_core_region_t *region = NULL; -#ifdef DER -{ -size_t count = H5SL_count(file->dirty_list); -if(count != 0) - fprintf(stderr, "LIST NOT EMPTY AT DESTROY\n"); -} -#endif while(NULL != (region = (H5FD_core_region_t *)H5SL_remove_first(file->dirty_list))) region = H5FL_FREE(H5FD_core_region_t, region); if(H5SL_close(file->dirty_list) < 0) HGOTO_ERROR(H5E_SLIST, H5E_CLOSEERROR, FAIL, "can't close core vfd dirty list") file->dirty_list = NULL; - } + } /* end if */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -394,14 +362,8 @@ H5FD__core_write_to_bstore(H5FD_core_t *file, haddr_t addr, size_t size) else bytes_in = (h5_posix_io_t)size; -#ifdef DER -fprintf(stderr, "\nNEW\n"); -#endif do { bytes_wrote = HDwrite(file->fd, ptr, bytes_in); -#ifdef DER -fprintf(stderr, "bytes wrote: %lu\n", bytes_wrote); -#endif } while(-1 == bytes_wrote && EINTR == errno); if(-1 == bytes_wrote) { /* error */ @@ -844,9 +806,6 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr if(use_write_tracking) { if(NULL == (file->dirty_list = H5SL_create(H5SL_TYPE_HADDR, NULL))) HGOTO_ERROR(H5E_SLIST, H5E_CANTCREATE, NULL, "can't create core vfd dirty region list"); -#ifdef DER -fprintf(stderr, "\n"); -#endif } /* end if */ } /* end if */ @@ -1350,9 +1309,6 @@ H5FD__core_flush(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, hbool_t H5_ATTR_UN H5FD_core_region_t *item = NULL; size_t size; -#ifdef DER - fprintf(stderr, "FLUSHING. DIRTY LIST:\n"); -#endif while(NULL != (item = (H5FD_core_region_t *)H5SL_remove_first(file->dirty_list))) { /* The file may have been truncated, so check for that @@ -1362,11 +1318,8 @@ H5FD__core_flush(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, hbool_t H5_ATTR_UN if(item->end >= file->eof) item->end = file->eof - 1; - size = (size_t)((item->end - item->start) + 1); -#ifdef DER -fprintf(stderr, "(%llu, %llu : %lu)\n", item->start, item->end, size); -#endif + if(H5FD__core_write_to_bstore(file, item->start, size) != SUCCEED) HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "unable to write to backing store") } /* end if */ @@ -1374,13 +1327,6 @@ fprintf(stderr, "(%llu, %llu : %lu)\n", item->start, item->end, size); item = H5FL_FREE(H5FD_core_region_t, item); } /* end while */ -#ifdef DER -fprintf(stderr, "EOF: %llu\n", file->eof); -fprintf(stderr, "EOA: %llu\n", file->eoa); -if(file->eoa > file->eof) - fprintf(stderr, "*** EOA BADNESS ***\n"); -fprintf(stderr, "\n"); -#endif } /* end if */ /* Otherwise, write the entire file out at once */ else { @@ -1504,9 +1450,6 @@ H5FD__core_truncate(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, hbool_t closing HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to extend file properly") #endif /* H5_HAVE_WIN32_API */ -#ifdef DER -fprintf(stderr, "OLD: Truncated to: %llu\n", file->eoa); -#endif } /* end if */ /* Update the eof value */ diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c index 3b38836..7ec8751 100644 --- a/src/H5FDfamily.c +++ b/src/H5FDfamily.c @@ -46,10 +46,8 @@ #include "H5MMprivate.h" /* Memory management */ #include "H5Pprivate.h" /* Property lists */ -#undef MAX -#define MAX(X,Y) ((X)>(Y)?(X):(Y)) -#undef MIN -#define MIN(X,Y) ((X)<(Y)?(X):(Y)) +/* The size of the member name buffers */ +#define H5FD_FAM_MEMB_NAME_BUF_SIZE 4096 /* The driver identification number, initialized at runtime */ static hid_t H5FD_FAMILY_g = 0; @@ -623,11 +621,11 @@ static H5FD_t * H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) { - H5FD_family_t *file=NULL; - H5FD_t *ret_value=NULL; - char memb_name[4096], temp[4096]; - hsize_t eof=HADDR_UNDEF; + H5FD_family_t *file = NULL; + char *memb_name = NULL, *temp = NULL; + hsize_t eof = HADDR_UNDEF; unsigned t_flags = flags & ~H5F_ACC_CREAT; + H5FD_t *ret_value = NULL; FUNC_ENTER_NOAPI_NOINIT @@ -683,15 +681,21 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id, file->name = H5MM_strdup(name); file->flags = flags; + /* Allocate space for the string buffers */ + if(NULL == (memb_name = (char *)H5MM_malloc(H5FD_FAM_MEMB_NAME_BUF_SIZE))) + HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "unable to allocate member name") + if(NULL == (temp = (char *)H5MM_malloc(H5FD_FAM_MEMB_NAME_BUF_SIZE))) + HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "unable to allocate temporary member name") + /* Check that names are unique */ - HDsnprintf(memb_name, sizeof(memb_name), name, 0); - HDsnprintf(temp, sizeof(temp), name, 1); + HDsnprintf(memb_name, H5FD_FAM_MEMB_NAME_BUF_SIZE, name, 0); + HDsnprintf(temp, H5FD_FAM_MEMB_NAME_BUF_SIZE, name, 1); if(!HDstrcmp(memb_name, temp)) HGOTO_ERROR(H5E_FILE, H5E_FILEEXISTS, NULL, "file names not unique") /* Open all the family members */ while(1) { - HDsnprintf(memb_name, sizeof(memb_name), name, file->nmembs); + HDsnprintf(memb_name, H5FD_FAM_MEMB_NAME_BUF_SIZE, name, file->nmembs); /* Enlarge member array */ if(file->nmembs >= file->amembs) { @@ -732,6 +736,12 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id, ret_value=(H5FD_t *)file; done: + /* Release resources */ + if(memb_name) + H5MM_xfree(memb_name); + if(temp) + H5MM_xfree(temp); + /* Cleanup and fail */ if(ret_value == NULL && file != NULL) { unsigned nerrors = 0; /* Number of errors closing member files */ @@ -941,12 +951,16 @@ H5FD_family_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t abs_eoa) { H5FD_family_t *file = (H5FD_family_t*)_file; haddr_t addr = abs_eoa; - char memb_name[4096]; + char *memb_name = NULL; unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT + /* Allocate space for the member name buffer */ + if(NULL == (memb_name = (char *)H5MM_malloc(H5FD_FAM_MEMB_NAME_BUF_SIZE))) + HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "unable to allocate member name") + for(u = 0; addr || u < file->nmembs; u++) { /* Enlarge member array */ @@ -964,7 +978,7 @@ H5FD_family_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t abs_eoa) /* Create another file if necessary */ if(u >= file->nmembs || !file->memb[u]) { file->nmembs = MAX(file->nmembs, u+1); - HDsnprintf(memb_name, sizeof(memb_name), file->name, u); + HDsnprintf(memb_name, H5FD_FAM_MEMB_NAME_BUF_SIZE, file->name, u); H5E_BEGIN_TRY { H5_CHECK_OVERFLOW(file->memb_size, hsize_t, haddr_t); file->memb[u] = H5FDopen(memb_name, file->flags | H5F_ACC_CREAT, @@ -992,6 +1006,10 @@ H5FD_family_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t abs_eoa) file->eoa = abs_eoa; done: + /* Release resources */ + if(memb_name) + H5MM_xfree(memb_name); + FUNC_LEAVE_NOAPI(ret_value) } diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c index 0e49813..d0dfab3 100644 --- a/src/H5FDmulti.c +++ b/src/H5FDmulti.c @@ -44,16 +44,22 @@ #endif /* Loop through all mapped files */ -#define UNIQUE_MEMBERS(MAP,LOOPVAR) { \ - H5FD_mem_t _unmapped, LOOPVAR; \ - unsigned _seen[H5FD_MEM_NTYPES]; \ +#define UNIQUE_MEMBERS_CORE(MAP, ITER, SEEN, LOOPVAR) { \ + H5FD_mem_t ITER, LOOPVAR; \ + unsigned SEEN[H5FD_MEM_NTYPES]; \ \ - memset(_seen, 0, sizeof _seen); \ - for (_unmapped=H5FD_MEM_SUPER; _unmapped<H5FD_MEM_NTYPES; _unmapped=(H5FD_mem_t)(_unmapped+1)) { \ - LOOPVAR = MAP[_unmapped]; \ - if (H5FD_MEM_DEFAULT==LOOPVAR) LOOPVAR=_unmapped; \ + memset(SEEN, 0, sizeof SEEN); \ + for (ITER=H5FD_MEM_SUPER; ITER<H5FD_MEM_NTYPES; ITER=(H5FD_mem_t)(ITER+1)) { \ + LOOPVAR = MAP[ITER]; \ + if (H5FD_MEM_DEFAULT==LOOPVAR) LOOPVAR=ITER; \ assert(LOOPVAR>0 && LOOPVAR<H5FD_MEM_NTYPES); \ - if (_seen[LOOPVAR]++) continue; \ + if (SEEN[LOOPVAR]++) continue; \ + +/* Need two front-ends, since they are nested sometimes */ +#define UNIQUE_MEMBERS(MAP, LOOPVAR) \ + UNIQUE_MEMBERS_CORE(MAP, _unmapped, _seen, LOOPVAR) +#define UNIQUE_MEMBERS2(MAP, LOOPVAR) \ + UNIQUE_MEMBERS_CORE(MAP, _unmapped2, _seen2, LOOPVAR) #define ALL_MEMBERS(LOOPVAR) { \ H5FD_mem_t LOOPVAR; \ @@ -1904,7 +1910,7 @@ compute_next(H5FD_multi_t *file) } END_MEMBERS; UNIQUE_MEMBERS(file->fa.memb_map, mt1) { - UNIQUE_MEMBERS(file->fa.memb_map, mt2) { + UNIQUE_MEMBERS2(file->fa.memb_map, mt2) { if (file->fa.memb_addr[mt1]<file->fa.memb_addr[mt2] && (HADDR_UNDEF==file->memb_next[mt1] || file->memb_next[mt1]>file->fa.memb_addr[mt2])) { @@ -293,7 +293,7 @@ H5FL_reg_init(H5FL_reg_head_t *head) H5FL_reg_gc_head.first=new_node; /* Indicate that the free list is initialized */ - head->init=1; + head->init = TRUE; /* Make certain that the space allocated is large enough to store a free list pointer (eventually) */ if(head->size<sizeof(H5FL_reg_node_t)) @@ -655,7 +655,7 @@ printf("%s: head->name = %s, head->allocated = %d\n", FUNC, H5FL_reg_gc_head.fir /* No allocations left open for list, get rid of it */ else { /* Reset the "initialized" flag, in case we restart this list somehow (I don't know how..) */ - H5FL_reg_gc_head.first->list->init = 0; + H5FL_reg_gc_head.first->list->init = FALSE; /* Free the node from the garbage collection list */ H5MM_xfree(H5FL_reg_gc_head.first); @@ -822,7 +822,7 @@ H5FL_blk_init(H5FL_blk_head_t *head) H5FL_blk_gc_head.first=new_node; /* Indicate that the PQ is initialized */ - head->init=1; + head->init = TRUE; done: FUNC_LEAVE_NOAPI(ret_value) @@ -1326,7 +1326,7 @@ printf("%s: head->name = %s, head->allocated = %d\n", FUNC, H5FL_blk_gc_head.fir /* No allocations left open for list, get rid of it */ else { /* Reset the "initialized" flag, in case we restart this list somehow (I don't know how..) */ - H5FL_blk_gc_head.first->pq->init = 0; + H5FL_blk_gc_head.first->pq->init = FALSE; /* Free the node from the garbage collection list */ H5MM_free(H5FL_blk_gc_head.first); @@ -1379,7 +1379,7 @@ H5FL_arr_init(H5FL_arr_head_t *head) H5FL_arr_gc_head.first=new_node; /* Allocate room for the free lists */ - if(NULL == (head->list_arr = (H5FL_arr_node_t *)H5MM_calloc((size_t)head->maxelem*sizeof(H5FL_arr_node_t)))) + if(NULL == (head->list_arr = (H5FL_arr_node_t *)H5MM_calloc((size_t)head->maxelem * sizeof(H5FL_arr_node_t)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Initialize the size of each array */ @@ -1387,7 +1387,7 @@ H5FL_arr_init(H5FL_arr_head_t *head) head->list_arr[u].size = head->base_size + (head->elem_size * u); /* Indicate that the free list is initialized */ - head->init = 1; + head->init = TRUE; done: FUNC_LEAVE_NOAPI(ret_value) @@ -1795,7 +1795,7 @@ printf("%s: head->name = %s, head->allocated = %d\n", FUNC, H5FL_arr_gc_head.fir H5MM_xfree(H5FL_arr_gc_head.first->list->list_arr); /* Reset the "initialized" flag, in case we restart this list somehow (I don't know how..) */ - H5FL_arr_gc_head.first->list->init = 0; + H5FL_arr_gc_head.first->list->init = FALSE; /* Free the node from the garbage collection list */ H5MM_free(H5FL_arr_gc_head.first); @@ -2007,7 +2007,7 @@ H5FL_fac_init(size_t size) #endif /* H5FL_TRACK */ /* Indicate that the free list is initialized */ - factory->init = 1; + factory->init = TRUE; /* Set return value */ ret_value = factory; @@ -2417,7 +2417,7 @@ printf("%s: head->size = %d, head->allocated = %d\n", FUNC, (int)H5FL_fac_gc_hea HDassert(H5FL_fac_gc_head.first->list->allocated == 0); /* Reset the "initialized" flag, in case we restart this list somehow (I don't know how..) */ - H5FL_fac_gc_head.first->list->init = 0; + H5FL_fac_gc_head.first->list->init = FALSE; /* Free the node from the garbage collection list */ H5FL_fac_gc_head.first = H5FL_FREE(H5FL_fac_gc_node_t, H5FL_fac_gc_head.first); diff --git a/src/H5FLprivate.h b/src/H5FLprivate.h index 3cd30a6..f44d359 100644 --- a/src/H5FLprivate.h +++ b/src/H5FLprivate.h @@ -97,7 +97,7 @@ typedef struct H5FL_reg_node_t { /* Data structure for free list of blocks */ typedef struct H5FL_reg_head_t { - unsigned init; /* Whether the free list has been initialized */ + hbool_t init; /* Whether the free list has been initialized */ unsigned allocated; /* Number of blocks allocated */ unsigned onlist; /* Number of blocks on free list */ const char *name; /* Name of the type */ @@ -166,9 +166,9 @@ typedef struct H5FL_blk_node_t { /* Data structure for priority queue of native block free lists */ typedef struct H5FL_blk_head_t { - unsigned init; /* Whether the free list has been initialized */ - unsigned allocated; /* Number of blocks allocated */ - unsigned onlist; /* Number of blocks on free list */ + hbool_t init; /* Whether the free list has been initialized */ + unsigned allocated; /* Number of blocks allocated */ + unsigned onlist; /* Number of blocks on free list */ size_t list_mem; /* Amount of memory in block on free list */ const char *name; /* Name of the type */ H5FL_blk_node_t *head; /* Pointer to first free list in queue */ @@ -237,7 +237,7 @@ typedef struct H5FL_arr_node_t { /* Data structure for free list of array blocks */ typedef struct H5FL_arr_head_t { - unsigned init; /* Whether the free list has been initialized */ + hbool_t init; /* Whether the free list has been initialized */ unsigned allocated; /* Number of blocks allocated */ size_t list_mem; /* Amount of memory in block on free list */ const char *name; /* Name of the type */ @@ -354,7 +354,7 @@ typedef struct H5FL_fac_node_t H5FL_fac_node_t; /* Data structure for free list block factory */ typedef struct H5FL_fac_head_t { - unsigned init; /* Whether the free list has been initialized */ + hbool_t init; /* Whether the free list has been initialized */ unsigned allocated; /* Number of blocks allocated */ unsigned onlist; /* Number of blocks on free list */ size_t size; /* Size of the blocks in the list */ @@ -606,7 +606,7 @@ H5FS__new(const H5F_t *f, uint16_t nclasses, const H5FS_section_class_t *classes HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for free space free list") /* Set immutable free list parameters */ - H5_CHECKED_ASSIGN(fspace->nclasses, unsigned, nclasses, size_t); + H5_CHECKED_ASSIGN(fspace->nclasses, uint16_t, nclasses, size_t); if(nclasses > 0) { if(NULL == (fspace->sect_cls = H5FL_SEQ_MALLOC(H5FS_section_class_t, nclasses))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for free space section class array") diff --git a/src/H5FSpkg.h b/src/H5FSpkg.h index eafe3c2..7e52b5f 100644 --- a/src/H5FSpkg.h +++ b/src/H5FSpkg.h @@ -65,18 +65,18 @@ \ /* Free space header specific fields */ \ + 1 /* Client ID */ \ - + H5F_SIZEOF_SIZE(f) /* Total free space tracked */ \ - + H5F_SIZEOF_SIZE(f) /* Total # of sections tracked */ \ - + H5F_SIZEOF_SIZE(f) /* # of serializable sections tracked */ \ - + H5F_SIZEOF_SIZE(f) /* # of ghost sections tracked */ \ + + (unsigned)H5F_SIZEOF_SIZE(f) /* Total free space tracked */ \ + + (unsigned)H5F_SIZEOF_SIZE(f) /* Total # of sections tracked */ \ + + (unsigned)H5F_SIZEOF_SIZE(f) /* # of serializable sections tracked */ \ + + (unsigned)H5F_SIZEOF_SIZE(f) /* # of ghost sections tracked */ \ + 2 /* Number of section classes */ \ + 2 /* Shrink percent */ \ + 2 /* Expand percent */ \ + 2 /* Size of address space for sections (log2 of value) */ \ - + H5F_SIZEOF_SIZE(f) /* Max. size of section to track */ \ - + H5F_SIZEOF_ADDR(f) /* Address of serialized free space sections */ \ - + H5F_SIZEOF_SIZE(f) /* Size of serialized free space sections used */ \ - + H5F_SIZEOF_SIZE(f) /* Allocated size of serialized free space sections */ \ + + (unsigned)H5F_SIZEOF_SIZE(f) /* Max. size of section to track */ \ + + (unsigned)H5F_SIZEOF_ADDR(f) /* Address of serialized free space sections */ \ + + (unsigned)H5F_SIZEOF_SIZE(f) /* Size of serialized free space sections used */ \ + + (unsigned)H5F_SIZEOF_SIZE(f) /* Allocated size of serialized free space sections */ \ ) /* Size of the free space serialized sections on disk */ @@ -85,7 +85,7 @@ H5FS_METADATA_PREFIX_SIZE \ \ /* Free space serialized sections specific fields */ \ - + H5F_SIZEOF_ADDR(f) /* Address of free space header for these sections */ \ + + (unsigned)H5F_SIZEOF_ADDR(f) /* Address of free space header for these sections */ \ ) diff --git a/src/H5FSsection.c b/src/H5FSsection.c index 5638f4f..4697bd50 100644 --- a/src/H5FSsection.c +++ b/src/H5FSsection.c @@ -144,7 +144,7 @@ HDfprintf(stderr, "%s: fspace->addr = %a\n", FUNC, fspace->addr); /* Set non-zero values */ sinfo->nbins = H5VM_log2_gen(fspace->max_sect_size); - sinfo->sect_prefix_size = (size_t)H5FS_SINFO_PREFIX_SIZE(f); + sinfo->sect_prefix_size = H5FS_SINFO_PREFIX_SIZE(f); sinfo->sect_off_size = (fspace->max_sect_addr + 7) / 8; sinfo->sect_len_size = H5VM_limit_enc_size((uint64_t)fspace->max_sect_size); #ifdef H5FS_SINFO_DEBUG diff --git a/src/H5FSstat.c b/src/H5FSstat.c index d2c0177..3200849 100644 --- a/src/H5FSstat.c +++ b/src/H5FSstat.c @@ -96,7 +96,7 @@ H5FS_stat_info(const H5F_t *f, const H5FS_t *frsp, H5FS_stat_t *stats) stats->serial_sect_count = frsp->serial_sect_count; stats->ghost_sect_count = frsp->ghost_sect_count; stats->addr = frsp->addr; - stats->hdr_size = (size_t)H5FS_HEADER_SIZE(f); + stats->hdr_size = (hsize_t)H5FS_HEADER_SIZE(f); stats->sect_addr = frsp->sect_addr; stats->alloc_sect_size = frsp->alloc_sect_size; stats->sect_size = frsp->sect_size; diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index e3b5547..40e5ff2 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -411,7 +411,7 @@ #endif #if (H5_SIZEOF_HSIZE_T >= H5_SIZEOF_OFF_T) # define H5F_OVERFLOW_HSIZET2OFFT(X) \ - ((hsize_t)(X)>=(hsize_t)((hsize_t)1<<(8*sizeof(HDoff_t)-1))) + ((hsize_t)(X) >= (hsize_t)((hsize_t)1 << (8 * sizeof(HDoff_t) - 1))) #else # define H5F_OVERFLOW_HSIZET2OFFT(X) 0 #endif @@ -735,3 +735,71 @@ done: FUNC_LEAVE_API(ret_value) } /* end H5Gclose() */ + +/*------------------------------------------------------------------------- + * Function: H5Gflush + * + * Purpose: Flushes all buffers associated with a group to disk. + * + * Return: Non-negative on success, negative on failure + * + * Programmer: Mike McGreevy + * May 19, 2010 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Gflush(hid_t group_id) +{ + H5G_t *grp; /* Dataset for this operation */ + herr_t ret_value = SUCCEED; /* return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "i", group_id); + + /* Check args */ + if(NULL == (grp = (H5G_t *)H5I_object_verify(group_id, H5I_GROUP))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group") + + /* Flush object's metadata to file */ + if(H5O_flush_common(&grp->oloc, group_id, H5AC_ind_read_dxpl_id) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTFLUSH, FAIL, "unable to flush group and object flush callback") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Gflush */ + + +/*------------------------------------------------------------------------- + * Function: H5Grefresh + * + * Purpose: Refreshes all buffers associated with a dataset. + * + * Return: Non-negative on success, negative on failure + * + * Programmer: Mike McGreevy + * July 21, 2010 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Grefresh(hid_t group_id) +{ + H5G_t * grp = NULL; + herr_t ret_value = SUCCEED; /* return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "i", group_id); + + /* Check args */ + if(NULL == (grp = (H5G_t *)H5I_object_verify(group_id, H5I_GROUP))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a group") + + /* Call private function to refresh group object */ + if ((H5O_refresh_metadata(group_id, grp->oloc, H5AC_ind_read_dxpl_id)) < 0) + HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, FAIL, "unable to refresh group") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Grefresh */ + diff --git a/src/H5Gnode.c b/src/H5Gnode.c index 4d299dc..89d1df8 100644 --- a/src/H5Gnode.c +++ b/src/H5Gnode.c @@ -715,7 +715,7 @@ H5G_node_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, md_key->offset = ent.name_off; } /* end if */ else { - idx -= H5F_SYM_LEAF_K(f); + idx -= (int)H5F_SYM_LEAF_K(f); insert_into = snrt; if(idx == (int)H5F_SYM_LEAF_K(f)) { rt_key->offset = ent.name_off; diff --git a/src/H5Gpkg.h b/src/H5Gpkg.h index 4cb6f9b..c994da3 100644 --- a/src/H5Gpkg.h +++ b/src/H5Gpkg.h @@ -55,7 +55,7 @@ + 2 /* Number of symbols */ \ \ /* Entries */ \ - + ((2 * H5F_SYM_LEAF_K(f)) * H5G_SIZEOF_ENTRY_FILE(f)) \ + + ((2 * H5F_SYM_LEAF_K(f)) * (unsigned)H5G_SIZEOF_ENTRY_FILE(f)) \ ) diff --git a/src/H5Gpublic.h b/src/H5Gpublic.h index 5b8b054..9d8ade5 100644 --- a/src/H5Gpublic.h +++ b/src/H5Gpublic.h @@ -84,6 +84,8 @@ H5_DLL herr_t H5Gget_info_by_idx(hid_t loc_id, const char *group_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, H5G_info_t *ginfo, hid_t lapl_id); H5_DLL herr_t H5Gclose(hid_t group_id); +H5_DLL herr_t H5Gflush(hid_t group_id); +H5_DLL herr_t H5Grefresh(hid_t group_id); /* Symbols defined for compatibility with previous versions of the HDF5 API. * diff --git a/src/H5HFcache.c b/src/H5HFcache.c index 759fff0..31ecc62 100644 --- a/src/H5HFcache.c +++ b/src/H5HFcache.c @@ -618,8 +618,8 @@ H5HF__cache_hdr_image_len(const void *_thing, size_t *image_len, *------------------------------------------------------------------------- */ static herr_t -H5HF__cache_hdr_pre_serialize(const H5F_t *f, hid_t dxpl_id, void *_thing, - haddr_t addr, size_t len, size_t H5_ATTR_UNUSED compressed_len, +H5HF__cache_hdr_pre_serialize(const H5F_t *f, hid_t H5_ATTR_UNUSED dxpl_id, + void *_thing, haddr_t addr, size_t len, size_t H5_ATTR_UNUSED compressed_len, haddr_t H5_ATTR_UNUSED *new_addr, size_t H5_ATTR_UNUSED *new_len, size_t H5_ATTR_UNUSED *new_compressed_len, unsigned *flags) { diff --git a/src/H5MFaggr.c b/src/H5MFaggr.c index f2c5936..c45b473 100644 --- a/src/H5MFaggr.c +++ b/src/H5MFaggr.c @@ -201,7 +201,7 @@ HDfprintf(stderr, "%s: aggr = {%a, %Hu, %Hu}\n", FUNC, aggr->addr, aggr->tot_siz alignment = 0; /* no alignment */ /* Generate fragment if aggregator is mis-aligned */ - if(alignment && aggr->addr > 0 && aggr->size > 0 && (aggr_mis_align = (aggr->addr + H5FD_get_base_addr(f->shared->lf)) % alignment)) { + if(alignment && aggr->addr > 0 && (aggr_mis_align = (aggr->addr + H5FD_get_base_addr(f->shared->lf)) % alignment)) { aggr_frag_addr = aggr->addr; aggr_frag_size = alignment - aggr_mis_align; } /* end if */ @@ -295,10 +295,26 @@ HDfprintf(stderr, "%s: Allocating block\n", FUNC); if(H5MF_xfree(f, alloc_type, dxpl_id, aggr->addr, aggr->size) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, HADDR_UNDEF, "can't free aggregation block") - /* Point the aggregator at the newly allocated block */ - aggr->addr = new_space; - aggr->size = aggr->alloc_size; - aggr->tot_size = aggr->alloc_size; + /* If the block is not to be aligned, fold the eoa fragment + * into the newly allocated aggregator, as it could have + * been allocated in an aligned manner if the aggregator + * block is larger than the threshold */ + if(eoa_frag_size && !alignment) { + HDassert(eoa_frag_addr + eoa_frag_size == new_space); + aggr->addr = eoa_frag_addr; + aggr->size = aggr->alloc_size + eoa_frag_size; + aggr->tot_size = aggr->size; + + /* Reset EOA fragment */ + eoa_frag_addr = HADDR_UNDEF; + eoa_frag_size = 0; + } /* end if */ + else { + /* Point the aggregator at the newly allocated block */ + aggr->addr = new_space; + aggr->size = aggr->alloc_size; + aggr->tot_size = aggr->alloc_size; + } } /* end else */ /* Allocate space out of the metadata block */ diff --git a/src/H5Oalloc.c b/src/H5Oalloc.c index 99f1322..69b4b11 100644 --- a/src/H5Oalloc.c +++ b/src/H5Oalloc.c @@ -763,7 +763,7 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size, size_t *new size_t idx; /* Message number */ uint8_t *p = NULL; /*ptr into new chunk */ H5O_cont_t *cont = NULL; /*native continuation message */ - size_t chunkno; /* Chunk allocated */ + unsigned chunkno; /* Chunk allocated */ haddr_t new_chunk_addr; unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ @@ -921,7 +921,8 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size, size_t *new oh->chunk = x; } /* end if */ - chunkno = (unsigned)oh->nchunks++; + H5_CHECKED_ASSIGN(chunkno, unsigned, oh->nchunks, size_t); + oh->nchunks++; oh->chunk[chunkno].addr = new_chunk_addr; oh->chunk[chunkno].size = size; oh->chunk[chunkno].gap = 0; diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 9cbcdc4..064c4cb 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -128,6 +128,9 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, unsigned H5_ATTR_UNUSED H5A_t *attr = NULL; H5S_extent_t *extent; /*extent dimensionality information */ size_t name_len; /*attribute name length */ + size_t dt_size; /* Datatype size */ + hssize_t sds_size; /* Signed Dataspace size */ + hsize_t ds_size; /* Dataspace size */ unsigned flags = 0; /* Attribute flags */ H5A_t *ret_value = NULL; /* Return value */ @@ -199,7 +202,7 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, unsigned H5_ATTR_UNUSED /* Decode attribute's dataspace extent */ if((extent = (H5S_extent_t *)(H5O_MSG_SDSPACE->decode)(f, dxpl_id, open_oh, - ((flags & H5O_ATTR_FLAG_SPACE_SHARED) ? H5O_MSG_FLAG_SHARED : 0), ioflags, p)) == NULL) + ((flags & H5O_ATTR_FLAG_SPACE_SHARED) ? H5O_MSG_FLAG_SHARED : 0), ioflags, p)) == NULL) HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL, "can't decode attribute dataspace") /* Copy the extent information to the dataspace */ @@ -217,8 +220,19 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, unsigned H5_ATTR_UNUSED else p += attr->shared->ds_size; + /* Get the datatype's size */ + if(0 == (dt_size = H5T_get_size(attr->shared->dt))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "unable to get datatype size") + + /* Get the datatype & dataspace sizes */ + if(0 == (dt_size = H5T_get_size(attr->shared->dt))) + HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "unable to get datatype size") + if((sds_size = H5S_GET_EXTENT_NPOINTS(attr->shared->ds)) < 0) + HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "unable to get dataspace size") + ds_size = (hsize_t)sds_size; + /* Compute the size of the data */ - H5_CHECKED_ASSIGN(attr->shared->data_size, size_t, H5S_GET_EXTENT_NPOINTS(attr->shared->ds) * H5T_get_size(attr->shared->dt), hsize_t); + H5_CHECKED_ASSIGN(attr->shared->data_size, size_t, ds_size * (hsize_t)dt_size, hsize_t); /* Go get the data */ if(attr->shared->data_size) { diff --git a/src/H5Ocache.c b/src/H5Ocache.c index e085242..3803978 100644 --- a/src/H5Ocache.c +++ b/src/H5Ocache.c @@ -770,7 +770,7 @@ H5O__cache_chk_deserialize(const void *image, size_t len, void *_udata, /* Set the fields for the chunk proxy */ chk_proxy->oh = udata->oh; - chk_proxy->chunkno = udata->oh->nchunks - 1; + H5_CHECKED_ASSIGN(chk_proxy->chunkno, unsigned, udata->oh->nchunks - 1, size_t); } /* end if */ else { /* Sanity check */ @@ -1162,6 +1162,10 @@ H5O__chunk_deserialize(H5O_t *oh, haddr_t addr, size_t len, const uint8_t *image HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "bad flag combination for message") if((flags & H5O_MSG_FLAG_WAS_UNKNOWN) && !(flags & H5O_MSG_FLAG_MARK_IF_UNKNOWN)) HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "bad flag combination for message") + if((flags & H5O_MSG_FLAG_SHAREABLE) + && H5O_msg_class_g[id] + && !(H5O_msg_class_g[id]->share_flags & H5O_SHARE_IS_SHARABLE)) + HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "message of unsharable class flagged as sharable") /* Reserved bytes/creation index */ if(oh->version == H5O_VERSION_1) @@ -1320,7 +1324,7 @@ H5O__chunk_deserialize(H5O_t *oh, haddr_t addr, size_t len, const uint8_t *image /* Decode continuation message */ cont = (H5O_cont_t *)(H5O_MSG_CONT->decode)(udata->f, udata->dxpl_id, NULL, 0, &ioflags, oh->mesg[curmesg].raw); - cont->chunkno = udata->cont_msg_info->nmsgs + 1; /*the next continuation message/chunk */ + H5_CHECKED_ASSIGN(cont->chunkno, unsigned, udata->cont_msg_info->nmsgs + 1, size_t); /* the next continuation message/chunk */ /* Save 'native' form of continuation message */ oh->mesg[curmesg].native = cont; diff --git a/src/H5Oflush.c b/src/H5Oflush.c index 6484dfd..4fc9c8e 100644 --- a/src/H5Oflush.c +++ b/src/H5Oflush.c @@ -177,6 +177,39 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5O_oh_tag() */ + +/*------------------------------------------------------------------------- + * Function: H5Orefresh + * + * Purpose: Refreshes all buffers associated with an object. + * + * Return: Non-negative on success, negative on failure + * + * Programmer: Mike McGreevy + * July 28, 2010 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Orefresh(hid_t oid) +{ + H5O_loc_t *oloc; /* object location */ + herr_t ret_value = SUCCEED; /* return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "i", oid); + + /* Check args */ + if(NULL == (oloc = H5O_get_loc(oid))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an object") + + /* Private function */ + if(H5O_refresh_metadata(oid, *oloc, H5AC_ind_read_dxpl_id) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unable to refresh object") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5Orefresh() */ /*------------------------------------------------------------------------- diff --git a/src/H5Opkg.h b/src/H5Opkg.h index 14bb342..e40d28a 100644 --- a/src/H5Opkg.h +++ b/src/H5Opkg.h @@ -201,6 +201,7 @@ \ /* Set the message's "shared info", if it's shareable */ \ if((MSG)->flags & H5O_MSG_FLAG_SHAREABLE) { \ + HDassert(msg_type->share_flags & H5O_SHARE_IS_SHARABLE); \ H5O_UPDATE_SHARED((H5O_shared_t *)(MSG)->native, H5O_SHARE_TYPE_HERE, (F), msg_type->id, (MSG)->crt_idx, (OH)->chunk[0].addr) \ } /* end if */ \ \ diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index 44b4998..0acac8c 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -349,7 +349,7 @@ typedef struct H5O_link_t { typedef struct H5O_efl_entry_t { size_t name_offset; /*offset of name within heap */ char *name; /*malloc'd name */ - off_t offset; /*offset of data within file */ + HDoff_t offset; /*offset of data within file */ hsize_t size; /*size allocated within file */ } H5O_efl_entry_t; diff --git a/src/H5Opublic.h b/src/H5Opublic.h index 1d2ab7b..dec7b5b 100644 --- a/src/H5Opublic.h +++ b/src/H5Opublic.h @@ -183,6 +183,7 @@ H5_DLL herr_t H5Ovisit_by_name(hid_t loc_id, const char *obj_name, void *op_data, hid_t lapl_id); H5_DLL herr_t H5Oclose(hid_t object_id); H5_DLL herr_t H5Oflush(hid_t obj_id); +H5_DLL herr_t H5Orefresh(hid_t oid); H5_DLL herr_t H5Odisable_mdc_flushes(hid_t object_id); H5_DLL herr_t H5Oenable_mdc_flushes(hid_t object_id); H5_DLL herr_t H5Oare_mdc_flushes_disabled(hid_t object_id, hbool_t *are_disabled); @@ -36,7 +36,7 @@ #define H5PL_MAX_PATH_NUM 16 /****************************/ -/* Macros for supporting +/* Macros for supporting * both Windows and Unix */ /****************************/ /* Windows support @@ -70,6 +70,9 @@ /* Clear error - nothing to do */ #define H5PL_CLR_ERROR +/* maximum size for expanding env vars */ +#define H5PL_EXPAND_BUFFER_SIZE 32767 + typedef const void *(__cdecl *H5PL_get_plugin_info_t)(void); /* Unix support */ @@ -207,7 +210,7 @@ int H5PL_term_package(void) { int n = 0; - + FUNC_ENTER_NOAPI_NOINIT_NOERR if(H5_PKG_INIT_VAR) { @@ -363,12 +366,12 @@ H5PL_load(H5PL_type_t type, int id) /* If not found, iterate through the path table to find the right dynamic library */ if(!found) { - size_t i; /* Local index variable */ + size_t i; /* Local index variable */ for(i = 0; i < H5PL_num_paths_g; i++) { if((found = H5PL__find(type, id, H5PL_path_table_g[i], &plugin_info)) < 0) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, NULL, "search in paths failed") - + /* Break out if found */ if(found) { HDassert(plugin_info); @@ -419,6 +422,26 @@ H5PL__init_path_table(void) if(NULL == dl_path) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") +#ifdef H5_HAVE_WIN32_API + else { /* Expand windows env var*/ + long bufCharCount; + char *tempbuf; + if(NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") + if((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { + tempbuf = (char *)H5MM_xfree(tempbuf); + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") + } + if(bufCharCount == 0) { + tempbuf = (char *)H5MM_xfree(tempbuf); + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") + } + dl_path = (char *)H5MM_xfree(dl_path); + dl_path = H5MM_strdup(tempbuf); + tempbuf = (char *)H5MM_xfree(tempbuf); + } +#endif /* H5_HAVE_WIN32_API */ + /* Put paths in the path table. They are separated by ":" */ dir = HDstrtok(dl_path, H5PL_PATH_SEPARATOR); while(dir) { @@ -445,11 +468,11 @@ done: * Function: H5PL__find * * Purpose: Given a path, this function opens the directory and envokes - * another function to go through all files to find the right - * plugin library. Two function definitions are for Unix and + * another function to go through all files to find the right + * plugin library. Two function definitions are for Unix and * Windows. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * negative on failure * @@ -469,17 +492,17 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info) FUNC_ENTER_STATIC - /* Open the directory */ + /* Open the directory */ if(!(dirp = HDopendir(dir))) - HGOTO_ERROR(H5E_PLUGIN, H5E_OPENERROR, FAIL, "can't open directory") + HGOTO_ERROR(H5E_PLUGIN, H5E_OPENERROR, FAIL, "can't open directory: %s", dir) /* Iterates through all entries in the directory to find the right plugin library */ while(NULL != (dp = HDreaddir(dirp))) { - /* The library we are looking for should be called libxxx.so... on Unix + /* The library we are looking for should be called libxxx.so... on Unix * or libxxx.xxx.dylib on Mac. - */ + */ #ifndef __CYGWIN__ - if(!HDstrncmp(dp->d_name, "lib", (size_t)3) && + if(!HDstrncmp(dp->d_name, "lib", (size_t)3) && (HDstrstr(dp->d_name, ".so") || HDstrstr(dp->d_name, ".dylib"))) { #else if(!HDstrncmp(dp->d_name, "cyg", (size_t)3) && @@ -500,29 +523,24 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info) if(HDstat(pathname, &my_stat) == -1) HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't stat file: %s", HDstrerror(errno)) - /* If it is a directory, skip it */ + /* If it is a directory, skip it */ if(S_ISDIR(my_stat.st_mode)) continue; /* Attempt to open the dynamic library as a filter library */ if((found_in_dir = H5PL__open(plugin_type, pathname, type_id, info)) < 0) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in directory failed") - if(found_in_dir) { - /* Indicate success */ - HGOTO_DONE(TRUE) - } /* end if */ - else - HDassert(pathname); - pathname = (char *)H5MM_xfree(pathname); + if(found_in_dir) + HGOTO_DONE(TRUE) /* Indicate success */ + pathname = (char *)H5MM_xfree(pathname); } /* end if */ } /* end while */ done: - if(dirp) + if(dirp) if(HDclosedir(dirp) < 0) HDONE_ERROR(H5E_FILE, H5E_CLOSEERROR, FAIL, "can't close directory: %s", HDstrerror(errno)) - if(pathname) - pathname = (char *)H5MM_xfree(pathname); + pathname = (char *)H5MM_xfree(pathname); FUNC_LEAVE_NOAPI(ret_value) } /* end H5PL__find() */ @@ -563,20 +581,16 @@ H5PL__find(H5PL_type_t plugin_type, int type_id, char *dir, const void **info) if((found_in_dir = H5PL__open(plugin_type, pathname, type_id, info)) < 0) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "search in directory failed") - if(found_in_dir) { - /* Indicate success */ - HGOTO_DONE(TRUE) - } /* end if */ - else - HDassert(pathname); - pathname = (char *)H5MM_xfree(pathname); + if(found_in_dir) + HGOTO_DONE(TRUE) /* Indicate success */ + pathname = (char *)H5MM_xfree(pathname); } /* end if */ } while(FindNextFileA(hFind, &fdFile)); /* Find the next file. */ done: - if(hFind) + if(hFind) FindClose(hFind); - if(pathname) + if(pathname) pathname = (char *)H5MM_xfree(pathname); FUNC_LEAVE_NOAPI(ret_value) @@ -588,10 +602,10 @@ done: * Function: H5PL__open * * Purpose: Iterates through all files to find the right plugin library. - * It loads the dynamic plugin library and keeps it on the list + * It loads the dynamic plugin library and keeps it on the list * of loaded libraries. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * negative on failure * @@ -657,7 +671,7 @@ H5PL__open(H5PL_type_t pl_type, char *libname, int pl_id, const void **pl_info) /* Set the plugin info to return */ *pl_info = (const void *)plugin_info; - + /* Indicate success */ ret_value = TRUE; } /* end if */ @@ -678,7 +692,7 @@ done: * Purpose: Search in the list of already opened dynamic libraries * to see if the one we are looking for is already opened. * - * Return: TRUE on success, + * Return: TRUE on success, * FALSE on not found, * Negative on failure * @@ -723,7 +737,7 @@ done: /*------------------------------------------------------------------------- * Function: H5PL__close * - * Purpose: Closes the handle for dynamic library + * Purpose: Closes the handle for dynamic library * * Return: Non-negative on success/Negative on failure * @@ -738,7 +752,7 @@ H5PL__close(H5PL_HANDLE handle) FUNC_ENTER_STATIC_NOERR H5PL_CLOSE_LIB(handle); - + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5PL__close() */ diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c index 62d674c..d96bd54 100644 --- a/src/H5Pfapl.c +++ b/src/H5Pfapl.c @@ -790,7 +790,7 @@ done: const void * H5P_peek_driver_info(H5P_genplist_t *plist) { - void *ret_value = NULL; /* Return value */ + const void *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI(NULL) diff --git a/src/H5Shyper.c b/src/H5Shyper.c index fe013a7..5231c6e 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -145,6 +145,9 @@ H5FL_DEFINE_STATIC(H5S_hyper_span_t); /* Declare a free list to manage the H5S_hyper_span_info_t struct */ H5FL_DEFINE_STATIC(H5S_hyper_span_info_t); +/* Declare extern free list to manage the H5S_sel_iter_t struct */ +H5FL_EXTERN(H5S_sel_iter_t); + /* #define H5S_HYPER_DEBUG */ #ifdef H5S_HYPER_DEBUG static herr_t @@ -9288,7 +9291,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, size_t ss_nelem; /* Number of elements for src_space */ size_t ss_i = (size_t)0; /* Index into offset/length arrays for src_space */ hbool_t advance_ss = FALSE; /* Whether to advance ss_i on the next iteration */ - H5S_sel_iter_t ss_iter; /* Selection iterator for src_space */ + H5S_sel_iter_t *ss_iter = NULL; /* Selection iterator for src_space */ hbool_t ss_iter_init = FALSE; /* Whether ss_iter is initialized */ hsize_t ss_sel_off = (hsize_t)0; /* Offset within src_space selection */ hsize_t ds_off[H5S_PROJECT_INTERSECT_NSEQS]; /* Offset array for dst_space */ @@ -9296,7 +9299,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, size_t ds_nseq; /* Number of sequences for dst_space */ size_t ds_nelem; /* Number of elements for dst_space */ size_t ds_i = (size_t)0; /* Index into offset/length arrays for dst_space */ - H5S_sel_iter_t ds_iter; /* Selection iterator for dst_space */ + H5S_sel_iter_t *ds_iter = NULL; /* Selection iterator for dst_space */ hbool_t ds_iter_init = FALSE; /* Whether ds_iter is initialized */ hsize_t ds_sel_off = (hsize_t)0; /* Offset within dst_space selection */ hsize_t sis_off[H5S_PROJECT_INTERSECT_NSEQS]; /* Offset array for src_intersect_space */ @@ -9305,7 +9308,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, size_t sis_nelem; /* Number of elements for src_intersect_space */ size_t sis_i = (size_t)0; /* Index into offset/length arrays for src_intersect_space */ hbool_t advance_sis = FALSE; /* Whether to advance sis_i on the next iteration */ - H5S_sel_iter_t sis_iter; /* Selection iterator for src_intersect_space */ + H5S_sel_iter_t *sis_iter = NULL; /* Selection iterator for src_intersect_space */ hbool_t sis_iter_init = FALSE; /* Whether sis_iter is initialized */ hsize_t int_sel_off; /* Offset within intersected selections (ss/sis and ds/ps) */ size_t int_len; /* Length of segment in intersected selections */ @@ -9384,35 +9387,47 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, /* Set unlim_dim */ proj_space->select.sel_info.hslab->unlim_dim = -1; + /* Allocate the source space iterator */ + if(NULL == (ss_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate source space iterator") + /* Initialize source space iterator */ - if(H5S_select_iter_init(&ss_iter, src_space, (size_t)1) < 0) + if(H5S_select_iter_init(ss_iter, src_space, (size_t)1) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") ss_iter_init = TRUE; /* Get sequence list for source space */ - if(H5S_SELECT_GET_SEQ_LIST(src_space, 0u, &ss_iter, H5S_PROJECT_INTERSECT_NSEQS, ss_nelem, &ss_nseq, &nelem, ss_off, ss_len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(src_space, 0u, ss_iter, H5S_PROJECT_INTERSECT_NSEQS, ss_nelem, &ss_nseq, &nelem, ss_off, ss_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") ss_nelem -= nelem; HDassert(ss_nseq > 0); + /* Allocate the destination space iterator */ + if(NULL == (ds_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate destination space iterator") + /* Initialize destination space iterator */ - if(H5S_select_iter_init(&ds_iter, dst_space, (size_t)1) < 0) + if(H5S_select_iter_init(ds_iter, dst_space, (size_t)1) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") ds_iter_init = TRUE; /* Get sequence list for destination space */ - if(H5S_SELECT_GET_SEQ_LIST(dst_space, 0u, &ds_iter, H5S_PROJECT_INTERSECT_NSEQS, ds_nelem, &ds_nseq, &nelem, ds_off, ds_len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(dst_space, 0u, ds_iter, H5S_PROJECT_INTERSECT_NSEQS, ds_nelem, &ds_nseq, &nelem, ds_off, ds_len) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") ds_nelem -= nelem; HDassert(ds_nseq > 0); + /* Allocate the source intersect space iterator */ + if(NULL == (sis_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate source intersect space iterator") + /* Initialize source intersect space iterator */ - if(H5S_select_iter_init(&sis_iter, src_intersect_space, (size_t)1) < 0) + if(H5S_select_iter_init(sis_iter, src_intersect_space, (size_t)1) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") sis_iter_init = TRUE; /* Get sequence list for source intersect space */ - if(H5S_SELECT_GET_SEQ_LIST(src_intersect_space, 0u, &sis_iter, H5S_PROJECT_INTERSECT_NSEQS, sis_nelem, &sis_nseq, &nelem, sis_off, sis_len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(src_intersect_space, 0u, sis_iter, H5S_PROJECT_INTERSECT_NSEQS, sis_nelem, &sis_nseq, &nelem, sis_off, sis_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") sis_nelem -= nelem; HDassert(sis_nseq > 0); @@ -9427,7 +9442,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, if(++ss_i == ss_nseq) { if(ss_nelem > 0) { /* Try to grab more sequences from src_space */ - if(H5S_SELECT_GET_SEQ_LIST(src_space, 0u, &ss_iter, H5S_PROJECT_INTERSECT_NSEQS, ss_nelem, &ss_nseq, &nelem, ss_off, ss_len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(src_space, 0u, ss_iter, H5S_PROJECT_INTERSECT_NSEQS, ss_nelem, &ss_nseq, &nelem, ss_off, ss_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") HDassert(ss_len[0] > 0); @@ -9459,7 +9474,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, if(sis_nelem > 0) { /* Try to grab more sequences from src_intersect_space */ - if(H5S_SELECT_GET_SEQ_LIST(src_intersect_space, 0u, &sis_iter, H5S_PROJECT_INTERSECT_NSEQS, sis_nelem, &sis_nseq, &nelem, sis_off, sis_len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(src_intersect_space, 0u, sis_iter, H5S_PROJECT_INTERSECT_NSEQS, sis_nelem, &sis_nseq, &nelem, sis_off, sis_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") HDassert(sis_len[0] > 0); @@ -9511,7 +9526,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, HDassert(ds_nelem > 0); /* Try to grab more sequences from dst_space */ - if(H5S_SELECT_GET_SEQ_LIST(dst_space, 0u, &ds_iter, H5S_PROJECT_INTERSECT_NSEQS, ds_nelem, &ds_nseq, &nelem, ds_off, ds_len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(dst_space, 0u, ds_iter, H5S_PROJECT_INTERSECT_NSEQS, ds_nelem, &ds_nseq, &nelem, ds_off, ds_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") HDassert(ds_len[0] > 0); @@ -9625,19 +9640,22 @@ loop_end: done: /* Release source selection iterator */ - if(ss_iter_init) - if(H5S_SELECT_ITER_RELEASE(&ss_iter) < 0) - HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + if(ss_iter_init && H5S_SELECT_ITER_RELEASE(ss_iter) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + if(ss_iter) + ss_iter = H5FL_FREE(H5S_sel_iter_t, ss_iter); /* Release destination selection iterator */ - if(ds_iter_init) - if(H5S_SELECT_ITER_RELEASE(&ds_iter) < 0) - HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + if(ds_iter_init && H5S_SELECT_ITER_RELEASE(ds_iter) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + if(ds_iter) + ds_iter = H5FL_FREE(H5S_sel_iter_t, ds_iter); /* Release source intersect selection iterator */ - if(sis_iter_init) - if(H5S_SELECT_ITER_RELEASE(&sis_iter) < 0) - HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + if(sis_iter_init && H5S_SELECT_ITER_RELEASE(sis_iter) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + if(sis_iter) + sis_iter = H5FL_FREE(H5S_sel_iter_t, sis_iter); /* Cleanup on error */ if(ret_value < 0) { diff --git a/src/H5Spoint.c b/src/H5Spoint.c index 0f85110..1531bac 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -1125,10 +1125,10 @@ H5S_point_bounds(const H5S_t *space, hsize_t *start, hsize_t *end) if(((hssize_t)node->pnt[u] + space->select.offset[u]) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds") - if(start[u] > (node->pnt[u] + space->select.offset[u])) - start[u] = node->pnt[u] + space->select.offset[u]; - if(end[u] < (node->pnt[u] + space->select.offset[u])) - end[u] = node->pnt[u] + space->select.offset[u]; + if(start[u] > (hsize_t)((hssize_t)node->pnt[u] + space->select.offset[u])) + start[u] = (hsize_t)((hssize_t)node->pnt[u] + space->select.offset[u]); + if(end[u] < (hsize_t)((hssize_t)node->pnt[u] + space->select.offset[u])) + end[u] = (hsize_t)((hssize_t)node->pnt[u] + space->select.offset[u]); } /* end for */ node = node->next; } /* end while */ @@ -1703,7 +1703,7 @@ H5S_point_get_seq_list(const H5S_t *space, unsigned flags, H5S_sel_iter_t *iter, while(NULL != node) { /* Compute the offset of each selected point in the buffer */ for(i = ndims - 1, acc = iter->elmt_size, loc = 0; i >= 0; i--) { - loc += (node->pnt[i] + space->select.offset[i]) * acc; + loc += (hsize_t)((hssize_t)node->pnt[i] + space->select.offset[i]) * acc; acc *= dims[i]; } /* end for */ diff --git a/src/H5Sselect.c b/src/H5Sselect.c index d4a4d69..2968bed 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -39,6 +39,15 @@ static htri_t H5S_select_iter_has_next_block(const H5S_sel_iter_t *iter); static herr_t H5S_select_iter_next_block(H5S_sel_iter_t *iter); #endif /* LATER */ +/* Declare a free list to manage the H5S_sel_iter_t struct */ +H5FL_DEFINE(H5S_sel_iter_t); + +/* Declare extern free list to manage sequences of size_t */ +H5FL_SEQ_EXTERN(size_t); + +/* Declare extern free list to manage sequences of hsize_t */ +H5FL_SEQ_EXTERN(hsize_t); + /*-------------------------------------------------------------------------- @@ -1364,8 +1373,10 @@ herr_t H5S_select_iterate(void *buf, const H5T_t *type, const H5S_t *space, const H5S_sel_iter_op_t *op, void *op_data) { - H5S_sel_iter_t iter; /* Selection iteration info */ + H5S_sel_iter_t *iter = NULL; /* Selection iteration info */ hbool_t iter_init = FALSE; /* Selection iteration info has been initialized */ + hsize_t *off = NULL; /* Array to store sequence offsets */ + size_t *len = NULL; /* Array to store sequence lengths */ hssize_t nelmts; /* Number of elements in selection */ hsize_t space_size[H5O_LAYOUT_NDIMS]; /* Dataspace size */ size_t max_elem; /* Maximum number of elements allowed in sequences */ @@ -1386,8 +1397,12 @@ H5S_select_iterate(void *buf, const H5T_t *type, const H5S_t *space, if(0 == (elmt_size = H5T_get_size(type))) HGOTO_ERROR(H5E_DATATYPE, H5E_BADSIZE, FAIL, "datatype size invalid") + /* Allocate the selection iterator */ + if(NULL == (iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate selection iterator") + /* Initialize iterator */ - if(H5S_select_iter_init(&iter, space, elmt_size) < 0) + if(H5S_select_iter_init(iter, space, elmt_size) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") iter_init = TRUE; /* Selection iteration info has been initialized */ @@ -1408,16 +1423,20 @@ H5S_select_iterate(void *buf, const H5T_t *type, const H5S_t *space, /* Compute the maximum number of bytes required */ H5_CHECKED_ASSIGN(max_elem, size_t, nelmts, hssize_t); + /* Allocate the offset & length arrays */ + if(NULL == (len = H5FL_SEQ_MALLOC(size_t, H5D_IO_VECTOR_SIZE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate length vector array") + if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, H5D_IO_VECTOR_SIZE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate offset vector array") + /* Loop, while elements left in selection */ while(max_elem > 0 && user_ret == 0) { - hsize_t off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets */ - size_t len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths */ size_t nelem; /* Number of elements used in sequences */ size_t nseq; /* Number of sequences generated */ size_t curr_seq; /* Current sequence being worked on */ /* Get the sequences of bytes */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, &iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off, len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Loop, while sequences left to process */ @@ -1477,9 +1496,17 @@ H5S_select_iterate(void *buf, const H5T_t *type, const H5S_t *space, ret_value = user_ret; done: + /* Release resources, if allocated */ + if(len) + len = H5FL_SEQ_FREE(size_t, len); + if(off) + off = H5FL_SEQ_FREE(hsize_t, off); + /* Release selection iterator */ - if(iter_init && H5S_SELECT_ITER_RELEASE(&iter) < 0) + if(iter_init && H5S_SELECT_ITER_RELEASE(iter) < 0) HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + if(iter) + iter = H5FL_FREE(H5S_sel_iter_t, iter); FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_select_iterate() */ @@ -1583,8 +1610,8 @@ H5S_get_select_type(const H5S_t *space) htri_t H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) { - H5S_sel_iter_t iter_a; /* Selection a iteration info */ - H5S_sel_iter_t iter_b; /* Selection b iteration info */ + H5S_sel_iter_t *iter_a = NULL; /* Selection a iteration info */ + H5S_sel_iter_t *iter_b = NULL; /* Selection b iteration info */ hbool_t iter_a_init = 0; /* Selection a iteration info has been initialized */ hbool_t iter_b_init = 0; /* Selection b iteration info has been initialized */ htri_t ret_value = TRUE; /* Return value */ @@ -1729,15 +1756,21 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) hsize_t off_b[H5O_LAYOUT_NDIMS]; /* Offset of selection b blocks */ hbool_t first_block = TRUE; /* Flag to indicate the first block */ + /* Allocate the selection iterators */ + if(NULL == (iter_a = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate selection iterator") + if(NULL == (iter_b = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate selection iterator") + /* Initialize iterator for each dataspace selection * Use '0' for element size instead of actual element size to indicate * that the selection iterator shouldn't be "flattened", since we * aren't actually going to be doing I/O with the iterators. */ - if(H5S_select_iter_init(&iter_a, space_a, (size_t)0) < 0) + if(H5S_select_iter_init(iter_a, space_a, (size_t)0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator a") iter_a_init = 1; - if(H5S_select_iter_init(&iter_b, space_b, (size_t)0) < 0) + if(H5S_select_iter_init(iter_b, space_b, (size_t)0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator b") iter_b_init = 1; @@ -1748,9 +1781,9 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) htri_t status_a, status_b; /* Status from next block checks */ /* Get the current block for each selection iterator */ - if(H5S_SELECT_ITER_BLOCK(&iter_a, start_a, end_a) < 0) + if(H5S_SELECT_ITER_BLOCK(iter_a, start_a, end_a) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "unable to get iterator block a") - if(H5S_SELECT_ITER_BLOCK(&iter_b, start_b, end_b) < 0) + if(H5S_SELECT_ITER_BLOCK(iter_b, start_b, end_b) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "unable to get iterator block b") space_a_dim = (int)space_a_rank - 1; @@ -1821,10 +1854,10 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) } /* end else */ /* Check if we are able to advance to the next selection block */ - if((status_a = H5S_SELECT_ITER_HAS_NEXT_BLOCK(&iter_a)) < 0) + if((status_a = H5S_SELECT_ITER_HAS_NEXT_BLOCK(iter_a)) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTNEXT, FAIL, "unable to check iterator block a") - if((status_b = H5S_SELECT_ITER_HAS_NEXT_BLOCK(&iter_b)) < 0) + if((status_b = H5S_SELECT_ITER_HAS_NEXT_BLOCK(iter_b)) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTNEXT, FAIL, "unable to check iterator block b") /* Did we run out of blocks at the same time? */ @@ -1834,10 +1867,10 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) HGOTO_DONE(FALSE) else { /* Advance to next block in selection iterators */ - if(H5S_SELECT_ITER_NEXT_BLOCK(&iter_a) < 0) + if(H5S_SELECT_ITER_NEXT_BLOCK(iter_a) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTNEXT, FAIL, "unable to advance to next iterator block a") - if(H5S_SELECT_ITER_NEXT_BLOCK(&iter_b) < 0) + if(H5S_SELECT_ITER_NEXT_BLOCK(iter_b) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTNEXT, FAIL, "unable to advance to next iterator block b") } /* end else */ } /* end while */ @@ -1845,12 +1878,14 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) } /* end else */ done: - if(iter_a_init) - if(H5S_SELECT_ITER_RELEASE(&iter_a) < 0) - HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator a") - if(iter_b_init) - if(H5S_SELECT_ITER_RELEASE(&iter_b) < 0) - HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator b") + if(iter_a_init && H5S_SELECT_ITER_RELEASE(iter_a) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator a") + if(iter_a) + iter_a = H5FL_FREE(H5S_sel_iter_t, iter_a); + if(iter_b_init && H5S_SELECT_ITER_RELEASE(iter_b) < 0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator b") + if(iter_b) + iter_b = H5FL_FREE(H5S_sel_iter_t, iter_b); FUNC_LEAVE_NOAPI(ret_value) } /* H5S_select_shape_same() */ @@ -2152,8 +2187,10 @@ done: herr_t H5S_select_fill(const void *fill, size_t fill_size, const H5S_t *space, void *_buf) { - H5S_sel_iter_t iter; /* Selection iteration info */ + H5S_sel_iter_t *iter = NULL; /* Selection iteration info */ hbool_t iter_init = 0; /* Selection iteration info has been initialized */ + hsize_t *off = NULL; /* Array to store sequence offsets */ + size_t *len = NULL; /* Array to store sequence lengths */ hssize_t nelmts; /* Number of elements in selection */ size_t max_elem; /* Total number of elements in selection */ herr_t ret_value = SUCCEED; /* Return value */ @@ -2166,8 +2203,12 @@ H5S_select_fill(const void *fill, size_t fill_size, const H5S_t *space, void *_b HDassert(space); HDassert(_buf); + /* Allocate the selection iterator */ + if(NULL == (iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate selection iterator") + /* Initialize iterator */ - if(H5S_select_iter_init(&iter, space, fill_size) < 0) + if(H5S_select_iter_init(iter, space, fill_size) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") iter_init = 1; /* Selection iteration info has been initialized */ @@ -2178,16 +2219,20 @@ H5S_select_fill(const void *fill, size_t fill_size, const H5S_t *space, void *_b /* Compute the number of bytes to process */ H5_CHECKED_ASSIGN(max_elem, size_t, nelmts, hssize_t); + /* Allocate the offset & length arrays */ + if(NULL == (len = H5FL_SEQ_MALLOC(size_t, H5D_IO_VECTOR_SIZE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate length vector array") + if(NULL == (off = H5FL_SEQ_MALLOC(hsize_t, H5D_IO_VECTOR_SIZE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate offset vector array") + /* Loop, while elements left in selection */ while(max_elem > 0) { - hsize_t off[H5D_IO_VECTOR_SIZE]; /* Array to store sequence offsets */ - size_t len[H5D_IO_VECTOR_SIZE]; /* Array to store sequence lengths */ size_t nseq; /* Number of sequences generated */ size_t curr_seq; /* Current sequnce being worked on */ size_t nelem; /* Number of elements used in sequences */ /* Get the sequences of bytes */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, &iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off, len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Loop over sequences */ @@ -2207,9 +2252,17 @@ H5S_select_fill(const void *fill, size_t fill_size, const H5S_t *space, void *_b } /* end while */ done: - /* Release resouces */ - if(iter_init && H5S_SELECT_ITER_RELEASE(&iter) < 0) + /* Release resources, if allocated */ + if(len) + len = H5FL_SEQ_FREE(size_t, len); + if(off) + off = H5FL_SEQ_FREE(hsize_t, off); + + /* Release selection iterator */ + if(iter_init && H5S_SELECT_ITER_RELEASE(iter) < 0) HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator") + if(iter) + iter = H5FL_FREE(H5S_sel_iter_t, iter); FUNC_LEAVE_NOAPI(ret_value) } /* H5S_select_fill() */ @@ -5057,6 +5057,49 @@ done: FUNC_LEAVE_NOAPI(ret_value) } +/*------------------------------------------------------------------------- + * Function: H5T_convert_committed_datatype + * + * Purpose: To convert the committed datatype "dt" to a transient embedded + * type if the file location associated with the committed datatype is + * different from the parameter "f". + * "f" is the file location where the dataset or attribute will be created. + * + * Notes: See HDFFV-9940 + * + * Return: Success: non-negative + * Failure: negative + * + * Programmer: Vailin Choi; June 2016 + * + *------------------------------------------------------------------------- + */ +herr_t +H5T_convert_committed_datatype(H5T_t *dt, H5F_t *f) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + HDassert(dt); + HDassert(f); + + if(H5T_is_named(dt) && (dt->sh_loc.file != f)) { + HDassert(dt->sh_loc.type == H5O_SHARE_TYPE_COMMITTED); + + H5O_msg_reset_share(H5O_DTYPE_ID, dt); + if(H5O_loc_free(&dt->oloc) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTRESET, FAIL, "unable to initialize location") + if(H5G_name_free(&dt->path) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTOPENOBJ, FAIL, "unable to reset path") + + dt->shared->state = H5T_STATE_TRANSIENT; + } + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5T_convert_committed_datatype() */ + /*-------------------------------------------------------------------------- NAME @@ -5549,3 +5592,75 @@ H5T_patch_vlen_file(H5T_t *dt, H5F_t *f) FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5T_patch_vlen_file() */ + +/*------------------------------------------------------------------------- + * Function: H5Tflush + * + * Purpose: Flushes all buffers associated with a named datatype to disk. + * + * Return: Non-negative on success, negative on failure + * + * Programmer: Mike McGreevy + * May 19, 2010 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Tflush(hid_t type_id) +{ + H5T_t *dt; /* Datatype for this operation */ + herr_t ret_value = SUCCEED; /* return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "i", type_id); + + /* Check args */ + if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") + if(!H5T_is_named(dt)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a committed datatype") + + /* To flush metadata and invoke flush callback if there is */ + if(H5O_flush_common(&dt->oloc, type_id, H5AC_ind_read_dxpl_id) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFLUSH, FAIL, "unable to flush datatype and object flush callback") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Tflush */ + + +/*------------------------------------------------------------------------- + * Function: H5Trefresh + * + * Purpose: Refreshes all buffers associated with a named datatype. + * + * Return: Non-negative on success, negative on failure + * + * Programmer: Mike McGreevy + * July 21, 2010 + * + *------------------------------------------------------------------------- + */ +herr_t +H5Trefresh(hid_t type_id) +{ + H5T_t * dt = NULL; + herr_t ret_value = SUCCEED; /* return value */ + + FUNC_ENTER_API(FAIL) + H5TRACE1("e", "i", type_id); + + /* Check args */ + if(NULL == (dt = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") + if(!H5T_is_named(dt)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a committed datatype") + + /* Call private function to refresh datatype object */ + if ((H5O_refresh_metadata(type_id, dt->oloc, H5AC_ind_read_dxpl_id)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTLOAD, FAIL, "unable to refresh datatype") + +done: + FUNC_LEAVE_API(ret_value) +} /* H5Trefresh */ + diff --git a/src/H5Tprivate.h b/src/H5Tprivate.h index 45d8d76..5fd0cf3 100644 --- a/src/H5Tprivate.h +++ b/src/H5Tprivate.h @@ -121,6 +121,7 @@ H5_DLL struct H5O_loc_t *H5T_oloc(H5T_t *dt); H5_DLL H5G_name_t *H5T_nameof(H5T_t *dt); H5_DLL htri_t H5T_is_immutable(const H5T_t *dt); H5_DLL htri_t H5T_is_named(const H5T_t *dt); +H5_DLL herr_t H5T_convert_committed_datatype(H5T_t *dt, H5F_t *f); H5_DLL htri_t H5T_is_relocatable(const H5T_t *dt); H5_DLL H5T_path_t *H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name, H5T_conv_t func, hid_t dxpl_id, hbool_t is_api); diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index d646ef1..df7ad41 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -511,6 +511,8 @@ H5_DLL hid_t H5Tget_create_plist(hid_t type_id); H5_DLL htri_t H5Tcommitted(hid_t type_id); H5_DLL herr_t H5Tencode(hid_t obj_id, void *buf, size_t *nalloc); H5_DLL hid_t H5Tdecode(const void *buf); +H5_DLL herr_t H5Tflush(hid_t type_id); +H5_DLL herr_t H5Trefresh(hid_t type_id); /* Operations defined on compound datatypes */ H5_DLL herr_t H5Tinsert(hid_t parent_id, const char *name, size_t offset, diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index 0ed8209..d198d50 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -243,7 +243,7 @@ H5T__vlen_set_loc(const H5T_t *dt, H5F_t *f, H5T_loc_t loc) * of an address in this file, plus 4 bytes for the size of a heap * ID. Memory size is different */ - dt->shared->size = 4 + H5F_SIZEOF_ADDR(f) + 4; + dt->shared->size = 4 + (size_t)H5F_SIZEOF_ADDR(f) + 4; /* Set up the function pointers to access the VL information on disk */ /* VL sequences and VL strings are stored identically on disk, so use the same functions */ @@ -801,7 +801,7 @@ H5T_vlen_disk_getptr(void H5_ATTR_UNUSED *vl) static htri_t H5T_vlen_disk_isnull(const H5F_t *f, void *_vl) { - uint8_t *vl=(uint8_t *)_vl; /* Pointer to the disk VL information */ + uint8_t *vl = (uint8_t *)_vl; /* Pointer to the disk VL information */ haddr_t addr; /* Sequence's heap address */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -810,12 +810,12 @@ H5T_vlen_disk_isnull(const H5F_t *f, void *_vl) HDassert(vl); /* Skip the sequence's length */ - vl+=4; + vl += 4; /* Get the heap address */ - H5F_addr_decode(f,(const uint8_t **)&vl,&addr); + H5F_addr_decode(f, (const uint8_t **)&vl, &addr); - FUNC_LEAVE_NOAPI(addr==0 ? TRUE : FALSE) + FUNC_LEAVE_NOAPI(addr == 0 ? TRUE : FALSE) } /* end H5T_vlen_disk_isnull() */ diff --git a/src/H5Zscaleoffset.c b/src/H5Zscaleoffset.c index 1cca9b1..91a6c00 100644 --- a/src/H5Zscaleoffset.c +++ b/src/H5Zscaleoffset.c @@ -667,6 +667,58 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ H5Z_scaleoffset_modify_4(i, type, pow_fun, buf, d_nelmts, min, D_val) \ } +/* Include our own rounding routine and alias it to the stdc macros, if they + * aren't available. + */ +#if !(defined(H5_HAVE_LLROUND) && defined(H5_HAVE_LLROUNDF) && defined(H5_HAVE_LROUND) && defined(H5_HAVE_LROUNDF) && defined(H5_HAVE_ROUND) && defined(H5_HAVE_ROUNDF)) +/* Round a floating-point value to the nearest integer value 4/19/05 */ +/* rounding to the bigger absolute value if val is in the middle, + 0.5 -> 1, -0.5 ->-1 +5/9/05, KY */ +static double +H5Z__scaleoffset_rnd(double val) +{ + double u_val, l_val; + + u_val = HDceil(val); + l_val = HDfloor(val); + + if(val > 0) { + if((u_val - val) <= (val - l_val)) + return u_val; + else + return l_val; + } /* end if */ + else { + if((val - l_val) <= (u_val - val)) + return l_val; + else + return u_val; + } +} /* H5Z__scaleoffset_rnd() */ + +/* Alias rounding macros to routine above, if not defined */ +#if !defined(H5_HAVE_LLROUND) +#define llround(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_LLROUND) */ +#if !defined(H5_HAVE_LLROUNDF) +#define llroundf(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_LLROUNDF) */ +#if !defined(H5_HAVE_LROUND) +#define lround(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_LROUND) */ +#if !defined(H5_HAVE_LROUNDF) +#define lroundf(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_LROUNDF) */ +#if !defined(H5_HAVE_ROUND) +#define round(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_ROUND) */ +#if !defined(H5_HAVE_ROUNDF) +#define roundf(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_ROUNDF) */ + +#endif /* !(defined(H5_HAVE_LLROUND) && defined(H5_HAVE_LLROUNDF) && defined(H5_HAVE_LROUND) && defined(H5_HAVE_LROUNDF) && defined(H5_HAVE_ROUND) && defined(H5_HAVE_ROUNDF)) */ + /*------------------------------------------------------------------------- * Function: H5Z_can_apply_scaleoffset diff --git a/src/H5private.h b/src/H5private.h index 6a677bb..4c40965 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1142,7 +1142,9 @@ typedef off_t h5_stat_size_t; #ifndef HDpowf #define HDpowf(X,Y) powf(X,Y) #endif /* HDpowf */ -/* printf() variable arguments */ +#ifndef HDprintf + #define HDprintf(...) HDfprintf(stdout, __VA_ARGS__) +#endif /* HDprintf */ #ifndef HDputc #define HDputc(C,F) putc(C,F) #endif /* HDputc*/ diff --git a/src/H5system.c b/src/H5system.c index e6ca5d4..e17373c 100644 --- a/src/H5system.c +++ b/src/H5system.c @@ -172,7 +172,7 @@ HDfprintf(FILE *stream, const char *fmt, ...) s = rest; } /* end if */ else if ('*'==*s) { - fwidth = va_arg (ap, int); + fwidth = va_arg(ap, int); if(fwidth < 0) { leftjust = 1; fwidth = -fwidth; @@ -269,23 +269,22 @@ HDfprintf(FILE *stream, const char *fmt, ...) len += HDsnprintf(format_templ + len, (sizeof(format_templ) - (size_t)(len + 1)), "%s", modifier); HDsnprintf(format_templ + len, (sizeof(format_templ) - (size_t)(len + 1)), "%c", conv); - /* Conversion */ switch (conv) { case 'd': case 'i': if(!HDstrcmp(modifier, "h")) { - short x = (short)va_arg (ap, int); - n = fprintf (stream, format_templ, x); + short x = (short)va_arg(ap, int); + n = fprintf(stream, format_templ, x); } else if(!*modifier) { - int x = va_arg (ap, int); - n = fprintf (stream, format_templ, x); - } else if(!HDstrcmp (modifier, "l")) { - long x = va_arg (ap, long); - n = fprintf (stream, format_templ, x); + int x = va_arg(ap, int); + n = fprintf(stream, format_templ, x); + } else if(!HDstrcmp(modifier, "l")) { + long x = va_arg(ap, long); + n = fprintf(stream, format_templ, x); } else { int64_t x = va_arg(ap, int64_t); - n = fprintf (stream, format_templ, x); + n = fprintf(stream, format_templ, x); } break; @@ -294,13 +293,13 @@ HDfprintf(FILE *stream, const char *fmt, ...) case 'x': case 'X': if(!HDstrcmp(modifier, "h")) { - unsigned short x = (unsigned short)va_arg (ap, unsigned int); + unsigned short x = (unsigned short)va_arg(ap, unsigned int); n = fprintf(stream, format_templ, x); } else if(!*modifier) { - unsigned int x = va_arg (ap, unsigned int); /*lint !e732 Loss of sign not really occuring */ + unsigned int x = va_arg(ap, unsigned int); /*lint !e732 Loss of sign not really occuring */ n = fprintf(stream, format_templ, x); } else if(!HDstrcmp(modifier, "l")) { - unsigned long x = va_arg (ap, unsigned long); /*lint !e732 Loss of sign not really occuring */ + unsigned long x = va_arg(ap, unsigned long); /*lint !e732 Loss of sign not really occuring */ n = fprintf(stream, format_templ, x); } else { uint64_t x = va_arg(ap, uint64_t); /*lint !e732 Loss of sign not really occuring */ @@ -336,7 +335,7 @@ HDfprintf(FILE *stream, const char *fmt, ...) case 'a': { - haddr_t x = va_arg (ap, haddr_t); /*lint !e732 Loss of sign not really occuring */ + haddr_t x = va_arg(ap, haddr_t); /*lint !e732 Loss of sign not really occuring */ if(H5F_addr_defined(x)) { len = 0; @@ -405,7 +404,7 @@ HDfprintf(FILE *stream, const char *fmt, ...) htri_t tri_var = va_arg(ap, htri_t); if(tri_var > 0) - fprintf (stream, "TRUE"); + fprintf(stream, "TRUE"); else if(!tri_var) fprintf(stream, "FALSE"); else diff --git a/src/H5timer.c b/src/H5timer.c index d9be6bb..f36681e 100644 --- a/src/H5timer.c +++ b/src/H5timer.c @@ -127,16 +127,16 @@ H5_timer_begin (H5_timer_t *timer) #ifdef H5_HAVE_GETRUSAGE HDgetrusage (RUSAGE_SELF, &rusage); timer->utime = (double)rusage.ru_utime.tv_sec + - ((double)rusage.ru_utime.tv_usec / 1e6F); + ((double)rusage.ru_utime.tv_usec / (double)1e6F); timer->stime = (double)rusage.ru_stime.tv_sec + - ((double)rusage.ru_stime.tv_usec / 1e6F); + ((double)rusage.ru_stime.tv_usec / (double)1e6F); #else timer->utime = 0.0F; timer->stime = 0.0F; #endif #ifdef H5_HAVE_GETTIMEOFDAY HDgettimeofday (&etime, NULL); - timer->etime = (double)etime.tv_sec + ((double)etime.tv_usec / 1e6F); + timer->etime = (double)etime.tv_sec + ((double)etime.tv_usec / (double)1e6F); #else timer->etime = 0.0F; #endif @@ -166,9 +166,9 @@ H5_timer_end (H5_timer_t *sum/*in,out*/, H5_timer_t *timer/*in,out*/) HDassert(timer); H5_timer_begin(&now); - timer->utime = MAX(0.0F, now.utime - timer->utime); - timer->stime = MAX(0.0F, now.stime - timer->stime); - timer->etime = MAX(0.0F, now.etime - timer->etime); + timer->utime = MAX((double)0.0F, now.utime - timer->utime); + timer->stime = MAX((double)0.0F, now.stime - timer->stime); + timer->etime = MAX((double)0.0F, now.etime - timer->etime); if (sum) { sum->utime += timer->utime; @@ -208,28 +208,28 @@ H5_bandwidth(char *buf/*out*/, double nbytes, double nseconds) { double bw; - if(nseconds <= 0.0F) + if(nseconds <= (double)0.0F) HDstrcpy(buf, " NaN"); else { bw = nbytes/nseconds; - if(H5_DBL_ABS_EQUAL(bw, 0.0F)) - HDstrcpy(buf, "0.000 B/s"); - else if(bw < 1.0F) + if(H5_DBL_ABS_EQUAL(bw, (double)0.0F)) + HDstrcpy(buf, "0.000 B/s"); + else if(bw < (double)1.0F) sprintf(buf, "%10.4e", bw); - else if(bw < H5_KB) { + else if(bw < (double)H5_KB) { sprintf(buf, "%05.4f", bw); HDstrcpy(buf+5, " B/s"); - } else if(bw < H5_MB) { - sprintf(buf, "%05.4f", bw / H5_KB); + } else if(bw < (double)H5_MB) { + sprintf(buf, "%05.4f", bw / (double)H5_KB); HDstrcpy(buf+5, " kB/s"); - } else if(bw < H5_GB) { - sprintf(buf, "%05.4f", bw / H5_MB); + } else if(bw < (double)H5_GB) { + sprintf(buf, "%05.4f", bw / (double)H5_MB); HDstrcpy(buf+5, " MB/s"); - } else if(bw < H5_TB) { - sprintf(buf, "%05.4f", bw / H5_GB); + } else if(bw < (double)H5_TB) { + sprintf(buf, "%05.4f", bw / (double)H5_GB); HDstrcpy(buf+5, " GB/s"); - } else if(bw < H5_PB) { - sprintf(buf, "%05.4f", bw / H5_TB); + } else if(bw < (double)H5_PB) { + sprintf(buf, "%05.4f", bw / (double)H5_TB); HDstrcpy(buf+5, " TB/s"); } else { sprintf(buf, "%10.4e", bw); |