summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2020-01-30 19:01:25 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2020-01-30 19:01:25 (GMT)
commit9da387342eea566659daed83c850220cee041059 (patch)
tree4ef05589271e0800fb5bf853bad09cd1c4dfeb7c
parentd1f2eff23148da5e39463bd351be51767755b1c1 (diff)
downloadhdf5-9da387342eea566659daed83c850220cee041059.zip
hdf5-9da387342eea566659daed83c850220cee041059.tar.gz
hdf5-9da387342eea566659daed83c850220cee041059.tar.bz2
Added a free wrapper that lets us free constant pointers without
generating warnings. Also, brought the const-ness of the VOL connector info in line with the VFD info (not visible externally).
-rw-r--r--src/H5CX.c6
-rw-r--r--src/H5Eint.c8
-rw-r--r--src/H5FD.c13
-rw-r--r--src/H5MM.c26
-rw-r--r--src/H5MMprivate.h1
-rw-r--r--src/H5Pfapl.c17
-rw-r--r--src/H5VLint.c14
-rw-r--r--src/H5VLprivate.h2
8 files changed, 62 insertions, 25 deletions
diff --git a/src/H5CX.c b/src/H5CX.c
index 160aa84..244439e 100644
--- a/src/H5CX.c
+++ b/src/H5CX.c
@@ -1034,6 +1034,7 @@ H5CX_restore_state(const H5CX_state_t *api_state)
*
*-------------------------------------------------------------------------
*/
+H5_GCC_DIAG_OFF(cast-qual)
herr_t
H5CX_free_state(H5CX_state_t *api_state)
{
@@ -1071,9 +1072,9 @@ H5CX_free_state(H5CX_state_t *api_state)
/* Release the VOL connector property, if it was set */
if(api_state->vol_connector_prop.connector_id) {
- /* Clean up any VOL connector info */
+ /* Clean up any VOL connector info, ignoring const-ness of connector info */
if(api_state->vol_connector_prop.connector_info)
- if(H5VL_free_connector_info(api_state->vol_connector_prop.connector_id, api_state->vol_connector_prop.connector_info) < 0)
+ if(H5VL_free_connector_info(api_state->vol_connector_prop.connector_id, (void *)api_state->vol_connector_prop.connector_info) < 0)
HGOTO_ERROR(H5E_CONTEXT, H5E_CANTRELEASE, FAIL, "unable to release VOL connector info object")
/* Decrement connector ID */
if(H5I_dec_ref(api_state->vol_connector_prop.connector_id) < 0)
@@ -1086,6 +1087,7 @@ H5CX_free_state(H5CX_state_t *api_state)
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5CX_free_state() */
+H5_GCC_DIAG_ON(cast-qual)
/*-------------------------------------------------------------------------
diff --git a/src/H5Eint.c b/src/H5Eint.c
index e76db82..acd5b28 100644
--- a/src/H5Eint.c
+++ b/src/H5Eint.c
@@ -883,12 +883,12 @@ H5E__clear_entries(H5E_t *estack, size_t nentries)
/* Release strings */
if(error->func_name)
- error->func_name = (const char *) H5MM_xfree((void *)error->func_name); /* Casting away const OK - QAK */
+ error->func_name = (const char *) H5MM_xfree_const(error->func_name);
if(error->file_name)
- error->file_name = (const char *) H5MM_xfree((void *)error->file_name); /* Casting away const OK - QAK */
+ error->file_name = (const char *) H5MM_xfree_const(error->file_name);
if(error->desc)
- error->desc = (const char *) H5MM_xfree((void *)error->desc); /* Casting away const OK - QAK */
- } /* end for */
+ error->desc = (const char *) H5MM_xfree_const(error->desc);
+ }
/* Decrement number of errors on stack */
estack->nused -= u;
diff --git a/src/H5FD.c b/src/H5FD.c
index 1a4ab4d..0cc5654 100644
--- a/src/H5FD.c
+++ b/src/H5FD.c
@@ -574,6 +574,7 @@ done:
*
*-------------------------------------------------------------------------
*/
+H5_GCC_DIAG_OFF(cast-qual)
herr_t
H5FD_fapl_close(hid_t driver_id, const void *driver_info)
{
@@ -591,17 +592,19 @@ H5FD_fapl_close(hid_t driver_id, const void *driver_info)
/* Allow driver to free info or do it ourselves */
if(driver_info) {
if(driver->fapl_free) {
- if((driver->fapl_free)((void *)driver_info) < 0) /* Casting away const OK -QAK */
+ /* Free the const pointer (why we turn off the diagnostic) */
+ if((driver->fapl_free)((void *)driver_info) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTFREE, FAIL, "driver free request failed")
- } /* end if */
+ }
else
- driver_info = H5MM_xfree((void *)driver_info); /* Casting away const OK -QAK */
- } /* end if */
- } /* end if */
+ driver_info = H5MM_xfree_const(driver_info);
+ }
+ }
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_fapl_close() */
+H5_GCC_DIAG_ON(cast-qual)
/*-------------------------------------------------------------------------
diff --git a/src/H5MM.c b/src/H5MM.c
index ac3c26e..dae3f81 100644
--- a/src/H5MM.c
+++ b/src/H5MM.c
@@ -566,6 +566,32 @@ H5MM_xfree(void *mem)
/*-------------------------------------------------------------------------
+ * Function: H5MM_xfree_const
+ *
+ * Purpose: H5MM_xfree() wrapper that handles const pointers without
+ * warnings. Used for freeing buffers that should be regarded
+ * as const in use but need to be freed when no longer needed.
+ *
+ * Return: Success: NULL
+ * Failure: never fails
+ *
+ *-------------------------------------------------------------------------
+ */
+H5_GCC_DIAG_OFF(cast-qual)
+void *
+H5MM_xfree_const(const void *mem)
+{
+ /* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
+
+ H5MM_xfree((void *)mem);
+
+ FUNC_LEAVE_NOAPI(NULL)
+} /* end H5MM_xfree_const() */
+H5_GCC_DIAG_ON(cast-qual)
+
+
+/*-------------------------------------------------------------------------
* Function: H5MM_memcpy
*
* Purpose: Like memcpy(3) but with sanity checks on the parameters,
diff --git a/src/H5MMprivate.h b/src/H5MMprivate.h
index 2053215..240b931 100644
--- a/src/H5MMprivate.h
+++ b/src/H5MMprivate.h
@@ -45,6 +45,7 @@ H5_DLL void *H5MM_realloc(void *mem, size_t size);
H5_DLL char *H5MM_xstrdup(const char *s);
H5_DLL char *H5MM_strdup(const char *s);
H5_DLL void *H5MM_xfree(void *mem);
+H5_DLL void *H5MM_xfree_const(const void *mem);
H5_DLL void *H5MM_memcpy(void *dest, const void *src, size_t n);
#if defined H5_MEMORY_ALLOC_SANITY_CHECK
H5_DLL void H5MM_sanity_check_all(void);
diff --git a/src/H5Pfapl.c b/src/H5Pfapl.c
index 3668229..f238466 100644
--- a/src/H5Pfapl.c
+++ b/src/H5Pfapl.c
@@ -1146,6 +1146,7 @@ done:
*
*-------------------------------------------------------------------------
*/
+H5_GCC_DIAG_OFF(cast-qual)
static herr_t
H5P__file_driver_free(void *value)
{
@@ -1167,22 +1168,24 @@ H5P__file_driver_free(void *value)
/* Allow driver to free info or do it ourselves */
if(driver->fapl_free) {
- if((driver->fapl_free)((void *)info->driver_info) < 0) /* Casting away const OK -QAK */
+ /* Free the const pointer (why we turn off the diagnostic) */
+ if((driver->fapl_free)((void *)info->driver_info) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTFREE, FAIL, "driver info free request failed")
- } /* end if */
+ }
else
- H5MM_xfree((void *)info->driver_info); /* Casting away const OK -QAK */
- } /* end if */
+ H5MM_xfree_const(info->driver_info);
+ }
/* Decrement reference count for driver */
if(H5I_dec_ref(info->driver_id) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTDEC, FAIL, "can't decrement reference count for driver ID")
- } /* end if */
- } /* end if */
+ }
+ }
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5P__file_driver_free() */
+H5_GCC_DIAG_ON(cast-qual)
/*-------------------------------------------------------------------------
@@ -5407,7 +5410,7 @@ H5P_set_vol(H5P_genplist_t *plist, hid_t vol_id, const void *vol_info)
/* Prepare the VOL connector property */
vol_prop.connector_id = vol_id;
- vol_prop.connector_info = (void *)vol_info;
+ vol_prop.connector_info = vol_info;
/* Set the connector ID & info property */
if(H5P_set(plist, H5F_ACS_VOL_CONN_NAME, &vol_prop) < 0)
diff --git a/src/H5VLint.c b/src/H5VLint.c
index 39b0f53..df1f7a4 100644
--- a/src/H5VLint.c
+++ b/src/H5VLint.c
@@ -318,7 +318,7 @@ H5VL__free_cls(H5VL_class_t *cls)
HGOTO_ERROR(H5E_VOL, H5E_CANTCLOSEOBJ, FAIL, "VOL connector did not terminate cleanly")
/* Release the class */
- H5MM_xfree((void *)cls->name); /* Casting away const OK -QAK */
+ H5MM_xfree_const(cls->name);
H5FL_FREE(H5VL_class_t, cls);
done:
@@ -670,6 +670,7 @@ done:
*
*-------------------------------------------------------------------------
*/
+H5_GCC_DIAG_OFF(cast-qual)
herr_t
H5VL_conn_free(const H5VL_connector_prop_t *connector_prop)
{
@@ -681,19 +682,20 @@ H5VL_conn_free(const H5VL_connector_prop_t *connector_prop)
/* Free the connector info (if it exists) and decrement the ID */
if(connector_prop->connector_id > 0) {
if(connector_prop->connector_info)
- /* Free the connector info */
- if(H5VL_free_connector_info(connector_prop->connector_id, (void *)connector_prop->connector_info) < 0) /* Casting away const OK - QAK */
+ /* Free the connector info, ignoring the const */
+ if(H5VL_free_connector_info(connector_prop->connector_id, (void *)connector_prop->connector_info) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release VOL connector info object")
/* Decrement reference count for connector ID */
if(H5I_dec_ref(connector_prop->connector_id) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "can't decrement reference count for connector ID")
- } /* end if */
- } /* end if */
+ }
+ }
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_conn_free() */
+H5_GCC_DIAG_ON(cast-qual)
/*-------------------------------------------------------------------------
@@ -1144,7 +1146,7 @@ H5VL_register_connector(const void *_cls, hbool_t app_ref, hid_t vipl_id)
done:
if(ret_value < 0 && saved) {
if(saved->name)
- H5MM_xfree((void *)(saved->name)); /* Casting away const OK -QAK */
+ H5MM_xfree_const(saved->name);
H5FL_FREE(H5VL_class_t, saved);
} /* end if */
diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h
index 24ae1f3..27dd18c 100644
--- a/src/H5VLprivate.h
+++ b/src/H5VLprivate.h
@@ -44,7 +44,7 @@ typedef struct H5VL_object_t {
/* Internal structure to hold the connector ID & info for FAPLs */
typedef struct H5VL_connector_prop_t {
hid_t connector_id; /* VOL connector's ID */
- void *connector_info; /* VOL connector info, for open callbacks */
+ const void *connector_info; /* VOL connector info, for open callbacks */
} H5VL_connector_prop_t;
/* Which kind of VOL connector field to use for searching */