summaryrefslogtreecommitdiffstats
path: root/src/H5HG.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-07-26 04:41:48 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-07-26 04:41:48 (GMT)
commit7a07c6cc133e62f5f00e6a4baf214c9011657800 (patch)
tree8f3407f18b78c8b0283f0663fd0ba0a4ee608212 /src/H5HG.c
parent6543e55efad7ded7f5a0e0dc50786c966aea6b98 (diff)
downloadhdf5-7a07c6cc133e62f5f00e6a4baf214c9011657800.zip
hdf5-7a07c6cc133e62f5f00e6a4baf214c9011657800.tar.gz
hdf5-7a07c6cc133e62f5f00e6a4baf214c9011657800.tar.bz2
[svn-r8946] Purpose:
Code cleanup, sorta Description: Added ifdef sections for "H5_USING_PURIFY" in various places in the code, which are designed to reduce the spurious "uninitialized memory read" warnings from purify which are actually OK. Note that this macro will have to be turned on by adding it to the CFLAGS for the build - I didn't think it was important enough to add a configure flag for. Also, the changes in H5HG.c optimize the walks through the objects in a heap to only look at the 'used' entries instead of all the 'allocated' entries. Platforms tested: Solaris 2.7 (arabica) w/purify Not tested by h5committest
Diffstat (limited to 'src/H5HG.c')
-rw-r--r--src/H5HG.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/H5HG.c b/src/H5HG.c
index 6ccc0fe..252af88 100644
--- a/src/H5HG.c
+++ b/src/H5HG.c
@@ -218,8 +218,11 @@ H5HG_create (H5F_t *f, hid_t dxpl_id, size_t size)
if (NULL==(heap->chunk = H5FL_BLK_MALLOC (heap_chunk,size)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, \
"memory allocation failed");
+#ifdef H5_USING_PURIFY
+HDmemset(heap->chunk,0,size);
+#endif /* H5_USING_PURIFY */
heap->nalloc = H5HG_NOBJS (f, size);
- heap->next_idx = 1; /* skip index 0, which is used for the free object */
+ heap->nused = 1; /* account for index 0, which is used for the free object */
if (NULL==(heap->obj = H5FL_SEQ_MALLOC (H5HG_obj_t,heap->nalloc)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, \
"memory allocation failed");
@@ -444,9 +447,9 @@ H5HG_load (H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
/* Set the next index value to use */
if(max_idx>0)
- heap->next_idx=max_idx+1;
+ heap->nused=max_idx+1;
else
- heap->next_idx=1;
+ heap->nused=1;
/*
* Add the new heap to the CWFS list, removing some other entry if
@@ -682,11 +685,10 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, size_t size)
* Find an ID for the new object. ID zero is reserved for the free space
* object.
*/
- if(heap->next_idx<H5HG_MAXIDX) {
- idx=heap->next_idx++;
- } /* end if */
+ if(heap->nused<H5HG_MAXIDX)
+ idx=heap->nused++;
else {
- for (idx=1; idx<heap->nalloc; idx++)
+ for (idx=1; idx<heap->nused; idx++)
if (NULL==heap->obj[idx].begin)
break;
} /* end else */
@@ -707,7 +709,7 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, size_t size)
/* Update heap information */
heap->nalloc=new_alloc;
heap->obj=new_obj;
- assert(heap->nalloc>heap->next_idx);
+ assert(heap->nalloc>heap->nused);
} /* end if */
/* Initialize the new object */
@@ -815,6 +817,9 @@ H5HG_extend (H5F_t *f, H5HG_heap_t *heap, size_t size)
/* Re-allocate the heap information in memory */
if (NULL==(new_chunk = H5FL_BLK_REALLOC (heap_chunk, heap->chunk, heap->size+need)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "new heap allocation failed");
+#ifdef H5_USING_PURIFY
+HDmemset(new_chunk+heap->size,0,need);
+#endif /* H5_USING_PURIFY */
/* Adjust the size of the heap */
old_size=heap->size;
@@ -825,7 +830,7 @@ H5HG_extend (H5F_t *f, H5HG_heap_t *heap, size_t size)
H5F_ENCODE_LENGTH (f, p, heap->size);
/* Move the pointers to the existing objects to their new locations */
- for (u=0; u<heap->nalloc; u++)
+ for (u=0; u<heap->nused; u++)
if(heap->obj[u].begin)
heap->obj[u].begin = new_chunk + (heap->obj[u].begin - heap->chunk);
@@ -1081,7 +1086,7 @@ H5HG_peek (H5F_t *f, hid_t dxpl_id, H5HG_t *hobj)
if (NULL == (heap = H5AC_protect(f, dxpl_id, H5AC_GHEAP, hobj->addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR (H5E_HEAP, H5E_CANTLOAD, NULL, "unable to load heap");
- assert (hobj->idx>0 && hobj->idx<heap->nalloc);
+ assert (hobj->idx>0 && hobj->idx<heap->nused);
ret_value = heap->obj[hobj->idx].begin + H5HG_SIZEOF_OBJHDR (f);
assert (ret_value);
@@ -1148,7 +1153,7 @@ H5HG_read (H5F_t *f, hid_t dxpl_id, H5HG_t *hobj, void *object/*out*/)
if (NULL == (heap = H5AC_protect(f, dxpl_id, H5AC_GHEAP, hobj->addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR (H5E_HEAP, H5E_CANTLOAD, NULL, "unable to load heap");
- assert (hobj->idx>0 && hobj->idx<heap->nalloc);
+ assert (hobj->idx>0 && hobj->idx<heap->nused);
assert (heap->obj[hobj->idx].begin);
size = heap->obj[hobj->idx].size;
p = heap->obj[hobj->idx].begin + H5HG_SIZEOF_OBJHDR (f);
@@ -1222,7 +1227,7 @@ H5HG_link (H5F_t *f, hid_t dxpl_id, const H5HG_t *hobj, int adjust)
if (NULL == (heap = H5AC_protect(f, dxpl_id, H5AC_GHEAP, hobj->addr, NULL, NULL, H5AC_WRITE)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load heap");
- assert (hobj->idx>0 && hobj->idx<heap->nalloc);
+ assert (hobj->idx>0 && hobj->idx<heap->nused);
assert (heap->obj[hobj->idx].begin);
if (heap->obj[hobj->idx].nrefs+adjust<0)
HGOTO_ERROR (H5E_HEAP, H5E_BADRANGE, FAIL, "new link count would be out of range");
@@ -1280,14 +1285,14 @@ H5HG_remove (H5F_t *f, hid_t dxpl_id, H5HG_t *hobj)
if (NULL == (heap = H5AC_protect(f, dxpl_id, H5AC_GHEAP, hobj->addr, NULL, NULL, H5AC_WRITE)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load heap");
- assert (hobj->idx>0 && hobj->idx<heap->nalloc);
+ assert (hobj->idx>0 && hobj->idx<heap->nused);
assert (heap->obj[hobj->idx].begin);
obj_start = heap->obj[hobj->idx].begin;
/* Include object header size */
need = H5HG_ALIGN(heap->obj[hobj->idx].size)+H5HG_SIZEOF_OBJHDR(f);
/* Move the new free space to the end of the heap */
- for (u=0; u<heap->nalloc; u++) {
+ for (u=0; u<heap->nused; u++) {
if (heap->obj[u].begin > heap->obj[hobj->idx].begin)
heap->obj[u].begin -= need;
}
@@ -1331,7 +1336,7 @@ H5HG_remove (H5F_t *f, hid_t dxpl_id, H5HG_t *hobj)
f->shared->cwfs[i] = f->shared->cwfs[i-1];
f->shared->cwfs[i-1] = heap;
}
- break;
+ break;
}
}
if (i>=f->shared->ncwfs) {