Skip to content

Commit

Permalink
Address some warnings from casting away of const (HDFGroup#1684)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendersonHDF committed May 8, 2022
1 parent 0948679 commit 6661718
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 127 deletions.
67 changes: 32 additions & 35 deletions src/H5Dchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,8 +1117,7 @@ H5D__chunk_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf
fm->mem_space = NULL;

if (file_space_normalized == TRUE)
if (H5S_hyper_denormalize_offset((H5S_t *)file_space, old_offset) <
0) /* (Casting away const OK -QAK) */
if (H5S_hyper_denormalize_offset(file_space, old_offset) < 0)
HDONE_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "can't denormalize selection")

FUNC_LEAVE_NOAPI(ret_value)
Expand Down Expand Up @@ -1345,15 +1344,16 @@ H5D__chunk_io_init_selections(const H5D_io_info_t *io_info, const H5D_type_info_
*-------------------------------------------------------------------------
*/
void *
H5D__chunk_mem_alloc(size_t size, const H5O_pline_t *pline)
H5D__chunk_mem_alloc(size_t size, void *pline)
{
void *ret_value = NULL; /* Return value */
H5O_pline_t *_pline = (H5O_pline_t *)pline;
void * ret_value = NULL; /* Return value */

FUNC_ENTER_STATIC_NOERR

HDassert(size);

if (pline && pline->nused)
if (_pline && _pline->nused)
ret_value = H5MM_malloc(size);
else
ret_value = H5FL_BLK_MALLOC(chunk, size);
Expand All @@ -1376,12 +1376,14 @@ H5D__chunk_mem_alloc(size_t size, const H5O_pline_t *pline)
*-------------------------------------------------------------------------
*/
void *
H5D__chunk_mem_xfree(void *chk, const H5O_pline_t *pline)
H5D__chunk_mem_xfree(void *chk, const void *pline)
{
const H5O_pline_t *_pline = (const H5O_pline_t *)pline;

FUNC_ENTER_STATIC_NOERR

if (chk) {
if (pline && pline->nused)
if (_pline && _pline->nused)
H5MM_xfree(chk);
else
chk = H5FL_BLK_FREE(chunk, chk);
Expand All @@ -1398,9 +1400,9 @@ H5D__chunk_mem_xfree(void *chk, const H5O_pline_t *pline)
*-------------------------------------------------------------------------
*/
void
H5D__chunk_mem_free(void *chk, const H5O_pline_t *_pline)
H5D__chunk_mem_free(void *chk, void *pline)
{
(void)H5D__chunk_mem_xfree(chk, _pline);
(void)H5D__chunk_mem_xfree(chk, pline);
}

/*-------------------------------------------------------------------------
Expand Down Expand Up @@ -1552,8 +1554,7 @@ H5D__create_chunk_map_single(H5D_chunk_map_t *fm, const H5D_io_info_t
chunk_info->fspace_shared = TRUE;

/* Just point at the memory dataspace & selection */
/* (Casting away const OK -QAK) */
chunk_info->mspace = (H5S_t *)fm->mem_space;
chunk_info->mspace = fm->mem_space;

/* Indicate that the chunk's memory dataspace is shared */
chunk_info->mspace_shared = TRUE;
Expand Down Expand Up @@ -1828,7 +1829,6 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t
/* Iterate through each chunk in the dataset */
while (sel_points) {
/* Check for intersection of current chunk and file selection */
/* (Casting away const OK - QAK) */
if (TRUE == H5S_SELECT_INTERSECT_BLOCK(fm->file_space, coords, end)) {
H5D_chunk_info_t *new_chunk_info; /* chunk information to insert into skip list */
hsize_t chunk_points; /* Number of elements in chunk selection */
Expand Down Expand Up @@ -1987,8 +1987,7 @@ H5D__create_chunk_mem_map_hyper(const H5D_chunk_map_t *fm)
HDassert(chunk_info);

/* Just point at the memory dataspace & selection */
/* (Casting away const OK -QAK) */
chunk_info->mspace = (H5S_t *)fm->mem_space;
chunk_info->mspace = fm->mem_space;

/* Indicate that the chunk's memory space is shared */
chunk_info->mspace_shared = TRUE;
Expand Down Expand Up @@ -2110,8 +2109,7 @@ H5D__create_chunk_mem_map_1d(const H5D_chunk_map_t *fm)
HDassert(chunk_info);

/* Just point at the memory dataspace & selection */
/* (Casting away const OK -QAK) */
chunk_info->mspace = (H5S_t *)fm->mem_space;
chunk_info->mspace = fm->mem_space;

/* Indicate that the chunk's memory space is shared */
chunk_info->mspace_shared = TRUE;
Expand Down Expand Up @@ -3702,11 +3700,11 @@ H5D__chunk_cache_prune(const H5D_t *dset, size_t size)
static void *
H5D__chunk_lock(const H5D_io_info_t *io_info, H5D_chunk_ud_t *udata, hbool_t relax, hbool_t prev_unfilt_chunk)
{
const H5D_t * dset = io_info->dset; /* Local pointer to the dataset info */
const H5O_pline_t *pline =
const H5D_t *dset = io_info->dset; /* Local pointer to the dataset info */
H5O_pline_t *pline =
&(dset->shared->dcpl_cache
.pline); /* I/O pipeline info - always equal to the pline passed to H5D__chunk_mem_alloc */
const H5O_pline_t * old_pline = pline; /* Old pipeline, i.e. pipeline used to read the chunk */
H5O_pline_t * old_pline = pline; /* Old pipeline, i.e. pipeline used to read the chunk */
const H5O_layout_t *layout = &(dset->shared->layout); /* Dataset layout */
const H5O_fill_t * fill = &(dset->shared->dcpl_cache.fill); /* Fill value info */
H5D_fill_buf_info_t fb_info; /* Dataset's fill buffer info */
Expand Down Expand Up @@ -4285,18 +4283,18 @@ H5D__chunk_allocate(const H5D_io_info_t *io_info, hbool_t full_overwrite, const
coordinates) */
hsize_t max_unalloc[H5O_LAYOUT_NDIMS]; /* Last chunk in each dimension that is unallocated (in scaled
coordinates) */
hsize_t scaled[H5O_LAYOUT_NDIMS]; /* Offset of current chunk (in scaled coordinates) */
size_t orig_chunk_size; /* Original size of chunk in bytes */
size_t chunk_size; /* Actual size of chunk in bytes, possibly filtered */
unsigned filter_mask = 0; /* Filter mask for chunks that have them */
const H5O_layout_t *layout = &(dset->shared->layout); /* Dataset layout */
const H5O_pline_t * pline = &(dset->shared->dcpl_cache.pline); /* I/O pipeline info */
const H5O_pline_t def_pline = H5O_CRT_PIPELINE_DEF; /* Default pipeline */
const H5O_fill_t * fill = &(dset->shared->dcpl_cache.fill); /* Fill value info */
H5D_fill_value_t fill_status; /* The fill value status */
hbool_t should_fill = FALSE; /* Whether fill values should be written */
void * unfilt_fill_buf = NULL; /* Unfiltered fill value buffer */
void ** fill_buf = NULL; /* Pointer to the fill buffer to use for a chunk */
hsize_t scaled[H5O_LAYOUT_NDIMS]; /* Offset of current chunk (in scaled coordinates) */
size_t orig_chunk_size; /* Original size of chunk in bytes */
size_t chunk_size; /* Actual size of chunk in bytes, possibly filtered */
unsigned filter_mask = 0; /* Filter mask for chunks that have them */
H5O_layout_t * layout = &(dset->shared->layout); /* Dataset layout */
H5O_pline_t * pline = &(dset->shared->dcpl_cache.pline); /* I/O pipeline info */
H5O_pline_t def_pline = H5O_CRT_PIPELINE_DEF; /* Default pipeline */
const H5O_fill_t *fill = &(dset->shared->dcpl_cache.fill); /* Fill value info */
H5D_fill_value_t fill_status; /* The fill value status */
hbool_t should_fill = FALSE; /* Whether fill values should be written */
void * unfilt_fill_buf = NULL; /* Unfiltered fill value buffer */
void ** fill_buf = NULL; /* Pointer to the fill buffer to use for a chunk */
#ifdef H5_HAVE_PARALLEL
hbool_t blocks_written = FALSE; /* Flag to indicate that chunk was actually written */
hbool_t using_mpi =
Expand Down Expand Up @@ -4401,10 +4399,9 @@ H5D__chunk_allocate(const H5D_io_info_t *io_info, hbool_t full_overwrite, const
if (should_fill) {
/* Initialize the fill value buffer */
/* (delay allocating fill buffer for VL datatypes until refilling) */
/* (casting away const OK - QAK) */
if (H5D__fill_init(&fb_info, NULL, (H5MM_allocate_t)H5D__chunk_mem_alloc, (void *)pline,
(H5MM_free_t)H5D__chunk_mem_free, (void *)pline, &dset->shared->dcpl_cache.fill,
dset->shared->type, dset->shared->type_id, (size_t)0, orig_chunk_size) < 0)
if (H5D__fill_init(&fb_info, NULL, H5D__chunk_mem_alloc, pline, H5D__chunk_mem_free, pline,
&dset->shared->dcpl_cache.fill, dset->shared->type, dset->shared->type_id,
(size_t)0, orig_chunk_size) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't initialize fill buffer info")
fb_info_init = TRUE;

Expand Down
10 changes: 5 additions & 5 deletions src/H5Dint.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

/* General stuff */
static H5D_shared_t *H5D__new(hid_t dcpl_id, hid_t dapl_id, hbool_t creating, hbool_t vl_type);
static herr_t H5D__init_type(H5F_t *file, const H5D_t *dset, hid_t type_id, const H5T_t *type);
static herr_t H5D__init_type(H5F_t *file, const H5D_t *dset, hid_t type_id, H5T_t *type);
static herr_t H5D__cache_dataspace_info(const H5D_t *dset);
static herr_t H5D__init_space(H5F_t *file, const H5D_t *dset, const H5S_t *space);
static herr_t H5D__update_oh_info(H5F_t *file, H5D_t *dset, hid_t dapl_id);
Expand Down Expand Up @@ -470,7 +470,7 @@ H5D__new(hid_t dcpl_id, hid_t dapl_id, hbool_t creating, hbool_t vl_type)
*-------------------------------------------------------------------------
*/
static herr_t
H5D__init_type(H5F_t *file, const H5D_t *dset, hid_t type_id, const H5T_t *type)
H5D__init_type(H5F_t *file, const H5D_t *dset, hid_t type_id, H5T_t *type)
{
htri_t relocatable; /* Flag whether the type is relocatable */
htri_t immutable; /* Flag whether the type is immutable */
Expand Down Expand Up @@ -526,8 +526,8 @@ H5D__init_type(H5F_t *file, const H5D_t *dset, hid_t type_id, const H5T_t *type)

/* Use existing datatype */
dset->shared->type_id = type_id;
dset->shared->type = (H5T_t *)type; /* (Cast away const OK - QAK) */
} /* end else */
dset->shared->type = type;
} /* end else */

done:
FUNC_LEAVE_NOAPI(ret_value)
Expand Down Expand Up @@ -2199,7 +2199,7 @@ H5D_oloc(H5D_t *dataset)
*-------------------------------------------------------------------------
*/
H5G_name_t *
H5D_nameof(const H5D_t *dataset)
H5D_nameof(H5D_t *dataset)
{
/* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */
FUNC_ENTER_NOAPI_NOINIT_NOERR
Expand Down
24 changes: 12 additions & 12 deletions src/H5Dio.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,20 +496,20 @@ H5D__read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, const H5S_t
*/
if (TRUE == H5S_SELECT_SHAPE_SAME(mem_space, file_space) &&
H5S_GET_EXTENT_NDIMS(mem_space) != H5S_GET_EXTENT_NDIMS(file_space)) {
void *adj_buf = NULL; /* Pointer to the location in buf corresponding */
/* to the beginning of the projected mem space. */
ptrdiff_t buf_adj = 0;

/* Attempt to construct projected dataspace for memory dataspace */
if (H5S_select_construct_projection(mem_space, &projected_mem_space,
(unsigned)H5S_GET_EXTENT_NDIMS(file_space), buf,
(const void **)&adj_buf, type_info.dst_type_size) < 0)
(unsigned)H5S_GET_EXTENT_NDIMS(file_space),
type_info.dst_type_size, &buf_adj) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to construct projected memory dataspace")
HDassert(projected_mem_space);
HDassert(adj_buf);

/* Adjust the buffer by the given amount */
buf = (void *)(((uint8_t *)buf) + buf_adj);

/* Switch to using projected memory dataspace & adjusted buffer */
mem_space = projected_mem_space;
buf = adj_buf;
} /* end if */

/* Retrieve dataset properties */
Expand Down Expand Up @@ -735,20 +735,20 @@ H5D__write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, const H5S_
*/
if (TRUE == H5S_SELECT_SHAPE_SAME(mem_space, file_space) &&
H5S_GET_EXTENT_NDIMS(mem_space) != H5S_GET_EXTENT_NDIMS(file_space)) {
void *adj_buf = NULL; /* Pointer to the location in buf corresponding */
/* to the beginning of the projected mem space. */
ptrdiff_t buf_adj = 0;

/* Attempt to construct projected dataspace for memory dataspace */
if (H5S_select_construct_projection(mem_space, &projected_mem_space,
(unsigned)H5S_GET_EXTENT_NDIMS(file_space), buf,
(const void **)&adj_buf, type_info.src_type_size) < 0)
(unsigned)H5S_GET_EXTENT_NDIMS(file_space),
type_info.src_type_size, &buf_adj) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to construct projected memory dataspace")
HDassert(projected_mem_space);
HDassert(adj_buf);

/* Adjust the buffer by the given amount */
buf = (const void *)(((const uint8_t *)buf) + buf_adj);

/* Switch to using projected memory dataspace & adjusted buffer */
mem_space = projected_mem_space;
buf = adj_buf;
} /* end if */

/* Retrieve dataset properties */
Expand Down
10 changes: 5 additions & 5 deletions src/H5Dpkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ H5_DLL herr_t H5D__select_write(const H5D_io_info_t *io_info, const H5D_type_inf
hsize_t nelmts, const H5S_t *file_space, const H5S_t *mem_space);

/* Functions that perform direct copying between memory buffers */
H5_DLL herr_t H5D_select_io_mem(void *dst_buf, const H5S_t *dst_space, const void *src_buf,
const H5S_t *src_space, size_t elmt_size, size_t nelmts);
H5_DLL herr_t H5D_select_io_mem(void *dst_buf, H5S_t *dst_space, const void *src_buf, H5S_t *src_space,
size_t elmt_size, size_t nelmts);

/* Functions that perform scatter-gather serial I/O operations */
H5_DLL herr_t H5D__scatter_mem(const void *_tscat_buf, H5S_sel_iter_t *iter, size_t nelmts, void *_buf);
Expand Down Expand Up @@ -647,9 +647,9 @@ H5_DLL herr_t H5D__chunk_allocate(const H5D_io_info_t *io_info, hbool_t full_ov
const hsize_t old_dim[]);
H5_DLL herr_t H5D__chunk_file_alloc(const H5D_chk_idx_info_t *idx_info, const H5F_block_t *old_chunk,
H5F_block_t *new_chunk, hbool_t *need_insert, hsize_t scaled[]);
H5_DLL void * H5D__chunk_mem_alloc(size_t size, const H5O_pline_t *pline);
H5_DLL void H5D__chunk_mem_free(void *chk, const H5O_pline_t *_pline);
H5_DLL void * H5D__chunk_mem_xfree(void *chk, const H5O_pline_t *pline);
H5_DLL void * H5D__chunk_mem_alloc(size_t size, void *pline);
H5_DLL void H5D__chunk_mem_free(void *chk, void *pline);
H5_DLL void * H5D__chunk_mem_xfree(void *chk, const void *pline);
H5_DLL void * H5D__chunk_mem_realloc(void *chk, size_t size, const H5O_pline_t *pline);
H5_DLL herr_t H5D__chunk_update_old_edge_chunks(H5D_t *dset, hsize_t old_dim[]);
H5_DLL hbool_t H5D__chunk_is_partial_edge_chunk(unsigned dset_ndims, const uint32_t *chunk_dims,
Expand Down
2 changes: 1 addition & 1 deletion src/H5Dprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ H5_DLL herr_t H5D_close(H5D_t *dataset);
H5_DLL herr_t H5D_mult_refresh_close(hid_t dset_id);
H5_DLL herr_t H5D_mult_refresh_reopen(H5D_t *dataset);
H5_DLL H5O_loc_t *H5D_oloc(H5D_t *dataset);
H5_DLL H5G_name_t *H5D_nameof(const H5D_t *dataset);
H5_DLL H5G_name_t *H5D_nameof(H5D_t *dataset);
H5_DLL H5T_t *H5D_typeof(const H5D_t *dset);
H5_DLL herr_t H5D_flush_all(const H5F_t *f);
H5_DLL hid_t H5D_get_create_plist(const H5D_t *dset);
Expand Down
4 changes: 2 additions & 2 deletions src/H5Dselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, size_t nelmts, co
*-------------------------------------------------------------------------
*/
herr_t
H5D_select_io_mem(void *dst_buf, const H5S_t *dst_space, const void *src_buf, const H5S_t *src_space,
size_t elmt_size, size_t nelmts)
H5D_select_io_mem(void *dst_buf, H5S_t *dst_space, const void *src_buf, H5S_t *src_space, size_t elmt_size,
size_t nelmts)
{
H5S_sel_iter_t *dst_sel_iter = NULL; /* Destination dataspace iteration info */
H5S_sel_iter_t *src_sel_iter = NULL; /* Source dataspace iteration info */
Expand Down
5 changes: 2 additions & 3 deletions src/H5Gent.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ H5G_ent_encode(const H5F_t *f, uint8_t **pp, const H5G_entry_t *ent)
*-------------------------------------------------------------------------
*/
void
H5G__ent_copy(H5G_entry_t *dst, const H5G_entry_t *src, H5_copy_depth_t depth)
H5G__ent_copy(H5G_entry_t *dst, H5G_entry_t *src, H5_copy_depth_t depth)
{
FUNC_ENTER_PACKAGE_NOERR

Expand All @@ -321,8 +321,7 @@ H5G__ent_copy(H5G_entry_t *dst, const H5G_entry_t *src, H5_copy_depth_t depth)
;
}
else if (depth == H5_COPY_SHALLOW) {
/* Discarding 'const' qualifier OK - QAK */
H5G__ent_reset((H5G_entry_t *)src);
H5G__ent_reset(src);
} /* end if */

FUNC_LEAVE_NOAPI_VOID
Expand Down
22 changes: 11 additions & 11 deletions src/H5Gloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@ H5G_loc_find_by_idx(const H5G_loc_t *loc, const char *group_name, H5_index_t idx
*-------------------------------------------------------------------------
*/
herr_t
H5G__loc_insert(H5G_loc_t *grp_loc, const char *name, H5G_loc_t *obj_loc, H5O_type_t obj_type,
const void *crt_info)
H5G__loc_insert(H5G_loc_t *grp_loc, char *name, H5G_loc_t *obj_loc, H5O_type_t obj_type, const void *crt_info)
{
H5O_link_t lnk; /* Link for object to insert */
herr_t ret_value = SUCCEED; /* Return value */
Expand All @@ -537,9 +536,8 @@ H5G__loc_insert(H5G_loc_t *grp_loc, const char *name, H5G_loc_t *obj_loc, H5O_ty
lnk.cset = H5F_DEFAULT_CSET;
lnk.corder = 0; /* Will be reset if the group is tracking creation order */
lnk.corder_valid = FALSE; /* Indicate that the creation order isn't valid (yet) */
/* Casting away const OK -QAK */
lnk.name = (char *)name;
lnk.u.hard.addr = obj_loc->oloc->addr;
lnk.name = name;
lnk.u.hard.addr = obj_loc->oloc->addr;

/* Insert new group into current group's symbol table */
if (H5G_obj_insert(grp_loc->oloc, name, &lnk, TRUE, obj_type, crt_info) < 0)
Expand Down Expand Up @@ -722,10 +720,10 @@ H5G__loc_set_comment_cb(H5G_loc_t H5_ATTR_UNUSED *grp_loc /*in*/, const char H5_
const H5O_link_t H5_ATTR_UNUSED *lnk, H5G_loc_t *obj_loc, void *_udata /*in,out*/,
H5G_own_loc_t *own_loc /*out*/)
{
H5G_loc_sc_t *udata = (H5G_loc_sc_t *)_udata; /* User data passed in */
H5O_name_t comment; /* Object header "comment" message */
htri_t exists; /* Whether a "comment" message already exists */
herr_t ret_value = SUCCEED; /* Return value */
H5G_loc_sc_t *udata = (H5G_loc_sc_t *)_udata; /* User data passed in */
H5O_name_t comment = {0}; /* Object header "comment" message */
htri_t exists; /* Whether a "comment" message already exists */
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_STATIC

Expand All @@ -745,13 +743,15 @@ H5G__loc_set_comment_cb(H5G_loc_t H5_ATTR_UNUSED *grp_loc /*in*/, const char H5_

/* Add the new message */
if (udata->comment && *udata->comment) {
/* Casting away const OK -QAK */
comment.s = (char *)udata->comment;
if (NULL == (comment.s = HDstrdup(udata->comment)))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't copy group comment")
if (H5O_msg_create(obj_loc->oloc, H5O_NAME_ID, 0, H5O_UPDATE_TIME, &comment) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL, "unable to set comment object header message")
} /* end if */

done:
HDfree(comment.s);

/* Indicate that this callback didn't take ownership of the group *
* location for the object */
*own_loc = H5G_OWN_NONE;
Expand Down
Loading

0 comments on commit 6661718

Please sign in to comment.