summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-01-07 17:01:41 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-01-07 17:01:41 (GMT)
commit836f11303ca41edd765e858c5c50c39c6e057e39 (patch)
tree5fb86519b25f0a7d3489d1c40655fb9b45f5c541
parent859f28dab377a9326a781b13f4ef1c0c68659e7e (diff)
downloadhdf5-836f11303ca41edd765e858c5c50c39c6e057e39.zip
hdf5-836f11303ca41edd765e858c5c50c39c6e057e39.tar.gz
hdf5-836f11303ca41edd765e858c5c50c39c6e057e39.tar.bz2
[svn-r18070] Description:
Various tweaks, upgrades & corrections from merging the local heap changes on this branch back to the trunk. Tested on: Mac OS X/32 10.6.2 (amazon) debug & prod (h5committest not required on this branch)
-rw-r--r--src/H5C2.c6
-rw-r--r--src/H5F.c142
-rw-r--r--src/H5Fprivate.h8
-rw-r--r--src/H5HL.c95
-rw-r--r--src/H5HLcache.c82
-rw-r--r--src/H5HLdbg.c5
-rw-r--r--src/H5HLint.c114
-rw-r--r--src/H5HLpkg.h23
8 files changed, 303 insertions, 172 deletions
diff --git a/src/H5C2.c b/src/H5C2.c
index 7a14184..1e60a12 100644
--- a/src/H5C2.c
+++ b/src/H5C2.c
@@ -9191,9 +9191,9 @@ H5C2_load_entry(H5F_t * f,
*
* In the following assert:
*
- * HDassert( ( dirty == FALSE ) || ( type->id == 4 ) );
+ * HDassert( ( dirty == FALSE ) || ( type->id == 5 || type->id == 6 ) );
*
- * note that type id 4 is associated with object headers in the metadata
+ * note that type ids 5 & 6 are associated with object headers in the metadata
* cache.
*
* When we get to using H5C2 for other purposes, we may wish to
@@ -9201,7 +9201,7 @@ H5C2_load_entry(H5F_t * f,
* metadata cache.
*/
- HDassert( ( dirty == FALSE ) || ( type->id == 4 || type->id == 5) );
+ HDassert( ( dirty == FALSE ) || ( type->id == 5 || type->id == 6) );
HDassert( entry_ptr->size < H5C2_MAX_ENTRY_SIZE );
#ifndef NDEBUG
entry_ptr->magic = H5C2__H5C2_CACHE_ENTRY_T_MAGIC;
diff --git a/src/H5F.c b/src/H5F.c
index 6579dfe..48eff8f 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -3125,7 +3125,7 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5F_addr_encode
+ * Function: H5F_addr_encode_len
*
* Purpose: Encodes an address into the buffer pointed to by *PP and
* then increments the pointer to the first byte after the
@@ -3136,35 +3136,65 @@ done:
* Programmer: Robb Matzke
* Friday, November 7, 1997
*
- * Modifications:
- * Robb Matzke, 1999-07-28
- * The ADDR argument is passed by value.
*-------------------------------------------------------------------------
*/
void
-H5F_addr_encode(const H5F_t *f, uint8_t **pp/*in,out*/, haddr_t addr)
+H5F_addr_encode_len(size_t addr_len, uint8_t **pp/*in,out*/, haddr_t addr)
{
- unsigned u; /* Local index variable */
+ unsigned u; /* Local index variable */
- HDassert(f);
+ /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_addr_encode_len)
+
+ HDassert(addr_len);
HDassert(pp && *pp);
if(H5F_addr_defined(addr)) {
- for(u = 0; u < H5F_SIZEOF_ADDR(f); u++) {
+ for(u = 0; u < addr_len; u++) {
*(*pp)++ = (uint8_t)(addr & 0xff);
addr >>= 8;
} /* end for */
- assert("overflow" && 0 == addr);
+ HDassert("overflow" && 0 == addr);
} /* end if */
else {
- for(u = 0; u < H5F_SIZEOF_ADDR(f); u++)
+ for(u = 0; u < addr_len; u++)
*(*pp)++ = 0xff;
} /* end else */
+
+ FUNC_LEAVE_NOAPI_VOID
+} /* end H5F_addr_encode_len() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5F_addr_encode
+ *
+ * Purpose: Encodes an address into the buffer pointed to by *PP and
+ * then increments the pointer to the first byte after the
+ * address. An undefined value is stored as all 1's.
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Friday, November 7, 1997
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+H5F_addr_encode(const H5F_t *f, uint8_t **pp/*in,out*/, haddr_t addr)
+{
+ /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_addr_encode)
+
+ HDassert(f);
+
+ H5F_addr_encode_len(H5F_SIZEOF_ADDR(f), pp, addr);
+
+ FUNC_LEAVE_NOAPI_VOID
} /* end H5F_addr_encode() */
/*-------------------------------------------------------------------------
- * Function: H5F_addr_decode
+ * Function: H5F_addr_decode_len
*
* Purpose: Decodes an address from the buffer pointed to by *PP and
* updates the pointer to point to the next byte after the
@@ -3178,40 +3208,88 @@ H5F_addr_encode(const H5F_t *f, uint8_t **pp/*in,out*/, haddr_t addr)
* Programmer: Robb Matzke
* Friday, November 7, 1997
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
void
-H5F_addr_decode(const H5F_t *f, const uint8_t **pp/*in,out*/, haddr_t *addr_p/*out*/)
+H5F_addr_decode_len(size_t addr_len, const uint8_t **pp/*in,out*/, haddr_t *addr_p/*out*/)
{
- unsigned i;
- haddr_t tmp;
- uint8_t c;
- hbool_t all_zero = TRUE;
+ hbool_t all_zero = TRUE; /* True if address was all zeroes */
+ unsigned u; /* Local index variable */
- assert(f);
- assert(pp && *pp);
- assert(addr_p);
+ /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_addr_decode_len)
+ HDassert(addr_len);
+ HDassert(pp && *pp);
+ HDassert(addr_p);
+
+ /* Reset value in destination */
*addr_p = 0;
- for (i=0; i<H5F_SIZEOF_ADDR(f); i++) {
+ /* Decode bytes from address */
+ for(u = 0; u < addr_len; u++) {
+ uint8_t c; /* Local decoded byte */
+
+ /* Get decoded byte (and advance pointer) */
c = *(*pp)++;
- if (c != 0xff)
+
+ /* Check for non-undefined address byte value */
+ if(c != 0xff)
all_zero = FALSE;
- if (i<sizeof(*addr_p)) {
- tmp = c;
- tmp <<= (i * 8); /*use tmp to get casting right */
+ if(u < sizeof(*addr_p)) {
+ haddr_t tmp = c; /* Local copy of address, for casting */
+
+ /* Shift decoded byte to correct position */
+ tmp <<= (u * 8); /*use tmp to get casting right */
+
+ /* Merge into already decoded bytes */
*addr_p |= tmp;
- } else if (!all_zero) {
- assert(0 == **pp); /*overflow */
- }
- }
- if (all_zero)
+ } /* end if */
+ else
+ if(!all_zero)
+ HDassert(0 == **pp); /*overflow */
+ } /* end for */
+
+ /* If 'all_zero' is still TRUE, the address was entirely composed of '0xff'
+ * bytes, which is the encoded form of 'HADDR_UNDEF', so set the destination
+ * to that value */
+ if(all_zero)
*addr_p = HADDR_UNDEF;
-}
+
+ FUNC_LEAVE_NOAPI_VOID
+} /* end H5F_addr_decode_len() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5F_addr_decode
+ *
+ * Purpose: Decodes an address from the buffer pointed to by *PP and
+ * updates the pointer to point to the next byte after the
+ * address.
+ *
+ * If the value read is all 1's then the address is returned
+ * with an undefined value.
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Friday, November 7, 1997
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+H5F_addr_decode(const H5F_t *f, const uint8_t **pp/*in,out*/, haddr_t *addr_p/*out*/)
+{
+ /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_addr_decode)
+
+ HDassert(f);
+
+ H5F_addr_decode_len(H5F_SIZEOF_ADDR(f), pp, addr_p);
+
+ FUNC_LEAVE_NOAPI_VOID
+} /* end H5F_addr_decode() */
/*-------------------------------------------------------------------------
diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h
index 8786306..354de3a 100644
--- a/src/H5Fprivate.h
+++ b/src/H5Fprivate.h
@@ -471,10 +471,10 @@ H5_DLL herr_t H5F_block_write(const H5F_t *f, H5FD_mem_t type, haddr_t addr,
size_t size, hid_t dxpl_id, const void *buf);
/* Address-related functions */
-H5_DLL void H5F_addr_encode(const H5F_t *f, uint8_t **pp/*in,out*/,
- haddr_t addr);
-H5_DLL void H5F_addr_decode(const H5F_t *f, const uint8_t **pp/*in,out*/,
- haddr_t *addr_p/*out*/);
+H5_DLL void H5F_addr_encode(const H5F_t *f, uint8_t **pp, haddr_t addr);
+H5_DLL void H5F_addr_encode_len(size_t addr_len, uint8_t **pp, haddr_t addr);
+H5_DLL void H5F_addr_decode(const H5F_t *f, const uint8_t **pp, haddr_t *addr_p);
+H5_DLL void H5F_addr_decode_len(size_t addr_len, const uint8_t **pp, haddr_t *addr_p);
/* File access property list callbacks */
H5_DLL herr_t H5P_facc_close(hid_t dxpl_id, void *close_data);
diff --git a/src/H5HL.c b/src/H5HL.c
index a069e11..bcb62eb 100644
--- a/src/H5HL.c
+++ b/src/H5HL.c
@@ -81,9 +81,6 @@ static herr_t H5HL_minimize_heap_space(H5F_t *f, hid_t dxpl_id, H5HL_t *heap);
/* Declare a free list to manage the H5HL_free_t struct */
H5FL_DEFINE(H5HL_free_t);
-/* Declare a free list to manage the H5HL_t struct */
-H5FL_DEFINE(H5HL_t);
-
/* Declare a PQ free list to manage the heap chunk information */
H5FL_BLK_DEFINE(lheap_chunk);
@@ -139,10 +136,9 @@ H5HL_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, haddr_t *addr_p/*out*/)
size_hint = H5HL_SIZEOF_FREE(f);
size_hint = H5HL_ALIGN(size_hint);
- /* Allocate memory structure */
- if(NULL == (heap = H5FL_CALLOC(H5HL_t)))
- HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed")
- heap->prfx_size = H5HL_SIZEOF_HDR(f);
+ /* Allocate new heap structure */
+ if(NULL == (heap = H5HL_new(H5F_SIZEOF_SIZE(f), H5F_SIZEOF_ADDR(f), H5HL_SIZEOF_HDR(f))))
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "can't allocate new heap struct")
/* Allocate file space */
total_size = heap->prfx_size + size_hint;
@@ -154,7 +150,7 @@ H5HL_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, haddr_t *addr_p/*out*/)
heap->dblk_addr = heap->prfx_addr + (hsize_t)heap->prfx_size;
heap->dblk_size = size_hint;
if(size_hint)
- if(NULL == (heap->image = H5FL_BLK_CALLOC(lheap_chunk, size_hint)))
+ if(NULL == (heap->dblk_image = H5FL_BLK_CALLOC(lheap_chunk, size_hint)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed")
/* free list */
@@ -413,7 +409,7 @@ H5HL_minimize_heap_space(H5F_t *f, hid_t dxpl_id, H5HL_t *heap)
HDassert(new_heap_size < heap->dblk_size);
/* Resize the memory buffer */
- if(NULL == (heap->image = H5FL_BLK_REALLOC(lheap_chunk, heap->image, new_heap_size)))
+ if(NULL == (heap->dblk_image = H5FL_BLK_REALLOC(lheap_chunk, heap->dblk_image, new_heap_size)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "memory allocation failed")
/* Reallocate data block in file */
@@ -459,9 +455,11 @@ H5HL_protect(H5F_t *f, hid_t dxpl_id, haddr_t addr, H5AC2_protect_t rw)
/* Construct the user data for protect callback */
prfx_udata.made_attempt = FALSE;
- prfx_udata.f = f;
+ prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f);
+ prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f);
+ prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f);
prfx_udata.loaded = FALSE;
- prfx_udata.free_block = 0;
+ prfx_udata.free_block = H5HL_FREE_NULL;
/* Protect the local heap prefix */
if(NULL == (prfx = (H5HL_prfx_t *)H5AC2_protect(f, dxpl_id, H5AC2_LHEAP_PRFX, addr, H5HL_SPEC_READ_SIZE, &prfx_udata, rw)))
@@ -482,7 +480,6 @@ H5HL_protect(H5F_t *f, hid_t dxpl_id, haddr_t addr, H5AC2_protect_t rw)
H5HL_cache_dblk_ud_t dblk_udata; /* User data for protecting local heap data block */
/* Construct the user data for protect callback */
- dblk_udata.f = f;
dblk_udata.heap = heap;
dblk_udata.free_block = prfx_udata.loaded ? prfx_udata.free_block :
(heap->freelist ? heap->freelist->offset : H5HL_FREE_NULL);
@@ -548,7 +545,7 @@ H5HL_offset_into(const H5HL_t *heap, size_t offset)
HDassert(heap);
HDassert(offset < heap->dblk_size);
- FUNC_LEAVE_NOAPI(heap->image + offset)
+ FUNC_LEAVE_NOAPI(heap->dblk_image + offset)
} /* end H5HL_offset_into() */
@@ -683,8 +680,7 @@ done:
* Purpose: Inserts a new item into the heap.
*
* Return: Success: Offset of new item within heap.
- *
- * Failure: (size_t)(-1)
+ * Failure: UFAIL
*
* Programmer: Robb Matzke
* matzke@llnl.gov
@@ -872,16 +868,16 @@ H5HL_insert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, size_t buf_size, const void *
(unsigned long)(old_dblk_size + need_more));
}
#endif
- if(NULL == (heap->image = H5FL_BLK_REALLOC(lheap_chunk, heap->image, heap->dblk_size)))
+ if(NULL == (heap->dblk_image = H5FL_BLK_REALLOC(lheap_chunk, heap->dblk_image, heap->dblk_size)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, UFAIL, "memory allocation failed")
/* Clear new section so junk doesn't appear in the file */
/* (Avoid clearing section which will be overwritten with newly inserted data) */
- HDmemset(heap->image + offset + buf_size, 0, (new_dblk_size - (offset + buf_size)));
+ HDmemset(heap->dblk_image + offset + buf_size, 0, (new_dblk_size - (offset + buf_size)));
} /* end if */
/* Copy the data into the heap */
- HDmemcpy(heap->image + offset, buf, buf_size);
+ HDmemcpy(heap->dblk_image + offset, buf, buf_size);
/* Set return value */
ret_value = offset;
@@ -1080,9 +1076,11 @@ H5HL_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr)
/* Construct the user data for protect callback */
prfx_udata.made_attempt = FALSE;
- prfx_udata.f = f;
+ prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f);
+ prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f);
+ prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f);
prfx_udata.loaded = FALSE;
- prfx_udata.free_block = 0;
+ prfx_udata.free_block = H5HL_FREE_NULL;
/* Protect the local heap prefix */
if(NULL == (prfx = (H5HL_prfx_t *)H5AC2_protect(f, dxpl_id, H5AC2_LHEAP_PRFX, addr, H5HL_SPEC_READ_SIZE, &prfx_udata, H5AC2_WRITE)))
@@ -1096,7 +1094,6 @@ H5HL_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr)
H5HL_cache_dblk_ud_t dblk_udata; /* User data for protecting local heap data block */
/* Construct the user data for protect callback */
- dblk_udata.f = f;
dblk_udata.heap = heap;
dblk_udata.free_block = prfx_udata.loaded ? prfx_udata.free_block :
(heap->freelist ? heap->freelist->offset : H5HL_FREE_NULL);
@@ -1178,9 +1175,11 @@ H5HL_get_size(H5F_t *f, hid_t dxpl_id, haddr_t addr, size_t *size)
/* Construct the user data for protect callback */
prfx_udata.made_attempt = FALSE;
- prfx_udata.f = f;
+ prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f);
+ prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f);
+ prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f);
prfx_udata.loaded = FALSE;
- prfx_udata.free_block = 0;
+ prfx_udata.free_block = H5HL_FREE_NULL;
/* Protect the local heap prefix */
if(NULL == (prfx = (H5HL_prfx_t *)H5AC2_protect(f, dxpl_id, H5AC2_LHEAP_PRFX, addr, H5HL_SPEC_READ_SIZE, &prfx_udata, H5AC2_READ)))
@@ -1230,9 +1229,11 @@ H5HL_heapsize(H5F_t *f, hid_t dxpl_id, haddr_t addr, hsize_t *heap_size)
/* Construct the user data for protect callback */
prfx_udata.made_attempt = FALSE;
- prfx_udata.f = f;
+ prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f);
+ prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f);
+ prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f);
prfx_udata.loaded = FALSE;
- prfx_udata.free_block = 0;
+ prfx_udata.free_block = H5HL_FREE_NULL;
/* Protect the local heap prefix */
if(NULL == (prfx = (H5HL_prfx_t *)H5AC2_protect(f, dxpl_id, H5AC2_LHEAP_PRFX, addr, H5HL_SPEC_READ_SIZE, &prfx_udata, H5AC2_READ)))
@@ -1241,7 +1242,7 @@ H5HL_heapsize(H5F_t *f, hid_t dxpl_id, haddr_t addr, hsize_t *heap_size)
/* Get the pointer to the heap */
heap = prfx->heap;
- /* Accumulate the size of the local heap */
+ /* Compute the size of the local heap */
*heap_size += (hsize_t)(heap->prfx_size + heap->dblk_size);
done:
@@ -1251,45 +1252,3 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HL_heapsize() */
-
-/*-------------------------------------------------------------------------
- * Function: H5HL_dest
- *
- * Purpose: Destroys a heap in memory.
- *
- * Return: Non-negative on success/Negative on failure
- *
- * Programmer: Quincey Koziol
- * koziol@ncsa.uiuc.edu
- * Jan 15 2003
- *
- *-------------------------------------------------------------------------
- */
-herr_t
-H5HL_dest(H5HL_t *heap)
-{
- FUNC_ENTER_NOAPI_NOFUNC(H5HL_dest)
-
- /* check arguments */
- HDassert(heap);
-
- /* Verify that node is unused */
- HDassert(heap->prots == 0);
- HDassert(heap->rc == 0);
- HDassert(heap->prfx == NULL);
- HDassert(heap->dblk == NULL);
-
- if(heap->image)
- heap->image = H5FL_BLK_FREE(lheap_chunk, heap->image);
- while(heap->freelist) {
- H5HL_free_t *fl;
-
- fl = heap->freelist;
- heap->freelist = fl->next;
- H5FL_FREE(H5HL_free_t, fl);
- } /* end while */
- H5FL_FREE(H5HL_t, heap);
-
- FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5HL_dest() */
-
diff --git a/src/H5HLcache.c b/src/H5HLcache.c
index 6bd1ee1..e0d6930 100644
--- a/src/H5HLcache.c
+++ b/src/H5HLcache.c
@@ -139,7 +139,7 @@ const H5AC2_class_t H5AC2_LHEAP_DBLK[1] = {{
*-------------------------------------------------------------------------
*/
static herr_t
-H5HL_fl_deserialize(const H5F_t *f, H5HL_t *heap, hsize_t free_block)
+H5HL_fl_deserialize(H5HL_t *heap, hsize_t free_block)
{
H5HL_free_t *fl, *tail = NULL; /* Heap free block nodes */
herr_t ret_value = SUCCEED; /* Return value */
@@ -155,7 +155,7 @@ H5HL_fl_deserialize(const H5F_t *f, H5HL_t *heap, hsize_t free_block)
/* Sanity check */
if(free_block >= heap->dblk_size)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "bad heap free list")
+ HGOTO_ERROR(H5E_HEAP, H5E_BADRANGE, FAIL, "bad heap free list")
/* Allocate & initialize free list node */
if(NULL == (fl = H5FL_MALLOC(H5HL_free_t)))
@@ -172,15 +172,15 @@ H5HL_fl_deserialize(const H5F_t *f, H5HL_t *heap, hsize_t free_block)
heap->freelist = fl;
/* Decode offset of next free block */
- p = heap->image + free_block;
- H5F_DECODE_LENGTH(f, p, free_block);
+ p = heap->dblk_image + free_block;
+ H5F_DECODE_LENGTH_LEN(p, free_block, heap->sizeof_size);
if(free_block == 0)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "free block size is zero?")
+ HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "free block size is zero?")
/* Decode length of this free block */
- H5F_DECODE_LENGTH(f, p, fl->size);
- if(fl->offset + fl->size > heap->dblk_size)
- HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "bad heap free list")
+ H5F_DECODE_LENGTH_LEN(p, fl->size, heap->sizeof_size);
+ if((fl->offset + fl->size) > heap->dblk_size)
+ HGOTO_ERROR(H5E_HEAP, H5E_BADRANGE, FAIL, "bad heap free list")
} /* end while */
done:
@@ -203,7 +203,7 @@ done:
*-------------------------------------------------------------------------
*/
static void
-H5HL_fl_serialize(const H5F_t *f, H5HL_t *heap)
+H5HL_fl_serialize(const H5HL_t *heap)
{
H5HL_free_t *fl; /* Pointer to heap free list node */
@@ -217,14 +217,14 @@ H5HL_fl_serialize(const H5F_t *f, H5HL_t *heap)
uint8_t *p; /* Pointer into raw data buffer */
HDassert(fl->offset == H5HL_ALIGN(fl->offset));
- p = heap->image + fl->offset;
+ p = heap->dblk_image + fl->offset;
if(fl->next)
- H5F_ENCODE_LENGTH(f, p, fl->next->offset)
+ H5F_ENCODE_LENGTH_LEN(p, fl->next->offset, heap->sizeof_size)
else
- H5F_ENCODE_LENGTH(f, p, H5HL_FREE_NULL)
+ H5F_ENCODE_LENGTH_LEN(p, H5HL_FREE_NULL, heap->sizeof_size)
- H5F_ENCODE_LENGTH(f, p, fl->size);
+ H5F_ENCODE_LENGTH_LEN(p, fl->size, heap->sizeof_size)
} /* end for */
FUNC_LEAVE_NOAPI_VOID
@@ -262,7 +262,9 @@ H5HL_prfx_deserialize(haddr_t addr, size_t len, const void *image,
HDassert(len > 0);
HDassert(image);
HDassert(udata);
- HDassert(udata->f);
+ HDassert(udata->sizeof_size > 0);
+ HDassert(udata->sizeof_addr > 0);
+ HDassert(udata->sizeof_prfx > 0);
/* Point to beginning of image buffer */
p = (const uint8_t *)image;
@@ -280,7 +282,7 @@ H5HL_prfx_deserialize(haddr_t addr, size_t len, const void *image,
p += 3;
/* Allocate space in memory for the heap */
- if(NULL == (heap = H5FL_CALLOC(H5HL_t)))
+ if(NULL == (heap = H5HL_new(udata->sizeof_size, udata->sizeof_addr, udata->sizeof_prfx)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "memory allocation failed")
/* Allocate the heap prefix */
@@ -289,18 +291,18 @@ H5HL_prfx_deserialize(haddr_t addr, size_t len, const void *image,
/* Store the prefix's address & length */
heap->prfx_addr = addr;
- heap->prfx_size = H5HL_SIZEOF_HDR(udata->f);
+ heap->prfx_size = udata->sizeof_prfx;
/* Heap data size */
- H5F_DECODE_LENGTH(udata->f, p, heap->dblk_size);
+ H5F_DECODE_LENGTH_LEN(p, heap->dblk_size, udata->sizeof_size);
/* Free list head */
- H5F_DECODE_LENGTH(udata->f, p, udata->free_block);
+ H5F_DECODE_LENGTH_LEN(p, udata->free_block, udata->sizeof_size);
if(udata->free_block != H5HL_FREE_NULL && udata->free_block >= heap->dblk_size)
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, NULL, "bad heap free list")
/* Heap data address */
- H5F_addr_decode(udata->f, &p, &(heap->dblk_addr));
+ H5F_addr_decode_len(udata->sizeof_addr, &p, &(heap->dblk_addr));
/* Check if heap block exists */
if(heap->dblk_size) {
@@ -312,14 +314,14 @@ H5HL_prfx_deserialize(haddr_t addr, size_t len, const void *image,
/* Check if the current image from the cache is big enough to hold the heap data */
if(len >= (heap->prfx_size + heap->dblk_size)) {
/* Allocate space for the heap data image */
- if(NULL == (heap->image = H5FL_BLK_MALLOC(lheap_chunk, heap->dblk_size)))
+ if(NULL == (heap->dblk_image = H5FL_BLK_MALLOC(lheap_chunk, heap->dblk_size)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "memory allocation failed")
/* Copy the heap data from the image */
- HDmemcpy(heap->image, p, heap->dblk_size);
+ HDmemcpy(heap->dblk_image, p, heap->dblk_size);
/* Build free list */
- if(H5HL_fl_deserialize(udata->f, heap, udata->free_block) < 0)
+ if(H5HL_fl_deserialize(heap, udata->free_block) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't initialize free list")
} /* end if */
else
@@ -407,7 +409,7 @@ H5HL_prfx_image_len(const void *thing, size_t *image_len_ptr)
*-------------------------------------------------------------------------
*/
static herr_t
-H5HL_prfx_serialize(const H5F_t *f, hid_t UNUSED dxpl_id, haddr_t UNUSED addr,
+H5HL_prfx_serialize(const H5F_t UNUSED *f, hid_t UNUSED dxpl_id, haddr_t UNUSED addr,
size_t UNUSED len, void *image, void *_thing, unsigned *flags,
haddr_t UNUSED *new_addr, size_t UNUSED *new_len, void UNUSED **new_image)
{
@@ -418,7 +420,6 @@ H5HL_prfx_serialize(const H5F_t *f, hid_t UNUSED dxpl_id, haddr_t UNUSED addr,
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5HL_prfx_serialize)
/* check arguments */
- HDassert(f);
HDassert(image);
HDassert(prfx);
HDassert(prfx->heap);
@@ -437,17 +438,17 @@ H5HL_prfx_serialize(const H5F_t *f, hid_t UNUSED dxpl_id, haddr_t UNUSED addr,
*p++ = 0; /*reserved*/
*p++ = 0; /*reserved*/
*p++ = 0; /*reserved*/
- H5F_ENCODE_LENGTH(f, p, heap->dblk_size);
- H5F_ENCODE_LENGTH(f, p, heap->freelist ? heap->freelist->offset : H5HL_FREE_NULL);
- H5F_addr_encode(f, &p, heap->dblk_addr);
+ H5F_ENCODE_LENGTH_LEN(p, heap->dblk_size, heap->sizeof_size);
+ H5F_ENCODE_LENGTH_LEN(p, heap->freelist ? heap->freelist->offset : H5HL_FREE_NULL, heap->sizeof_size);
+ H5F_addr_encode_len(heap->sizeof_addr, &p, heap->dblk_addr);
/* Check if the local heap is a single object in cache */
if(heap->single_cache_obj) {
/* Serialize the free list into the heap data's image */
- H5HL_fl_serialize(f, heap);
+ H5HL_fl_serialize(heap);
/* Copy the heap data block into the cache image */
- HDmemcpy(p, heap->image, heap->dblk_size);
+ HDmemcpy(p, heap->dblk_image, heap->dblk_size);
} /* end if */
/* Reset the cache flags for this operation */
@@ -519,7 +520,6 @@ H5HL_dblk_deserialize(haddr_t UNUSED addr, size_t UNUSED len, const void *image,
/* check arguments */
HDassert(image);
HDassert(udata);
- HDassert(udata->f);
HDassert(udata->heap);
HDassert(!udata->heap->single_cache_obj);
HDassert(NULL == udata->heap->dblk);
@@ -529,16 +529,16 @@ H5HL_dblk_deserialize(haddr_t UNUSED addr, size_t UNUSED len, const void *image,
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "memory allocation failed")
/* Check for heap still retaining image */
- if(NULL == udata->heap->image) {
+ if(NULL == udata->heap->dblk_image) {
/* Allocate space for the heap data image */
- if(NULL == (udata->heap->image = H5FL_BLK_MALLOC(lheap_chunk, udata->heap->dblk_size)))
+ if(NULL == (udata->heap->dblk_image = H5FL_BLK_MALLOC(lheap_chunk, udata->heap->dblk_size)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "memory allocation failed")
/* Copy the cache image into the heap's data image */
- HDmemcpy(udata->heap->image, image, udata->heap->dblk_size);
+ HDmemcpy(udata->heap->dblk_image, image, udata->heap->dblk_size);
/* Build free list */
- if(H5HL_fl_deserialize(udata->f, udata->heap, udata->free_block) < 0)
+ if(H5HL_fl_deserialize(udata->heap, udata->free_block) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't initialize free list")
} /* end if */
@@ -572,28 +572,26 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5HL_dblk_serialize(const H5F_t *f, hid_t UNUSED dxpl_id, haddr_t UNUSED addr,
+H5HL_dblk_serialize(const H5F_t UNUSED *f, hid_t UNUSED dxpl_id, haddr_t UNUSED addr,
size_t UNUSED len, void *image, void *_thing, unsigned *flags,
haddr_t UNUSED *new_addr, size_t UNUSED *new_len, void UNUSED **new_image)
{
- H5HL_dblk_t *dblk = (H5HL_dblk_t *)_thing; /* Pointer to the local heap data block */
- H5HL_t *heap; /* Pointer to the local heap */
+ H5HL_dblk_t *dblk = (H5HL_dblk_t *)_thing; /* Pointer to the local heap data block */
+ H5HL_t *heap = dblk->heap; /* Pointer to the local heap */
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5HL_dblk_serialize)
/* check arguments */
HDassert(image);
HDassert(dblk);
+ HDassert(dblk->heap);
HDassert(flags);
- /* Get the pointer to the heap */
- heap = dblk->heap;
-
/* Serialize the free list into the heap data's image */
- H5HL_fl_serialize(f, heap);
+ H5HL_fl_serialize(heap);
/* Copy the heap's data block into the cache's image */
- HDmemcpy(image, heap->image, heap->dblk_size);
+ HDmemcpy(image, heap->dblk_image, heap->dblk_size);
/* Reset the cache flags for this operation */
*flags = 0;
diff --git a/src/H5HLdbg.c b/src/H5HLdbg.c
index 9822607..cb9d070 100644
--- a/src/H5HLdbg.c
+++ b/src/H5HLdbg.c
@@ -108,8 +108,7 @@ H5HL_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, int
marker[freelist->offset + i] = 1;
} /* end for */
if(overlap)
- fprintf(stream, "***THAT FREE BLOCK OVERLAPPED A PREVIOUS "
- "ONE!\n");
+ fprintf(stream, "***THAT FREE BLOCK OVERLAPPED A PREVIOUS ONE!\n");
else
amount_free += freelist->size;
} /* end for */
@@ -123,7 +122,7 @@ H5HL_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE * stream, int indent, int
/*
* Print the data in a VMS-style octal dump.
*/
- H5_buffer_dump(stream, indent, h->image, marker, (size_t)0, h->dblk_size);
+ H5_buffer_dump(stream, indent, h->dblk_image, marker, (size_t)0, h->dblk_size);
done:
if(h && H5HL_unprotect(h) < 0)
diff --git a/src/H5HLint.c b/src/H5HLint.c
index c8d0305..43e3b1f 100644
--- a/src/H5HLint.c
+++ b/src/H5HLint.c
@@ -73,12 +73,59 @@
/* Local Variables */
/*******************/
+/* 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(H5HL_dblk_t);
+H5FL_DEFINE_STATIC(H5HL_dblk_t);
/* Declare a free list to manage the H5HL_prfx_t struct */
-H5FL_DEFINE(H5HL_prfx_t);
+H5FL_DEFINE_STATIC(H5HL_prfx_t);
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5HL_new
+ *
+ * Purpose: Create a new local heap object
+ *
+ * Return: Success: non-NULL pointer to new local heap
+ * Failure: NULL
+ *
+ * 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 */
+
+ FUNC_ENTER_NOAPI(H5HL_new, NULL)
+
+ /* check arguments */
+ HDassert(sizeof_size > 0);
+ HDassert(sizeof_addr > 0);
+ HDassert(prfx_size > 0);
+ /* Allocate new local heap structure */
+ if(NULL == (heap = H5FL_CALLOC(H5HL_t)))
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "memory allocation failed")
+
+ /* Initialize non-zero fields */
+ heap->sizeof_size = sizeof_size;
+ heap->sizeof_addr = sizeof_addr;
+ heap->prfx_size = prfx_size;
+
+ /* Set the return value */
+ ret_value = heap;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5HL_new() */
/*-------------------------------------------------------------------------
@@ -144,6 +191,48 @@ H5HL_dec_rc(H5HL_t *heap)
/*-------------------------------------------------------------------------
+ * Function: H5HL_dest
+ *
+ * Purpose: Destroys a heap in memory.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * koziol@ncsa.uiuc.edu
+ * Jan 15 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5HL_dest(H5HL_t *heap)
+{
+ FUNC_ENTER_NOAPI_NOFUNC(H5HL_dest)
+
+ /* check arguments */
+ HDassert(heap);
+
+ /* Verify that node is unused */
+ HDassert(heap->prots == 0);
+ HDassert(heap->rc == 0);
+ HDassert(heap->prfx == NULL);
+ HDassert(heap->dblk == NULL);
+
+ if(heap->dblk_image)
+ heap->dblk_image = H5FL_BLK_FREE(lheap_chunk, heap->dblk_image);
+ while(heap->freelist) {
+ H5HL_free_t *fl;
+
+ fl = heap->freelist;
+ heap->freelist = fl->next;
+ fl = H5FL_FREE(H5HL_free_t, fl);
+ } /* 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
@@ -212,18 +301,21 @@ H5HL_prfx_dest(H5HL_prfx_t *prfx)
/* check arguments */
HDassert(prfx);
- /* Unlink prefix from heap */
- prfx->heap->prfx = NULL;
+ /* 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")
+ /* 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;
+ /* Unlink heap from prefix */
+ prfx->heap = NULL;
+ } /* end if */
/* Free local heap prefix */
- H5FL_FREE(H5HL_prfx_t, prfx);
+ prfx = H5FL_FREE(H5HL_prfx_t, prfx);
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -317,7 +409,7 @@ H5HL_dblk_dest(H5HL_dblk_t *dblk)
} /* end if */
/* Free local heap data block */
- H5FL_FREE(H5HL_dblk_t, dblk);
+ dblk = H5FL_FREE(H5HL_dblk_t, dblk);
done:
FUNC_LEAVE_NOAPI(ret_value)
diff --git a/src/H5HLpkg.h b/src/H5HLpkg.h
index 4d72212..819ea9d 100644
--- a/src/H5HLpkg.h
+++ b/src/H5HLpkg.h
@@ -48,9 +48,6 @@ H5_DLLVAR const H5AC2_class_t H5AC2_LHEAP_DBLK[1];
/* Declare extern the free list to manage the H5HL_free_t struct */
H5FL_EXTERN(H5HL_free_t);
-/* Declare extern the free list to manage the H5HL_t struct */
-H5FL_EXTERN(H5HL_t);
-
/* Declare extern the PQ free list to manage the heap chunk information */
H5FL_BLK_EXTERN(lheap_chunk);
@@ -87,16 +84,23 @@ typedef struct H5HL_dblk_t H5HL_dblk_t;
typedef struct H5HL_prfx_t H5HL_prfx_t;
struct H5HL_t {
+ /* General heap-management fields */
size_t rc; /* Ref. count for prefix & data block using this struct */
size_t prots; /* # of times the heap has been protected */
+ size_t sizeof_size; /* Size of file sizes */
+ size_t sizeof_addr; /* Size of file addresses */
+ hbool_t single_cache_obj; /* Indicate if the heap is a single object in the cache */
+
+ /* Prefix-specific fields */
H5HL_prfx_t *prfx; /* The prefix object for the heap */
haddr_t prfx_addr; /* address of heap prefix */
size_t prfx_size; /* size of heap prefix */
+
+ /* Data block-specific fields */
H5HL_dblk_t *dblk; /* The data block object for the heap */
haddr_t dblk_addr; /* address of data block */
size_t dblk_size; /* size of heap data block on disk and in mem */
- hbool_t single_cache_obj; /* Indicate if the heap is a single object in the cache */
- uint8_t *image; /*the heap image, including header */
+ uint8_t *dblk_image; /* The data block image */
H5HL_free_t *freelist; /*the free list */
};
@@ -118,7 +122,9 @@ struct H5HL_prfx_t {
typedef struct H5HL_cache_prfx_ud_t {
/* Downwards */
hbool_t made_attempt; /* Whether the deserialize routine was already attempted */
- H5F_t *f; /* File pointer */
+ size_t sizeof_size; /* Size of file sizes */
+ size_t sizeof_addr; /* Size of file addresses */
+ size_t sizeof_prfx; /* Size of heap prefix */
/* Upwards */
hbool_t loaded; /* Whether prefix was loaded from file */
@@ -128,7 +134,6 @@ typedef struct H5HL_cache_prfx_ud_t {
/* Callback information for loading local heap data block from disk */
typedef struct H5HL_cache_dblk_ud_t {
/* Downwards */
- H5F_t *f; /* File pointer */
H5HL_t *heap; /* Local heap */
hsize_t free_block; /* First free block in heap */
@@ -142,6 +147,7 @@ typedef struct H5HL_cache_dblk_ud_t {
/******************************/
/* Heap routines */
+H5_DLL H5HL_t *H5HL_new(size_t sizeof_size, size_t sizeof_addr, size_t prfx_size);
H5_DLL herr_t H5HL_dest(H5HL_t *heap);
/* Heap prefix routines */
@@ -152,6 +158,5 @@ H5_DLL herr_t H5HL_prfx_dest(H5HL_prfx_t *prfx);
H5_DLL H5HL_dblk_t *H5HL_dblk_new(H5HL_t *heap);
H5_DLL herr_t H5HL_dblk_dest(H5HL_dblk_t *dblk);
-#endif
-
+#endif /* _H5HLpkg_H */