summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2016-01-06 17:50:08 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2016-01-06 17:50:08 (GMT)
commit06da6031a596c2d19dcc4a253253b6ea33378728 (patch)
tree941f2252be0b16269e3575c43346627cc163e5d7 /src
parent4bf63f78e71aed68ba946dbfda545d657a9a94b5 (diff)
downloadhdf5-06da6031a596c2d19dcc4a253253b6ea33378728.zip
hdf5-06da6031a596c2d19dcc4a253253b6ea33378728.tar.gz
hdf5-06da6031a596c2d19dcc4a253253b6ea33378728.tar.bz2
[svn-r28819] Description:
Align internal memory sanity checking buffer, to avoid problems when optimization is enabled. Tested on: MacOSX/64 10.11.2 (amazon) w/serial & parallel Linux/32 2.6.x (jam) w/serial
Diffstat (limited to 'src')
-rw-r--r--src/H5MM.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/H5MM.c b/src/H5MM.c
index fd9a4a9..b830d21 100644
--- a/src/H5MM.c
+++ b/src/H5MM.c
@@ -60,9 +60,14 @@ typedef struct H5MM_block_t {
unsigned char sig[H5MM_SIG_SIZE]; /* Signature for the block, to indicate it was allocated with H5MM* interface */
struct H5MM_block_t *next; /* Pointer to next block in the list of allocated blocks */
struct H5MM_block_t *prev; /* Pointer to previous block in the list of allocated blocks */
- size_t size;
- hbool_t in_use;
- unsigned char b[];
+ union {
+ struct {
+ size_t size; /* Size of allocated block */
+ hbool_t in_use; /* Whether the block is in use or is free */
+ } info;
+ double _align; /* Align following buffer (b) to double boundary (unused) */
+ } u;
+ unsigned char b[]; /* Buffer for caller (includes header and footer) */
} H5MM_block_t;
#endif /* H5_MEMORY_ALLOC_SANITY_CHECK */
@@ -154,12 +159,12 @@ H5MM__is_our_block(void *mem)
static void
H5MM__sanity_check_block(const H5MM_block_t *block)
{
- HDassert(block->size > 0);
- HDassert(block->in_use);
+ HDassert(block->u.info.size > 0);
+ HDassert(block->u.info.in_use);
/* Check for head & tail guards, if not head of linked list */
- if(block->size != SIZET_MAX) {
+ if(block->u.info.size != SIZET_MAX) {
HDassert(0 == HDmemcmp(block->b, H5MM_block_head_guard_s, H5MM_HEAD_GUARD_SIZE));
- HDassert(0 == HDmemcmp(block->b + H5MM_HEAD_GUARD_SIZE + block->size, H5MM_block_tail_guard_s, H5MM_TAIL_GUARD_SIZE));
+ HDassert(0 == HDmemcmp(block->b + H5MM_HEAD_GUARD_SIZE + block->u.info.size, H5MM_block_tail_guard_s, H5MM_TAIL_GUARD_SIZE));
}
}
@@ -271,13 +276,16 @@ H5MM_malloc(size_t size)
FUNC_ENTER_NOAPI_NOINIT_NOERR
#if defined H5_MEMORY_ALLOC_SANITY_CHECK
+ /* Make certain that the buffer in the struct is properly aligned */
+ HDcompile_assert(offsetof(H5MM_block_t, b) % sizeof(double) == 0);
+
/* Initialize block list head singleton */
if(!H5MM_init_s) {
HDmemcpy(H5MM_block_head_s.sig, H5MM_block_signature_s, H5MM_SIG_SIZE);
H5MM_block_head_s.next = &H5MM_block_head_s;
H5MM_block_head_s.prev = &H5MM_block_head_s;
- H5MM_block_head_s.size = SIZET_MAX;
- H5MM_block_head_s.in_use = TRUE;
+ H5MM_block_head_s.u.info.size = SIZET_MAX;
+ H5MM_block_head_s.u.info.in_use = TRUE;
H5MM_init_s = TRUE;
} /* end if */
@@ -295,8 +303,8 @@ H5MM_malloc(size_t size)
H5MM_block_head_s.next = block;
block->next->prev = block;
block->prev = &H5MM_block_head_s;
- block->size = size;
- block->in_use = TRUE;
+ block->u.info.size = size;
+ block->u.info.in_use = TRUE;
HDmemcpy(block->b, H5MM_block_head_guard_s, H5MM_HEAD_GUARD_SIZE);
HDmemcpy(block->b + H5MM_HEAD_GUARD_SIZE + size, H5MM_block_tail_guard_s, H5MM_TAIL_GUARD_SIZE);
@@ -414,7 +422,7 @@ H5MM_realloc(void *mem, size_t size)
if(mem) {
if(H5MM__is_our_block(mem)) {
H5MM_block_t *block = H5MM_BLOCK_FROM_BUF(mem);
- size_t old_size = block->size;
+ size_t old_size = block->u.info.size;
H5MM__sanity_check(mem);
@@ -545,7 +553,7 @@ H5MM_xfree(void *mem)
H5MM__sanity_check_block(block->prev);
/* Update statistics */
- H5MM_curr_alloc_bytes_s -= block->size;
+ H5MM_curr_alloc_bytes_s -= block->u.info.size;
H5MM_curr_alloc_blocks_count_s--;
/* Reset block info */
@@ -554,7 +562,7 @@ H5MM_xfree(void *mem)
block->prev->next = block->next;
block->next = NULL;
block->prev = NULL;
- block->in_use = FALSE;
+ block->u.info.in_use = FALSE;
/* Free the block (finally!) */
HDfree(block);