summaryrefslogtreecommitdiffstats
path: root/src/H5Oalloc.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2012-07-26 19:33:59 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2012-07-26 19:33:59 (GMT)
commit7143164de9d7de52516697bbb6bfc7cd2cf749d6 (patch)
tree107977d9f4732e672d5690072a2e85d82e1ebf28 /src/H5Oalloc.c
parent74e00605264ffb2b782b4f28be15accc7784217c (diff)
downloadhdf5-7143164de9d7de52516697bbb6bfc7cd2cf749d6.zip
hdf5-7143164de9d7de52516697bbb6bfc7cd2cf749d6.tar.gz
hdf5-7143164de9d7de52516697bbb6bfc7cd2cf749d6.tar.bz2
[svn-r22608] Description:
Switch propert list/class iteration from internal to external form of iteration, cleaning up and simplifying the code a bit. Bring other general improvements from plist_encode_decode branch back to trunk. Clean up many warnings. Tested on: Mac OSX/64 10.7.4 (amazon) w/gcc 4.7, debug and C++ & FORTRAN (too minor to require h5committest)
Diffstat (limited to 'src/H5Oalloc.c')
-rw-r--r--src/H5Oalloc.c88
1 files changed, 46 insertions, 42 deletions
diff --git a/src/H5Oalloc.c b/src/H5Oalloc.c
index 05322af..5c00fb2 100644
--- a/src/H5Oalloc.c
+++ b/src/H5Oalloc.c
@@ -59,14 +59,15 @@
/********************/
static herr_t H5O_add_gap(H5F_t *f, H5O_t *oh, unsigned chunkno,
- hbool_t *chk_dirtied, unsigned idx, uint8_t *new_gap_loc, size_t new_gap_size);
+ hbool_t *chk_dirtied, size_t idx, uint8_t *new_gap_loc, size_t new_gap_size);
static herr_t H5O_eliminate_gap(H5O_t *oh, hbool_t *chk_dirtied,
H5O_mesg_t *mesg, uint8_t *new_gap_loc, size_t new_gap_size);
-static herr_t H5O_alloc_null(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned null_idx,
+static herr_t H5O_alloc_null(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t null_idx,
const H5O_msg_class_t *new_type, void *new_native, size_t new_size);
static htri_t H5O_alloc_extend_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh,
- unsigned chunkno, size_t size, int *msg_idx);
-static int H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size);
+ unsigned chunkno, size_t size, size_t *msg_idx);
+static herr_t H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size,
+ size_t *new_idx);
static htri_t H5O_move_cont(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned cont_u);
static htri_t H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh);
static htri_t H5O_merge_null(H5F_t *f, hid_t dxpl_id, H5O_t *oh);
@@ -109,10 +110,10 @@ H5FL_EXTERN(H5O_cont_t);
*/
static herr_t
H5O_add_gap(H5F_t *f, H5O_t *oh, unsigned chunkno, hbool_t *chk_dirtied,
- unsigned idx, uint8_t *new_gap_loc, size_t new_gap_size)
+ size_t idx, uint8_t *new_gap_loc, size_t new_gap_size)
{
hbool_t merged_with_null; /* Whether the gap was merged with a null message */
- unsigned u; /* Local index variable */
+ size_t u; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -335,7 +336,7 @@ H5O_eliminate_gap(H5O_t *oh, hbool_t *chk_dirtied, H5O_mesg_t *mesg,
*-------------------------------------------------------------------------
*/
static herr_t
-H5O_alloc_null(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned null_idx,
+H5O_alloc_null(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t null_idx,
const H5O_msg_class_t *new_type, void *new_native, size_t new_size)
{
H5O_chunk_proxy_t *chk_proxy = NULL; /* Chunk that message is in */
@@ -505,7 +506,7 @@ done:
*/
static htri_t
H5O_alloc_extend_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno,
- size_t size, int *msg_idx)
+ size_t size, size_t *msg_idx)
{
H5O_chunk_proxy_t *chk_proxy = NULL; /* Chunk that message is in */
hbool_t chk_dirtied = FALSE; /* Flag for unprotecting chunk */
@@ -514,11 +515,12 @@ H5O_alloc_extend_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno,
uint8_t *old_image; /* Old address of chunk's image in memory */
size_t old_size; /* Old size of chunk */
htri_t extended; /* If chunk can be extended */
- int extend_msg = -1;/* Index of null message to extend */
+ size_t extend_msg; /* Index of null message to extend */
+ hbool_t extended_msg = FALSE; /* Whether an existing message was extended */
uint8_t new_size_flags = 0; /* New chunk #0 size flags */
hbool_t adjust_size_flags = FALSE; /* Whether to adjust the chunk #0 size flags */
size_t extra_prfx_size = 0; /* Extra bytes added to object header prefix */
- unsigned u; /* Local index variable */
+ size_t u; /* Local index variable */
htri_t ret_value = TRUE; /* return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -542,13 +544,14 @@ H5O_alloc_extend_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno,
== ((oh->chunk[chunkno].image + oh->chunk[chunkno].size) -
(oh->chunk[chunkno].gap + H5O_SIZEOF_CHKSUM_OH(oh))))) {
- extend_msg = (int)u;
+ extend_msg = u;
+ extended_msg = TRUE;
break;
} /* end if */
} /* end for */
/* If we can extend an existing null message, adjust the delta appropriately */
- if(extend_msg >= 0) {
+ if(extended_msg) {
HDassert(oh->chunk[chunkno].gap == 0);
delta = aligned_size - oh->mesg[extend_msg].raw_size;
} /* end if */
@@ -598,7 +601,7 @@ H5O_alloc_extend_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno,
/* Adjust object header prefix flags */
if(adjust_size_flags) {
- oh->flags &= (uint8_t)~H5O_HDR_CHUNK0_SIZE;
+ oh->flags = (uint8_t)(oh->flags & ~H5O_HDR_CHUNK0_SIZE);
oh->flags |= new_size_flags;
/* Mark object header as dirty in cache */
@@ -607,7 +610,7 @@ H5O_alloc_extend_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno,
} /* end if */
/* If we can extend an existing null message, take care of that */
- if(extend_msg >= 0) {
+ if(extended_msg) {
/* Adjust message size of existing null message */
oh->mesg[extend_msg].raw_size += delta;
} /* end if */
@@ -619,7 +622,7 @@ H5O_alloc_extend_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno,
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate more space for messages")
/* Set extension message */
- extend_msg = (int)oh->nmesgs++;
+ extend_msg = oh->nmesgs++;
/* Initialize new null message */
oh->mesg[extend_msg].type = H5O_MSG_NULL;
@@ -690,7 +693,7 @@ H5O_alloc_extend_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno,
if(H5O_chunk_resize(oh, chk_proxy) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTRESIZE, FAIL, "unable to resize object header chunk")
- /* Set return value */
+ /* Set new message index */
*msg_idx = extend_msg;
done:
@@ -737,8 +740,8 @@ done:
*
*-------------------------------------------------------------------------
*/
-static int
-H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size)
+static herr_t
+H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size, size_t *new_idx)
{
/* Struct for storing information about "best" messages to allocate from */
typedef struct {
@@ -756,13 +759,13 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size)
int found_null = (-1); /* Best fit null message */
alloc_info found_attr = {-1, 0, 0, 0, 0}; /* Best fit attribute message */
alloc_info found_other = {-1, 0, 0, 0, 0}; /* Best fit other message */
- unsigned idx; /*message number */
+ size_t idx; /* Message number */
uint8_t *p = NULL; /*ptr into new chunk */
H5O_cont_t *cont = NULL; /*native continuation message */
unsigned chunkno; /* Chunk allocated */
haddr_t new_chunk_addr;
unsigned u; /* Local index variable */
- int ret_value; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
@@ -1089,11 +1092,11 @@ H5O_alloc_new_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, size_t size)
cont->chunkno = chunkno;
/* Split the null message and point at continuation message */
- if(H5O_alloc_null(f, dxpl_id, oh, (unsigned)found_null, H5O_MSG_CONT, cont, cont_size) < 0)
+ if(H5O_alloc_null(f, dxpl_id, oh, (size_t)found_null, H5O_MSG_CONT, cont, cont_size) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTINSERT, FAIL, "can't split null message")
- /* Set return value */
- ret_value = (int)idx;
+ /* Set new message index value */
+ *new_idx = idx;
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -1114,14 +1117,14 @@ done:
*
*-------------------------------------------------------------------------
*/
-int
+herr_t
H5O_alloc(H5F_t *f, hid_t dxpl_id, H5O_t *oh, const H5O_msg_class_t *type,
- const void *mesg)
+ const void *mesg, size_t *mesg_idx)
{
- size_t raw_size; /* Raw size of message */
- size_t aligned_size; /* Size of message including alignment */
- int idx; /* Index of message which fits allocation */
- int ret_value; /* Return value */
+ size_t raw_size; /* Raw size of message */
+ size_t aligned_size; /* Size of message including alignment */
+ size_t idx; /* Index of message which fits allocation */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
@@ -1129,6 +1132,7 @@ H5O_alloc(H5F_t *f, hid_t dxpl_id, H5O_t *oh, const H5O_msg_class_t *type,
HDassert(oh);
HDassert(type);
HDassert(mesg);
+ HDassert(mesg_idx);
/* Compute the size needed to store the message in the object header */
raw_size = (type->raw_size)(f, FALSE, mesg);
@@ -1139,12 +1143,12 @@ H5O_alloc(H5F_t *f, hid_t dxpl_id, H5O_t *oh, const H5O_msg_class_t *type,
aligned_size = H5O_ALIGN_OH(oh, raw_size);
/* look for a null message which is large enough */
- for(idx = 0; idx < (int)oh->nmesgs; idx++)
+ for(idx = 0; idx < oh->nmesgs; idx++)
if(H5O_NULL_ID == oh->mesg[idx].type->id && oh->mesg[idx].raw_size >= aligned_size)
break;
/* if we didn't find one, then allocate more header space */
- if(idx >= (int)oh->nmesgs) {
+ if(idx >= oh->nmesgs) {
unsigned chunkno;
/* check to see if we can extend one of the chunks. If we can,
@@ -1163,22 +1167,22 @@ H5O_alloc(H5F_t *f, hid_t dxpl_id, H5O_t *oh, const H5O_msg_class_t *type,
} /* end for */
/* If we were not able to extend a chunk, create a new one */
- if(idx >= (int)oh->nmesgs)
- if((idx = H5O_alloc_new_chunk(f, dxpl_id, oh, raw_size)) < 0)
+ if(idx >= oh->nmesgs)
+ if(H5O_alloc_new_chunk(f, dxpl_id, oh, raw_size, &idx) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_NOSPACE, FAIL, "unable to create a new object header data chunk")
} /* end if */
- HDassert(idx >= 0 && idx < (int)oh->nmesgs);
+ HDassert(idx < oh->nmesgs);
/* Split the null message and point at continuation message */
- if(H5O_alloc_null(f, dxpl_id, oh, (unsigned)idx, type, NULL, aligned_size) < 0)
+ if(H5O_alloc_null(f, dxpl_id, oh, idx, type, NULL, aligned_size) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTINSERT, FAIL, "can't split null message")
/* Mark object header as dirty in cache */
if(H5AC_mark_entry_dirty(oh) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTMARKDIRTY, FAIL, "unable to mark object header as dirty")
- /* Set return value */
- ret_value = (int)idx;
+ /* Set message index value */
+ *mesg_idx = idx;
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -1296,7 +1300,7 @@ H5O_move_cont(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned cont_u)
size_t nonnull_size; /* Total size of nonnull messages in the chunk pointed to by cont message */
H5O_mesg_t *curr_msg; /* Pointer to the current message to operate on */
size_t gap_size; /* Size of gap produced */
- unsigned v; /* Local index variable */
+ size_t v; /* Local index variable */
/* Spin through messages */
nonnull_size = 0;
@@ -1533,7 +1537,7 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh)
} /* end if */
else {
H5O_mesg_t *null_msg; /* Pointer to current message to operate on */
- unsigned v; /* Local index variable */
+ size_t v; /* Local index variable */
/* Check if messages in chunk pointed to can replace continuation message */
if(H5O_CONT_ID == curr_msg->type->id) {
@@ -1607,7 +1611,7 @@ H5O_move_msgs_forward(H5F_t *f, hid_t dxpl_id, H5O_t *oh)
null_chk_dirtied = FALSE;
} /* end if */
else {
- unsigned new_null_msg; /* Message index for new null message */
+ size_t new_null_msg; /* Message index for new null message */
/* Check if null message is large enough to still exist */
if((null_msg->raw_size - curr_msg->raw_size) < (size_t)H5O_SIZEOF_MSGHDR_OH(oh)) {
@@ -2135,8 +2139,8 @@ H5O_alloc_shrink_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno)
uint8_t new_size_flags = 0; /* New chunk #0 size flags */
hbool_t adjust_size_flags = FALSE; /* Whether to adjust the chunk #0 size flags */
size_t less_prfx_size = 0; /* Bytes removed from object header prefix */
+ size_t u; /* Index */
herr_t ret_value = SUCCEED; /* Return value */
- unsigned u; /* Index */
FUNC_ENTER_NOAPI_NOINIT
@@ -2237,7 +2241,7 @@ H5O_alloc_shrink_chunk(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned chunkno)
if(adjust_size_flags) {
/* Adjust object header prefix flags */
- oh->flags &= (uint8_t)~H5O_HDR_CHUNK0_SIZE;
+ oh->flags = (uint8_t)(oh->flags & ~H5O_HDR_CHUNK0_SIZE);
oh->flags |= new_size_flags;
/* Slide chunk 0 data down */