From 377560fdd8a840a86be496f0d5e5f05094063605 Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Mon, 14 Mar 2022 19:22:57 -0500 Subject: Fix warnings in selection I/O code --- src/H5FDint.c | 95 +++++++++++++++++++++++++++++++++++++++---------------- src/H5FDmpio.c | 16 +++++----- src/H5FDprivate.h | 4 +-- src/H5private.h | 10 ++++++ 4 files changed, 87 insertions(+), 38 deletions(-) diff --git a/src/H5FDint.c b/src/H5FDint.c index f624aa8..fabcedf 100644 --- a/src/H5FDint.c +++ b/src/H5FDint.c @@ -34,6 +34,7 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* File access */ #include "H5FDpkg.h" /* File Drivers */ +#include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ #include "H5PLprivate.h" /* Plugins */ @@ -116,6 +117,9 @@ static herr_t H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid /* Local Variables */ /*******************/ +/* Declare extern free list to manage the H5S_sel_iter_t struct */ +H5FL_EXTERN(H5S_sel_iter_t); + /*------------------------------------------------------------------------- * Function: H5FD_locate_signature * @@ -761,8 +765,10 @@ H5FD__read_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, uin size_t nelmts; hssize_t hss_nelmts; size_t seq_nelem; - H5S_sel_iter_t file_iter; - H5S_sel_iter_t mem_iter; + H5S_sel_iter_t *file_iter = NULL; + H5S_sel_iter_t *mem_iter = NULL; + hbool_t file_iter_init = FALSE; + hbool_t mem_iter_init = FALSE; H5FD_mem_t types[2] = {type, H5FD_MEM_NOLIST}; size_t vec_arr_nalloc = sizeof(addrs_static) / sizeof(addrs_static[0]); size_t vec_arr_nused = 0; @@ -821,11 +827,19 @@ H5FD__read_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, uin } } + /* Allocate sequence lists for memory and file spaces */ + if (NULL == (file_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate file selection iterator") + if (NULL == (mem_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate memory selection iterator") + /* Initialize sequence lists for memory and file spaces */ - if (H5S_select_iter_init(&file_iter, file_spaces[i], element_size, 0) < 0) + if (H5S_select_iter_init(file_iter, file_spaces[i], element_size, 0) < 0) HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize sequence list for file space") - if (H5S_select_iter_init(&mem_iter, mem_spaces[i], element_size, 0) < 0) + file_iter_init = TRUE; + if (H5S_select_iter_init(mem_iter, mem_spaces[i], element_size, 0) < 0) HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize sequence list for memory space") + mem_iter_init = TRUE; /* Get the number of elements in selection */ if ((hss_nelmts = (hssize_t)H5S_GET_SELECT_NPOINTS(file_spaces[i])) < 0) @@ -852,7 +866,7 @@ H5FD__read_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, uin while (file_seq_i < file_nseq || nelmts > 0) { /* Fill/refill file sequence list if necessary */ if (file_seq_i == H5FD_SEQ_LIST_LEN) { - if (H5S_SELECT_ITER_GET_SEQ_LIST(&file_iter, H5FD_SEQ_LIST_LEN, SIZE_MAX, &file_nseq, + if (H5S_SELECT_ITER_GET_SEQ_LIST(file_iter, H5FD_SEQ_LIST_LEN, SIZE_MAX, &file_nseq, &seq_nelem, file_off, file_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") HDassert(file_nseq > 0); @@ -864,7 +878,7 @@ H5FD__read_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, uin /* Fill/refill memory sequence list if necessary */ if (mem_seq_i == H5FD_SEQ_LIST_LEN) { - if (H5S_SELECT_ITER_GET_SEQ_LIST(&mem_iter, H5FD_SEQ_LIST_LEN, SIZE_MAX, &mem_nseq, + if (H5S_SELECT_ITER_GET_SEQ_LIST(mem_iter, H5FD_SEQ_LIST_LEN, SIZE_MAX, &mem_nseq, &seq_nelem, mem_off, mem_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") HDassert(mem_nseq > 0); @@ -953,14 +967,9 @@ H5FD__read_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, uin } } + /* Make sure both memory and file sequences terminated at the same time */ if (mem_seq_i < mem_nseq) HGOTO_ERROR(H5E_INTERNAL, H5E_BADVALUE, FAIL, "file selection terminated before memory selection") - - /* Terminate iterators */ - if (H5S_SELECT_ITER_RELEASE(&file_iter) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release file selection iterator") - if (H5S_SELECT_ITER_RELEASE(&mem_iter) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release memory selection iterator") } /* Issue vector read call if appropriate */ @@ -972,7 +981,19 @@ H5FD__read_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, uin } done: - /* Cleanup */ + /* Terminate iterators */ + if (file_iter) { + if (file_iter_init && H5S_SELECT_ITER_RELEASE(file_iter) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release file selection iterator") + file_iter = H5FL_FREE(H5S_sel_iter_t, file_iter); + } + if (mem_iter) { + if (mem_iter_init && H5S_SELECT_ITER_RELEASE(mem_iter) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release memory selection iterator") + mem_iter = H5FL_FREE(H5S_sel_iter_t, mem_iter); + } + + /* Cleanup vector arrays */ if (use_vector) { if (addrs != addrs_static) addrs = H5MM_xfree(addrs); @@ -1379,8 +1400,10 @@ H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, ui size_t nelmts; hssize_t hss_nelmts; size_t seq_nelem; - H5S_sel_iter_t file_iter; - H5S_sel_iter_t mem_iter; + H5S_sel_iter_t *file_iter = NULL; + H5S_sel_iter_t *mem_iter = NULL; + hbool_t file_iter_init = FALSE; + hbool_t mem_iter_init = FALSE; H5FD_mem_t types[2] = {type, H5FD_MEM_NOLIST}; size_t vec_arr_nalloc = sizeof(addrs_static) / sizeof(addrs_static[0]); size_t vec_arr_nused = 0; @@ -1439,11 +1462,19 @@ H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, ui } } + /* Allocate sequence lists for memory and file spaces */ + if (NULL == (file_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate file selection iterator") + if (NULL == (mem_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate memory selection iterator") + /* Initialize sequence lists for memory and file spaces */ - if (H5S_select_iter_init(&file_iter, file_spaces[i], element_size, 0) < 0) + if (H5S_select_iter_init(file_iter, file_spaces[i], element_size, 0) < 0) HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize sequence list for file space") - if (H5S_select_iter_init(&mem_iter, mem_spaces[i], element_size, 0) < 0) + file_iter_init = TRUE; + if (H5S_select_iter_init(mem_iter, mem_spaces[i], element_size, 0) < 0) HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize sequence list for memory space") + mem_iter_init = TRUE; /* Get the number of elements in selection */ if ((hss_nelmts = (hssize_t)H5S_GET_SELECT_NPOINTS(file_spaces[i])) < 0) @@ -1470,7 +1501,7 @@ H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, ui while (file_seq_i < file_nseq || nelmts > 0) { /* Fill/refill file sequence list if necessary */ if (file_seq_i == H5FD_SEQ_LIST_LEN) { - if (H5S_SELECT_ITER_GET_SEQ_LIST(&file_iter, H5FD_SEQ_LIST_LEN, SIZE_MAX, &file_nseq, + if (H5S_SELECT_ITER_GET_SEQ_LIST(file_iter, H5FD_SEQ_LIST_LEN, SIZE_MAX, &file_nseq, &seq_nelem, file_off, file_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") HDassert(file_nseq > 0); @@ -1482,7 +1513,7 @@ H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, ui /* Fill/refill memory sequence list if necessary */ if (mem_seq_i == H5FD_SEQ_LIST_LEN) { - if (H5S_SELECT_ITER_GET_SEQ_LIST(&mem_iter, H5FD_SEQ_LIST_LEN, SIZE_MAX, &mem_nseq, + if (H5S_SELECT_ITER_GET_SEQ_LIST(mem_iter, H5FD_SEQ_LIST_LEN, SIZE_MAX, &mem_nseq, &seq_nelem, mem_off, mem_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") HDassert(mem_nseq > 0); @@ -1571,14 +1602,10 @@ H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, ui } } + /* Make sure both memory and file sequences terminated at the same time */ if (mem_seq_i < mem_nseq) HGOTO_ERROR(H5E_INTERNAL, H5E_BADVALUE, FAIL, "file selection terminated before memory selection") - /* Terminate iterators */ - if (H5S_SELECT_ITER_RELEASE(&file_iter) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release file selection iterator") - if (H5S_SELECT_ITER_RELEASE(&mem_iter) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release memory selection iterator") } /* Issue vector write call if appropriate */ @@ -1590,7 +1617,19 @@ H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, ui } done: - /* Cleanup */ + /* Terminate iterators */ + if (file_iter) { + if (file_iter_init && H5S_SELECT_ITER_RELEASE(file_iter) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release file selection iterator") + file_iter = H5FL_FREE(H5S_sel_iter_t, file_iter); + } + if (mem_iter) { + if (mem_iter_init && H5S_SELECT_ITER_RELEASE(mem_iter) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release memory selection iterator") + mem_iter = H5FL_FREE(H5S_sel_iter_t, mem_iter); + } + + /* Cleanup vector arrays */ if (use_vector) { if (addrs != addrs_static) addrs = H5MM_xfree(addrs); @@ -2127,8 +2166,8 @@ H5FD__vsrt_tmp_cmp(const void *element_1, const void *element_2) herr_t H5FD_sort_vector_io_req(hbool_t *vector_was_sorted, uint32_t _count, H5FD_mem_t types[], haddr_t addrs[], - size_t sizes[], const void *bufs[], H5FD_mem_t **s_types_ptr, haddr_t **s_addrs_ptr, - size_t **s_sizes_ptr, void ***s_bufs_ptr) + size_t sizes[], H5_flexible_const_ptr_t bufs[], H5FD_mem_t **s_types_ptr, haddr_t **s_addrs_ptr, + size_t **s_sizes_ptr, H5_flexible_const_ptr_t **s_bufs_ptr) { herr_t ret_value = SUCCEED; /* Return value */ size_t count = (size_t)_count; @@ -2229,7 +2268,7 @@ H5FD_sort_vector_io_req(hbool_t *vector_was_sorted, uint32_t _count, H5FD_mem_t if ((NULL == (*s_types_ptr = (H5FD_mem_t *)HDmalloc(count * sizeof(H5FD_mem_t)))) || (NULL == (*s_addrs_ptr = (haddr_t *)HDmalloc(count * sizeof(haddr_t)))) || (NULL == (*s_sizes_ptr = (size_t *)HDmalloc(count * sizeof(size_t)))) || - (NULL == (*s_bufs_ptr = (void *)HDmalloc(count * sizeof(void *))))) { + (NULL == (*s_bufs_ptr = (H5_flexible_const_ptr_t *)HDmalloc(count * sizeof(H5_flexible_const_ptr_t))))) { HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't alloc sorted vector(s)") } diff --git a/src/H5FDmpio.c b/src/H5FDmpio.c index 211da9c..74ab34e 100644 --- a/src/H5FDmpio.c +++ b/src/H5FDmpio.c @@ -1390,7 +1390,7 @@ H5FD__mpio_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU #ifdef H5FDmpio_DEBUG if (H5FD_mpio_debug_r_flag) HDfprintf(stderr, "%s: (%d) mpi_off = %ld bytes_read = %lld\n", __func__, file->mpi_rank, - (long)mpi_off, bytes_read); + (long)mpi_off, (long long)bytes_read); #endif /* @@ -1611,7 +1611,7 @@ H5FD__mpio_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, h #ifdef H5FDmpio_DEBUG if (H5FD_mpio_debug_w_flag) HDfprintf(stderr, "%s: (%d) mpi_off = %ld bytes_written = %lld\n", __func__, file->mpi_rank, - (long)mpi_off, bytes_written); + (long)mpi_off, (long long)bytes_written); #endif /* Each process will keep track of its perceived EOF value locally, and @@ -1811,8 +1811,8 @@ H5FD__mpio_read_vector(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, uint32_t cou * are allocated, populated, and returned in s_types, s_addrs, s_sizes, and s_bufs respectively. * In this case, this function must free the memory allocated for the sorted vectors. */ - if (H5FD_sort_vector_io_req(&vector_was_sorted, count, types, addrs, sizes, (const void **)bufs, - &s_types, &s_addrs, &s_sizes, &s_bufs) < 0) + if (H5FD_sort_vector_io_req(&vector_was_sorted, count, types, addrs, sizes, (H5_flexible_const_ptr_t *)bufs, + &s_types, &s_addrs, &s_sizes, (H5_flexible_const_ptr_t **)&s_bufs) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "can't sort vector I/O request") if ((NULL == (mpi_block_lengths = (int *)HDmalloc((size_t)count * sizeof(int)))) || @@ -2385,10 +2385,10 @@ H5FD__mpio_write_vector(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, uint32_t co H5FD_mem_t * s_types = NULL; haddr_t * s_addrs = NULL; size_t * s_sizes = NULL; - void ** s_bufs = NULL; + const void ** s_bufs = NULL; int * mpi_block_lengths = NULL; char unused = 0; /* Unused, except for non-NULL pointer value */ - void * mpi_bufs_base = NULL; + const void * mpi_bufs_base = NULL; MPI_Aint mpi_bufs_base_Aint; MPI_Aint * mpi_bufs = NULL; MPI_Aint * mpi_displacements = NULL; @@ -2446,8 +2446,8 @@ H5FD__mpio_write_vector(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, uint32_t co * are allocated, populated, and returned in s_types, s_addrs, s_sizes, and s_bufs respectively. * In this case, this function must free the memory allocated for the sorted vectors. */ - if (H5FD_sort_vector_io_req(&vector_was_sorted, count, types, addrs, sizes, bufs, &s_types, &s_addrs, - &s_sizes, &s_bufs) < 0) + if (H5FD_sort_vector_io_req(&vector_was_sorted, count, types, addrs, sizes, (H5_flexible_const_ptr_t *)bufs, &s_types, &s_addrs, + &s_sizes, (H5_flexible_const_ptr_t **)&s_bufs) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "can't sort vector I/O request") /* Get the transfer mode from the API context diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h index 3b6e23c..bcbc693 100644 --- a/src/H5FDprivate.h +++ b/src/H5FDprivate.h @@ -173,9 +173,9 @@ H5_DLL haddr_t H5FD_get_base_addr(const H5FD_t *file); H5_DLL herr_t H5FD_set_paged_aggr(H5FD_t *file, hbool_t paged); H5_DLL herr_t H5FD_sort_vector_io_req(hbool_t *vector_was_sorted, uint32_t count, H5FD_mem_t types[], - haddr_t addrs[], size_t sizes[], const void *bufs[], + haddr_t addrs[], size_t sizes[], H5_flexible_const_ptr_t bufs[], H5FD_mem_t **s_types_ptr, haddr_t **s_addrs_ptr, size_t **s_sizes_ptr, - void ***s_bufs_ptr); + H5_flexible_const_ptr_t **s_bufs_ptr); H5_DLL herr_t H5FD_init(void); /* Function prototypes for MPI based VFDs*/ diff --git a/src/H5private.h b/src/H5private.h index d71fca6..4a9b203 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -2507,6 +2507,16 @@ H5_DLL herr_t H5CX_pop(hbool_t update_dxpl_props); #define HDcompile_assert(e) do { typedef struct { unsigned int b: (e); } x; } while(0) */ +/* Private typedefs */ + +/* Union for const/non-const pointer for use by functions that manipulate + * pointers but do not write to their targets or return pointers to const + * specified locations. This helps us avoid compiler warnings. */ +typedef union { + void *vp; + const void *cvp; +} H5_flexible_const_ptr_t; + /* Private functions, not part of the publicly documented API */ H5_DLL herr_t H5_init_library(void); H5_DLL void H5_term_library(void); -- cgit v0.12