summaryrefslogtreecommitdiffstats
path: root/src/H5HLint.c
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2012-07-05 19:07:42 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2012-07-05 19:07:42 (GMT)
commitce0496520836aef9fdea54fc01d5d92fe8f43b77 (patch)
tree8c507794d59bcf8fbbe7c6bf5ccfa4546ee9cdde /src/H5HLint.c
parentc21ceb956ca9a6a1705b2d38fab31889b94cc3e9 (diff)
downloadhdf5-ce0496520836aef9fdea54fc01d5d92fe8f43b77.zip
hdf5-ce0496520836aef9fdea54fc01d5d92fe8f43b77.tar.gz
hdf5-ce0496520836aef9fdea54fc01d5d92fe8f43b77.tar.bz2
[svn-r22515] Converted local heap (H5HL) code to use the new enter/leave/error macro
scheme. Also created separate prefix and data block files so that the local heap code more closely resembles the rest of the data structures. Tested on jam. This branch still has h5diff errors. The library tests all pass, though.
Diffstat (limited to 'src/H5HLint.c')
-rw-r--r--src/H5HLint.c330
1 files changed, 71 insertions, 259 deletions
diff --git a/src/H5HLint.c b/src/H5HLint.c
index d5238eb..d5876f0 100644
--- a/src/H5HLint.c
+++ b/src/H5HLint.c
@@ -15,11 +15,11 @@
/*-------------------------------------------------------------------------
*
- * Created: H5HLint.c
- * Oct 12 2008
- * Quincey Koziol <koziol@hdfgroup.org>
+ * Created: H5HLint.c
+ * Oct 12 2008
+ * Quincey Koziol <koziol@hdfgroup.org>
*
- * Purpose: Local heap internal routines.
+ * Purpose: Local heap internal routines.
*
*-------------------------------------------------------------------------
*/
@@ -28,15 +28,16 @@
/* Module Setup */
/****************/
-#define H5HL_PACKAGE /* Suppress error about including H5HLpkg */
+#define H5HL_PACKAGE /* Suppress error about including H5HLpkg */
/***********/
/* Headers */
/***********/
-#include "H5private.h" /* Generic Functions */
-#include "H5Eprivate.h" /* Error handling */
-#include "H5HLpkg.h" /* Local Heaps */
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5FLprivate.h" /* Free lists */
+#include "H5HLpkg.h" /* Local Heaps */
/****************/
@@ -76,35 +77,27 @@
/* Declare a free list to manage the H5HL_t struct */
H5FL_DEFINE_STATIC(H5HL_t);
-/* Declare a free list to manage the H5HL_dblk_t struct */
-H5FL_DEFINE_STATIC(H5HL_dblk_t);
-
-/* Declare a free list to manage the H5HL_prfx_t struct */
-H5FL_DEFINE_STATIC(H5HL_prfx_t);
-
/*-------------------------------------------------------------------------
- * Function: H5HL_new
+ * Function: H5HL__new
*
- * Purpose: Create a new local heap object
+ * Purpose: Create a new local heap object
*
- * Return: Success: non-NULL pointer to new local heap
- * Failure: NULL
+ * Return: Success: non-NULL pointer to new local heap
+ * Failure: NULL
*
- * Programmer: Quincey Koziol
- * koziol@hdfgroup.org
- * Jan 5 2010
+ * Programmer: Quincey Koziol
+ * koziol@hdfgroup.org
+ * Jan 5 2010
*
*-------------------------------------------------------------------------
*/
-H5HL_t *
-H5HL_new(size_t sizeof_size, size_t sizeof_addr, size_t prfx_size)
-{
- H5HL_t *heap = NULL; /* New local heap */
- H5HL_t *ret_value; /* Return value */
+BEGIN_FUNC(PKG, ERR,
+H5HL_t *, NULL, NULL,
+H5HL__new(size_t sizeof_size, size_t sizeof_addr, size_t prfx_size))
- FUNC_ENTER_NOAPI(NULL)
+ H5HL_t *heap = NULL; /* New local heap */
/* check arguments */
HDassert(sizeof_size > 0);
@@ -113,7 +106,7 @@ H5HL_new(size_t sizeof_size, size_t sizeof_addr, size_t prfx_size)
/* Allocate new local heap structure */
if(NULL == (heap = H5FL_CALLOC(H5HL_t)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "memory allocation failed")
+ H5E_THROW(H5E_CANTALLOC, "memory allocation failed");
/* Initialize non-zero fields */
heap->sizeof_size = sizeof_size;
@@ -123,29 +116,31 @@ H5HL_new(size_t sizeof_size, size_t sizeof_addr, size_t prfx_size)
/* Set the return value */
ret_value = heap;
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5HL_new() */
+CATCH
+ if(!ret_value && heap != NULL)
+ if (NULL == (heap = H5FL_FREE(H5HL_t, heap)))
+ H5E_THROW(H5E_CANTFREE, "can't free heap memory");
+
+END_FUNC(PKG) /* end H5HL__new() */
/*-------------------------------------------------------------------------
- * Function: H5HL_inc_rc
+ * Function: H5HL__inc_rc
*
- * Purpose: Increment ref. count on heap
+ * Purpose: Increment ref. count on heap
*
- * Return: Success: Non-negative
- * Failure: Negative
+ * Return: Success: SUCCEED
+ * Failure: N/A
*
- * Programmer: Quincey Koziol
- * koziol@hdfgroup.org
- * Oct 12 2008
+ * Programmer: Quincey Koziol
+ * koziol@hdfgroup.org
+ * Oct 12 2008
*
*-------------------------------------------------------------------------
*/
-static herr_t
-H5HL_inc_rc(H5HL_t *heap)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+BEGIN_FUNC(PKG, NOERR,
+herr_t, SUCCEED, -,
+H5HL__inc_rc(H5HL_t *heap))
/* check arguments */
HDassert(heap);
@@ -153,28 +148,26 @@ H5HL_inc_rc(H5HL_t *heap)
/* Increment heap's ref. count */
heap->rc++;
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5HL_inc_rc() */
+END_FUNC(PKG) /* end H5HL__inc_rc() */
/*-------------------------------------------------------------------------
- * Function: H5HL_dec_rc
+ * Function: H5HL__dec_rc
*
- * Purpose: Decrement ref. count on heap
+ * Purpose: Decrement ref. count on heap
*
- * Return: Success: Non-negative
- * Failure: Negative
+ * Return: Success: SUCCEED
+ * Failure: FAIL
*
- * Programmer: Quincey Koziol
- * koziol@hdfgroup.org
- * Oct 12 2008
+ * Programmer: Quincey Koziol
+ * koziol@hdfgroup.org
+ * Oct 12 2008
*
*-------------------------------------------------------------------------
*/
-static herr_t
-H5HL_dec_rc(H5HL_t *heap)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+BEGIN_FUNC(PKG, ERR,
+herr_t, SUCCEED, FAIL,
+H5HL__dec_rc(H5HL_t *heap))
/* check arguments */
HDassert(heap);
@@ -182,31 +175,31 @@ H5HL_dec_rc(H5HL_t *heap)
/* Decrement heap's ref. count */
heap->rc--;
+CATCH
/* Check if we should destroy the heap */
- if(heap->rc == 0)
- H5HL_dest(heap);
+ if(heap->rc == 0 && FAIL == H5HL__dest(heap))
+ H5E_THROW(H5E_CANTFREE, "unable to destroy local heap");
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5HL_dec_rc() */
+END_FUNC(PKG) /* end H5HL__dec_rc() */
/*-------------------------------------------------------------------------
- * Function: H5HL_dest
+ * Function: H5HL__dest
*
- * Purpose: Destroys a heap in memory.
+ * Purpose: Destroys a heap in memory.
*
- * Return: Non-negative on success/Negative on failure
+ * Return: Success: SUCCEED
+ * Failure: FAIL
*
- * Programmer: Quincey Koziol
- * koziol@ncsa.uiuc.edu
- * Jan 15 2003
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Jan 15 2003
*
*-------------------------------------------------------------------------
*/
-herr_t
-H5HL_dest(H5HL_t *heap)
-{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+BEGIN_FUNC(PKG, ERR,
+herr_t, SUCCEED, FAIL,
+H5HL__dest(H5HL_t *heap))
/* check arguments */
HDassert(heap);
@@ -217,201 +210,20 @@ H5HL_dest(H5HL_t *heap)
HDassert(heap->prfx == NULL);
HDassert(heap->dblk == NULL);
+CATCH
if(heap->dblk_image)
- heap->dblk_image = H5FL_BLK_FREE(lheap_chunk, heap->dblk_image);
+ if(NULL != (heap->dblk_image = H5FL_BLK_FREE(lheap_chunk, heap->dblk_image)))
+ H5E_THROW(H5E_CANTFREE, "unable to free local heap data block image");
while(heap->freelist) {
H5HL_free_t *fl;
fl = heap->freelist;
heap->freelist = fl->next;
- fl = H5FL_FREE(H5HL_free_t, fl);
+ if(NULL != (fl = H5FL_FREE(H5HL_free_t, fl)))
+ H5E_THROW(H5E_CANTFREE, "unable to free local heap free list");
} /* end while */
- heap = H5FL_FREE(H5HL_t, heap);
-
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5HL_dest() */
-
-
-/*-------------------------------------------------------------------------
- * Function: H5HL_prfx_new
- *
- * Purpose: Create a new local heap prefix object
- *
- * Return: Success: non-NULL pointer to new local heap prefix
- * Failure: NULL
- *
- * Programmer: Quincey Koziol
- * koziol@hdfgroup.org
- * Oct 12 2008
- *
- *-------------------------------------------------------------------------
- */
-H5HL_prfx_t *
-H5HL_prfx_new(H5HL_t *heap)
-{
- H5HL_prfx_t *prfx = NULL; /* New local heap prefix */
- H5HL_prfx_t *ret_value; /* Return value */
-
- FUNC_ENTER_NOAPI(NULL)
-
- /* check arguments */
- HDassert(heap);
-
- /* Allocate new local heap prefix */
- if(NULL == (prfx = H5FL_CALLOC(H5HL_prfx_t)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "memory allocation failed")
-
- /* Increment ref. count on heap data structure */
- if(H5HL_inc_rc(heap) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't increment heap ref. count")
-
- /* Link the heap & the prefix */
- prfx->heap = heap;
- heap->prfx = prfx;
-
- /* Set the return value */
- ret_value = prfx;
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5HL_prfx_new() */
-
-
-/*-------------------------------------------------------------------------
- * Function: H5HL_prfx_dest
- *
- * Purpose: Destroy a local heap prefix object
- *
- * Return: Success: Non-negative
- * Failure: Negative
- *
- * Programmer: Quincey Koziol
- * koziol@hdfgroup.org
- * Oct 12 2008
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5HL_prfx_dest(H5HL_prfx_t *prfx)
-{
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(FAIL)
-
- /* check arguments */
- HDassert(prfx);
-
- /* Check if prefix was initialized */
- if(prfx->heap) {
- /* Unlink prefix from heap */
- prfx->heap->prfx = NULL;
-
- /* Decrement ref. count on heap data structure */
- if(H5HL_dec_rc(prfx->heap) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement heap ref. count")
-
- /* Unlink heap from prefix */
- prfx->heap = NULL;
- } /* end if */
-
- /* Free local heap prefix */
- prfx = H5FL_FREE(H5HL_prfx_t, prfx);
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5HL_prfx_dest() */
-
-
-/*-------------------------------------------------------------------------
- * Function: H5HL_dblk_new
- *
- * Purpose: Create a new local heap data block object
- *
- * Return: Success: non-NULL pointer to new local heap data block
- * Failure: NULL
- *
- * Programmer: Quincey Koziol
- * koziol@hdfgroup.org
- * Oct 12 2008
- *
- *-------------------------------------------------------------------------
- */
-H5HL_dblk_t *
-H5HL_dblk_new(H5HL_t *heap)
-{
- H5HL_dblk_t *dblk = NULL; /* New local heap data block */
- H5HL_dblk_t *ret_value; /* Return value */
-
- FUNC_ENTER_NOAPI(NULL)
-
- /* check arguments */
- HDassert(heap);
-
- /* Allocate new local heap data block */
- if(NULL == (dblk = H5FL_CALLOC(H5HL_dblk_t)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "memory allocation failed")
-
- /* Increment ref. count on heap data structure */
- if(H5HL_inc_rc(heap) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, "can't increment heap ref. count")
-
- /* Link the heap & the data block */
- dblk->heap = heap;
- heap->dblk = dblk;
-
- /* Set the return value */
- ret_value = dblk;
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5HL_dblk_new() */
-
-
-/*-------------------------------------------------------------------------
- * Function: H5HL_dblk_dest
- *
- * Purpose: Destroy a local heap data block object
- *
- * Return: Success: Non-negative
- * Failure: Negative
- *
- * Programmer: Quincey Koziol
- * koziol@hdfgroup.org
- * Oct 12 2008
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5HL_dblk_dest(H5HL_dblk_t *dblk)
-{
- herr_t ret_value = SUCCEED; /* Return value */
-
- FUNC_ENTER_NOAPI(FAIL)
-
- /* check arguments */
- HDassert(dblk);
-
- /* Check if data block was initialized */
- if(dblk->heap) {
- /* Unlink data block from heap */
- dblk->heap->dblk = NULL;
-
- /* Unpin the local heap prefix */
- if(H5AC_unpin_entry(dblk->heap->prfx) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPIN, FAIL, "can't unpin local heap prefix")
-
- /* Decrement ref. count on heap data structure */
- if(H5HL_dec_rc(dblk->heap) < 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement heap ref. count")
-
- /* Unlink heap from data block */
- dblk->heap = NULL;
- } /* end if */
-
- /* Free local heap data block */
- dblk = H5FL_FREE(H5HL_dblk_t, dblk);
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5HL_dblk_dest() */
+
+ if(NULL != (heap = H5FL_FREE(H5HL_t, heap)))
+ H5E_THROW(H5E_CANTFREE, "unable to free local heap");
+END_FUNC(PKG) /* end H5HL__dest() */