summaryrefslogtreecommitdiffstats
path: root/src/H5FL.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/H5FL.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/H5FL.c')
-rw-r--r--src/H5FL.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/H5FL.c b/src/H5FL.c
index cf14880..4045079 100644
--- a/src/H5FL.c
+++ b/src/H5FL.c
@@ -162,7 +162,7 @@ H5FL_reg_init(H5FL_reg_head_t *head)
/* Allocate a new garbage collection node */
if (NULL==(new_node = H5MM_malloc(sizeof(H5FL_reg_gc_node_t))))
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
/* Initialize the new garbage collection node */
new_node->list=head;
@@ -178,6 +178,7 @@ H5FL_reg_init(H5FL_reg_head_t *head)
if(head->size<sizeof(void *))
head->size=sizeof(void *);
+done:
FUNC_LEAVE (ret_value);
} /* end H5FL_reg_init() */
@@ -292,17 +293,17 @@ H5FL_reg_alloc(H5FL_reg_head_t *head, unsigned clear)
/* Otherwise allocate a node */
else {
if (NULL==(ret_value = H5FL_malloc(head->size)))
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
/* Increment the number of blocks allocated in list */
head->allocated++;
} /* end else */
/* Clear to zeros, if asked */
- if(clear) {
+ if(clear)
HDmemset(ret_value,0,head->size);
- } /* end if */
+done:
FUNC_LEAVE (ret_value);
} /* end H5FL_reg_alloc() */
@@ -500,7 +501,7 @@ static H5FL_blk_node_t *
H5FL_blk_find_list(H5FL_blk_node_t **head, size_t size)
{
H5FL_blk_node_t *temp; /* Temp. pointer to node in the native list */
- H5FL_blk_node_t *ret_value=NULL;
+ H5FL_blk_node_t *ret_value;
FUNC_ENTER_NOINIT(H5FL_blk_find_list);
@@ -554,7 +555,7 @@ static H5FL_blk_node_t *
H5FL_blk_create_list(H5FL_blk_node_t **head, size_t size)
{
H5FL_blk_node_t *temp; /* Temp. pointer to node in the list */
- H5FL_blk_node_t *ret_value=NULL;
+ H5FL_blk_node_t *ret_value;
FUNC_ENTER_NOINIT(H5FL_blk_create_list);
@@ -611,7 +612,7 @@ H5FL_blk_init(H5FL_blk_head_t *head)
/* Allocate a new garbage collection node */
if (NULL==(new_node = H5MM_malloc(sizeof(H5FL_blk_gc_node_t))))
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
/* Initialize the new garbage collection node */
new_node->pq=head;
@@ -623,6 +624,7 @@ H5FL_blk_init(H5FL_blk_head_t *head)
/* Indicate that the PQ is initialized */
head->init=1;
+done:
FUNC_LEAVE (ret_value);
} /* end H5FL_blk_init() */
@@ -699,9 +701,8 @@ H5FL_blk_alloc(H5FL_blk_head_t *head, size_t size, unsigned clear)
} /* end else */
/* Clear the block to zeros, if requested */
- if(clear) {
+ if(clear)
HDmemset(ret_value,0,size);
- } /* end if */
done:
FUNC_LEAVE(ret_value);
@@ -1021,7 +1022,7 @@ H5FL_arr_init(H5FL_arr_head_t *head)
/* Allocate a new garbage collection node */
if (NULL==(new_node = H5MM_malloc(sizeof(H5FL_gc_arr_node_t))))
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
/* Initialize the new garbage collection node */
new_node->list=head;
@@ -1033,9 +1034,9 @@ H5FL_arr_init(H5FL_arr_head_t *head)
/* Allocate room for the free lists, if the arrays have a maximum size */
if(head->maxelem>0) {
if (NULL==(head->u.list_arr = H5MM_calloc(head->maxelem*sizeof(H5FL_arr_node_t *))))
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
if (NULL==(head->onlist = H5MM_calloc(head->maxelem*sizeof(unsigned))))
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
} /* end if */
else {
head->u.queue.init=0;
@@ -1049,6 +1050,7 @@ H5FL_arr_init(H5FL_arr_head_t *head)
/* Indicate that the free list is initialized */
head->init=1;
+done:
FUNC_LEAVE (ret_value);
} /* end H5FL_arr_init() */
@@ -1074,12 +1076,13 @@ H5FL_arr_free(H5FL_arr_head_t *head, void *obj)
H5FL_arr_node_t *temp; /* Temp. ptr to the new free list node allocated */
size_t mem_size; /* Size of memory being freed */
size_t free_nelem; /* Number of elements in node being free'd */
+ void *ret_value=NULL; /* Return value */
FUNC_ENTER_NOAPI(H5FL_arr_free, NULL);
/* The H5MM_xfree code allows obj to null */
if (!obj)
- HRETURN (NULL);
+ HGOTO_DONE (NULL);
/* Double check parameters */
assert(head);
@@ -1125,11 +1128,11 @@ H5FL_arr_free(H5FL_arr_head_t *head, void *obj)
} /* end if */
/* No maximum number of elements, use block routine */
- else {
+ else
H5FL_blk_free(&(head->u.queue),obj);
- } /* end else */
- FUNC_LEAVE(NULL);
+done:
+ FUNC_LEAVE(ret_value);
} /* end H5FL_arr_free() */
@@ -1194,7 +1197,7 @@ H5FL_arr_alloc(H5FL_arr_head_t *head, size_t elem, unsigned clear)
/* Otherwise allocate a node */
else {
if (NULL==(new_obj = H5FL_malloc(sizeof(H5FL_arr_node_t)+mem_size)))
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
/* Increment the number of blocks allocated in list */
head->allocated++;
@@ -1211,10 +1214,10 @@ H5FL_arr_alloc(H5FL_arr_head_t *head, size_t elem, unsigned clear)
HDmemset(ret_value,0,mem_size);
} /* end if */
/* No fixed number of elements, use PQ routine */
- else {
+ else
ret_value=H5FL_blk_alloc(&(head->u.queue),mem_size,clear);
- } /* end else */
+done:
FUNC_LEAVE (ret_value);
} /* end H5FL_arr_alloc() */
@@ -1272,9 +1275,8 @@ H5FL_arr_realloc(H5FL_arr_head_t *head, void * obj, size_t new_elem)
ret_value=obj;
} /* end if */
/* No fixed number of elements, use block routine */
- else {
+ else
ret_value=H5FL_blk_realloc(&(head->u.queue),obj,head->size*new_elem);
- } /* end else */
} /* end else */
FUNC_LEAVE (ret_value);
@@ -1344,9 +1346,8 @@ H5FL_arr_gc_list(H5FL_arr_head_t *head)
} /* end if */
/* No maximum number of elements, use the block call to garbage collect */
- else {
+ else
H5FL_blk_gc_list(&(head->u.queue));
- } /* end else */
FUNC_LEAVE(SUCCEED);
} /* end H5FL_arr_gc_list() */