summaryrefslogtreecommitdiffstats
path: root/src/H5HG.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-10-08 17:13:14 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-10-08 17:13:14 (GMT)
commit19ec99786adba12a7517f633888c3976738135ce (patch)
tree8d40536cf23cbded60afb3133c1cefd1aebeb3ed /src/H5HG.c
parent1fddd40b8b45e8ced68d2192e10baf000deb0857 (diff)
downloadhdf5-19ec99786adba12a7517f633888c3976738135ce.zip
hdf5-19ec99786adba12a7517f633888c3976738135ce.tar.gz
hdf5-19ec99786adba12a7517f633888c3976738135ce.tar.bz2
[svn-r745] Changes since 19981002
---------------------- ./doc/html/H5.format.html ./src/H5HG.c Fixed a bug in the global heap that caused H5HG_read() to write past the end of the buffer in certain cases. ./test/big.c The test is skipped if hdf5 was configured with `--disable-hsizet'. ./src/H5Ofill.c Data type conversions are implemented for the fill value. ./src/H5.c Tracing prints one of H5P_FILE_CREATE, H5P_FILE_ACCESS, H5P_DATASET_CREATE, H5P_DATASET_XFER, or H5P_MOUNT instead of the more cryptic H5I_TEMPLATE_* constants. ./src/H5D.c Removed prototype for H5D_find_name(). ./src/H5I.c The GROUP_MASK and ID_MASK are both calculated from GROUP_BITS instead of being set by hand. We don't use the sign bit of hid_t; all valid hid_t values are positive so we can say things like `if ((file=H5Fopen(...))<0)'. Changed `(int)pow(2.0,x)' to `1<<x' so we don't have to worry about rounding. Fixed H5I_get_type() so it doesn't always fail an assertion. ./src/H5E.c ./src/H5Epublic.h Added minor error H5E_MOUNT ./src/H5F.c ./src/H5Fprivate.h Added H5Fmount() and H5Funmount(). Mounting and unmounting works as documented but some of the other things aren't implemented yet, the biggest being current working groups always acting on the root of the mount tree, and H5Fclose() closing the entire tree. The rest of the stuff will be added shortly... ./src/H5P.c ./src/H5Ppublic.h Added the H5P_MOUNT property list but haven't implemented any particular properties for it yet. ./src/H5Gstab.c Hard links across files return an error instead of failing an assertion.
Diffstat (limited to 'src/H5HG.c')
-rw-r--r--src/H5HG.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/src/H5HG.c b/src/H5HG.c
index b0e4c9d..f3e73bf 100644
--- a/src/H5HG.c
+++ b/src/H5HG.c
@@ -136,7 +136,7 @@ H5HG_create (H5F_t *f, size_t size)
H5F_encode_length (f, p, size);
/* The freespace object */
- heap->obj[0].size = size - H5HG_SIZEOF_HDR (f);
+ heap->obj[0].size = size - H5HG_SIZEOF_HDR(f);
heap->obj[0].begin = p;
UINT16ENCODE(p, 0); /*object ID*/
UINT16ENCODE(p, 0); /*reference count*/
@@ -294,10 +294,11 @@ H5HG_load (H5F_t *f, const haddr_t *addr, const void __unused__ *udata1,
p += 4; /*reserved*/
H5F_decode_length (f, p, heap->obj[idx].size);
heap->obj[idx].begin = begin;
- p = begin + heap->obj[idx].size;
+ p = begin + H5HG_ALIGN(heap->obj[idx].size);
}
}
- assert (p==heap->chunk+heap->size);
+ assert(p==heap->chunk+heap->size);
+ assert(heap->obj[0].size==H5HG_ALIGN(heap->obj[0].size));
/*
* Add the new heap to the CWFS list, removing some other entry if
@@ -404,7 +405,9 @@ H5HG_flush (H5F_t *f, hbool_t destroy, const haddr_t *addr, H5HG_heap_t *heap)
*
* Purpose: Given a heap with enough free space, this function will split
* the free space to make a new empty heap object and initialize
- * the header.
+ * the header. SIZE is the exact size of the object data to be
+ * stored. It will be increased to make room for the object
+ * header and then rounded up for alignment.
*
* Return: Success: The heap object ID of the new object.
*
@@ -422,12 +425,13 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, int cwfsno, size_t size)
{
int idx;
uint8 *p = NULL;
-
+ size_t need = H5HG_ALIGN(H5HG_SIZEOF_OBJHDR(f) + size);
+
FUNC_ENTER (H5HG_alloc, FAIL);
/* Check args */
assert (heap);
- assert (heap->obj[0].size>=size);
+ assert (heap->obj[0].size>=need);
/*
* Find an ID for the new object. ID zero is reserved for the free space
@@ -449,7 +453,7 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, int cwfsno, size_t size)
H5F_encode_length (f, p, size);
/* Fix the free space object */
- if (size==heap->obj[0].size) {
+ if (need==heap->obj[0].size) {
/*
* All free space has been exhausted from this collection. Remove the
* heap from the CWFS list.
@@ -462,13 +466,13 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, int cwfsno, size_t size)
(f->shared->ncwfs-cwfsno)*sizeof(H5HG_heap_t*));
}
- } else if (heap->obj[0].size-size >= H5HG_SIZEOF_OBJHDR (f)) {
+ } else if (heap->obj[0].size-need >= H5HG_SIZEOF_OBJHDR (f)) {
/*
* Some free space remains and it's larger than a heap object header,
* so write the new free heap object header to the heap.
*/
- heap->obj[0].size -= size;
- heap->obj[0].begin += size;
+ heap->obj[0].size -= need;
+ heap->obj[0].begin += need;
p = heap->obj[0].begin;
UINT16ENCODE(p, 0); /*id*/
UINT16ENCODE(p, 0); /*nrefs*/
@@ -480,8 +484,8 @@ H5HG_alloc (H5F_t *f, H5HG_heap_t *heap, int cwfsno, size_t size)
* Some free space remains but it's smaller than a heap object header,
* so we don't write the header.
*/
- heap->obj[0].size -= size;
- heap->obj[0].begin += size;
+ heap->obj[0].size -= need;
+ heap->obj[0].begin += need;
}
heap->dirty = 1;
@@ -566,7 +570,7 @@ H5HG_insert (H5F_t *f, size_t size, void *obj, H5HG_t *hobj/*out*/)
}
/* Split the free space to make room for the new object */
- idx = H5HG_alloc (f, heap, cwfsno, need);
+ idx = H5HG_alloc (f, heap, cwfsno, size);
assert (idx>0);
/* Copy data into the heap */
@@ -683,7 +687,7 @@ H5HG_read (H5F_t *f, H5HG_t *hobj, void *object/*out*/)
}
assert (hobj->idx>0 && hobj->idx<heap->nalloc);
assert (heap->obj[hobj->idx].begin);
- size = heap->obj[hobj->idx].size - H5HG_SIZEOF_OBJHDR (f);
+ size = heap->obj[hobj->idx].size;
p = heap->obj[hobj->idx].begin + H5HG_SIZEOF_OBJHDR (f);
if (!object && NULL==(object = H5MM_malloc (size))) {
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
@@ -788,7 +792,7 @@ H5HG_remove (H5F_t *f, H5HG_t *hobj)
{
uint8 *p=NULL, *obj_start=NULL;
H5HG_heap_t *heap = NULL;
- size_t size;
+ size_t need;
intn i;
FUNC_ENTER (H5HG_remove, FAIL);
@@ -808,29 +812,29 @@ H5HG_remove (H5F_t *f, H5HG_t *hobj)
assert (hobj->idx>0 && hobj->idx<heap->nalloc);
assert (heap->obj[hobj->idx].begin);
obj_start = heap->obj[hobj->idx].begin;
- size = heap->obj[hobj->idx].size;
+ need = H5HG_ALIGN(heap->obj[hobj->idx].size);
/* Move the new free space to the end of the heap */
for (i=0; i<heap->nalloc; i++) {
if (heap->obj[i].begin > heap->obj[hobj->idx].begin) {
- heap->obj[i].begin -= size;
+ heap->obj[i].begin -= need;
}
}
if (NULL==heap->obj[0].begin) {
- heap->obj[0].begin = heap->chunk + (heap->size-size);
- heap->obj[0].size = size;
+ heap->obj[0].begin = heap->chunk + (heap->size-need);
+ heap->obj[0].size = need;
heap->obj[0].nrefs = 0;
} else {
- heap->obj[0].size += size;
+ heap->obj[0].size += need;
}
- HDmemmove (obj_start, obj_start+size,
- heap->size-((obj_start+size)-heap->chunk));
+ HDmemmove (obj_start, obj_start+need,
+ heap->size-((obj_start+need)-heap->chunk));
if (heap->obj[0].size>=H5HG_SIZEOF_OBJHDR (f)) {
p = heap->obj[0].begin;
UINT16ENCODE(p, 0); /*id*/
UINT16ENCODE(p, 0); /*nrefs*/
UINT32ENCODE(p, 0); /*reserved*/
- H5F_encode_length (f, p, size);
+ H5F_encode_length (f, p, need);
}
HDmemset (heap->obj+hobj->idx, 0, sizeof(H5HG_obj_t));
heap->dirty = 1;
@@ -940,9 +944,11 @@ H5HG_debug(H5F_t *f, const haddr_t *addr, FILE *stream, intn indent,
fprintf (stream, "%*s%-*s %d\n", indent+3, "", MIN(fwidth-3, 0),
"Reference count:",
h->obj[i].nrefs);
- fprintf (stream, "%*s%-*s %lu\n", indent+3, "", MIN(fwidth-3, 0),
+ fprintf (stream, "%*s%-*s %lu/%lu\n", indent+3, "",
+ MIN(fwidth-3, 0),
"Size of object body:",
- (unsigned long)(h->obj[i].size));
+ (unsigned long)(h->obj[i].size),
+ (unsigned long)H5HG_ALIGN(h->obj[i].size));
size = h->obj[i].size - H5HG_SIZEOF_OBJHDR (f);
p = h->obj[i].begin + H5HG_SIZEOF_OBJHDR (f);
for (j=0; j<size; j+=16) {