summaryrefslogtreecommitdiffstats
path: root/src/H5FL.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2003-08-27 14:00:50 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2003-08-27 14:00:50 (GMT)
commitb259ca6f86657e1842f4ade4b15802f34080c11c (patch)
tree834f9fc7ef4eef325958dc1665fe9f60b4428c74 /src/H5FL.c
parent4bb0d2d2997063e233095f9303c47b3a6fbebf36 (diff)
downloadhdf5-b259ca6f86657e1842f4ade4b15802f34080c11c.zip
hdf5-b259ca6f86657e1842f4ade4b15802f34080c11c.tar.gz
hdf5-b259ca6f86657e1842f4ade4b15802f34080c11c.tar.bz2
[svn-r7417] Purpose:
Code cleanup Description: De-linted more code. Platforms tested: FreeBSD 4.8 (sleipnir) too minor to need h5committest
Diffstat (limited to 'src/H5FL.c')
-rw-r--r--src/H5FL.c241
1 files changed, 133 insertions, 108 deletions
diff --git a/src/H5FL.c b/src/H5FL.c
index 93fc902..b4c5613 100644
--- a/src/H5FL.c
+++ b/src/H5FL.c
@@ -26,14 +26,17 @@
* move frequently accessed free lists to the head of the queue.
*/
+/* Pablo information */
+/* (Put before include files to avoid problems with inline functions) */
+#define PABLO_MASK H5FL_mask
+
/* #define H5FL_DEBUG */
-#include "H5private.h" /*library */
-#include "H5Eprivate.h" /*error handling */
-#include "H5MMprivate.h" /*Core memory management */
-#include "H5FLprivate.h" /*Priority queues */
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5FLprivate.h" /* Free Lists */
+#include "H5MMprivate.h" /* Memory management */
-#define PABLO_MASK H5FL_mask
static int interface_initialize_g = 0;
#define INTERFACE_INIT NULL
@@ -130,20 +133,21 @@ H5FL_malloc(size_t mem_size)
{
void *ret_value=NULL; /* return value*/
- FUNC_ENTER_NOAPI(H5FL_malloc, NULL);
+ FUNC_ENTER_NOAPI(H5FL_malloc, NULL)
/* Attempt to allocate the memory requested */
if(NULL==(ret_value=H5MM_malloc(mem_size))) {
/* If we can't allocate the memory now, try garbage collecting first */
- H5FL_garbage_coll();
+ if(H5FL_garbage_coll()<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, NULL, "garbage collection failed during allocation")
/* Now try allocating the memory again */
if(NULL==(ret_value=H5MM_malloc(mem_size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for chunk");
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for chunk")
} /* end if */
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_malloc() */
@@ -169,11 +173,11 @@ H5FL_reg_init(H5FL_reg_head_t *head)
H5FL_reg_gc_node_t *new_node; /* Pointer to the node for the new list to garbage collect */
herr_t ret_value=SUCCEED; /* return value*/
- FUNC_ENTER_NOINIT(H5FL_reg_init);
+ FUNC_ENTER_NOINIT(H5FL_reg_init)
/* Allocate a new garbage collection node */
if (NULL==(new_node = H5MM_malloc(sizeof(H5FL_reg_gc_node_t))))
- HGOTO_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;
@@ -190,7 +194,7 @@ H5FL_reg_init(H5FL_reg_head_t *head)
head->size=sizeof(void *);
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_reg_init() */
@@ -215,7 +219,7 @@ H5FL_reg_free(H5FL_reg_head_t *head, void *obj)
H5FL_reg_node_t *temp; /* Temp. ptr to the new free list node allocated */
void *ret_value=NULL; /* Return value */
- FUNC_ENTER_NOAPI(H5FL_reg_free, NULL);
+ FUNC_ENTER_NOAPI(H5FL_reg_free, NULL)
/* Double check parameters */
assert(head);
@@ -247,14 +251,16 @@ H5FL_reg_free(H5FL_reg_head_t *head, void *obj)
/* Check for exceeding free list memory use limits */
/* First check this particular list */
if(head->list_mem>H5FL_reg_lst_mem_lim)
- H5FL_reg_gc_list(head);
+ if(H5FL_reg_gc_list(head)<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, NULL, "garbage collection failed during free")
/* Then check the global amount memory on regular free lists */
if(H5FL_reg_gc_head.mem_freed>H5FL_reg_glb_mem_lim)
- H5FL_reg_gc();
+ if(H5FL_reg_gc()<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, NULL, "garbage collection failed during free")
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_reg_free() */
@@ -278,14 +284,15 @@ H5FL_reg_malloc(H5FL_reg_head_t *head)
{
void *ret_value; /* Pointer to object to return */
- FUNC_ENTER_NOAPI(H5FL_reg_malloc, NULL);
+ FUNC_ENTER_NOAPI(H5FL_reg_malloc, NULL)
/* Double check parameters */
assert(head);
/* Make certain the list is initialized first */
if(!head->init)
- H5FL_reg_init(head);
+ if(H5FL_reg_init(head)<0)
+ HGOTO_ERROR (H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'regular' blocks")
/* Check for nodes available on the free list first */
if(head->list!=NULL) {
@@ -306,14 +313,14 @@ H5FL_reg_malloc(H5FL_reg_head_t *head)
/* Otherwise allocate a node */
else {
if (NULL==(ret_value = H5FL_malloc(head->size)))
- HGOTO_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 */
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_reg_malloc() */
@@ -337,20 +344,20 @@ H5FL_reg_calloc(H5FL_reg_head_t *head)
{
void *ret_value; /* Pointer to object to return */
- FUNC_ENTER_NOAPI(H5FL_reg_calloc, NULL);
+ FUNC_ENTER_NOAPI(H5FL_reg_calloc, NULL)
/* Double check parameters */
assert(head);
/* Allocate the block */
if (NULL==(ret_value = H5FL_reg_malloc(head)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
/* Clear to zeros */
HDmemset(ret_value,0,head->size);
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_reg_calloc() */
@@ -376,7 +383,7 @@ H5FL_reg_gc_list(H5FL_reg_head_t *head)
void *tmp; /* Temporary node pointer */
size_t total_mem; /* Total memory used on list */
- FUNC_ENTER_NOINIT(H5FL_reg_gc_list);
+ FUNC_ENTER_NOINIT(H5FL_reg_gc_list)
/* Calculate the total memory used on this list */
total_mem=head->onlist*head->size;
@@ -407,7 +414,7 @@ H5FL_reg_gc_list(H5FL_reg_head_t *head)
/* Decrement global count of free memory on "regular" lists */
H5FL_reg_gc_head.mem_freed-=total_mem;
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5FL_reg_gc_list() */
@@ -432,14 +439,16 @@ static herr_t
H5FL_reg_gc(void)
{
H5FL_reg_gc_node_t *gc_node; /* Pointer into the list of things to garbage collect */
+ herr_t ret_value=SUCCEED; /* return value*/
- FUNC_ENTER_NOINIT(H5FL_reg_gc);
+ FUNC_ENTER_NOINIT(H5FL_reg_gc)
/* Walk through all the free lists, free()'ing the nodes */
gc_node=H5FL_reg_gc_head.first;
while(gc_node!=NULL) {
/* Release the free nodes on the list */
- H5FL_reg_gc_list(gc_node->list);
+ if(H5FL_reg_gc_list(gc_node->list)<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, FAIL, "garbage collection of list failed")
/* Go on to the next free list to garbage collect */
gc_node=gc_node->next;
@@ -448,7 +457,8 @@ H5FL_reg_gc(void)
/* Double check that all the memory on the free lists is recycled */
assert(H5FL_reg_gc_head.mem_freed==0);
- FUNC_LEAVE_NOAPI(SUCCEED);
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_reg_gc() */
@@ -483,7 +493,7 @@ H5FL_reg_term(void)
H5FL_reg_gc_node_t *left; /* pointer to garbage collection lists with work left */
H5FL_reg_gc_node_t *tmp; /* Temporary pointer to a garbage collection node */
- FUNC_ENTER_NOINIT(H5FL_reg_term);
+ FUNC_ENTER_NOINIT(H5FL_reg_term)
if (interface_initialize_g) {
/* Free the nodes on the garbage collection list, keeping nodes with allocations outstanding */
@@ -520,7 +530,7 @@ H5FL_reg_term(void)
/* Terminating this layer never affects other layers; rather, other layers affect
* the termination of this layer. */
- FUNC_LEAVE_NOAPI(0);
+ FUNC_LEAVE_NOAPI(0)
} /* end H5FL_reg_term() */
@@ -549,7 +559,7 @@ 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;
- FUNC_ENTER_NOINIT(H5FL_blk_find_list);
+ FUNC_ENTER_NOINIT(H5FL_blk_find_list)
/* Find the correct free list */
temp=*head;
@@ -576,7 +586,7 @@ H5FL_blk_find_list(H5FL_blk_node_t **head, size_t size)
ret_value=temp;
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_blk_find_list() */
@@ -603,11 +613,11 @@ 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;
- FUNC_ENTER_NOINIT(H5FL_blk_create_list);
+ FUNC_ENTER_NOINIT(H5FL_blk_create_list)
/* Allocate room for the new free list node */
if(NULL==(temp=H5FL_MALLOC(H5FL_blk_node_t)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for chunk info");
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for chunk info")
/* Set the correct values for the new free list */
temp->size=size;
@@ -628,7 +638,7 @@ H5FL_blk_create_list(H5FL_blk_node_t **head, size_t size)
ret_value=temp;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_blk_create_list() */
@@ -654,11 +664,11 @@ H5FL_blk_init(H5FL_blk_head_t *head)
H5FL_blk_gc_node_t *new_node; /* Pointer to the node for the new list to garbage collect */
herr_t ret_value=SUCCEED; /* return value*/
- FUNC_ENTER_NOINIT(H5FL_blk_init);
+ FUNC_ENTER_NOINIT(H5FL_blk_init)
/* Allocate a new garbage collection node */
if (NULL==(new_node = H5MM_malloc(sizeof(H5FL_blk_gc_node_t))))
- HGOTO_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;
@@ -671,7 +681,7 @@ H5FL_blk_init(H5FL_blk_head_t *head)
head->init=1;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_blk_init() */
@@ -697,7 +707,7 @@ H5FL_blk_free_block_avail(H5FL_blk_head_t *head, size_t size)
H5FL_blk_node_t *free_list; /* The free list of nodes of correct size */
htri_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5FL_blk_free_block_avail, FAIL);
+ FUNC_ENTER_NOAPI(H5FL_blk_free_block_avail, FAIL)
/* Double check parameters */
assert(head);
@@ -709,7 +719,7 @@ H5FL_blk_free_block_avail(H5FL_blk_head_t *head, size_t size)
else
ret_value=FALSE;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_blk_free_block_avail() */
@@ -738,14 +748,15 @@ H5FL_blk_malloc(H5FL_blk_head_t *head, size_t size)
H5FL_blk_list_t *temp; /* Temp. ptr to the new native list allocated */
void *ret_value; /* Pointer to the block to return to the user */
- FUNC_ENTER_NOAPI(H5FL_blk_malloc, NULL);
+ FUNC_ENTER_NOAPI(H5FL_blk_malloc, NULL)
/* Double check parameters */
assert(head);
/* Make certain the list is initialized first */
if(!head->init)
- H5FL_blk_init(head);
+ if(H5FL_blk_init(head)<0)
+ HGOTO_ERROR (H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'block' list")
/* check if there is a free list for blocks of this size */
/* and if there are any blocks available on the list */
@@ -772,7 +783,7 @@ H5FL_blk_malloc(H5FL_blk_head_t *head, size_t size)
else {
/* Allocate new node, with room for the page info header and the actual page data */
if(NULL==(temp=H5FL_malloc(sizeof(H5FL_blk_list_t)+size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for chunk");
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for chunk")
/* Increment the number of blocks allocated */
head->allocated++;
@@ -785,7 +796,7 @@ H5FL_blk_malloc(H5FL_blk_head_t *head, size_t size)
} /* end else */
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_blk_malloc() */
@@ -813,20 +824,20 @@ H5FL_blk_calloc(H5FL_blk_head_t *head, size_t size)
{
void *ret_value; /* Pointer to the block to return to the user */
- FUNC_ENTER_NOAPI(H5FL_blk_calloc, NULL);
+ FUNC_ENTER_NOAPI(H5FL_blk_calloc, NULL)
/* Double check parameters */
assert(head);
/* Allocate the block */
if (NULL==(ret_value = H5FL_blk_malloc(head,size)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
/* Clear the block to zeros */
HDmemset(ret_value,0,size);
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_blk_calloc() */
@@ -856,14 +867,14 @@ H5FL_blk_free(H5FL_blk_head_t *head, void *block)
size_t free_size; /* Size of the block freed */
void *ret_value=NULL; /* Return value */
- FUNC_ENTER_NOAPI(H5FL_blk_free, NULL);
+ FUNC_ENTER_NOAPI(H5FL_blk_free, NULL)
/* Double check parameters */
assert(head);
assert(block);
/* Get the pointer to the native block info header in front of the native block to free */
- temp=(H5FL_blk_list_t *)((unsigned char *)block-sizeof(H5FL_blk_list_t));
+ temp=(H5FL_blk_list_t *)((unsigned char *)block-sizeof(H5FL_blk_list_t)); /*lint !e826 Pointer-to-pointer cast is appropriate here */
/* Save the block's size for later */
free_size=temp->size;
@@ -890,14 +901,16 @@ H5FL_blk_free(H5FL_blk_head_t *head, void *block)
/* Check for exceeding free list memory use limits */
/* First check this particular list */
if(head->list_mem>H5FL_blk_lst_mem_lim)
- H5FL_blk_gc_list(head);
+ if(H5FL_blk_gc_list(head)<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, NULL, "garbage collection failed during free")
/* Then check the global amount memory on block free lists */
if(H5FL_blk_gc_head.mem_freed>H5FL_blk_glb_mem_lim)
- H5FL_blk_gc();
+ if(H5FL_blk_gc()<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, NULL, "garbage collection failed during free")
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_blk_free() */
@@ -925,7 +938,7 @@ H5FL_blk_realloc(H5FL_blk_head_t *head, void *block, size_t new_size)
H5FL_blk_list_t *temp; /* Temp. ptr to the new block node allocated */
void *ret_value=NULL; /* Return value */
- FUNC_ENTER_NOAPI(H5FL_blk_realloc, NULL);
+ FUNC_ENTER_NOAPI(H5FL_blk_realloc, NULL)
/* Double check parameters */
assert(head);
@@ -933,12 +946,12 @@ H5FL_blk_realloc(H5FL_blk_head_t *head, void *block, size_t new_size)
/* Check if we are actually re-allocating a block */
if(block!=NULL) {
/* Get the pointer to the chunk info header in front of the chunk to free */
- temp=(H5FL_blk_list_t *)((unsigned char *)block-sizeof(H5FL_blk_list_t));
+ temp=(H5FL_blk_list_t *)((unsigned char *)block-sizeof(H5FL_blk_list_t)); /*lint !e826 Pointer-to-pointer cast is appropriate here */
/* check if we are actually changing the size of the buffer */
if(new_size!=temp->size) {
if((ret_value=H5FL_blk_malloc(head,new_size))==NULL)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for block");
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for block")
blk_size=MIN(new_size,temp->size);
HDmemcpy(ret_value,block,blk_size);
H5FL_blk_free(head,block);
@@ -951,7 +964,7 @@ H5FL_blk_realloc(H5FL_blk_head_t *head, void *block, size_t new_size)
ret_value=H5FL_blk_malloc(head,new_size);
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_blk_realloc() */
@@ -977,7 +990,7 @@ H5FL_blk_gc_list(H5FL_blk_head_t *head)
void *next; /* Temp. ptr to the free list list node */
void *temp; /* Temp. ptr to the free list page node */
- FUNC_ENTER_NOINIT(H5FL_blk_gc_list);
+ FUNC_ENTER_NOINIT(H5FL_blk_gc_list)
/* Loop through all the nodes in the block free list queue */
while(head->head!=NULL) {
@@ -1015,7 +1028,7 @@ H5FL_blk_gc_list(H5FL_blk_head_t *head)
/* Double check that all the memory on this list is recycled */
assert(head->list_mem==0);
- FUNC_LEAVE_NOAPI(SUCCEED);
+ FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5FL_blk_gc_list() */
@@ -1038,14 +1051,16 @@ static herr_t
H5FL_blk_gc(void)
{
H5FL_blk_gc_node_t *gc_node; /* Pointer into the list of things to garbage collect */
+ herr_t ret_value=SUCCEED; /* return value*/
- FUNC_ENTER_NOINIT(H5FL_blk_gc);
+ FUNC_ENTER_NOINIT(H5FL_blk_gc)
/* Walk through all the free lists, free()'ing the nodes */
gc_node=H5FL_blk_gc_head.first;
while(gc_node!=NULL) {
/* For each free list being garbage collected, walk through the nodes and free them */
- H5FL_blk_gc_list(gc_node->pq);
+ if(H5FL_blk_gc_list(gc_node->pq)<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, FAIL, "garbage collection of list failed")
/* Go on to the next free list to garbage collect */
gc_node=gc_node->next;
@@ -1054,7 +1069,8 @@ H5FL_blk_gc(void)
/* Double check that all the memory on the free lists are recycled */
assert(H5FL_blk_gc_head.mem_freed==0);
- FUNC_LEAVE_NOAPI(SUCCEED);
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_blk_gc() */
@@ -1083,7 +1099,7 @@ H5FL_blk_term(void)
H5FL_blk_gc_node_t *left; /* pointer to garbage collection lists with work left */
H5FL_blk_gc_node_t *tmp; /* Temporary pointer to a garbage collection node */
- FUNC_ENTER_NOINIT(H5FL_blk_term);
+ FUNC_ENTER_NOINIT(H5FL_blk_term)
/* Free the nodes on the garbage collection list, keeping nodes with allocations outstanding */
left=NULL;
@@ -1115,7 +1131,7 @@ printf("H5FL_blk_term: head->name=%s, head->allocated=%d\n", H5FL_blk_gc_head.fi
/* Point to the list of nodes left with allocations open, if any */
H5FL_blk_gc_head.first=left;
- FUNC_LEAVE_NOAPI(H5FL_blk_gc_head.first!=NULL ? 1 : 0);
+ FUNC_LEAVE_NOAPI(H5FL_blk_gc_head.first!=NULL ? 1 : 0)
} /* end H5FL_blk_term() */
@@ -1141,11 +1157,11 @@ H5FL_arr_init(H5FL_arr_head_t *head)
H5FL_gc_arr_node_t *new_node; /* Pointer to the node for the new list to garbage collect */
herr_t ret_value=SUCCEED; /* return value*/
- FUNC_ENTER_NOINIT(H5FL_arr_init);
+ FUNC_ENTER_NOINIT(H5FL_arr_init)
/* Allocate a new garbage collection node */
if (NULL==(new_node = H5MM_malloc(sizeof(H5FL_gc_arr_node_t))))
- HGOTO_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;
@@ -1156,10 +1172,10 @@ 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 *))))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
- if (NULL==(head->onlist = H5MM_calloc(head->maxelem*sizeof(unsigned))))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
+ if (NULL==(head->u.list_arr = H5MM_calloc((size_t)head->maxelem*sizeof(H5FL_arr_node_t *))))
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ if (NULL==(head->onlist = H5MM_calloc((size_t)head->maxelem*sizeof(unsigned))))
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
} /* end if */
else {
head->u.queue.init=0;
@@ -1174,7 +1190,7 @@ H5FL_arr_init(H5FL_arr_head_t *head)
head->init=1;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_arr_init() */
@@ -1201,11 +1217,11 @@ H5FL_arr_free(H5FL_arr_head_t *head, void *obj)
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);
+ FUNC_ENTER_NOAPI(H5FL_arr_free, NULL)
/* The H5MM_xfree code allows obj to null */
if (!obj)
- HGOTO_DONE (NULL);
+ HGOTO_DONE (NULL)
/* Double check parameters */
assert(head);
@@ -1216,7 +1232,7 @@ H5FL_arr_free(H5FL_arr_head_t *head, void *obj)
/* Check if there are a maximum number of elements in list */
if(head->maxelem>0) {
/* Get the pointer to the info header in front of the block to free */
- temp=(H5FL_arr_node_t *)((unsigned char *)obj-sizeof(H5FL_arr_node_t));
+ temp=(H5FL_arr_node_t *)((unsigned char *)obj-sizeof(H5FL_arr_node_t)); /*lint !e826 Pointer-to-pointer cast is appropriate here */
/* Save the number of elements for later */
free_nelem=temp->nelem;
@@ -1243,11 +1259,13 @@ H5FL_arr_free(H5FL_arr_head_t *head, void *obj)
/* Check for exceeding free list memory use limits */
/* First check this particular list */
if(head->list_mem>H5FL_arr_lst_mem_lim)
- H5FL_arr_gc_list(head);
+ if(H5FL_arr_gc_list(head)<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, NULL, "garbage collection failed during free")
/* Then check the global amount memory on array free lists */
if(H5FL_arr_gc_head.mem_freed>H5FL_arr_glb_mem_lim)
- H5FL_arr_gc();
+ if(H5FL_arr_gc()<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, NULL, "garbage collection failed during free")
} /* end if */
/* No maximum number of elements, use block routine */
@@ -1255,7 +1273,7 @@ H5FL_arr_free(H5FL_arr_head_t *head, void *obj)
H5FL_blk_free(&(head->u.queue),obj);
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_arr_free() */
@@ -1281,14 +1299,15 @@ H5FL_arr_malloc(H5FL_arr_head_t *head, size_t elem)
void *ret_value; /* Pointer to object to return */
size_t mem_size; /* Size of memory block being recycled */
- FUNC_ENTER_NOAPI(H5FL_arr_malloc, NULL);
+ FUNC_ENTER_NOAPI(H5FL_arr_malloc, NULL)
/* Double check parameters */
assert(head);
/* Make certain the list is initialized first */
if(!head->init)
- H5FL_arr_init(head);
+ if(H5FL_arr_init(head)<0)
+ HGOTO_ERROR (H5E_RESOURCE, H5E_CANTINIT, NULL, "can't initialize 'array' blocks")
/* Set the set of the memory block */
mem_size=head->size*elem;
@@ -1323,7 +1342,7 @@ H5FL_arr_malloc(H5FL_arr_head_t *head, size_t elem)
/* Otherwise allocate a node */
else {
if (NULL==(new_obj = H5FL_malloc(sizeof(H5FL_arr_node_t)+mem_size)))
- HGOTO_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++;
@@ -1340,7 +1359,7 @@ H5FL_arr_malloc(H5FL_arr_head_t *head, size_t elem)
ret_value=H5FL_blk_malloc(&(head->u.queue),mem_size);
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_arr_malloc() */
@@ -1364,20 +1383,20 @@ H5FL_arr_calloc(H5FL_arr_head_t *head, size_t elem)
{
void *ret_value; /* Pointer to object to return */
- FUNC_ENTER_NOAPI(H5FL_arr_calloc, NULL);
+ FUNC_ENTER_NOAPI(H5FL_arr_calloc, NULL)
/* Double check parameters */
assert(head);
/* Allocate the array */
if (NULL==(ret_value = H5FL_arr_malloc(head,elem)))
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
/* Clear to zeros */
HDmemset(ret_value,0,head->size*elem);
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_arr_calloc() */
@@ -1403,7 +1422,7 @@ H5FL_arr_realloc(H5FL_arr_head_t *head, void * obj, size_t new_elem)
H5FL_arr_node_t *temp; /* Temp. ptr to the new free list node allocated */
void *ret_value; /* Pointer to object to return */
- FUNC_ENTER_NOAPI(H5FL_arr_realloc, NULL);
+ FUNC_ENTER_NOAPI(H5FL_arr_realloc, NULL)
/* Double check parameters */
assert(head);
@@ -1419,7 +1438,7 @@ H5FL_arr_realloc(H5FL_arr_head_t *head, void * obj, size_t new_elem)
assert((int)new_elem<=head->maxelem);
/* Get the pointer to the info header in front of the block to free */
- temp=(H5FL_arr_node_t *)((unsigned char *)obj-sizeof(H5FL_arr_node_t));
+ temp=(H5FL_arr_node_t *)((unsigned char *)obj-sizeof(H5FL_arr_node_t)); /*lint !e826 Pointer-to-pointer cast is appropriate here */
/* Check if the size is really changing */
if(temp->nelem!=new_elem) {
@@ -1442,7 +1461,7 @@ H5FL_arr_realloc(H5FL_arr_head_t *head, void * obj, size_t new_elem)
} /* end else */
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_arr_realloc() */
@@ -1466,21 +1485,22 @@ H5FL_arr_gc_list(H5FL_arr_head_t *head)
{
H5FL_arr_node_t *arr_free_list; /* Pointer to nodes in free list being garbage collected */
void *tmp; /* Temporary node pointer */
- int i; /* Counter for array of free lists */
+ unsigned u; /* Counter for array of free lists */
size_t total_mem; /* Total memory used on list */
+ herr_t ret_value=SUCCEED; /* return value*/
- FUNC_ENTER_NOINIT(H5FL_arr_gc_list);
+ FUNC_ENTER_NOINIT(H5FL_arr_gc_list)
/* Check if the array has a fixed maximum number of elements */
if(head->maxelem>0) {
/* Walk through the array of free lists */
- for(i=0; i<head->maxelem; i++) {
- if(head->onlist[i]>0) {
+ for(u=0; u<(unsigned)head->maxelem; u++) {
+ if(head->onlist[u]>0) {
/* Calculate the total memory used on this list */
- total_mem=head->onlist[i]*i*head->size;
+ total_mem=head->onlist[u]*u*head->size;
/* For each free list being garbage collected, walk through the nodes and free them */
- arr_free_list=head->u.list_arr[i];
+ arr_free_list=head->u.list_arr[u];
while(arr_free_list!=NULL) {
tmp=arr_free_list->next;
@@ -1492,8 +1512,8 @@ H5FL_arr_gc_list(H5FL_arr_head_t *head)
} /* end while */
/* Indicate no free nodes on the free list */
- head->u.list_arr[i]=NULL;
- head->onlist[i]=0;
+ head->u.list_arr[u]=NULL;
+ head->onlist[u]=0;
/* Decrement count of free memory on this "array" list */
head->list_mem-=total_mem;
@@ -1510,9 +1530,11 @@ H5FL_arr_gc_list(H5FL_arr_head_t *head)
} /* end if */
/* No maximum number of elements, use the block call to garbage collect */
else
- H5FL_blk_gc_list(&(head->u.queue));
+ if(H5FL_blk_gc_list(&(head->u.queue))<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, FAIL, "garbage collection of list failed")
- FUNC_LEAVE_NOAPI(SUCCEED);
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_arr_gc_list() */
@@ -1535,14 +1557,16 @@ static herr_t
H5FL_arr_gc(void)
{
H5FL_gc_arr_node_t *gc_arr_node; /* Pointer into the list of things to garbage collect */
+ herr_t ret_value=SUCCEED; /* return value*/
- FUNC_ENTER_NOINIT(H5FL_arr_gc);
+ FUNC_ENTER_NOINIT(H5FL_arr_gc)
/* Walk through all the free lists, free()'ing the nodes */
gc_arr_node=H5FL_arr_gc_head.first;
while(gc_arr_node!=NULL) {
/* Release the free nodes on the list */
- H5FL_arr_gc_list(gc_arr_node->list);
+ if(H5FL_arr_gc_list(gc_arr_node->list)<0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, FAIL, "garbage collection of list failed")
/* Go on to the next free list to garbage collect */
gc_arr_node=gc_arr_node->next;
@@ -1551,7 +1575,8 @@ H5FL_arr_gc(void)
/* Double check that all the memory on the free lists are recycled */
assert(H5FL_arr_gc_head.mem_freed==0);
- FUNC_LEAVE_NOAPI(SUCCEED);
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_arr_gc() */
@@ -1580,7 +1605,7 @@ H5FL_arr_term(void)
H5FL_gc_arr_node_t *left; /* pointer to garbage collection lists with work left */
H5FL_gc_arr_node_t *tmp; /* Temporary pointer to a garbage collection node */
- FUNC_ENTER_NOINIT(H5FL_arr_term);
+ FUNC_ENTER_NOINIT(H5FL_arr_term)
/* Free the nodes on the garbage collection list, keeping nodes with allocations outstanding */
left=NULL;
@@ -1640,7 +1665,7 @@ printf("H5FL_arr_term: head->name=%s, head->allocated=%d\n", H5FL_arr_gc_head.fi
/* Point to the list of nodes left with allocations open, if any */
H5FL_arr_gc_head.first=left;
- FUNC_LEAVE_NOAPI(H5FL_arr_gc_head.first!=NULL ? 1 : 0);
+ FUNC_LEAVE_NOAPI(H5FL_arr_gc_head.first!=NULL ? 1 : 0)
} /* end H5FL_arr_term() */
@@ -1664,7 +1689,7 @@ H5FL_garbage_coll(void)
{
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOINIT(H5FL_garbage_coll);
+ FUNC_ENTER_NOINIT(H5FL_garbage_coll)
/* Garbage collect the free lists for array objects */
if(H5FL_arr_gc()<0)
@@ -1679,7 +1704,7 @@ H5FL_garbage_coll(void)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTGC, FAIL, "can't garbage collect regular objects")
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_garbage_coll() */
@@ -1718,7 +1743,7 @@ H5FL_set_free_list_limits(int reg_global_lim, int reg_list_lim, int arr_global_l
{
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI(H5FL_set_free_list_limits, FAIL);
+ FUNC_ENTER_NOAPI(H5FL_set_free_list_limits, FAIL)
/* Set the limit variables */
/* limit on all regular free lists */
@@ -1735,7 +1760,7 @@ H5FL_set_free_list_limits(int reg_global_lim, int reg_list_lim, int arr_global_l
H5FL_blk_lst_mem_lim=(blk_list_lim==-1 ? UINT_MAX : (size_t)blk_list_lim);
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FL_set_free_list_limits() */
@@ -1763,13 +1788,13 @@ H5FL_term_interface(void)
{
int ret_value=0;
- FUNC_ENTER_NOINIT(H5FL_term_interface);
+ FUNC_ENTER_NOINIT(H5FL_term_interface)
/* Garbage collect any nodes on the free lists */
- H5FL_garbage_coll();
+ (void)H5FL_garbage_coll();
ret_value=H5FL_reg_term()+H5FL_arr_term()+H5FL_blk_term();
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}