summaryrefslogtreecommitdiffstats
path: root/src/H5MM.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-06-23 03:41:22 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-06-23 03:41:22 (GMT)
commit4bf629adc96541fda24bafbdde00fd4ff92be344 (patch)
tree8e6d57995ba50bafdf172df9d480bd99cdb1230e /src/H5MM.c
parent62607debf74800472572e65517ed284aef19a63c (diff)
downloadhdf5-4bf629adc96541fda24bafbdde00fd4ff92be344.zip
hdf5-4bf629adc96541fda24bafbdde00fd4ff92be344.tar.gz
hdf5-4bf629adc96541fda24bafbdde00fd4ff92be344.tar.bz2
[svn-r435] ./INSTALL
./INSTALL_MAINT ./README ./RELEASE Partially updated for second alpha, but haven't updated version numbers yet. ./src/H5.c ./src/H5A.c ./src/H5AC.c ./src/H5B.c ./src/H5D.c ./src/H5F.c ./src/H5Fcore.c ./src/H5Ffamily.c ./src/H5Fistore.c ./src/H5Fmpio.c ./src/H5Fsec2.c ./src/H5Fsplit.c ./src/H5Fstdio.c ./src/H5G.c ./src/H5Gnode.c ./src/H5HG.c ./src/H5HL.c ./src/H5I.c ./src/H5MM.c ./src/H5MMprivate.h ./src/H5O.c ./src/H5Oattr.c ./src/H5Ocomp.c ./src/H5Ocont.c ./src/H5Odtype.c ./src/H5Oefl.c ./src/H5Olayout.c ./src/H5Oname.c ./src/H5Osdspace.c ./src/H5Oshared.c ./src/H5Ostab.c ./src/H5P.c ./src/H5S.c ./src/H5T.c ./src/H5Tconv.c ./src/H5detect.c ./test/hyperslab.c ./test/istore.c Changed memory allocation functions so they fail instead of dumping core. The `x' was removed from the name to remind us of that: H5MM_xmalloc() -> H5MM_malloc(), etc. H5MM_calloc() takes one argument like H5MM_malloc() instead of two like calloc() because we almost always called it with `1' for one of the arguments anyway. The only difference between the two functions is that H5MM_calloc() returns memory which is initialized to zero. ./src/H5Gent.c ./src/H5Gprivate.h Removed H5G_ent_calloc() since it wasn't used. ./src/H5Fistore.c Fixed a bug found by Albert. Thanks, Albert! This fix combined with the changes to memory allocation prevent the library from failing an assertion if the application uses an unreasonable size for chunks (like Alberts 10000x10000x4). ./src/H5MF.c ./src/H5MFprivate.h Changed H5MF_free() to H5MF_xfree() since calling it with an undefined address is allowed.
Diffstat (limited to 'src/H5MM.c')
-rw-r--r--src/H5MM.c108
1 files changed, 47 insertions, 61 deletions
diff --git a/src/H5MM.c b/src/H5MM.c
index 5a02f41..af38125 100644
--- a/src/H5MM.c
+++ b/src/H5MM.c
@@ -15,41 +15,26 @@
*-------------------------------------------------------------------------
*/
#include <H5private.h>
+#include <H5Eprivate.h>
#include <H5MMprivate.h>
-
-/*-------------------------------------------------------------------------
- * Function: H5MM_xmalloc
- *
- * Purpose: Just like malloc(3) except it aborts on an error.
- *
- * Return: Success: Ptr to new memory.
- *
- * Failure: abort()
- *
- * Programmer: Robb Matzke
- * matzke@llnl.gov
- * Jul 10 1997
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-void *
-H5MM_xmalloc(size_t size)
-{
- void *mem = HDmalloc(size);
- assert(mem);
- return mem;
-}
+/* Interface initialization? */
+static hbool_t interface_initialize_g = FALSE;
+#define INTERFACE_INIT NULL
/*-------------------------------------------------------------------------
- * Function: H5MM_xcalloc
+ * Function: H5MM_realloc
*
- * Purpose: Just like calloc(3) except it aborts on an error.
+ * Purpose: Just like the POSIX version of realloc(3). Specifically, the
+ * following calls are equivalent
*
- * Return: Success: Ptr to memory.
+ * H5MM_realloc (NULL, size) <==> H5MM_malloc (size)
+ * H5MM_realloc (ptr, 0) <==> H5MM_xfree (ptr)
+ * H5MM_realloc (NULL, 0) <==> NULL
+ *
+ * Return: Success: Ptr to new memory or NULL if the memory
+ * was freed.
*
* Failure: abort()
*
@@ -62,34 +47,32 @@ H5MM_xmalloc(size_t size)
*-------------------------------------------------------------------------
*/
void *
-H5MM_xcalloc(intn n, size_t size)
+H5MM_realloc(void *mem, size_t size)
{
- void *mem = NULL;
+ if (!mem) {
+ if (0 == size) return NULL;
+ mem = H5MM_malloc(size);
- assert (n>=0);
+ } else if (0 == size) {
+ mem = H5MM_xfree(mem);
- if (n>0) {
- mem = HDcalloc((size_t)n, size);
+ } else {
+ mem = HDrealloc(mem, size);
assert(mem);
}
-
+
return mem;
}
/*-------------------------------------------------------------------------
- * Function: H5MM_xrealloc
- *
- * Purpose: Just like the POSIX version of realloc(3) exept it aborts
- * on an error. Specifically, the following calls are
- * equivalent
+ * Function: H5MM_xstrdup
*
- * H5MM_xrealloc (NULL, size) <==> H5MM_xmalloc (size)
- * H5MM_xrealloc (ptr, 0) <==> H5MM_xfree (ptr)
- * H5MM_xrealloc (NULL, 0) <==> NULL
+ * Purpose: Duplicates a string. If the string to be duplicated is the
+ * null pointer, then return null. If the string to be duplicated
+ * is the empty string then return a new empty string.
*
- * Return: Success: Ptr to new memory or NULL if the memory
- * was freed.
+ * Return: Success: Ptr to a new string (or null if no string).
*
* Failure: abort()
*
@@ -101,21 +84,15 @@ H5MM_xcalloc(intn n, size_t size)
*
*-------------------------------------------------------------------------
*/
-void *
-H5MM_xrealloc(void *mem, size_t size)
+char *
+H5MM_xstrdup(const char *s)
{
- if (!mem) {
- if (0 == size) return NULL;
- mem = H5MM_xmalloc(size);
-
- } else if (0 == size) {
- mem = H5MM_xfree(mem);
-
- } else {
- mem = HDrealloc(mem, size);
- assert(mem);
- }
+ char *mem;
+ if (!s) return NULL;
+ mem = H5MM_malloc(HDstrlen(s) + 1);
+ assert (mem);
+ HDstrcpy(mem, s);
return mem;
}
@@ -140,14 +117,23 @@ H5MM_xrealloc(void *mem, size_t size)
*-------------------------------------------------------------------------
*/
char *
-H5MM_xstrdup(const char *s)
+H5MM_strdup(const char *s)
{
char *mem;
- if (!s) return NULL;
- mem = H5MM_xmalloc(HDstrlen(s) + 1);
+ FUNC_ENTER (H5MM_strdup, NULL);
+
+ if (!s) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, NULL,
+ "null string");
+ }
+ if (NULL==(mem = H5MM_malloc(HDstrlen(s) + 1))) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
HDstrcpy(mem, s);
- return mem;
+
+ FUNC_LEAVE (mem);
}