summaryrefslogtreecommitdiffstats
path: root/src/H5MM.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2002-08-08 16:52:55 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2002-08-08 16:52:55 (GMT)
commitd8397a6f426227d09d20e647ce8b12b8c6295b2d (patch)
tree2943fbfd2bfb66cf167eb642835fdb4deb3afd3c /src/H5MM.c
parent573307786a1f5f7ce597e5191ea08c3bbd95b66c (diff)
downloadhdf5-d8397a6f426227d09d20e647ce8b12b8c6295b2d.zip
hdf5-d8397a6f426227d09d20e647ce8b12b8c6295b2d.tar.gz
hdf5-d8397a6f426227d09d20e647ce8b12b8c6295b2d.tar.bz2
[svn-r5842] Purpose:
Code cleanup Description: Change most (all?) HRETURN_ERROR macros to HGOTO_ERROR macros, along with HRETURN macros to HGOTO_DONE macros. This unifies the error return path from functions and reduces the size of the library by up to 10% on some platforms. Additionally, I improved a lot of the error cleanup code in many routines. Platforms tested: FreeBSD 4.6 (sleipnir) serial & parallel and IRIX64 6.5 (modi4) serial & parallel.
Diffstat (limited to 'src/H5MM.c')
-rw-r--r--src/H5MM.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/H5MM.c b/src/H5MM.c
index 3acc30b..fbd66f7 100644
--- a/src/H5MM.c
+++ b/src/H5MM.c
@@ -50,11 +50,14 @@ static int interface_initialize_g = 0;
void *
H5MM_realloc(void *mem, size_t size)
{
+ void *ret_value;
+
/* Use FUNC_ENTER_NOINIT here to avoid performance issues */
FUNC_ENTER_NOINIT(H5MM_realloc);
if (!mem) {
- if (0 == size) HRETURN(NULL);
+ if (0 == size)
+ HGOTO_DONE(NULL);
mem = H5MM_malloc(size);
} else if (0 == size) {
@@ -65,7 +68,11 @@ H5MM_realloc(void *mem, size_t size)
assert(mem);
}
- FUNC_LEAVE(mem);
+ /* Set return value */
+ ret_value=mem;
+
+done:
+ FUNC_LEAVE(ret_value);
}
@@ -91,17 +98,19 @@ H5MM_realloc(void *mem, size_t size)
char *
H5MM_xstrdup(const char *s)
{
- char *mem;
+ char *ret_value;
/* Use FUNC_ENTER_NOINIT here to avoid performance issues */
FUNC_ENTER_NOINIT(H5MM_xstrdup);
- if (!s) HRETURN(NULL);
- mem = H5MM_malloc(HDstrlen(s) + 1);
- assert (mem);
- HDstrcpy(mem, s);
+ if (!s)
+ HGOTO_DONE(NULL);
+ ret_value = H5MM_malloc(HDstrlen(s) + 1);
+ assert (ret_value);
+ HDstrcpy(ret_value, s);
- FUNC_LEAVE(mem);
+done:
+ FUNC_LEAVE(ret_value);
}
@@ -127,21 +136,18 @@ H5MM_xstrdup(const char *s)
char *
H5MM_strdup(const char *s)
{
- char *mem;
+ char *ret_value;
FUNC_ENTER_NOAPI(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);
+ if (!s)
+ HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, NULL, "null string");
+ if (NULL==(ret_value = H5MM_malloc(HDstrlen(s) + 1)))
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ HDstrcpy(ret_value, s);
- FUNC_LEAVE (mem);
+done:
+ FUNC_LEAVE (ret_value);
}
@@ -172,7 +178,8 @@ H5MM_xfree(void *mem)
/* Use FUNC_ENTER_NOINIT here to avoid performance issues */
FUNC_ENTER_NOINIT(H5MM_xfree);
- if (mem) HDfree(mem);
+ if (mem)
+ HDfree(mem);
FUNC_LEAVE(NULL);
}