diff options
author | Robb Matzke <matzke@llnl.gov> | 1997-12-16 21:08:26 (GMT) |
---|---|---|
committer | Robb Matzke <matzke@llnl.gov> | 1997-12-16 21:08:26 (GMT) |
commit | e615fc7a982c1817cf7d4c24adf9323604692310 (patch) | |
tree | 5dab77c6c1a4476ab5b5953c45f1ea6a1b5d994e /src/H5H.c | |
parent | faca6fbaa8c557b18d6b264841fc8717d1e73816 (diff) | |
download | hdf5-e615fc7a982c1817cf7d4c24adf9323604692310.zip hdf5-e615fc7a982c1817cf7d4c24adf9323604692310.tar.gz hdf5-e615fc7a982c1817cf7d4c24adf9323604692310.tar.bz2 |
[svn-r146] ./src/H5.c
Changes to error handling.
./src/H5B.c
Increased size of internal static buffers.
./src/H5C.c
Fixed syntax error when NDEBUG is defined.
./src/H5E.c
./src/H5Eprivate.h
./src/H5Epublic.h
Errors can now be printed with H5Eprint(). Other minor
changes to names and arg types.
./src/H5F.c
The base address is now stored in the boot block. The user
block size and the base address are synonyms.
./src/H5Fstdio.c
Fixed a bug with a return value from fseek().
./src/H5H.c
Added alignment constraints to get rid of unaligned access
errors on the DEC alpha having to do with the heap free list.
./src/H5P.c
./src/H5Ppublic.h
Changed some size arguments from int to size_t and fixed
memory allocation calls.
./src/H5T.c
./src/H5Tpublic.h
Changed the order of functions so all the public ones are at
the top of the file. Other minor changes.
./src/H5detect.c
Added a newline to a string constant.
Diffstat (limited to 'src/H5H.c')
-rw-r--r-- | src/H5H.c | 35 |
1 files changed, 22 insertions, 13 deletions
@@ -27,6 +27,7 @@ #define H5H_FREE_NULL 1 /*end of free list on disk */ #define PABLO_MASK H5H_mask +#define H5H_ALIGN(X) (((X)+7)&~0x03) /*align on 8-byte boundary */ typedef struct H5H_free_t { size_t offset; /*offset of free block */ @@ -113,6 +114,7 @@ H5H_create (H5F_t *f, H5H_type_t heap_type, size_t size_hint, if (size_hint && size_hint<H5H_SIZEOF_FREE(f)) { size_hint = H5H_SIZEOF_FREE(f); } + size_hint = H5H_ALIGN (size_hint); /* allocate file version */ total_size = H5H_SIZEOF_HDR(f) + size_hint; @@ -547,7 +549,7 @@ H5H_insert (H5F_t *f, const haddr_t *addr, size_t buf_size, const void *buf) H5H_t *heap=NULL; H5H_free_t *fl=NULL, *max_fl=NULL; size_t offset = 0; - size_t old_size, need_more; + size_t need_size, old_size, need_more; hbool_t found; #ifndef NDEBUG static nmessages = 0; @@ -569,18 +571,25 @@ H5H_insert (H5F_t *f, const haddr_t *addr, size_t buf_size, const void *buf) heap->dirty += 1; /* + * In order to keep the free list descriptors aligned on word boundaries, + * whatever that might mean, we round the size up to the next multiple of + * a word. + */ + need_size = H5H_ALIGN (buf_size); + + /* * Look for a free slot large enough for this object and which would * leave zero or at least H5G_SIZEOF_FREE bytes left over. */ for (fl=heap->freelist,found=FALSE; fl; fl=fl->next) { - if (fl->size>buf_size && fl->size-buf_size>=H5H_SIZEOF_FREE(f)) { + if (fl->size>need_size && fl->size-need_size>=H5H_SIZEOF_FREE(f)) { /* a bigger free block was found */ offset = fl->offset; - fl->offset += buf_size; - fl->size -= buf_size; + fl->offset += need_size; + fl->size -= need_size; found = TRUE; break; - } else if (fl->size==buf_size) { + } else if (fl->size==need_size) { /* free block of exact size found */ offset = fl->offset; fl = H5H_remove_free (heap, fl); @@ -601,15 +610,15 @@ H5H_insert (H5F_t *f, const haddr_t *addr, size_t buf_size, const void *buf) */ if (!found) { - need_more = MAX3 (buf_size, heap->mem_alloc, H5H_SIZEOF_FREE(f)); + need_more = MAX3 (need_size, heap->mem_alloc, H5H_SIZEOF_FREE(f)); if (max_fl && max_fl->offset+max_fl->size==heap->mem_alloc) { /* * Increase the size of the maximum free block. */ offset = max_fl->offset; - max_fl->offset += buf_size; - max_fl->size += need_more - buf_size; + max_fl->offset += need_size; + max_fl->size += need_more - need_size; if (max_fl->size < H5H_SIZEOF_FREE(f)) { #ifndef NDEBUG @@ -631,18 +640,18 @@ H5H_insert (H5F_t *f, const haddr_t *addr, size_t buf_size, const void *buf) * take some space out of it right away. */ offset = heap->mem_alloc; - if (need_more-buf_size >= H5H_SIZEOF_FREE(f)) { + if (need_more-need_size >= H5H_SIZEOF_FREE(f)) { fl = H5MM_xmalloc (sizeof(H5H_free_t)); - fl->offset = heap->mem_alloc + buf_size; - fl->size = need_more - buf_size; + fl->offset = heap->mem_alloc + need_size; + fl->size = need_more - need_size; fl->prev = NULL; fl->next = heap->freelist; if (heap->freelist) heap->freelist->prev = fl; heap->freelist = fl; #ifndef NDEBUG - } else if (need_more>buf_size) { + } else if (need_more>need_size) { fprintf (stderr, "H5H_insert: lost %lu bytes at line %d\n", - (unsigned long)(need_more-buf_size), __LINE__); + (unsigned long)(need_more-need_size), __LINE__); if (0==nmessages++) { fprintf (stderr, "Messages from H5H_insert() will go away " "when assertions are turned off.\n"); |