summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2020-01-31 00:50:41 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2020-01-31 00:50:41 (GMT)
commit0147d2493eed235ba31077a6da38608ce2fe152a (patch)
treec2bf4154aa88d4cf42801bbadd26dafde9815da9
parent0e56affc7e484ef1a8c306aeec7be8049af13f80 (diff)
parent10301154215fb6a22590e80f7b5ed0005f3e1786 (diff)
downloadhdf5-0147d2493eed235ba31077a6da38608ce2fe152a.zip
hdf5-0147d2493eed235ba31077a6da38608ce2fe152a.tar.gz
hdf5-0147d2493eed235ba31077a6da38608ce2fe152a.tar.bz2
Merge pull request #2329 in HDFFV/hdf5 from ~DEROBINS/hdf5_der:H5MM_const to develop
* commit '10301154215fb6a22590e80f7b5ed0005f3e1786': Minor refactoring to the VFD info free call. Updated the 'const memory free' changes based on PR feedback. Added a free wrapper that lets us free constant pointers without generating warnings.
-rw-r--r--src/H5Eint.c8
-rw-r--r--src/H5FD.c30
-rw-r--r--src/H5FDprivate.h2
-rw-r--r--src/H5Fint.c2
-rw-r--r--src/H5MM.c25
-rw-r--r--src/H5MMprivate.h1
-rw-r--r--src/H5Pfapl.c24
-rw-r--r--src/H5VLcallback.c11
-rw-r--r--src/H5VLint.c10
-rw-r--r--src/H5VLprivate.h4
10 files changed, 67 insertions, 50 deletions
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..63112bd 100644
--- a/src/H5FD.c
+++ b/src/H5FD.c
@@ -202,7 +202,7 @@ H5FD__free_cls(H5FD_class_t *cls)
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_free_cls() */
+} /* end H5FD__free_cls() */
/*-------------------------------------------------------------------------
@@ -566,22 +566,22 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5FD_fapl_close
+ * Function: H5FD_free_driver_info
*
- * Purpose: Closes a driver for a dataset transfer property list
+ * Purpose: Frees a driver's info
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
-H5FD_fapl_close(hid_t driver_id, const void *driver_info)
+H5FD_free_driver_info(hid_t driver_id, const void *driver_info)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
- if(driver_id > 0) {
+ if(driver_id > 0 && driver_info) {
H5FD_class_t *driver;
/* Retrieve the driver for the ID */
@@ -589,19 +589,19 @@ H5FD_fapl_close(hid_t driver_id, const void *driver_info)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a driver ID")
/* 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 */
- 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 */
+ if(driver->fapl_free) {
+ /* Free the const pointer */
+ /* Cast through uintptr_t to de-const memory */
+ if((driver->fapl_free)((void *)(uintptr_t)driver_info) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTFREE, FAIL, "driver free request failed")
+ }
+ else
+ driver_info = H5MM_xfree_const(driver_info);
+ }
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5FD_fapl_close() */
+} /* end H5FD_free_driver_info() */
/*-------------------------------------------------------------------------
diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h
index ac08f7f..2e3d3ce 100644
--- a/src/H5FDprivate.h
+++ b/src/H5FDprivate.h
@@ -115,7 +115,7 @@ H5_DLL hsize_t H5FD_sb_size(H5FD_t *file);
H5_DLL herr_t H5FD_sb_encode(H5FD_t *file, char *name/*out*/, uint8_t *buf);
H5_DLL herr_t H5FD_sb_load(H5FD_t *file, const char *name, const uint8_t *buf);
H5_DLL void *H5FD_fapl_get(H5FD_t *file);
-H5_DLL herr_t H5FD_fapl_close(hid_t driver_id, const void *fapl);
+H5_DLL herr_t H5FD_free_driver_info(hid_t driver_id, const void *driver_info);
H5_DLL hid_t H5FD_register(const void *cls, size_t size, hbool_t app_ref);
H5_DLL H5FD_t *H5FD_open(const char *name, unsigned flags, hid_t fapl_id,
haddr_t maxaddr);
diff --git a/src/H5Fint.c b/src/H5Fint.c
index 74189c1..0000512 100644
--- a/src/H5Fint.c
+++ b/src/H5Fint.c
@@ -273,7 +273,7 @@ H5F_get_access_plist(H5F_t *f, hbool_t app_ref)
done:
/* Release the copy of the driver info, if it was set up */
- if(driver_prop_copied && H5FD_fapl_close(driver_prop.driver_id, driver_prop.driver_info) < 0)
+ if(driver_prop_copied && H5FD_free_driver_info(driver_prop.driver_id, driver_prop.driver_info) < 0)
HDONE_ERROR(H5E_FILE, H5E_CANTCLOSEOBJ, H5I_INVALID_HID, "can't close copy of driver info")
FUNC_LEAVE_NOAPI(ret_value)
diff --git a/src/H5MM.c b/src/H5MM.c
index ac3c26e..94bd542 100644
--- a/src/H5MM.c
+++ b/src/H5MM.c
@@ -566,6 +566,31 @@ 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
+ *
+ *-------------------------------------------------------------------------
+ */
+void *
+H5MM_xfree_const(const void *mem)
+{
+ /* Use FUNC_ENTER_NOAPI_NOINIT_NOERR here to avoid performance issues */
+ FUNC_ENTER_NOAPI_NOINIT_NOERR
+
+ /* Cast through uintptr_t to de-const memory */
+ H5MM_xfree((void *)(uintptr_t)mem);
+
+ FUNC_LEAVE_NOAPI(NULL)
+} /* end H5MM_xfree_const() */
+
+
+/*-------------------------------------------------------------------------
* 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..9a04c3e 100644
--- a/src/H5Pfapl.c
+++ b/src/H5Pfapl.c
@@ -1158,27 +1158,17 @@ H5P__file_driver_free(void *value)
/* Copy the driver & info, if there is one */
if(info->driver_id > 0) {
- if(info->driver_info) {
- H5FD_class_t *driver; /* Pointer to driver */
-
- /* Retrieve the driver for the ID */
- if(NULL == (driver = (H5FD_class_t *)H5I_object(info->driver_id)))
- HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a driver ID")
- /* 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 */
- 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 */
+ /* Free the driver info, if it exists */
+ if(info->driver_info)
+ if(H5FD_free_driver_info(info->driver_id, info->driver_info) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTFREE, FAIL, "driver info free request failed")
/* 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)
@@ -5407,7 +5397,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/H5VLcallback.c b/src/H5VLcallback.c
index e4ebb95..5c54b5b 100644
--- a/src/H5VLcallback.c
+++ b/src/H5VLcallback.c
@@ -525,7 +525,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5VL_free_connector_info(hid_t connector_id, void *info)
+H5VL_free_connector_info(hid_t connector_id, const void *info)
{
H5VL_class_t *cls; /* VOL connector's class struct */
herr_t ret_value = SUCCEED; /* Return value */
@@ -543,12 +543,13 @@ H5VL_free_connector_info(hid_t connector_id, void *info)
if(info) {
/* Allow the connector to free info or do it ourselves */
if(cls->info_cls.free) {
- if((cls->info_cls.free)(info) < 0)
+ /* Cast through uintptr_t to de-const memory */
+ if((cls->info_cls.free)((void *)(uintptr_t)info) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "connector info free request failed")
- } /* end if */
+ }
else
- H5MM_xfree(info);
- } /* end if */
+ H5MM_xfree_const(info);
+ }
done:
FUNC_LEAVE_NOAPI(ret_value)
diff --git a/src/H5VLint.c b/src/H5VLint.c
index 39b0f53..6572faa 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:
@@ -682,14 +682,14 @@ H5VL_conn_free(const H5VL_connector_prop_t *connector_prop)
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 */
+ if(H5VL_free_connector_info(connector_prop->connector_id, 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)
@@ -1144,7 +1144,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..3235357 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 */
@@ -128,7 +128,7 @@ H5_DLL int H5VL_copy_connector_info(const H5VL_class_t *connector, void **dst_in
const void *src_info);
H5_DLL herr_t H5VL_cmp_connector_info(const H5VL_class_t *connector, int *cmp_value,
const void *info1, const void *info2);
-H5_DLL herr_t H5VL_free_connector_info(hid_t connector_id, void *info);
+H5_DLL herr_t H5VL_free_connector_info(hid_t connector_id, const void *info);
/* Attribute functions */
H5_DLL void *H5VL_attr_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req);