summaryrefslogtreecommitdiffstats
path: root/src/H5O.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5O.c')
-rw-r--r--src/H5O.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/H5O.c b/src/H5O.c
index 5a8169d..b289bd4 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -1285,7 +1285,6 @@ H5O_modify(H5G_entry_t *ent, const H5O_class_t *type, intn overwrite,
"object header message is too large (16k max)");
}
}
- size = H5O_ALIGN(size);
idx = H5O_alloc(ent->file, oh, type, size);
if (idx < 0) {
HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL,
@@ -1371,7 +1370,6 @@ H5O_touch_oh(H5F_t *f, H5O_t *oh, hbool_t force)
if (idx==oh->nmesgs) {
if (!force) HRETURN(SUCCEED); /*nothing to do*/
size = (H5O_MTIME->raw_size)(f, &now);
- size = H5O_ALIGN(size);
if ((idx=H5O_alloc(f, oh, H5O_MTIME, size))<0) {
HRETURN_ERROR(H5E_OHDR, H5E_CANTINIT, FAIL,
"unable to allocate space for modification time "
@@ -1571,7 +1569,7 @@ H5O_remove(H5G_entry_t *ent, const H5O_class_t *type, intn sequence)
*
* Purpose: Extends a chunk which hasn't been allocated on disk yet
* to make the chunk large enough to contain a message whose
- * data size is at least SIZE bytes.
+ * data size is exactly SIZE bytes (SIZE need not be aligned).
*
* If the last message of the chunk is the null message, then
* that message will be extended with the chunk. Otherwise a
@@ -1598,7 +1596,8 @@ static intn
H5O_alloc_extend_chunk(H5O_t *oh, intn chunkno, size_t size)
{
intn idx, i;
- size_t delta, padding;
+ size_t delta, old_size;
+ size_t aligned_size = H5O_ALIGN(size);
uint8_t *old_addr;
FUNC_ENTER(H5O_alloc_extend_chunk, FAIL);
@@ -1607,7 +1606,6 @@ H5O_alloc_extend_chunk(H5O_t *oh, intn chunkno, size_t size)
assert(oh);
assert(chunkno >= 0 && chunkno < oh->nchunks);
assert(size > 0);
- assert (size==H5O_ALIGN (size));
if (H5F_addr_defined(oh->chunk[chunkno].addr)) {
HRETURN_ERROR(H5E_OHDR, H5E_NOSPACE, FAIL, "chunk is on disk");
@@ -1619,7 +1617,7 @@ H5O_alloc_extend_chunk(H5O_t *oh, intn chunkno, size_t size)
(oh->mesg[idx].raw + oh->mesg[idx].raw_size ==
oh->chunk[chunkno].image + oh->chunk[chunkno].size)) {
- delta = MAX (H5O_MIN_SIZE, size - oh->mesg[idx].raw_size);
+ delta = MAX (H5O_MIN_SIZE, aligned_size - oh->mesg[idx].raw_size);
assert (delta=H5O_ALIGN (delta));
oh->mesg[idx].dirty = TRUE;
oh->mesg[idx].raw_size += delta;
@@ -1662,8 +1660,7 @@ H5O_alloc_extend_chunk(H5O_t *oh, intn chunkno, size_t size)
oh->alloc_nmesgs = (intn)na;
oh->mesg = x;
}
- delta = MAX(H5O_MIN_SIZE, size+H5O_SIZEOF_MSGHDR(f));
- padding = H5O_ALIGN(delta) - delta;
+ delta = MAX(H5O_MIN_SIZE, aligned_size+H5O_SIZEOF_MSGHDR(f));
delta = H5O_ALIGN(delta);
idx = oh->nmesgs++;
oh->mesg[idx].type = H5O_NULL;
@@ -1676,6 +1673,7 @@ H5O_alloc_extend_chunk(H5O_t *oh, intn chunkno, size_t size)
oh->mesg[idx].chunkno = chunkno;
old_addr = oh->chunk[chunkno].image;
+ old_size = oh->chunk[chunkno].size;
oh->chunk[chunkno].size += delta;
oh->chunk[chunkno].image = H5MM_realloc(old_addr,
oh->chunk[chunkno].size);
@@ -1683,8 +1681,8 @@ H5O_alloc_extend_chunk(H5O_t *oh, intn chunkno, size_t size)
HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
"memory allocation failed");
}
- HDmemset(oh->chunk[chunkno].image+oh->chunk[chunkno].size-padding,
- 0, padding);
+ HDmemset(oh->chunk[chunkno].image+old_size, 0,
+ oh->chunk[chunkno].size - old_size);
/* adjust raw addresses for messages of this chunk */
if (old_addr != oh->chunk[chunkno].image) {
@@ -1709,6 +1707,8 @@ H5O_alloc_extend_chunk(H5O_t *oh, intn chunkno, size_t size)
* message, then some message from another chunk is moved into
* this chunk to make room.
*
+ * SIZE need not be aligned.
+ *
* Return: Success: Index number of the null message for the
* new chunk. The null message will be at
* least SIZE bytes not counting the message
@@ -1740,7 +1740,7 @@ H5O_alloc_new_chunk(H5F_t *f, H5O_t *oh, size_t size)
/* check args */
assert (oh);
assert (size > 0);
- assert (size == H5O_ALIGN (size));
+ size = H5O_ALIGN(size);
/*
* Find the smallest null message that will hold an object
@@ -1916,18 +1916,18 @@ H5O_alloc(H5F_t *f, H5O_t *oh, const H5O_class_t *type, size_t size)
intn chunkno;
intn idx;
intn null_idx;
+ size_t aligned_size = H5O_ALIGN(size);
FUNC_ENTER(H5O_alloc, FAIL);
/* check args */
assert (oh);
assert (type);
- assert (size == H5O_ALIGN (size));
/* look for a null message which is large enough */
for (idx = 0; idx < oh->nmesgs; idx++) {
if (H5O_NULL_ID == oh->mesg[idx].type->id &&
- oh->mesg[idx].raw_size >= size)
+ oh->mesg[idx].raw_size >= aligned_size)
break;
}
@@ -1966,8 +1966,8 @@ H5O_alloc(H5F_t *f, H5O_t *oh, const H5O_class_t *type, size_t size)
}
/* do we need to split the null message? */
- if (oh->mesg[idx].raw_size > size) {
- assert(oh->mesg[idx].raw_size - size >= H5O_SIZEOF_MSGHDR(f));
+ if (oh->mesg[idx].raw_size > aligned_size) {
+ assert(oh->mesg[idx].raw_size - aligned_size >= H5O_SIZEOF_MSGHDR(f));
if (oh->nmesgs >= oh->alloc_nmesgs) {
int old_alloc=oh->alloc_nmesgs;
@@ -1989,12 +1989,12 @@ H5O_alloc(H5F_t *f, H5O_t *oh, const H5O_class_t *type, size_t size)
oh->mesg[null_idx].dirty = TRUE;
oh->mesg[null_idx].native = NULL;
oh->mesg[null_idx].raw = oh->mesg[idx].raw +
- size +
+ aligned_size +
H5O_SIZEOF_MSGHDR(f);
oh->mesg[null_idx].raw_size = oh->mesg[idx].raw_size -
- (size + H5O_SIZEOF_MSGHDR(f));
+ (aligned_size + H5O_SIZEOF_MSGHDR(f));
oh->mesg[null_idx].chunkno = oh->mesg[idx].chunkno;
- oh->mesg[idx].raw_size = size;
+ oh->mesg[idx].raw_size = aligned_size;
}
/* initialize the new message */