summaryrefslogtreecommitdiffstats
path: root/src/H5.c
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2015-03-09 00:41:54 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2015-03-09 00:41:54 (GMT)
commit2a4ea9b24e5d28598b627fca39fb42a9baedfaa3 (patch)
tree5952db2c3be4eba3007958ccc98942cd255f776f /src/H5.c
parent63bd09ec8bb62e31b7ca52ce4c36d9bfd143c555 (diff)
downloadhdf5-2a4ea9b24e5d28598b627fca39fb42a9baedfaa3.zip
hdf5-2a4ea9b24e5d28598b627fca39fb42a9baedfaa3.tar.gz
hdf5-2a4ea9b24e5d28598b627fca39fb42a9baedfaa3.tar.bz2
[svn-r26392] Reinstates r26327-8, which had been reverted due to failures on
Solaris and OS X. Added public API functions that expose the C library's memory allocator for use in filter functions that need to allocate or resize buffers. Intended for use with filter plugins, particularly on Windows, where C runtime (CRT) issues can cause problems. Fixes: HDFFV-9100 Tested on: h5committest + OS X (quail) + Solaris (emu)
Diffstat (limited to 'src/H5.c')
-rw-r--r--src/H5.c89
1 files changed, 86 insertions, 3 deletions
diff --git a/src/H5.c b/src/H5.c
index 52dc566..68b339a 100644
--- a/src/H5.c
+++ b/src/H5.c
@@ -860,27 +860,109 @@ H5close(void)
/*-------------------------------------------------------------------------
+ * Function: H5allocate_memory
+ *
+ * Purpose: Allocate a memory buffer with the semantics of malloc().
+ *
+ * NOTE: This function is intended for use with filter
+ * plugins so that all allocation and free operations
+ * use the same memory allocator. It is not intended for
+ * use as a general memory allocator in applications.
+ *
+ * Parameters:
+ *
+ * size: The size of the buffer.
+ *
+ * clear: Whether or not to memset the buffer to 0.
+ *
+ * Return:
+ *
+ * Success: A pointer to the allocated buffer.
+ *
+ * Failure: NULL
+ *
+ *-------------------------------------------------------------------------
+ */
+void *
+H5allocate_memory(size_t size, hbool_t clear)
+{
+ void *ret_value = NULL;
+
+ FUNC_ENTER_API_NOINIT;
+ H5TRACE2("*x", "zb", size, clear);
+
+ if(clear)
+ ret_value = H5MM_calloc(size);
+ else
+ ret_value = H5MM_malloc(size);
+
+ FUNC_LEAVE_API(ret_value)
+
+} /* end H5allocate_memory() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5resize_memory
+ *
+ * Purpose: Resize a memory buffer with the semantics of realloc().
+ *
+ * NOTE: This function is intended for use with filter
+ * plugins so that all allocation and free operations
+ * use the same memory allocator. It is not intended for
+ * use as a general memory allocator in applications.
+ *
+ * Parameters:
+ *
+ * mem: The buffer to be resized.
+ *
+ * size: The size of the buffer.
+ *
+ * Return:
+ *
+ * Success: A pointer to the resized buffer.
+ *
+ * Failure: NULL (the input buffer will be unchanged)
+ *
+ *-------------------------------------------------------------------------
+ */
+void *
+H5resize_memory(void *mem, size_t size)
+{
+ void *ret_value = NULL;
+
+ FUNC_ENTER_API_NOINIT;
+ H5TRACE2("*x", "*xz", mem, size);
+
+ ret_value = H5MM_realloc(mem, size);
+
+ FUNC_LEAVE_API(ret_value)
+
+} /* end H5resize_memory() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5free_memory
*
- * Purpose: Frees memory allocated by the library that it is the user's
+ * Purpose: Frees memory allocated by the library that it is the user's
* responsibility to free. Ensures that the same library
* that was used to allocate the memory frees it. Passing
* NULL pointers is allowed.
*
- * Return: SUCCEED/FAIL
+ * Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5free_memory(void *mem)
{
- FUNC_ENTER_API_NOINIT
+ FUNC_ENTER_API_NOINIT;
H5TRACE1("e", "*x", mem);
/* At this time, it is impossible for this to fail. */
HDfree(mem);
FUNC_LEAVE_API(SUCCEED)
+
} /* end H5free_memory() */
@@ -944,3 +1026,4 @@ DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved)
return fOkay;
}
#endif /* H5_HAVE_WIN32_API && H5_BUILT_AS_DYNAMIC_LIB && H5_HAVE_WIN_THREADS && H5_HAVE_THREADSAFE*/
+