diff options
author | Larry Knox <lrknox@hdfgroup.org> | 2020-10-08 18:40:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 18:40:06 (GMT) |
commit | e146de3feaa761cffd0d1575bd6450f22bbdf09f (patch) | |
tree | a914d23cea0a0e9bd81daf1b73b037441a5f08c3 /src | |
parent | 8c2e9b608ce5243a3e194d125d98772ce60d9c33 (diff) | |
parent | 0e830ba4360a154d4b72a65298aae0f4cf888504 (diff) | |
download | hdf5-e146de3feaa761cffd0d1575bd6450f22bbdf09f.zip hdf5-e146de3feaa761cffd0d1575bd6450f22bbdf09f.tar.gz hdf5-e146de3feaa761cffd0d1575bd6450f22bbdf09f.tar.bz2 |
Merge pull request #29 from byrnHDF/hdf5_1_10
Merge from develop and 1.12
Diffstat (limited to 'src')
-rw-r--r-- | src/H5EA.c | 1220 | ||||
-rw-r--r-- | src/H5EAcache.c | 2166 | ||||
-rw-r--r-- | src/H5EAdbg.c | 548 | ||||
-rw-r--r-- | src/H5EAdblkpage.c | 273 | ||||
-rw-r--r-- | src/H5EAdblock.c | 480 | ||||
-rw-r--r-- | src/H5EAhdr.c | 716 | ||||
-rw-r--r-- | src/H5EAiblock.c | 537 | ||||
-rw-r--r-- | src/H5EAint.c | 28 | ||||
-rw-r--r-- | src/H5EAsblock.c | 422 | ||||
-rw-r--r-- | src/H5EAstat.c | 16 | ||||
-rw-r--r-- | src/H5EAtest.c | 270 | ||||
-rw-r--r-- | src/H5FA.c | 837 | ||||
-rw-r--r-- | src/H5FAcache.c | 1116 | ||||
-rw-r--r-- | src/H5FAdbg.c | 314 | ||||
-rw-r--r-- | src/H5FAdblkpage.c | 260 | ||||
-rw-r--r-- | src/H5FAdblock.c | 430 | ||||
-rw-r--r-- | src/H5FAhdr.c | 428 | ||||
-rw-r--r-- | src/H5FAint.c | 28 | ||||
-rw-r--r-- | src/H5FAstat.c | 16 | ||||
-rw-r--r-- | src/H5FAtest.c | 194 | ||||
-rw-r--r-- | src/H5HL.c | 1211 | ||||
-rw-r--r-- | src/H5HLdbg.c | 134 | ||||
-rw-r--r-- | src/H5HLdblk.c | 244 | ||||
-rw-r--r-- | src/H5HLint.c | 108 | ||||
-rw-r--r-- | src/H5HLprfx.c | 70 |
25 files changed, 6050 insertions, 6016 deletions
@@ -119,50 +119,50 @@ H5FL_BLK_DEFINE(ea_native_elmt); BEGIN_FUNC(STATIC, ERR, H5EA_t *, NULL, NULL, H5EA__new(H5F_t *f, haddr_t ea_addr, hbool_t from_open, void *ctx_udata)) -/* Local variables */ -H5EA_t * ea = NULL; /* Pointer to new extensible array */ -H5EA_hdr_t *hdr = NULL; /* The extensible array header information */ + /* Local variables */ + H5EA_t * ea = NULL; /* Pointer to new extensible array */ + H5EA_hdr_t *hdr = NULL; /* The extensible array header information */ -/* - * Check arguments. - */ -HDassert(f); -HDassert(H5F_addr_defined(ea_addr)); + /* + * Check arguments. + */ + HDassert(f); + HDassert(H5F_addr_defined(ea_addr)); -/* Allocate extensible array wrapper */ -if (NULL == (ea = H5FL_CALLOC(H5EA_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array info") + /* Allocate extensible array wrapper */ + if (NULL == (ea = H5FL_CALLOC(H5EA_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array info") -/* Lock the array header into memory */ -if (NULL == (hdr = H5EA__hdr_protect(f, ea_addr, ctx_udata, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load extensible array header") + /* Lock the array header into memory */ + if (NULL == (hdr = H5EA__hdr_protect(f, ea_addr, ctx_udata, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load extensible array header") -/* Check for pending array deletion */ -if (from_open && hdr->pending_delete) - H5E_THROW(H5E_CANTOPENOBJ, "can't open extensible array pending deletion") + /* Check for pending array deletion */ + if (from_open && hdr->pending_delete) + H5E_THROW(H5E_CANTOPENOBJ, "can't open extensible array pending deletion") -/* Point extensible array wrapper at header and bump it's ref count */ -ea->hdr = hdr; -if (H5EA__hdr_incr(ea->hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") + /* Point extensible array wrapper at header and bump it's ref count */ + ea->hdr = hdr; + if (H5EA__hdr_incr(ea->hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") -/* Increment # of files using this array header */ -if (H5EA__hdr_fuse_incr(ea->hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment file reference count on shared array header") + /* Increment # of files using this array header */ + if (H5EA__hdr_fuse_incr(ea->hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment file reference count on shared array header") -/* Set file pointer for this array open context */ -ea->f = f; + /* Set file pointer for this array open context */ + ea->f = f; -/* Set the return value */ -ret_value = ea; + /* Set the return value */ + ret_value = ea; -CATCH + CATCH -if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") -if (!ret_value) - if (ea && H5EA_close(ea) < 0) - H5E_THROW(H5E_CLOSEERROR, "unable to close extensible array") + if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") + if (!ret_value) + if (ea && H5EA_close(ea) < 0) + H5E_THROW(H5E_CLOSEERROR, "unable to close extensible array") END_FUNC(STATIC) /* end H5EA__new() */ @@ -182,35 +182,35 @@ END_FUNC(STATIC) /* end H5EA__new() */ BEGIN_FUNC(PRIV, ERR, H5EA_t *, NULL, NULL, H5EA_create(H5F_t *f, const H5EA_create_t *cparam, void *ctx_udata)) -/* Local variables */ -H5EA_t *ea = NULL; /* Pointer to new extensible array */ -haddr_t ea_addr; /* Array header address */ + /* Local variables */ + H5EA_t *ea = NULL; /* Pointer to new extensible array */ + haddr_t ea_addr; /* Array header address */ -/* - * Check arguments. - */ -HDassert(f); -HDassert(cparam); + /* + * Check arguments. + */ + HDassert(f); + HDassert(cparam); -/* H5EA interface sanity check */ -HDcompile_assert(H5EA_NUM_CLS_ID == NELMTS(H5EA_client_class_g)); + /* H5EA interface sanity check */ + HDcompile_assert(H5EA_NUM_CLS_ID == NELMTS(H5EA_client_class_g)); -/* Create extensible array header */ -if (HADDR_UNDEF == (ea_addr = H5EA__hdr_create(f, cparam, ctx_udata))) - H5E_THROW(H5E_CANTINIT, "can't create extensible array header") + /* Create extensible array header */ + if (HADDR_UNDEF == (ea_addr = H5EA__hdr_create(f, cparam, ctx_udata))) + H5E_THROW(H5E_CANTINIT, "can't create extensible array header") -/* Allocate and initialize new extensible array wrapper */ -if (NULL == (ea = H5EA__new(f, ea_addr, FALSE, ctx_udata))) - H5E_THROW(H5E_CANTINIT, "allocation and/or initialization failed for extensible array wrapper") + /* Allocate and initialize new extensible array wrapper */ + if (NULL == (ea = H5EA__new(f, ea_addr, FALSE, ctx_udata))) + H5E_THROW(H5E_CANTINIT, "allocation and/or initialization failed for extensible array wrapper") -/* Set the return value */ -ret_value = ea; + /* Set the return value */ + ret_value = ea; -CATCH + CATCH -if (!ret_value) - if (ea && H5EA_close(ea) < 0) - H5E_THROW(H5E_CLOSEERROR, "unable to close extensible array") + if (!ret_value) + if (ea && H5EA_close(ea) < 0) + H5E_THROW(H5E_CLOSEERROR, "unable to close extensible array") END_FUNC(PRIV) /* end H5EA_create() */ @@ -229,27 +229,27 @@ END_FUNC(PRIV) /* end H5EA_create() */ */ BEGIN_FUNC(PRIV, ERR, H5EA_t *, NULL, NULL, H5EA_open(H5F_t *f, haddr_t ea_addr, void *ctx_udata)) -/* Local variables */ -H5EA_t *ea = NULL; /* Pointer to new extensible array wrapper */ + /* Local variables */ + H5EA_t *ea = NULL; /* Pointer to new extensible array wrapper */ -/* - * Check arguments. - */ -HDassert(f); -HDassert(H5F_addr_defined(ea_addr)); + /* + * Check arguments. + */ + HDassert(f); + HDassert(H5F_addr_defined(ea_addr)); -/* Allocate and initialize new extensible array wrapper */ -if (NULL == (ea = H5EA__new(f, ea_addr, TRUE, ctx_udata))) - H5E_THROW(H5E_CANTINIT, "allocation and/or initialization failed for extensible array wrapper") + /* Allocate and initialize new extensible array wrapper */ + if (NULL == (ea = H5EA__new(f, ea_addr, TRUE, ctx_udata))) + H5E_THROW(H5E_CANTINIT, "allocation and/or initialization failed for extensible array wrapper") -/* Set the return value */ -ret_value = ea; + /* Set the return value */ + ret_value = ea; -CATCH + CATCH -if (!ret_value) - if (ea && H5EA_close(ea) < 0) - H5E_THROW(H5E_CLOSEERROR, "unable to close extensible array") + if (!ret_value) + if (ea && H5EA_close(ea) < 0) + H5E_THROW(H5E_CLOSEERROR, "unable to close extensible array") END_FUNC(PRIV) /* end H5EA_open() */ @@ -267,16 +267,16 @@ END_FUNC(PRIV) /* end H5EA_open() */ */ BEGIN_FUNC(PRIV, NOERR, herr_t, SUCCEED, -, H5EA_get_nelmts(const H5EA_t *ea, hsize_t *nelmts)) -/* Local variables */ + /* Local variables */ -/* - * Check arguments. - */ -HDassert(ea); -HDassert(nelmts); + /* + * Check arguments. + */ + HDassert(ea); + HDassert(nelmts); -/* Retrieve the max. index set */ -*nelmts = ea->hdr->stats.stored.max_idx_set; + /* Retrieve the max. index set */ + *nelmts = ea->hdr->stats.stored.max_idx_set; END_FUNC(PRIV) /* end H5EA_get_nelmts() */ @@ -294,17 +294,17 @@ END_FUNC(PRIV) /* end H5EA_get_nelmts() */ */ BEGIN_FUNC(PRIV, NOERR, herr_t, SUCCEED, -, H5EA_get_addr(const H5EA_t *ea, haddr_t *addr)) -/* Local variables */ + /* Local variables */ -/* - * Check arguments. - */ -HDassert(ea); -HDassert(ea->hdr); -HDassert(addr); + /* + * Check arguments. + */ + HDassert(ea); + HDassert(ea->hdr); + HDassert(addr); -/* Retrieve the address of the extensible array's header */ -*addr = ea->hdr->addr; + /* Retrieve the address of the extensible array's header */ + *addr = ea->hdr->addr; END_FUNC(PRIV) /* end H5EA_get_addr() */ @@ -326,263 +326,114 @@ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, void **thing, uint8_t **thing_elmt_buf, hsize_t *thing_elmt_idx, H5EA__unprotect_func_t *thing_unprot_func)) -/* Local variables */ -H5EA_hdr_t * hdr = ea->hdr; /* Header for EA */ -H5EA_iblock_t * iblock = NULL; /* Pointer to index block for EA */ -H5EA_sblock_t * sblock = NULL; /* Pointer to super block for EA */ -H5EA_dblock_t * dblock = NULL; /* Pointer to data block for EA */ -H5EA_dblk_page_t *dblk_page = NULL; /* Pointer to data block page for EA */ -unsigned iblock_cache_flags = H5AC__NO_FLAGS_SET; /* Flags to unprotecting index block */ -unsigned sblock_cache_flags = H5AC__NO_FLAGS_SET; /* Flags to unprotecting super block */ -hbool_t stats_changed = FALSE; /* Whether array statistics changed */ -hbool_t hdr_dirty = FALSE; /* Whether the array header changed */ - -/* - * Check arguments. - */ -HDassert(ea); -HDassert(hdr); -HDassert(thing); -HDassert(thing_elmt_buf); -HDassert(thing_unprot_func); - -/* only the H5AC__READ_ONLY_FLAG may be set in thing_acc */ -HDassert((thing_acc & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); - -/* Set the shared array header's file context for this operation */ -hdr->f = ea->f; - -/* Reset the pointers to the 'thing' info */ -*thing = NULL; -*thing_elmt_buf = NULL; -*thing_elmt_idx = 0; -*thing_unprot_func = (H5EA__unprotect_func_t)NULL; - -/* Check if we should create the index block */ -if (!H5F_addr_defined(hdr->idx_blk_addr)) { - /* Check if we are allowed to create the thing */ - if (0 == (thing_acc & H5AC__READ_ONLY_FLAG)) { /* i.e. r/w access */ - /* Create the index block */ - hdr->idx_blk_addr = H5EA__iblock_create(hdr, &stats_changed); - if (!H5F_addr_defined(hdr->idx_blk_addr)) - H5E_THROW(H5E_CANTCREATE, "unable to create index block") - hdr_dirty = TRUE; - } /* end if */ - else - H5_LEAVE(SUCCEED) -} /* end if */ - -/* Protect index block */ -if (NULL == (iblock = H5EA__iblock_protect(hdr, thing_acc))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array index block, address = %llu", - (unsigned long long)hdr->idx_blk_addr) - -/* Check if element is in index block */ -if (idx < hdr->cparam.idx_blk_elmts) { - /* Set 'thing' info to refer to the index block */ - *thing = iblock; - *thing_elmt_buf = (uint8_t *)iblock->elmts; - *thing_elmt_idx = idx; - *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__iblock_unprotect; -} /* end if */ -else { - unsigned sblk_idx; /* Which superblock does this index fall in? */ - size_t dblk_idx; /* Data block index */ - hsize_t elmt_idx; /* Offset of element in super block */ - - /* Get super block index where element is located */ - sblk_idx = H5EA__dblock_sblk_idx(hdr, idx); - - /* Adjust index to offset in super block */ - elmt_idx = idx - (hdr->cparam.idx_blk_elmts + hdr->sblk_info[sblk_idx].start_idx); - - /* Check for data block containing element address in the index block */ - if (sblk_idx < iblock->nsblks) { - /* Compute the data block index in index block */ - dblk_idx = - (size_t)(hdr->sblk_info[sblk_idx].start_dblk + (elmt_idx / hdr->sblk_info[sblk_idx].dblk_nelmts)); - HDassert(dblk_idx < iblock->ndblk_addrs); - - /* Check if the data block has been allocated on disk yet */ - if (!H5F_addr_defined(iblock->dblk_addrs[dblk_idx])) { - /* Check if we are allowed to create the thing */ - if (0 == (thing_acc & H5AC__READ_ONLY_FLAG)) { /* i.e. r/w access */ - haddr_t dblk_addr; /* Address of data block created */ - hsize_t dblk_off; /* Offset of data block in array */ - - /* Create data block */ - dblk_off = - hdr->sblk_info[sblk_idx].start_idx + (dblk_idx * hdr->sblk_info[sblk_idx].dblk_nelmts); - dblk_addr = H5EA__dblock_create(hdr, iblock, &stats_changed, dblk_off, - hdr->sblk_info[sblk_idx].dblk_nelmts); - if (!H5F_addr_defined(dblk_addr)) - H5E_THROW(H5E_CANTCREATE, "unable to create extensible array data block") - - /* Set data block address in index block */ - iblock->dblk_addrs[dblk_idx] = dblk_addr; - iblock_cache_flags |= H5AC__DIRTIED_FLAG; - } /* end if */ - else - H5_LEAVE(SUCCEED) - } /* end if */ - - /* Protect data block */ - if (NULL == (dblock = H5EA__dblock_protect(hdr, iblock, iblock->dblk_addrs[dblk_idx], - hdr->sblk_info[sblk_idx].dblk_nelmts, thing_acc))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block, address = %llu", - (unsigned long long)iblock->dblk_addrs[dblk_idx]) - - /* Adjust index to offset in data block */ - elmt_idx %= hdr->sblk_info[sblk_idx].dblk_nelmts; - - /* Check if there is already a dependency on the header */ - if (will_extend && !dblock->has_hdr_depend) { - if (H5EA__create_flush_depend((H5AC_info_t *)hdr, (H5AC_info_t *)dblock) < 0) - H5E_THROW(H5E_CANTDEPEND, - "unable to create flush dependency between data block and header, index = %llu", - (unsigned long long)idx) - dblock->has_hdr_depend = TRUE; - } /* end if */ - - /* Set 'thing' info to refer to the data block */ - *thing = dblock; - *thing_elmt_buf = (uint8_t *)dblock->elmts; - *thing_elmt_idx = elmt_idx; - *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__dblock_unprotect; - } /* end if */ - else { - size_t sblk_off; /* Offset of super block in index block array of super blocks */ - - /* Calculate offset of super block in index block's array */ - sblk_off = sblk_idx - iblock->nsblks; - - /* Check if the super block has been allocated on disk yet */ - if (!H5F_addr_defined(iblock->sblk_addrs[sblk_off])) { - /* Check if we are allowed to create the thing */ - if (0 == (thing_acc & H5AC__READ_ONLY_FLAG)) { /* i.e. r/w access */ - haddr_t sblk_addr; /* Address of data block created */ + /* Local variables */ + H5EA_hdr_t * hdr = ea->hdr; /* Header for EA */ + H5EA_iblock_t * iblock = NULL; /* Pointer to index block for EA */ + H5EA_sblock_t * sblock = NULL; /* Pointer to super block for EA */ + H5EA_dblock_t * dblock = NULL; /* Pointer to data block for EA */ + H5EA_dblk_page_t *dblk_page = NULL; /* Pointer to data block page for EA */ + unsigned iblock_cache_flags = H5AC__NO_FLAGS_SET; /* Flags to unprotecting index block */ + unsigned sblock_cache_flags = H5AC__NO_FLAGS_SET; /* Flags to unprotecting super block */ + hbool_t stats_changed = FALSE; /* Whether array statistics changed */ + hbool_t hdr_dirty = FALSE; /* Whether the array header changed */ + + /* + * Check arguments. + */ + HDassert(ea); + HDassert(hdr); + HDassert(thing); + HDassert(thing_elmt_buf); + HDassert(thing_unprot_func); + + /* only the H5AC__READ_ONLY_FLAG may be set in thing_acc */ + HDassert((thing_acc & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); - /* Create super block */ - sblk_addr = H5EA__sblock_create(hdr, iblock, &stats_changed, sblk_idx); - if (!H5F_addr_defined(sblk_addr)) - H5E_THROW(H5E_CANTCREATE, "unable to create extensible array super block") + /* Set the shared array header's file context for this operation */ + hdr->f = ea->f; - /* Set super block address in index block */ - iblock->sblk_addrs[sblk_off] = sblk_addr; - iblock_cache_flags |= H5AC__DIRTIED_FLAG; - } /* end if */ - else - H5_LEAVE(SUCCEED) - } /* end if */ + /* Reset the pointers to the 'thing' info */ + *thing = NULL; + *thing_elmt_buf = NULL; + *thing_elmt_idx = 0; + *thing_unprot_func = (H5EA__unprotect_func_t)NULL; - /* Protect super block */ - if (NULL == - (sblock = H5EA__sblock_protect(hdr, iblock, iblock->sblk_addrs[sblk_off], sblk_idx, thing_acc))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array super block, address = %llu", - (unsigned long long)iblock->sblk_addrs[sblk_off]) - - /* Compute the data block index in super block */ - dblk_idx = (size_t)(elmt_idx / sblock->dblk_nelmts); - HDassert(dblk_idx < sblock->ndblks); - - /* Check if the data block has been allocated on disk yet */ - if (!H5F_addr_defined(sblock->dblk_addrs[dblk_idx])) { - /* Check if we are allowed to create the thing */ - if (0 == (thing_acc & H5AC__READ_ONLY_FLAG)) { /* i.e. r/w access */ - haddr_t dblk_addr; /* Address of data block created */ - hsize_t dblk_off; /* Offset of data block in array */ - - /* Create data block */ - dblk_off = - hdr->sblk_info[sblk_idx].start_idx + (dblk_idx * hdr->sblk_info[sblk_idx].dblk_nelmts); - dblk_addr = H5EA__dblock_create(hdr, sblock, &stats_changed, dblk_off, sblock->dblk_nelmts); - if (!H5F_addr_defined(dblk_addr)) - H5E_THROW(H5E_CANTCREATE, "unable to create extensible array data block") - - /* Set data block address in index block */ - sblock->dblk_addrs[dblk_idx] = dblk_addr; - sblock_cache_flags |= H5AC__DIRTIED_FLAG; - - /* Create flush dependency on header, if extending the array and one doesn't already exist */ - if (will_extend && !sblock->has_hdr_depend) { - if (H5EA__create_flush_depend((H5AC_info_t *)sblock->hdr, (H5AC_info_t *)sblock) < 0) - H5E_THROW(H5E_CANTDEPEND, - "unable to create flush dependency between super block and header, address " - "= %llu", - (unsigned long long)sblock->addr) - sblock->has_hdr_depend = TRUE; - } /* end if */ - } /* end if */ - else - H5_LEAVE(SUCCEED) + /* Check if we should create the index block */ + if (!H5F_addr_defined(hdr->idx_blk_addr)) { + /* Check if we are allowed to create the thing */ + if (0 == (thing_acc & H5AC__READ_ONLY_FLAG)) { /* i.e. r/w access */ + /* Create the index block */ + hdr->idx_blk_addr = H5EA__iblock_create(hdr, &stats_changed); + if (!H5F_addr_defined(hdr->idx_blk_addr)) + H5E_THROW(H5E_CANTCREATE, "unable to create index block") + hdr_dirty = TRUE; } /* end if */ + else + H5_LEAVE(SUCCEED) + } /* end if */ - /* Adjust index to offset in data block */ - elmt_idx %= sblock->dblk_nelmts; - - /* Check if the data block is paged */ - if (sblock->dblk_npages) { - haddr_t dblk_page_addr; /* Address of data block page */ - size_t page_idx; /* Index of page within data block */ - size_t page_init_idx; /* Index of 'page init' bit */ - - /* Compute page index */ - page_idx = (size_t)elmt_idx / hdr->dblk_page_nelmts; + /* Protect index block */ + if (NULL == (iblock = H5EA__iblock_protect(hdr, thing_acc))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array index block, address = %llu", + (unsigned long long)hdr->idx_blk_addr) + + /* Check if element is in index block */ + if (idx < hdr->cparam.idx_blk_elmts) { + /* Set 'thing' info to refer to the index block */ + *thing = iblock; + *thing_elmt_buf = (uint8_t *)iblock->elmts; + *thing_elmt_idx = idx; + *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__iblock_unprotect; + } /* end if */ + else { + unsigned sblk_idx; /* Which superblock does this index fall in? */ + size_t dblk_idx; /* Data block index */ + hsize_t elmt_idx; /* Offset of element in super block */ - /* Compute 'page init' index */ - page_init_idx = (dblk_idx * sblock->dblk_npages) + page_idx; + /* Get super block index where element is located */ + sblk_idx = H5EA__dblock_sblk_idx(hdr, idx); - /* Adjust index to offset in data block page */ - elmt_idx %= hdr->dblk_page_nelmts; + /* Adjust index to offset in super block */ + elmt_idx = idx - (hdr->cparam.idx_blk_elmts + hdr->sblk_info[sblk_idx].start_idx); - /* Compute data block page address */ - dblk_page_addr = sblock->dblk_addrs[dblk_idx] + H5EA_DBLOCK_PREFIX_SIZE(sblock) + - (page_idx * sblock->dblk_page_size); + /* Check for data block containing element address in the index block */ + if (sblk_idx < iblock->nsblks) { + /* Compute the data block index in index block */ + dblk_idx = (size_t)(hdr->sblk_info[sblk_idx].start_dblk + + (elmt_idx / hdr->sblk_info[sblk_idx].dblk_nelmts)); + HDassert(dblk_idx < iblock->ndblk_addrs); - /* Check if page has been initialized yet */ - if (!H5VM_bit_get(sblock->page_init, page_init_idx)) { + /* Check if the data block has been allocated on disk yet */ + if (!H5F_addr_defined(iblock->dblk_addrs[dblk_idx])) { /* Check if we are allowed to create the thing */ if (0 == (thing_acc & H5AC__READ_ONLY_FLAG)) { /* i.e. r/w access */ - /* Create the data block page */ - if (H5EA__dblk_page_create(hdr, sblock, dblk_page_addr) < 0) - H5E_THROW(H5E_CANTCREATE, "unable to create data block page") - - /* Mark data block page as initialized in super block */ - H5VM_bit_set(sblock->page_init, page_init_idx, TRUE); - sblock_cache_flags |= H5AC__DIRTIED_FLAG; + haddr_t dblk_addr; /* Address of data block created */ + hsize_t dblk_off; /* Offset of data block in array */ + + /* Create data block */ + dblk_off = hdr->sblk_info[sblk_idx].start_idx + + (dblk_idx * hdr->sblk_info[sblk_idx].dblk_nelmts); + dblk_addr = H5EA__dblock_create(hdr, iblock, &stats_changed, dblk_off, + hdr->sblk_info[sblk_idx].dblk_nelmts); + if (!H5F_addr_defined(dblk_addr)) + H5E_THROW(H5E_CANTCREATE, "unable to create extensible array data block") + + /* Set data block address in index block */ + iblock->dblk_addrs[dblk_idx] = dblk_addr; + iblock_cache_flags |= H5AC__DIRTIED_FLAG; } /* end if */ else H5_LEAVE(SUCCEED) } /* end if */ - /* Protect data block page */ - if (NULL == (dblk_page = H5EA__dblk_page_protect(hdr, sblock, dblk_page_addr, thing_acc))) - H5E_THROW(H5E_CANTPROTECT, - "unable to protect extensible array data block page, address = %llu", - (unsigned long long)dblk_page_addr) - - /* Check if there is already a dependency on the header */ - if (will_extend && !dblk_page->has_hdr_depend) { - if (H5EA__create_flush_depend((H5AC_info_t *)hdr, (H5AC_info_t *)dblk_page) < 0) - H5E_THROW( - H5E_CANTDEPEND, - "unable to create flush dependency between data block page and header, index = %llu", - (unsigned long long)idx) - dblk_page->has_hdr_depend = TRUE; - } /* end if */ - - /* Set 'thing' info to refer to the data block page */ - *thing = dblk_page; - *thing_elmt_buf = (uint8_t *)dblk_page->elmts; - *thing_elmt_idx = elmt_idx; - *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__dblk_page_unprotect; - } /* end if */ - else { /* Protect data block */ - if (NULL == (dblock = H5EA__dblock_protect(hdr, sblock, sblock->dblk_addrs[dblk_idx], - sblock->dblk_nelmts, thing_acc))) + if (NULL == (dblock = H5EA__dblock_protect(hdr, iblock, iblock->dblk_addrs[dblk_idx], + hdr->sblk_info[sblk_idx].dblk_nelmts, thing_acc))) H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block, address = %llu", - (unsigned long long)sblock->dblk_addrs[dblk_idx]) + (unsigned long long)iblock->dblk_addrs[dblk_idx]) + + /* Adjust index to offset in data block */ + elmt_idx %= hdr->sblk_info[sblk_idx].dblk_nelmts; /* Check if there is already a dependency on the header */ if (will_extend && !dblock->has_hdr_depend) { @@ -598,42 +449,196 @@ else { *thing_elmt_buf = (uint8_t *)dblock->elmts; *thing_elmt_idx = elmt_idx; *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__dblock_unprotect; - } /* end else */ - } /* end else */ -} /* end else */ + } /* end if */ + else { + size_t sblk_off; /* Offset of super block in index block array of super blocks */ -/* Sanity checks */ -HDassert(*thing != NULL); -HDassert(*thing_unprot_func != NULL); + /* Calculate offset of super block in index block's array */ + sblk_off = sblk_idx - iblock->nsblks; -CATCH -/* Reset 'thing' info on error */ -if (ret_value < 0) { - *thing = NULL; - *thing_elmt_buf = NULL; - *thing_elmt_idx = 0; - *thing_unprot_func = (H5EA__unprotect_func_t)NULL; -} /* end if */ - -/* Check for updating array statistics */ -if (stats_changed) - hdr_dirty = TRUE; - -/* Check for header modified */ -if (hdr_dirty) - if (H5EA__hdr_modified(hdr) < 0) - H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark extensible array header as modified") - -/* Release resources */ -if (iblock && *thing != iblock && H5EA__iblock_unprotect(iblock, iblock_cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array index block") -/* (Note: super blocks don't contain elements, so don't have a '*thing != sblock' check) */ -if (sblock && H5EA__sblock_unprotect(sblock, sblock_cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array super block") -if (dblock && *thing != dblock && H5EA__dblock_unprotect(dblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array data block") -if (dblk_page && *thing != dblk_page && H5EA__dblk_page_unprotect(dblk_page, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array data block page") + /* Check if the super block has been allocated on disk yet */ + if (!H5F_addr_defined(iblock->sblk_addrs[sblk_off])) { + /* Check if we are allowed to create the thing */ + if (0 == (thing_acc & H5AC__READ_ONLY_FLAG)) { /* i.e. r/w access */ + haddr_t sblk_addr; /* Address of data block created */ + + /* Create super block */ + sblk_addr = H5EA__sblock_create(hdr, iblock, &stats_changed, sblk_idx); + if (!H5F_addr_defined(sblk_addr)) + H5E_THROW(H5E_CANTCREATE, "unable to create extensible array super block") + + /* Set super block address in index block */ + iblock->sblk_addrs[sblk_off] = sblk_addr; + iblock_cache_flags |= H5AC__DIRTIED_FLAG; + } /* end if */ + else + H5_LEAVE(SUCCEED) + } /* end if */ + + /* Protect super block */ + if (NULL == (sblock = H5EA__sblock_protect(hdr, iblock, iblock->sblk_addrs[sblk_off], sblk_idx, + thing_acc))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array super block, address = %llu", + (unsigned long long)iblock->sblk_addrs[sblk_off]) + + /* Compute the data block index in super block */ + dblk_idx = (size_t)(elmt_idx / sblock->dblk_nelmts); + HDassert(dblk_idx < sblock->ndblks); + + /* Check if the data block has been allocated on disk yet */ + if (!H5F_addr_defined(sblock->dblk_addrs[dblk_idx])) { + /* Check if we are allowed to create the thing */ + if (0 == (thing_acc & H5AC__READ_ONLY_FLAG)) { /* i.e. r/w access */ + haddr_t dblk_addr; /* Address of data block created */ + hsize_t dblk_off; /* Offset of data block in array */ + + /* Create data block */ + dblk_off = hdr->sblk_info[sblk_idx].start_idx + + (dblk_idx * hdr->sblk_info[sblk_idx].dblk_nelmts); + dblk_addr = + H5EA__dblock_create(hdr, sblock, &stats_changed, dblk_off, sblock->dblk_nelmts); + if (!H5F_addr_defined(dblk_addr)) + H5E_THROW(H5E_CANTCREATE, "unable to create extensible array data block") + + /* Set data block address in index block */ + sblock->dblk_addrs[dblk_idx] = dblk_addr; + sblock_cache_flags |= H5AC__DIRTIED_FLAG; + + /* Create flush dependency on header, if extending the array and one doesn't already exist + */ + if (will_extend && !sblock->has_hdr_depend) { + if (H5EA__create_flush_depend((H5AC_info_t *)sblock->hdr, (H5AC_info_t *)sblock) < 0) + H5E_THROW( + H5E_CANTDEPEND, + "unable to create flush dependency between super block and header, address " + "= %llu", + (unsigned long long)sblock->addr) + sblock->has_hdr_depend = TRUE; + } /* end if */ + } /* end if */ + else + H5_LEAVE(SUCCEED) + } /* end if */ + + /* Adjust index to offset in data block */ + elmt_idx %= sblock->dblk_nelmts; + + /* Check if the data block is paged */ + if (sblock->dblk_npages) { + haddr_t dblk_page_addr; /* Address of data block page */ + size_t page_idx; /* Index of page within data block */ + size_t page_init_idx; /* Index of 'page init' bit */ + + /* Compute page index */ + page_idx = (size_t)elmt_idx / hdr->dblk_page_nelmts; + + /* Compute 'page init' index */ + page_init_idx = (dblk_idx * sblock->dblk_npages) + page_idx; + + /* Adjust index to offset in data block page */ + elmt_idx %= hdr->dblk_page_nelmts; + + /* Compute data block page address */ + dblk_page_addr = sblock->dblk_addrs[dblk_idx] + H5EA_DBLOCK_PREFIX_SIZE(sblock) + + (page_idx * sblock->dblk_page_size); + + /* Check if page has been initialized yet */ + if (!H5VM_bit_get(sblock->page_init, page_init_idx)) { + /* Check if we are allowed to create the thing */ + if (0 == (thing_acc & H5AC__READ_ONLY_FLAG)) { /* i.e. r/w access */ + /* Create the data block page */ + if (H5EA__dblk_page_create(hdr, sblock, dblk_page_addr) < 0) + H5E_THROW(H5E_CANTCREATE, "unable to create data block page") + + /* Mark data block page as initialized in super block */ + H5VM_bit_set(sblock->page_init, page_init_idx, TRUE); + sblock_cache_flags |= H5AC__DIRTIED_FLAG; + } /* end if */ + else + H5_LEAVE(SUCCEED) + } /* end if */ + + /* Protect data block page */ + if (NULL == (dblk_page = H5EA__dblk_page_protect(hdr, sblock, dblk_page_addr, thing_acc))) + H5E_THROW(H5E_CANTPROTECT, + "unable to protect extensible array data block page, address = %llu", + (unsigned long long)dblk_page_addr) + + /* Check if there is already a dependency on the header */ + if (will_extend && !dblk_page->has_hdr_depend) { + if (H5EA__create_flush_depend((H5AC_info_t *)hdr, (H5AC_info_t *)dblk_page) < 0) + H5E_THROW(H5E_CANTDEPEND, + "unable to create flush dependency between data block page and header, " + "index = %llu", + (unsigned long long)idx) + dblk_page->has_hdr_depend = TRUE; + } /* end if */ + + /* Set 'thing' info to refer to the data block page */ + *thing = dblk_page; + *thing_elmt_buf = (uint8_t *)dblk_page->elmts; + *thing_elmt_idx = elmt_idx; + *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__dblk_page_unprotect; + } /* end if */ + else { + /* Protect data block */ + if (NULL == (dblock = H5EA__dblock_protect(hdr, sblock, sblock->dblk_addrs[dblk_idx], + sblock->dblk_nelmts, thing_acc))) + H5E_THROW(H5E_CANTPROTECT, + "unable to protect extensible array data block, address = %llu", + (unsigned long long)sblock->dblk_addrs[dblk_idx]) + + /* Check if there is already a dependency on the header */ + if (will_extend && !dblock->has_hdr_depend) { + if (H5EA__create_flush_depend((H5AC_info_t *)hdr, (H5AC_info_t *)dblock) < 0) + H5E_THROW( + H5E_CANTDEPEND, + "unable to create flush dependency between data block and header, index = %llu", + (unsigned long long)idx) + dblock->has_hdr_depend = TRUE; + } /* end if */ + + /* Set 'thing' info to refer to the data block */ + *thing = dblock; + *thing_elmt_buf = (uint8_t *)dblock->elmts; + *thing_elmt_idx = elmt_idx; + *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__dblock_unprotect; + } /* end else */ + } /* end else */ + } /* end else */ + + /* Sanity checks */ + HDassert(*thing != NULL); + HDassert(*thing_unprot_func != NULL); + + CATCH + /* Reset 'thing' info on error */ + if (ret_value < 0) { + *thing = NULL; + *thing_elmt_buf = NULL; + *thing_elmt_idx = 0; + *thing_unprot_func = (H5EA__unprotect_func_t)NULL; + } /* end if */ + + /* Check for updating array statistics */ + if (stats_changed) + hdr_dirty = TRUE; + + /* Check for header modified */ + if (hdr_dirty) + if (H5EA__hdr_modified(hdr) < 0) + H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark extensible array header as modified") + + /* Release resources */ + if (iblock && *thing != iblock && H5EA__iblock_unprotect(iblock, iblock_cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array index block") + /* (Note: super blocks don't contain elements, so don't have a '*thing != sblock' check) */ + if (sblock && H5EA__sblock_unprotect(sblock, sblock_cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array super block") + if (dblock && *thing != dblock && H5EA__dblock_unprotect(dblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array data block") + if (dblk_page && *thing != dblk_page && H5EA__dblk_page_unprotect(dblk_page, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array data block page") END_FUNC(STATIC) /* end H5EA__lookup_elmt() */ @@ -651,52 +656,52 @@ END_FUNC(STATIC) /* end H5EA__lookup_elmt() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5EA_set(const H5EA_t *ea, hsize_t idx, const void *elmt)) -/* Local variables */ -H5EA_hdr_t *hdr = ea->hdr; /* Header for EA */ -void * thing = NULL; /* Pointer to the array metadata containing the array index we are interested in */ -uint8_t * thing_elmt_buf; /* Pointer to the element buffer for the array metadata */ -hsize_t thing_elmt_idx; /* Index of the element in the element buffer for the array metadata */ -H5EA__unprotect_func_t thing_unprot_func; /* Function pointer for unprotecting the array metadata */ -hbool_t will_extend; /* Flag indicating if setting the element will extend the array */ -unsigned thing_cache_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotecting array metadata */ - -/* - * Check arguments. - */ -HDassert(ea); -HDassert(hdr); - -/* Set the shared array header's file context for this operation */ -hdr->f = ea->f; - -/* Look up the array metadata containing the element we want to set */ -will_extend = (idx >= hdr->stats.stored.max_idx_set); -if (H5EA__lookup_elmt(ea, idx, will_extend, H5AC__NO_FLAGS_SET, &thing, &thing_elmt_buf, &thing_elmt_idx, - &thing_unprot_func) < 0) - H5E_THROW(H5E_CANTPROTECT, "unable to protect array metadata") - -/* Sanity check */ -HDassert(thing); -HDassert(thing_elmt_buf); -HDassert(thing_unprot_func); - -/* Set element in thing's element buffer */ -H5MM_memcpy(thing_elmt_buf + (hdr->cparam.cls->nat_elmt_size * thing_elmt_idx), elmt, - hdr->cparam.cls->nat_elmt_size); -thing_cache_flags |= H5AC__DIRTIED_FLAG; - -/* Update max. element set in array, if appropriate */ -if (will_extend) { - /* Update the max index for the array */ - hdr->stats.stored.max_idx_set = idx + 1; - if (H5EA__hdr_modified(hdr) < 0) - H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark extensible array header as modified") -} /* end if */ - -CATCH -/* Release resources */ -if (thing && (thing_unprot_func)(thing, thing_cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array metadata") + /* Local variables */ + H5EA_hdr_t *hdr = ea->hdr; /* Header for EA */ + void * thing = NULL; /* Pointer to the array metadata containing the array index we are interested in */ + uint8_t *thing_elmt_buf; /* Pointer to the element buffer for the array metadata */ + hsize_t thing_elmt_idx; /* Index of the element in the element buffer for the array metadata */ + H5EA__unprotect_func_t thing_unprot_func; /* Function pointer for unprotecting the array metadata */ + hbool_t will_extend; /* Flag indicating if setting the element will extend the array */ + unsigned thing_cache_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotecting array metadata */ + + /* + * Check arguments. + */ + HDassert(ea); + HDassert(hdr); + + /* Set the shared array header's file context for this operation */ + hdr->f = ea->f; + + /* Look up the array metadata containing the element we want to set */ + will_extend = (idx >= hdr->stats.stored.max_idx_set); + if (H5EA__lookup_elmt(ea, idx, will_extend, H5AC__NO_FLAGS_SET, &thing, &thing_elmt_buf, &thing_elmt_idx, + &thing_unprot_func) < 0) + H5E_THROW(H5E_CANTPROTECT, "unable to protect array metadata") + + /* Sanity check */ + HDassert(thing); + HDassert(thing_elmt_buf); + HDassert(thing_unprot_func); + + /* Set element in thing's element buffer */ + H5MM_memcpy(thing_elmt_buf + (hdr->cparam.cls->nat_elmt_size * thing_elmt_idx), elmt, + hdr->cparam.cls->nat_elmt_size); + thing_cache_flags |= H5AC__DIRTIED_FLAG; + + /* Update max. element set in array, if appropriate */ + if (will_extend) { + /* Update the max index for the array */ + hdr->stats.stored.max_idx_set = idx + 1; + if (H5EA__hdr_modified(hdr) < 0) + H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark extensible array header as modified") + } /* end if */ + + CATCH + /* Release resources */ + if (thing && (thing_unprot_func)(thing, thing_cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array metadata") END_FUNC(PRIV) /* end H5EA_set() */ @@ -714,51 +719,51 @@ END_FUNC(PRIV) /* end H5EA_set() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5EA_get(const H5EA_t *ea, hsize_t idx, void *elmt)) -/* Local variables */ -H5EA_hdr_t *hdr = ea->hdr; /* Header for EA */ -void * thing = NULL; /* Pointer to the array metadata containing the array index we are interested in */ -H5EA__unprotect_func_t thing_unprot_func; /* Function pointer for unprotecting the array metadata */ - -/* - * Check arguments. - */ -HDassert(ea); -HDassert(hdr); - -/* Check for element beyond max. element in array */ -if (idx >= hdr->stats.stored.max_idx_set) { - /* Call the class's 'fill' callback */ - if ((hdr->cparam.cls->fill)(elmt, (size_t)1) < 0) - H5E_THROW(H5E_CANTSET, "can't set element to class's fill value") -} /* end if */ -else { - uint8_t *thing_elmt_buf; /* Pointer to the element buffer for the array metadata */ - hsize_t thing_elmt_idx; /* Index of the element in the element buffer for the array metadata */ - - /* Set the shared array header's file context for this operation */ - hdr->f = ea->f; + /* Local variables */ + H5EA_hdr_t *hdr = ea->hdr; /* Header for EA */ + void *thing = NULL; /* Pointer to the array metadata containing the array index we are interested in */ + H5EA__unprotect_func_t thing_unprot_func; /* Function pointer for unprotecting the array metadata */ - /* Look up the array metadata containing the element we want to set */ - if (H5EA__lookup_elmt(ea, idx, FALSE, H5AC__READ_ONLY_FLAG, &thing, &thing_elmt_buf, &thing_elmt_idx, - &thing_unprot_func) < 0) - H5E_THROW(H5E_CANTPROTECT, "unable to protect array metadata") + /* + * Check arguments. + */ + HDassert(ea); + HDassert(hdr); - /* Check if the thing holding the element has been created yet */ - if (NULL == thing) { + /* Check for element beyond max. element in array */ + if (idx >= hdr->stats.stored.max_idx_set) { /* Call the class's 'fill' callback */ if ((hdr->cparam.cls->fill)(elmt, (size_t)1) < 0) H5E_THROW(H5E_CANTSET, "can't set element to class's fill value") } /* end if */ - else - /* Get element from thing's element buffer */ - H5MM_memcpy(elmt, thing_elmt_buf + (hdr->cparam.cls->nat_elmt_size * thing_elmt_idx), - hdr->cparam.cls->nat_elmt_size); -} /* end else */ + else { + uint8_t *thing_elmt_buf; /* Pointer to the element buffer for the array metadata */ + hsize_t thing_elmt_idx; /* Index of the element in the element buffer for the array metadata */ + + /* Set the shared array header's file context for this operation */ + hdr->f = ea->f; + + /* Look up the array metadata containing the element we want to set */ + if (H5EA__lookup_elmt(ea, idx, FALSE, H5AC__READ_ONLY_FLAG, &thing, &thing_elmt_buf, &thing_elmt_idx, + &thing_unprot_func) < 0) + H5E_THROW(H5E_CANTPROTECT, "unable to protect array metadata") + + /* Check if the thing holding the element has been created yet */ + if (NULL == thing) { + /* Call the class's 'fill' callback */ + if ((hdr->cparam.cls->fill)(elmt, (size_t)1) < 0) + H5E_THROW(H5E_CANTSET, "can't set element to class's fill value") + } /* end if */ + else + /* Get element from thing's element buffer */ + H5MM_memcpy(elmt, thing_elmt_buf + (hdr->cparam.cls->nat_elmt_size * thing_elmt_idx), + hdr->cparam.cls->nat_elmt_size); + } /* end else */ -CATCH -/* Release thing */ -if (thing && (thing_unprot_func)(thing, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array metadata") + CATCH + /* Release thing */ + if (thing && (thing_unprot_func)(thing, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array metadata") END_FUNC(PRIV) /* end H5EA_get() */ @@ -777,35 +782,35 @@ END_FUNC(PRIV) /* end H5EA_get() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5EA_depend(H5EA_t *ea, H5AC_proxy_entry_t *parent)) -/* Local variables */ -H5EA_hdr_t *hdr = ea->hdr; /* Header for EA */ + /* Local variables */ + H5EA_hdr_t *hdr = ea->hdr; /* Header for EA */ + + /* + * Check arguments. + */ + HDassert(ea); + HDassert(hdr); + HDassert(parent); + + /* + * Check to see if a flush dependency between the extensible array + * and another data structure in the file has already been set up. + * If it hasn't, do so now. + */ + if (NULL == hdr->parent) { + /* Sanity check */ + HDassert(hdr->top_proxy); -/* - * Check arguments. - */ -HDassert(ea); -HDassert(hdr); -HDassert(parent); - -/* - * Check to see if a flush dependency between the extensible array - * and another data structure in the file has already been set up. - * If it hasn't, do so now. - */ -if (NULL == hdr->parent) { - /* Sanity check */ - HDassert(hdr->top_proxy); - - /* Set the shared array header's file context for this operation */ - hdr->f = ea->f; + /* Set the shared array header's file context for this operation */ + hdr->f = ea->f; - /* Add the extensible array as a child of the parent (proxy) */ - if (H5AC_proxy_entry_add_child(parent, hdr->f, hdr->top_proxy) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array as child of proxy") - hdr->parent = parent; -} /* end if */ + /* Add the extensible array as a child of the parent (proxy) */ + if (H5AC_proxy_entry_add_child(parent, hdr->f, hdr->top_proxy) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array as child of proxy") + hdr->parent = parent; + } /* end if */ -CATCH + CATCH END_FUNC(PRIV) /* end H5EA_depend() */ @@ -823,87 +828,88 @@ END_FUNC(PRIV) /* end H5EA_depend() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5EA_close(H5EA_t *ea)) -/* Local variables */ -hbool_t pending_delete = FALSE; /* Whether the array is pending deletion */ -haddr_t ea_addr = HADDR_UNDEF; /* Address of array (for deletion) */ - -/* - * Check arguments. - */ -HDassert(ea); - -/* Close the header, if it was set */ -if (ea->hdr) { - /* Decrement file reference & check if this is the last open extensible array using the shared array - * header */ - if (0 == H5EA__hdr_fuse_decr(ea->hdr)) { - /* Set the shared array header's file context for this operation */ - ea->hdr->f = ea->f; - - /* Shut down anything that can't be put in the header's 'flush' callback */ + /* Local variables */ + hbool_t pending_delete = FALSE; /* Whether the array is pending deletion */ + haddr_t ea_addr = HADDR_UNDEF; /* Address of array (for deletion) */ + + /* + * Check arguments. + */ + HDassert(ea); + + /* Close the header, if it was set */ + if (ea->hdr) { + /* Decrement file reference & check if this is the last open extensible array using the shared array + * header */ + if (0 == H5EA__hdr_fuse_decr(ea->hdr)) { + /* Set the shared array header's file context for this operation */ + ea->hdr->f = ea->f; + + /* Shut down anything that can't be put in the header's 'flush' callback */ + + /* Check for pending array deletion */ + if (ea->hdr->pending_delete) { + /* Set local info, so array deletion can occur after decrementing the + * header's ref count + */ + pending_delete = TRUE; + ea_addr = ea->hdr->addr; + } /* end if */ + } /* end if */ /* Check for pending array deletion */ - if (ea->hdr->pending_delete) { - /* Set local info, so array deletion can occur after decrementing the - * header's ref count - */ - pending_delete = TRUE; - ea_addr = ea->hdr->addr; - } /* end if */ - } /* end if */ - - /* Check for pending array deletion */ - if (pending_delete) { - H5EA_hdr_t *hdr; /* Another pointer to extensible array header */ + if (pending_delete) { + H5EA_hdr_t *hdr; /* Another pointer to extensible array header */ #ifndef NDEBUG - { - unsigned hdr_status = 0; /* Header's status in the metadata cache */ - - /* Check the header's status in the metadata cache */ - if (H5AC_get_entry_status(ea->f, ea_addr, &hdr_status) < 0) - H5E_THROW(H5E_CANTGET, "unable to check metadata cache status for extensible array header") - - /* Sanity checks on header */ - HDassert(hdr_status & H5AC_ES__IN_CACHE); - HDassert(hdr_status & H5AC_ES__IS_PINNED); - HDassert(!(hdr_status & H5AC_ES__IS_PROTECTED)); - } + { + unsigned hdr_status = 0; /* Header's status in the metadata cache */ + + /* Check the header's status in the metadata cache */ + if (H5AC_get_entry_status(ea->f, ea_addr, &hdr_status) < 0) + H5E_THROW(H5E_CANTGET, + "unable to check metadata cache status for extensible array header") + + /* Sanity checks on header */ + HDassert(hdr_status & H5AC_ES__IN_CACHE); + HDassert(hdr_status & H5AC_ES__IS_PINNED); + HDassert(!(hdr_status & H5AC_ES__IS_PROTECTED)); + } #endif /* NDEBUG */ - /* Lock the array header into memory */ - /* (OK to pass in NULL for callback context, since we know the header must be in the cache) */ - if (NULL == (hdr = H5EA__hdr_protect(ea->f, ea_addr, NULL, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTLOAD, "unable to load extensible array header") + /* Lock the array header into memory */ + /* (OK to pass in NULL for callback context, since we know the header must be in the cache) */ + if (NULL == (hdr = H5EA__hdr_protect(ea->f, ea_addr, NULL, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTLOAD, "unable to load extensible array header") - /* Set the shared array header's file context for this operation */ - hdr->f = ea->f; + /* Set the shared array header's file context for this operation */ + hdr->f = ea->f; - /* Decrement the reference count on the array header */ - /* (don't put in H5EA_hdr_fuse_decr() as the array header may be evicted - * immediately -QAK) - */ - if (H5EA__hdr_decr(ea->hdr) < 0) - H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + /* Decrement the reference count on the array header */ + /* (don't put in H5EA_hdr_fuse_decr() as the array header may be evicted + * immediately -QAK) + */ + if (H5EA__hdr_decr(ea->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") - /* Delete array, starting with header (unprotects header) */ - if (H5EA__hdr_delete(hdr) < 0) - H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array") - } /* end if */ - else { - /* Decrement the reference count on the array header */ - /* (don't put in H5EA_hdr_fuse_decr() as the array header may be evicted - * immediately -QAK) - */ - if (H5EA__hdr_decr(ea->hdr) < 0) - H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") - } /* end else */ -} /* end if */ + /* Delete array, starting with header (unprotects header) */ + if (H5EA__hdr_delete(hdr) < 0) + H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array") + } /* end if */ + else { + /* Decrement the reference count on the array header */ + /* (don't put in H5EA_hdr_fuse_decr() as the array header may be evicted + * immediately -QAK) + */ + if (H5EA__hdr_decr(ea->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + } /* end else */ + } /* end if */ -/* Release the extensible array wrapper */ -ea = (H5EA_t *)H5FL_FREE(H5EA_t, ea); + /* Release the extensible array wrapper */ + ea = (H5EA_t *)H5FL_FREE(H5EA_t, ea); -CATCH + CATCH END_FUNC(PRIV) /* end H5EA_close() */ @@ -921,38 +927,38 @@ END_FUNC(PRIV) /* end H5EA_close() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5EA_delete(H5F_t *f, haddr_t ea_addr, void *ctx_udata)) -/* Local variables */ -H5EA_hdr_t *hdr = NULL; /* The fractal heap header information */ + /* Local variables */ + H5EA_hdr_t *hdr = NULL; /* The fractal heap header information */ -/* - * Check arguments. - */ -HDassert(f); -HDassert(H5F_addr_defined(ea_addr)); - -/* Lock the array header into memory */ -if (NULL == (hdr = H5EA__hdr_protect(f, ea_addr, ctx_udata, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array header, address = %llu", - (unsigned long long)ea_addr) - -/* Check for files using shared array header */ -if (hdr->file_rc) - hdr->pending_delete = TRUE; -else { - /* Set the shared array header's file context for this operation */ - hdr->f = f; + /* + * Check arguments. + */ + HDassert(f); + HDassert(H5F_addr_defined(ea_addr)); - /* Delete array now, starting with header (unprotects header) */ - if (H5EA__hdr_delete(hdr) < 0) - H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array") - hdr = NULL; -} /* end if */ + /* Lock the array header into memory */ + if (NULL == (hdr = H5EA__hdr_protect(f, ea_addr, ctx_udata, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array header, address = %llu", + (unsigned long long)ea_addr) -CATCH + /* Check for files using shared array header */ + if (hdr->file_rc) + hdr->pending_delete = TRUE; + else { + /* Set the shared array header's file context for this operation */ + hdr->f = f; + + /* Delete array now, starting with header (unprotects header) */ + if (H5EA__hdr_delete(hdr) < 0) + H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array") + hdr = NULL; + } /* end if */ + + CATCH -/* Unprotect the header, if an error occurred */ -if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") + /* Unprotect the header, if an error occurred */ + if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") END_FUNC(PRIV) /* end H5EA_delete() */ @@ -971,37 +977,37 @@ END_FUNC(PRIV) /* end H5EA_delete() */ BEGIN_FUNC(PRIV, ERR, int, H5_ITER_CONT, H5_ITER_ERROR, H5EA_iterate(H5EA_t *ea, H5EA_operator_t op, void *udata)) -/* Local variables */ -uint8_t *elmt = NULL; -hsize_t u; -int cb_ret = H5_ITER_CONT; /* Return value from callback */ - -/* Check arguments */ -HDassert(ea); -HDassert(op); -HDassert(udata); - -/* Allocate space for a native array element */ -if (NULL == (elmt = H5FL_BLK_MALLOC(ea_native_elmt, ea->hdr->cparam.cls->nat_elmt_size))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array element") - -/* Iterate over all elements in array */ -for (u = 0; u < ea->hdr->stats.stored.max_idx_set && cb_ret == H5_ITER_CONT; u++) { - /* Get array element */ - if (H5EA_get(ea, u, elmt) < 0) - H5E_THROW(H5E_CANTGET, "unable to delete fixed array") - - /* Make callback */ - if ((cb_ret = (*op)(u, elmt, udata)) < 0) { - H5E_PRINTF(H5E_BADITER, "iterator function failed"); - H5_LEAVE(cb_ret) - } /* end if */ -} /* end for */ + /* Local variables */ + uint8_t *elmt = NULL; + hsize_t u; + int cb_ret = H5_ITER_CONT; /* Return value from callback */ + + /* Check arguments */ + HDassert(ea); + HDassert(op); + HDassert(udata); + + /* Allocate space for a native array element */ + if (NULL == (elmt = H5FL_BLK_MALLOC(ea_native_elmt, ea->hdr->cparam.cls->nat_elmt_size))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array element") + + /* Iterate over all elements in array */ + for (u = 0; u < ea->hdr->stats.stored.max_idx_set && cb_ret == H5_ITER_CONT; u++) { + /* Get array element */ + if (H5EA_get(ea, u, elmt) < 0) + H5E_THROW(H5E_CANTGET, "unable to delete fixed array") + + /* Make callback */ + if ((cb_ret = (*op)(u, elmt, udata)) < 0) { + H5E_PRINTF(H5E_BADITER, "iterator function failed"); + H5_LEAVE(cb_ret) + } /* end if */ + } /* end for */ -CATCH + CATCH -if (elmt) - elmt = H5FL_BLK_FREE(ea_native_elmt, elmt); + if (elmt) + elmt = H5FL_BLK_FREE(ea_native_elmt, elmt); END_FUNC(PRIV) /* end H5EA_iterate() */ @@ -1019,15 +1025,15 @@ END_FUNC(PRIV) /* end H5EA_iterate() */ */ BEGIN_FUNC(PRIV, NOERR, herr_t, SUCCEED, -, H5EA_patch_file(H5EA_t *ea, H5F_t *f)) -/* Local variables */ + /* Local variables */ -/* - * Check arguments. - */ -HDassert(ea); -HDassert(f); + /* + * Check arguments. + */ + HDassert(ea); + HDassert(f); -if (ea->f != f || ea->hdr->f != f) - ea->f = ea->hdr->f = f; + if (ea->f != f || ea->hdr->f != f) + ea->f = ea->hdr->f = f; END_FUNC(PRIV) /* end H5EA_patch_file() */ diff --git a/src/H5EAcache.c b/src/H5EAcache.c index d621483..6316ded 100644 --- a/src/H5EAcache.c +++ b/src/H5EAcache.c @@ -224,16 +224,16 @@ const H5AC_class_t H5AC_EARRAY_DBLK_PAGE[1] = {{ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_hdr_get_initial_load_size(void *_udata, size_t *image_len)) -/* Local variables */ -H5EA_hdr_cache_ud_t *udata = (H5EA_hdr_cache_ud_t *)_udata; /* User data for callback */ + /* Local variables */ + H5EA_hdr_cache_ud_t *udata = (H5EA_hdr_cache_ud_t *)_udata; /* User data for callback */ -/* Check arguments */ -HDassert(udata); -HDassert(udata->f); -HDassert(image_len); + /* Check arguments */ + HDassert(udata); + HDassert(udata->f); + HDassert(image_len); -/* Set the image length size */ -*image_len = (size_t)H5EA_HEADER_SIZE_FILE(udata->f); + /* Set the image length size */ + *image_len = (size_t)H5EA_HEADER_SIZE_FILE(udata->f); END_FUNC(STATIC) /* end H5EA__cache_hdr_get_initial_load_size() */ @@ -253,19 +253,19 @@ END_FUNC(STATIC) /* end H5EA__cache_hdr_get_initial_load_size() */ BEGIN_FUNC(STATIC, NOERR, htri_t, TRUE, -, H5EA__cache_hdr_verify_chksum(const void *_image, size_t len, void H5_ATTR_UNUSED *_udata)) -/* Local variables */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -uint32_t computed_chksum; /* Computed metadata checksum value */ + /* Local variables */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ -/* Check arguments */ -HDassert(image); + /* Check arguments */ + HDassert(image); -/* Get stored and computed checksums */ -H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); + /* Get stored and computed checksums */ + H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); -if (stored_chksum != computed_chksum) - ret_value = FALSE; + if (stored_chksum != computed_chksum) + ret_value = FALSE; END_FUNC(STATIC) /* end H5EA__cache_hdr_verify_chksum() */ @@ -286,111 +286,111 @@ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5EA__cache_hdr_deserialize(const void *_image, size_t len, void *_udata, hbool_t H5_ATTR_UNUSED *dirty)) -/* Local variables */ -H5EA_cls_id_t id; /* ID of extensible array class, as found in file */ -H5EA_hdr_t * hdr = NULL; /* Extensible array info */ -H5EA_hdr_cache_ud_t *udata = (H5EA_hdr_cache_ud_t *)_udata; -const uint8_t * image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ - -/* Check arguments */ -HDassert(image); -HDassert(udata); -HDassert(udata->f); -HDassert(H5F_addr_defined(udata->addr)); - -/* Allocate space for the extensible array data structure */ -if (NULL == (hdr = H5EA__hdr_alloc(udata->f))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array shared header") - -/* Set the extensible array header's address */ -hdr->addr = udata->addr; - -/* Magic number */ -if (HDmemcmp(image, H5EA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) - H5E_THROW(H5E_BADVALUE, "wrong extensible array header signature") -image += H5_SIZEOF_MAGIC; - -/* Version */ -if (*image++ != H5EA_HDR_VERSION) - H5E_THROW(H5E_VERSION, "wrong extensible array header version") - -/* Extensible array class */ -id = (H5EA_cls_id_t)*image++; -if (id >= H5EA_NUM_CLS_ID) - H5E_THROW(H5E_BADTYPE, "incorrect extensible array class") -hdr->cparam.cls = H5EA_client_class_g[id]; - -/* General array creation/configuration information */ -hdr->cparam.raw_elmt_size = *image++; /* Element size in file (in bytes) */ -hdr->cparam.max_nelmts_bits = - *image++; /* Log2(Max. # of elements in array) - i.e. # of bits needed to store max. # of elements */ -hdr->cparam.idx_blk_elmts = *image++; /* # of elements to store in index block */ -hdr->cparam.data_blk_min_elmts = *image++; /* Min. # of elements per data block */ -hdr->cparam.sup_blk_min_data_ptrs = *image++; /* Min. # of data block pointers for a super block */ -hdr->cparam.max_dblk_page_nelmts_bits = - *image++; /* Log2(Max. # of elements in data block page) - i.e. # of bits needed to store max. # of - elements in data block page */ - -/* Array statistics */ -hdr->stats.computed.hdr_size = len; /* Size of header in file */ -H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.nsuper_blks); /* Number of super blocks created */ -H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.super_blk_size); /* Size of super blocks created */ -H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.ndata_blks); /* Number of data blocks created */ -H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.data_blk_size); /* Size of data blocks created */ -H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.max_idx_set); /* Max. index set (+1) */ -H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.nelmts); /* Number of elements 'realized' */ - -/* Internal information */ -H5F_addr_decode(udata->f, &image, &hdr->idx_blk_addr); /* Address of index block */ - -/* Index block statistics */ -if (H5F_addr_defined(hdr->idx_blk_addr)) { - H5EA_iblock_t iblock; /* Fake index block for computing size */ - - /* Set index block count for file */ - hdr->stats.computed.nindex_blks = 1; - - /* Set up fake index block for computing size on disk */ - iblock.hdr = hdr; - iblock.nsblks = H5EA_SBLK_FIRST_IDX(hdr->cparam.sup_blk_min_data_ptrs); - iblock.ndblk_addrs = 2 * ((size_t)hdr->cparam.sup_blk_min_data_ptrs - 1); - iblock.nsblk_addrs = hdr->nsblks - iblock.nsblks; - - /* Compute size of index block in file */ - hdr->stats.computed.index_blk_size = H5EA_IBLOCK_SIZE(&iblock); -} /* end if */ -else { - hdr->stats.computed.nindex_blks = 0; /* Number of index blocks in file */ - hdr->stats.computed.index_blk_size = 0; /* Size of index blocks in file */ -} /* end else */ - -/* Sanity check */ -/* (allow for checksum not decoded yet) */ -HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5EA_SIZEOF_CHKSUM)); - -/* checksum verification already done in verify_chksum cb */ - -/* Metadata checksum */ -UINT32DECODE(image, stored_chksum); - -/* Sanity check */ -HDassert((size_t)(image - (const uint8_t *)_image) == len); - -/* Finish initializing extensible array header */ -if (H5EA__hdr_init(hdr, udata->ctx_udata) < 0) - H5E_THROW(H5E_CANTINIT, "initialization failed for extensible array header") -HDassert(hdr->size == len); - -/* Set return value */ -ret_value = hdr; - -CATCH - -/* Release resources */ -if (!ret_value) - if (hdr && H5EA__hdr_dest(hdr) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array header") + /* Local variables */ + H5EA_cls_id_t id; /* ID of extensible array class, as found in file */ + H5EA_hdr_t * hdr = NULL; /* Extensible array info */ + H5EA_hdr_cache_ud_t *udata = (H5EA_hdr_cache_ud_t *)_udata; + const uint8_t * image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + + /* Check arguments */ + HDassert(image); + HDassert(udata); + HDassert(udata->f); + HDassert(H5F_addr_defined(udata->addr)); + + /* Allocate space for the extensible array data structure */ + if (NULL == (hdr = H5EA__hdr_alloc(udata->f))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array shared header") + + /* Set the extensible array header's address */ + hdr->addr = udata->addr; + + /* Magic number */ + if (HDmemcmp(image, H5EA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) + H5E_THROW(H5E_BADVALUE, "wrong extensible array header signature") + image += H5_SIZEOF_MAGIC; + + /* Version */ + if (*image++ != H5EA_HDR_VERSION) + H5E_THROW(H5E_VERSION, "wrong extensible array header version") + + /* Extensible array class */ + id = (H5EA_cls_id_t)*image++; + if (id >= H5EA_NUM_CLS_ID) + H5E_THROW(H5E_BADTYPE, "incorrect extensible array class") + hdr->cparam.cls = H5EA_client_class_g[id]; + + /* General array creation/configuration information */ + hdr->cparam.raw_elmt_size = *image++; /* Element size in file (in bytes) */ + hdr->cparam.max_nelmts_bits = + *image++; /* Log2(Max. # of elements in array) - i.e. # of bits needed to store max. # of elements */ + hdr->cparam.idx_blk_elmts = *image++; /* # of elements to store in index block */ + hdr->cparam.data_blk_min_elmts = *image++; /* Min. # of elements per data block */ + hdr->cparam.sup_blk_min_data_ptrs = *image++; /* Min. # of data block pointers for a super block */ + hdr->cparam.max_dblk_page_nelmts_bits = + *image++; /* Log2(Max. # of elements in data block page) - i.e. # of bits needed to store max. # of + elements in data block page */ + + /* Array statistics */ + hdr->stats.computed.hdr_size = len; /* Size of header in file */ + H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.nsuper_blks); /* Number of super blocks created */ + H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.super_blk_size); /* Size of super blocks created */ + H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.ndata_blks); /* Number of data blocks created */ + H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.data_blk_size); /* Size of data blocks created */ + H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.max_idx_set); /* Max. index set (+1) */ + H5F_DECODE_LENGTH(udata->f, image, hdr->stats.stored.nelmts); /* Number of elements 'realized' */ + + /* Internal information */ + H5F_addr_decode(udata->f, &image, &hdr->idx_blk_addr); /* Address of index block */ + + /* Index block statistics */ + if (H5F_addr_defined(hdr->idx_blk_addr)) { + H5EA_iblock_t iblock; /* Fake index block for computing size */ + + /* Set index block count for file */ + hdr->stats.computed.nindex_blks = 1; + + /* Set up fake index block for computing size on disk */ + iblock.hdr = hdr; + iblock.nsblks = H5EA_SBLK_FIRST_IDX(hdr->cparam.sup_blk_min_data_ptrs); + iblock.ndblk_addrs = 2 * ((size_t)hdr->cparam.sup_blk_min_data_ptrs - 1); + iblock.nsblk_addrs = hdr->nsblks - iblock.nsblks; + + /* Compute size of index block in file */ + hdr->stats.computed.index_blk_size = H5EA_IBLOCK_SIZE(&iblock); + } /* end if */ + else { + hdr->stats.computed.nindex_blks = 0; /* Number of index blocks in file */ + hdr->stats.computed.index_blk_size = 0; /* Size of index blocks in file */ + } /* end else */ + + /* Sanity check */ + /* (allow for checksum not decoded yet) */ + HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5EA_SIZEOF_CHKSUM)); + + /* checksum verification already done in verify_chksum cb */ + + /* Metadata checksum */ + UINT32DECODE(image, stored_chksum); + + /* Sanity check */ + HDassert((size_t)(image - (const uint8_t *)_image) == len); + + /* Finish initializing extensible array header */ + if (H5EA__hdr_init(hdr, udata->ctx_udata) < 0) + H5E_THROW(H5E_CANTINIT, "initialization failed for extensible array header") + HDassert(hdr->size == len); + + /* Set return value */ + ret_value = hdr; + + CATCH + + /* Release resources */ + if (!ret_value) + if (hdr && H5EA__hdr_dest(hdr) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array header") END_FUNC(STATIC) /* end H5EA__cache_hdr_deserialize() */ @@ -409,15 +409,15 @@ END_FUNC(STATIC) /* end H5EA__cache_hdr_deserialize() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_hdr_image_len(const void *_thing, size_t *image_len)) -/* Local variables */ -const H5EA_hdr_t *hdr = (const H5EA_hdr_t *)_thing; /* Pointer to the object */ + /* Local variables */ + const H5EA_hdr_t *hdr = (const H5EA_hdr_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(hdr); -HDassert(image_len); + /* Check arguments */ + HDassert(hdr); + HDassert(image_len); -/* Set the image length size */ -*image_len = hdr->size; + /* Set the image length size */ + *image_len = hdr->size; END_FUNC(STATIC) /* end H5EA__cache_hdr_image_len() */ @@ -436,57 +436,57 @@ END_FUNC(STATIC) /* end H5EA__cache_hdr_image_len() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_hdr_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, void *_thing)) -/* Local variables */ -H5EA_hdr_t *hdr = (H5EA_hdr_t *)_thing; /* Pointer to the extensible array header */ -uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t metadata_chksum; /* Computed metadata checksum value */ - -/* check arguments */ -HDassert(f); -HDassert(image); -HDassert(hdr); - -/* Magic number */ -H5MM_memcpy(image, H5EA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); -image += H5_SIZEOF_MAGIC; - -/* Version # */ -*image++ = H5EA_HDR_VERSION; - -/* Extensible array type */ -HDassert(hdr->cparam.cls->id <= 255); -*image++ = (uint8_t)hdr->cparam.cls->id; - -/* General array creation/configuration information */ -*image++ = hdr->cparam.raw_elmt_size; /* Element size in file (in bytes) */ -*image++ = hdr->cparam.max_nelmts_bits; /* Log2(Max. # of elements in array) - i.e. # of bits needed to store - max. # of elements */ -*image++ = hdr->cparam.idx_blk_elmts; /* # of elements to store in index block */ -*image++ = hdr->cparam.data_blk_min_elmts; /* Min. # of elements per data block */ -*image++ = hdr->cparam.sup_blk_min_data_ptrs; /* Min. # of data block pointers for a super block */ -*image++ = - hdr->cparam.max_dblk_page_nelmts_bits; /* Log2(Max. # of elements in data block page) - i.e. # of bits - needed to store max. # of elements in data block page */ - -/* Array statistics */ -H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.nsuper_blks); /* Number of super blocks created */ -H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.super_blk_size); /* Size of super blocks created */ -H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.ndata_blks); /* Number of data blocks created */ -H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.data_blk_size); /* Size of data blocks created */ -H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.max_idx_set); /* Max. index set (+1) */ -H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.nelmts); /* Number of elements 'realized' */ - -/* Internal information */ -H5F_addr_encode(f, &image, hdr->idx_blk_addr); /* Address of index block */ - -/* Compute metadata checksum */ -metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); - -/* Metadata checksum */ -UINT32ENCODE(image, metadata_chksum); - -/* Sanity check */ -HDassert((size_t)(image - (uint8_t *)_image) == len); + /* Local variables */ + H5EA_hdr_t *hdr = (H5EA_hdr_t *)_thing; /* Pointer to the extensible array header */ + uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t metadata_chksum; /* Computed metadata checksum value */ + + /* check arguments */ + HDassert(f); + HDassert(image); + HDassert(hdr); + + /* Magic number */ + H5MM_memcpy(image, H5EA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); + image += H5_SIZEOF_MAGIC; + + /* Version # */ + *image++ = H5EA_HDR_VERSION; + + /* Extensible array type */ + HDassert(hdr->cparam.cls->id <= 255); + *image++ = (uint8_t)hdr->cparam.cls->id; + + /* General array creation/configuration information */ + *image++ = hdr->cparam.raw_elmt_size; /* Element size in file (in bytes) */ + *image++ = hdr->cparam.max_nelmts_bits; /* Log2(Max. # of elements in array) - i.e. # of bits needed to + store max. # of elements */ + *image++ = hdr->cparam.idx_blk_elmts; /* # of elements to store in index block */ + *image++ = hdr->cparam.data_blk_min_elmts; /* Min. # of elements per data block */ + *image++ = hdr->cparam.sup_blk_min_data_ptrs; /* Min. # of data block pointers for a super block */ + *image++ = + hdr->cparam.max_dblk_page_nelmts_bits; /* Log2(Max. # of elements in data block page) - i.e. # of bits + needed to store max. # of elements in data block page */ + + /* Array statistics */ + H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.nsuper_blks); /* Number of super blocks created */ + H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.super_blk_size); /* Size of super blocks created */ + H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.ndata_blks); /* Number of data blocks created */ + H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.data_blk_size); /* Size of data blocks created */ + H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.max_idx_set); /* Max. index set (+1) */ + H5F_ENCODE_LENGTH(f, image, hdr->stats.stored.nelmts); /* Number of elements 'realized' */ + + /* Internal information */ + H5F_addr_encode(f, &image, hdr->idx_blk_addr); /* Address of index block */ + + /* Compute metadata checksum */ + metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); + + /* Metadata checksum */ + UINT32ENCODE(image, metadata_chksum); + + /* Sanity check */ + HDassert((size_t)(image - (uint8_t *)_image) == len); END_FUNC(STATIC) /* end H5EA__cache_hdr_serialize() */ @@ -505,66 +505,65 @@ END_FUNC(STATIC) /* end H5EA__cache_hdr_serialize() */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_hdr_notify(H5AC_notify_action_t action, void *_thing)) -/* Local variables */ -H5EA_hdr_t *hdr = (H5EA_hdr_t *)_thing; /* Pointer to the object */ - -/* Sanity check */ -HDassert(hdr); - -/* Check if the file was opened with SWMR-write access */ -if (hdr->swmr_write) { - /* Determine which action to take */ - switch (action) { - case H5AC_NOTIFY_ACTION_AFTER_INSERT: - case H5AC_NOTIFY_ACTION_AFTER_LOAD: - case H5AC_NOTIFY_ACTION_AFTER_FLUSH: - case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: - case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: - case H5AC_NOTIFY_ACTION_CHILD_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: - case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: - /* do nothing */ - break; - - case H5AC_NOTIFY_ACTION_BEFORE_EVICT: - /* If hdr->parent != NULL, hdr->parent is used to destroy - * the flush dependency before the header is evicted. - */ - if (hdr->parent) { - /* Sanity check */ - HDassert(hdr->top_proxy); - - /* Destroy flush dependency on object header proxy */ - if (H5AC_proxy_entry_remove_child((H5AC_proxy_entry_t *)hdr->parent, (void *)hdr->top_proxy) < - 0) - H5E_THROW(H5E_CANTUNDEPEND, - "unable to destroy flush dependency between extensible array and proxy") - hdr->parent = NULL; - } /* end if */ - - /* Detach from 'top' proxy for extensible array */ - if (hdr->top_proxy) { - if (H5AC_proxy_entry_remove_child(hdr->top_proxy, hdr) < 0) - H5E_THROW( - H5E_CANTUNDEPEND, - "unable to destroy flush dependency between header and extensible array 'top' proxy") - /* Don't reset hdr->top_proxy here, it's destroyed when the header is freed -QAK */ - } /* end if */ - break; - - default: + /* Local variables */ + H5EA_hdr_t *hdr = (H5EA_hdr_t *)_thing; /* Pointer to the object */ + + /* Sanity check */ + HDassert(hdr); + + /* Check if the file was opened with SWMR-write access */ + if (hdr->swmr_write) { + /* Determine which action to take */ + switch (action) { + case H5AC_NOTIFY_ACTION_AFTER_INSERT: + case H5AC_NOTIFY_ACTION_AFTER_LOAD: + case H5AC_NOTIFY_ACTION_AFTER_FLUSH: + case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: + case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: + case H5AC_NOTIFY_ACTION_CHILD_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: + case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: + /* do nothing */ + break; + + case H5AC_NOTIFY_ACTION_BEFORE_EVICT: + /* If hdr->parent != NULL, hdr->parent is used to destroy + * the flush dependency before the header is evicted. + */ + if (hdr->parent) { + /* Sanity check */ + HDassert(hdr->top_proxy); + + /* Destroy flush dependency on object header proxy */ + if (H5AC_proxy_entry_remove_child((H5AC_proxy_entry_t *)hdr->parent, + (void *)hdr->top_proxy) < 0) + H5E_THROW(H5E_CANTUNDEPEND, + "unable to destroy flush dependency between extensible array and proxy") + hdr->parent = NULL; + } /* end if */ + + /* Detach from 'top' proxy for extensible array */ + if (hdr->top_proxy) { + if (H5AC_proxy_entry_remove_child(hdr->top_proxy, hdr) < 0) + H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency between header and " + "extensible array 'top' proxy") + /* Don't reset hdr->top_proxy here, it's destroyed when the header is freed -QAK */ + } /* end if */ + break; + + default: #ifdef NDEBUG - H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") -#else /* NDEBUG */ - HDassert(0 && "Unknown action?!?"); -#endif /* NDEBUG */ - } /* end switch */ -} /* end if */ -else - HDassert(NULL == hdr->parent); + H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") +#else /* NDEBUG */ + HDassert(0 && "Unknown action?!?"); +#endif /* NDEBUG */ + } /* end switch */ + } /* end if */ + else + HDassert(NULL == hdr->parent); -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_hdr_notify() */ @@ -583,14 +582,14 @@ END_FUNC(STATIC) /* end H5EA__cache_hdr_notify() */ */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_hdr_free_icr(void *thing)) -/* Check arguments */ -HDassert(thing); + /* Check arguments */ + HDassert(thing); -/* Release the extensible array header */ -if (H5EA__hdr_dest((H5EA_hdr_t *)thing) < 0) - H5E_THROW(H5E_CANTFREE, "can't free extensible array header") + /* Release the extensible array header */ + if (H5EA__hdr_dest((H5EA_hdr_t *)thing) < 0) + H5E_THROW(H5E_CANTFREE, "can't free extensible array header") -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_hdr_free_icr() */ @@ -609,23 +608,23 @@ END_FUNC(STATIC) /* end H5EA__cache_hdr_free_icr() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_iblock_get_initial_load_size(void *_udata, size_t *image_len)) -/* Local variables */ -H5EA_hdr_t * hdr = (H5EA_hdr_t *)_udata; /* User data for callback */ -H5EA_iblock_t iblock; /* Fake index block for computing size */ + /* Local variables */ + H5EA_hdr_t * hdr = (H5EA_hdr_t *)_udata; /* User data for callback */ + H5EA_iblock_t iblock; /* Fake index block for computing size */ -/* Check arguments */ -HDassert(hdr); -HDassert(image_len); + /* Check arguments */ + HDassert(hdr); + HDassert(image_len); -/* Set up fake index block for computing size on disk */ -HDmemset(&iblock, 0, sizeof(iblock)); -iblock.hdr = (H5EA_hdr_t *)hdr; /* Casting away 'const' OK - QAK */ -iblock.nsblks = H5EA_SBLK_FIRST_IDX(hdr->cparam.sup_blk_min_data_ptrs); -iblock.ndblk_addrs = 2 * ((size_t)hdr->cparam.sup_blk_min_data_ptrs - 1); -iblock.nsblk_addrs = hdr->nsblks - iblock.nsblks; + /* Set up fake index block for computing size on disk */ + HDmemset(&iblock, 0, sizeof(iblock)); + iblock.hdr = (H5EA_hdr_t *)hdr; /* Casting away 'const' OK - QAK */ + iblock.nsblks = H5EA_SBLK_FIRST_IDX(hdr->cparam.sup_blk_min_data_ptrs); + iblock.ndblk_addrs = 2 * ((size_t)hdr->cparam.sup_blk_min_data_ptrs - 1); + iblock.nsblk_addrs = hdr->nsblks - iblock.nsblks; -/* Set the image length size */ -*image_len = (size_t)H5EA_IBLOCK_SIZE(&iblock); + /* Set the image length size */ + *image_len = (size_t)H5EA_IBLOCK_SIZE(&iblock); END_FUNC(STATIC) /* end H5EA__cache_iblock_get_initial_load_size() */ @@ -645,19 +644,19 @@ END_FUNC(STATIC) /* end H5EA__cache_iblock_get_initial_load_size() */ BEGIN_FUNC(STATIC, NOERR, htri_t, TRUE, -, H5EA__cache_iblock_verify_chksum(const void *_image, size_t len, void H5_ATTR_UNUSED *_udata)) -/* Local variables */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -uint32_t computed_chksum; /* Computed metadata checksum value */ + /* Local variables */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ -/* Check arguments */ -HDassert(image); + /* Check arguments */ + HDassert(image); -/* Get stored and computed checksums */ -H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); + /* Get stored and computed checksums */ + H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); -if (stored_chksum != computed_chksum) - ret_value = FALSE; + if (stored_chksum != computed_chksum) + ret_value = FALSE; END_FUNC(STATIC) /* end H5EA__cache_iblock_verify_chksum() */ @@ -678,91 +677,92 @@ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5EA__cache_iblock_deserialize(const void *_image, size_t len, void *_udata, hbool_t H5_ATTR_UNUSED *dirty)) -/* Local variables */ -H5EA_iblock_t *iblock = NULL; /* Index block info */ -H5EA_hdr_t * hdr = (H5EA_hdr_t *)_udata; /* User data for callback */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -haddr_t arr_addr; /* Address of array header in the file */ -size_t u; /* Local index variable */ - -/* Check arguments */ -HDassert(image); -HDassert(hdr); - -/* Allocate the extensible array index block */ -if (NULL == (iblock = H5EA__iblock_alloc(hdr))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array index block") - -/* Set the extensible array index block's address */ -iblock->addr = hdr->idx_blk_addr; - -/* Magic number */ -if (HDmemcmp(image, H5EA_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) - H5E_THROW(H5E_BADVALUE, "wrong extensible array index block signature") -image += H5_SIZEOF_MAGIC; - -/* Version */ -if (*image++ != H5EA_IBLOCK_VERSION) - H5E_THROW(H5E_VERSION, "wrong extensible array index block version") - -/* Extensible array type */ -if (*image++ != (uint8_t)hdr->cparam.cls->id) - H5E_THROW(H5E_BADTYPE, "incorrect extensible array class") - -/* Address of header for array that owns this block (just for file integrity checks) */ -H5F_addr_decode(hdr->f, &image, &arr_addr); -if (H5F_addr_ne(arr_addr, hdr->addr)) - H5E_THROW(H5E_BADVALUE, "wrong extensible array header address") - -/* Internal information */ - -/* Decode elements in index block */ -if (hdr->cparam.idx_blk_elmts > 0) { - /* Convert from raw elements on disk into native elements in memory */ - if ((hdr->cparam.cls->decode)(image, iblock->elmts, (size_t)hdr->cparam.idx_blk_elmts, hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTDECODE, "can't decode extensible array index elements") - image += (hdr->cparam.idx_blk_elmts * hdr->cparam.raw_elmt_size); -} /* end if */ - -/* Decode data block addresses in index block */ -if (iblock->ndblk_addrs > 0) { - /* Decode addresses of data blocks in index block */ - for (u = 0; u < iblock->ndblk_addrs; u++) - H5F_addr_decode(hdr->f, &image, &iblock->dblk_addrs[u]); -} /* end if */ - -/* Decode super block addresses in index block */ -if (iblock->nsblk_addrs > 0) { - /* Decode addresses of super blocks in index block */ - for (u = 0; u < iblock->nsblk_addrs; u++) - H5F_addr_decode(hdr->f, &image, &iblock->sblk_addrs[u]); -} /* end if */ - -/* Sanity check */ -/* (allow for checksum not decoded yet) */ -HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5EA_SIZEOF_CHKSUM)); - -/* Save the index block's size */ -iblock->size = len; - -/* checksum verification already done in verify_chksum cb */ - -/* Metadata checksum */ -UINT32DECODE(image, stored_chksum); - -/* Sanity check */ -HDassert((size_t)(image - (const uint8_t *)_image) == iblock->size); - -/* Set return value */ -ret_value = iblock; - -CATCH - -/* Release resources */ -if (!ret_value) - if (iblock && H5EA__iblock_dest(iblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array index block") + /* Local variables */ + H5EA_iblock_t *iblock = NULL; /* Index block info */ + H5EA_hdr_t * hdr = (H5EA_hdr_t *)_udata; /* User data for callback */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + haddr_t arr_addr; /* Address of array header in the file */ + size_t u; /* Local index variable */ + + /* Check arguments */ + HDassert(image); + HDassert(hdr); + + /* Allocate the extensible array index block */ + if (NULL == (iblock = H5EA__iblock_alloc(hdr))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array index block") + + /* Set the extensible array index block's address */ + iblock->addr = hdr->idx_blk_addr; + + /* Magic number */ + if (HDmemcmp(image, H5EA_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) + H5E_THROW(H5E_BADVALUE, "wrong extensible array index block signature") + image += H5_SIZEOF_MAGIC; + + /* Version */ + if (*image++ != H5EA_IBLOCK_VERSION) + H5E_THROW(H5E_VERSION, "wrong extensible array index block version") + + /* Extensible array type */ + if (*image++ != (uint8_t)hdr->cparam.cls->id) + H5E_THROW(H5E_BADTYPE, "incorrect extensible array class") + + /* Address of header for array that owns this block (just for file integrity checks) */ + H5F_addr_decode(hdr->f, &image, &arr_addr); + if (H5F_addr_ne(arr_addr, hdr->addr)) + H5E_THROW(H5E_BADVALUE, "wrong extensible array header address") + + /* Internal information */ + + /* Decode elements in index block */ + if (hdr->cparam.idx_blk_elmts > 0) { + /* Convert from raw elements on disk into native elements in memory */ + if ((hdr->cparam.cls->decode)(image, iblock->elmts, (size_t)hdr->cparam.idx_blk_elmts, hdr->cb_ctx) < + 0) + H5E_THROW(H5E_CANTDECODE, "can't decode extensible array index elements") + image += (hdr->cparam.idx_blk_elmts * hdr->cparam.raw_elmt_size); + } /* end if */ + + /* Decode data block addresses in index block */ + if (iblock->ndblk_addrs > 0) { + /* Decode addresses of data blocks in index block */ + for (u = 0; u < iblock->ndblk_addrs; u++) + H5F_addr_decode(hdr->f, &image, &iblock->dblk_addrs[u]); + } /* end if */ + + /* Decode super block addresses in index block */ + if (iblock->nsblk_addrs > 0) { + /* Decode addresses of super blocks in index block */ + for (u = 0; u < iblock->nsblk_addrs; u++) + H5F_addr_decode(hdr->f, &image, &iblock->sblk_addrs[u]); + } /* end if */ + + /* Sanity check */ + /* (allow for checksum not decoded yet) */ + HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5EA_SIZEOF_CHKSUM)); + + /* Save the index block's size */ + iblock->size = len; + + /* checksum verification already done in verify_chksum cb */ + + /* Metadata checksum */ + UINT32DECODE(image, stored_chksum); + + /* Sanity check */ + HDassert((size_t)(image - (const uint8_t *)_image) == iblock->size); + + /* Set return value */ + ret_value = iblock; + + CATCH + + /* Release resources */ + if (!ret_value) + if (iblock && H5EA__iblock_dest(iblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array index block") END_FUNC(STATIC) /* end H5EA__cache_iblock_deserialize() */ @@ -781,15 +781,15 @@ END_FUNC(STATIC) /* end H5EA__cache_iblock_deserialize() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_iblock_image_len(const void *_thing, size_t *image_len)) -/* Local variables */ -const H5EA_iblock_t *iblock = (const H5EA_iblock_t *)_thing; /* Pointer to the object */ + /* Local variables */ + const H5EA_iblock_t *iblock = (const H5EA_iblock_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(iblock); -HDassert(image_len); + /* Check arguments */ + HDassert(iblock); + HDassert(image_len); -/* Set the image length size */ -*image_len = iblock->size; + /* Set the image length size */ + *image_len = iblock->size; END_FUNC(STATIC) /* end H5EA__cache_iblock_image_len() */ @@ -809,72 +809,72 @@ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_iblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, void *_thing)) -/* Local variables */ -H5EA_iblock_t *iblock = (H5EA_iblock_t *)_thing; /* Pointer to the object to serialize */ -uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t metadata_chksum; /* Computed metadata checksum value */ + /* Local variables */ + H5EA_iblock_t *iblock = (H5EA_iblock_t *)_thing; /* Pointer to the object to serialize */ + uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t metadata_chksum; /* Computed metadata checksum value */ -/* check arguments */ -HDassert(f); -HDassert(image); -HDassert(iblock); -HDassert(iblock->hdr); + /* check arguments */ + HDassert(f); + HDassert(image); + HDassert(iblock); + HDassert(iblock->hdr); -/* Get temporary pointer to serialized info */ + /* Get temporary pointer to serialized info */ -/* Magic number */ -H5MM_memcpy(image, H5EA_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); -image += H5_SIZEOF_MAGIC; + /* Magic number */ + H5MM_memcpy(image, H5EA_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + image += H5_SIZEOF_MAGIC; -/* Version # */ -*image++ = H5EA_IBLOCK_VERSION; + /* Version # */ + *image++ = H5EA_IBLOCK_VERSION; -/* Extensible array type */ -HDassert(iblock->hdr->cparam.cls->id <= 255); -*image++ = (uint8_t)iblock->hdr->cparam.cls->id; + /* Extensible array type */ + HDassert(iblock->hdr->cparam.cls->id <= 255); + *image++ = (uint8_t)iblock->hdr->cparam.cls->id; -/* Address of array header for array which owns this block */ -H5F_addr_encode(f, &image, iblock->hdr->addr); + /* Address of array header for array which owns this block */ + H5F_addr_encode(f, &image, iblock->hdr->addr); -/* Internal information */ + /* Internal information */ -/* Encode elements in index block */ -if (iblock->hdr->cparam.idx_blk_elmts > 0) { - /* Convert from native elements in memory into raw elements on disk */ - if ((iblock->hdr->cparam.cls->encode)(image, iblock->elmts, (size_t)iblock->hdr->cparam.idx_blk_elmts, - iblock->hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTENCODE, "can't encode extensible array index elements") - image += (iblock->hdr->cparam.idx_blk_elmts * iblock->hdr->cparam.raw_elmt_size); -} /* end if */ + /* Encode elements in index block */ + if (iblock->hdr->cparam.idx_blk_elmts > 0) { + /* Convert from native elements in memory into raw elements on disk */ + if ((iblock->hdr->cparam.cls->encode)(image, iblock->elmts, (size_t)iblock->hdr->cparam.idx_blk_elmts, + iblock->hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTENCODE, "can't encode extensible array index elements") + image += (iblock->hdr->cparam.idx_blk_elmts * iblock->hdr->cparam.raw_elmt_size); + } /* end if */ -/* Encode data block addresses in index block */ -if (iblock->ndblk_addrs > 0) { - size_t u; /* Local index variable */ + /* Encode data block addresses in index block */ + if (iblock->ndblk_addrs > 0) { + size_t u; /* Local index variable */ - /* Encode addresses of data blocks in index block */ - for (u = 0; u < iblock->ndblk_addrs; u++) - H5F_addr_encode(f, &image, iblock->dblk_addrs[u]); -} /* end if */ + /* Encode addresses of data blocks in index block */ + for (u = 0; u < iblock->ndblk_addrs; u++) + H5F_addr_encode(f, &image, iblock->dblk_addrs[u]); + } /* end if */ -/* Encode data block addresses in index block */ -if (iblock->nsblk_addrs > 0) { - size_t u; /* Local index variable */ + /* Encode data block addresses in index block */ + if (iblock->nsblk_addrs > 0) { + size_t u; /* Local index variable */ - /* Encode addresses of super blocks in index block */ - for (u = 0; u < iblock->nsblk_addrs; u++) - H5F_addr_encode(f, &image, iblock->sblk_addrs[u]); -} /* end if */ + /* Encode addresses of super blocks in index block */ + for (u = 0; u < iblock->nsblk_addrs; u++) + H5F_addr_encode(f, &image, iblock->sblk_addrs[u]); + } /* end if */ -/* Compute metadata checksum */ -metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); + /* Compute metadata checksum */ + metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); -/* Metadata checksum */ -UINT32ENCODE(image, metadata_chksum); + /* Metadata checksum */ + UINT32ENCODE(image, metadata_chksum); -/* Sanity check */ -HDassert((size_t)(image - (uint8_t *)_image) == len); + /* Sanity check */ + HDassert((size_t)(image - (uint8_t *)_image) == len); -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_iblock_serialize() */ @@ -893,59 +893,58 @@ END_FUNC(STATIC) /* end H5EA__cache_iblock_serialize() */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_iblock_notify(H5AC_notify_action_t action, void *_thing)) -/* Local variables */ -H5EA_iblock_t *iblock = (H5EA_iblock_t *)_thing; /* Pointer to the object */ - -/* Sanity check */ -HDassert(iblock); - -/* Determine which action to take */ -switch (action) { - case H5AC_NOTIFY_ACTION_AFTER_INSERT: - case H5AC_NOTIFY_ACTION_AFTER_LOAD: - /* Create flush dependency on extensible array header */ - if (H5EA__create_flush_depend((H5AC_info_t *)iblock->hdr, (H5AC_info_t *)iblock) < 0) - H5E_THROW(H5E_CANTDEPEND, - "unable to create flush dependency between index block and header, address = %llu", - (unsigned long long)iblock->addr) - break; - - case H5AC_NOTIFY_ACTION_AFTER_FLUSH: - case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: - case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: - case H5AC_NOTIFY_ACTION_CHILD_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: - case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: - /* do nothing */ - break; - - case H5AC_NOTIFY_ACTION_BEFORE_EVICT: - /* Destroy flush dependency on extensible array header */ - if (H5EA__destroy_flush_depend((H5AC_info_t *)iblock->hdr, (H5AC_info_t *)iblock) < 0) - H5E_THROW(H5E_CANTUNDEPEND, - "unable to destroy flush dependency between index block and header, address = %llu", - (unsigned long long)iblock->addr) - - /* Detach from 'top' proxy for extensible array */ - if (iblock->top_proxy) { - if (H5AC_proxy_entry_remove_child(iblock->top_proxy, iblock) < 0) - H5E_THROW( - H5E_CANTUNDEPEND, - "unable to destroy flush dependency between index block and extensible array 'top' proxy") - iblock->top_proxy = NULL; - } /* end if */ - break; + /* Local variables */ + H5EA_iblock_t *iblock = (H5EA_iblock_t *)_thing; /* Pointer to the object */ + + /* Sanity check */ + HDassert(iblock); - default: + /* Determine which action to take */ + switch (action) { + case H5AC_NOTIFY_ACTION_AFTER_INSERT: + case H5AC_NOTIFY_ACTION_AFTER_LOAD: + /* Create flush dependency on extensible array header */ + if (H5EA__create_flush_depend((H5AC_info_t *)iblock->hdr, (H5AC_info_t *)iblock) < 0) + H5E_THROW(H5E_CANTDEPEND, + "unable to create flush dependency between index block and header, address = %llu", + (unsigned long long)iblock->addr) + break; + + case H5AC_NOTIFY_ACTION_AFTER_FLUSH: + case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: + case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: + case H5AC_NOTIFY_ACTION_CHILD_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: + case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: + /* do nothing */ + break; + + case H5AC_NOTIFY_ACTION_BEFORE_EVICT: + /* Destroy flush dependency on extensible array header */ + if (H5EA__destroy_flush_depend((H5AC_info_t *)iblock->hdr, (H5AC_info_t *)iblock) < 0) + H5E_THROW(H5E_CANTUNDEPEND, + "unable to destroy flush dependency between index block and header, address = %llu", + (unsigned long long)iblock->addr) + + /* Detach from 'top' proxy for extensible array */ + if (iblock->top_proxy) { + if (H5AC_proxy_entry_remove_child(iblock->top_proxy, iblock) < 0) + H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency between index block and " + "extensible array 'top' proxy") + iblock->top_proxy = NULL; + } /* end if */ + break; + + default: #ifdef NDEBUG - H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") + H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") #else /* NDEBUG */ - HDassert(0 && "Unknown action?!?"); + HDassert(0 && "Unknown action?!?"); #endif /* NDEBUG */ -} /* end switch */ + } /* end switch */ -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_iblock_notify() */ @@ -964,14 +963,14 @@ END_FUNC(STATIC) /* end H5EA__cache_iblock_notify() */ */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_iblock_free_icr(void *thing)) -/* Check arguments */ -HDassert(thing); + /* Check arguments */ + HDassert(thing); -/* Release the extensible array index block */ -if (H5EA__iblock_dest((H5EA_iblock_t *)thing) < 0) - H5E_THROW(H5E_CANTFREE, "can't free extensible array index block") + /* Release the extensible array index block */ + if (H5EA__iblock_dest((H5EA_iblock_t *)thing) < 0) + H5E_THROW(H5E_CANTFREE, "can't free extensible array index block") -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_iblock_free_icr() */ @@ -990,42 +989,42 @@ END_FUNC(STATIC) /* end H5EA__cache_iblock_free_icr() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_sblock_get_initial_load_size(void *_udata, size_t *image_len)) -/* Local variables */ -H5EA_sblock_cache_ud_t *udata = (H5EA_sblock_cache_ud_t *)_udata; /* User data */ -H5EA_sblock_t sblock; /* Fake super block for computing size */ + /* Local variables */ + H5EA_sblock_cache_ud_t *udata = (H5EA_sblock_cache_ud_t *)_udata; /* User data */ + H5EA_sblock_t sblock; /* Fake super block for computing size */ -/* Check arguments */ -HDassert(udata); -HDassert(udata->hdr); -HDassert(udata->sblk_idx > 0); -HDassert(H5F_addr_defined(udata->sblk_addr)); -HDassert(image_len); + /* Check arguments */ + HDassert(udata); + HDassert(udata->hdr); + HDassert(udata->sblk_idx > 0); + HDassert(H5F_addr_defined(udata->sblk_addr)); + HDassert(image_len); -/* Set up fake super block for computing size on disk */ -/* (Note: extracted from H5EA__sblock_alloc) */ -HDmemset(&sblock, 0, sizeof(sblock)); -sblock.hdr = udata->hdr; -sblock.ndblks = udata->hdr->sblk_info[udata->sblk_idx].ndblks; -sblock.dblk_nelmts = udata->hdr->sblk_info[udata->sblk_idx].dblk_nelmts; + /* Set up fake super block for computing size on disk */ + /* (Note: extracted from H5EA__sblock_alloc) */ + HDmemset(&sblock, 0, sizeof(sblock)); + sblock.hdr = udata->hdr; + sblock.ndblks = udata->hdr->sblk_info[udata->sblk_idx].ndblks; + sblock.dblk_nelmts = udata->hdr->sblk_info[udata->sblk_idx].dblk_nelmts; -/* Check if # of elements in data blocks requires paging */ -if (sblock.dblk_nelmts > udata->hdr->dblk_page_nelmts) { - /* Compute # of pages in each data block from this super block */ - sblock.dblk_npages = sblock.dblk_nelmts / udata->hdr->dblk_page_nelmts; + /* Check if # of elements in data blocks requires paging */ + if (sblock.dblk_nelmts > udata->hdr->dblk_page_nelmts) { + /* Compute # of pages in each data block from this super block */ + sblock.dblk_npages = sblock.dblk_nelmts / udata->hdr->dblk_page_nelmts; - /* Sanity check that we have at least 2 pages in data block */ - HDassert(sblock.dblk_npages > 1); + /* Sanity check that we have at least 2 pages in data block */ + HDassert(sblock.dblk_npages > 1); - /* Sanity check for integer truncation */ - HDassert((sblock.dblk_npages * udata->hdr->dblk_page_nelmts) == sblock.dblk_nelmts); + /* Sanity check for integer truncation */ + HDassert((sblock.dblk_npages * udata->hdr->dblk_page_nelmts) == sblock.dblk_nelmts); - /* Compute size of buffer for each data block's 'page init' bitmask */ - sblock.dblk_page_init_size = ((sblock.dblk_npages) + 7) / 8; - HDassert(sblock.dblk_page_init_size > 0); -} /* end if */ + /* Compute size of buffer for each data block's 'page init' bitmask */ + sblock.dblk_page_init_size = ((sblock.dblk_npages) + 7) / 8; + HDassert(sblock.dblk_page_init_size > 0); + } /* end if */ -/* Set the image length size */ -*image_len = (size_t)H5EA_SBLOCK_SIZE(&sblock); + /* Set the image length size */ + *image_len = (size_t)H5EA_SBLOCK_SIZE(&sblock); END_FUNC(STATIC) /* end H5EA__cache_sblock_get_initial_load_size() */ @@ -1045,19 +1044,19 @@ END_FUNC(STATIC) /* end H5EA__cache_sblock_get_initial_load_size() */ BEGIN_FUNC(STATIC, NOERR, htri_t, TRUE, -, H5EA__cache_sblock_verify_chksum(const void *_image, size_t len, void H5_ATTR_UNUSED *_udata)) -/* Local variables */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -uint32_t computed_chksum; /* Computed metadata checksum value */ + /* Local variables */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ -/* Check arguments */ -HDassert(image); + /* Check arguments */ + HDassert(image); -/* Get stored and computed checksums */ -H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); + /* Get stored and computed checksums */ + H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); -if (stored_chksum != computed_chksum) - ret_value = FALSE; + if (stored_chksum != computed_chksum) + ret_value = FALSE; END_FUNC(STATIC) /* end H5EA__cache_sblock_verify_chksum() */ @@ -1078,89 +1077,89 @@ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5EA__cache_sblock_deserialize(const void *_image, size_t len, void *_udata, hbool_t H5_ATTR_UNUSED *dirty)) -/* Local variables */ -H5EA_sblock_t * sblock = NULL; /* Super block info */ -H5EA_sblock_cache_ud_t *udata = (H5EA_sblock_cache_ud_t *)_udata; /* User data */ -const uint8_t * image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -haddr_t arr_addr; /* Address of array header in the file */ -size_t u; /* Local index variable */ + /* Local variables */ + H5EA_sblock_t * sblock = NULL; /* Super block info */ + H5EA_sblock_cache_ud_t *udata = (H5EA_sblock_cache_ud_t *)_udata; /* User data */ + const uint8_t * image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + haddr_t arr_addr; /* Address of array header in the file */ + size_t u; /* Local index variable */ -/* Sanity check */ -HDassert(udata); -HDassert(udata->hdr); -HDassert(udata->parent); -HDassert(udata->sblk_idx > 0); -HDassert(H5F_addr_defined(udata->sblk_addr)); + /* Sanity check */ + HDassert(udata); + HDassert(udata->hdr); + HDassert(udata->parent); + HDassert(udata->sblk_idx > 0); + HDassert(H5F_addr_defined(udata->sblk_addr)); -/* Allocate the extensible array super block */ -if (NULL == (sblock = H5EA__sblock_alloc(udata->hdr, udata->parent, udata->sblk_idx))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array super block") + /* Allocate the extensible array super block */ + if (NULL == (sblock = H5EA__sblock_alloc(udata->hdr, udata->parent, udata->sblk_idx))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array super block") -/* Set the extensible array super block's address */ -sblock->addr = udata->sblk_addr; + /* Set the extensible array super block's address */ + sblock->addr = udata->sblk_addr; -/* Magic number */ -if (HDmemcmp(image, H5EA_SBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) - H5E_THROW(H5E_BADVALUE, "wrong extensible array super block signature") -image += H5_SIZEOF_MAGIC; + /* Magic number */ + if (HDmemcmp(image, H5EA_SBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) + H5E_THROW(H5E_BADVALUE, "wrong extensible array super block signature") + image += H5_SIZEOF_MAGIC; -/* Version */ -if (*image++ != H5EA_SBLOCK_VERSION) - H5E_THROW(H5E_VERSION, "wrong extensible array super block version") + /* Version */ + if (*image++ != H5EA_SBLOCK_VERSION) + H5E_THROW(H5E_VERSION, "wrong extensible array super block version") -/* Extensible array type */ -if (*image++ != (uint8_t)udata->hdr->cparam.cls->id) - H5E_THROW(H5E_BADTYPE, "incorrect extensible array class") + /* Extensible array type */ + if (*image++ != (uint8_t)udata->hdr->cparam.cls->id) + H5E_THROW(H5E_BADTYPE, "incorrect extensible array class") -/* Address of header for array that owns this block (just for file integrity checks) */ -H5F_addr_decode(udata->hdr->f, &image, &arr_addr); -if (H5F_addr_ne(arr_addr, udata->hdr->addr)) - H5E_THROW(H5E_BADVALUE, "wrong extensible array header address") + /* Address of header for array that owns this block (just for file integrity checks) */ + H5F_addr_decode(udata->hdr->f, &image, &arr_addr); + if (H5F_addr_ne(arr_addr, udata->hdr->addr)) + H5E_THROW(H5E_BADVALUE, "wrong extensible array header address") -/* Offset of block within the array's address space */ -UINT64DECODE_VAR(image, sblock->block_off, udata->hdr->arr_off_size); + /* Offset of block within the array's address space */ + UINT64DECODE_VAR(image, sblock->block_off, udata->hdr->arr_off_size); -/* Internal information */ + /* Internal information */ -/* Check for 'page init' bitmasks for this super block */ -if (sblock->dblk_npages > 0) { - size_t tot_page_init_size = - sblock->ndblks * sblock->dblk_page_init_size; /* Compute total size of 'page init' buffer */ + /* Check for 'page init' bitmasks for this super block */ + if (sblock->dblk_npages > 0) { + size_t tot_page_init_size = + sblock->ndblks * sblock->dblk_page_init_size; /* Compute total size of 'page init' buffer */ - /* Retrieve the 'page init' bitmasks */ - H5MM_memcpy(sblock->page_init, image, tot_page_init_size); - image += tot_page_init_size; -} /* end if */ + /* Retrieve the 'page init' bitmasks */ + H5MM_memcpy(sblock->page_init, image, tot_page_init_size); + image += tot_page_init_size; + } /* end if */ -/* Decode data block addresses */ -for (u = 0; u < sblock->ndblks; u++) - H5F_addr_decode(udata->hdr->f, &image, &sblock->dblk_addrs[u]); + /* Decode data block addresses */ + for (u = 0; u < sblock->ndblks; u++) + H5F_addr_decode(udata->hdr->f, &image, &sblock->dblk_addrs[u]); -/* Sanity check */ -/* (allow for checksum not decoded yet) */ -HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5EA_SIZEOF_CHKSUM)); + /* Sanity check */ + /* (allow for checksum not decoded yet) */ + HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5EA_SIZEOF_CHKSUM)); -/* Save the super block's size */ -sblock->size = len; + /* Save the super block's size */ + sblock->size = len; -/* checksum verification already done in verify_chksum cb */ + /* checksum verification already done in verify_chksum cb */ -/* Metadata checksum */ -UINT32DECODE(image, stored_chksum); + /* Metadata checksum */ + UINT32DECODE(image, stored_chksum); -/* Sanity check */ -HDassert((size_t)(image - (const uint8_t *)_image) == sblock->size); + /* Sanity check */ + HDassert((size_t)(image - (const uint8_t *)_image) == sblock->size); -/* Set return value */ -ret_value = sblock; + /* Set return value */ + ret_value = sblock; -CATCH + CATCH -/* Release resources */ -if (!ret_value) - if (sblock && H5EA__sblock_dest(sblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array super block") + /* Release resources */ + if (!ret_value) + if (sblock && H5EA__sblock_dest(sblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array super block") END_FUNC(STATIC) /* end H5EA__cache_sblock_deserialize() */ @@ -1179,15 +1178,15 @@ END_FUNC(STATIC) /* end H5EA__cache_sblock_deserialize() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_sblock_image_len(const void *_thing, size_t *image_len)) -/* Local variables */ -const H5EA_sblock_t *sblock = (const H5EA_sblock_t *)_thing; /* Pointer to the object */ + /* Local variables */ + const H5EA_sblock_t *sblock = (const H5EA_sblock_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(sblock); -HDassert(image_len); + /* Check arguments */ + HDassert(sblock); + HDassert(image_len); -/* Set the image length size */ -*image_len = sblock->size; + /* Set the image length size */ + *image_len = sblock->size; END_FUNC(STATIC) /* end H5EA__cache_sblock_image_len() */ @@ -1207,59 +1206,59 @@ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_sblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, void *_thing)) -/* Local variables */ -H5EA_sblock_t *sblock = (H5EA_sblock_t *)_thing; /* Pointer to the object to serialize */ -uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t metadata_chksum; /* Computed metadata checksum value */ -size_t u; /* Local index variable */ + /* Local variables */ + H5EA_sblock_t *sblock = (H5EA_sblock_t *)_thing; /* Pointer to the object to serialize */ + uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t metadata_chksum; /* Computed metadata checksum value */ + size_t u; /* Local index variable */ -/* check arguments */ -HDassert(f); -HDassert(image); -HDassert(sblock); -HDassert(sblock->hdr); + /* check arguments */ + HDassert(f); + HDassert(image); + HDassert(sblock); + HDassert(sblock->hdr); -/* Magic number */ -H5MM_memcpy(image, H5EA_SBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); -image += H5_SIZEOF_MAGIC; + /* Magic number */ + H5MM_memcpy(image, H5EA_SBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + image += H5_SIZEOF_MAGIC; -/* Version # */ -*image++ = H5EA_SBLOCK_VERSION; + /* Version # */ + *image++ = H5EA_SBLOCK_VERSION; -/* Extensible array type */ -HDassert(sblock->hdr->cparam.cls->id <= 255); -*image++ = (uint8_t)sblock->hdr->cparam.cls->id; + /* Extensible array type */ + HDassert(sblock->hdr->cparam.cls->id <= 255); + *image++ = (uint8_t)sblock->hdr->cparam.cls->id; -/* Address of array header for array which owns this block */ -H5F_addr_encode(f, &image, sblock->hdr->addr); + /* Address of array header for array which owns this block */ + H5F_addr_encode(f, &image, sblock->hdr->addr); -/* Offset of block in array */ -UINT64ENCODE_VAR(image, sblock->block_off, sblock->hdr->arr_off_size); + /* Offset of block in array */ + UINT64ENCODE_VAR(image, sblock->block_off, sblock->hdr->arr_off_size); -/* Internal information */ + /* Internal information */ -/* Check for 'page init' bitmasks for this super block */ -if (sblock->dblk_npages > 0) { - size_t tot_page_init_size = - sblock->ndblks * sblock->dblk_page_init_size; /* Compute total size of 'page init' buffer */ + /* Check for 'page init' bitmasks for this super block */ + if (sblock->dblk_npages > 0) { + size_t tot_page_init_size = + sblock->ndblks * sblock->dblk_page_init_size; /* Compute total size of 'page init' buffer */ - /* Store the 'page init' bitmasks */ - H5MM_memcpy(image, sblock->page_init, tot_page_init_size); - image += tot_page_init_size; -} /* end if */ + /* Store the 'page init' bitmasks */ + H5MM_memcpy(image, sblock->page_init, tot_page_init_size); + image += tot_page_init_size; + } /* end if */ -/* Encode addresses of data blocks in super block */ -for (u = 0; u < sblock->ndblks; u++) - H5F_addr_encode(f, &image, sblock->dblk_addrs[u]); + /* Encode addresses of data blocks in super block */ + for (u = 0; u < sblock->ndblks; u++) + H5F_addr_encode(f, &image, sblock->dblk_addrs[u]); -/* Compute metadata checksum */ -metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); + /* Compute metadata checksum */ + metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); -/* Metadata checksum */ -UINT32ENCODE(image, metadata_chksum); + /* Metadata checksum */ + UINT32ENCODE(image, metadata_chksum); -/* Sanity check */ -HDassert((size_t)(image - (uint8_t *)_image) == len); + /* Sanity check */ + HDassert((size_t)(image - (uint8_t *)_image) == len); END_FUNC(STATIC) /* end H5EA__cache_sblock_serialize() */ @@ -1278,79 +1277,81 @@ END_FUNC(STATIC) /* end H5EA__cache_sblock_serialize() */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_sblock_notify(H5AC_notify_action_t action, void *_thing)) -/* Local variables */ -H5EA_sblock_t *sblock = (H5EA_sblock_t *)_thing; /* Pointer to the object */ - -/* Sanity check */ -HDassert(sblock); - -/* Determine which action to take */ -switch (action) { - case H5AC_NOTIFY_ACTION_AFTER_INSERT: - case H5AC_NOTIFY_ACTION_AFTER_LOAD: - /* Create flush dependency on index block */ - if (H5EA__create_flush_depend((H5AC_info_t *)sblock->parent, (H5AC_info_t *)sblock) < 0) - H5E_THROW(H5E_CANTDEPEND, - "unable to create flush dependency between super block and index block, address = %llu", - (unsigned long long)sblock->addr) - break; - - case H5AC_NOTIFY_ACTION_AFTER_FLUSH: - /* Destroy flush dependency on extensible array header, if set */ - if (sblock->has_hdr_depend) { - if (H5EA__destroy_flush_depend((H5AC_info_t *)sblock->hdr, (H5AC_info_t *)sblock) < 0) - H5E_THROW(H5E_CANTUNDEPEND, - "unable to destroy flush dependency between super block and header, address = %llu", - (unsigned long long)sblock->addr) - sblock->has_hdr_depend = FALSE; - } /* end if */ - break; - - case H5AC_NOTIFY_ACTION_BEFORE_EVICT: - /* Destroy flush dependency on index block */ - if (H5EA__destroy_flush_depend((H5AC_info_t *)sblock->parent, (H5AC_info_t *)sblock) < 0) - H5E_THROW( - H5E_CANTUNDEPEND, - "unable to destroy flush dependency between super block and index block, address = %llu", - (unsigned long long)sblock->addr) - - /* Destroy flush dependency on extensible array header, if set */ - if (sblock->has_hdr_depend) { - if (H5EA__destroy_flush_depend((H5AC_info_t *)sblock->hdr, (H5AC_info_t *)sblock) < 0) - H5E_THROW(H5E_CANTUNDEPEND, - "unable to destroy flush dependency between super block and header, address = %llu", - (unsigned long long)sblock->addr) - sblock->has_hdr_depend = FALSE; - } /* end if */ - - /* Detach from 'top' proxy for extensible array */ - if (sblock->top_proxy) { - if (H5AC_proxy_entry_remove_child(sblock->top_proxy, sblock) < 0) + /* Local variables */ + H5EA_sblock_t *sblock = (H5EA_sblock_t *)_thing; /* Pointer to the object */ + + /* Sanity check */ + HDassert(sblock); + + /* Determine which action to take */ + switch (action) { + case H5AC_NOTIFY_ACTION_AFTER_INSERT: + case H5AC_NOTIFY_ACTION_AFTER_LOAD: + /* Create flush dependency on index block */ + if (H5EA__create_flush_depend((H5AC_info_t *)sblock->parent, (H5AC_info_t *)sblock) < 0) + H5E_THROW( + H5E_CANTDEPEND, + "unable to create flush dependency between super block and index block, address = %llu", + (unsigned long long)sblock->addr) + break; + + case H5AC_NOTIFY_ACTION_AFTER_FLUSH: + /* Destroy flush dependency on extensible array header, if set */ + if (sblock->has_hdr_depend) { + if (H5EA__destroy_flush_depend((H5AC_info_t *)sblock->hdr, (H5AC_info_t *)sblock) < 0) + H5E_THROW( + H5E_CANTUNDEPEND, + "unable to destroy flush dependency between super block and header, address = %llu", + (unsigned long long)sblock->addr) + sblock->has_hdr_depend = FALSE; + } /* end if */ + break; + + case H5AC_NOTIFY_ACTION_BEFORE_EVICT: + /* Destroy flush dependency on index block */ + if (H5EA__destroy_flush_depend((H5AC_info_t *)sblock->parent, (H5AC_info_t *)sblock) < 0) H5E_THROW( H5E_CANTUNDEPEND, - "unable to destroy flush dependency between super block and extensible array 'top' proxy") - sblock->top_proxy = NULL; - } /* end if */ - break; - - case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: - case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: - case H5AC_NOTIFY_ACTION_CHILD_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: - case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: - /* do nothing */ - break; - - default: + "unable to destroy flush dependency between super block and index block, address = %llu", + (unsigned long long)sblock->addr) + + /* Destroy flush dependency on extensible array header, if set */ + if (sblock->has_hdr_depend) { + if (H5EA__destroy_flush_depend((H5AC_info_t *)sblock->hdr, (H5AC_info_t *)sblock) < 0) + H5E_THROW( + H5E_CANTUNDEPEND, + "unable to destroy flush dependency between super block and header, address = %llu", + (unsigned long long)sblock->addr) + sblock->has_hdr_depend = FALSE; + } /* end if */ + + /* Detach from 'top' proxy for extensible array */ + if (sblock->top_proxy) { + if (H5AC_proxy_entry_remove_child(sblock->top_proxy, sblock) < 0) + H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency between super block and " + "extensible array 'top' proxy") + sblock->top_proxy = NULL; + } /* end if */ + break; + + case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: + case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: + case H5AC_NOTIFY_ACTION_CHILD_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: + case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: + /* do nothing */ + break; + + default: #ifdef NDEBUG - H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") + H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") #else /* NDEBUG */ - HDassert(0 && "Unknown action?!?"); + HDassert(0 && "Unknown action?!?"); #endif /* NDEBUG */ -} /* end switch */ + } /* end switch */ -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_sblock_notify() */ @@ -1369,14 +1370,14 @@ END_FUNC(STATIC) /* end H5EA__cache_sblock_notify() */ */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_sblock_free_icr(void *thing)) -/* Check arguments */ -HDassert(thing); + /* Check arguments */ + HDassert(thing); -/* Release the extensible array super block */ -if (H5EA__sblock_dest((H5EA_sblock_t *)thing) < 0) - H5E_THROW(H5E_CANTFREE, "can't free extensible array super block") + /* Release the extensible array super block */ + if (H5EA__sblock_dest((H5EA_sblock_t *)thing) < 0) + H5E_THROW(H5E_CANTFREE, "can't free extensible array super block") -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_sblock_free_icr() */ @@ -1395,43 +1396,43 @@ END_FUNC(STATIC) /* end H5EA__cache_sblock_free_icr() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_dblock_get_initial_load_size(void *_udata, size_t *image_len)) -/* Local variables */ -H5EA_dblock_cache_ud_t *udata = (H5EA_dblock_cache_ud_t *)_udata; /* User data */ -H5EA_dblock_t dblock; /* Fake data block for computing size */ - -/* Check arguments */ -HDassert(udata); -HDassert(udata->hdr); -HDassert(udata->nelmts > 0); -HDassert(image_len); - -/* Set up fake data block for computing size on disk */ -/* (Note: extracted from H5EA__dblock_alloc) */ -HDmemset(&dblock, 0, sizeof(dblock)); - -/* need to set: - * - * dblock.hdr - * dblock.npages - * dblock.nelmts - * - * before we invoke either H5EA_DBLOCK_PREFIX_SIZE() or - * H5EA_DBLOCK_SIZE(). - */ -dblock.hdr = udata->hdr; -dblock.nelmts = udata->nelmts; - -if (udata->nelmts > udata->hdr->dblk_page_nelmts) { - /* Set the # of pages in the direct block */ - dblock.npages = udata->nelmts / udata->hdr->dblk_page_nelmts; - HDassert(udata->nelmts == (dblock.npages * udata->hdr->dblk_page_nelmts)); -} /* end if */ - -/* Set the image length size */ -if (!dblock.npages) - *image_len = H5EA_DBLOCK_SIZE(&dblock); -else - *image_len = H5EA_DBLOCK_PREFIX_SIZE(&dblock); + /* Local variables */ + H5EA_dblock_cache_ud_t *udata = (H5EA_dblock_cache_ud_t *)_udata; /* User data */ + H5EA_dblock_t dblock; /* Fake data block for computing size */ + + /* Check arguments */ + HDassert(udata); + HDassert(udata->hdr); + HDassert(udata->nelmts > 0); + HDassert(image_len); + + /* Set up fake data block for computing size on disk */ + /* (Note: extracted from H5EA__dblock_alloc) */ + HDmemset(&dblock, 0, sizeof(dblock)); + + /* need to set: + * + * dblock.hdr + * dblock.npages + * dblock.nelmts + * + * before we invoke either H5EA_DBLOCK_PREFIX_SIZE() or + * H5EA_DBLOCK_SIZE(). + */ + dblock.hdr = udata->hdr; + dblock.nelmts = udata->nelmts; + + if (udata->nelmts > udata->hdr->dblk_page_nelmts) { + /* Set the # of pages in the direct block */ + dblock.npages = udata->nelmts / udata->hdr->dblk_page_nelmts; + HDassert(udata->nelmts == (dblock.npages * udata->hdr->dblk_page_nelmts)); + } /* end if */ + + /* Set the image length size */ + if (!dblock.npages) + *image_len = H5EA_DBLOCK_SIZE(&dblock); + else + *image_len = H5EA_DBLOCK_PREFIX_SIZE(&dblock); END_FUNC(STATIC) /* end H5EA__cache_dblock_get_initial_load_size() */ @@ -1451,19 +1452,19 @@ END_FUNC(STATIC) /* end H5EA__cache_dblock_get_initial_load_size() */ BEGIN_FUNC(STATIC, NOERR, htri_t, TRUE, -, H5EA__cache_dblock_verify_chksum(const void *_image, size_t len, void H5_ATTR_UNUSED *_udata)) -/* Local variables */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -uint32_t computed_chksum; /* Computed metadata checksum value */ + /* Local variables */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ -/* Check arguments */ -HDassert(image); + /* Check arguments */ + HDassert(image); -/* Get stored and computed checksums */ -H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); + /* Get stored and computed checksums */ + H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); -if (stored_chksum != computed_chksum) - ret_value = FALSE; + if (stored_chksum != computed_chksum) + ret_value = FALSE; END_FUNC(STATIC) /* end H5EA__cache_sblock_verify_chksum() */ @@ -1484,87 +1485,87 @@ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5EA__cache_dblock_deserialize(const void *_image, size_t H5_ATTR_NDEBUG_UNUSED len, void *_udata, hbool_t H5_ATTR_UNUSED *dirty)) -/* Local variables */ -H5EA_dblock_t * dblock = NULL; /* Data block info */ -H5EA_dblock_cache_ud_t *udata = (H5EA_dblock_cache_ud_t *)_udata; /* User data */ -const uint8_t * image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -haddr_t arr_addr; /* Address of array header in the file */ + /* Local variables */ + H5EA_dblock_t * dblock = NULL; /* Data block info */ + H5EA_dblock_cache_ud_t *udata = (H5EA_dblock_cache_ud_t *)_udata; /* User data */ + const uint8_t * image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + haddr_t arr_addr; /* Address of array header in the file */ -/* Check arguments */ -HDassert(udata); -HDassert(udata->hdr); -HDassert(udata->parent); -HDassert(udata->nelmts > 0); -HDassert(H5F_addr_defined(udata->dblk_addr)); + /* Check arguments */ + HDassert(udata); + HDassert(udata->hdr); + HDassert(udata->parent); + HDassert(udata->nelmts > 0); + HDassert(H5F_addr_defined(udata->dblk_addr)); -/* Allocate the extensible array data block */ -if (NULL == (dblock = H5EA__dblock_alloc(udata->hdr, udata->parent, udata->nelmts))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block") + /* Allocate the extensible array data block */ + if (NULL == (dblock = H5EA__dblock_alloc(udata->hdr, udata->parent, udata->nelmts))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block") -HDassert(((!dblock->npages) && (len == H5EA_DBLOCK_SIZE(dblock))) || - (len == H5EA_DBLOCK_PREFIX_SIZE(dblock))); + HDassert(((!dblock->npages) && (len == H5EA_DBLOCK_SIZE(dblock))) || + (len == H5EA_DBLOCK_PREFIX_SIZE(dblock))); -/* Set the extensible array data block's information */ -dblock->addr = udata->dblk_addr; + /* Set the extensible array data block's information */ + dblock->addr = udata->dblk_addr; -/* Magic number */ -if (HDmemcmp(image, H5EA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) - H5E_THROW(H5E_BADVALUE, "wrong extensible array data block signature") -image += H5_SIZEOF_MAGIC; + /* Magic number */ + if (HDmemcmp(image, H5EA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) + H5E_THROW(H5E_BADVALUE, "wrong extensible array data block signature") + image += H5_SIZEOF_MAGIC; -/* Version */ -if (*image++ != H5EA_DBLOCK_VERSION) - H5E_THROW(H5E_VERSION, "wrong extensible array data block version") + /* Version */ + if (*image++ != H5EA_DBLOCK_VERSION) + H5E_THROW(H5E_VERSION, "wrong extensible array data block version") -/* Extensible array type */ -if (*image++ != (uint8_t)udata->hdr->cparam.cls->id) - H5E_THROW(H5E_BADTYPE, "incorrect extensible array class") + /* Extensible array type */ + if (*image++ != (uint8_t)udata->hdr->cparam.cls->id) + H5E_THROW(H5E_BADTYPE, "incorrect extensible array class") -/* Address of header for array that owns this block (just for file integrity checks) */ -H5F_addr_decode(udata->hdr->f, &image, &arr_addr); -if (H5F_addr_ne(arr_addr, udata->hdr->addr)) - H5E_THROW(H5E_BADVALUE, "wrong extensible array header address") + /* Address of header for array that owns this block (just for file integrity checks) */ + H5F_addr_decode(udata->hdr->f, &image, &arr_addr); + if (H5F_addr_ne(arr_addr, udata->hdr->addr)) + H5E_THROW(H5E_BADVALUE, "wrong extensible array header address") -/* Offset of block within the array's address space */ -UINT64DECODE_VAR(image, dblock->block_off, udata->hdr->arr_off_size); + /* Offset of block within the array's address space */ + UINT64DECODE_VAR(image, dblock->block_off, udata->hdr->arr_off_size); -/* Internal information */ + /* Internal information */ -/* Only decode elements if the data block is not paged */ -if (!dblock->npages) { - /* Decode elements in data block */ - /* Convert from raw elements on disk into native elements in memory */ - if ((udata->hdr->cparam.cls->decode)(image, dblock->elmts, udata->nelmts, udata->hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTDECODE, "can't decode extensible array data elements") - image += (udata->nelmts * udata->hdr->cparam.raw_elmt_size); -} /* end if */ + /* Only decode elements if the data block is not paged */ + if (!dblock->npages) { + /* Decode elements in data block */ + /* Convert from raw elements on disk into native elements in memory */ + if ((udata->hdr->cparam.cls->decode)(image, dblock->elmts, udata->nelmts, udata->hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTDECODE, "can't decode extensible array data elements") + image += (udata->nelmts * udata->hdr->cparam.raw_elmt_size); + } /* end if */ -/* Sanity check */ -/* (allow for checksum not decoded yet) */ -HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5EA_SIZEOF_CHKSUM)); + /* Sanity check */ + /* (allow for checksum not decoded yet) */ + HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5EA_SIZEOF_CHKSUM)); -/* Set the data block's size */ -/* (Note: This is not the same as the image length, for paged data blocks) */ -dblock->size = H5EA_DBLOCK_SIZE(dblock); + /* Set the data block's size */ + /* (Note: This is not the same as the image length, for paged data blocks) */ + dblock->size = H5EA_DBLOCK_SIZE(dblock); -/* checksum verification already done in verify_chksum cb */ + /* checksum verification already done in verify_chksum cb */ -/* Metadata checksum */ -UINT32DECODE(image, stored_chksum); + /* Metadata checksum */ + UINT32DECODE(image, stored_chksum); -/* Sanity check */ -HDassert((size_t)(image - (const uint8_t *)_image) == len); + /* Sanity check */ + HDassert((size_t)(image - (const uint8_t *)_image) == len); -/* Set return value */ -ret_value = dblock; + /* Set return value */ + ret_value = dblock; -CATCH + CATCH -/* Release resources */ -if (!ret_value) - if (dblock && H5EA__dblock_dest(dblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block") + /* Release resources */ + if (!ret_value) + if (dblock && H5EA__dblock_dest(dblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block") END_FUNC(STATIC) /* end H5EA__cache_dblock_deserialize() */ @@ -1583,18 +1584,18 @@ END_FUNC(STATIC) /* end H5EA__cache_dblock_deserialize() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_dblock_image_len(const void *_thing, size_t *image_len)) -/* Local variables */ -const H5EA_dblock_t *dblock = (const H5EA_dblock_t *)_thing; /* Pointer to the object */ + /* Local variables */ + const H5EA_dblock_t *dblock = (const H5EA_dblock_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(dblock); -HDassert(image_len); + /* Check arguments */ + HDassert(dblock); + HDassert(image_len); -/* Set the image length size */ -if (!dblock->npages) - *image_len = dblock->size; -else - *image_len = (size_t)H5EA_DBLOCK_PREFIX_SIZE(dblock); + /* Set the image length size */ + if (!dblock->npages) + *image_len = dblock->size; + else + *image_len = (size_t)H5EA_DBLOCK_PREFIX_SIZE(dblock); END_FUNC(STATIC) /* end H5EA__cache_dblock_image_len() */ @@ -1614,56 +1615,56 @@ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_dblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, void *_thing)) -/* Local variables */ -H5EA_dblock_t *dblock = (H5EA_dblock_t *)_thing; /* Pointer to the object to serialize */ -uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t metadata_chksum; /* Computed metadata checksum value */ + /* Local variables */ + H5EA_dblock_t *dblock = (H5EA_dblock_t *)_thing; /* Pointer to the object to serialize */ + uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t metadata_chksum; /* Computed metadata checksum value */ -/* check arguments */ -HDassert(f); -HDassert(image); -HDassert(dblock); -HDassert(dblock->hdr); + /* check arguments */ + HDassert(f); + HDassert(image); + HDassert(dblock); + HDassert(dblock->hdr); -/* Magic number */ -H5MM_memcpy(image, H5EA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); -image += H5_SIZEOF_MAGIC; + /* Magic number */ + H5MM_memcpy(image, H5EA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + image += H5_SIZEOF_MAGIC; -/* Version # */ -*image++ = H5EA_DBLOCK_VERSION; + /* Version # */ + *image++ = H5EA_DBLOCK_VERSION; -/* Extensible array type */ -HDassert(dblock->hdr->cparam.cls->id <= 255); -*image++ = (uint8_t)dblock->hdr->cparam.cls->id; + /* Extensible array type */ + HDassert(dblock->hdr->cparam.cls->id <= 255); + *image++ = (uint8_t)dblock->hdr->cparam.cls->id; -/* Address of array header for array which owns this block */ -H5F_addr_encode(f, &image, dblock->hdr->addr); + /* Address of array header for array which owns this block */ + H5F_addr_encode(f, &image, dblock->hdr->addr); -/* Offset of block in array */ -UINT64ENCODE_VAR(image, dblock->block_off, dblock->hdr->arr_off_size); + /* Offset of block in array */ + UINT64ENCODE_VAR(image, dblock->block_off, dblock->hdr->arr_off_size); -/* Internal information */ + /* Internal information */ -/* Only encode elements if the data block is not paged */ -if (!dblock->npages) { - /* Encode elements in data block */ + /* Only encode elements if the data block is not paged */ + if (!dblock->npages) { + /* Encode elements in data block */ - /* Convert from native elements in memory into raw elements on disk */ - if ((dblock->hdr->cparam.cls->encode)(image, dblock->elmts, dblock->nelmts, dblock->hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTENCODE, "can't encode extensible array data elements") - image += (dblock->nelmts * dblock->hdr->cparam.raw_elmt_size); -} /* end if */ + /* Convert from native elements in memory into raw elements on disk */ + if ((dblock->hdr->cparam.cls->encode)(image, dblock->elmts, dblock->nelmts, dblock->hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTENCODE, "can't encode extensible array data elements") + image += (dblock->nelmts * dblock->hdr->cparam.raw_elmt_size); + } /* end if */ -/* Compute metadata checksum */ -metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); + /* Compute metadata checksum */ + metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); -/* Metadata checksum */ -UINT32ENCODE(image, metadata_chksum); + /* Metadata checksum */ + UINT32ENCODE(image, metadata_chksum); -/* Sanity check */ -HDassert((size_t)(image - (uint8_t *)_image) == len); + /* Sanity check */ + HDassert((size_t)(image - (uint8_t *)_image) == len); -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_dblock_serialize() */ @@ -1682,79 +1683,79 @@ END_FUNC(STATIC) /* end H5EA__cache_dblock_serialize() */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_dblock_notify(H5AC_notify_action_t action, void *_thing)) -/* Local variables */ -H5EA_dblock_t *dblock = (H5EA_dblock_t *)_thing; /* Pointer to the object */ - -/* Check arguments */ -HDassert(dblock); - -/* Determine which action to take */ -switch (action) { - case H5AC_NOTIFY_ACTION_AFTER_INSERT: - case H5AC_NOTIFY_ACTION_AFTER_LOAD: - /* Create flush dependency on parent */ - if (H5EA__create_flush_depend((H5AC_info_t *)dblock->parent, (H5AC_info_t *)dblock) < 0) - H5E_THROW(H5E_CANTDEPEND, - "unable to create flush dependency between data block and parent, address = %llu", - (unsigned long long)dblock->addr) - break; - - case H5AC_NOTIFY_ACTION_AFTER_FLUSH: - /* Destroy flush dependency on extensible array header, if set */ - if (dblock->has_hdr_depend) { - if (H5EA__destroy_flush_depend((H5AC_info_t *)dblock->hdr, (H5AC_info_t *)dblock) < 0) - H5E_THROW( - H5E_CANTUNDEPEND, - "unable to destroy flush dependency between direct block and header, address = %llu", - (unsigned long long)dblock->addr) - dblock->has_hdr_depend = FALSE; - } /* end if */ - break; - - case H5AC_NOTIFY_ACTION_BEFORE_EVICT: - /* Destroy flush dependency on parent */ - if (H5EA__destroy_flush_depend((H5AC_info_t *)dblock->parent, (H5AC_info_t *)dblock) < 0) - H5E_THROW(H5E_CANTUNDEPEND, - "unable to destroy flush dependency between data block and parent, address = %llu", - (unsigned long long)dblock->addr) - - /* Destroy flush dependency on extensible array header, if set */ - if (dblock->has_hdr_depend) { - if (H5EA__destroy_flush_depend((H5AC_info_t *)dblock->hdr, (H5AC_info_t *)dblock) < 0) + /* Local variables */ + H5EA_dblock_t *dblock = (H5EA_dblock_t *)_thing; /* Pointer to the object */ + + /* Check arguments */ + HDassert(dblock); + + /* Determine which action to take */ + switch (action) { + case H5AC_NOTIFY_ACTION_AFTER_INSERT: + case H5AC_NOTIFY_ACTION_AFTER_LOAD: + /* Create flush dependency on parent */ + if (H5EA__create_flush_depend((H5AC_info_t *)dblock->parent, (H5AC_info_t *)dblock) < 0) + H5E_THROW(H5E_CANTDEPEND, + "unable to create flush dependency between data block and parent, address = %llu", + (unsigned long long)dblock->addr) + break; + + case H5AC_NOTIFY_ACTION_AFTER_FLUSH: + /* Destroy flush dependency on extensible array header, if set */ + if (dblock->has_hdr_depend) { + if (H5EA__destroy_flush_depend((H5AC_info_t *)dblock->hdr, (H5AC_info_t *)dblock) < 0) + H5E_THROW( + H5E_CANTUNDEPEND, + "unable to destroy flush dependency between direct block and header, address = %llu", + (unsigned long long)dblock->addr) + dblock->has_hdr_depend = FALSE; + } /* end if */ + break; + + case H5AC_NOTIFY_ACTION_BEFORE_EVICT: + /* Destroy flush dependency on parent */ + if (H5EA__destroy_flush_depend((H5AC_info_t *)dblock->parent, (H5AC_info_t *)dblock) < 0) H5E_THROW(H5E_CANTUNDEPEND, - "unable to destroy flush dependency between data block and header, address = %llu", + "unable to destroy flush dependency between data block and parent, address = %llu", (unsigned long long)dblock->addr) - dblock->has_hdr_depend = FALSE; - } /* end if */ - /* Detach from 'top' proxy for extensible array */ - if (dblock->top_proxy) { - if (H5AC_proxy_entry_remove_child(dblock->top_proxy, dblock) < 0) - H5E_THROW( - H5E_CANTUNDEPEND, - "unable to destroy flush dependency between data block and extensible array 'top' proxy") - dblock->top_proxy = NULL; - } /* end if */ - break; - - case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: - case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: - case H5AC_NOTIFY_ACTION_CHILD_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: - case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: - /* do nothing */ - break; - - default: + /* Destroy flush dependency on extensible array header, if set */ + if (dblock->has_hdr_depend) { + if (H5EA__destroy_flush_depend((H5AC_info_t *)dblock->hdr, (H5AC_info_t *)dblock) < 0) + H5E_THROW( + H5E_CANTUNDEPEND, + "unable to destroy flush dependency between data block and header, address = %llu", + (unsigned long long)dblock->addr) + dblock->has_hdr_depend = FALSE; + } /* end if */ + + /* Detach from 'top' proxy for extensible array */ + if (dblock->top_proxy) { + if (H5AC_proxy_entry_remove_child(dblock->top_proxy, dblock) < 0) + H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency between data block and " + "extensible array 'top' proxy") + dblock->top_proxy = NULL; + } /* end if */ + break; + + case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: + case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: + case H5AC_NOTIFY_ACTION_CHILD_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: + case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: + /* do nothing */ + break; + + default: #ifdef NDEBUG - H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") + H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") #else /* NDEBUG */ - HDassert(0 && "Unknown action?!?"); + HDassert(0 && "Unknown action?!?"); #endif /* NDEBUG */ -} /* end switch */ + } /* end switch */ -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_dblock_notify() */ @@ -1773,14 +1774,14 @@ END_FUNC(STATIC) /* end H5EA__cache_dblock_notify() */ */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_dblock_free_icr(void *thing)) -/* Check arguments */ -HDassert(thing); + /* Check arguments */ + HDassert(thing); -/* Release the extensible array data block */ -if (H5EA__dblock_dest((H5EA_dblock_t *)thing) < 0) - H5E_THROW(H5E_CANTFREE, "can't free extensible array data block") + /* Release the extensible array data block */ + if (H5EA__dblock_dest((H5EA_dblock_t *)thing) < 0) + H5E_THROW(H5E_CANTFREE, "can't free extensible array data block") -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_dblock_free_icr() */ @@ -1816,16 +1817,16 @@ END_FUNC(STATIC) /* end H5EA__cache_dblock_free_icr() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_dblock_fsf_size(const void *_thing, hsize_t *fsf_size)) -/* Local variables */ -const H5EA_dblock_t *dblock = (const H5EA_dblock_t *)_thing; /* Pointer to the object */ + /* Local variables */ + const H5EA_dblock_t *dblock = (const H5EA_dblock_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(dblock); -HDassert(dblock->cache_info.magic == H5C__H5C_CACHE_ENTRY_T_MAGIC); -HDassert(dblock->cache_info.type == H5AC_EARRAY_DBLOCK); -HDassert(fsf_size); + /* Check arguments */ + HDassert(dblock); + HDassert(dblock->cache_info.magic == H5C__H5C_CACHE_ENTRY_T_MAGIC); + HDassert(dblock->cache_info.type == H5AC_EARRAY_DBLOCK); + HDassert(fsf_size); -*fsf_size = dblock->size; + *fsf_size = dblock->size; END_FUNC(STATIC) /* end H5EA__cache_dblock_fsf_size() */ @@ -1844,16 +1845,16 @@ END_FUNC(STATIC) /* end H5EA__cache_dblock_fsf_size() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_dblk_page_get_initial_load_size(void *_udata, size_t *image_len)) -/* Local variables */ -H5EA_dblk_page_cache_ud_t *udata = (H5EA_dblk_page_cache_ud_t *)_udata; /* User data */ + /* Local variables */ + H5EA_dblk_page_cache_ud_t *udata = (H5EA_dblk_page_cache_ud_t *)_udata; /* User data */ -/* Check arguments */ -HDassert(udata); -HDassert(udata->hdr); -HDassert(image_len); + /* Check arguments */ + HDassert(udata); + HDassert(udata->hdr); + HDassert(image_len); -/* Set the image length size */ -*image_len = (size_t)H5EA_DBLK_PAGE_SIZE(udata->hdr); + /* Set the image length size */ + *image_len = (size_t)H5EA_DBLK_PAGE_SIZE(udata->hdr); END_FUNC(STATIC) /* end H5EA__cache_dblk_page_get_initial_load_size() */ @@ -1873,19 +1874,19 @@ END_FUNC(STATIC) /* end H5EA__cache_dblk_page_get_initial_load_size() */ BEGIN_FUNC(STATIC, NOERR, htri_t, TRUE, -, H5EA__cache_dblk_page_verify_chksum(const void *_image, size_t len, void H5_ATTR_UNUSED *_udata)) -/* Local variables */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -uint32_t computed_chksum; /* Computed metadata checksum value */ + /* Local variables */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ -/* Check arguments */ -HDassert(image); + /* Check arguments */ + HDassert(image); -/* Get stored and computed checksums */ -H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); + /* Get stored and computed checksums */ + H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); -if (stored_chksum != computed_chksum) - ret_value = FALSE; + if (stored_chksum != computed_chksum) + ret_value = FALSE; END_FUNC(STATIC) /* end H5EA__cache_dblk_page_verify_chksum() */ @@ -1906,59 +1907,59 @@ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5EA__cache_dblk_page_deserialize(const void *_image, size_t len, void *_udata, hbool_t H5_ATTR_UNUSED *dirty)) -/* Local variables */ -H5EA_dblk_page_t * dblk_page = NULL; /* Data block page info */ -H5EA_dblk_page_cache_ud_t *udata = - (H5EA_dblk_page_cache_ud_t *)_udata; /* User data for loading data block page */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ + /* Local variables */ + H5EA_dblk_page_t * dblk_page = NULL; /* Data block page info */ + H5EA_dblk_page_cache_ud_t *udata = + (H5EA_dblk_page_cache_ud_t *)_udata; /* User data for loading data block page */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ -/* Sanity check */ -HDassert(udata); -HDassert(udata->hdr); -HDassert(udata->parent); -HDassert(H5F_addr_defined(udata->dblk_page_addr)); + /* Sanity check */ + HDassert(udata); + HDassert(udata->hdr); + HDassert(udata->parent); + HDassert(H5F_addr_defined(udata->dblk_page_addr)); -/* Allocate the extensible array data block page */ -if (NULL == (dblk_page = H5EA__dblk_page_alloc(udata->hdr, udata->parent))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block page") + /* Allocate the extensible array data block page */ + if (NULL == (dblk_page = H5EA__dblk_page_alloc(udata->hdr, udata->parent))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block page") -/* Set the extensible array data block page's information */ -dblk_page->addr = udata->dblk_page_addr; + /* Set the extensible array data block page's information */ + dblk_page->addr = udata->dblk_page_addr; -/* Internal information */ + /* Internal information */ -/* Decode elements in data block page */ -/* Convert from raw elements on disk into native elements in memory */ -if ((udata->hdr->cparam.cls->decode)(image, dblk_page->elmts, udata->hdr->dblk_page_nelmts, - udata->hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTDECODE, "can't decode extensible array data elements") -image += (udata->hdr->dblk_page_nelmts * udata->hdr->cparam.raw_elmt_size); + /* Decode elements in data block page */ + /* Convert from raw elements on disk into native elements in memory */ + if ((udata->hdr->cparam.cls->decode)(image, dblk_page->elmts, udata->hdr->dblk_page_nelmts, + udata->hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTDECODE, "can't decode extensible array data elements") + image += (udata->hdr->dblk_page_nelmts * udata->hdr->cparam.raw_elmt_size); -/* Sanity check */ -/* (allow for checksum not decoded yet) */ -HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5EA_SIZEOF_CHKSUM)); + /* Sanity check */ + /* (allow for checksum not decoded yet) */ + HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5EA_SIZEOF_CHKSUM)); -/* Set the data block page's size */ -dblk_page->size = len; + /* Set the data block page's size */ + dblk_page->size = len; -/* checksum verification already done in verify_chksum cb */ + /* checksum verification already done in verify_chksum cb */ -/* Metadata checksum */ -UINT32DECODE(image, stored_chksum); + /* Metadata checksum */ + UINT32DECODE(image, stored_chksum); -/* Sanity check */ -HDassert((size_t)(image - (const uint8_t *)_image) == dblk_page->size); + /* Sanity check */ + HDassert((size_t)(image - (const uint8_t *)_image) == dblk_page->size); -/* Set return value */ -ret_value = dblk_page; + /* Set return value */ + ret_value = dblk_page; -CATCH + CATCH -/* Release resources */ -if (!ret_value) - if (dblk_page && H5EA__dblk_page_dest(dblk_page) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block page") + /* Release resources */ + if (!ret_value) + if (dblk_page && H5EA__dblk_page_dest(dblk_page) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block page") END_FUNC(STATIC) /* end H5EA__cache_dblk_page_deserialize() */ @@ -1977,15 +1978,15 @@ END_FUNC(STATIC) /* end H5EA__cache_dblk_page_deserialize() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__cache_dblk_page_image_len(const void *_thing, size_t *image_len)) -/* Local variables */ -const H5EA_dblk_page_t *dblk_page = (const H5EA_dblk_page_t *)_thing; /* Pointer to the object */ + /* Local variables */ + const H5EA_dblk_page_t *dblk_page = (const H5EA_dblk_page_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(dblk_page); -HDassert(image_len); + /* Check arguments */ + HDassert(dblk_page); + HDassert(image_len); -/* Set the image length size */ -*image_len = dblk_page->size; + /* Set the image length size */ + *image_len = dblk_page->size; END_FUNC(STATIC) /* end H5EA__cache_dblk_page_image_len() */ @@ -2005,37 +2006,37 @@ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_dblk_page_serialize(const H5F_t H5_ATTR_NDEBUG_UNUSED *f, void *_image, size_t H5_ATTR_UNUSED len, void *_thing)) -/* Local variables */ -H5EA_dblk_page_t *dblk_page = (H5EA_dblk_page_t *)_thing; /* Pointer to the object to serialize */ -uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t metadata_chksum; /* Computed metadata checksum value */ + /* Local variables */ + H5EA_dblk_page_t *dblk_page = (H5EA_dblk_page_t *)_thing; /* Pointer to the object to serialize */ + uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t metadata_chksum; /* Computed metadata checksum value */ -/* Check arguments */ -HDassert(f); -HDassert(image); -HDassert(dblk_page); -HDassert(dblk_page->hdr); + /* Check arguments */ + HDassert(f); + HDassert(image); + HDassert(dblk_page); + HDassert(dblk_page->hdr); -/* Internal information */ + /* Internal information */ -/* Encode elements in data block page */ + /* Encode elements in data block page */ -/* Convert from native elements in memory into raw elements on disk */ -if ((dblk_page->hdr->cparam.cls->encode)(image, dblk_page->elmts, dblk_page->hdr->dblk_page_nelmts, - dblk_page->hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTENCODE, "can't encode extensible array data elements") -image += (dblk_page->hdr->dblk_page_nelmts * dblk_page->hdr->cparam.raw_elmt_size); + /* Convert from native elements in memory into raw elements on disk */ + if ((dblk_page->hdr->cparam.cls->encode)(image, dblk_page->elmts, dblk_page->hdr->dblk_page_nelmts, + dblk_page->hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTENCODE, "can't encode extensible array data elements") + image += (dblk_page->hdr->dblk_page_nelmts * dblk_page->hdr->cparam.raw_elmt_size); -/* Compute metadata checksum */ -metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); + /* Compute metadata checksum */ + metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); -/* Metadata checksum */ -UINT32ENCODE(image, metadata_chksum); + /* Metadata checksum */ + UINT32ENCODE(image, metadata_chksum); -/* Sanity check */ -HDassert((size_t)(image - (uint8_t *)_image) == len); + /* Sanity check */ + HDassert((size_t)(image - (uint8_t *)_image) == len); -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_dblk_page_serialize() */ @@ -2054,79 +2055,82 @@ END_FUNC(STATIC) /* end H5EA__cache_dblk_page_serialize() */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_dblk_page_notify(H5AC_notify_action_t action, void *_thing)) -/* Local variables */ -H5EA_dblk_page_t *dblk_page = (H5EA_dblk_page_t *)_thing; /* Pointer to the object */ - -/* Sanity check */ -HDassert(dblk_page); - -/* Determine which action to take */ -switch (action) { - case H5AC_NOTIFY_ACTION_AFTER_INSERT: - case H5AC_NOTIFY_ACTION_AFTER_LOAD: - /* Create flush dependency on parent */ - if (H5EA__create_flush_depend((H5AC_info_t *)dblk_page->parent, (H5AC_info_t *)dblk_page) < 0) - H5E_THROW(H5E_CANTDEPEND, - "unable to create flush dependency between data block page and parent, address = %llu", - (unsigned long long)dblk_page->addr) - break; - - case H5AC_NOTIFY_ACTION_AFTER_FLUSH: - /* Destroy flush dependency on extensible array header, if set */ - if (dblk_page->has_hdr_depend) { - if (H5EA__destroy_flush_depend((H5AC_info_t *)dblk_page->hdr, (H5AC_info_t *)dblk_page) < 0) + /* Local variables */ + H5EA_dblk_page_t *dblk_page = (H5EA_dblk_page_t *)_thing; /* Pointer to the object */ + + /* Sanity check */ + HDassert(dblk_page); + + /* Determine which action to take */ + switch (action) { + case H5AC_NOTIFY_ACTION_AFTER_INSERT: + case H5AC_NOTIFY_ACTION_AFTER_LOAD: + /* Create flush dependency on parent */ + if (H5EA__create_flush_depend((H5AC_info_t *)dblk_page->parent, (H5AC_info_t *)dblk_page) < 0) H5E_THROW( - H5E_CANTUNDEPEND, - "unable to destroy flush dependency between data block page and header, address = %llu", + H5E_CANTDEPEND, + "unable to create flush dependency between data block page and parent, address = %llu", (unsigned long long)dblk_page->addr) - dblk_page->has_hdr_depend = FALSE; - } /* end if */ - break; - - case H5AC_NOTIFY_ACTION_BEFORE_EVICT: - /* Destroy flush dependency on parent */ - if (H5EA__destroy_flush_depend((H5AC_info_t *)dblk_page->parent, (H5AC_info_t *)dblk_page) < 0) - H5E_THROW(H5E_CANTUNDEPEND, - "unable to destroy flush dependency between data block page and parent, address = %llu", - (unsigned long long)dblk_page->addr) - - /* Destroy flush dependency on extensible array header, if set */ - if (dblk_page->has_hdr_depend) { - if (H5EA__destroy_flush_depend((H5AC_info_t *)dblk_page->hdr, (H5AC_info_t *)dblk_page) < 0) + break; + + case H5AC_NOTIFY_ACTION_AFTER_FLUSH: + /* Destroy flush dependency on extensible array header, if set */ + if (dblk_page->has_hdr_depend) { + if (H5EA__destroy_flush_depend((H5AC_info_t *)dblk_page->hdr, (H5AC_info_t *)dblk_page) < 0) + H5E_THROW(H5E_CANTUNDEPEND, + "unable to destroy flush dependency between data block page and header, " + "address = %llu", + (unsigned long long)dblk_page->addr) + dblk_page->has_hdr_depend = FALSE; + } /* end if */ + break; + + case H5AC_NOTIFY_ACTION_BEFORE_EVICT: + /* Destroy flush dependency on parent */ + if (H5EA__destroy_flush_depend((H5AC_info_t *)dblk_page->parent, (H5AC_info_t *)dblk_page) < 0) H5E_THROW( H5E_CANTUNDEPEND, - "unable to destroy flush dependency between data block page and header, address = %llu", + "unable to destroy flush dependency between data block page and parent, address = %llu", (unsigned long long)dblk_page->addr) - dblk_page->has_hdr_depend = FALSE; - } /* end if */ - - /* Detach from 'top' proxy for extensible array */ - if (dblk_page->top_proxy) { - if (H5AC_proxy_entry_remove_child(dblk_page->top_proxy, dblk_page) < 0) - H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency between data block page and " - "extensible array 'top' proxy") - dblk_page->top_proxy = NULL; - } /* end if */ - break; - - case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: - case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: - case H5AC_NOTIFY_ACTION_CHILD_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: - case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: - /* do nothing */ - break; - - default: + + /* Destroy flush dependency on extensible array header, if set */ + if (dblk_page->has_hdr_depend) { + if (H5EA__destroy_flush_depend((H5AC_info_t *)dblk_page->hdr, (H5AC_info_t *)dblk_page) < 0) + H5E_THROW(H5E_CANTUNDEPEND, + "unable to destroy flush dependency between data block page and header, " + "address = %llu", + (unsigned long long)dblk_page->addr) + dblk_page->has_hdr_depend = FALSE; + } /* end if */ + + /* Detach from 'top' proxy for extensible array */ + if (dblk_page->top_proxy) { + if (H5AC_proxy_entry_remove_child(dblk_page->top_proxy, dblk_page) < 0) + H5E_THROW(H5E_CANTUNDEPEND, + "unable to destroy flush dependency between data block page and " + "extensible array 'top' proxy") + dblk_page->top_proxy = NULL; + } /* end if */ + break; + + case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: + case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: + case H5AC_NOTIFY_ACTION_CHILD_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: + case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: + /* do nothing */ + break; + + default: #ifdef NDEBUG - H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") + H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") #else /* NDEBUG */ - HDassert(0 && "Unknown action?!?"); + HDassert(0 && "Unknown action?!?"); #endif /* NDEBUG */ -} /* end switch */ + } /* end switch */ -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_dblk_page_notify() */ @@ -2145,13 +2149,13 @@ END_FUNC(STATIC) /* end H5EA__cache_dblk_page_notify() */ */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__cache_dblk_page_free_icr(void *thing)) -/* Check arguments */ -HDassert(thing); + /* Check arguments */ + HDassert(thing); -/* Release the extensible array data block page */ -if (H5EA__dblk_page_dest((H5EA_dblk_page_t *)thing) < 0) - H5E_THROW(H5E_CANTFREE, "can't free extensible array data block page") + /* Release the extensible array data block page */ + if (H5EA__dblk_page_dest((H5EA_dblk_page_t *)thing) < 0) + H5E_THROW(H5E_CANTFREE, "can't free extensible array data block page") -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__cache_dblk_page_free_icr() */ diff --git a/src/H5EAdbg.c b/src/H5EAdbg.c index a482eb0..2ff1e9a 100644 --- a/src/H5EAdbg.c +++ b/src/H5EAdbg.c @@ -83,64 +83,64 @@ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__hdr_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth, const H5EA_class_t *cls, haddr_t obj_addr)) -/* Local variables */ -H5EA_hdr_t *hdr = NULL; /* Shared extensible array header */ -void * dbg_ctx = NULL; /* Extensible array debugging context */ - -/* Check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); -HDassert(H5F_addr_defined(obj_addr)); -HDassert(stream); -HDassert(indent >= 0); -HDassert(fwidth >= 0); -HDassert(cls); - -/* Check for debugging context callback available */ -if (cls->crt_dbg_ctx) - /* Create debugging context */ - if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) - H5E_THROW(H5E_CANTGET, "unable to create fixed array debugging context") - -/* Load the extensible array header */ -if (NULL == (hdr = H5EA__hdr_protect(f, addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load extensible array header") - -/* Print opening message */ -HDfprintf(stream, "%*sExtensible Array Header...\n", indent, ""); - -/* Print the values */ -HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Header size:", hdr->size); -HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, - "Raw Element Size:", (unsigned)hdr->cparam.raw_elmt_size); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, - "Native Element Size (on this platform):", hdr->cparam.cls->nat_elmt_size); -HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, - "Log2(Max. # of elements in array):", (unsigned)hdr->cparam.max_nelmts_bits); -HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, - "# of elements in index block:", (unsigned)hdr->cparam.idx_blk_elmts); -HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, - "Min. # of elements per data block:", (unsigned)hdr->cparam.data_blk_min_elmts); -HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, - "Min. # of data block pointers for a super block:", (unsigned)hdr->cparam.sup_blk_min_data_ptrs); -HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, - "Log2(Max. # of elements in data block page):", (unsigned)hdr->cparam.max_dblk_page_nelmts_bits); -HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, - "Highest element index stored (+1):", hdr->stats.stored.max_idx_set); -HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, - "Number of super blocks created:", hdr->stats.stored.nsuper_blks); -HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, - "Number of data blocks created:", hdr->stats.stored.ndata_blks); -HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, - "Number of elements 'realized':", hdr->stats.stored.nelmts); -HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Index Block Address:", hdr->idx_blk_addr); - -CATCH -if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to release extensible array debugging context") -if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") + /* Local variables */ + H5EA_hdr_t *hdr = NULL; /* Shared extensible array header */ + void * dbg_ctx = NULL; /* Extensible array debugging context */ + + /* Check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + HDassert(H5F_addr_defined(obj_addr)); + HDassert(stream); + HDassert(indent >= 0); + HDassert(fwidth >= 0); + HDassert(cls); + + /* Check for debugging context callback available */ + if (cls->crt_dbg_ctx) + /* Create debugging context */ + if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) + H5E_THROW(H5E_CANTGET, "unable to create fixed array debugging context") + + /* Load the extensible array header */ + if (NULL == (hdr = H5EA__hdr_protect(f, addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load extensible array header") + + /* Print opening message */ + HDfprintf(stream, "%*sExtensible Array Header...\n", indent, ""); + + /* Print the values */ + HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Header size:", hdr->size); + HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, + "Raw Element Size:", (unsigned)hdr->cparam.raw_elmt_size); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, + "Native Element Size (on this platform):", hdr->cparam.cls->nat_elmt_size); + HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, + "Log2(Max. # of elements in array):", (unsigned)hdr->cparam.max_nelmts_bits); + HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, + "# of elements in index block:", (unsigned)hdr->cparam.idx_blk_elmts); + HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, + "Min. # of elements per data block:", (unsigned)hdr->cparam.data_blk_min_elmts); + HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Min. # of data block pointers for a super block:", + (unsigned)hdr->cparam.sup_blk_min_data_ptrs); + HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Log2(Max. # of elements in data block page):", + (unsigned)hdr->cparam.max_dblk_page_nelmts_bits); + HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, + "Highest element index stored (+1):", hdr->stats.stored.max_idx_set); + HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, + "Number of super blocks created:", hdr->stats.stored.nsuper_blks); + HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, + "Number of data blocks created:", hdr->stats.stored.ndata_blks); + HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, + "Number of elements 'realized':", hdr->stats.stored.nelmts); + HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Index Block Address:", hdr->idx_blk_addr); + + CATCH + if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to release extensible array debugging context") + if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") END_FUNC(PKG) /* end H5EA__hdr_debug() */ @@ -160,101 +160,102 @@ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__iblock_debug(H5F_t *f, haddr_t H5_ATTR_UNUSED addr, FILE *stream, int indent, int fwidth, const H5EA_class_t *cls, haddr_t hdr_addr, haddr_t obj_addr)) -/* Local variables */ -H5EA_hdr_t * hdr = NULL; /* Shared extensible array header */ -H5EA_iblock_t *iblock = NULL; /* Extensible array index block */ -void * dbg_ctx = NULL; /* Extensible array context */ - -/* Check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); -HDassert(stream); -HDassert(indent >= 0); -HDassert(fwidth >= 0); -HDassert(cls); -HDassert(H5F_addr_defined(hdr_addr)); -HDassert(H5F_addr_defined(obj_addr)); - -/* Check for debugging context callback available */ -if (cls->crt_dbg_ctx) - /* Create debugging context */ - if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) - H5E_THROW(H5E_CANTGET, "unable to create extensible array debugging context") - -/* Load the extensible array header */ -if (NULL == (hdr = H5EA__hdr_protect(f, hdr_addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load extensible array header") - -/* Sanity check */ -HDassert(H5F_addr_eq(hdr->idx_blk_addr, addr)); - -/* Protect index block */ -if (NULL == (iblock = H5EA__iblock_protect(hdr, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array index block, address = %llu", - (unsigned long long)hdr->idx_blk_addr) - -/* Print opening message */ -HDfprintf(stream, "%*sExtensible Array Index Block...\n", indent, ""); - -/* Print the values */ -HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Index Block size:", iblock->size); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, - "# of data block addresses in index block:", iblock->ndblk_addrs); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, - "# of super block addresses in index block:", iblock->nsblk_addrs); - -/* Check if there are any elements in index block */ -if (hdr->cparam.idx_blk_elmts > 0) { - unsigned u; /* Local index variable */ - - /* Print the elements in the index block */ - HDfprintf(stream, "%*sElements in Index Block:\n", indent, ""); - for (u = 0; u < hdr->cparam.idx_blk_elmts; u++) { - /* Call the class's 'debug' callback */ - if ((hdr->cparam.cls->debug)(stream, (indent + 3), MAX(0, (fwidth - 3)), (hsize_t)u, - ((uint8_t *)iblock->elmts) + (hdr->cparam.cls->nat_elmt_size * u)) < 0) - H5E_THROW(H5E_CANTGET, "can't get element for debugging") - } /* end for */ -} /* end if */ - -/* Check if there are any data block addresses in index block */ -if (iblock->ndblk_addrs > 0) { - char temp_str[128]; /* Temporary string, for formatting */ - unsigned u; /* Local index variable */ - - /* Print the data block addresses in the index block */ - HDfprintf(stream, "%*sData Block Addresses in Index Block:\n", indent, ""); - for (u = 0; u < iblock->ndblk_addrs; u++) { - /* Print address */ - HDsprintf(temp_str, "Address #%u:", u); - HDfprintf(stream, "%*s%-*s %a\n", (indent + 3), "", MAX(0, (fwidth - 3)), temp_str, - iblock->dblk_addrs[u]); - } /* end for */ -} /* end if */ - -/* Check if there are any super block addresses in index block */ -if (iblock->nsblk_addrs > 0) { - char temp_str[128]; /* Temporary string, for formatting */ - unsigned u; /* Local index variable */ - - /* Print the super block addresses in the index block */ - HDfprintf(stream, "%*sSuper Block Addresses in Index Block:\n", indent, ""); - for (u = 0; u < iblock->nsblk_addrs; u++) { - /* Print address */ - HDsprintf(temp_str, "Address #%u:", u); - HDfprintf(stream, "%*s%-*s %a\n", (indent + 3), "", MAX(0, (fwidth - 3)), temp_str, - iblock->sblk_addrs[u]); - } /* end for */ -} /* end if */ - -CATCH -if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to release extensible array debugging context") -if (iblock && H5EA__iblock_unprotect(iblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array index block") -if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") + /* Local variables */ + H5EA_hdr_t * hdr = NULL; /* Shared extensible array header */ + H5EA_iblock_t *iblock = NULL; /* Extensible array index block */ + void * dbg_ctx = NULL; /* Extensible array context */ + + /* Check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + HDassert(stream); + HDassert(indent >= 0); + HDassert(fwidth >= 0); + HDassert(cls); + HDassert(H5F_addr_defined(hdr_addr)); + HDassert(H5F_addr_defined(obj_addr)); + + /* Check for debugging context callback available */ + if (cls->crt_dbg_ctx) + /* Create debugging context */ + if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) + H5E_THROW(H5E_CANTGET, "unable to create extensible array debugging context") + + /* Load the extensible array header */ + if (NULL == (hdr = H5EA__hdr_protect(f, hdr_addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load extensible array header") + + /* Sanity check */ + HDassert(H5F_addr_eq(hdr->idx_blk_addr, addr)); + + /* Protect index block */ + if (NULL == (iblock = H5EA__iblock_protect(hdr, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array index block, address = %llu", + (unsigned long long)hdr->idx_blk_addr) + + /* Print opening message */ + HDfprintf(stream, "%*sExtensible Array Index Block...\n", indent, ""); + + /* Print the values */ + HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Index Block size:", iblock->size); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, + "# of data block addresses in index block:", iblock->ndblk_addrs); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, + "# of super block addresses in index block:", iblock->nsblk_addrs); + + /* Check if there are any elements in index block */ + if (hdr->cparam.idx_blk_elmts > 0) { + unsigned u; /* Local index variable */ + + /* Print the elements in the index block */ + HDfprintf(stream, "%*sElements in Index Block:\n", indent, ""); + for (u = 0; u < hdr->cparam.idx_blk_elmts; u++) { + /* Call the class's 'debug' callback */ + if ((hdr->cparam.cls->debug)(stream, (indent + 3), MAX(0, (fwidth - 3)), (hsize_t)u, + ((uint8_t *)iblock->elmts) + (hdr->cparam.cls->nat_elmt_size * u)) < + 0) + H5E_THROW(H5E_CANTGET, "can't get element for debugging") + } /* end for */ + } /* end if */ + + /* Check if there are any data block addresses in index block */ + if (iblock->ndblk_addrs > 0) { + char temp_str[128]; /* Temporary string, for formatting */ + unsigned u; /* Local index variable */ + + /* Print the data block addresses in the index block */ + HDfprintf(stream, "%*sData Block Addresses in Index Block:\n", indent, ""); + for (u = 0; u < iblock->ndblk_addrs; u++) { + /* Print address */ + HDsprintf(temp_str, "Address #%u:", u); + HDfprintf(stream, "%*s%-*s %a\n", (indent + 3), "", MAX(0, (fwidth - 3)), temp_str, + iblock->dblk_addrs[u]); + } /* end for */ + } /* end if */ + + /* Check if there are any super block addresses in index block */ + if (iblock->nsblk_addrs > 0) { + char temp_str[128]; /* Temporary string, for formatting */ + unsigned u; /* Local index variable */ + + /* Print the super block addresses in the index block */ + HDfprintf(stream, "%*sSuper Block Addresses in Index Block:\n", indent, ""); + for (u = 0; u < iblock->nsblk_addrs; u++) { + /* Print address */ + HDsprintf(temp_str, "Address #%u:", u); + HDfprintf(stream, "%*s%-*s %a\n", (indent + 3), "", MAX(0, (fwidth - 3)), temp_str, + iblock->sblk_addrs[u]); + } /* end for */ + } /* end if */ + + CATCH + if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to release extensible array debugging context") + if (iblock && H5EA__iblock_unprotect(iblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array index block") + if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") END_FUNC(PKG) /* end H5EA__iblock_debug() */ @@ -274,70 +275,71 @@ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__sblock_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth, const H5EA_class_t *cls, haddr_t hdr_addr, unsigned sblk_idx, haddr_t obj_addr)) -/* Local variables */ -H5EA_hdr_t * hdr = NULL; /* Shared extensible array header */ -H5EA_sblock_t *sblock = NULL; /* Extensible array super block */ -void * dbg_ctx = NULL; /* Extensible array context */ - -/* Check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); -HDassert(stream); -HDassert(indent >= 0); -HDassert(fwidth >= 0); -HDassert(cls); -HDassert(H5F_addr_defined(hdr_addr)); -HDassert(H5F_addr_defined(obj_addr)); - -/* Check for debugging context callback available */ -if (cls->crt_dbg_ctx) - /* Create debugging context */ - if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) - H5E_THROW(H5E_CANTGET, "unable to create extensible array debugging context") - -/* Load the extensible array header */ -if (NULL == (hdr = H5EA__hdr_protect(f, hdr_addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load extensible array header") - -/* Protect super block */ -/* (Note: setting parent of super block to 'hdr' for this operation should be OK -QAK) */ -if (NULL == (sblock = H5EA__sblock_protect(hdr, (H5EA_iblock_t *)hdr, addr, sblk_idx, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array super block, address = %llu", - (unsigned long long)addr) - -/* Print opening message */ -HDfprintf(stream, "%*sExtensible Array Super Block...\n", indent, ""); - -/* Print the values */ -HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Super Block size:", sblock->size); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, - "# of data block addresses in super block:", sblock->ndblks); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, - "# of elements in data blocks from this super block:", sblock->dblk_nelmts); - -/* Check if there are any data block addresses in super block */ -if (sblock->ndblks > 0) { - char temp_str[128]; /* Temporary string, for formatting */ - unsigned u; /* Local index variable */ - - /* Print the data block addresses in the super block */ - HDfprintf(stream, "%*sData Block Addresses in Super Block:\n", indent, ""); - for (u = 0; u < sblock->ndblks; u++) { - /* Print address */ - HDsprintf(temp_str, "Address #%u:", u); - HDfprintf(stream, "%*s%-*s %a\n", (indent + 3), "", MAX(0, (fwidth - 3)), temp_str, - sblock->dblk_addrs[u]); - } /* end for */ -} /* end if */ - -CATCH -if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to release extensible array debugging context") -if (sblock && H5EA__sblock_unprotect(sblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array super block") -if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") + /* Local variables */ + H5EA_hdr_t * hdr = NULL; /* Shared extensible array header */ + H5EA_sblock_t *sblock = NULL; /* Extensible array super block */ + void * dbg_ctx = NULL; /* Extensible array context */ + + /* Check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + HDassert(stream); + HDassert(indent >= 0); + HDassert(fwidth >= 0); + HDassert(cls); + HDassert(H5F_addr_defined(hdr_addr)); + HDassert(H5F_addr_defined(obj_addr)); + + /* Check for debugging context callback available */ + if (cls->crt_dbg_ctx) + /* Create debugging context */ + if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) + H5E_THROW(H5E_CANTGET, "unable to create extensible array debugging context") + + /* Load the extensible array header */ + if (NULL == (hdr = H5EA__hdr_protect(f, hdr_addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load extensible array header") + + /* Protect super block */ + /* (Note: setting parent of super block to 'hdr' for this operation should be OK -QAK) */ + if (NULL == + (sblock = H5EA__sblock_protect(hdr, (H5EA_iblock_t *)hdr, addr, sblk_idx, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array super block, address = %llu", + (unsigned long long)addr) + + /* Print opening message */ + HDfprintf(stream, "%*sExtensible Array Super Block...\n", indent, ""); + + /* Print the values */ + HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Super Block size:", sblock->size); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, + "# of data block addresses in super block:", sblock->ndblks); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, + "# of elements in data blocks from this super block:", sblock->dblk_nelmts); + + /* Check if there are any data block addresses in super block */ + if (sblock->ndblks > 0) { + char temp_str[128]; /* Temporary string, for formatting */ + unsigned u; /* Local index variable */ + + /* Print the data block addresses in the super block */ + HDfprintf(stream, "%*sData Block Addresses in Super Block:\n", indent, ""); + for (u = 0; u < sblock->ndblks; u++) { + /* Print address */ + HDsprintf(temp_str, "Address #%u:", u); + HDfprintf(stream, "%*s%-*s %a\n", (indent + 3), "", MAX(0, (fwidth - 3)), temp_str, + sblock->dblk_addrs[u]); + } /* end for */ + } /* end if */ + + CATCH + if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to release extensible array debugging context") + if (sblock && H5EA__sblock_unprotect(sblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array super block") + if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") END_FUNC(PKG) /* end H5EA__sblock_debug() */ @@ -358,61 +360,61 @@ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, const H5EA_class_t *cls, haddr_t hdr_addr, size_t dblk_nelmts, haddr_t obj_addr)) -/* Local variables */ -H5EA_hdr_t * hdr = NULL; /* Shared extensible array header */ -H5EA_dblock_t *dblock = NULL; /* Extensible array data block */ -void * dbg_ctx = NULL; /* Extensible array context */ -size_t u; /* Local index variable */ - -/* Check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); -HDassert(stream); -HDassert(indent >= 0); -HDassert(fwidth >= 0); -HDassert(cls); -HDassert(H5F_addr_defined(hdr_addr)); -HDassert(H5F_addr_defined(obj_addr)); -HDassert(dblk_nelmts > 0); - -/* Check for debugging context callback available */ -if (cls->crt_dbg_ctx) - /* Create debugging context */ - if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) - H5E_THROW(H5E_CANTGET, "unable to create extensible array debugging context") - -/* Load the extensible array header */ -if (NULL == (hdr = H5EA__hdr_protect(f, hdr_addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load extensible array header") - -/* Protect data block */ -/* (Note: setting parent of data block to 'hdr' for this operation should be OK -QAK) */ -if (NULL == (dblock = H5EA__dblock_protect(hdr, hdr, addr, dblk_nelmts, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block, address = %llu", - (unsigned long long)addr) - -/* Print opening message */ -HDfprintf(stream, "%*sExtensible Array data Block...\n", indent, ""); - -/* Print the values */ -HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Data Block size:", dblock->size); - -/* Print the elements in the index block */ -HDfprintf(stream, "%*sElements:\n", indent, ""); -for (u = 0; u < dblk_nelmts; u++) { - /* Call the class's 'debug' callback */ - if ((hdr->cparam.cls->debug)(stream, (indent + 3), MAX(0, (fwidth - 3)), (hsize_t)u, - ((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * u)) < 0) - H5E_THROW(H5E_CANTGET, "can't get element for debugging") -} /* end for */ - -CATCH -if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to release extensible array debugging context") -if (dblock && H5EA__dblock_unprotect(dblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array data block") -if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") + /* Local variables */ + H5EA_hdr_t * hdr = NULL; /* Shared extensible array header */ + H5EA_dblock_t *dblock = NULL; /* Extensible array data block */ + void * dbg_ctx = NULL; /* Extensible array context */ + size_t u; /* Local index variable */ + + /* Check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + HDassert(stream); + HDassert(indent >= 0); + HDassert(fwidth >= 0); + HDassert(cls); + HDassert(H5F_addr_defined(hdr_addr)); + HDassert(H5F_addr_defined(obj_addr)); + HDassert(dblk_nelmts > 0); + + /* Check for debugging context callback available */ + if (cls->crt_dbg_ctx) + /* Create debugging context */ + if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) + H5E_THROW(H5E_CANTGET, "unable to create extensible array debugging context") + + /* Load the extensible array header */ + if (NULL == (hdr = H5EA__hdr_protect(f, hdr_addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load extensible array header") + + /* Protect data block */ + /* (Note: setting parent of data block to 'hdr' for this operation should be OK -QAK) */ + if (NULL == (dblock = H5EA__dblock_protect(hdr, hdr, addr, dblk_nelmts, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block, address = %llu", + (unsigned long long)addr) + + /* Print opening message */ + HDfprintf(stream, "%*sExtensible Array data Block...\n", indent, ""); + + /* Print the values */ + HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Data Block size:", dblock->size); + + /* Print the elements in the index block */ + HDfprintf(stream, "%*sElements:\n", indent, ""); + for (u = 0; u < dblk_nelmts; u++) { + /* Call the class's 'debug' callback */ + if ((hdr->cparam.cls->debug)(stream, (indent + 3), MAX(0, (fwidth - 3)), (hsize_t)u, + ((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * u)) < 0) + H5E_THROW(H5E_CANTGET, "can't get element for debugging") + } /* end for */ + + CATCH + if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to release extensible array debugging context") + if (dblock && H5EA__dblock_unprotect(dblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array data block") + if (hdr && H5EA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") END_FUNC(PKG) /* end H5EA__dblock_debug() */ diff --git a/src/H5EAdblkpage.c b/src/H5EAdblkpage.c index 43b59d6..f8ea0ed 100644 --- a/src/H5EAdblkpage.c +++ b/src/H5EAdblkpage.c @@ -87,35 +87,35 @@ H5FL_DEFINE_STATIC(H5EA_dblk_page_t); BEGIN_FUNC(PKG, ERR, H5EA_dblk_page_t *, NULL, NULL, H5EA__dblk_page_alloc(H5EA_hdr_t *hdr, H5EA_sblock_t *parent)) -/* Local variables */ -H5EA_dblk_page_t *dblk_page = NULL; /* Extensible array data block page */ + /* Local variables */ + H5EA_dblk_page_t *dblk_page = NULL; /* Extensible array data block page */ -/* Check arguments */ -HDassert(hdr); + /* Check arguments */ + HDassert(hdr); -/* Allocate memory for the data block */ -if (NULL == (dblk_page = H5FL_CALLOC(H5EA_dblk_page_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block page") + /* Allocate memory for the data block */ + if (NULL == (dblk_page = H5FL_CALLOC(H5EA_dblk_page_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block page") -/* Share common array information */ -if (H5EA__hdr_incr(hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") -dblk_page->hdr = hdr; + /* Share common array information */ + if (H5EA__hdr_incr(hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") + dblk_page->hdr = hdr; -/* Set non-zero internal fields */ -dblk_page->parent = parent; + /* Set non-zero internal fields */ + dblk_page->parent = parent; -/* Allocate buffer for elements in data block page */ -if (NULL == (dblk_page->elmts = H5EA__hdr_alloc_elmts(hdr, hdr->dblk_page_nelmts))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block page element buffer") + /* Allocate buffer for elements in data block page */ + if (NULL == (dblk_page->elmts = H5EA__hdr_alloc_elmts(hdr, hdr->dblk_page_nelmts))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block page element buffer") -/* Set the return value */ -ret_value = dblk_page; + /* Set the return value */ + ret_value = dblk_page; -CATCH -if (!ret_value) - if (dblk_page && H5EA__dblk_page_dest(dblk_page) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block page") + CATCH + if (!ret_value) + if (dblk_page && H5EA__dblk_page_dest(dblk_page) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block page") END_FUNC(PKG) /* end H5EA__dblk_page_alloc() */ @@ -134,50 +134,50 @@ END_FUNC(PKG) /* end H5EA__dblk_page_alloc() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__dblk_page_create(H5EA_hdr_t *hdr, H5EA_sblock_t *parent, haddr_t addr)) -/* Local variables */ -H5EA_dblk_page_t *dblk_page = NULL; /* Extensible array data block page */ -hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ - -/* Sanity check */ -HDassert(hdr); - -/* Allocate the data block page */ -if (NULL == (dblk_page = H5EA__dblk_page_alloc(hdr, parent))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block page") - -/* Set info about data block page on disk */ -dblk_page->addr = addr; -dblk_page->size = H5EA_DBLK_PAGE_SIZE(hdr); - -/* Clear any elements in data block page to fill value */ -if ((hdr->cparam.cls->fill)(dblk_page->elmts, (size_t)hdr->dblk_page_nelmts) < 0) - H5E_THROW(H5E_CANTSET, "can't set extensible array data block page elements to class's fill value") - -/* Cache the new extensible array data block page */ -if (H5AC_insert_entry(hdr->f, H5AC_EARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTINSERT, "can't add extensible array data block page to cache") -inserted = TRUE; - -/* Add data block page as child of 'top' proxy */ -if (hdr->top_proxy) { - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblk_page) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") - dblk_page->top_proxy = hdr->top_proxy; -} /* end if */ - -CATCH -if (ret_value < 0) - if (dblk_page) { - /* Remove from cache, if inserted */ - if (inserted) - if (H5AC_remove_entry(dblk_page) < 0) - H5E_THROW(H5E_CANTREMOVE, "unable to remove extensible array data block page from cache") - - /* Destroy data block page */ - if (H5EA__dblk_page_dest(dblk_page) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block page") + /* Local variables */ + H5EA_dblk_page_t *dblk_page = NULL; /* Extensible array data block page */ + hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ + + /* Sanity check */ + HDassert(hdr); + + /* Allocate the data block page */ + if (NULL == (dblk_page = H5EA__dblk_page_alloc(hdr, parent))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block page") + + /* Set info about data block page on disk */ + dblk_page->addr = addr; + dblk_page->size = H5EA_DBLK_PAGE_SIZE(hdr); + + /* Clear any elements in data block page to fill value */ + if ((hdr->cparam.cls->fill)(dblk_page->elmts, (size_t)hdr->dblk_page_nelmts) < 0) + H5E_THROW(H5E_CANTSET, "can't set extensible array data block page elements to class's fill value") + + /* Cache the new extensible array data block page */ + if (H5AC_insert_entry(hdr->f, H5AC_EARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTINSERT, "can't add extensible array data block page to cache") + inserted = TRUE; + + /* Add data block page as child of 'top' proxy */ + if (hdr->top_proxy) { + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblk_page) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") + dblk_page->top_proxy = hdr->top_proxy; } /* end if */ + CATCH + if (ret_value < 0) + if (dblk_page) { + /* Remove from cache, if inserted */ + if (inserted) + if (H5AC_remove_entry(dblk_page) < 0) + H5E_THROW(H5E_CANTREMOVE, "unable to remove extensible array data block page from cache") + + /* Destroy data block page */ + if (H5EA__dblk_page_dest(dblk_page) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block page") + } /* end if */ + END_FUNC(PKG) /* end H5EA__dblk_page_create() */ /*------------------------------------------------------------------------- @@ -197,48 +197,49 @@ BEGIN_FUNC(PKG, ERR, H5EA_dblk_page_t *, NULL, NULL, H5EA__dblk_page_protect(H5EA_hdr_t *hdr, H5EA_sblock_t *parent, haddr_t dblk_page_addr, unsigned flags)) -/* Local variables */ -H5EA_dblk_page_t * dblk_page = NULL; /* Extensible array data block page */ -H5EA_dblk_page_cache_ud_t udata; /* Information needed for loading data block page */ - -/* Sanity check */ -HDassert(hdr); -HDassert(H5F_addr_defined(dblk_page_addr)); - -/* only the H5AC__READ_ONLY_FLAG may be set */ -HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); - -/* Set up user data */ -udata.hdr = hdr; -udata.parent = parent; -udata.dblk_page_addr = dblk_page_addr; - -/* Protect the data block page */ -if (NULL == (dblk_page = (H5EA_dblk_page_t *)H5AC_protect(hdr->f, H5AC_EARRAY_DBLK_PAGE, dblk_page_addr, - &udata, flags))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block page, address = %llu", - (unsigned long long)dblk_page_addr) + /* Local variables */ + H5EA_dblk_page_t * dblk_page = NULL; /* Extensible array data block page */ + H5EA_dblk_page_cache_ud_t udata; /* Information needed for loading data block page */ + + /* Sanity check */ + HDassert(hdr); + HDassert(H5F_addr_defined(dblk_page_addr)); + + /* only the H5AC__READ_ONLY_FLAG may be set */ + HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); + + /* Set up user data */ + udata.hdr = hdr; + udata.parent = parent; + udata.dblk_page_addr = dblk_page_addr; + + /* Protect the data block page */ + if (NULL == (dblk_page = (H5EA_dblk_page_t *)H5AC_protect(hdr->f, H5AC_EARRAY_DBLK_PAGE, dblk_page_addr, + &udata, flags))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block page, address = %llu", + (unsigned long long)dblk_page_addr) + + /* Create top proxy, if it doesn't exist */ + if (hdr->top_proxy && NULL == dblk_page->top_proxy) { + /* Add data block page as child of 'top' proxy */ + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblk_page) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") + dblk_page->top_proxy = hdr->top_proxy; + } /* end if */ -/* Create top proxy, if it doesn't exist */ -if (hdr->top_proxy && NULL == dblk_page->top_proxy) { - /* Add data block page as child of 'top' proxy */ - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblk_page) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") - dblk_page->top_proxy = hdr->top_proxy; -} /* end if */ - -/* Set return value */ -ret_value = dblk_page; - -CATCH -/* Clean up on error */ -if (!ret_value) { - /* Release the data block page, if it was protected */ - if (dblk_page && - H5AC_unprotect(hdr->f, H5AC_EARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array data block page, address = %llu", - (unsigned long long)dblk_page->addr) -} /* end if */ + /* Set return value */ + ret_value = dblk_page; + + CATCH + /* Clean up on error */ + if (!ret_value) { + /* Release the data block page, if it was protected */ + if (dblk_page && + H5AC_unprotect(hdr->f, H5AC_EARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, + "unable to unprotect extensible array data block page, address = %llu", + (unsigned long long)dblk_page->addr) + } /* end if */ END_FUNC(PKG) /* end H5EA__dblk_page_protect() */ @@ -258,17 +259,17 @@ END_FUNC(PKG) /* end H5EA__dblk_page_protect() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__dblk_page_unprotect(H5EA_dblk_page_t *dblk_page, unsigned cache_flags)) -/* Local variables */ + /* Local variables */ -/* Sanity check */ -HDassert(dblk_page); + /* Sanity check */ + HDassert(dblk_page); -/* Unprotect the data block page */ -if (H5AC_unprotect(dblk_page->hdr->f, H5AC_EARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array data block page, address = %llu", - (unsigned long long)dblk_page->addr) + /* Unprotect the data block page */ + if (H5AC_unprotect(dblk_page->hdr->f, H5AC_EARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array data block page, address = %llu", + (unsigned long long)dblk_page->addr) -CATCH + CATCH END_FUNC(PKG) /* end H5EA__dblk_page_unprotect() */ @@ -286,32 +287,32 @@ END_FUNC(PKG) /* end H5EA__dblk_page_unprotect() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__dblk_page_dest(H5EA_dblk_page_t *dblk_page)) -/* Sanity check */ -HDassert(dblk_page); -HDassert(!dblk_page->has_hdr_depend); - -/* Check if header field has been initialized */ -if (dblk_page->hdr) { - /* Check if buffer for data block page elements has been initialized */ - if (dblk_page->elmts) { - /* Free buffer for data block page elements */ - if (H5EA__hdr_free_elmts(dblk_page->hdr, dblk_page->hdr->dblk_page_nelmts, dblk_page->elmts) < 0) - H5E_THROW(H5E_CANTFREE, "unable to free extensible array data block element buffer") - dblk_page->elmts = NULL; + /* Sanity check */ + HDassert(dblk_page); + HDassert(!dblk_page->has_hdr_depend); + + /* Check if header field has been initialized */ + if (dblk_page->hdr) { + /* Check if buffer for data block page elements has been initialized */ + if (dblk_page->elmts) { + /* Free buffer for data block page elements */ + if (H5EA__hdr_free_elmts(dblk_page->hdr, dblk_page->hdr->dblk_page_nelmts, dblk_page->elmts) < 0) + H5E_THROW(H5E_CANTFREE, "unable to free extensible array data block element buffer") + dblk_page->elmts = NULL; + } /* end if */ + + /* Decrement reference count on shared info */ + if (H5EA__hdr_decr(dblk_page->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + dblk_page->hdr = NULL; } /* end if */ - /* Decrement reference count on shared info */ - if (H5EA__hdr_decr(dblk_page->hdr) < 0) - H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") - dblk_page->hdr = NULL; -} /* end if */ - -/* Sanity check */ -HDassert(NULL == dblk_page->top_proxy); + /* Sanity check */ + HDassert(NULL == dblk_page->top_proxy); -/* Free the data block page itself */ -dblk_page = H5FL_FREE(H5EA_dblk_page_t, dblk_page); + /* Free the data block page itself */ + dblk_page = H5FL_FREE(H5EA_dblk_page_t, dblk_page); -CATCH + CATCH END_FUNC(PKG) /* end H5EA__dblk_page_dest() */ diff --git a/src/H5EAdblock.c b/src/H5EAdblock.c index 2897aba..ddc4036 100644 --- a/src/H5EAdblock.c +++ b/src/H5EAdblock.c @@ -88,46 +88,46 @@ H5FL_DEFINE_STATIC(H5EA_dblock_t); BEGIN_FUNC(PKG, ERR, H5EA_dblock_t *, NULL, NULL, H5EA__dblock_alloc(H5EA_hdr_t *hdr, void *parent, size_t nelmts)) -/* Local variables */ -H5EA_dblock_t *dblock = NULL; /* Extensible array data block */ - -/* Check arguments */ -HDassert(hdr); -HDassert(parent); -HDassert(nelmts > 0); - -/* Allocate memory for the data block */ -if (NULL == (dblock = H5FL_CALLOC(H5EA_dblock_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block") - -/* Share common array information */ -if (H5EA__hdr_incr(hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") -dblock->hdr = hdr; - -/* Set non-zero internal fields */ -dblock->parent = parent; -dblock->nelmts = nelmts; - -/* Check if the data block is not going to be paged */ -if (nelmts > hdr->dblk_page_nelmts) { - /* Set the # of pages in the direct block */ - dblock->npages = nelmts / hdr->dblk_page_nelmts; - HDassert(nelmts == (dblock->npages * hdr->dblk_page_nelmts)); -} /* end if */ -else { - /* Allocate buffer for elements in data block */ - if (NULL == (dblock->elmts = H5EA__hdr_alloc_elmts(hdr, nelmts))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block element buffer") -} /* end else */ - -/* Set the return value */ -ret_value = dblock; - -CATCH -if (!ret_value) - if (dblock && H5EA__dblock_dest(dblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block") + /* Local variables */ + H5EA_dblock_t *dblock = NULL; /* Extensible array data block */ + + /* Check arguments */ + HDassert(hdr); + HDassert(parent); + HDassert(nelmts > 0); + + /* Allocate memory for the data block */ + if (NULL == (dblock = H5FL_CALLOC(H5EA_dblock_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block") + + /* Share common array information */ + if (H5EA__hdr_incr(hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") + dblock->hdr = hdr; + + /* Set non-zero internal fields */ + dblock->parent = parent; + dblock->nelmts = nelmts; + + /* Check if the data block is not going to be paged */ + if (nelmts > hdr->dblk_page_nelmts) { + /* Set the # of pages in the direct block */ + dblock->npages = nelmts / hdr->dblk_page_nelmts; + HDassert(nelmts == (dblock->npages * hdr->dblk_page_nelmts)); + } /* end if */ + else { + /* Allocate buffer for elements in data block */ + if (NULL == (dblock->elmts = H5EA__hdr_alloc_elmts(hdr, nelmts))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block element buffer") + } /* end else */ + + /* Set the return value */ + ret_value = dblock; + + CATCH + if (!ret_value) + if (dblock && H5EA__dblock_dest(dblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block") END_FUNC(PKG) /* end H5EA__dblock_alloc() */ @@ -147,80 +147,80 @@ BEGIN_FUNC(PKG, ERR, haddr_t, HADDR_UNDEF, HADDR_UNDEF, H5EA__dblock_create(H5EA_hdr_t *hdr, void *parent, hbool_t *stats_changed, hsize_t dblk_off, size_t nelmts)) -/* Local variables */ -H5EA_dblock_t *dblock = NULL; /* Extensible array data block */ -haddr_t dblock_addr; /* Extensible array data block address */ -hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ - -/* Sanity check */ -HDassert(hdr); -HDassert(stats_changed); -HDassert(nelmts > 0); - -/* Allocate the data block */ -if (NULL == (dblock = H5EA__dblock_alloc(hdr, parent, nelmts))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block") - -/* Set size of data block on disk */ -dblock->size = H5EA_DBLOCK_SIZE(dblock); - -/* Set offset of block in array's address space */ -dblock->block_off = dblk_off; - -/* Allocate space for the data block on disk */ -if (HADDR_UNDEF == (dblock_addr = H5MF_alloc(hdr->f, H5FD_MEM_EARRAY_DBLOCK, (hsize_t)dblock->size))) - H5E_THROW(H5E_CANTALLOC, "file allocation failed for extensible array data block") -dblock->addr = dblock_addr; - -/* Don't initialize elements if paged */ -if (!dblock->npages) - /* Clear any elements in data block to fill value */ - if ((hdr->cparam.cls->fill)(dblock->elmts, (size_t)dblock->nelmts) < 0) - H5E_THROW(H5E_CANTSET, "can't set extensible array data block elements to class's fill value") - -/* Cache the new extensible array data block */ -if (H5AC_insert_entry(hdr->f, H5AC_EARRAY_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTINSERT, "can't add extensible array data block to cache") -inserted = TRUE; - -/* Add data block as child of 'top' proxy */ -if (hdr->top_proxy) { - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblock) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") - dblock->top_proxy = hdr->top_proxy; -} /* end if */ - -/* Update extensible array data block statistics */ -hdr->stats.stored.ndata_blks++; -hdr->stats.stored.data_blk_size += dblock->size; - -/* Increment count of elements "realized" */ -hdr->stats.stored.nelmts += nelmts; - -/* Mark the statistics as changed */ -*stats_changed = TRUE; - -/* Set address of data block to return */ -ret_value = dblock_addr; - -CATCH -if (!H5F_addr_defined(ret_value)) - if (dblock) { - /* Remove from cache, if inserted */ - if (inserted) - if (H5AC_remove_entry(dblock) < 0) - H5E_THROW(H5E_CANTREMOVE, "unable to remove extensible array data block from cache") - - /* Release data block's disk space */ - if (H5F_addr_defined(dblock->addr) && - H5MF_xfree(hdr->f, H5FD_MEM_EARRAY_DBLOCK, dblock->addr, (hsize_t)dblock->size) < 0) - H5E_THROW(H5E_CANTFREE, "unable to release extensible array data block") - - /* Destroy data block */ - if (H5EA__dblock_dest(dblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block") + /* Local variables */ + H5EA_dblock_t *dblock = NULL; /* Extensible array data block */ + haddr_t dblock_addr; /* Extensible array data block address */ + hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ + + /* Sanity check */ + HDassert(hdr); + HDassert(stats_changed); + HDassert(nelmts > 0); + + /* Allocate the data block */ + if (NULL == (dblock = H5EA__dblock_alloc(hdr, parent, nelmts))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array data block") + + /* Set size of data block on disk */ + dblock->size = H5EA_DBLOCK_SIZE(dblock); + + /* Set offset of block in array's address space */ + dblock->block_off = dblk_off; + + /* Allocate space for the data block on disk */ + if (HADDR_UNDEF == (dblock_addr = H5MF_alloc(hdr->f, H5FD_MEM_EARRAY_DBLOCK, (hsize_t)dblock->size))) + H5E_THROW(H5E_CANTALLOC, "file allocation failed for extensible array data block") + dblock->addr = dblock_addr; + + /* Don't initialize elements if paged */ + if (!dblock->npages) + /* Clear any elements in data block to fill value */ + if ((hdr->cparam.cls->fill)(dblock->elmts, (size_t)dblock->nelmts) < 0) + H5E_THROW(H5E_CANTSET, "can't set extensible array data block elements to class's fill value") + + /* Cache the new extensible array data block */ + if (H5AC_insert_entry(hdr->f, H5AC_EARRAY_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTINSERT, "can't add extensible array data block to cache") + inserted = TRUE; + + /* Add data block as child of 'top' proxy */ + if (hdr->top_proxy) { + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblock) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") + dblock->top_proxy = hdr->top_proxy; } /* end if */ + /* Update extensible array data block statistics */ + hdr->stats.stored.ndata_blks++; + hdr->stats.stored.data_blk_size += dblock->size; + + /* Increment count of elements "realized" */ + hdr->stats.stored.nelmts += nelmts; + + /* Mark the statistics as changed */ + *stats_changed = TRUE; + + /* Set address of data block to return */ + ret_value = dblock_addr; + + CATCH + if (!H5F_addr_defined(ret_value)) + if (dblock) { + /* Remove from cache, if inserted */ + if (inserted) + if (H5AC_remove_entry(dblock) < 0) + H5E_THROW(H5E_CANTREMOVE, "unable to remove extensible array data block from cache") + + /* Release data block's disk space */ + if (H5F_addr_defined(dblock->addr) && + H5MF_xfree(hdr->f, H5FD_MEM_EARRAY_DBLOCK, dblock->addr, (hsize_t)dblock->size) < 0) + H5E_THROW(H5E_CANTFREE, "unable to release extensible array data block") + + /* Destroy data block */ + if (H5EA__dblock_dest(dblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array data block") + } /* end if */ + END_FUNC(PKG) /* end H5EA__dblock_create() */ /*------------------------------------------------------------------------- @@ -238,22 +238,22 @@ END_FUNC(PKG) /* end H5EA__dblock_create() */ */ BEGIN_FUNC(PKG, NOERR, unsigned, 0, -, H5EA__dblock_sblk_idx(const H5EA_hdr_t *hdr, hsize_t idx)) -/* Local variables */ -unsigned sblk_idx; /* Which superblock does this index fall in? */ + /* Local variables */ + unsigned sblk_idx; /* Which superblock does this index fall in? */ -/* Sanity check */ -HDassert(hdr); -HDassert(idx >= hdr->cparam.idx_blk_elmts); + /* Sanity check */ + HDassert(hdr); + HDassert(idx >= hdr->cparam.idx_blk_elmts); -/* Adjust index for elements in index block */ -idx -= hdr->cparam.idx_blk_elmts; + /* Adjust index for elements in index block */ + idx -= hdr->cparam.idx_blk_elmts; -/* Determine the superblock information for the index */ -H5_CHECK_OVERFLOW(idx, /*From:*/ hsize_t, /*To:*/ uint64_t); -sblk_idx = H5VM_log2_gen((uint64_t)((idx / hdr->cparam.data_blk_min_elmts) + 1)); + /* Determine the superblock information for the index */ + H5_CHECK_OVERFLOW(idx, /*From:*/ hsize_t, /*To:*/ uint64_t); + sblk_idx = H5VM_log2_gen((uint64_t)((idx / hdr->cparam.data_blk_min_elmts) + 1)); -/* Set return value */ -ret_value = sblk_idx; + /* Set return value */ + ret_value = sblk_idx; END_FUNC(PKG) /* end H5EA__dblock_sblk_idx() */ @@ -273,49 +273,51 @@ BEGIN_FUNC(PKG, ERR, H5EA_dblock_t *, NULL, NULL, H5EA__dblock_protect(H5EA_hdr_t *hdr, void *parent, haddr_t dblk_addr, size_t dblk_nelmts, unsigned flags)) -/* Local variables */ -H5EA_dblock_t * dblock; /* Extensible array data block */ -H5EA_dblock_cache_ud_t udata; /* Information needed for loading data block */ - -/* Sanity check */ -HDassert(hdr); -HDassert(H5F_addr_defined(dblk_addr)); -HDassert(dblk_nelmts); - -/* only the H5AC__READ_ONLY_FLAG may be set */ -HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); - -/* Set up user data */ -udata.hdr = hdr; -udata.parent = parent; -udata.nelmts = dblk_nelmts; -udata.dblk_addr = dblk_addr; - -/* Protect the data block */ -if (NULL == (dblock = (H5EA_dblock_t *)H5AC_protect(hdr->f, H5AC_EARRAY_DBLOCK, dblk_addr, &udata, flags))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block, address = %llu", - (unsigned long long)dblk_addr) - -/* Create top proxy, if it doesn't exist */ -if (hdr->top_proxy && NULL == dblock->top_proxy) { - /* Add data block as child of 'top' proxy */ - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblock) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") - dblock->top_proxy = hdr->top_proxy; -} /* end if */ + /* Local variables */ + H5EA_dblock_t * dblock; /* Extensible array data block */ + H5EA_dblock_cache_ud_t udata; /* Information needed for loading data block */ + + /* Sanity check */ + HDassert(hdr); + HDassert(H5F_addr_defined(dblk_addr)); + HDassert(dblk_nelmts); + + /* only the H5AC__READ_ONLY_FLAG may be set */ + HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); + + /* Set up user data */ + udata.hdr = hdr; + udata.parent = parent; + udata.nelmts = dblk_nelmts; + udata.dblk_addr = dblk_addr; + + /* Protect the data block */ + if (NULL == + (dblock = (H5EA_dblock_t *)H5AC_protect(hdr->f, H5AC_EARRAY_DBLOCK, dblk_addr, &udata, flags))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block, address = %llu", + (unsigned long long)dblk_addr) + + /* Create top proxy, if it doesn't exist */ + if (hdr->top_proxy && NULL == dblock->top_proxy) { + /* Add data block as child of 'top' proxy */ + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblock) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") + dblock->top_proxy = hdr->top_proxy; + } /* end if */ -/* Set return value */ -ret_value = dblock; + /* Set return value */ + ret_value = dblock; -CATCH + CATCH -/* Clean up on error */ -if (!ret_value) { - /* Release the data block, if it was protected */ - if (dblock && H5AC_unprotect(hdr->f, H5AC_EARRAY_DBLOCK, dblock->addr, dblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array data block, address = %llu", - (unsigned long long)dblock->addr) -} /* end if */ + /* Clean up on error */ + if (!ret_value) { + /* Release the data block, if it was protected */ + if (dblock && + H5AC_unprotect(hdr->f, H5AC_EARRAY_DBLOCK, dblock->addr, dblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array data block, address = %llu", + (unsigned long long)dblock->addr) + } /* end if */ END_FUNC(PKG) /* end H5EA__dblock_protect() */ @@ -334,17 +336,17 @@ END_FUNC(PKG) /* end H5EA__dblock_protect() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__dblock_unprotect(H5EA_dblock_t *dblock, unsigned cache_flags)) -/* Local variables */ + /* Local variables */ -/* Sanity check */ -HDassert(dblock); + /* Sanity check */ + HDassert(dblock); -/* Unprotect the data block */ -if (H5AC_unprotect(dblock->hdr->f, H5AC_EARRAY_DBLOCK, dblock->addr, dblock, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array data block, address = %llu", - (unsigned long long)dblock->addr) + /* Unprotect the data block */ + if (H5AC_unprotect(dblock->hdr->f, H5AC_EARRAY_DBLOCK, dblock->addr, dblock, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array data block, address = %llu", + (unsigned long long)dblock->addr) -CATCH + CATCH END_FUNC(PKG) /* end H5EA__dblock_unprotect() */ @@ -363,48 +365,48 @@ END_FUNC(PKG) /* end H5EA__dblock_unprotect() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__dblock_delete(H5EA_hdr_t *hdr, void *parent, haddr_t dblk_addr, size_t dblk_nelmts)) -/* Local variables */ -H5EA_dblock_t *dblock = NULL; /* Pointer to data block */ - -/* Sanity check */ -HDassert(hdr); -HDassert(parent); -HDassert(H5F_addr_defined(dblk_addr)); -HDassert(dblk_nelmts > 0); - -/* Protect data block */ -if (NULL == (dblock = H5EA__dblock_protect(hdr, parent, dblk_addr, dblk_nelmts, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block, address = %llu", - (unsigned long long)dblk_addr) - -/* Check if this is a paged data block */ -if (dblk_nelmts > hdr->dblk_page_nelmts) { - size_t npages = dblk_nelmts / hdr->dblk_page_nelmts; /* Number of pages in data block */ - haddr_t dblk_page_addr; /* Address of each data block page */ - size_t dblk_page_size; /* Size of each data block page */ - size_t u; /* Local index variable */ - - /* Set up initial state */ - dblk_page_addr = dblk_addr + H5EA_DBLOCK_PREFIX_SIZE(dblock); - dblk_page_size = (hdr->dblk_page_nelmts * hdr->cparam.raw_elmt_size) + H5EA_SIZEOF_CHKSUM; - - /* Iterate over pages in data block */ - for (u = 0; u < npages; u++) { - /* Evict the data block page from the metadata cache */ - /* (OK to call if it doesn't exist in the cache) */ - if (H5AC_expunge_entry(hdr->f, H5AC_EARRAY_DBLK_PAGE, dblk_page_addr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTEXPUNGE, "unable to remove array data block page from metadata cache") - - /* Advance to next page address */ - dblk_page_addr += dblk_page_size; - } /* end for */ -} /* end if */ - -CATCH -/* Finished deleting data block in metadata cache */ -if (dblock && - H5EA__dblock_unprotect(dblock, H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array data block") + /* Local variables */ + H5EA_dblock_t *dblock = NULL; /* Pointer to data block */ + + /* Sanity check */ + HDassert(hdr); + HDassert(parent); + HDassert(H5F_addr_defined(dblk_addr)); + HDassert(dblk_nelmts > 0); + + /* Protect data block */ + if (NULL == (dblock = H5EA__dblock_protect(hdr, parent, dblk_addr, dblk_nelmts, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array data block, address = %llu", + (unsigned long long)dblk_addr) + + /* Check if this is a paged data block */ + if (dblk_nelmts > hdr->dblk_page_nelmts) { + size_t npages = dblk_nelmts / hdr->dblk_page_nelmts; /* Number of pages in data block */ + haddr_t dblk_page_addr; /* Address of each data block page */ + size_t dblk_page_size; /* Size of each data block page */ + size_t u; /* Local index variable */ + + /* Set up initial state */ + dblk_page_addr = dblk_addr + H5EA_DBLOCK_PREFIX_SIZE(dblock); + dblk_page_size = (hdr->dblk_page_nelmts * hdr->cparam.raw_elmt_size) + H5EA_SIZEOF_CHKSUM; + + /* Iterate over pages in data block */ + for (u = 0; u < npages; u++) { + /* Evict the data block page from the metadata cache */ + /* (OK to call if it doesn't exist in the cache) */ + if (H5AC_expunge_entry(hdr->f, H5AC_EARRAY_DBLK_PAGE, dblk_page_addr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTEXPUNGE, "unable to remove array data block page from metadata cache") + + /* Advance to next page address */ + dblk_page_addr += dblk_page_size; + } /* end for */ + } /* end if */ + + CATCH + /* Finished deleting data block in metadata cache */ + if (dblock && H5EA__dblock_unprotect(dblock, H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | + H5AC__FREE_FILE_SPACE_FLAG) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array data block") END_FUNC(PKG) /* end H5EA__dblock_delete() */ @@ -422,34 +424,34 @@ END_FUNC(PKG) /* end H5EA__dblock_delete() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__dblock_dest(H5EA_dblock_t *dblock)) -/* Sanity check */ -HDassert(dblock); -HDassert(!dblock->has_hdr_depend); - -/* Check if shared header field has been initialized */ -if (dblock->hdr) { - /* Check if we've got elements in the data block */ - if (dblock->elmts && !dblock->npages) { - /* Free buffer for data block elements */ - HDassert(dblock->nelmts > 0); - if (H5EA__hdr_free_elmts(dblock->hdr, dblock->nelmts, dblock->elmts) < 0) - H5E_THROW(H5E_CANTFREE, "unable to free extensible array data block element buffer") - dblock->elmts = NULL; - dblock->nelmts = 0; + /* Sanity check */ + HDassert(dblock); + HDassert(!dblock->has_hdr_depend); + + /* Check if shared header field has been initialized */ + if (dblock->hdr) { + /* Check if we've got elements in the data block */ + if (dblock->elmts && !dblock->npages) { + /* Free buffer for data block elements */ + HDassert(dblock->nelmts > 0); + if (H5EA__hdr_free_elmts(dblock->hdr, dblock->nelmts, dblock->elmts) < 0) + H5E_THROW(H5E_CANTFREE, "unable to free extensible array data block element buffer") + dblock->elmts = NULL; + dblock->nelmts = 0; + } /* end if */ + + /* Decrement reference count on shared info */ + if (H5EA__hdr_decr(dblock->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + dblock->hdr = NULL; } /* end if */ - /* Decrement reference count on shared info */ - if (H5EA__hdr_decr(dblock->hdr) < 0) - H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") - dblock->hdr = NULL; -} /* end if */ - -/* Sanity check */ -HDassert(NULL == dblock->top_proxy); + /* Sanity check */ + HDassert(NULL == dblock->top_proxy); -/* Free the data block itself */ -dblock = H5FL_FREE(H5EA_dblock_t, dblock); + /* Free the data block itself */ + dblock = H5FL_FREE(H5EA_dblock_t, dblock); -CATCH + CATCH END_FUNC(PKG) /* end H5EA__dblock_dest() */ diff --git a/src/H5EAhdr.c b/src/H5EAhdr.c index 1a7839f..236811f 100644 --- a/src/H5EAhdr.c +++ b/src/H5EAhdr.c @@ -104,32 +104,32 @@ H5FL_SEQ_DEFINE_STATIC(H5EA_sblk_info_t); */ BEGIN_FUNC(PKG, ERR, H5EA_hdr_t *, NULL, NULL, H5EA__hdr_alloc(H5F_t *f)) -/* Local variables */ -H5EA_hdr_t *hdr = NULL; /* Shared extensible array header */ + /* Local variables */ + H5EA_hdr_t *hdr = NULL; /* Shared extensible array header */ -/* Check arguments */ -HDassert(f); + /* Check arguments */ + HDassert(f); -/* Allocate space for the shared information */ -if (NULL == (hdr = H5FL_CALLOC(H5EA_hdr_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array shared header") + /* Allocate space for the shared information */ + if (NULL == (hdr = H5FL_CALLOC(H5EA_hdr_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array shared header") -/* Set non-zero internal fields */ -hdr->addr = HADDR_UNDEF; + /* Set non-zero internal fields */ + hdr->addr = HADDR_UNDEF; -/* Set the internal parameters for the array */ -hdr->f = f; -hdr->swmr_write = (H5F_INTENT(f) & H5F_ACC_SWMR_WRITE) > 0; -hdr->sizeof_addr = H5F_SIZEOF_ADDR(f); -hdr->sizeof_size = H5F_SIZEOF_SIZE(f); + /* Set the internal parameters for the array */ + hdr->f = f; + hdr->swmr_write = (H5F_INTENT(f) & H5F_ACC_SWMR_WRITE) > 0; + hdr->sizeof_addr = H5F_SIZEOF_ADDR(f); + hdr->sizeof_size = H5F_SIZEOF_SIZE(f); -/* Set the return value */ -ret_value = hdr; + /* Set the return value */ + ret_value = hdr; -CATCH -if (!ret_value) - if (hdr && H5EA__hdr_dest(hdr) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array header") + CATCH + if (!ret_value) + if (hdr && H5EA__hdr_dest(hdr) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array header") END_FUNC(PKG) /* end H5EA__hdr_alloc() */ @@ -170,50 +170,50 @@ END_FUNC(PKG) /* end H5EA__hdr_alloc() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__hdr_init(H5EA_hdr_t *hdr, void *ctx_udata)) -/* Local variables */ -hsize_t start_idx; /* First element index for each super block */ -hsize_t start_dblk; /* First data block index for each super block */ -size_t u; /* Local index variable */ - -/* Sanity check */ -HDassert(hdr); -HDassert(hdr->cparam.max_nelmts_bits); -HDassert(hdr->cparam.data_blk_min_elmts); -HDassert(hdr->cparam.sup_blk_min_data_ptrs); - -/* Compute general information */ -hdr->nsblks = 1 + (hdr->cparam.max_nelmts_bits - H5VM_log2_of2(hdr->cparam.data_blk_min_elmts)); -hdr->dblk_page_nelmts = (size_t)1 << hdr->cparam.max_dblk_page_nelmts_bits; -hdr->arr_off_size = (unsigned char)H5EA_SIZEOF_OFFSET_BITS(hdr->cparam.max_nelmts_bits); - -/* Allocate information for each super block */ -if (NULL == (hdr->sblk_info = H5FL_SEQ_MALLOC(H5EA_sblk_info_t, hdr->nsblks))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for super block info array") - -/* Compute information about each super block */ -start_idx = 0; -start_dblk = 0; -for (u = 0; u < hdr->nsblks; u++) { - hdr->sblk_info[u].ndblks = (size_t)H5_EXP2(u / 2); - hdr->sblk_info[u].dblk_nelmts = H5EA_SBLK_DBLK_NELMTS(u, hdr->cparam.data_blk_min_elmts); - hdr->sblk_info[u].start_idx = start_idx; - hdr->sblk_info[u].start_dblk = start_dblk; - - /* Advance starting indices for next super block */ - start_idx += (hsize_t)hdr->sblk_info[u].ndblks * (hsize_t)hdr->sblk_info[u].dblk_nelmts; - start_dblk += (hsize_t)hdr->sblk_info[u].ndblks; -} /* end for */ - -/* Set size of header on disk (locally and in statistics) */ -hdr->stats.computed.hdr_size = hdr->size = H5EA_HEADER_SIZE_HDR(hdr); - -/* Create the callback context, if there's one */ -if (hdr->cparam.cls->crt_context) { - if (NULL == (hdr->cb_ctx = (*hdr->cparam.cls->crt_context)(ctx_udata))) - H5E_THROW(H5E_CANTCREATE, "unable to create extensible array client callback context") -} /* end if */ - -CATCH + /* Local variables */ + hsize_t start_idx; /* First element index for each super block */ + hsize_t start_dblk; /* First data block index for each super block */ + size_t u; /* Local index variable */ + + /* Sanity check */ + HDassert(hdr); + HDassert(hdr->cparam.max_nelmts_bits); + HDassert(hdr->cparam.data_blk_min_elmts); + HDassert(hdr->cparam.sup_blk_min_data_ptrs); + + /* Compute general information */ + hdr->nsblks = 1 + (hdr->cparam.max_nelmts_bits - H5VM_log2_of2(hdr->cparam.data_blk_min_elmts)); + hdr->dblk_page_nelmts = (size_t)1 << hdr->cparam.max_dblk_page_nelmts_bits; + hdr->arr_off_size = (unsigned char)H5EA_SIZEOF_OFFSET_BITS(hdr->cparam.max_nelmts_bits); + + /* Allocate information for each super block */ + if (NULL == (hdr->sblk_info = H5FL_SEQ_MALLOC(H5EA_sblk_info_t, hdr->nsblks))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for super block info array") + + /* Compute information about each super block */ + start_idx = 0; + start_dblk = 0; + for (u = 0; u < hdr->nsblks; u++) { + hdr->sblk_info[u].ndblks = (size_t)H5_EXP2(u / 2); + hdr->sblk_info[u].dblk_nelmts = H5EA_SBLK_DBLK_NELMTS(u, hdr->cparam.data_blk_min_elmts); + hdr->sblk_info[u].start_idx = start_idx; + hdr->sblk_info[u].start_dblk = start_dblk; + + /* Advance starting indices for next super block */ + start_idx += (hsize_t)hdr->sblk_info[u].ndblks * (hsize_t)hdr->sblk_info[u].dblk_nelmts; + start_dblk += (hsize_t)hdr->sblk_info[u].ndblks; + } /* end for */ + + /* Set size of header on disk (locally and in statistics) */ + hdr->stats.computed.hdr_size = hdr->size = H5EA_HEADER_SIZE_HDR(hdr); + + /* Create the callback context, if there's one */ + if (hdr->cparam.cls->crt_context) { + if (NULL == (hdr->cb_ctx = (*hdr->cparam.cls->crt_context)(ctx_udata))) + H5E_THROW(H5E_CANTCREATE, "unable to create extensible array client callback context") + } /* end if */ + + CATCH END_FUNC(PKG) /* end H5EA__hdr_init() */ @@ -231,54 +231,55 @@ END_FUNC(PKG) /* end H5EA__hdr_init() */ */ BEGIN_FUNC(PKG, ERR, void *, NULL, NULL, H5EA__hdr_alloc_elmts(H5EA_hdr_t *hdr, size_t nelmts)) -/* Local variables */ -void * elmts = NULL; /* Element buffer allocated */ -unsigned idx; /* Index of element buffer factory in header */ + /* Local variables */ + void * elmts = NULL; /* Element buffer allocated */ + unsigned idx; /* Index of element buffer factory in header */ -/* Check arguments */ -HDassert(hdr); -HDassert(nelmts > 0); + /* Check arguments */ + HDassert(hdr); + HDassert(nelmts > 0); -/* Compute the index of the element buffer factory */ -H5_CHECK_OVERFLOW(nelmts, /*From:*/ size_t, /*To:*/ uint32_t); -idx = H5VM_log2_of2((uint32_t)nelmts) - H5VM_log2_of2((uint32_t)hdr->cparam.data_blk_min_elmts); + /* Compute the index of the element buffer factory */ + H5_CHECK_OVERFLOW(nelmts, /*From:*/ size_t, /*To:*/ uint32_t); + idx = H5VM_log2_of2((uint32_t)nelmts) - H5VM_log2_of2((uint32_t)hdr->cparam.data_blk_min_elmts); -/* Check for needing to increase size of array of factories */ -if (idx >= hdr->elmt_fac.nalloc) { - H5FL_fac_head_t **new_fac; /* New array of element factories */ - size_t new_nalloc = - MAX3(1, (idx + 1), (2 * hdr->elmt_fac.nalloc)); /* New number of factories allocated */ + /* Check for needing to increase size of array of factories */ + if (idx >= hdr->elmt_fac.nalloc) { + H5FL_fac_head_t **new_fac; /* New array of element factories */ + size_t new_nalloc = + MAX3(1, (idx + 1), (2 * hdr->elmt_fac.nalloc)); /* New number of factories allocated */ - /* Re-allocate array of element factories */ - if (NULL == (new_fac = H5FL_SEQ_REALLOC(H5FL_fac_head_ptr_t, hdr->elmt_fac.fac, new_nalloc))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block data element buffer factory array") + /* Re-allocate array of element factories */ + if (NULL == (new_fac = H5FL_SEQ_REALLOC(H5FL_fac_head_ptr_t, hdr->elmt_fac.fac, new_nalloc))) + H5E_THROW(H5E_CANTALLOC, + "memory allocation failed for data block data element buffer factory array") - /* Zero out new elements allocated */ - HDmemset(new_fac + hdr->elmt_fac.nalloc, 0, - (new_nalloc - hdr->elmt_fac.nalloc) * sizeof(H5FL_fac_head_ptr_t)); + /* Zero out new elements allocated */ + HDmemset(new_fac + hdr->elmt_fac.nalloc, 0, + (new_nalloc - hdr->elmt_fac.nalloc) * sizeof(H5FL_fac_head_ptr_t)); - /* Update information about element factories in header */ - hdr->elmt_fac.nalloc = new_nalloc; - hdr->elmt_fac.fac = new_fac; -} /* end if */ + /* Update information about element factories in header */ + hdr->elmt_fac.nalloc = new_nalloc; + hdr->elmt_fac.fac = new_fac; + } /* end if */ -/* Check for un-initialized factory at index */ -if (NULL == hdr->elmt_fac.fac[idx]) { - if (NULL == (hdr->elmt_fac.fac[idx] = H5FL_fac_init(nelmts * (size_t)hdr->cparam.cls->nat_elmt_size))) - H5E_THROW(H5E_CANTINIT, "can't create data block data element buffer factory") -} /* end if */ + /* Check for un-initialized factory at index */ + if (NULL == hdr->elmt_fac.fac[idx]) { + if (NULL == (hdr->elmt_fac.fac[idx] = H5FL_fac_init(nelmts * (size_t)hdr->cparam.cls->nat_elmt_size))) + H5E_THROW(H5E_CANTINIT, "can't create data block data element buffer factory") + } /* end if */ -/* Allocate buffer for elements in index block */ -if (NULL == (elmts = H5FL_FAC_MALLOC(hdr->elmt_fac.fac[idx]))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block data element buffer") + /* Allocate buffer for elements in index block */ + if (NULL == (elmts = H5FL_FAC_MALLOC(hdr->elmt_fac.fac[idx]))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block data element buffer") -/* Set the return value */ -ret_value = elmts; + /* Set the return value */ + ret_value = elmts; -CATCH -if (!ret_value) - if (elmts) - elmts = H5FL_FAC_FREE(hdr->elmt_fac.fac[idx], elmts); + CATCH + if (!ret_value) + if (elmts) + elmts = H5FL_FAC_FREE(hdr->elmt_fac.fac[idx], elmts); END_FUNC(PKG) /* end H5EA__hdr_alloc_elmts() */ @@ -296,22 +297,22 @@ END_FUNC(PKG) /* end H5EA__hdr_alloc_elmts() */ */ BEGIN_FUNC(PKG, NOERR, herr_t, SUCCEED, -, H5EA__hdr_free_elmts(H5EA_hdr_t *hdr, size_t nelmts, void *elmts)) -/* Local variables */ -unsigned idx; /* Index of element buffer factory in header */ + /* Local variables */ + unsigned idx; /* Index of element buffer factory in header */ -/* Check arguments */ -HDassert(hdr); -HDassert(nelmts > 0); -HDassert(elmts); + /* Check arguments */ + HDassert(hdr); + HDassert(nelmts > 0); + HDassert(elmts); -/* Compute the index of the element buffer factory */ -H5_CHECK_OVERFLOW(nelmts, /*From:*/ size_t, /*To:*/ uint32_t); -idx = H5VM_log2_of2((uint32_t)nelmts) - H5VM_log2_of2((uint32_t)hdr->cparam.data_blk_min_elmts); + /* Compute the index of the element buffer factory */ + H5_CHECK_OVERFLOW(nelmts, /*From:*/ size_t, /*To:*/ uint32_t); + idx = H5VM_log2_of2((uint32_t)nelmts) - H5VM_log2_of2((uint32_t)hdr->cparam.data_blk_min_elmts); -/* Free buffer for elements in index block */ -HDassert(idx < hdr->elmt_fac.nalloc); -HDassert(hdr->elmt_fac.fac[idx]); -elmts = H5FL_FAC_FREE(hdr->elmt_fac.fac[idx], elmts); + /* Free buffer for elements in index block */ + HDassert(idx < hdr->elmt_fac.nalloc); + HDassert(hdr->elmt_fac.fac[idx]); + elmts = H5FL_FAC_FREE(hdr->elmt_fac.fac[idx], elmts); END_FUNC(PKG) /* end H5EA__hdr_free_elmts() */ @@ -330,104 +331,105 @@ END_FUNC(PKG) /* end H5EA__hdr_free_elmts() */ BEGIN_FUNC(PKG, ERR, haddr_t, HADDR_UNDEF, HADDR_UNDEF, H5EA__hdr_create(H5F_t *f, const H5EA_create_t *cparam, void *ctx_udata)) -/* Local variables */ -H5EA_hdr_t *hdr = NULL; /* Extensible array header */ -hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ + /* Local variables */ + H5EA_hdr_t *hdr = NULL; /* Extensible array header */ + hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ -/* Check arguments */ -HDassert(f); -HDassert(cparam); + /* Check arguments */ + HDassert(f); + HDassert(cparam); #ifndef NDEBUG -{ - unsigned sblk_idx; /* Super block index for first "actual" super block */ - size_t dblk_nelmts; /* Number of data block elements */ - size_t dblk_page_nelmts; /* Number of elements in a data block page */ - - /* Check for valid parameters */ - if (cparam->raw_elmt_size == 0) - H5E_THROW(H5E_BADVALUE, "element size must be greater than zero") - if (cparam->max_nelmts_bits == 0) - H5E_THROW(H5E_BADVALUE, "max. # of elements bits must be greater than zero") - if (cparam->max_nelmts_bits > H5EA_MAX_NELMTS_IDX_MAX) - H5E_THROW(H5E_BADVALUE, "max. # of elements bits must be <= %u", (unsigned)H5EA_MAX_NELMTS_IDX_MAX) - if (cparam->sup_blk_min_data_ptrs < 2) - H5E_THROW(H5E_BADVALUE, "min # of data block pointers in super block must be >= two") - if (!POWER_OF_TWO(cparam->sup_blk_min_data_ptrs)) - H5E_THROW(H5E_BADVALUE, "min # of data block pointers in super block must be power of two") - if (!POWER_OF_TWO(cparam->data_blk_min_elmts)) - H5E_THROW(H5E_BADVALUE, "min # of elements per data block must be power of two") - dblk_page_nelmts = (size_t)1 << cparam->max_dblk_page_nelmts_bits; - if (dblk_page_nelmts < cparam->idx_blk_elmts) - H5E_THROW(H5E_BADVALUE, - "# of elements per data block page must be greater than # of elements in index block") - - /* Compute the number of elements in data blocks for first actual super block */ - sblk_idx = H5EA_SBLK_FIRST_IDX(cparam->sup_blk_min_data_ptrs); - dblk_nelmts = H5EA_SBLK_DBLK_NELMTS(sblk_idx, cparam->data_blk_min_elmts); - if (dblk_page_nelmts < dblk_nelmts) - H5E_THROW(H5E_BADVALUE, "max. # of elements per data block page bits must be > # of elements in " - "first data block from super block") - - if (cparam->max_dblk_page_nelmts_bits > cparam->max_nelmts_bits) - H5E_THROW(H5E_BADVALUE, - "max. # of elements per data block page bits must be <= max. # of elements bits") -} + { + unsigned sblk_idx; /* Super block index for first "actual" super block */ + size_t dblk_nelmts; /* Number of data block elements */ + size_t dblk_page_nelmts; /* Number of elements in a data block page */ + + /* Check for valid parameters */ + if (cparam->raw_elmt_size == 0) + H5E_THROW(H5E_BADVALUE, "element size must be greater than zero") + if (cparam->max_nelmts_bits == 0) + H5E_THROW(H5E_BADVALUE, "max. # of elements bits must be greater than zero") + if (cparam->max_nelmts_bits > H5EA_MAX_NELMTS_IDX_MAX) + H5E_THROW(H5E_BADVALUE, "max. # of elements bits must be <= %u", + (unsigned)H5EA_MAX_NELMTS_IDX_MAX) + if (cparam->sup_blk_min_data_ptrs < 2) + H5E_THROW(H5E_BADVALUE, "min # of data block pointers in super block must be >= two") + if (!POWER_OF_TWO(cparam->sup_blk_min_data_ptrs)) + H5E_THROW(H5E_BADVALUE, "min # of data block pointers in super block must be power of two") + if (!POWER_OF_TWO(cparam->data_blk_min_elmts)) + H5E_THROW(H5E_BADVALUE, "min # of elements per data block must be power of two") + dblk_page_nelmts = (size_t)1 << cparam->max_dblk_page_nelmts_bits; + if (dblk_page_nelmts < cparam->idx_blk_elmts) + H5E_THROW(H5E_BADVALUE, + "# of elements per data block page must be greater than # of elements in index block") + + /* Compute the number of elements in data blocks for first actual super block */ + sblk_idx = H5EA_SBLK_FIRST_IDX(cparam->sup_blk_min_data_ptrs); + dblk_nelmts = H5EA_SBLK_DBLK_NELMTS(sblk_idx, cparam->data_blk_min_elmts); + if (dblk_page_nelmts < dblk_nelmts) + H5E_THROW(H5E_BADVALUE, "max. # of elements per data block page bits must be > # of elements in " + "first data block from super block") + + if (cparam->max_dblk_page_nelmts_bits > cparam->max_nelmts_bits) + H5E_THROW(H5E_BADVALUE, + "max. # of elements per data block page bits must be <= max. # of elements bits") + } #endif /* NDEBUG */ -/* Allocate space for the shared information */ -if (NULL == (hdr = H5EA__hdr_alloc(f))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array shared header") - -/* Set the internal parameters for the array */ -hdr->idx_blk_addr = HADDR_UNDEF; - -/* Set the creation parameters for the array */ -H5MM_memcpy(&hdr->cparam, cparam, sizeof(hdr->cparam)); - -/* Finish initializing extensible array header */ -if (H5EA__hdr_init(hdr, ctx_udata) < 0) - H5E_THROW(H5E_CANTINIT, "initialization failed for extensible array header") - -/* Allocate space for the header on disk */ -if (HADDR_UNDEF == (hdr->addr = H5MF_alloc(f, H5FD_MEM_EARRAY_HDR, (hsize_t)hdr->size))) - H5E_THROW(H5E_CANTALLOC, "file allocation failed for extensible array header") - -/* Create 'top' proxy for extensible array entries */ -if (hdr->swmr_write) - if (NULL == (hdr->top_proxy = H5AC_proxy_entry_create())) - H5E_THROW(H5E_CANTCREATE, "can't create extensible array entry proxy") - -/* Cache the new extensible array header */ -if (H5AC_insert_entry(f, H5AC_EARRAY_HDR, hdr->addr, hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTINSERT, "can't add extensible array header to cache") -inserted = TRUE; - -/* Add header as child of 'top' proxy */ -if (hdr->top_proxy) - if (H5AC_proxy_entry_add_child(hdr->top_proxy, f, hdr) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") - -/* Set address of array header to return */ -ret_value = hdr->addr; - -CATCH -if (!H5F_addr_defined(ret_value)) - if (hdr) { - /* Remove from cache, if inserted */ - if (inserted) - if (H5AC_remove_entry(hdr) < 0) - H5E_THROW(H5E_CANTREMOVE, "unable to remove extensible array header from cache") - - /* Release header's disk space */ - if (H5F_addr_defined(hdr->addr) && - H5MF_xfree(f, H5FD_MEM_EARRAY_HDR, hdr->addr, (hsize_t)hdr->size) < 0) - H5E_THROW(H5E_CANTFREE, "unable to free extensible array header") - - /* Destroy header */ - if (H5EA__hdr_dest(hdr) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array header") - } /* end if */ + /* Allocate space for the shared information */ + if (NULL == (hdr = H5EA__hdr_alloc(f))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array shared header") + + /* Set the internal parameters for the array */ + hdr->idx_blk_addr = HADDR_UNDEF; + + /* Set the creation parameters for the array */ + H5MM_memcpy(&hdr->cparam, cparam, sizeof(hdr->cparam)); + + /* Finish initializing extensible array header */ + if (H5EA__hdr_init(hdr, ctx_udata) < 0) + H5E_THROW(H5E_CANTINIT, "initialization failed for extensible array header") + + /* Allocate space for the header on disk */ + if (HADDR_UNDEF == (hdr->addr = H5MF_alloc(f, H5FD_MEM_EARRAY_HDR, (hsize_t)hdr->size))) + H5E_THROW(H5E_CANTALLOC, "file allocation failed for extensible array header") + + /* Create 'top' proxy for extensible array entries */ + if (hdr->swmr_write) + if (NULL == (hdr->top_proxy = H5AC_proxy_entry_create())) + H5E_THROW(H5E_CANTCREATE, "can't create extensible array entry proxy") + + /* Cache the new extensible array header */ + if (H5AC_insert_entry(f, H5AC_EARRAY_HDR, hdr->addr, hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTINSERT, "can't add extensible array header to cache") + inserted = TRUE; + + /* Add header as child of 'top' proxy */ + if (hdr->top_proxy) + if (H5AC_proxy_entry_add_child(hdr->top_proxy, f, hdr) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") + + /* Set address of array header to return */ + ret_value = hdr->addr; + + CATCH + if (!H5F_addr_defined(ret_value)) + if (hdr) { + /* Remove from cache, if inserted */ + if (inserted) + if (H5AC_remove_entry(hdr) < 0) + H5E_THROW(H5E_CANTREMOVE, "unable to remove extensible array header from cache") + + /* Release header's disk space */ + if (H5F_addr_defined(hdr->addr) && + H5MF_xfree(f, H5FD_MEM_EARRAY_HDR, hdr->addr, (hsize_t)hdr->size) < 0) + H5E_THROW(H5E_CANTFREE, "unable to free extensible array header") + + /* Destroy header */ + if (H5EA__hdr_dest(hdr) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array header") + } /* end if */ END_FUNC(PKG) /* end H5EA__hdr_create() */ @@ -445,18 +447,18 @@ END_FUNC(PKG) /* end H5EA__hdr_create() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__hdr_incr(H5EA_hdr_t *hdr)) -/* Sanity check */ -HDassert(hdr); + /* Sanity check */ + HDassert(hdr); -/* Mark header as un-evictable when something is depending on it */ -if (hdr->rc == 0) - if (H5AC_pin_protected_entry(hdr) < 0) - H5E_THROW(H5E_CANTPIN, "unable to pin extensible array header") + /* Mark header as un-evictable when something is depending on it */ + if (hdr->rc == 0) + if (H5AC_pin_protected_entry(hdr) < 0) + H5E_THROW(H5E_CANTPIN, "unable to pin extensible array header") -/* Increment reference count on shared header */ -hdr->rc++; + /* Increment reference count on shared header */ + hdr->rc++; -CATCH + CATCH END_FUNC(PKG) /* end H5EA__hdr_incr() */ @@ -474,21 +476,21 @@ END_FUNC(PKG) /* end H5EA__hdr_incr() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__hdr_decr(H5EA_hdr_t *hdr)) -/* Sanity check */ -HDassert(hdr); -HDassert(hdr->rc); + /* Sanity check */ + HDassert(hdr); + HDassert(hdr->rc); -/* Decrement reference count on shared header */ -hdr->rc--; + /* Decrement reference count on shared header */ + hdr->rc--; -/* Mark header as evictable again when nothing depend on it */ -if (hdr->rc == 0) { - HDassert(hdr->file_rc == 0); - if (H5AC_unpin_entry(hdr) < 0) - H5E_THROW(H5E_CANTUNPIN, "unable to unpin extensible array header") -} /* end if */ + /* Mark header as evictable again when nothing depend on it */ + if (hdr->rc == 0) { + HDassert(hdr->file_rc == 0); + if (H5AC_unpin_entry(hdr) < 0) + H5E_THROW(H5E_CANTUNPIN, "unable to unpin extensible array header") + } /* end if */ -CATCH + CATCH END_FUNC(PKG) /* end H5EA__hdr_decr() */ @@ -506,11 +508,11 @@ END_FUNC(PKG) /* end H5EA__hdr_decr() */ */ BEGIN_FUNC(PKG, NOERR, herr_t, SUCCEED, -, H5EA__hdr_fuse_incr(H5EA_hdr_t *hdr)) -/* Sanity check */ -HDassert(hdr); + /* Sanity check */ + HDassert(hdr); -/* Increment file reference count on shared header */ -hdr->file_rc++; + /* Increment file reference count on shared header */ + hdr->file_rc++; END_FUNC(PKG) /* end H5EA__hdr_fuse_incr() */ @@ -528,15 +530,15 @@ END_FUNC(PKG) /* end H5EA__hdr_fuse_incr() */ */ BEGIN_FUNC(PKG, NOERR, size_t, 0, -, H5EA__hdr_fuse_decr(H5EA_hdr_t *hdr)) -/* Sanity check */ -HDassert(hdr); -HDassert(hdr->file_rc); + /* Sanity check */ + HDassert(hdr); + HDassert(hdr->file_rc); -/* Decrement file reference count on shared header */ -hdr->file_rc--; + /* Decrement file reference count on shared header */ + hdr->file_rc--; -/* Set return value */ -ret_value = hdr->file_rc; + /* Set return value */ + ret_value = hdr->file_rc; END_FUNC(PKG) /* end H5EA__hdr_fuse_decr() */ @@ -554,15 +556,15 @@ END_FUNC(PKG) /* end H5EA__hdr_fuse_decr() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__hdr_modified(H5EA_hdr_t *hdr)) -/* Sanity check */ -HDassert(hdr); -HDassert(hdr->f); + /* Sanity check */ + HDassert(hdr); + HDassert(hdr->f); -/* Mark header as dirty in cache */ -if (H5AC_mark_entry_dirty(hdr) < 0) - H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark extensible array header as dirty") + /* Mark header as dirty in cache */ + if (H5AC_mark_entry_dirty(hdr) < 0) + H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark extensible array header as dirty") -CATCH + CATCH END_FUNC(PKG) /* end H5EA__hdr_modified() */ @@ -581,43 +583,43 @@ END_FUNC(PKG) /* end H5EA__hdr_modified() */ BEGIN_FUNC(PKG, ERR, H5EA_hdr_t *, NULL, NULL, H5EA__hdr_protect(H5F_t *f, haddr_t ea_addr, void *ctx_udata, unsigned flags)) -/* Local variables */ -H5EA_hdr_t * hdr; /* Extensible array header */ -H5EA_hdr_cache_ud_t udata; /* User data for cache callbacks */ - -/* Sanity check */ -HDassert(f); -HDassert(H5F_addr_defined(ea_addr)); - -/* only the H5AC__READ_ONLY_FLAG may appear in flags */ -HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); - -/* Set up user data for cache callbacks */ -udata.f = f; -udata.addr = ea_addr; -udata.ctx_udata = ctx_udata; - -/* Protect the header */ -if (NULL == (hdr = (H5EA_hdr_t *)H5AC_protect(f, H5AC_EARRAY_HDR, ea_addr, &udata, flags))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array header, address = %llu", - (unsigned long long)ea_addr) -hdr->f = f; /* (Must be set again here, in case the header was already in the cache -QAK) */ + /* Local variables */ + H5EA_hdr_t * hdr; /* Extensible array header */ + H5EA_hdr_cache_ud_t udata; /* User data for cache callbacks */ -/* Create top proxy, if it doesn't exist */ -if (hdr->swmr_write && NULL == hdr->top_proxy) { - /* Create 'top' proxy for extensible array entries */ - if (NULL == (hdr->top_proxy = H5AC_proxy_entry_create())) - H5E_THROW(H5E_CANTCREATE, "can't create extensible array entry proxy") - - /* Add header as child of 'top' proxy */ - if (H5AC_proxy_entry_add_child(hdr->top_proxy, f, hdr) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") -} /* end if */ + /* Sanity check */ + HDassert(f); + HDassert(H5F_addr_defined(ea_addr)); + + /* only the H5AC__READ_ONLY_FLAG may appear in flags */ + HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); + + /* Set up user data for cache callbacks */ + udata.f = f; + udata.addr = ea_addr; + udata.ctx_udata = ctx_udata; + + /* Protect the header */ + if (NULL == (hdr = (H5EA_hdr_t *)H5AC_protect(f, H5AC_EARRAY_HDR, ea_addr, &udata, flags))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array header, address = %llu", + (unsigned long long)ea_addr) + hdr->f = f; /* (Must be set again here, in case the header was already in the cache -QAK) */ + + /* Create top proxy, if it doesn't exist */ + if (hdr->swmr_write && NULL == hdr->top_proxy) { + /* Create 'top' proxy for extensible array entries */ + if (NULL == (hdr->top_proxy = H5AC_proxy_entry_create())) + H5E_THROW(H5E_CANTCREATE, "can't create extensible array entry proxy") + + /* Add header as child of 'top' proxy */ + if (H5AC_proxy_entry_add_child(hdr->top_proxy, f, hdr) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") + } /* end if */ -/* Set return value */ -ret_value = hdr; + /* Set return value */ + ret_value = hdr; -CATCH + CATCH END_FUNC(PKG) /* end H5EA__hdr_protect() */ @@ -635,17 +637,17 @@ END_FUNC(PKG) /* end H5EA__hdr_protect() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__hdr_unprotect(H5EA_hdr_t *hdr, unsigned cache_flags)) -/* Local variables */ + /* Local variables */ -/* Sanity check */ -HDassert(hdr); + /* Sanity check */ + HDassert(hdr); -/* Unprotect the header */ -if (H5AC_unprotect(hdr->f, H5AC_EARRAY_HDR, hdr->addr, hdr, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array hdr, address = %llu", - (unsigned long long)hdr->addr) + /* Unprotect the header */ + if (H5AC_unprotect(hdr->f, H5AC_EARRAY_HDR, hdr->addr, hdr, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array hdr, address = %llu", + (unsigned long long)hdr->addr) -CATCH + CATCH END_FUNC(PKG) /* end H5EA__hdr_unprotect() */ @@ -663,42 +665,42 @@ END_FUNC(PKG) /* end H5EA__hdr_unprotect() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__hdr_delete(H5EA_hdr_t *hdr)) -/* Local variables */ -unsigned cache_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotecting header */ + /* Local variables */ + unsigned cache_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotecting header */ -/* Sanity check */ -HDassert(hdr); -HDassert(!hdr->file_rc); + /* Sanity check */ + HDassert(hdr); + HDassert(!hdr->file_rc); #ifndef NDEBUG -{ - unsigned hdr_status = 0; /* Array header's status in the metadata cache */ + { + unsigned hdr_status = 0; /* Array header's status in the metadata cache */ - /* Check the array header's status in the metadata cache */ - if (H5AC_get_entry_status(hdr->f, hdr->addr, &hdr_status) < 0) - H5E_THROW(H5E_CANTGET, "unable to check metadata cache status for array header") + /* Check the array header's status in the metadata cache */ + if (H5AC_get_entry_status(hdr->f, hdr->addr, &hdr_status) < 0) + H5E_THROW(H5E_CANTGET, "unable to check metadata cache status for array header") - /* Sanity checks on array header */ - HDassert(hdr_status & H5AC_ES__IN_CACHE); - HDassert(hdr_status & H5AC_ES__IS_PROTECTED); -} /* end block */ + /* Sanity checks on array header */ + HDassert(hdr_status & H5AC_ES__IN_CACHE); + HDassert(hdr_status & H5AC_ES__IS_PROTECTED); + } /* end block */ #endif /* NDEBUG */ -/* Check for index block */ -if (H5F_addr_defined(hdr->idx_blk_addr)) { - /* Delete index block */ - if (H5EA__iblock_delete(hdr) < 0) - H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array index block") -} /* end if */ + /* Check for index block */ + if (H5F_addr_defined(hdr->idx_blk_addr)) { + /* Delete index block */ + if (H5EA__iblock_delete(hdr) < 0) + H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array index block") + } /* end if */ -/* Set flags to finish deleting header on unprotect */ -cache_flags |= H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG; + /* Set flags to finish deleting header on unprotect */ + cache_flags |= H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG; -CATCH + CATCH -/* Unprotect the header, deleting it if an error hasn't occurred */ -if (H5EA__hdr_unprotect(hdr, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") + /* Unprotect the header, deleting it if an error hasn't occurred */ + if (H5EA__hdr_unprotect(hdr, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array header") END_FUNC(PKG) /* end H5EA__hdr_delete() */ @@ -716,52 +718,52 @@ END_FUNC(PKG) /* end H5EA__hdr_delete() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__hdr_dest(H5EA_hdr_t *hdr)) -/* Check arguments */ -HDassert(hdr); -HDassert(hdr->rc == 0); + /* Check arguments */ + HDassert(hdr); + HDassert(hdr->rc == 0); -/* Destroy the callback context */ -if (hdr->cb_ctx) { - if ((*hdr->cparam.cls->dst_context)(hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to destroy extensible array client callback context") -} /* end if */ -hdr->cb_ctx = NULL; - -/* Check for data block element buffer factory info to free */ -if (hdr->elmt_fac.fac) { - unsigned u; /* Local index variable */ - - /* Sanity check */ - HDassert(hdr->elmt_fac.nalloc > 0); - - /* Iterate over factories, shutting them down */ - for (u = 0; u < hdr->elmt_fac.nalloc; u++) { - /* Check if this factory has been initialized */ - if (hdr->elmt_fac.fac[u]) { - if (H5FL_fac_term(hdr->elmt_fac.fac[u]) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to destroy extensible array header factory") - hdr->elmt_fac.fac[u] = NULL; - } /* end if */ - } /* end for */ - - /* Free factory array */ - hdr->elmt_fac.fac = (H5FL_fac_head_t **)H5FL_SEQ_FREE(H5FL_fac_head_ptr_t, hdr->elmt_fac.fac); -} /* end if */ + /* Destroy the callback context */ + if (hdr->cb_ctx) { + if ((*hdr->cparam.cls->dst_context)(hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to destroy extensible array client callback context") + } /* end if */ + hdr->cb_ctx = NULL; + + /* Check for data block element buffer factory info to free */ + if (hdr->elmt_fac.fac) { + unsigned u; /* Local index variable */ + + /* Sanity check */ + HDassert(hdr->elmt_fac.nalloc > 0); + + /* Iterate over factories, shutting them down */ + for (u = 0; u < hdr->elmt_fac.nalloc; u++) { + /* Check if this factory has been initialized */ + if (hdr->elmt_fac.fac[u]) { + if (H5FL_fac_term(hdr->elmt_fac.fac[u]) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to destroy extensible array header factory") + hdr->elmt_fac.fac[u] = NULL; + } /* end if */ + } /* end for */ + + /* Free factory array */ + hdr->elmt_fac.fac = (H5FL_fac_head_t **)H5FL_SEQ_FREE(H5FL_fac_head_ptr_t, hdr->elmt_fac.fac); + } /* end if */ -/* Free the super block info array */ -if (hdr->sblk_info) - hdr->sblk_info = (H5EA_sblk_info_t *)H5FL_SEQ_FREE(H5EA_sblk_info_t, hdr->sblk_info); + /* Free the super block info array */ + if (hdr->sblk_info) + hdr->sblk_info = (H5EA_sblk_info_t *)H5FL_SEQ_FREE(H5EA_sblk_info_t, hdr->sblk_info); -/* Destroy the 'top' proxy */ -if (hdr->top_proxy) { - if (H5AC_proxy_entry_dest(hdr->top_proxy) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to destroy extensible array 'top' proxy") - hdr->top_proxy = NULL; -} /* end if */ + /* Destroy the 'top' proxy */ + if (hdr->top_proxy) { + if (H5AC_proxy_entry_dest(hdr->top_proxy) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to destroy extensible array 'top' proxy") + hdr->top_proxy = NULL; + } /* end if */ -/* Free the shared info itself */ -hdr = H5FL_FREE(H5EA_hdr_t, hdr); + /* Free the shared info itself */ + hdr = H5FL_FREE(H5EA_hdr_t, hdr); -CATCH + CATCH END_FUNC(PKG) /* end H5EA__hdr_dest() */ diff --git a/src/H5EAiblock.c b/src/H5EAiblock.c index 1e42716..fcbe65f 100644 --- a/src/H5EAiblock.c +++ b/src/H5EAiblock.c @@ -93,52 +93,53 @@ H5FL_SEQ_DEFINE_STATIC(haddr_t); */ BEGIN_FUNC(PKG, ERR, H5EA_iblock_t *, NULL, NULL, H5EA__iblock_alloc(H5EA_hdr_t *hdr)) -/* Local variables */ -H5EA_iblock_t *iblock = NULL; /* Extensible array index block */ - -/* Check arguments */ -HDassert(hdr); - -/* Allocate memory for the index block */ -if (NULL == (iblock = H5FL_CALLOC(H5EA_iblock_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array index block") - -/* Share common array information */ -if (H5EA__hdr_incr(hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") -iblock->hdr = hdr; - -/* Set non-zero internal fields */ -iblock->addr = HADDR_UNDEF; - -/* Compute information */ -iblock->nsblks = H5EA_SBLK_FIRST_IDX(hdr->cparam.sup_blk_min_data_ptrs); -iblock->ndblk_addrs = 2 * ((size_t)hdr->cparam.sup_blk_min_data_ptrs - 1); -iblock->nsblk_addrs = hdr->nsblks - iblock->nsblks; - -/* Allocate buffer for elements in index block */ -if (hdr->cparam.idx_blk_elmts > 0) - if (NULL == (iblock->elmts = H5FL_BLK_MALLOC( - idx_blk_elmt_buf, (size_t)(hdr->cparam.idx_blk_elmts * hdr->cparam.cls->nat_elmt_size)))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for index block data element buffer") - -/* Allocate buffer for data block addresses in index block */ -if (iblock->ndblk_addrs > 0) - if (NULL == (iblock->dblk_addrs = H5FL_SEQ_MALLOC(haddr_t, iblock->ndblk_addrs))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for index block data block addresses") - -/* Allocate buffer for super block addresses in index block */ -if (iblock->nsblk_addrs > 0) - if (NULL == (iblock->sblk_addrs = H5FL_SEQ_MALLOC(haddr_t, iblock->nsblk_addrs))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for index block super block addresses") - -/* Set the return value */ -ret_value = iblock; - -CATCH -if (!ret_value) - if (iblock && H5EA__iblock_dest(iblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array index block") + /* Local variables */ + H5EA_iblock_t *iblock = NULL; /* Extensible array index block */ + + /* Check arguments */ + HDassert(hdr); + + /* Allocate memory for the index block */ + if (NULL == (iblock = H5FL_CALLOC(H5EA_iblock_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array index block") + + /* Share common array information */ + if (H5EA__hdr_incr(hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") + iblock->hdr = hdr; + + /* Set non-zero internal fields */ + iblock->addr = HADDR_UNDEF; + + /* Compute information */ + iblock->nsblks = H5EA_SBLK_FIRST_IDX(hdr->cparam.sup_blk_min_data_ptrs); + iblock->ndblk_addrs = 2 * ((size_t)hdr->cparam.sup_blk_min_data_ptrs - 1); + iblock->nsblk_addrs = hdr->nsblks - iblock->nsblks; + + /* Allocate buffer for elements in index block */ + if (hdr->cparam.idx_blk_elmts > 0) + if (NULL == + (iblock->elmts = H5FL_BLK_MALLOC( + idx_blk_elmt_buf, (size_t)(hdr->cparam.idx_blk_elmts * hdr->cparam.cls->nat_elmt_size)))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for index block data element buffer") + + /* Allocate buffer for data block addresses in index block */ + if (iblock->ndblk_addrs > 0) + if (NULL == (iblock->dblk_addrs = H5FL_SEQ_MALLOC(haddr_t, iblock->ndblk_addrs))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for index block data block addresses") + + /* Allocate buffer for super block addresses in index block */ + if (iblock->nsblk_addrs > 0) + if (NULL == (iblock->sblk_addrs = H5FL_SEQ_MALLOC(haddr_t, iblock->nsblk_addrs))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for index block super block addresses") + + /* Set the return value */ + ret_value = iblock; + + CATCH + if (!ret_value) + if (iblock && H5EA__iblock_dest(iblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array index block") END_FUNC(PKG) /* end H5EA__iblock_alloc() */ @@ -157,95 +158,95 @@ END_FUNC(PKG) /* end H5EA__iblock_alloc() */ BEGIN_FUNC(PKG, ERR, haddr_t, HADDR_UNDEF, HADDR_UNDEF, H5EA__iblock_create(H5EA_hdr_t *hdr, hbool_t *stats_changed)) -/* Local variables */ -H5EA_iblock_t *iblock = NULL; /* Extensible array index block */ -haddr_t iblock_addr; /* Extensible array index block address */ -hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ - -/* Sanity check */ -HDassert(hdr); -HDassert(stats_changed); - -/* Allocate the index block */ -if (NULL == (iblock = H5EA__iblock_alloc(hdr))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array index block") - -/* Set size of index block on disk */ -iblock->size = H5EA_IBLOCK_SIZE(iblock); - -/* Allocate space for the index block on disk */ -if (HADDR_UNDEF == (iblock_addr = H5MF_alloc(hdr->f, H5FD_MEM_EARRAY_IBLOCK, (hsize_t)iblock->size))) - H5E_THROW(H5E_CANTALLOC, "file allocation failed for extensible array index block") -iblock->addr = iblock_addr; - -/* Clear any elements in index block to fill value */ -if (hdr->cparam.idx_blk_elmts > 0) { - /* Call the class's 'fill' callback */ - if ((hdr->cparam.cls->fill)(iblock->elmts, (size_t)hdr->cparam.idx_blk_elmts) < 0) - H5E_THROW(H5E_CANTSET, "can't set extensible array index block elements to class's fill value") -} /* end if */ - -/* Reset any data block addresses in the index block */ -if (iblock->ndblk_addrs > 0) { - haddr_t tmp_addr = HADDR_UNDEF; /* Address value to fill data block addresses with */ - - /* Set all the data block addresses to "undefined" address value */ - H5VM_array_fill(iblock->dblk_addrs, &tmp_addr, sizeof(haddr_t), iblock->ndblk_addrs); -} /* end if */ - -/* Reset any super block addresses in the index block */ -if (iblock->nsblk_addrs > 0) { - haddr_t tmp_addr = HADDR_UNDEF; /* Address value to fill super block addresses with */ - - /* Set all the super block addresses to "undefined" address value */ - H5VM_array_fill(iblock->sblk_addrs, &tmp_addr, sizeof(haddr_t), iblock->nsblk_addrs); -} /* end if */ - -/* Cache the new extensible array index block */ -if (H5AC_insert_entry(hdr->f, H5AC_EARRAY_IBLOCK, iblock_addr, iblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTINSERT, "can't add extensible array index block to cache") -inserted = TRUE; - -/* Add index block as child of 'top' proxy */ -if (hdr->top_proxy) { - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, iblock) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") - iblock->top_proxy = hdr->top_proxy; -} /* end if */ - -/* Update extensible array index block statistics */ -HDassert(0 == hdr->stats.computed.nindex_blks); -HDassert(0 == hdr->stats.computed.index_blk_size); -hdr->stats.computed.nindex_blks = 1; -hdr->stats.computed.index_blk_size = iblock->size; - -/* Increment count of elements "realized" */ -hdr->stats.stored.nelmts += hdr->cparam.idx_blk_elmts; - -/* Mark the statistics as changed */ -*stats_changed = TRUE; - -/* Set address of index block to return */ -ret_value = iblock_addr; - -CATCH -if (!H5F_addr_defined(ret_value)) - if (iblock) { - /* Remove from cache, if inserted */ - if (inserted) - if (H5AC_remove_entry(iblock) < 0) - H5E_THROW(H5E_CANTREMOVE, "unable to remove extensible array index block from cache") - - /* Release index block's disk space */ - if (H5F_addr_defined(iblock->addr) && - H5MF_xfree(hdr->f, H5FD_MEM_EARRAY_IBLOCK, iblock->addr, (hsize_t)iblock->size) < 0) - H5E_THROW(H5E_CANTFREE, "unable to release file space for extensible array index block") - - /* Destroy index block */ - if (H5EA__iblock_dest(iblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array index block") + /* Local variables */ + H5EA_iblock_t *iblock = NULL; /* Extensible array index block */ + haddr_t iblock_addr; /* Extensible array index block address */ + hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ + + /* Sanity check */ + HDassert(hdr); + HDassert(stats_changed); + + /* Allocate the index block */ + if (NULL == (iblock = H5EA__iblock_alloc(hdr))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array index block") + + /* Set size of index block on disk */ + iblock->size = H5EA_IBLOCK_SIZE(iblock); + + /* Allocate space for the index block on disk */ + if (HADDR_UNDEF == (iblock_addr = H5MF_alloc(hdr->f, H5FD_MEM_EARRAY_IBLOCK, (hsize_t)iblock->size))) + H5E_THROW(H5E_CANTALLOC, "file allocation failed for extensible array index block") + iblock->addr = iblock_addr; + + /* Clear any elements in index block to fill value */ + if (hdr->cparam.idx_blk_elmts > 0) { + /* Call the class's 'fill' callback */ + if ((hdr->cparam.cls->fill)(iblock->elmts, (size_t)hdr->cparam.idx_blk_elmts) < 0) + H5E_THROW(H5E_CANTSET, "can't set extensible array index block elements to class's fill value") + } /* end if */ + + /* Reset any data block addresses in the index block */ + if (iblock->ndblk_addrs > 0) { + haddr_t tmp_addr = HADDR_UNDEF; /* Address value to fill data block addresses with */ + + /* Set all the data block addresses to "undefined" address value */ + H5VM_array_fill(iblock->dblk_addrs, &tmp_addr, sizeof(haddr_t), iblock->ndblk_addrs); + } /* end if */ + + /* Reset any super block addresses in the index block */ + if (iblock->nsblk_addrs > 0) { + haddr_t tmp_addr = HADDR_UNDEF; /* Address value to fill super block addresses with */ + + /* Set all the super block addresses to "undefined" address value */ + H5VM_array_fill(iblock->sblk_addrs, &tmp_addr, sizeof(haddr_t), iblock->nsblk_addrs); + } /* end if */ + + /* Cache the new extensible array index block */ + if (H5AC_insert_entry(hdr->f, H5AC_EARRAY_IBLOCK, iblock_addr, iblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTINSERT, "can't add extensible array index block to cache") + inserted = TRUE; + + /* Add index block as child of 'top' proxy */ + if (hdr->top_proxy) { + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, iblock) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") + iblock->top_proxy = hdr->top_proxy; } /* end if */ + /* Update extensible array index block statistics */ + HDassert(0 == hdr->stats.computed.nindex_blks); + HDassert(0 == hdr->stats.computed.index_blk_size); + hdr->stats.computed.nindex_blks = 1; + hdr->stats.computed.index_blk_size = iblock->size; + + /* Increment count of elements "realized" */ + hdr->stats.stored.nelmts += hdr->cparam.idx_blk_elmts; + + /* Mark the statistics as changed */ + *stats_changed = TRUE; + + /* Set address of index block to return */ + ret_value = iblock_addr; + + CATCH + if (!H5F_addr_defined(ret_value)) + if (iblock) { + /* Remove from cache, if inserted */ + if (inserted) + if (H5AC_remove_entry(iblock) < 0) + H5E_THROW(H5E_CANTREMOVE, "unable to remove extensible array index block from cache") + + /* Release index block's disk space */ + if (H5F_addr_defined(iblock->addr) && + H5MF_xfree(hdr->f, H5FD_MEM_EARRAY_IBLOCK, iblock->addr, (hsize_t)iblock->size) < 0) + H5E_THROW(H5E_CANTFREE, "unable to release file space for extensible array index block") + + /* Destroy index block */ + if (H5EA__iblock_dest(iblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array index block") + } /* end if */ + END_FUNC(PKG) /* end H5EA__iblock_create() */ /*------------------------------------------------------------------------- @@ -262,40 +263,41 @@ END_FUNC(PKG) /* end H5EA__iblock_create() */ */ BEGIN_FUNC(PKG, ERR, H5EA_iblock_t *, NULL, NULL, H5EA__iblock_protect(H5EA_hdr_t *hdr, unsigned flags)) -/* Local variables */ -H5EA_iblock_t *iblock = NULL; /* Pointer to index block */ + /* Local variables */ + H5EA_iblock_t *iblock = NULL; /* Pointer to index block */ -/* Sanity check */ -HDassert(hdr); + /* Sanity check */ + HDassert(hdr); -/* only the H5AC__READ_ONLY_FLAG may be set */ -HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); + /* only the H5AC__READ_ONLY_FLAG may be set */ + HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); -/* Protect the index block */ -if (NULL == - (iblock = (H5EA_iblock_t *)H5AC_protect(hdr->f, H5AC_EARRAY_IBLOCK, hdr->idx_blk_addr, hdr, flags))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array index block, address = %llu", - (unsigned long long)hdr->idx_blk_addr) + /* Protect the index block */ + if (NULL == + (iblock = (H5EA_iblock_t *)H5AC_protect(hdr->f, H5AC_EARRAY_IBLOCK, hdr->idx_blk_addr, hdr, flags))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array index block, address = %llu", + (unsigned long long)hdr->idx_blk_addr) -/* Create top proxy, if it doesn't exist */ -if (hdr->top_proxy && NULL == iblock->top_proxy) { - /* Add index block as child of 'top' proxy */ - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, iblock) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") - iblock->top_proxy = hdr->top_proxy; -} /* end if */ - -/* Set return value */ -ret_value = iblock; - -CATCH -/* Clean up on error */ -if (!ret_value) { - /* Release the index block, if it was protected */ - if (iblock && H5AC_unprotect(hdr->f, H5AC_EARRAY_IBLOCK, iblock->addr, iblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array index block, address = %llu", - (unsigned long long)iblock->addr) -} /* end if */ + /* Create top proxy, if it doesn't exist */ + if (hdr->top_proxy && NULL == iblock->top_proxy) { + /* Add index block as child of 'top' proxy */ + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, iblock) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") + iblock->top_proxy = hdr->top_proxy; + } /* end if */ + + /* Set return value */ + ret_value = iblock; + + CATCH + /* Clean up on error */ + if (!ret_value) { + /* Release the index block, if it was protected */ + if (iblock && + H5AC_unprotect(hdr->f, H5AC_EARRAY_IBLOCK, iblock->addr, iblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array index block, address = %llu", + (unsigned long long)iblock->addr) + } /* end if */ END_FUNC(PKG) /* end H5EA__iblock_protect() */ @@ -314,17 +316,17 @@ END_FUNC(PKG) /* end H5EA__iblock_protect() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__iblock_unprotect(H5EA_iblock_t *iblock, unsigned cache_flags)) -/* Local variables */ + /* Local variables */ -/* Sanity check */ -HDassert(iblock); + /* Sanity check */ + HDassert(iblock); -/* Unprotect the index block */ -if (H5AC_unprotect(iblock->hdr->f, H5AC_EARRAY_IBLOCK, iblock->addr, iblock, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array index block, address = %llu", - (unsigned long long)iblock->addr) + /* Unprotect the index block */ + if (H5AC_unprotect(iblock->hdr->f, H5AC_EARRAY_IBLOCK, iblock->addr, iblock, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array index block, address = %llu", + (unsigned long long)iblock->addr) -CATCH + CATCH END_FUNC(PKG) /* end H5EA__iblock_unprotect() */ @@ -342,68 +344,69 @@ END_FUNC(PKG) /* end H5EA__iblock_unprotect() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__iblock_delete(H5EA_hdr_t *hdr)) -/* Local variables */ -H5EA_iblock_t *iblock = NULL; /* Pointer to index block */ - -/* Sanity check */ -HDassert(hdr); -HDassert(H5F_addr_defined(hdr->idx_blk_addr)); - -/* Protect index block */ -if (NULL == (iblock = H5EA__iblock_protect(hdr, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array index block, address = %llu", - (unsigned long long)hdr->idx_blk_addr) - -/* Check for index block having data block pointers */ -if (iblock->ndblk_addrs > 0) { - unsigned sblk_idx; /* Current super block index */ - unsigned dblk_idx; /* Current data block index w/in super block */ - size_t u; /* Local index variable */ - - /* Iterate over data blocks */ - sblk_idx = dblk_idx = 0; - for (u = 0; u < iblock->ndblk_addrs; u++) { - /* Check for data block existing */ - if (H5F_addr_defined(iblock->dblk_addrs[u])) { - /* Delete data block */ - if (H5EA__dblock_delete(hdr, iblock, iblock->dblk_addrs[u], - hdr->sblk_info[sblk_idx].dblk_nelmts) < 0) - H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array data block") - iblock->dblk_addrs[u] = HADDR_UNDEF; - } /* end if */ - - /* Advance to next data block w/in super block */ - dblk_idx++; - - /* Check for moving to next super block */ - if (dblk_idx >= hdr->sblk_info[sblk_idx].ndblks) { - sblk_idx++; - dblk_idx = 0; - } /* end if */ - } /* end for */ -} /* end if */ - -/* Check for index block having data block pointers (not yet) */ -if (iblock->nsblk_addrs > 0) { - size_t u; /* Local index variable */ - - /* Iterate over super blocks */ - for (u = 0; u < iblock->nsblk_addrs; u++) { - /* Check for data block existing */ - if (H5F_addr_defined(iblock->sblk_addrs[u])) { - /* Delete super block */ - if (H5EA__sblock_delete(hdr, iblock, iblock->sblk_addrs[u], (unsigned)(u + iblock->nsblks)) < 0) - H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array super block") - iblock->sblk_addrs[u] = HADDR_UNDEF; - } /* end if */ - } /* end for */ -} /* end if */ - -CATCH -/* Finished deleting index block in metadata cache */ -if (iblock && - H5EA__iblock_unprotect(iblock, H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array index block") + /* Local variables */ + H5EA_iblock_t *iblock = NULL; /* Pointer to index block */ + + /* Sanity check */ + HDassert(hdr); + HDassert(H5F_addr_defined(hdr->idx_blk_addr)); + + /* Protect index block */ + if (NULL == (iblock = H5EA__iblock_protect(hdr, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array index block, address = %llu", + (unsigned long long)hdr->idx_blk_addr) + + /* Check for index block having data block pointers */ + if (iblock->ndblk_addrs > 0) { + unsigned sblk_idx; /* Current super block index */ + unsigned dblk_idx; /* Current data block index w/in super block */ + size_t u; /* Local index variable */ + + /* Iterate over data blocks */ + sblk_idx = dblk_idx = 0; + for (u = 0; u < iblock->ndblk_addrs; u++) { + /* Check for data block existing */ + if (H5F_addr_defined(iblock->dblk_addrs[u])) { + /* Delete data block */ + if (H5EA__dblock_delete(hdr, iblock, iblock->dblk_addrs[u], + hdr->sblk_info[sblk_idx].dblk_nelmts) < 0) + H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array data block") + iblock->dblk_addrs[u] = HADDR_UNDEF; + } /* end if */ + + /* Advance to next data block w/in super block */ + dblk_idx++; + + /* Check for moving to next super block */ + if (dblk_idx >= hdr->sblk_info[sblk_idx].ndblks) { + sblk_idx++; + dblk_idx = 0; + } /* end if */ + } /* end for */ + } /* end if */ + + /* Check for index block having data block pointers (not yet) */ + if (iblock->nsblk_addrs > 0) { + size_t u; /* Local index variable */ + + /* Iterate over super blocks */ + for (u = 0; u < iblock->nsblk_addrs; u++) { + /* Check for data block existing */ + if (H5F_addr_defined(iblock->sblk_addrs[u])) { + /* Delete super block */ + if (H5EA__sblock_delete(hdr, iblock, iblock->sblk_addrs[u], (unsigned)(u + iblock->nsblks)) < + 0) + H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array super block") + iblock->sblk_addrs[u] = HADDR_UNDEF; + } /* end if */ + } /* end for */ + } /* end if */ + + CATCH + /* Finished deleting index block in metadata cache */ + if (iblock && H5EA__iblock_unprotect(iblock, H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | + H5AC__FREE_FILE_SPACE_FLAG) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array index block") END_FUNC(PKG) /* end H5EA__iblock_delete() */ @@ -421,46 +424,46 @@ END_FUNC(PKG) /* end H5EA__iblock_delete() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__iblock_dest(H5EA_iblock_t *iblock)) -/* Sanity check */ -HDassert(iblock); + /* Sanity check */ + HDassert(iblock); -/* Check if shared header field has been initialized */ -if (iblock->hdr) { - /* Check if we've got elements in the index block */ - if (iblock->elmts) { - /* Free buffer for index block elements */ - HDassert(iblock->hdr->cparam.idx_blk_elmts > 0); - iblock->elmts = H5FL_BLK_FREE(idx_blk_elmt_buf, iblock->elmts); - } /* end if */ + /* Check if shared header field has been initialized */ + if (iblock->hdr) { + /* Check if we've got elements in the index block */ + if (iblock->elmts) { + /* Free buffer for index block elements */ + HDassert(iblock->hdr->cparam.idx_blk_elmts > 0); + iblock->elmts = H5FL_BLK_FREE(idx_blk_elmt_buf, iblock->elmts); + } /* end if */ - /* Check if we've got data block addresses in the index block */ - if (iblock->dblk_addrs) { - /* Free buffer for index block data block addresses */ - HDassert(iblock->ndblk_addrs > 0); - iblock->dblk_addrs = H5FL_SEQ_FREE(haddr_t, iblock->dblk_addrs); - iblock->ndblk_addrs = 0; - } /* end if */ + /* Check if we've got data block addresses in the index block */ + if (iblock->dblk_addrs) { + /* Free buffer for index block data block addresses */ + HDassert(iblock->ndblk_addrs > 0); + iblock->dblk_addrs = H5FL_SEQ_FREE(haddr_t, iblock->dblk_addrs); + iblock->ndblk_addrs = 0; + } /* end if */ - /* Check if we've got super block addresses in the index block */ - if (iblock->sblk_addrs) { - /* Free buffer for index block super block addresses */ - HDassert(iblock->nsblk_addrs > 0); - iblock->sblk_addrs = H5FL_SEQ_FREE(haddr_t, iblock->sblk_addrs); - iblock->nsblk_addrs = 0; - } /* end if */ + /* Check if we've got super block addresses in the index block */ + if (iblock->sblk_addrs) { + /* Free buffer for index block super block addresses */ + HDassert(iblock->nsblk_addrs > 0); + iblock->sblk_addrs = H5FL_SEQ_FREE(haddr_t, iblock->sblk_addrs); + iblock->nsblk_addrs = 0; + } /* end if */ - /* Decrement reference count on shared info */ - if (H5EA__hdr_decr(iblock->hdr) < 0) - H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") - iblock->hdr = NULL; -} /* end if */ + /* Decrement reference count on shared info */ + if (H5EA__hdr_decr(iblock->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + iblock->hdr = NULL; + } /* end if */ -/* Sanity check */ -HDassert(NULL == iblock->top_proxy); + /* Sanity check */ + HDassert(NULL == iblock->top_proxy); -/* Free the index block itself */ -iblock = H5FL_FREE(H5EA_iblock_t, iblock); + /* Free the index block itself */ + iblock = H5FL_FREE(H5EA_iblock_t, iblock); -CATCH + CATCH END_FUNC(PKG) /* end H5EA__iblock_dest() */ diff --git a/src/H5EAint.c b/src/H5EAint.c index f1d988b..34b52d0 100644 --- a/src/H5EAint.c +++ b/src/H5EAint.c @@ -82,15 +82,15 @@ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__create_flush_depend(H5AC_info_t *parent_entry, H5AC_info_t *child_entry)) -/* Sanity check */ -HDassert(parent_entry); -HDassert(child_entry); + /* Sanity check */ + HDassert(parent_entry); + HDassert(child_entry); -/* Create a flush dependency between parent and child entry */ -if (H5AC_create_flush_dependency(parent_entry, child_entry) < 0) - H5E_THROW(H5E_CANTDEPEND, "unable to create flush dependency") + /* Create a flush dependency between parent and child entry */ + if (H5AC_create_flush_dependency(parent_entry, child_entry) < 0) + H5E_THROW(H5E_CANTDEPEND, "unable to create flush dependency") -CATCH + CATCH END_FUNC(PKG) /* end H5EA__create_flush_depend() */ @@ -109,14 +109,14 @@ END_FUNC(PKG) /* end H5EA__create_flush_depend() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__destroy_flush_depend(H5AC_info_t *parent_entry, H5AC_info_t *child_entry)) -/* Sanity check */ -HDassert(parent_entry); -HDassert(child_entry); + /* Sanity check */ + HDassert(parent_entry); + HDassert(child_entry); -/* Destroy a flush dependency between parent and child entry */ -if (H5AC_destroy_flush_dependency(parent_entry, child_entry) < 0) - H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency") + /* Destroy a flush dependency between parent and child entry */ + if (H5AC_destroy_flush_dependency(parent_entry, child_entry) < 0) + H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency") -CATCH + CATCH END_FUNC(PKG) /* end H5EA__destroy_flush_depend() */ diff --git a/src/H5EAsblock.c b/src/H5EAsblock.c index f48525f..304947b 100644 --- a/src/H5EAsblock.c +++ b/src/H5EAsblock.c @@ -94,66 +94,66 @@ H5FL_BLK_DEFINE(page_init); BEGIN_FUNC(PKG, ERR, H5EA_sblock_t *, NULL, NULL, H5EA__sblock_alloc(H5EA_hdr_t *hdr, H5EA_iblock_t *parent, unsigned sblk_idx)) -/* Local variables */ -H5EA_sblock_t *sblock = NULL; /* Extensible array super block */ + /* Local variables */ + H5EA_sblock_t *sblock = NULL; /* Extensible array super block */ -/* Check arguments */ -HDassert(hdr); + /* Check arguments */ + HDassert(hdr); -/* Allocate memory for the index block */ -if (NULL == (sblock = H5FL_CALLOC(H5EA_sblock_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array super block") + /* Allocate memory for the index block */ + if (NULL == (sblock = H5FL_CALLOC(H5EA_sblock_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array super block") -/* Share common array information */ -if (H5EA__hdr_incr(hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") -sblock->hdr = hdr; + /* Share common array information */ + if (H5EA__hdr_incr(hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") + sblock->hdr = hdr; -/* Set non-zero internal fields */ -sblock->parent = parent; -sblock->addr = HADDR_UNDEF; + /* Set non-zero internal fields */ + sblock->parent = parent; + sblock->addr = HADDR_UNDEF; -/* Compute/cache information */ -sblock->idx = sblk_idx; -sblock->ndblks = hdr->sblk_info[sblk_idx].ndblks; -HDassert(sblock->ndblks); -sblock->dblk_nelmts = hdr->sblk_info[sblk_idx].dblk_nelmts; + /* Compute/cache information */ + sblock->idx = sblk_idx; + sblock->ndblks = hdr->sblk_info[sblk_idx].ndblks; + HDassert(sblock->ndblks); + sblock->dblk_nelmts = hdr->sblk_info[sblk_idx].dblk_nelmts; -/* Allocate buffer for data block addresses in super block */ -if (NULL == (sblock->dblk_addrs = H5FL_SEQ_MALLOC(haddr_t, sblock->ndblks))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for super block data block addresses") + /* Allocate buffer for data block addresses in super block */ + if (NULL == (sblock->dblk_addrs = H5FL_SEQ_MALLOC(haddr_t, sblock->ndblks))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for super block data block addresses") -/* Check if # of elements in data blocks requires paging */ -if (sblock->dblk_nelmts > hdr->dblk_page_nelmts) { - /* Compute # of pages in each data block from this super block */ - sblock->dblk_npages = sblock->dblk_nelmts / hdr->dblk_page_nelmts; + /* Check if # of elements in data blocks requires paging */ + if (sblock->dblk_nelmts > hdr->dblk_page_nelmts) { + /* Compute # of pages in each data block from this super block */ + sblock->dblk_npages = sblock->dblk_nelmts / hdr->dblk_page_nelmts; - /* Sanity check that we have at least 2 pages in data block */ - HDassert(sblock->dblk_npages > 1); + /* Sanity check that we have at least 2 pages in data block */ + HDassert(sblock->dblk_npages > 1); - /* Sanity check for integer truncation */ - HDassert((sblock->dblk_npages * hdr->dblk_page_nelmts) == sblock->dblk_nelmts); + /* Sanity check for integer truncation */ + HDassert((sblock->dblk_npages * hdr->dblk_page_nelmts) == sblock->dblk_nelmts); - /* Compute size of buffer for each data block's 'page init' bitmask */ - sblock->dblk_page_init_size = ((sblock->dblk_npages) + 7) / 8; - HDassert(sblock->dblk_page_init_size > 0); + /* Compute size of buffer for each data block's 'page init' bitmask */ + sblock->dblk_page_init_size = ((sblock->dblk_npages) + 7) / 8; + HDassert(sblock->dblk_page_init_size > 0); - /* Allocate buffer for all 'page init' bitmasks in super block */ - if (NULL == - (sblock->page_init = H5FL_BLK_CALLOC(page_init, sblock->ndblks * sblock->dblk_page_init_size))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for super block page init bitmask") + /* Allocate buffer for all 'page init' bitmasks in super block */ + if (NULL == + (sblock->page_init = H5FL_BLK_CALLOC(page_init, sblock->ndblks * sblock->dblk_page_init_size))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for super block page init bitmask") - /* Compute data block page size */ - sblock->dblk_page_size = (hdr->dblk_page_nelmts * hdr->cparam.raw_elmt_size) + H5EA_SIZEOF_CHKSUM; -} /* end if */ + /* Compute data block page size */ + sblock->dblk_page_size = (hdr->dblk_page_nelmts * hdr->cparam.raw_elmt_size) + H5EA_SIZEOF_CHKSUM; + } /* end if */ -/* Set the return value */ -ret_value = sblock; + /* Set the return value */ + ret_value = sblock; -CATCH -if (!ret_value) - if (sblock && H5EA__sblock_dest(sblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array super block") + CATCH + if (!ret_value) + if (sblock && H5EA__sblock_dest(sblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array super block") END_FUNC(PKG) /* end H5EA__sblock_alloc() */ @@ -173,74 +173,74 @@ BEGIN_FUNC(PKG, ERR, haddr_t, HADDR_UNDEF, HADDR_UNDEF, H5EA__sblock_create(H5EA_hdr_t *hdr, H5EA_iblock_t *parent, hbool_t *stats_changed, unsigned sblk_idx)) -/* Local variables */ -H5EA_sblock_t *sblock = NULL; /* Extensible array super block */ -haddr_t sblock_addr; /* Extensible array super block address */ -haddr_t tmp_addr = HADDR_UNDEF; /* Address value to fill data block addresses with */ -hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ - -/* Sanity check */ -HDassert(hdr); -HDassert(stats_changed); - -/* Allocate the super block */ -if (NULL == (sblock = H5EA__sblock_alloc(hdr, parent, sblk_idx))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array super block") - -/* Set size of super block on disk */ -sblock->size = H5EA_SBLOCK_SIZE(sblock); - -/* Set offset of block in array's address space */ -sblock->block_off = hdr->sblk_info[sblk_idx].start_idx; - -/* Allocate space for the super block on disk */ -if (HADDR_UNDEF == (sblock_addr = H5MF_alloc(hdr->f, H5FD_MEM_EARRAY_SBLOCK, (hsize_t)sblock->size))) - H5E_THROW(H5E_CANTALLOC, "file allocation failed for extensible array super block") -sblock->addr = sblock_addr; - -/* Reset data block addresses to "undefined" address value */ -H5VM_array_fill(sblock->dblk_addrs, &tmp_addr, sizeof(haddr_t), sblock->ndblks); - -/* Cache the new extensible array super block */ -if (H5AC_insert_entry(hdr->f, H5AC_EARRAY_SBLOCK, sblock_addr, sblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTINSERT, "can't add extensible array super block to cache") -inserted = TRUE; - -/* Add super block as child of 'top' proxy */ -if (hdr->top_proxy) { - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, sblock) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") - sblock->top_proxy = hdr->top_proxy; -} /* end if */ - -/* Update extensible array super block statistics */ -hdr->stats.stored.nsuper_blks++; -hdr->stats.stored.super_blk_size += sblock->size; - -/* Mark the statistics as changed */ -*stats_changed = TRUE; - -/* Set address of super block to return */ -ret_value = sblock_addr; - -CATCH -if (!H5F_addr_defined(ret_value)) - if (sblock) { - /* Remove from cache, if inserted */ - if (inserted) - if (H5AC_remove_entry(sblock) < 0) - H5E_THROW(H5E_CANTREMOVE, "unable to remove extensible array super block from cache") - - /* Release super block's disk space */ - if (H5F_addr_defined(sblock->addr) && - H5MF_xfree(hdr->f, H5FD_MEM_EARRAY_SBLOCK, sblock->addr, (hsize_t)sblock->size) < 0) - H5E_THROW(H5E_CANTFREE, "unable to release extensible array super block") - - /* Destroy super block */ - if (H5EA__sblock_dest(sblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array super block") + /* Local variables */ + H5EA_sblock_t *sblock = NULL; /* Extensible array super block */ + haddr_t sblock_addr; /* Extensible array super block address */ + haddr_t tmp_addr = HADDR_UNDEF; /* Address value to fill data block addresses with */ + hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ + + /* Sanity check */ + HDassert(hdr); + HDassert(stats_changed); + + /* Allocate the super block */ + if (NULL == (sblock = H5EA__sblock_alloc(hdr, parent, sblk_idx))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for extensible array super block") + + /* Set size of super block on disk */ + sblock->size = H5EA_SBLOCK_SIZE(sblock); + + /* Set offset of block in array's address space */ + sblock->block_off = hdr->sblk_info[sblk_idx].start_idx; + + /* Allocate space for the super block on disk */ + if (HADDR_UNDEF == (sblock_addr = H5MF_alloc(hdr->f, H5FD_MEM_EARRAY_SBLOCK, (hsize_t)sblock->size))) + H5E_THROW(H5E_CANTALLOC, "file allocation failed for extensible array super block") + sblock->addr = sblock_addr; + + /* Reset data block addresses to "undefined" address value */ + H5VM_array_fill(sblock->dblk_addrs, &tmp_addr, sizeof(haddr_t), sblock->ndblks); + + /* Cache the new extensible array super block */ + if (H5AC_insert_entry(hdr->f, H5AC_EARRAY_SBLOCK, sblock_addr, sblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTINSERT, "can't add extensible array super block to cache") + inserted = TRUE; + + /* Add super block as child of 'top' proxy */ + if (hdr->top_proxy) { + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, sblock) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") + sblock->top_proxy = hdr->top_proxy; } /* end if */ + /* Update extensible array super block statistics */ + hdr->stats.stored.nsuper_blks++; + hdr->stats.stored.super_blk_size += sblock->size; + + /* Mark the statistics as changed */ + *stats_changed = TRUE; + + /* Set address of super block to return */ + ret_value = sblock_addr; + + CATCH + if (!H5F_addr_defined(ret_value)) + if (sblock) { + /* Remove from cache, if inserted */ + if (inserted) + if (H5AC_remove_entry(sblock) < 0) + H5E_THROW(H5E_CANTREMOVE, "unable to remove extensible array super block from cache") + + /* Release super block's disk space */ + if (H5F_addr_defined(sblock->addr) && + H5MF_xfree(hdr->f, H5FD_MEM_EARRAY_SBLOCK, sblock->addr, (hsize_t)sblock->size) < 0) + H5E_THROW(H5E_CANTFREE, "unable to release extensible array super block") + + /* Destroy super block */ + if (H5EA__sblock_dest(sblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy extensible array super block") + } /* end if */ + END_FUNC(PKG) /* end H5EA__sblock_create() */ /*------------------------------------------------------------------------- @@ -259,47 +259,49 @@ BEGIN_FUNC(PKG, ERR, H5EA_sblock_t *, NULL, NULL, H5EA__sblock_protect(H5EA_hdr_t *hdr, H5EA_iblock_t *parent, haddr_t sblk_addr, unsigned sblk_idx, unsigned flags)) -/* Local variables */ -H5EA_sblock_t * sblock = NULL; /* Pointer to super block */ -H5EA_sblock_cache_ud_t udata; /* Information needed for loading super block */ + /* Local variables */ + H5EA_sblock_t * sblock = NULL; /* Pointer to super block */ + H5EA_sblock_cache_ud_t udata; /* Information needed for loading super block */ -/* Sanity check */ -HDassert(hdr); -HDassert(H5F_addr_defined(sblk_addr)); + /* Sanity check */ + HDassert(hdr); + HDassert(H5F_addr_defined(sblk_addr)); -/* only the H5AC__READ_ONLY_FLAG may be set */ -HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); + /* only the H5AC__READ_ONLY_FLAG may be set */ + HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); -/* Set up user data */ -udata.hdr = hdr; -udata.parent = parent; -udata.sblk_idx = sblk_idx; -udata.sblk_addr = sblk_addr; + /* Set up user data */ + udata.hdr = hdr; + udata.parent = parent; + udata.sblk_idx = sblk_idx; + udata.sblk_addr = sblk_addr; -/* Protect the super block */ -if (NULL == (sblock = (H5EA_sblock_t *)H5AC_protect(hdr->f, H5AC_EARRAY_SBLOCK, sblk_addr, &udata, flags))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array super block, address = %llu", - (unsigned long long)sblk_addr) + /* Protect the super block */ + if (NULL == + (sblock = (H5EA_sblock_t *)H5AC_protect(hdr->f, H5AC_EARRAY_SBLOCK, sblk_addr, &udata, flags))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array super block, address = %llu", + (unsigned long long)sblk_addr) + + /* Create top proxy, if it doesn't exist */ + if (hdr->top_proxy && NULL == sblock->top_proxy) { + /* Add super block as child of 'top' proxy */ + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, sblock) < 0) + H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") + sblock->top_proxy = hdr->top_proxy; + } /* end if */ -/* Create top proxy, if it doesn't exist */ -if (hdr->top_proxy && NULL == sblock->top_proxy) { - /* Add super block as child of 'top' proxy */ - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, sblock) < 0) - H5E_THROW(H5E_CANTSET, "unable to add extensible array entry as child of array proxy") - sblock->top_proxy = hdr->top_proxy; -} /* end if */ - -/* Set return value */ -ret_value = sblock; - -CATCH -/* Clean up on error */ -if (!ret_value) { - /* Release the super block, if it was protected */ - if (sblock && H5AC_unprotect(hdr->f, H5AC_EARRAY_SBLOCK, sblock->addr, sblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array super block, address = %llu", - (unsigned long long)sblock->addr) -} /* end if */ + /* Set return value */ + ret_value = sblock; + + CATCH + /* Clean up on error */ + if (!ret_value) { + /* Release the super block, if it was protected */ + if (sblock && + H5AC_unprotect(hdr->f, H5AC_EARRAY_SBLOCK, sblock->addr, sblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array super block, address = %llu", + (unsigned long long)sblock->addr) + } /* end if */ END_FUNC(PKG) /* end H5EA__sblock_protect() */ @@ -318,17 +320,17 @@ END_FUNC(PKG) /* end H5EA__sblock_protect() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__sblock_unprotect(H5EA_sblock_t *sblock, unsigned cache_flags)) -/* Local variables */ + /* Local variables */ -/* Sanity check */ -HDassert(sblock); + /* Sanity check */ + HDassert(sblock); -/* Unprotect the super block */ -if (H5AC_unprotect(sblock->hdr->f, H5AC_EARRAY_SBLOCK, sblock->addr, sblock, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array super block, address = %llu", - (unsigned long long)sblock->addr) + /* Unprotect the super block */ + if (H5AC_unprotect(sblock->hdr->f, H5AC_EARRAY_SBLOCK, sblock->addr, sblock, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect extensible array super block, address = %llu", + (unsigned long long)sblock->addr) -CATCH + CATCH END_FUNC(PKG) /* end H5EA__sblock_unprotect() */ @@ -347,35 +349,35 @@ END_FUNC(PKG) /* end H5EA__sblock_unprotect() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__sblock_delete(H5EA_hdr_t *hdr, H5EA_iblock_t *parent, haddr_t sblk_addr, unsigned sblk_idx)) -/* Local variables */ -H5EA_sblock_t *sblock = NULL; /* Pointer to super block */ -size_t u; /* Local index variable */ - -/* Sanity check */ -HDassert(hdr); -HDassert(H5F_addr_defined(sblk_addr)); - -/* Protect super block */ -if (NULL == (sblock = H5EA__sblock_protect(hdr, parent, sblk_addr, sblk_idx, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array super block, address = %llu", - (unsigned long long)sblk_addr) - -/* Iterate over data blocks */ -for (u = 0; u < sblock->ndblks; u++) { - /* Check for data block existing */ - if (H5F_addr_defined(sblock->dblk_addrs[u])) { - /* Delete data block */ - if (H5EA__dblock_delete(hdr, sblock, sblock->dblk_addrs[u], sblock->dblk_nelmts) < 0) - H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array data block") - sblock->dblk_addrs[u] = HADDR_UNDEF; - } /* end if */ -} /* end for */ - -CATCH -/* Finished deleting super block in metadata cache */ -if (sblock && - H5EA__sblock_unprotect(sblock, H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array super block") + /* Local variables */ + H5EA_sblock_t *sblock = NULL; /* Pointer to super block */ + size_t u; /* Local index variable */ + + /* Sanity check */ + HDassert(hdr); + HDassert(H5F_addr_defined(sblk_addr)); + + /* Protect super block */ + if (NULL == (sblock = H5EA__sblock_protect(hdr, parent, sblk_addr, sblk_idx, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect extensible array super block, address = %llu", + (unsigned long long)sblk_addr) + + /* Iterate over data blocks */ + for (u = 0; u < sblock->ndblks; u++) { + /* Check for data block existing */ + if (H5F_addr_defined(sblock->dblk_addrs[u])) { + /* Delete data block */ + if (H5EA__dblock_delete(hdr, sblock, sblock->dblk_addrs[u], sblock->dblk_nelmts) < 0) + H5E_THROW(H5E_CANTDELETE, "unable to delete extensible array data block") + sblock->dblk_addrs[u] = HADDR_UNDEF; + } /* end if */ + } /* end for */ + + CATCH + /* Finished deleting super block in metadata cache */ + if (sblock && H5EA__sblock_unprotect(sblock, H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | + H5AC__FREE_FILE_SPACE_FLAG) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release extensible array super block") END_FUNC(PKG) /* end H5EA__sblock_delete() */ @@ -393,34 +395,34 @@ END_FUNC(PKG) /* end H5EA__sblock_delete() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5EA__sblock_dest(H5EA_sblock_t *sblock)) -/* Sanity check */ -HDassert(sblock); -HDassert(!sblock->has_hdr_depend); - -/* Check if shared header field has been initialized */ -if (sblock->hdr) { - /* Free buffer for super block data block addresses, if there are any */ - if (sblock->dblk_addrs) - sblock->dblk_addrs = H5FL_SEQ_FREE(haddr_t, sblock->dblk_addrs); - - /* Free buffer for super block 'page init' bitmask, if there is one */ - if (sblock->page_init) { - HDassert(sblock->dblk_npages > 0); - sblock->page_init = H5FL_BLK_FREE(page_init, sblock->page_init); + /* Sanity check */ + HDassert(sblock); + HDassert(!sblock->has_hdr_depend); + + /* Check if shared header field has been initialized */ + if (sblock->hdr) { + /* Free buffer for super block data block addresses, if there are any */ + if (sblock->dblk_addrs) + sblock->dblk_addrs = H5FL_SEQ_FREE(haddr_t, sblock->dblk_addrs); + + /* Free buffer for super block 'page init' bitmask, if there is one */ + if (sblock->page_init) { + HDassert(sblock->dblk_npages > 0); + sblock->page_init = H5FL_BLK_FREE(page_init, sblock->page_init); + } /* end if */ + + /* Decrement reference count on shared info */ + if (H5EA__hdr_decr(sblock->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + sblock->hdr = NULL; } /* end if */ - /* Decrement reference count on shared info */ - if (H5EA__hdr_decr(sblock->hdr) < 0) - H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") - sblock->hdr = NULL; -} /* end if */ - -/* Sanity check */ -HDassert(NULL == sblock->top_proxy); + /* Sanity check */ + HDassert(NULL == sblock->top_proxy); -/* Free the super block itself */ -sblock = H5FL_FREE(H5EA_sblock_t, sblock); + /* Free the super block itself */ + sblock = H5FL_FREE(H5EA_sblock_t, sblock); -CATCH + CATCH END_FUNC(PKG) /* end H5EA__sblock_dest() */ diff --git a/src/H5EAstat.c b/src/H5EAstat.c index 1e0197d..35a2462 100644 --- a/src/H5EAstat.c +++ b/src/H5EAstat.c @@ -82,15 +82,15 @@ */ BEGIN_FUNC(PRIV, NOERR, herr_t, SUCCEED, -, H5EA_get_stats(const H5EA_t *ea, H5EA_stat_t *stats)) -/* Local variables */ + /* Local variables */ -/* - * Check arguments. - */ -HDassert(ea); -HDassert(stats); + /* + * Check arguments. + */ + HDassert(ea); + HDassert(stats); -/* Copy extensible array statistics */ -H5MM_memcpy(stats, &ea->hdr->stats, sizeof(ea->hdr->stats)); + /* Copy extensible array statistics */ + H5MM_memcpy(stats, &ea->hdr->stats, sizeof(ea->hdr->stats)); END_FUNC(PRIV) /* end H5EA_get_stats() */ diff --git a/src/H5EAtest.c b/src/H5EAtest.c index 9442cd9..0a85729 100644 --- a/src/H5EAtest.c +++ b/src/H5EAtest.c @@ -121,24 +121,24 @@ H5FL_DEFINE_STATIC(H5EA__ctx_cb_t); */ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5EA__test_crt_context(void *_udata)) -/* Local variables */ -H5EA__test_ctx_t *ctx; /* Context for callbacks */ -H5EA__ctx_cb_t * udata = (H5EA__ctx_cb_t *)_udata; /* User data for context */ + /* Local variables */ + H5EA__test_ctx_t *ctx; /* Context for callbacks */ + H5EA__ctx_cb_t * udata = (H5EA__ctx_cb_t *)_udata; /* User data for context */ -/* Sanity checks */ + /* Sanity checks */ -/* Allocate new context structure */ -if (NULL == (ctx = H5FL_MALLOC(H5EA__test_ctx_t))) - H5E_THROW(H5E_CANTALLOC, "can't allocate extensible array client callback context") + /* Allocate new context structure */ + if (NULL == (ctx = H5FL_MALLOC(H5EA__test_ctx_t))) + H5E_THROW(H5E_CANTALLOC, "can't allocate extensible array client callback context") -/* Initialize the context */ -ctx->bogus = H5EA__TEST_BOGUS_VAL; -ctx->cb = udata; + /* Initialize the context */ + ctx->bogus = H5EA__TEST_BOGUS_VAL; + ctx->cb = udata; -/* Set return value */ -ret_value = ctx; + /* Set return value */ + ret_value = ctx; -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__test_crt_context() */ @@ -157,14 +157,14 @@ END_FUNC(STATIC) /* end H5EA__test_crt_context() */ */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__test_dst_context(void *_ctx)) -/* Local variables */ -H5EA__test_ctx_t *ctx = (H5EA__test_ctx_t *)_ctx; /* Callback context to destroy */ + /* Local variables */ + H5EA__test_ctx_t *ctx = (H5EA__test_ctx_t *)_ctx; /* Callback context to destroy */ -/* Sanity checks */ -HDassert(H5EA__TEST_BOGUS_VAL == ctx->bogus); + /* Sanity checks */ + HDassert(H5EA__TEST_BOGUS_VAL == ctx->bogus); -/* Release context structure */ -ctx = H5FL_FREE(H5EA__test_ctx_t, ctx); + /* Release context structure */ + ctx = H5FL_FREE(H5EA__test_ctx_t, ctx); END_FUNC(STATIC) /* end H5EA__test_dst_context() */ @@ -183,14 +183,14 @@ END_FUNC(STATIC) /* end H5EA__test_dst_context() */ */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__test_fill(void *nat_blk, size_t nelmts)) -/* Local variables */ -uint64_t fill_val = H5EA_TEST_FILL; /* Value to fill elements with */ + /* Local variables */ + uint64_t fill_val = H5EA_TEST_FILL; /* Value to fill elements with */ -/* Sanity checks */ -HDassert(nat_blk); -HDassert(nelmts); + /* Sanity checks */ + HDassert(nat_blk); + HDassert(nelmts); -H5VM_array_fill(nat_blk, &fill_val, sizeof(uint64_t), nelmts); + H5VM_array_fill(nat_blk, &fill_val, sizeof(uint64_t), nelmts); END_FUNC(STATIC) /* end H5EA__test_fill() */ @@ -210,36 +210,36 @@ END_FUNC(STATIC) /* end H5EA__test_fill() */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5EA__test_encode(void *raw, const void *_elmt, size_t nelmts, void *_ctx)) -/* Local variables */ -H5EA__test_ctx_t *ctx = (H5EA__test_ctx_t *)_ctx; /* Callback context to destroy */ -const uint64_t * elmt = (const uint64_t *)_elmt; /* Convenience pointer to native elements */ + /* Local variables */ + H5EA__test_ctx_t *ctx = (H5EA__test_ctx_t *)_ctx; /* Callback context to destroy */ + const uint64_t * elmt = (const uint64_t *)_elmt; /* Convenience pointer to native elements */ -/* Sanity checks */ -HDassert(raw); -HDassert(elmt); -HDassert(nelmts); -HDassert(H5EA__TEST_BOGUS_VAL == ctx->bogus); + /* Sanity checks */ + HDassert(raw); + HDassert(elmt); + HDassert(nelmts); + HDassert(H5EA__TEST_BOGUS_VAL == ctx->bogus); -/* Check for callback action */ -if (ctx->cb) { - if ((*ctx->cb->encode)(elmt, nelmts, ctx->cb->udata) < 0) - H5E_THROW(H5E_BADVALUE, "extensible array testing callback action failed") -} /* end if */ + /* Check for callback action */ + if (ctx->cb) { + if ((*ctx->cb->encode)(elmt, nelmts, ctx->cb->udata) < 0) + H5E_THROW(H5E_BADVALUE, "extensible array testing callback action failed") + } /* end if */ -/* Encode native elements into raw elements */ -while (nelmts) { - /* Encode element */ - /* (advances 'raw' pointer) */ - UINT64ENCODE(raw, *elmt); + /* Encode native elements into raw elements */ + while (nelmts) { + /* Encode element */ + /* (advances 'raw' pointer) */ + UINT64ENCODE(raw, *elmt); - /* Advance native element pointer */ - elmt++; + /* Advance native element pointer */ + elmt++; - /* Decrement # of elements to encode */ - nelmts--; -} /* end while */ + /* Decrement # of elements to encode */ + nelmts--; + } /* end while */ -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__test_encode() */ @@ -261,29 +261,29 @@ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, /* Local variables */ #ifndef NDEBUG -H5EA__test_ctx_t *ctx = (H5EA__test_ctx_t *)_ctx; /* Callback context to destroy */ -#endif /* NDEBUG */ -uint64_t * elmt = (uint64_t *)_elmt; /* Convenience pointer to native elements */ -const uint8_t *raw = (const uint8_t *)_raw; /* Convenience pointer to raw elements */ - -/* Sanity checks */ -HDassert(raw); -HDassert(elmt); -HDassert(nelmts); -HDassert(H5EA__TEST_BOGUS_VAL == ctx->bogus); - -/* Decode raw elements into native elements */ -while (nelmts) { - /* Decode element */ - /* (advances 'raw' pointer) */ - UINT64DECODE(raw, *elmt); - - /* Advance native element pointer */ - elmt++; - - /* Decrement # of elements to decode */ - nelmts--; -} /* end while */ + H5EA__test_ctx_t *ctx = (H5EA__test_ctx_t *)_ctx; /* Callback context to destroy */ +#endif /* NDEBUG */ + uint64_t * elmt = (uint64_t *)_elmt; /* Convenience pointer to native elements */ + const uint8_t *raw = (const uint8_t *)_raw; /* Convenience pointer to raw elements */ + + /* Sanity checks */ + HDassert(raw); + HDassert(elmt); + HDassert(nelmts); + HDassert(H5EA__TEST_BOGUS_VAL == ctx->bogus); + + /* Decode raw elements into native elements */ + while (nelmts) { + /* Decode element */ + /* (advances 'raw' pointer) */ + UINT64DECODE(raw, *elmt); + + /* Advance native element pointer */ + elmt++; + + /* Decrement # of elements to decode */ + nelmts--; + } /* end while */ END_FUNC(STATIC) /* end H5EA__test_decode() */ @@ -303,17 +303,17 @@ END_FUNC(STATIC) /* end H5EA__test_decode() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__test_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const void *elmt)) -/* Local variables */ -char temp_str[128]; /* Temporary string, for formatting */ + /* Local variables */ + char temp_str[128]; /* Temporary string, for formatting */ -/* Sanity checks */ -HDassert(stream); -HDassert(elmt); + /* Sanity checks */ + HDassert(stream); + HDassert(elmt); -/* Print element */ -HDsprintf(temp_str, "Element #%llu:", (unsigned long long)idx); -HDfprintf(stream, "%*s%-*s %llu\n", indent, "", fwidth, temp_str, - (unsigned long long)*(const uint64_t *)elmt); + /* Print element */ + HDsprintf(temp_str, "Element #%llu:", (unsigned long long)idx); + HDfprintf(stream, "%*s%-*s %llu\n", indent, "", fwidth, temp_str, + (unsigned long long)*(const uint64_t *)elmt); END_FUNC(STATIC) /* end H5EA__test_debug() */ @@ -332,17 +332,17 @@ END_FUNC(STATIC) /* end H5EA__test_debug() */ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5EA__test_crt_dbg_context(H5F_t H5_ATTR_UNUSED *f, haddr_t H5_ATTR_UNUSED obj_addr)) -/* Local variables */ -H5EA__ctx_cb_t *ctx; /* Context for callbacks */ + /* Local variables */ + H5EA__ctx_cb_t *ctx; /* Context for callbacks */ -/* Allocate new context structure */ -if (NULL == (ctx = H5FL_MALLOC(H5EA__ctx_cb_t))) - H5E_THROW(H5E_CANTALLOC, "can't allocate extensible array client callback context") + /* Allocate new context structure */ + if (NULL == (ctx = H5FL_MALLOC(H5EA__ctx_cb_t))) + H5E_THROW(H5E_CANTALLOC, "can't allocate extensible array client callback context") -/* Set return value */ -ret_value = ctx; + /* Set return value */ + ret_value = ctx; -CATCH + CATCH END_FUNC(STATIC) /* end H5EA__test_crt_dbg_context() */ @@ -360,13 +360,13 @@ END_FUNC(STATIC) /* end H5EA__test_crt_dbg_context() */ */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5EA__test_dst_dbg_context(void *_ctx)) -/* Local variables */ -H5EA__ctx_cb_t *ctx = (H5EA__ctx_cb_t *)_ctx; /* Callback context to destroy */ + /* Local variables */ + H5EA__ctx_cb_t *ctx = (H5EA__ctx_cb_t *)_ctx; /* Callback context to destroy */ -HDassert(_ctx); + HDassert(_ctx); -/* Release context structure */ -ctx = H5FL_FREE(H5EA__ctx_cb_t, ctx); + /* Release context structure */ + ctx = H5FL_FREE(H5EA__ctx_cb_t, ctx); END_FUNC(STATIC) /* end H5EA__test_dst_dbg_context() */ @@ -385,17 +385,17 @@ END_FUNC(STATIC) /* end H5EA__test_dst_dbg_context() */ */ BEGIN_FUNC(PKG, NOERR, herr_t, SUCCEED, -, H5EA__get_cparam_test(const H5EA_t *ea, H5EA_create_t *cparam)) -/* Check arguments. */ -HDassert(ea); -HDassert(cparam); + /* Check arguments. */ + HDassert(ea); + HDassert(cparam); -/* Get extensible array creation parameters */ -cparam->raw_elmt_size = ea->hdr->cparam.raw_elmt_size; -cparam->max_nelmts_bits = ea->hdr->cparam.max_nelmts_bits; -cparam->idx_blk_elmts = ea->hdr->cparam.idx_blk_elmts; -cparam->sup_blk_min_data_ptrs = ea->hdr->cparam.sup_blk_min_data_ptrs; -cparam->data_blk_min_elmts = ea->hdr->cparam.data_blk_min_elmts; -cparam->max_dblk_page_nelmts_bits = ea->hdr->cparam.max_dblk_page_nelmts_bits; + /* Get extensible array creation parameters */ + cparam->raw_elmt_size = ea->hdr->cparam.raw_elmt_size; + cparam->max_nelmts_bits = ea->hdr->cparam.max_nelmts_bits; + cparam->idx_blk_elmts = ea->hdr->cparam.idx_blk_elmts; + cparam->sup_blk_min_data_ptrs = ea->hdr->cparam.sup_blk_min_data_ptrs; + cparam->data_blk_min_elmts = ea->hdr->cparam.data_blk_min_elmts; + cparam->max_dblk_page_nelmts_bits = ea->hdr->cparam.max_dblk_page_nelmts_bits; END_FUNC(PKG) /* end H5EA__get_cparam_test() */ @@ -415,36 +415,36 @@ END_FUNC(PKG) /* end H5EA__get_cparam_test() */ BEGIN_FUNC(PKG, ERRCATCH, int, 0, -, H5EA__cmp_cparam_test(const H5EA_create_t *cparam1, const H5EA_create_t *cparam2)) -/* Check arguments. */ -HDassert(cparam1); -HDassert(cparam2); - -/* Compare creation parameters for array */ -if (cparam1->raw_elmt_size < cparam2->raw_elmt_size) - H5_LEAVE(-1) -else if (cparam1->raw_elmt_size > cparam2->raw_elmt_size) - H5_LEAVE(1) -if (cparam1->max_nelmts_bits < cparam2->max_nelmts_bits) - H5_LEAVE(-1) -else if (cparam1->max_nelmts_bits > cparam2->max_nelmts_bits) - H5_LEAVE(1) -if (cparam1->idx_blk_elmts < cparam2->idx_blk_elmts) - H5_LEAVE(-1) -else if (cparam1->idx_blk_elmts > cparam2->idx_blk_elmts) - H5_LEAVE(1) -if (cparam1->sup_blk_min_data_ptrs < cparam2->sup_blk_min_data_ptrs) - H5_LEAVE(-1) -else if (cparam1->sup_blk_min_data_ptrs > cparam2->sup_blk_min_data_ptrs) - H5_LEAVE(1) -if (cparam1->data_blk_min_elmts < cparam2->data_blk_min_elmts) - H5_LEAVE(-1) -else if (cparam1->data_blk_min_elmts > cparam2->data_blk_min_elmts) - H5_LEAVE(1) -if (cparam1->max_dblk_page_nelmts_bits < cparam2->max_dblk_page_nelmts_bits) - H5_LEAVE(-1) -else if (cparam1->max_dblk_page_nelmts_bits > cparam2->max_dblk_page_nelmts_bits) - H5_LEAVE(1) - -CATCH + /* Check arguments. */ + HDassert(cparam1); + HDassert(cparam2); + + /* Compare creation parameters for array */ + if (cparam1->raw_elmt_size < cparam2->raw_elmt_size) + H5_LEAVE(-1) + else if (cparam1->raw_elmt_size > cparam2->raw_elmt_size) + H5_LEAVE(1) + if (cparam1->max_nelmts_bits < cparam2->max_nelmts_bits) + H5_LEAVE(-1) + else if (cparam1->max_nelmts_bits > cparam2->max_nelmts_bits) + H5_LEAVE(1) + if (cparam1->idx_blk_elmts < cparam2->idx_blk_elmts) + H5_LEAVE(-1) + else if (cparam1->idx_blk_elmts > cparam2->idx_blk_elmts) + H5_LEAVE(1) + if (cparam1->sup_blk_min_data_ptrs < cparam2->sup_blk_min_data_ptrs) + H5_LEAVE(-1) + else if (cparam1->sup_blk_min_data_ptrs > cparam2->sup_blk_min_data_ptrs) + H5_LEAVE(1) + if (cparam1->data_blk_min_elmts < cparam2->data_blk_min_elmts) + H5_LEAVE(-1) + else if (cparam1->data_blk_min_elmts > cparam2->data_blk_min_elmts) + H5_LEAVE(1) + if (cparam1->max_dblk_page_nelmts_bits < cparam2->max_dblk_page_nelmts_bits) + H5_LEAVE(-1) + else if (cparam1->max_dblk_page_nelmts_bits > cparam2->max_dblk_page_nelmts_bits) + H5_LEAVE(1) + + CATCH END_FUNC(PKG) /* end H5EA__cmp_cparam_test() */ @@ -108,50 +108,50 @@ H5FL_BLK_DEFINE(fa_native_elmt); BEGIN_FUNC(STATIC, ERR, H5FA_t *, NULL, NULL, H5FA__new(H5F_t *f, haddr_t fa_addr, hbool_t from_open, void *ctx_udata)) -/* Local variables */ -H5FA_t * fa = NULL; /* Pointer to new fixed array */ -H5FA_hdr_t *hdr = NULL; /* The fixed array header information */ + /* Local variables */ + H5FA_t * fa = NULL; /* Pointer to new fixed array */ + H5FA_hdr_t *hdr = NULL; /* The fixed array header information */ -/* - * Check arguments. - */ -HDassert(f); -HDassert(H5F_addr_defined(fa_addr)); + /* + * Check arguments. + */ + HDassert(f); + HDassert(H5F_addr_defined(fa_addr)); -/* Allocate fixed array wrapper */ -if (NULL == (fa = H5FL_CALLOC(H5FA_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array info") + /* Allocate fixed array wrapper */ + if (NULL == (fa = H5FL_CALLOC(H5FA_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array info") -/* Lock the array header into memory */ -if (NULL == (hdr = H5FA__hdr_protect(f, fa_addr, ctx_udata, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load fixed array header") + /* Lock the array header into memory */ + if (NULL == (hdr = H5FA__hdr_protect(f, fa_addr, ctx_udata, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load fixed array header") -/* Check for pending array deletion */ -if (from_open && hdr->pending_delete) - H5E_THROW(H5E_CANTOPENOBJ, "can't open fixed array pending deletion") + /* Check for pending array deletion */ + if (from_open && hdr->pending_delete) + H5E_THROW(H5E_CANTOPENOBJ, "can't open fixed array pending deletion") -/* Point fixed array wrapper at header and bump it's ref count */ -fa->hdr = hdr; -if (H5FA__hdr_incr(fa->hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") + /* Point fixed array wrapper at header and bump it's ref count */ + fa->hdr = hdr; + if (H5FA__hdr_incr(fa->hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") -/* Increment # of files using this array header */ -if (H5FA__hdr_fuse_incr(fa->hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment file reference count on shared array header") + /* Increment # of files using this array header */ + if (H5FA__hdr_fuse_incr(fa->hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment file reference count on shared array header") -/* Set file pointer for this array open context */ -fa->f = f; + /* Set file pointer for this array open context */ + fa->f = f; -/* Set the return value */ -ret_value = fa; + /* Set the return value */ + ret_value = fa; -CATCH + CATCH -if (hdr && H5FA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array header") -if (!ret_value) - if (fa && H5FA_close(fa) < 0) - H5E_THROW(H5E_CLOSEERROR, "unable to close fixed array") + if (hdr && H5FA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array header") + if (!ret_value) + if (fa && H5FA_close(fa) < 0) + H5E_THROW(H5E_CLOSEERROR, "unable to close fixed array") END_FUNC(STATIC) /* end H5FA__new() */ @@ -171,35 +171,35 @@ END_FUNC(STATIC) /* end H5FA__new() */ BEGIN_FUNC(PRIV, ERR, H5FA_t *, NULL, NULL, H5FA_create(H5F_t *f, const H5FA_create_t *cparam, void *ctx_udata)) -/* Local variables */ -H5FA_t *fa = NULL; /* Pointer to new fixed array */ -haddr_t fa_addr; /* Fixed array header address */ + /* Local variables */ + H5FA_t *fa = NULL; /* Pointer to new fixed array */ + haddr_t fa_addr; /* Fixed array header address */ -/* - * Check arguments. - */ -HDassert(f); -HDassert(cparam); + /* + * Check arguments. + */ + HDassert(f); + HDassert(cparam); -/* H5FA interface sanity check */ -HDcompile_assert(H5FA_NUM_CLS_ID == NELMTS(H5FA_client_class_g)); + /* H5FA interface sanity check */ + HDcompile_assert(H5FA_NUM_CLS_ID == NELMTS(H5FA_client_class_g)); -/* Create fixed array header */ -if (HADDR_UNDEF == (fa_addr = H5FA__hdr_create(f, cparam, ctx_udata))) - H5E_THROW(H5E_CANTINIT, "can't create fixed array header") + /* Create fixed array header */ + if (HADDR_UNDEF == (fa_addr = H5FA__hdr_create(f, cparam, ctx_udata))) + H5E_THROW(H5E_CANTINIT, "can't create fixed array header") -/* Allocate and initialize new fixed array wrapper */ -if (NULL == (fa = H5FA__new(f, fa_addr, FALSE, ctx_udata))) - H5E_THROW(H5E_CANTINIT, "allocation and/or initialization failed for fixed array wrapper") + /* Allocate and initialize new fixed array wrapper */ + if (NULL == (fa = H5FA__new(f, fa_addr, FALSE, ctx_udata))) + H5E_THROW(H5E_CANTINIT, "allocation and/or initialization failed for fixed array wrapper") -/* Set the return value */ -ret_value = fa; + /* Set the return value */ + ret_value = fa; -CATCH + CATCH -if (!ret_value) - if (fa && H5FA_close(fa) < 0) - H5E_THROW(H5E_CLOSEERROR, "unable to close fixed array") + if (!ret_value) + if (fa && H5FA_close(fa) < 0) + H5E_THROW(H5E_CLOSEERROR, "unable to close fixed array") END_FUNC(PRIV) /* end H5FA_create() */ @@ -218,27 +218,27 @@ END_FUNC(PRIV) /* end H5FA_create() */ */ BEGIN_FUNC(PRIV, ERR, H5FA_t *, NULL, NULL, H5FA_open(H5F_t *f, haddr_t fa_addr, void *ctx_udata)) -/* Local variables */ -H5FA_t *fa = NULL; /* Pointer to new fixed array wrapper */ + /* Local variables */ + H5FA_t *fa = NULL; /* Pointer to new fixed array wrapper */ -/* - * Check arguments. - */ -HDassert(f); -HDassert(H5F_addr_defined(fa_addr)); + /* + * Check arguments. + */ + HDassert(f); + HDassert(H5F_addr_defined(fa_addr)); -/* Allocate and initialize new fixed array wrapper */ -if (NULL == (fa = H5FA__new(f, fa_addr, TRUE, ctx_udata))) - H5E_THROW(H5E_CANTINIT, "allocation and/or initialization failed for fixed array wrapper") + /* Allocate and initialize new fixed array wrapper */ + if (NULL == (fa = H5FA__new(f, fa_addr, TRUE, ctx_udata))) + H5E_THROW(H5E_CANTINIT, "allocation and/or initialization failed for fixed array wrapper") -/* Set the return value */ -ret_value = fa; + /* Set the return value */ + ret_value = fa; -CATCH + CATCH -if (!ret_value) - if (fa && H5FA_close(fa) < 0) - H5E_THROW(H5E_CLOSEERROR, "unable to close fixed array") + if (!ret_value) + if (fa && H5FA_close(fa) < 0) + H5E_THROW(H5E_CLOSEERROR, "unable to close fixed array") END_FUNC(PRIV) /* end H5FA_open() */ @@ -256,16 +256,16 @@ END_FUNC(PRIV) /* end H5FA_open() */ */ BEGIN_FUNC(PRIV, NOERR, herr_t, SUCCEED, -, H5FA_get_nelmts(const H5FA_t *fa, hsize_t *nelmts)) -/* Local variables */ + /* Local variables */ -/* - * Check arguments. - */ -HDassert(fa); -HDassert(nelmts); + /* + * Check arguments. + */ + HDassert(fa); + HDassert(nelmts); -/* Retrieve the current number of elements in the fixed array */ -*nelmts = fa->hdr->stats.nelmts; + /* Retrieve the current number of elements in the fixed array */ + *nelmts = fa->hdr->stats.nelmts; END_FUNC(PRIV) /* end H5FA_get_nelmts() */ @@ -283,17 +283,17 @@ END_FUNC(PRIV) /* end H5FA_get_nelmts() */ */ BEGIN_FUNC(PRIV, NOERR, herr_t, SUCCEED, -, H5FA_get_addr(const H5FA_t *fa, haddr_t *addr)) -/* Local variables */ + /* Local variables */ -/* - * Check arguments. - */ -HDassert(fa); -HDassert(fa->hdr); -HDassert(addr); + /* + * Check arguments. + */ + HDassert(fa); + HDassert(fa->hdr); + HDassert(addr); -/* Retrieve the address of the fixed array's header */ -*addr = fa->hdr->addr; + /* Retrieve the address of the fixed array's header */ + *addr = fa->hdr->addr; END_FUNC(PRIV) /* end H5FA_get_addr() */ @@ -311,99 +311,100 @@ END_FUNC(PRIV) /* end H5FA_get_addr() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5FA_set(const H5FA_t *fa, hsize_t idx, const void *elmt)) -/* Local variables */ -H5FA_hdr_t * hdr = fa->hdr; /* Header for fixed array */ -H5FA_dblock_t * dblock = NULL; /* Pointer to fixed array Data block */ -H5FA_dblk_page_t *dblk_page = NULL; /* Pointer to fixed array Data block page */ -unsigned dblock_cache_flags = H5AC__NO_FLAGS_SET; /* Flags to unprotecting fixed array Data block */ -unsigned dblk_page_cache_flags = H5AC__NO_FLAGS_SET; /* Flags to unprotecting FIxed Array Data block page */ -hbool_t hdr_dirty = FALSE; /* Whether header information changed */ + /* Local variables */ + H5FA_hdr_t * hdr = fa->hdr; /* Header for fixed array */ + H5FA_dblock_t * dblock = NULL; /* Pointer to fixed array Data block */ + H5FA_dblk_page_t *dblk_page = NULL; /* Pointer to fixed array Data block page */ + unsigned dblock_cache_flags = H5AC__NO_FLAGS_SET; /* Flags to unprotecting fixed array Data block */ + unsigned dblk_page_cache_flags = + H5AC__NO_FLAGS_SET; /* Flags to unprotecting FIxed Array Data block page */ + hbool_t hdr_dirty = FALSE; /* Whether header information changed */ + + /* + * Check arguments. + */ + HDassert(fa); + HDassert(fa->hdr); -/* - * Check arguments. - */ -HDassert(fa); -HDassert(fa->hdr); - -/* Set the shared array header's file context for this operation */ -hdr->f = fa->f; - -/* Check if we need to create the fixed array data block */ -if (!H5F_addr_defined(hdr->dblk_addr)) { - /* Create the data block */ - hdr->dblk_addr = H5FA__dblock_create(hdr, &hdr_dirty); - if (!H5F_addr_defined(hdr->dblk_addr)) - H5E_THROW(H5E_CANTCREATE, "unable to create fixed array data block") -} /* end if */ - -HDassert(idx < hdr->cparam.nelmts); - -/* Protect data block */ -if (NULL == (dblock = H5FA__dblock_protect(hdr, hdr->dblk_addr, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block, address = %llu", - (unsigned long long)hdr->dblk_addr) - -/* Check for paging data block */ -if (!dblock->npages) { - /* Set element in data block */ - H5MM_memcpy(((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * idx), elmt, - hdr->cparam.cls->nat_elmt_size); - dblock_cache_flags |= H5AC__DIRTIED_FLAG; -} /* end if */ -else { /* paging */ - size_t page_idx; /* Index of page within data block */ - size_t dblk_page_nelmts; /* # of elements in a data block page */ - size_t elmt_idx; /* Element index within the page */ - haddr_t dblk_page_addr; /* Address of data block page */ - - /* Compute the page & element index */ - page_idx = (size_t)(idx / dblock->dblk_page_nelmts); - elmt_idx = (size_t)(idx % dblock->dblk_page_nelmts); - - /* Get the address of the data block page */ - dblk_page_addr = - dblock->addr + H5FA_DBLOCK_PREFIX_SIZE(dblock) + ((hsize_t)page_idx * dblock->dblk_page_size); - - /* Check for using last page, to set the number of elements on the page */ - if ((page_idx + 1) == dblock->npages) - dblk_page_nelmts = dblock->last_page_nelmts; - else - dblk_page_nelmts = dblock->dblk_page_nelmts; - - /* Check if the page has been created yet */ - if (!H5VM_bit_get(dblock->dblk_page_init, page_idx)) { - /* Create the data block page */ - if (H5FA__dblk_page_create(hdr, dblk_page_addr, dblk_page_nelmts) < 0) - H5E_THROW(H5E_CANTCREATE, "unable to create data block page") - - /* Mark data block page as initialized in data block */ - H5VM_bit_set(dblock->dblk_page_init, page_idx, TRUE); - dblock_cache_flags |= H5AC__DIRTIED_FLAG; + /* Set the shared array header's file context for this operation */ + hdr->f = fa->f; + + /* Check if we need to create the fixed array data block */ + if (!H5F_addr_defined(hdr->dblk_addr)) { + /* Create the data block */ + hdr->dblk_addr = H5FA__dblock_create(hdr, &hdr_dirty); + if (!H5F_addr_defined(hdr->dblk_addr)) + H5E_THROW(H5E_CANTCREATE, "unable to create fixed array data block") } /* end if */ - /* Protect the data block page */ - if (NULL == - (dblk_page = H5FA__dblk_page_protect(hdr, dblk_page_addr, dblk_page_nelmts, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block page, address = %llu", - (unsigned long long)dblk_page_addr) - - /* Set the element in the data block page */ - H5MM_memcpy(((uint8_t *)dblk_page->elmts) + (hdr->cparam.cls->nat_elmt_size * elmt_idx), elmt, - hdr->cparam.cls->nat_elmt_size); - dblk_page_cache_flags |= H5AC__DIRTIED_FLAG; -} /* end else */ - -CATCH -/* Check for header modified */ -if (hdr_dirty) - if (H5FA__hdr_modified(hdr) < 0) - H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark fixed array header as modified") - -/* Release resources */ -if (dblock && H5FA__dblock_unprotect(dblock, dblock_cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block") -if (dblk_page && H5FA__dblk_page_unprotect(dblk_page, dblk_page_cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block page") + HDassert(idx < hdr->cparam.nelmts); + + /* Protect data block */ + if (NULL == (dblock = H5FA__dblock_protect(hdr, hdr->dblk_addr, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block, address = %llu", + (unsigned long long)hdr->dblk_addr) + + /* Check for paging data block */ + if (!dblock->npages) { + /* Set element in data block */ + H5MM_memcpy(((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * idx), elmt, + hdr->cparam.cls->nat_elmt_size); + dblock_cache_flags |= H5AC__DIRTIED_FLAG; + } /* end if */ + else { /* paging */ + size_t page_idx; /* Index of page within data block */ + size_t dblk_page_nelmts; /* # of elements in a data block page */ + size_t elmt_idx; /* Element index within the page */ + haddr_t dblk_page_addr; /* Address of data block page */ + + /* Compute the page & element index */ + page_idx = (size_t)(idx / dblock->dblk_page_nelmts); + elmt_idx = (size_t)(idx % dblock->dblk_page_nelmts); + + /* Get the address of the data block page */ + dblk_page_addr = + dblock->addr + H5FA_DBLOCK_PREFIX_SIZE(dblock) + ((hsize_t)page_idx * dblock->dblk_page_size); + + /* Check for using last page, to set the number of elements on the page */ + if ((page_idx + 1) == dblock->npages) + dblk_page_nelmts = dblock->last_page_nelmts; + else + dblk_page_nelmts = dblock->dblk_page_nelmts; + + /* Check if the page has been created yet */ + if (!H5VM_bit_get(dblock->dblk_page_init, page_idx)) { + /* Create the data block page */ + if (H5FA__dblk_page_create(hdr, dblk_page_addr, dblk_page_nelmts) < 0) + H5E_THROW(H5E_CANTCREATE, "unable to create data block page") + + /* Mark data block page as initialized in data block */ + H5VM_bit_set(dblock->dblk_page_init, page_idx, TRUE); + dblock_cache_flags |= H5AC__DIRTIED_FLAG; + } /* end if */ + + /* Protect the data block page */ + if (NULL == + (dblk_page = H5FA__dblk_page_protect(hdr, dblk_page_addr, dblk_page_nelmts, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block page, address = %llu", + (unsigned long long)dblk_page_addr) + + /* Set the element in the data block page */ + H5MM_memcpy(((uint8_t *)dblk_page->elmts) + (hdr->cparam.cls->nat_elmt_size * elmt_idx), elmt, + hdr->cparam.cls->nat_elmt_size); + dblk_page_cache_flags |= H5AC__DIRTIED_FLAG; + } /* end else */ + + CATCH + /* Check for header modified */ + if (hdr_dirty) + if (H5FA__hdr_modified(hdr) < 0) + H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark fixed array header as modified") + + /* Release resources */ + if (dblock && H5FA__dblock_unprotect(dblock, dblock_cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block") + if (dblk_page && H5FA__dblk_page_unprotect(dblk_page, dblk_page_cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block page") END_FUNC(PRIV) /* end H5FA_set() */ @@ -421,89 +422,90 @@ END_FUNC(PRIV) /* end H5FA_set() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5FA_get(const H5FA_t *fa, hsize_t idx, void *elmt)) -/* Local variables */ -H5FA_hdr_t * hdr = fa->hdr; /* Header for FA */ -H5FA_dblock_t * dblock = NULL; /* Pointer to data block for FA */ -H5FA_dblk_page_t *dblk_page = NULL; /* Pointer to data block page for FA */ - -/* - * Check arguments. - */ -HDassert(fa); -HDassert(fa->hdr); - -/* Set the shared array header's file context for this operation */ -hdr->f = fa->f; - -/* Check if the fixed array data block has been allocated on disk yet */ -if (!H5F_addr_defined(hdr->dblk_addr)) { - /* Call the class's 'fill' callback */ - if ((hdr->cparam.cls->fill)(elmt, (size_t)1) < 0) - H5E_THROW(H5E_CANTSET, "can't set element to class's fill value") -} /* end if */ -else { - /* Get the data block */ - HDassert(H5F_addr_defined(hdr->dblk_addr)); - if (NULL == (dblock = H5FA__dblock_protect(hdr, hdr->dblk_addr, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block, address = %llu", - (unsigned long long)hdr->dblk_addr) - - /* Check for paged data block */ - if (!dblock->npages) - /* Retrieve element from data block */ - H5MM_memcpy(elmt, ((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * idx), - hdr->cparam.cls->nat_elmt_size); - else { /* paging */ - size_t page_idx; /* Index of page within data block */ + /* Local variables */ + H5FA_hdr_t * hdr = fa->hdr; /* Header for FA */ + H5FA_dblock_t * dblock = NULL; /* Pointer to data block for FA */ + H5FA_dblk_page_t *dblk_page = NULL; /* Pointer to data block page for FA */ - /* Compute the page index */ - page_idx = (size_t)(idx / dblock->dblk_page_nelmts); + /* + * Check arguments. + */ + HDassert(fa); + HDassert(fa->hdr); - /* Check if the page is defined yet */ - if (!H5VM_bit_get(dblock->dblk_page_init, page_idx)) { - /* Call the class's 'fill' callback */ - if ((hdr->cparam.cls->fill)(elmt, (size_t)1) < 0) - H5E_THROW(H5E_CANTSET, "can't set element to class's fill value") - - /* We've retrieved the value, leave now */ - H5_LEAVE(SUCCEED) - } /* end if */ - else { /* get the page */ - size_t dblk_page_nelmts; /* # of elements in a data block page */ - size_t elmt_idx; /* Element index within the page */ - haddr_t dblk_page_addr; /* Address of data block page */ - - /* Compute the element index */ - elmt_idx = (size_t)(idx % dblock->dblk_page_nelmts); - - /* Compute the address of the data block */ - dblk_page_addr = - dblock->addr + H5FA_DBLOCK_PREFIX_SIZE(dblock) + ((hsize_t)page_idx * dblock->dblk_page_size); - - /* Check for using last page, to set the number of elements on the page */ - if ((page_idx + 1) == dblock->npages) - dblk_page_nelmts = dblock->last_page_nelmts; - else - dblk_page_nelmts = dblock->dblk_page_nelmts; - - /* Protect the data block page */ - if (NULL == (dblk_page = H5FA__dblk_page_protect(hdr, dblk_page_addr, dblk_page_nelmts, - H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block page, address = %llu", - (unsigned long long)dblk_page_addr) + /* Set the shared array header's file context for this operation */ + hdr->f = fa->f; + /* Check if the fixed array data block has been allocated on disk yet */ + if (!H5F_addr_defined(hdr->dblk_addr)) { + /* Call the class's 'fill' callback */ + if ((hdr->cparam.cls->fill)(elmt, (size_t)1) < 0) + H5E_THROW(H5E_CANTSET, "can't set element to class's fill value") + } /* end if */ + else { + /* Get the data block */ + HDassert(H5F_addr_defined(hdr->dblk_addr)); + if (NULL == (dblock = H5FA__dblock_protect(hdr, hdr->dblk_addr, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block, address = %llu", + (unsigned long long)hdr->dblk_addr) + + /* Check for paged data block */ + if (!dblock->npages) /* Retrieve element from data block */ - H5MM_memcpy(elmt, ((uint8_t *)dblk_page->elmts) + (hdr->cparam.cls->nat_elmt_size * elmt_idx), + H5MM_memcpy(elmt, ((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * idx), hdr->cparam.cls->nat_elmt_size); - } /* end else */ - } /* end else */ -} /* end else */ - -CATCH -if (dblock && H5FA__dblock_unprotect(dblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block") -if (dblk_page && H5FA__dblk_page_unprotect(dblk_page, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block page") + else { /* paging */ + size_t page_idx; /* Index of page within data block */ + + /* Compute the page index */ + page_idx = (size_t)(idx / dblock->dblk_page_nelmts); + + /* Check if the page is defined yet */ + if (!H5VM_bit_get(dblock->dblk_page_init, page_idx)) { + /* Call the class's 'fill' callback */ + if ((hdr->cparam.cls->fill)(elmt, (size_t)1) < 0) + H5E_THROW(H5E_CANTSET, "can't set element to class's fill value") + + /* We've retrieved the value, leave now */ + H5_LEAVE(SUCCEED) + } /* end if */ + else { /* get the page */ + size_t dblk_page_nelmts; /* # of elements in a data block page */ + size_t elmt_idx; /* Element index within the page */ + haddr_t dblk_page_addr; /* Address of data block page */ + + /* Compute the element index */ + elmt_idx = (size_t)(idx % dblock->dblk_page_nelmts); + + /* Compute the address of the data block */ + dblk_page_addr = dblock->addr + H5FA_DBLOCK_PREFIX_SIZE(dblock) + + ((hsize_t)page_idx * dblock->dblk_page_size); + + /* Check for using last page, to set the number of elements on the page */ + if ((page_idx + 1) == dblock->npages) + dblk_page_nelmts = dblock->last_page_nelmts; + else + dblk_page_nelmts = dblock->dblk_page_nelmts; + + /* Protect the data block page */ + if (NULL == (dblk_page = H5FA__dblk_page_protect(hdr, dblk_page_addr, dblk_page_nelmts, + H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, + "unable to protect fixed array data block page, address = %llu", + (unsigned long long)dblk_page_addr) + + /* Retrieve element from data block */ + H5MM_memcpy(elmt, ((uint8_t *)dblk_page->elmts) + (hdr->cparam.cls->nat_elmt_size * elmt_idx), + hdr->cparam.cls->nat_elmt_size); + } /* end else */ + } /* end else */ + } /* end else */ + + CATCH + if (dblock && H5FA__dblock_unprotect(dblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block") + if (dblk_page && H5FA__dblk_page_unprotect(dblk_page, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block page") END_FUNC(PRIV) /* end H5FA_get() */ @@ -521,86 +523,87 @@ END_FUNC(PRIV) /* end H5FA_get() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5FA_close(H5FA_t *fa)) -/* Local variables */ -hbool_t pending_delete = FALSE; /* Whether the array is pending deletion */ -haddr_t fa_addr = HADDR_UNDEF; /* Address of array (for deletion) */ + /* Local variables */ + hbool_t pending_delete = FALSE; /* Whether the array is pending deletion */ + haddr_t fa_addr = HADDR_UNDEF; /* Address of array (for deletion) */ -/* - * Check arguments. - */ -HDassert(fa); + /* + * Check arguments. + */ + HDassert(fa); -/* Close the header, if it was set */ -if (fa->hdr) { - /* Decrement file reference & check if this is the last open fixed array using the shared array header */ - if (0 == H5FA__hdr_fuse_decr(fa->hdr)) { - /* Set the shared array header's file context for this operation */ - fa->hdr->f = fa->f; - - /* Shut down anything that can't be put in the header's 'flush' callback */ + /* Close the header, if it was set */ + if (fa->hdr) { + /* Decrement file reference & check if this is the last open fixed array using the shared array header + */ + if (0 == H5FA__hdr_fuse_decr(fa->hdr)) { + /* Set the shared array header's file context for this operation */ + fa->hdr->f = fa->f; + + /* Shut down anything that can't be put in the header's 'flush' callback */ + + /* Check for pending array deletion */ + if (fa->hdr->pending_delete) { + /* Set local info, so array deletion can occur after decrementing the + * header's ref count + */ + pending_delete = TRUE; + fa_addr = fa->hdr->addr; + } /* end if */ + } /* end if */ /* Check for pending array deletion */ - if (fa->hdr->pending_delete) { - /* Set local info, so array deletion can occur after decrementing the - * header's ref count - */ - pending_delete = TRUE; - fa_addr = fa->hdr->addr; - } /* end if */ - } /* end if */ - - /* Check for pending array deletion */ - if (pending_delete) { - H5FA_hdr_t *hdr; /* Another pointer to fixed array header */ + if (pending_delete) { + H5FA_hdr_t *hdr; /* Another pointer to fixed array header */ #ifndef NDEBUG - { - unsigned hdr_status = 0; /* Header's status in the metadata cache */ - - /* Check the header's status in the metadata cache */ - if (H5AC_get_entry_status(fa->f, fa_addr, &hdr_status) < 0) - H5E_THROW(H5E_CANTGET, "unable to check metadata cache status for fixed array header") - - /* Sanity checks on header */ - HDassert(hdr_status & H5AC_ES__IN_CACHE); - HDassert(hdr_status & H5AC_ES__IS_PINNED); - HDassert(!(hdr_status & H5AC_ES__IS_PROTECTED)); - } + { + unsigned hdr_status = 0; /* Header's status in the metadata cache */ + + /* Check the header's status in the metadata cache */ + if (H5AC_get_entry_status(fa->f, fa_addr, &hdr_status) < 0) + H5E_THROW(H5E_CANTGET, "unable to check metadata cache status for fixed array header") + + /* Sanity checks on header */ + HDassert(hdr_status & H5AC_ES__IN_CACHE); + HDassert(hdr_status & H5AC_ES__IS_PINNED); + HDassert(!(hdr_status & H5AC_ES__IS_PROTECTED)); + } #endif /* NDEBUG */ - /* Lock the array header into memory */ - /* (OK to pass in NULL for callback context, since we know the header must be in the cache) */ - if (NULL == (hdr = H5FA__hdr_protect(fa->f, fa_addr, NULL, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTLOAD, "unable to load fixed array header") + /* Lock the array header into memory */ + /* (OK to pass in NULL for callback context, since we know the header must be in the cache) */ + if (NULL == (hdr = H5FA__hdr_protect(fa->f, fa_addr, NULL, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTLOAD, "unable to load fixed array header") - /* Set the shared array header's file context for this operation */ - hdr->f = fa->f; + /* Set the shared array header's file context for this operation */ + hdr->f = fa->f; - /* Decrement the reference count on the array header */ - /* (don't put in H5FA_hdr_fuse_decr() as the array header may be evicted - * immediately -QAK) - */ - if (H5FA__hdr_decr(fa->hdr) < 0) - H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + /* Decrement the reference count on the array header */ + /* (don't put in H5FA_hdr_fuse_decr() as the array header may be evicted + * immediately -QAK) + */ + if (H5FA__hdr_decr(fa->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") - /* Delete array, starting with header (unprotects header) */ - if (H5FA__hdr_delete(hdr) < 0) - H5E_THROW(H5E_CANTDELETE, "unable to delete fixed array") - } /* end if */ - else { - /* Decrement the reference count on the array header */ - /* (don't put in H5FA_hdr_fuse_decr() as the array header may be evicted - * immediately -QAK) - */ - if (H5FA__hdr_decr(fa->hdr) < 0) - H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") - } /* end else */ -} /* end if */ + /* Delete array, starting with header (unprotects header) */ + if (H5FA__hdr_delete(hdr) < 0) + H5E_THROW(H5E_CANTDELETE, "unable to delete fixed array") + } /* end if */ + else { + /* Decrement the reference count on the array header */ + /* (don't put in H5FA_hdr_fuse_decr() as the array header may be evicted + * immediately -QAK) + */ + if (H5FA__hdr_decr(fa->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + } /* end else */ + } /* end if */ -/* Release the fixed array wrapper */ -fa = H5FL_FREE(H5FA_t, fa); + /* Release the fixed array wrapper */ + fa = H5FL_FREE(H5FA_t, fa); -CATCH + CATCH END_FUNC(PRIV) /* end H5FA_close() */ @@ -618,38 +621,38 @@ END_FUNC(PRIV) /* end H5FA_close() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5FA_delete(H5F_t *f, haddr_t fa_addr, void *ctx_udata)) -/* Local variables */ -H5FA_hdr_t *hdr = NULL; /* The fixed array header information */ + /* Local variables */ + H5FA_hdr_t *hdr = NULL; /* The fixed array header information */ -/* - * Check arguments. - */ -HDassert(f); -HDassert(H5F_addr_defined(fa_addr)); - -/* Lock the array header into memory */ -if (NULL == (hdr = H5FA__hdr_protect(f, fa_addr, ctx_udata, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array header, address = %llu", - (unsigned long long)fa_addr) - -/* Check for files using shared array header */ -if (hdr->file_rc) - hdr->pending_delete = TRUE; -else { - /* Set the shared array header's file context for this operation */ - hdr->f = f; + /* + * Check arguments. + */ + HDassert(f); + HDassert(H5F_addr_defined(fa_addr)); - /* Delete array now, starting with header (unprotects header) */ - if (H5FA__hdr_delete(hdr) < 0) - H5E_THROW(H5E_CANTDELETE, "unable to delete fixed array") - hdr = NULL; -} /* end if */ + /* Lock the array header into memory */ + if (NULL == (hdr = H5FA__hdr_protect(f, fa_addr, ctx_udata, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array header, address = %llu", + (unsigned long long)fa_addr) -CATCH + /* Check for files using shared array header */ + if (hdr->file_rc) + hdr->pending_delete = TRUE; + else { + /* Set the shared array header's file context for this operation */ + hdr->f = f; -/* Unprotect the header, if an error occurred */ -if (hdr && H5FA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array header") + /* Delete array now, starting with header (unprotects header) */ + if (H5FA__hdr_delete(hdr) < 0) + H5E_THROW(H5E_CANTDELETE, "unable to delete fixed array") + hdr = NULL; + } /* end if */ + + CATCH + + /* Unprotect the header, if an error occurred */ + if (hdr && H5FA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array header") END_FUNC(PRIV) /* end H5FA_delete() */ @@ -671,39 +674,39 @@ END_FUNC(PRIV) /* end H5FA_delete() */ BEGIN_FUNC(PRIV, ERR, int, H5_ITER_CONT, H5_ITER_ERROR, H5FA_iterate(H5FA_t *fa, H5FA_operator_t op, void *udata)) -/* Local variables */ -uint8_t *elmt = NULL; -hsize_t u; -int cb_ret = H5_ITER_CONT; /* Return value from callback */ - -/* - * Check arguments. - */ -HDassert(fa); -HDassert(op); -HDassert(udata); - -/* Allocate space for a native array element */ -if (NULL == (elmt = H5FL_BLK_MALLOC(fa_native_elmt, fa->hdr->cparam.cls->nat_elmt_size))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array element") - -/* Iterate over all elements in array */ -for (u = 0; u < fa->hdr->stats.nelmts && cb_ret == H5_ITER_CONT; u++) { - /* Get array element */ - if (H5FA_get(fa, u, elmt) < 0) - H5E_THROW(H5E_CANTGET, "unable to delete fixed array") - - /* Make callback */ - if ((cb_ret = (*op)(u, elmt, udata)) < 0) { - H5E_PRINTF(H5E_BADITER, "iterator function failed"); - H5_LEAVE(cb_ret) - } /* end if */ -} /* end for */ + /* Local variables */ + uint8_t *elmt = NULL; + hsize_t u; + int cb_ret = H5_ITER_CONT; /* Return value from callback */ + + /* + * Check arguments. + */ + HDassert(fa); + HDassert(op); + HDassert(udata); + + /* Allocate space for a native array element */ + if (NULL == (elmt = H5FL_BLK_MALLOC(fa_native_elmt, fa->hdr->cparam.cls->nat_elmt_size))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array element") + + /* Iterate over all elements in array */ + for (u = 0; u < fa->hdr->stats.nelmts && cb_ret == H5_ITER_CONT; u++) { + /* Get array element */ + if (H5FA_get(fa, u, elmt) < 0) + H5E_THROW(H5E_CANTGET, "unable to delete fixed array") + + /* Make callback */ + if ((cb_ret = (*op)(u, elmt, udata)) < 0) { + H5E_PRINTF(H5E_BADITER, "iterator function failed"); + H5_LEAVE(cb_ret) + } /* end if */ + } /* end for */ -CATCH + CATCH -if (elmt) - elmt = H5FL_BLK_FREE(fa_native_elmt, elmt); + if (elmt) + elmt = H5FL_BLK_FREE(fa_native_elmt, elmt); END_FUNC(PRIV) /* end H5FA_iterate() */ @@ -722,35 +725,35 @@ END_FUNC(PRIV) /* end H5FA_iterate() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5FA_depend(H5FA_t *fa, H5AC_proxy_entry_t *parent)) -/* Local variables */ -H5FA_hdr_t *hdr = fa->hdr; /* Header for FA */ - -/* - * Check arguments. - */ -HDassert(fa); -HDassert(hdr); -HDassert(parent); - -/* - * Check to see if a flush dependency between the fixed array - * and another data structure in the file has already been set up. - * If it hasn't, do so now. - */ -if (NULL == hdr->parent) { - /* Sanity check */ - HDassert(hdr->top_proxy); + /* Local variables */ + H5FA_hdr_t *hdr = fa->hdr; /* Header for FA */ + + /* + * Check arguments. + */ + HDassert(fa); + HDassert(hdr); + HDassert(parent); + + /* + * Check to see if a flush dependency between the fixed array + * and another data structure in the file has already been set up. + * If it hasn't, do so now. + */ + if (NULL == hdr->parent) { + /* Sanity check */ + HDassert(hdr->top_proxy); - /* Set the shared array header's file context for this operation */ - hdr->f = fa->f; + /* Set the shared array header's file context for this operation */ + hdr->f = fa->f; - /* Add the fixed array as a child of the parent (proxy) */ - if (H5AC_proxy_entry_add_child(parent, hdr->f, hdr->top_proxy) < 0) - H5E_THROW(H5E_CANTSET, "unable to add fixed array as child of proxy") - hdr->parent = parent; -} /* end if */ + /* Add the fixed array as a child of the parent (proxy) */ + if (H5AC_proxy_entry_add_child(parent, hdr->f, hdr->top_proxy) < 0) + H5E_THROW(H5E_CANTSET, "unable to add fixed array as child of proxy") + hdr->parent = parent; + } /* end if */ -CATCH + CATCH END_FUNC(PRIV) /* end H5FA_depend() */ @@ -768,15 +771,15 @@ END_FUNC(PRIV) /* end H5FA_depend() */ */ BEGIN_FUNC(PRIV, NOERR, herr_t, SUCCEED, -, H5FA_patch_file(H5FA_t *fa, H5F_t *f)) -/* Local variables */ + /* Local variables */ -/* - * Check arguments. - */ -HDassert(fa); -HDassert(f); + /* + * Check arguments. + */ + HDassert(fa); + HDassert(f); -if (fa->f != f || fa->hdr->f != f) - fa->f = fa->hdr->f = f; + if (fa->f != f || fa->hdr->f != f) + fa->f = fa->hdr->f = f; END_FUNC(PRIV) /* end H5FA_patch_file() */ diff --git a/src/H5FAcache.c b/src/H5FAcache.c index b030bd5..3772399 100644 --- a/src/H5FAcache.c +++ b/src/H5FAcache.c @@ -170,16 +170,16 @@ const H5AC_class_t H5AC_FARRAY_DBLK_PAGE[1] = {{ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__cache_hdr_get_initial_load_size(void *_udata, size_t *image_len)) -/* Local variables */ -H5FA_hdr_cache_ud_t *udata = (H5FA_hdr_cache_ud_t *)_udata; /* User data for callback */ + /* Local variables */ + H5FA_hdr_cache_ud_t *udata = (H5FA_hdr_cache_ud_t *)_udata; /* User data for callback */ -/* Check arguments */ -HDassert(udata); -HDassert(udata->f); -HDassert(image_len); + /* Check arguments */ + HDassert(udata); + HDassert(udata->f); + HDassert(image_len); -/* Set the image length size */ -*image_len = (size_t)H5FA_HEADER_SIZE_FILE(udata->f); + /* Set the image length size */ + *image_len = (size_t)H5FA_HEADER_SIZE_FILE(udata->f); END_FUNC(STATIC) /* end H5FA__cache_hdr_get_initial_load_size() */ @@ -199,19 +199,19 @@ END_FUNC(STATIC) /* end H5FA__cache_hdr_get_initial_load_size() */ BEGIN_FUNC(STATIC, NOERR, htri_t, TRUE, -, H5FA__cache_hdr_verify_chksum(const void *_image, size_t len, void H5_ATTR_UNUSED *_udata)) -/* Local variables */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -uint32_t computed_chksum; /* Computed metadata checksum value */ + /* Local variables */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ -/* Check arguments */ -HDassert(image); + /* Check arguments */ + HDassert(image); -/* Get stored and computed checksums */ -H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); + /* Get stored and computed checksums */ + H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); -if (stored_chksum != computed_chksum) - ret_value = FALSE; + if (stored_chksum != computed_chksum) + ret_value = FALSE; END_FUNC(STATIC) /* end H5FA__cache_hdr_verify_chksum() */ @@ -232,97 +232,97 @@ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5FA__cache_hdr_deserialize(const void *_image, size_t H5_ATTR_NDEBUG_UNUSED len, void *_udata, hbool_t H5_ATTR_UNUSED *dirty)) -/* Local variables */ -H5FA_cls_id_t id; /* ID of fixed array class, as found in file */ -H5FA_hdr_t * hdr = NULL; /* Fixed array info */ -H5FA_hdr_cache_ud_t *udata = (H5FA_hdr_cache_ud_t *)_udata; -const uint8_t * image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ - -/* Check arguments */ -HDassert(udata); -HDassert(udata->f); -HDassert(H5F_addr_defined(udata->addr)); - -/* Allocate space for the fixed array data structure */ -if (NULL == (hdr = H5FA__hdr_alloc(udata->f))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array shared header") - -/* Set the fixed array header's address */ -hdr->addr = udata->addr; - -/* Magic number */ -if (HDmemcmp(image, H5FA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) - H5E_THROW(H5E_BADVALUE, "wrong fixed array header signature") -image += H5_SIZEOF_MAGIC; - -/* Version */ -if (*image++ != H5FA_HDR_VERSION) - H5E_THROW(H5E_VERSION, "wrong fixed array header version") - -/* Fixed array class */ -id = (H5FA_cls_id_t)*image++; -if (id >= H5FA_NUM_CLS_ID) - H5E_THROW(H5E_BADTYPE, "incorrect fixed array class") -hdr->cparam.cls = H5FA_client_class_g[id]; - -/* General array creation/configuration information */ -hdr->cparam.raw_elmt_size = *image++; /* Element size in file (in bytes) */ -hdr->cparam.max_dblk_page_nelmts_bits = *image++; /* Log2(Max. # of elements in data block page) - - i.e. # of bits needed to store max. # of - elements in data block page. */ - -/* Array statistics */ -H5F_DECODE_LENGTH(udata->f, image, hdr->cparam.nelmts); /* Number of elements */ - -/* Internal information */ -H5F_addr_decode(udata->f, &image, &hdr->dblk_addr); /* Address of index block */ - -/* Check for data block */ -if (H5F_addr_defined(hdr->dblk_addr)) { - H5FA_dblock_t dblock; /* Fake data block for computing size */ - size_t dblk_page_nelmts; /* # of elements per data block page */ + /* Local variables */ + H5FA_cls_id_t id; /* ID of fixed array class, as found in file */ + H5FA_hdr_t * hdr = NULL; /* Fixed array info */ + H5FA_hdr_cache_ud_t *udata = (H5FA_hdr_cache_ud_t *)_udata; + const uint8_t * image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + + /* Check arguments */ + HDassert(udata); + HDassert(udata->f); + HDassert(H5F_addr_defined(udata->addr)); + + /* Allocate space for the fixed array data structure */ + if (NULL == (hdr = H5FA__hdr_alloc(udata->f))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array shared header") + + /* Set the fixed array header's address */ + hdr->addr = udata->addr; + + /* Magic number */ + if (HDmemcmp(image, H5FA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) + H5E_THROW(H5E_BADVALUE, "wrong fixed array header signature") + image += H5_SIZEOF_MAGIC; + + /* Version */ + if (*image++ != H5FA_HDR_VERSION) + H5E_THROW(H5E_VERSION, "wrong fixed array header version") + + /* Fixed array class */ + id = (H5FA_cls_id_t)*image++; + if (id >= H5FA_NUM_CLS_ID) + H5E_THROW(H5E_BADTYPE, "incorrect fixed array class") + hdr->cparam.cls = H5FA_client_class_g[id]; + + /* General array creation/configuration information */ + hdr->cparam.raw_elmt_size = *image++; /* Element size in file (in bytes) */ + hdr->cparam.max_dblk_page_nelmts_bits = *image++; /* Log2(Max. # of elements in data block page) - + i.e. # of bits needed to store max. # of + elements in data block page. */ + + /* Array statistics */ + H5F_DECODE_LENGTH(udata->f, image, hdr->cparam.nelmts); /* Number of elements */ + + /* Internal information */ + H5F_addr_decode(udata->f, &image, &hdr->dblk_addr); /* Address of index block */ + + /* Check for data block */ + if (H5F_addr_defined(hdr->dblk_addr)) { + H5FA_dblock_t dblock; /* Fake data block for computing size */ + size_t dblk_page_nelmts; /* # of elements per data block page */ + + /* Set up fake data block for computing size on disk */ + dblock.hdr = hdr; + dblock.dblk_page_init_size = 0; + dblock.npages = 0; + dblk_page_nelmts = (size_t)1 << hdr->cparam.max_dblk_page_nelmts_bits; + if (hdr->cparam.nelmts > dblk_page_nelmts) { + dblock.npages = (size_t)(((hdr->cparam.nelmts + dblk_page_nelmts) - 1) / dblk_page_nelmts); + dblock.dblk_page_init_size = (dblock.npages + 7) / 8; + } /* end if */ - /* Set up fake data block for computing size on disk */ - dblock.hdr = hdr; - dblock.dblk_page_init_size = 0; - dblock.npages = 0; - dblk_page_nelmts = (size_t)1 << hdr->cparam.max_dblk_page_nelmts_bits; - if (hdr->cparam.nelmts > dblk_page_nelmts) { - dblock.npages = (size_t)(((hdr->cparam.nelmts + dblk_page_nelmts) - 1) / dblk_page_nelmts); - dblock.dblk_page_init_size = (dblock.npages + 7) / 8; + /* Compute Fixed Array data block size for hdr statistics */ + hdr->stats.dblk_size = (size_t)H5FA_DBLOCK_SIZE(&dblock); } /* end if */ - /* Compute Fixed Array data block size for hdr statistics */ - hdr->stats.dblk_size = (size_t)H5FA_DBLOCK_SIZE(&dblock); -} /* end if */ - -/* Sanity check */ -/* (allow for checksum not decoded yet) */ -HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5FA_SIZEOF_CHKSUM)); + /* Sanity check */ + /* (allow for checksum not decoded yet) */ + HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5FA_SIZEOF_CHKSUM)); -/* checksum verification already done in verify_chksum cb */ + /* checksum verification already done in verify_chksum cb */ -/* Metadata checksum */ -UINT32DECODE(image, stored_chksum); + /* Metadata checksum */ + UINT32DECODE(image, stored_chksum); -/* Sanity check */ -HDassert((size_t)(image - (const uint8_t *)_image) == len); + /* Sanity check */ + HDassert((size_t)(image - (const uint8_t *)_image) == len); -/* Finish initializing fixed array header */ -if (H5FA__hdr_init(hdr, udata->ctx_udata) < 0) - H5E_THROW(H5E_CANTINIT, "initialization failed for fixed array header") -HDassert(hdr->size == len); + /* Finish initializing fixed array header */ + if (H5FA__hdr_init(hdr, udata->ctx_udata) < 0) + H5E_THROW(H5E_CANTINIT, "initialization failed for fixed array header") + HDassert(hdr->size == len); -/* Set return value */ -ret_value = hdr; + /* Set return value */ + ret_value = hdr; -CATCH + CATCH -/* Release resources */ -if (!ret_value) - if (hdr && H5FA__hdr_dest(hdr) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array header") + /* Release resources */ + if (!ret_value) + if (hdr && H5FA__hdr_dest(hdr) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array header") END_FUNC(STATIC) /* end H5FA__cache_hdr_deserialize() */ @@ -341,15 +341,15 @@ END_FUNC(STATIC) /* end H5FA__cache_hdr_deserialize() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__cache_hdr_image_len(const void *_thing, size_t *image_len)) -/* Local variables */ -const H5FA_hdr_t *hdr = (const H5FA_hdr_t *)_thing; /* Pointer to the object */ + /* Local variables */ + const H5FA_hdr_t *hdr = (const H5FA_hdr_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(hdr); -HDassert(image_len); + /* Check arguments */ + HDassert(hdr); + HDassert(image_len); -/* Set the image length size */ -*image_len = hdr->size; + /* Set the image length size */ + *image_len = hdr->size; END_FUNC(STATIC) /* end H5FA__cache_hdr_image_len() */ @@ -368,47 +368,47 @@ END_FUNC(STATIC) /* end H5FA__cache_hdr_image_len() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__cache_hdr_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, void *_thing)) -/* Local variables */ -H5FA_hdr_t *hdr = (H5FA_hdr_t *)_thing; /* Pointer to the fixed array header */ -uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t metadata_chksum; /* Computed metadata checksum value */ + /* Local variables */ + H5FA_hdr_t *hdr = (H5FA_hdr_t *)_thing; /* Pointer to the fixed array header */ + uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t metadata_chksum; /* Computed metadata checksum value */ -/* check arguments */ -HDassert(f); -HDassert(image); -HDassert(hdr); + /* check arguments */ + HDassert(f); + HDassert(image); + HDassert(hdr); -/* Magic number */ -H5MM_memcpy(image, H5FA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); -image += H5_SIZEOF_MAGIC; + /* Magic number */ + H5MM_memcpy(image, H5FA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC); + image += H5_SIZEOF_MAGIC; -/* Version # */ -*image++ = H5FA_HDR_VERSION; + /* Version # */ + *image++ = H5FA_HDR_VERSION; -/* Fixed array type */ -HDassert(hdr->cparam.cls->id <= 255); -*image++ = (uint8_t)hdr->cparam.cls->id; + /* Fixed array type */ + HDassert(hdr->cparam.cls->id <= 255); + *image++ = (uint8_t)hdr->cparam.cls->id; -/* General array creation/configuration information */ -*image++ = hdr->cparam.raw_elmt_size; /* Element size in file (in bytes) */ -*image++ = - hdr->cparam.max_dblk_page_nelmts_bits; /* Log2(Max. # of elements in data block page) - i.e. # of bits - needed to store max. # of elements in data block page */ + /* General array creation/configuration information */ + *image++ = hdr->cparam.raw_elmt_size; /* Element size in file (in bytes) */ + *image++ = + hdr->cparam.max_dblk_page_nelmts_bits; /* Log2(Max. # of elements in data block page) - i.e. # of bits + needed to store max. # of elements in data block page */ -/* Array statistics */ -H5F_ENCODE_LENGTH(f, image, hdr->stats.nelmts); /* Number of elements for the fixed array */ + /* Array statistics */ + H5F_ENCODE_LENGTH(f, image, hdr->stats.nelmts); /* Number of elements for the fixed array */ -/* Internal information */ -H5F_addr_encode(f, &image, hdr->dblk_addr); /* Address of fixed array data block */ + /* Internal information */ + H5F_addr_encode(f, &image, hdr->dblk_addr); /* Address of fixed array data block */ -/* Compute metadata checksum */ -metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); + /* Compute metadata checksum */ + metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); -/* Metadata checksum */ -UINT32ENCODE(image, metadata_chksum); + /* Metadata checksum */ + UINT32ENCODE(image, metadata_chksum); -/* Sanity check */ -HDassert((size_t)(image - (uint8_t *)_image) == len); + /* Sanity check */ + HDassert((size_t)(image - (uint8_t *)_image) == len); END_FUNC(STATIC) /* end H5FA__cache_hdr_serialize() */ @@ -427,65 +427,66 @@ END_FUNC(STATIC) /* end H5FA__cache_hdr_serialize() */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5FA__cache_hdr_notify(H5AC_notify_action_t action, void *_thing)) -/* Local variables */ -H5FA_hdr_t *hdr = (H5FA_hdr_t *)_thing; /* Pointer to the object */ - -/* Sanity check */ -HDassert(hdr); - -/* Check if the file was opened with SWMR-write access */ -if (hdr->swmr_write) { - /* Determine which action to take */ - switch (action) { - case H5AC_NOTIFY_ACTION_AFTER_INSERT: - case H5AC_NOTIFY_ACTION_AFTER_LOAD: - case H5AC_NOTIFY_ACTION_AFTER_FLUSH: - case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: - case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: - case H5AC_NOTIFY_ACTION_CHILD_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: - case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: - /* do nothing */ - break; - - case H5AC_NOTIFY_ACTION_BEFORE_EVICT: - /* If hdr->parent != NULL, hdr->parent is used to destroy - * the flush dependency before the header is evicted. - */ - if (hdr->parent) { - /* Sanity check */ - HDassert(hdr->top_proxy); - - /* Destroy flush dependency on object header proxy */ - if (H5AC_proxy_entry_remove_child((H5AC_proxy_entry_t *)hdr->parent, (void *)hdr->top_proxy) < - 0) - H5E_THROW(H5E_CANTUNDEPEND, - "unable to destroy flush dependency between fixed array and proxy") - hdr->parent = NULL; - } /* end if */ - - /* Detach from 'top' proxy for fixed array */ - if (hdr->top_proxy) { - if (H5AC_proxy_entry_remove_child(hdr->top_proxy, hdr) < 0) - H5E_THROW(H5E_CANTUNDEPEND, - "unable to destroy flush dependency between header and fixed array 'top' proxy") - /* Don't reset hdr->top_proxy here, it's destroyed when the header is freed -QAK */ - } /* end if */ - break; - - default: + /* Local variables */ + H5FA_hdr_t *hdr = (H5FA_hdr_t *)_thing; /* Pointer to the object */ + + /* Sanity check */ + HDassert(hdr); + + /* Check if the file was opened with SWMR-write access */ + if (hdr->swmr_write) { + /* Determine which action to take */ + switch (action) { + case H5AC_NOTIFY_ACTION_AFTER_INSERT: + case H5AC_NOTIFY_ACTION_AFTER_LOAD: + case H5AC_NOTIFY_ACTION_AFTER_FLUSH: + case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: + case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: + case H5AC_NOTIFY_ACTION_CHILD_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: + case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: + /* do nothing */ + break; + + case H5AC_NOTIFY_ACTION_BEFORE_EVICT: + /* If hdr->parent != NULL, hdr->parent is used to destroy + * the flush dependency before the header is evicted. + */ + if (hdr->parent) { + /* Sanity check */ + HDassert(hdr->top_proxy); + + /* Destroy flush dependency on object header proxy */ + if (H5AC_proxy_entry_remove_child((H5AC_proxy_entry_t *)hdr->parent, + (void *)hdr->top_proxy) < 0) + H5E_THROW(H5E_CANTUNDEPEND, + "unable to destroy flush dependency between fixed array and proxy") + hdr->parent = NULL; + } /* end if */ + + /* Detach from 'top' proxy for fixed array */ + if (hdr->top_proxy) { + if (H5AC_proxy_entry_remove_child(hdr->top_proxy, hdr) < 0) + H5E_THROW( + H5E_CANTUNDEPEND, + "unable to destroy flush dependency between header and fixed array 'top' proxy") + /* Don't reset hdr->top_proxy here, it's destroyed when the header is freed -QAK */ + } /* end if */ + break; + + default: #ifdef NDEBUG - H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") -#else /* NDEBUG */ - HDassert(0 && "Unknown action?!?"); -#endif /* NDEBUG */ - } /* end switch */ -} /* end if */ -else - HDassert(NULL == hdr->parent); + H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") +#else /* NDEBUG */ + HDassert(0 && "Unknown action?!?"); +#endif /* NDEBUG */ + } /* end switch */ + } /* end if */ + else + HDassert(NULL == hdr->parent); -CATCH + CATCH END_FUNC(STATIC) /* end H5FA__cache_hdr_notify() */ @@ -504,14 +505,14 @@ END_FUNC(STATIC) /* end H5FA__cache_hdr_notify() */ */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5FA__cache_hdr_free_icr(void *thing)) -/* Check arguments */ -HDassert(thing); + /* Check arguments */ + HDassert(thing); -/* Release the extensible array header */ -if (H5FA__hdr_dest((H5FA_hdr_t *)thing) < 0) - H5E_THROW(H5E_CANTFREE, "can't free fixed array header") + /* Release the extensible array header */ + if (H5FA__hdr_dest((H5FA_hdr_t *)thing) < 0) + H5E_THROW(H5E_CANTFREE, "can't free fixed array header") -CATCH + CATCH END_FUNC(STATIC) /* end H5FA__cache_hdr_free_icr() */ @@ -530,38 +531,38 @@ END_FUNC(STATIC) /* end H5FA__cache_hdr_free_icr() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__cache_dblock_get_initial_load_size(void *_udata, size_t *image_len)) -/* Local variables */ -H5FA_dblock_cache_ud_t *udata = (H5FA_dblock_cache_ud_t *)_udata; /* User data */ -H5FA_dblock_t dblock; /* Fake data block for computing size */ -size_t dblk_page_nelmts; /* # of elements per data block page */ + /* Local variables */ + H5FA_dblock_cache_ud_t *udata = (H5FA_dblock_cache_ud_t *)_udata; /* User data */ + H5FA_dblock_t dblock; /* Fake data block for computing size */ + size_t dblk_page_nelmts; /* # of elements per data block page */ -/* Check arguments */ -HDassert(udata); -HDassert(udata->hdr); -HDassert(image_len); + /* Check arguments */ + HDassert(udata); + HDassert(udata->hdr); + HDassert(image_len); -/* Set up fake data block for computing size on disk */ -/* (Note: extracted from H5FA__dblock_alloc) */ -HDmemset(&dblock, 0, sizeof(dblock)); + /* Set up fake data block for computing size on disk */ + /* (Note: extracted from H5FA__dblock_alloc) */ + HDmemset(&dblock, 0, sizeof(dblock)); + + /* Set up fake data block for computing size on disk + * + * need: dblock->hdr + * dblock->npages + * dblock->dblk_page_init_size + */ + dblock.hdr = udata->hdr; + dblk_page_nelmts = (size_t)1 << udata->hdr->cparam.max_dblk_page_nelmts_bits; + if (udata->hdr->cparam.nelmts > dblk_page_nelmts) { + dblock.npages = (size_t)(((udata->hdr->cparam.nelmts + dblk_page_nelmts) - 1) / dblk_page_nelmts); + dblock.dblk_page_init_size = (dblock.npages + 7) / 8; + } /* end if */ -/* Set up fake data block for computing size on disk - * - * need: dblock->hdr - * dblock->npages - * dblock->dblk_page_init_size - */ -dblock.hdr = udata->hdr; -dblk_page_nelmts = (size_t)1 << udata->hdr->cparam.max_dblk_page_nelmts_bits; -if (udata->hdr->cparam.nelmts > dblk_page_nelmts) { - dblock.npages = (size_t)(((udata->hdr->cparam.nelmts + dblk_page_nelmts) - 1) / dblk_page_nelmts); - dblock.dblk_page_init_size = (dblock.npages + 7) / 8; -} /* end if */ - -/* Set the image length size */ -if (!dblock.npages) - *image_len = (size_t)H5FA_DBLOCK_SIZE(&dblock); -else - *image_len = (size_t)H5FA_DBLOCK_PREFIX_SIZE(&dblock); + /* Set the image length size */ + if (!dblock.npages) + *image_len = (size_t)H5FA_DBLOCK_SIZE(&dblock); + else + *image_len = (size_t)H5FA_DBLOCK_PREFIX_SIZE(&dblock); END_FUNC(STATIC) /* end H5FA__cache_dblock_get_initial_load_size() */ @@ -581,19 +582,19 @@ END_FUNC(STATIC) /* end H5FA__cache_dblock_get_initial_load_size() */ BEGIN_FUNC(STATIC, NOERR, htri_t, TRUE, -, H5FA__cache_dblock_verify_chksum(const void *_image, size_t len, void H5_ATTR_UNUSED *_udata)) -/* Local variables */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -uint32_t computed_chksum; /* Computed metadata checksum value */ + /* Local variables */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ -/* Check arguments */ -HDassert(image); + /* Check arguments */ + HDassert(image); -/* Get stored and computed checksums */ -H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); + /* Get stored and computed checksums */ + H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); -if (stored_chksum != computed_chksum) - ret_value = FALSE; + if (stored_chksum != computed_chksum) + ret_value = FALSE; END_FUNC(STATIC) /* end H5FA__cache_dblock_verify_chksum() */ @@ -614,85 +615,85 @@ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5FA__cache_dblock_deserialize(const void *_image, size_t H5_ATTR_NDEBUG_UNUSED len, void *_udata, hbool_t H5_ATTR_UNUSED *dirty)) -/* Local variables */ -H5FA_dblock_t * dblock = NULL; /* Data block info */ -H5FA_dblock_cache_ud_t *udata = (H5FA_dblock_cache_ud_t *)_udata; /* User data for loading data block */ -const uint8_t * image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -haddr_t arr_addr; /* Address of array header in the file */ - -/* Sanity check */ -HDassert(udata); -HDassert(udata->hdr); - -/* Allocate the fixed array data block */ -if (NULL == (dblock = H5FA__dblock_alloc(udata->hdr))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block") - -HDassert(((!dblock->npages) && (len == (size_t)H5FA_DBLOCK_SIZE(dblock))) || - (len == (size_t)H5FA_DBLOCK_PREFIX_SIZE(dblock))); - -/* Set the fixed array data block's information */ -dblock->addr = udata->dblk_addr; - -/* Magic number */ -if (HDmemcmp(image, H5FA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) - H5E_THROW(H5E_BADVALUE, "wrong fixed array data block signature") -image += H5_SIZEOF_MAGIC; - -/* Version */ -if (*image++ != H5FA_DBLOCK_VERSION) - H5E_THROW(H5E_VERSION, "wrong fixed array data block version") - -/* Fixed array type */ -if (*image++ != (uint8_t)udata->hdr->cparam.cls->id) - H5E_THROW(H5E_BADTYPE, "incorrect fixed array class") - -/* Address of header for array that owns this block (just for file integrity checks) */ -H5F_addr_decode(udata->hdr->f, &image, &arr_addr); -if (H5F_addr_ne(arr_addr, udata->hdr->addr)) - H5E_THROW(H5E_BADVALUE, "wrong fixed array header address") - -/* Page initialization flags */ -if (dblock->npages > 0) { - H5MM_memcpy(dblock->dblk_page_init, image, dblock->dblk_page_init_size); - image += dblock->dblk_page_init_size; -} /* end if */ - -/* Only decode elements if the data block is not paged */ -if (!dblock->npages) { - /* Decode elements in data block */ - /* Convert from raw elements on disk into native elements in memory */ - if ((udata->hdr->cparam.cls->decode)(image, dblock->elmts, (size_t)udata->hdr->cparam.nelmts, - udata->hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTDECODE, "can't decode fixed array data elements") - image += (udata->hdr->cparam.nelmts * udata->hdr->cparam.raw_elmt_size); -} /* end if */ + /* Local variables */ + H5FA_dblock_t * dblock = NULL; /* Data block info */ + H5FA_dblock_cache_ud_t *udata = (H5FA_dblock_cache_ud_t *)_udata; /* User data for loading data block */ + const uint8_t * image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + haddr_t arr_addr; /* Address of array header in the file */ + + /* Sanity check */ + HDassert(udata); + HDassert(udata->hdr); + + /* Allocate the fixed array data block */ + if (NULL == (dblock = H5FA__dblock_alloc(udata->hdr))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block") + + HDassert(((!dblock->npages) && (len == (size_t)H5FA_DBLOCK_SIZE(dblock))) || + (len == (size_t)H5FA_DBLOCK_PREFIX_SIZE(dblock))); + + /* Set the fixed array data block's information */ + dblock->addr = udata->dblk_addr; + + /* Magic number */ + if (HDmemcmp(image, H5FA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) + H5E_THROW(H5E_BADVALUE, "wrong fixed array data block signature") + image += H5_SIZEOF_MAGIC; + + /* Version */ + if (*image++ != H5FA_DBLOCK_VERSION) + H5E_THROW(H5E_VERSION, "wrong fixed array data block version") + + /* Fixed array type */ + if (*image++ != (uint8_t)udata->hdr->cparam.cls->id) + H5E_THROW(H5E_BADTYPE, "incorrect fixed array class") + + /* Address of header for array that owns this block (just for file integrity checks) */ + H5F_addr_decode(udata->hdr->f, &image, &arr_addr); + if (H5F_addr_ne(arr_addr, udata->hdr->addr)) + H5E_THROW(H5E_BADVALUE, "wrong fixed array header address") + + /* Page initialization flags */ + if (dblock->npages > 0) { + H5MM_memcpy(dblock->dblk_page_init, image, dblock->dblk_page_init_size); + image += dblock->dblk_page_init_size; + } /* end if */ -/* Sanity check */ -/* (allow for checksum not decoded yet) */ -HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5FA_SIZEOF_CHKSUM)); + /* Only decode elements if the data block is not paged */ + if (!dblock->npages) { + /* Decode elements in data block */ + /* Convert from raw elements on disk into native elements in memory */ + if ((udata->hdr->cparam.cls->decode)(image, dblock->elmts, (size_t)udata->hdr->cparam.nelmts, + udata->hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTDECODE, "can't decode fixed array data elements") + image += (udata->hdr->cparam.nelmts * udata->hdr->cparam.raw_elmt_size); + } /* end if */ + + /* Sanity check */ + /* (allow for checksum not decoded yet) */ + HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5FA_SIZEOF_CHKSUM)); -/* Set the data block's size */ -dblock->size = H5FA_DBLOCK_SIZE(dblock); + /* Set the data block's size */ + dblock->size = H5FA_DBLOCK_SIZE(dblock); -/* checksum verification already done in verify_chksum cb */ + /* checksum verification already done in verify_chksum cb */ -/* Metadata checksum */ -UINT32DECODE(image, stored_chksum); + /* Metadata checksum */ + UINT32DECODE(image, stored_chksum); -/* Sanity check */ -HDassert((size_t)(image - (const uint8_t *)_image) == len); + /* Sanity check */ + HDassert((size_t)(image - (const uint8_t *)_image) == len); -/* Set return value */ -ret_value = dblock; + /* Set return value */ + ret_value = dblock; -CATCH + CATCH -/* Release resources */ -if (!ret_value) - if (dblock && H5FA__dblock_dest(dblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block") + /* Release resources */ + if (!ret_value) + if (dblock && H5FA__dblock_dest(dblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block") END_FUNC(STATIC) /* end H5FA__cache_dblock_deserialize() */ @@ -711,18 +712,18 @@ END_FUNC(STATIC) /* end H5FA__cache_dblock_deserialize() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__cache_dblock_image_len(const void *_thing, size_t *image_len)) -/* Local variables */ -const H5FA_dblock_t *dblock = (const H5FA_dblock_t *)_thing; /* Pointer to the object */ + /* Local variables */ + const H5FA_dblock_t *dblock = (const H5FA_dblock_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(dblock); -HDassert(image_len); + /* Check arguments */ + HDassert(dblock); + HDassert(image_len); -/* Set the image length size */ -if (!dblock->npages) - *image_len = (size_t)dblock->size; -else - *image_len = H5FA_DBLOCK_PREFIX_SIZE(dblock); + /* Set the image length size */ + if (!dblock->npages) + *image_len = (size_t)dblock->size; + else + *image_len = H5FA_DBLOCK_PREFIX_SIZE(dblock); END_FUNC(STATIC) /* end H5FA__cache_dblock_image_len() */ @@ -742,60 +743,60 @@ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5FA__cache_dblock_serialize(const H5F_t *f, void *_image, size_t H5_ATTR_UNUSED len, void *_thing)) -/* Local variables */ -H5FA_dblock_t *dblock = (H5FA_dblock_t *)_thing; /* Pointer to the object to serialize */ -uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t metadata_chksum; /* Computed metadata checksum value */ + /* Local variables */ + H5FA_dblock_t *dblock = (H5FA_dblock_t *)_thing; /* Pointer to the object to serialize */ + uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t metadata_chksum; /* Computed metadata checksum value */ -/* Check arguments */ -HDassert(f); -HDassert(image); -HDassert(dblock); -HDassert(dblock->hdr); + /* Check arguments */ + HDassert(f); + HDassert(image); + HDassert(dblock); + HDassert(dblock->hdr); -/* Magic number */ -H5MM_memcpy(image, H5FA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); -image += H5_SIZEOF_MAGIC; + /* Magic number */ + H5MM_memcpy(image, H5FA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC); + image += H5_SIZEOF_MAGIC; -/* Version # */ -*image++ = H5FA_DBLOCK_VERSION; + /* Version # */ + *image++ = H5FA_DBLOCK_VERSION; -/* Fixed array type */ -HDassert(dblock->hdr->cparam.cls->id <= 255); -*image++ = (uint8_t)dblock->hdr->cparam.cls->id; + /* Fixed array type */ + HDassert(dblock->hdr->cparam.cls->id <= 255); + *image++ = (uint8_t)dblock->hdr->cparam.cls->id; -/* Address of array header for array which owns this block */ -H5F_addr_encode(f, &image, dblock->hdr->addr); + /* Address of array header for array which owns this block */ + H5F_addr_encode(f, &image, dblock->hdr->addr); -/* Page init flags */ -if (dblock->npages > 0) { - /* Store the 'page init' bitmasks */ - H5MM_memcpy(image, dblock->dblk_page_init, dblock->dblk_page_init_size); - image += dblock->dblk_page_init_size; -} /* end if */ + /* Page init flags */ + if (dblock->npages > 0) { + /* Store the 'page init' bitmasks */ + H5MM_memcpy(image, dblock->dblk_page_init, dblock->dblk_page_init_size); + image += dblock->dblk_page_init_size; + } /* end if */ -/* Only encode elements if the data block is not paged */ -if (!dblock->npages) { - /* Encode elements in data block */ + /* Only encode elements if the data block is not paged */ + if (!dblock->npages) { + /* Encode elements in data block */ - /* Convert from native elements in memory into raw elements on disk */ - H5_CHECK_OVERFLOW(dblock->hdr->cparam.nelmts, /* From: */ hsize_t, /* To: */ size_t); - if ((dblock->hdr->cparam.cls->encode)(image, dblock->elmts, (size_t)dblock->hdr->cparam.nelmts, - dblock->hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTENCODE, "can't encode fixed array data elements") - image += (dblock->hdr->cparam.nelmts * dblock->hdr->cparam.raw_elmt_size); -} /* end if */ + /* Convert from native elements in memory into raw elements on disk */ + H5_CHECK_OVERFLOW(dblock->hdr->cparam.nelmts, /* From: */ hsize_t, /* To: */ size_t); + if ((dblock->hdr->cparam.cls->encode)(image, dblock->elmts, (size_t)dblock->hdr->cparam.nelmts, + dblock->hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTENCODE, "can't encode fixed array data elements") + image += (dblock->hdr->cparam.nelmts * dblock->hdr->cparam.raw_elmt_size); + } /* end if */ -/* Compute metadata checksum */ -metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); + /* Compute metadata checksum */ + metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); -/* Metadata checksum */ -UINT32ENCODE(image, metadata_chksum); + /* Metadata checksum */ + UINT32ENCODE(image, metadata_chksum); -/* Sanity check */ -HDassert((size_t)(image - (uint8_t *)_image) == len); + /* Sanity check */ + HDassert((size_t)(image - (uint8_t *)_image) == len); -CATCH + CATCH END_FUNC(STATIC) /* end H5FA__cache_dblock_serialize() */ @@ -814,60 +815,60 @@ END_FUNC(STATIC) /* end H5FA__cache_dblock_serialize() */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5FA__cache_dblock_notify(H5AC_notify_action_t action, void *_thing)) -/* Local variables */ -H5FA_dblock_t *dblock = (H5FA_dblock_t *)_thing; - -/* Sanity check */ -HDassert(dblock); - -/* Check if the file was opened with SWMR-write access */ -if (dblock->hdr->swmr_write) { - /* Determine which action to take */ - switch (action) { - case H5AC_NOTIFY_ACTION_AFTER_INSERT: - case H5AC_NOTIFY_ACTION_AFTER_LOAD: - /* Create flush dependency on parent */ - if (H5FA__create_flush_depend((H5AC_info_t *)dblock->hdr, (H5AC_info_t *)dblock) < 0) - H5E_THROW(H5E_CANTDEPEND, - "unable to create flush dependency between data block and header, address = %llu", - (unsigned long long)dblock->addr) - break; - - case H5AC_NOTIFY_ACTION_AFTER_FLUSH: - case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: - case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: - case H5AC_NOTIFY_ACTION_CHILD_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: - case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: - /* do nothing */ - break; + /* Local variables */ + H5FA_dblock_t *dblock = (H5FA_dblock_t *)_thing; - case H5AC_NOTIFY_ACTION_BEFORE_EVICT: - /* Destroy flush dependency on parent */ - if (H5FA__destroy_flush_depend((H5AC_info_t *)dblock->hdr, (H5AC_info_t *)dblock) < 0) - H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency") + /* Sanity check */ + HDassert(dblock); - /* Detach from 'top' proxy for fixed array */ - if (dblock->top_proxy) { - if (H5AC_proxy_entry_remove_child(dblock->top_proxy, dblock) < 0) + /* Check if the file was opened with SWMR-write access */ + if (dblock->hdr->swmr_write) { + /* Determine which action to take */ + switch (action) { + case H5AC_NOTIFY_ACTION_AFTER_INSERT: + case H5AC_NOTIFY_ACTION_AFTER_LOAD: + /* Create flush dependency on parent */ + if (H5FA__create_flush_depend((H5AC_info_t *)dblock->hdr, (H5AC_info_t *)dblock) < 0) H5E_THROW( - H5E_CANTUNDEPEND, - "unable to destroy flush dependency between data block and fixed array 'top' proxy") - dblock->top_proxy = NULL; - } /* end if */ - break; - - default: + H5E_CANTDEPEND, + "unable to create flush dependency between data block and header, address = %llu", + (unsigned long long)dblock->addr) + break; + + case H5AC_NOTIFY_ACTION_AFTER_FLUSH: + case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: + case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: + case H5AC_NOTIFY_ACTION_CHILD_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: + case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: + /* do nothing */ + break; + + case H5AC_NOTIFY_ACTION_BEFORE_EVICT: + /* Destroy flush dependency on parent */ + if (H5FA__destroy_flush_depend((H5AC_info_t *)dblock->hdr, (H5AC_info_t *)dblock) < 0) + H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency") + + /* Detach from 'top' proxy for fixed array */ + if (dblock->top_proxy) { + if (H5AC_proxy_entry_remove_child(dblock->top_proxy, dblock) < 0) + H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency between data block " + "and fixed array 'top' proxy") + dblock->top_proxy = NULL; + } /* end if */ + break; + + default: #ifdef NDEBUG - H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") -#else /* NDEBUG */ - HDassert(0 && "Unknown action?!?"); -#endif /* NDEBUG */ - } /* end switch */ -} /* end if */ + H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") +#else /* NDEBUG */ + HDassert(0 && "Unknown action?!?"); +#endif /* NDEBUG */ + } /* end switch */ + } /* end if */ -CATCH + CATCH END_FUNC(STATIC) /* end H5FA__cache_dblock_notify() */ @@ -886,16 +887,16 @@ END_FUNC(STATIC) /* end H5FA__cache_dblock_notify() */ */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5FA__cache_dblock_free_icr(void *_thing)) -H5FA_dblock_t *dblock = (H5FA_dblock_t *)_thing; /* Pointer to the object */ + H5FA_dblock_t *dblock = (H5FA_dblock_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(dblock); + /* Check arguments */ + HDassert(dblock); -/* Release the fixed array data block */ -if (H5FA__dblock_dest(dblock) < 0) - H5E_THROW(H5E_CANTFREE, "can't free fixed array data block") + /* Release the fixed array data block */ + if (H5FA__dblock_dest(dblock) < 0) + H5E_THROW(H5E_CANTFREE, "can't free fixed array data block") -CATCH + CATCH END_FUNC(STATIC) /* end H5FA__cache_dblock_free_icr() */ @@ -931,15 +932,15 @@ END_FUNC(STATIC) /* end H5FA__cache_dblock_free_icr() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__cache_dblock_fsf_size(const void *_thing, hsize_t *fsf_size)) -const H5FA_dblock_t *dblock = (const H5FA_dblock_t *)_thing; /* Pointer to the object */ + const H5FA_dblock_t *dblock = (const H5FA_dblock_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(dblock); -HDassert(dblock->cache_info.magic == H5C__H5C_CACHE_ENTRY_T_MAGIC); -HDassert(dblock->cache_info.type == H5AC_FARRAY_DBLOCK); -HDassert(fsf_size); + /* Check arguments */ + HDassert(dblock); + HDassert(dblock->cache_info.magic == H5C__H5C_CACHE_ENTRY_T_MAGIC); + HDassert(dblock->cache_info.type == H5AC_FARRAY_DBLOCK); + HDassert(fsf_size); -*fsf_size = dblock->size; + *fsf_size = dblock->size; END_FUNC(STATIC) /* end H5FA__cache_dblock_fsf_size() */ @@ -958,17 +959,17 @@ END_FUNC(STATIC) /* end H5FA__cache_dblock_fsf_size() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__cache_dblk_page_get_initial_load_size(void *_udata, size_t *image_len)) -/* Local variables */ -H5FA_dblk_page_cache_ud_t *udata = (H5FA_dblk_page_cache_ud_t *)_udata; /* User data */ + /* Local variables */ + H5FA_dblk_page_cache_ud_t *udata = (H5FA_dblk_page_cache_ud_t *)_udata; /* User data */ -/* Check arguments */ -HDassert(udata); -HDassert(udata->hdr); -HDassert(udata->nelmts > 0); -HDassert(image_len); + /* Check arguments */ + HDassert(udata); + HDassert(udata->hdr); + HDassert(udata->nelmts > 0); + HDassert(image_len); -/* Set the image length size */ -*image_len = (size_t)H5FA_DBLK_PAGE_SIZE(udata->hdr, udata->nelmts); + /* Set the image length size */ + *image_len = (size_t)H5FA_DBLK_PAGE_SIZE(udata->hdr, udata->nelmts); END_FUNC(STATIC) /* end H5FA__cache_dblk_page_get_initial_load_size() */ @@ -988,19 +989,19 @@ END_FUNC(STATIC) /* end H5FA__cache_dblk_page_get_initial_load_size() */ BEGIN_FUNC(STATIC, NOERR, htri_t, TRUE, -, H5FA__cache_dblk_page_verify_chksum(const void *_image, size_t len, void H5_ATTR_UNUSED *_udata)) -/* Local variables */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ -uint32_t computed_chksum; /* Computed metadata checksum value */ + /* Local variables */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ -/* Check arguments */ -HDassert(image); + /* Check arguments */ + HDassert(image); -/* Get stored and computed checksums */ -H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); + /* Get stored and computed checksums */ + H5F_get_checksums(image, len, &stored_chksum, &computed_chksum); -if (stored_chksum != computed_chksum) - ret_value = FALSE; + if (stored_chksum != computed_chksum) + ret_value = FALSE; END_FUNC(STATIC) /* end H5FA__cache_dblk_page_verify_chksum() */ @@ -1021,58 +1022,58 @@ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5FA__cache_dblk_page_deserialize(const void *_image, size_t len, void *_udata, hbool_t H5_ATTR_UNUSED *dirty)) -/* Local variables */ -H5FA_dblk_page_t * dblk_page = NULL; /* Data block page info */ -H5FA_dblk_page_cache_ud_t *udata = - (H5FA_dblk_page_cache_ud_t *)_udata; /* User data for loading data block page */ -const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t stored_chksum; /* Stored metadata checksum value */ + /* Local variables */ + H5FA_dblk_page_t * dblk_page = NULL; /* Data block page info */ + H5FA_dblk_page_cache_ud_t *udata = + (H5FA_dblk_page_cache_ud_t *)_udata; /* User data for loading data block page */ + const uint8_t *image = (const uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t stored_chksum; /* Stored metadata checksum value */ -/* Sanity check */ -HDassert(udata); -HDassert(udata->hdr); -HDassert(udata->nelmts > 0); -HDassert(H5F_addr_defined(udata->dblk_page_addr)); + /* Sanity check */ + HDassert(udata); + HDassert(udata->hdr); + HDassert(udata->nelmts > 0); + HDassert(H5F_addr_defined(udata->dblk_page_addr)); -/* Allocate the fixed array data block page */ -if (NULL == (dblk_page = H5FA__dblk_page_alloc(udata->hdr, udata->nelmts))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block page") + /* Allocate the fixed array data block page */ + if (NULL == (dblk_page = H5FA__dblk_page_alloc(udata->hdr, udata->nelmts))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block page") -/* Set the fixed array data block's information */ -dblk_page->addr = udata->dblk_page_addr; + /* Set the fixed array data block's information */ + dblk_page->addr = udata->dblk_page_addr; -/* Internal information */ + /* Internal information */ -/* Decode elements in data block page */ -/* Convert from raw elements on disk into native elements in memory */ -if ((udata->hdr->cparam.cls->decode)(image, dblk_page->elmts, udata->nelmts, udata->hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTDECODE, "can't decode fixed array data elements") -image += (udata->nelmts * udata->hdr->cparam.raw_elmt_size); + /* Decode elements in data block page */ + /* Convert from raw elements on disk into native elements in memory */ + if ((udata->hdr->cparam.cls->decode)(image, dblk_page->elmts, udata->nelmts, udata->hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTDECODE, "can't decode fixed array data elements") + image += (udata->nelmts * udata->hdr->cparam.raw_elmt_size); -/* Sanity check */ -/* (allow for checksum not decoded yet) */ -HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5FA_SIZEOF_CHKSUM)); + /* Sanity check */ + /* (allow for checksum not decoded yet) */ + HDassert((size_t)(image - (const uint8_t *)_image) == (len - H5FA_SIZEOF_CHKSUM)); -/* Set the data block page's size */ -dblk_page->size = len; + /* Set the data block page's size */ + dblk_page->size = len; -/* checksum verification already done in verify_chksum cb */ + /* checksum verification already done in verify_chksum cb */ -/* Metadata checksum */ -UINT32DECODE(image, stored_chksum); + /* Metadata checksum */ + UINT32DECODE(image, stored_chksum); -/* Sanity check */ -HDassert((size_t)(image - (const uint8_t *)_image) == dblk_page->size); + /* Sanity check */ + HDassert((size_t)(image - (const uint8_t *)_image) == dblk_page->size); -/* Set return value */ -ret_value = dblk_page; + /* Set return value */ + ret_value = dblk_page; -CATCH + CATCH -/* Release resources */ -if (!ret_value) - if (dblk_page && H5FA__dblk_page_dest(dblk_page) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block page") + /* Release resources */ + if (!ret_value) + if (dblk_page && H5FA__dblk_page_dest(dblk_page) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block page") END_FUNC(STATIC) /* end H5FA__cache_dblk_page_deserialize() */ @@ -1091,15 +1092,15 @@ END_FUNC(STATIC) /* end H5FA__cache_dblk_page_deserialize() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__cache_dblk_page_image_len(const void *_thing, size_t *image_len)) -/* Local variables */ -const H5FA_dblk_page_t *dblk_page = (const H5FA_dblk_page_t *)_thing; /* Pointer to the object */ + /* Local variables */ + const H5FA_dblk_page_t *dblk_page = (const H5FA_dblk_page_t *)_thing; /* Pointer to the object */ -/* Check arguments */ -HDassert(dblk_page); -HDassert(image_len); + /* Check arguments */ + HDassert(dblk_page); + HDassert(image_len); -/* Set the image length size */ -*image_len = dblk_page->size; + /* Set the image length size */ + *image_len = dblk_page->size; END_FUNC(STATIC) /* end H5FA__cache_dblk_page_image_len() */ @@ -1119,37 +1120,37 @@ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5FA__cache_dblk_page_serialize(const H5F_t H5_ATTR_NDEBUG_UNUSED *f, void *_image, size_t H5_ATTR_UNUSED len, void *_thing)) -/* Local variables */ -H5FA_dblk_page_t *dblk_page = (H5FA_dblk_page_t *)_thing; /* Pointer to the object to serialize */ -uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ -uint32_t metadata_chksum; /* Computed metadata checksum value */ + /* Local variables */ + H5FA_dblk_page_t *dblk_page = (H5FA_dblk_page_t *)_thing; /* Pointer to the object to serialize */ + uint8_t * image = (uint8_t *)_image; /* Pointer into raw data buffer */ + uint32_t metadata_chksum; /* Computed metadata checksum value */ -/* Sanity check */ -HDassert(f); -HDassert(image); -HDassert(dblk_page); -HDassert(dblk_page->hdr); + /* Sanity check */ + HDassert(f); + HDassert(image); + HDassert(dblk_page); + HDassert(dblk_page->hdr); -/* Internal information */ + /* Internal information */ -/* Encode elements in data block page */ + /* Encode elements in data block page */ -/* Convert from native elements in memory into raw elements on disk */ -if ((dblk_page->hdr->cparam.cls->encode)(image, dblk_page->elmts, dblk_page->nelmts, dblk_page->hdr->cb_ctx) < - 0) - H5E_THROW(H5E_CANTENCODE, "can't encode fixed array data elements") -image += (dblk_page->nelmts * dblk_page->hdr->cparam.raw_elmt_size); + /* Convert from native elements in memory into raw elements on disk */ + if ((dblk_page->hdr->cparam.cls->encode)(image, dblk_page->elmts, dblk_page->nelmts, + dblk_page->hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTENCODE, "can't encode fixed array data elements") + image += (dblk_page->nelmts * dblk_page->hdr->cparam.raw_elmt_size); -/* Compute metadata checksum */ -metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); + /* Compute metadata checksum */ + metadata_chksum = H5_checksum_metadata(_image, (size_t)(image - (uint8_t *)_image), 0); -/* Metadata checksum */ -UINT32ENCODE(image, metadata_chksum); + /* Metadata checksum */ + UINT32ENCODE(image, metadata_chksum); -/* Sanity check */ -HDassert((size_t)(image - (uint8_t *)_image) == len); + /* Sanity check */ + HDassert((size_t)(image - (uint8_t *)_image) == len); -CATCH + CATCH END_FUNC(STATIC) /* end H5FA__cache_dblk_page_serialize() */ @@ -1168,49 +1169,48 @@ END_FUNC(STATIC) /* end H5FA__cache_dblk_page_serialize() */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5FA__cache_dblk_page_notify(H5AC_notify_action_t action, void *_thing)) -/* Local variables */ -H5FA_dblk_page_t *dblk_page = (H5FA_dblk_page_t *)_thing; /* Pointer to the object */ - -/* Sanity check */ -HDassert(dblk_page); - -/* Determine which action to take */ -switch (action) { - case H5AC_NOTIFY_ACTION_AFTER_INSERT: - case H5AC_NOTIFY_ACTION_AFTER_LOAD: - case H5AC_NOTIFY_ACTION_AFTER_FLUSH: - /* do nothing */ - break; - - case H5AC_NOTIFY_ACTION_BEFORE_EVICT: - /* Detach from 'top' proxy for fixed array */ - if (dblk_page->top_proxy) { - if (H5AC_proxy_entry_remove_child(dblk_page->top_proxy, dblk_page) < 0) - H5E_THROW( - H5E_CANTUNDEPEND, - "unable to destroy flush dependency between data block page and fixed array 'top' proxy") - dblk_page->top_proxy = NULL; - } /* end if */ - break; - - case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: - case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: - case H5AC_NOTIFY_ACTION_CHILD_CLEANED: - case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: - case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: - /* do nothing */ - break; - - default: + /* Local variables */ + H5FA_dblk_page_t *dblk_page = (H5FA_dblk_page_t *)_thing; /* Pointer to the object */ + + /* Sanity check */ + HDassert(dblk_page); + + /* Determine which action to take */ + switch (action) { + case H5AC_NOTIFY_ACTION_AFTER_INSERT: + case H5AC_NOTIFY_ACTION_AFTER_LOAD: + case H5AC_NOTIFY_ACTION_AFTER_FLUSH: + /* do nothing */ + break; + + case H5AC_NOTIFY_ACTION_BEFORE_EVICT: + /* Detach from 'top' proxy for fixed array */ + if (dblk_page->top_proxy) { + if (H5AC_proxy_entry_remove_child(dblk_page->top_proxy, dblk_page) < 0) + H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency between data block page " + "and fixed array 'top' proxy") + dblk_page->top_proxy = NULL; + } /* end if */ + break; + + case H5AC_NOTIFY_ACTION_ENTRY_DIRTIED: + case H5AC_NOTIFY_ACTION_ENTRY_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_DIRTIED: + case H5AC_NOTIFY_ACTION_CHILD_CLEANED: + case H5AC_NOTIFY_ACTION_CHILD_UNSERIALIZED: + case H5AC_NOTIFY_ACTION_CHILD_SERIALIZED: + /* do nothing */ + break; + + default: #ifdef NDEBUG - H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") + H5E_THROW(H5E_BADVALUE, "unknown action from metadata cache") #else /* NDEBUG */ - HDassert(0 && "Unknown action?!?"); + HDassert(0 && "Unknown action?!?"); #endif /* NDEBUG */ -} /* end switch */ + } /* end switch */ -CATCH + CATCH END_FUNC(STATIC) /* end H5FA__cache_dblk_page_notify() */ @@ -1229,13 +1229,13 @@ END_FUNC(STATIC) /* end H5FA__cache_dblk_page_notify() */ */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5FA__cache_dblk_page_free_icr(void *thing)) -/* Check arguments */ -HDassert(thing); + /* Check arguments */ + HDassert(thing); -/* Release the fixed array data block page */ -if (H5FA__dblk_page_dest((H5FA_dblk_page_t *)thing) < 0) - H5E_THROW(H5E_CANTFREE, "can't free fixed array data block page") + /* Release the fixed array data block page */ + if (H5FA__dblk_page_dest((H5FA_dblk_page_t *)thing) < 0) + H5E_THROW(H5E_CANTFREE, "can't free fixed array data block page") -CATCH + CATCH END_FUNC(STATIC) /* end H5FA__cache_dblk_page_free_icr() */ diff --git a/src/H5FAdbg.c b/src/H5FAdbg.c index 37ad94d..b50cd67 100644 --- a/src/H5FAdbg.c +++ b/src/H5FAdbg.c @@ -83,53 +83,53 @@ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__hdr_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth, const H5FA_class_t *cls, haddr_t obj_addr)) -/* Local variables */ -H5FA_hdr_t *hdr = NULL; /* Shared fixed array header */ -void * dbg_ctx = NULL; /* Fixed array debugging context */ - -/* Check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); -HDassert(H5F_addr_defined(obj_addr)); -HDassert(stream); -HDassert(indent >= 0); -HDassert(fwidth >= 0); -HDassert(cls); - -/* Check for debugging context callback available */ -if (cls->crt_dbg_ctx) - /* Create debugging context */ - if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) - H5E_THROW(H5E_CANTGET, "unable to create fixed array debugging context") - -/* Load the fixed array header */ -if (NULL == (hdr = H5FA__hdr_protect(f, addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load fixed array header") - -/* Print opening message */ -HDfprintf(stream, "%*sFixed Array Header...\n", indent, ""); - -/* Print the values */ -HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Header size:", hdr->size); -HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, - "Raw Element Size:", (unsigned)hdr->cparam.raw_elmt_size); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, - "Native Element Size (on this platform):", hdr->cparam.cls->nat_elmt_size); - -HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Max. # of elements in data block page:", - (unsigned)((size_t)1 << hdr->cparam.max_dblk_page_nelmts_bits)); - -HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, - "Number of elements in Fixed Array:", hdr->stats.nelmts); - -HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Fixed Array Data Block Address:", hdr->dblk_addr); - -CATCH -if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to release fixed array debugging context") -if (hdr && H5FA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array header") + /* Local variables */ + H5FA_hdr_t *hdr = NULL; /* Shared fixed array header */ + void * dbg_ctx = NULL; /* Fixed array debugging context */ + + /* Check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + HDassert(H5F_addr_defined(obj_addr)); + HDassert(stream); + HDassert(indent >= 0); + HDassert(fwidth >= 0); + HDassert(cls); + + /* Check for debugging context callback available */ + if (cls->crt_dbg_ctx) + /* Create debugging context */ + if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) + H5E_THROW(H5E_CANTGET, "unable to create fixed array debugging context") + + /* Load the fixed array header */ + if (NULL == (hdr = H5FA__hdr_protect(f, addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load fixed array header") + + /* Print opening message */ + HDfprintf(stream, "%*sFixed Array Header...\n", indent, ""); + + /* Print the values */ + HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Header size:", hdr->size); + HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, + "Raw Element Size:", (unsigned)hdr->cparam.raw_elmt_size); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, + "Native Element Size (on this platform):", hdr->cparam.cls->nat_elmt_size); + + HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Max. # of elements in data block page:", + (unsigned)((size_t)1 << hdr->cparam.max_dblk_page_nelmts_bits)); + + HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, + "Number of elements in Fixed Array:", hdr->stats.nelmts); + + HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Fixed Array Data Block Address:", hdr->dblk_addr); + + CATCH + if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to release fixed array debugging context") + if (hdr && H5FA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array header") END_FUNC(PKG) /* end H5FA__hdr_debug() */ @@ -149,114 +149,116 @@ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__dblock_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth, const H5FA_class_t *cls, haddr_t hdr_addr, haddr_t obj_addr)) -/* Local variables */ -H5FA_hdr_t * hdr = NULL; /* Shared fixed array header */ -H5FA_dblock_t *dblock = NULL; /* Fixed array data block */ -void * dbg_ctx = NULL; /* Fixed array context */ -size_t u; /* Local index variable */ - -/* Check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); -HDassert(stream); -HDassert(indent >= 0); -HDassert(fwidth >= 0); -HDassert(cls); -HDassert(H5F_addr_defined(hdr_addr)); -HDassert(H5F_addr_defined(obj_addr)); - -/* Check for debugging context callback available */ -if (cls->crt_dbg_ctx) - /* Create debugging context */ - if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) - H5E_THROW(H5E_CANTGET, "unable to create fixed array debugging context") - -/* Load the fixed array header */ -if (NULL == (hdr = H5FA__hdr_protect(f, hdr_addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load fixed array header") - -/* Protect data block */ -if (NULL == (dblock = H5FA__dblock_protect(hdr, addr, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block, address = %llu", - (unsigned long long)addr) - -/* Print opening message */ -HDfprintf(stream, "%*sFixed Array data Block...\n", indent, ""); - -/* Print the values */ -HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); -HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Address of Data Block:", dblock->addr); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Data Block size:", dblock->size); -HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, - "Number of elements in Data Block:", hdr->cparam.nelmts); -HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, "Number of pages in Data Block:", dblock->npages); -HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, - "Number of elements per Data Block page:", dblock->dblk_page_nelmts); - -if (dblock->npages) { /* paging */ - size_t dblk_page_nelmts; /* # of elements in a data block page */ - haddr_t dblk_page_addr; /* Address of a data block page */ - size_t page_idx; /* Page index within data block */ - - HDfprintf(stream, "%*sPaging:\n", indent, ""); - - /* Iterate over the pages */ - dblk_page_addr = dblock->addr + H5FA_DBLOCK_PREFIX_SIZE(dblock); - dblk_page_nelmts = dblock->dblk_page_nelmts; - - /* Read and print each page's elements in the data block */ - for (page_idx = 0; page_idx < dblock->npages; page_idx++) { - if (!H5VM_bit_get(dblock->dblk_page_init, page_idx)) { - HDfprintf(stream, "%*s%-*s %Hu %s\n", indent, "", fwidth, "Page %Zu:", page_idx, "empty"); - - } /* end if */ - else { /* get the page */ - H5FA_dblk_page_t *dblk_page; /* Pointer to a data block page */ - hsize_t nelmts_left; /* Remaining elements in the last data block page */ - - /* Check for last page */ - if (((page_idx + 1) == dblock->npages) && - (nelmts_left = hdr->cparam.nelmts % dblock->dblk_page_nelmts)) - dblk_page_nelmts = (size_t)nelmts_left; - - if (NULL == (dblk_page = H5FA__dblk_page_protect(hdr, dblk_page_addr, dblk_page_nelmts, - H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block page, address = %llu", - (unsigned long long)dblk_page_addr) - - HDfprintf(stream, "%*sElements in page %Zu:\n", indent, "", page_idx); - for (u = 0; u < dblk_page_nelmts; u++) { - /* Call the class's 'debug' callback */ - if ((hdr->cparam.cls->debug)(stream, (indent + 3), MAX(0, (fwidth - 3)), (hsize_t)u, - ((uint8_t *)dblk_page->elmts) + - (hdr->cparam.cls->nat_elmt_size * u)) < 0) - H5E_THROW(H5E_CANTGET, "can't get element for debugging") - } /* end for */ - if (H5FA__dblk_page_unprotect(dblk_page, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block page") - - /* Advance to next page address */ - dblk_page_addr += dblock->dblk_page_size; - } /* paging */ - } /* end for npages */ -} /* end if */ -else { /* not paging */ - /* Print the elements in the data block */ - HDfprintf(stream, "%*sElements:\n", indent, ""); - for (u = 0; u < hdr->cparam.nelmts; u++) { - /* Call the class's 'debug' callback */ - if ((hdr->cparam.cls->debug)(stream, (indent + 3), MAX(0, (fwidth - 3)), (hsize_t)u, - ((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * u)) < 0) - H5E_THROW(H5E_CANTGET, "can't get element for debugging") - } /* end for */ -} /* end else */ - -CATCH -if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to release fixed array debugging context") -if (dblock && H5FA__dblock_unprotect(dblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block") -if (hdr && H5FA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array header") + /* Local variables */ + H5FA_hdr_t * hdr = NULL; /* Shared fixed array header */ + H5FA_dblock_t *dblock = NULL; /* Fixed array data block */ + void * dbg_ctx = NULL; /* Fixed array context */ + size_t u; /* Local index variable */ + + /* Check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + HDassert(stream); + HDassert(indent >= 0); + HDassert(fwidth >= 0); + HDassert(cls); + HDassert(H5F_addr_defined(hdr_addr)); + HDassert(H5F_addr_defined(obj_addr)); + + /* Check for debugging context callback available */ + if (cls->crt_dbg_ctx) + /* Create debugging context */ + if (NULL == (dbg_ctx = cls->crt_dbg_ctx(f, obj_addr))) + H5E_THROW(H5E_CANTGET, "unable to create fixed array debugging context") + + /* Load the fixed array header */ + if (NULL == (hdr = H5FA__hdr_protect(f, hdr_addr, dbg_ctx, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load fixed array header") + + /* Protect data block */ + if (NULL == (dblock = H5FA__dblock_protect(hdr, addr, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block, address = %llu", + (unsigned long long)addr) + + /* Print opening message */ + HDfprintf(stream, "%*sFixed Array data Block...\n", indent, ""); + + /* Print the values */ + HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Array class ID:", hdr->cparam.cls->name); + HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Address of Data Block:", dblock->addr); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Data Block size:", dblock->size); + HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, + "Number of elements in Data Block:", hdr->cparam.nelmts); + HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, "Number of pages in Data Block:", dblock->npages); + HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth, + "Number of elements per Data Block page:", dblock->dblk_page_nelmts); + + if (dblock->npages) { /* paging */ + size_t dblk_page_nelmts; /* # of elements in a data block page */ + haddr_t dblk_page_addr; /* Address of a data block page */ + size_t page_idx; /* Page index within data block */ + + HDfprintf(stream, "%*sPaging:\n", indent, ""); + + /* Iterate over the pages */ + dblk_page_addr = dblock->addr + H5FA_DBLOCK_PREFIX_SIZE(dblock); + dblk_page_nelmts = dblock->dblk_page_nelmts; + + /* Read and print each page's elements in the data block */ + for (page_idx = 0; page_idx < dblock->npages; page_idx++) { + if (!H5VM_bit_get(dblock->dblk_page_init, page_idx)) { + HDfprintf(stream, "%*s%-*s %Hu %s\n", indent, "", fwidth, "Page %Zu:", page_idx, "empty"); + + } /* end if */ + else { /* get the page */ + H5FA_dblk_page_t *dblk_page; /* Pointer to a data block page */ + hsize_t nelmts_left; /* Remaining elements in the last data block page */ + + /* Check for last page */ + if (((page_idx + 1) == dblock->npages) && + (nelmts_left = hdr->cparam.nelmts % dblock->dblk_page_nelmts)) + dblk_page_nelmts = (size_t)nelmts_left; + + if (NULL == (dblk_page = H5FA__dblk_page_protect(hdr, dblk_page_addr, dblk_page_nelmts, + H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, + "unable to protect fixed array data block page, address = %llu", + (unsigned long long)dblk_page_addr) + + HDfprintf(stream, "%*sElements in page %Zu:\n", indent, "", page_idx); + for (u = 0; u < dblk_page_nelmts; u++) { + /* Call the class's 'debug' callback */ + if ((hdr->cparam.cls->debug)(stream, (indent + 3), MAX(0, (fwidth - 3)), (hsize_t)u, + ((uint8_t *)dblk_page->elmts) + + (hdr->cparam.cls->nat_elmt_size * u)) < 0) + H5E_THROW(H5E_CANTGET, "can't get element for debugging") + } /* end for */ + if (H5FA__dblk_page_unprotect(dblk_page, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block page") + + /* Advance to next page address */ + dblk_page_addr += dblock->dblk_page_size; + } /* paging */ + } /* end for npages */ + } /* end if */ + else { /* not paging */ + /* Print the elements in the data block */ + HDfprintf(stream, "%*sElements:\n", indent, ""); + for (u = 0; u < hdr->cparam.nelmts; u++) { + /* Call the class's 'debug' callback */ + if ((hdr->cparam.cls->debug)(stream, (indent + 3), MAX(0, (fwidth - 3)), (hsize_t)u, + ((uint8_t *)dblock->elmts) + (hdr->cparam.cls->nat_elmt_size * u)) < + 0) + H5E_THROW(H5E_CANTGET, "can't get element for debugging") + } /* end for */ + } /* end else */ + + CATCH + if (dbg_ctx && cls->dst_dbg_ctx(dbg_ctx) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to release fixed array debugging context") + if (dblock && H5FA__dblock_unprotect(dblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block") + if (hdr && H5FA__hdr_unprotect(hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array header") END_FUNC(PKG) /* end H5FA__dblock_debug() */ diff --git a/src/H5FAdblkpage.c b/src/H5FAdblkpage.c index 24012ec..61aaf0e 100644 --- a/src/H5FAdblkpage.c +++ b/src/H5FAdblkpage.c @@ -86,36 +86,36 @@ H5FL_BLK_DEFINE(page_elmts); */ BEGIN_FUNC(PKG, ERR, H5FA_dblk_page_t *, NULL, NULL, H5FA__dblk_page_alloc(H5FA_hdr_t *hdr, size_t nelmts)) -/* Local variables */ -H5FA_dblk_page_t *dblk_page = NULL; /* Fixed array data block page */ + /* Local variables */ + H5FA_dblk_page_t *dblk_page = NULL; /* Fixed array data block page */ -/* Check arguments */ -HDassert(hdr); + /* Check arguments */ + HDassert(hdr); -/* Allocate memory for the data block */ -if (NULL == (dblk_page = H5FL_CALLOC(H5FA_dblk_page_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block page") + /* Allocate memory for the data block */ + if (NULL == (dblk_page = H5FL_CALLOC(H5FA_dblk_page_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block page") -/* Share common array information */ -if (H5FA__hdr_incr(hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") -dblk_page->hdr = hdr; + /* Share common array information */ + if (H5FA__hdr_incr(hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") + dblk_page->hdr = hdr; -/* Set non-zero internal fields */ -dblk_page->nelmts = nelmts; + /* Set non-zero internal fields */ + dblk_page->nelmts = nelmts; -/* Allocate buffer for elements in data block page */ -if (NULL == (dblk_page->elmts = H5FL_BLK_MALLOC(page_elmts, nelmts * hdr->cparam.cls->nat_elmt_size))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block page element buffer") + /* Allocate buffer for elements in data block page */ + if (NULL == (dblk_page->elmts = H5FL_BLK_MALLOC(page_elmts, nelmts * hdr->cparam.cls->nat_elmt_size))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block page element buffer") -/* Set the return value */ -ret_value = dblk_page; + /* Set the return value */ + ret_value = dblk_page; -CATCH + CATCH -if (!ret_value) - if (dblk_page && H5FA__dblk_page_dest(dblk_page) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block page") + if (!ret_value) + if (dblk_page && H5FA__dblk_page_dest(dblk_page) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block page") END_FUNC(PKG) /* end H5FA__dblk_page_alloc() */ @@ -134,57 +134,57 @@ END_FUNC(PKG) /* end H5FA__dblk_page_alloc() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__dblk_page_create(H5FA_hdr_t *hdr, haddr_t addr, size_t nelmts)) -/* Local variables */ -H5FA_dblk_page_t *dblk_page = NULL; /* Fixed array data block page */ -hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ + /* Local variables */ + H5FA_dblk_page_t *dblk_page = NULL; /* Fixed array data block page */ + hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ #ifdef H5FA_DEBUG -HDfprintf(stderr, "%s: Called, addr = %a\n", FUNC, addr); + HDfprintf(stderr, "%s: Called, addr = %a\n", FUNC, addr); #endif /* H5FA_DEBUG */ -/* Sanity check */ -HDassert(hdr); + /* Sanity check */ + HDassert(hdr); -/* Allocate the data block page */ -if (NULL == (dblk_page = H5FA__dblk_page_alloc(hdr, nelmts))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block page") + /* Allocate the data block page */ + if (NULL == (dblk_page = H5FA__dblk_page_alloc(hdr, nelmts))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block page") -/* Set info about data block page on disk */ -dblk_page->addr = addr; -dblk_page->size = H5FA_DBLK_PAGE_SIZE(hdr, nelmts); + /* Set info about data block page on disk */ + dblk_page->addr = addr; + dblk_page->size = H5FA_DBLK_PAGE_SIZE(hdr, nelmts); #ifdef H5FA_DEBUG -HDfprintf(stderr, "%s: dblk_page->size = %Zu\n", FUNC, dblk_page->size); + HDfprintf(stderr, "%s: dblk_page->size = %Zu\n", FUNC, dblk_page->size); #endif /* H5FA_DEBUG */ -/* Clear any elements in data block page to fill value */ -if ((hdr->cparam.cls->fill)(dblk_page->elmts, nelmts) < 0) - H5E_THROW(H5E_CANTSET, "can't set fixed array data block page elements to class's fill value") - -/* Cache the new fixed array data block page */ -if (H5AC_insert_entry(hdr->f, H5AC_FARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTINSERT, "can't add fixed array data block page to cache") -inserted = TRUE; - -/* Add data block page as child of 'top' proxy */ -if (hdr->top_proxy) { - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblk_page) < 0) - H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") - dblk_page->top_proxy = hdr->top_proxy; -} /* end if */ - -CATCH -if (ret_value < 0) - if (dblk_page) { - /* Remove from cache, if inserted */ - if (inserted) - if (H5AC_remove_entry(dblk_page) < 0) - H5E_THROW(H5E_CANTREMOVE, "unable to remove fixed array data block page from cache") - - /* Destroy data block page */ - if (H5FA__dblk_page_dest(dblk_page) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block page") + /* Clear any elements in data block page to fill value */ + if ((hdr->cparam.cls->fill)(dblk_page->elmts, nelmts) < 0) + H5E_THROW(H5E_CANTSET, "can't set fixed array data block page elements to class's fill value") + + /* Cache the new fixed array data block page */ + if (H5AC_insert_entry(hdr->f, H5AC_FARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTINSERT, "can't add fixed array data block page to cache") + inserted = TRUE; + + /* Add data block page as child of 'top' proxy */ + if (hdr->top_proxy) { + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblk_page) < 0) + H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") + dblk_page->top_proxy = hdr->top_proxy; } /* end if */ + CATCH + if (ret_value < 0) + if (dblk_page) { + /* Remove from cache, if inserted */ + if (inserted) + if (H5AC_remove_entry(dblk_page) < 0) + H5E_THROW(H5E_CANTREMOVE, "unable to remove fixed array data block page from cache") + + /* Destroy data block page */ + if (H5FA__dblk_page_dest(dblk_page) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block page") + } /* end if */ + END_FUNC(PKG) /* end H5FA__dblk_page_create() */ /*------------------------------------------------------------------------- @@ -204,53 +204,53 @@ BEGIN_FUNC(PKG, ERR, H5FA_dblk_page_t *, NULL, NULL, H5FA__dblk_page_protect(H5FA_hdr_t *hdr, haddr_t dblk_page_addr, size_t dblk_page_nelmts, unsigned flags)) -/* Local variables */ -H5FA_dblk_page_t * dblk_page = NULL; /* Fixed array data block page */ -H5FA_dblk_page_cache_ud_t udata; /* Information needed for loading data block page */ + /* Local variables */ + H5FA_dblk_page_t * dblk_page = NULL; /* Fixed array data block page */ + H5FA_dblk_page_cache_ud_t udata; /* Information needed for loading data block page */ #ifdef H5FA_DEBUG -HDfprintf(stderr, "%s: Called\n", FUNC); + HDfprintf(stderr, "%s: Called\n", FUNC); #endif /* H5FA_DEBUG */ -/* Sanity check */ -HDassert(hdr); -HDassert(H5F_addr_defined(dblk_page_addr)); - -/* only the H5AC__READ_ONLY_FLAG is permitted */ -HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); - -/* Set up user data */ -udata.hdr = hdr; -udata.nelmts = dblk_page_nelmts; -udata.dblk_page_addr = dblk_page_addr; - -/* Protect the data block page */ -if (NULL == (dblk_page = (H5FA_dblk_page_t *)H5AC_protect(hdr->f, H5AC_FARRAY_DBLK_PAGE, dblk_page_addr, - &udata, flags))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block page, address = %llu", - (unsigned long long)dblk_page_addr) - -/* Create top proxy, if it doesn't exist */ -if (hdr->top_proxy && NULL == dblk_page->top_proxy) { - /* Add data block page as child of 'top' proxy */ - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblk_page) < 0) - H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") - dblk_page->top_proxy = hdr->top_proxy; -} /* end if */ + /* Sanity check */ + HDassert(hdr); + HDassert(H5F_addr_defined(dblk_page_addr)); + + /* only the H5AC__READ_ONLY_FLAG is permitted */ + HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); + + /* Set up user data */ + udata.hdr = hdr; + udata.nelmts = dblk_page_nelmts; + udata.dblk_page_addr = dblk_page_addr; + + /* Protect the data block page */ + if (NULL == (dblk_page = (H5FA_dblk_page_t *)H5AC_protect(hdr->f, H5AC_FARRAY_DBLK_PAGE, dblk_page_addr, + &udata, flags))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block page, address = %llu", + (unsigned long long)dblk_page_addr) + + /* Create top proxy, if it doesn't exist */ + if (hdr->top_proxy && NULL == dblk_page->top_proxy) { + /* Add data block page as child of 'top' proxy */ + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblk_page) < 0) + H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") + dblk_page->top_proxy = hdr->top_proxy; + } /* end if */ -/* Set return value */ -ret_value = dblk_page; + /* Set return value */ + ret_value = dblk_page; -CATCH + CATCH -/* Clean up on error */ -if (!ret_value) { - /* Release the data block page, if it was protected */ - if (dblk_page && - H5AC_unprotect(hdr->f, H5AC_FARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect fixed array data block page, address = %llu", - (unsigned long long)dblk_page->addr) -} /* end if */ + /* Clean up on error */ + if (!ret_value) { + /* Release the data block page, if it was protected */ + if (dblk_page && + H5AC_unprotect(hdr->f, H5AC_FARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect fixed array data block page, address = %llu", + (unsigned long long)dblk_page->addr) + } /* end if */ END_FUNC(PKG) /* end H5FA__dblk_page_protect() */ @@ -273,18 +273,18 @@ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, /* Local variables */ #ifdef H5FA_DEBUG -HDfprintf(stderr, "%s: Called\n", FUNC); + HDfprintf(stderr, "%s: Called\n", FUNC); #endif /* H5FA_DEBUG */ -/* Sanity check */ -HDassert(dblk_page); + /* Sanity check */ + HDassert(dblk_page); -/* Unprotect the data block page */ -if (H5AC_unprotect(dblk_page->hdr->f, H5AC_FARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect fixed array data block page, address = %llu", - (unsigned long long)dblk_page->addr) + /* Unprotect the data block page */ + if (H5AC_unprotect(dblk_page->hdr->f, H5AC_FARRAY_DBLK_PAGE, dblk_page->addr, dblk_page, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect fixed array data block page, address = %llu", + (unsigned long long)dblk_page->addr) -CATCH + CATCH END_FUNC(PKG) /* end H5FA__dblk_page_unprotect() */ @@ -302,29 +302,29 @@ END_FUNC(PKG) /* end H5FA__dblk_page_unprotect() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__dblk_page_dest(H5FA_dblk_page_t *dblk_page)) -/* Sanity check */ -HDassert(dblk_page); - -/* Check if header field has been initialized */ -if (dblk_page->hdr) { - /* Check if buffer for data block page elements has been initialized */ - if (dblk_page->elmts) { - /* Free buffer for data block page elements */ - dblk_page->elmts = H5FL_BLK_FREE(page_elmts, dblk_page->elmts); + /* Sanity check */ + HDassert(dblk_page); + + /* Check if header field has been initialized */ + if (dblk_page->hdr) { + /* Check if buffer for data block page elements has been initialized */ + if (dblk_page->elmts) { + /* Free buffer for data block page elements */ + dblk_page->elmts = H5FL_BLK_FREE(page_elmts, dblk_page->elmts); + } /* end if */ + + /* Decrement reference count on shared info */ + if (H5FA__hdr_decr(dblk_page->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + dblk_page->hdr = NULL; } /* end if */ - /* Decrement reference count on shared info */ - if (H5FA__hdr_decr(dblk_page->hdr) < 0) - H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") - dblk_page->hdr = NULL; -} /* end if */ - -/* Sanity check */ -HDassert(NULL == dblk_page->top_proxy); + /* Sanity check */ + HDassert(NULL == dblk_page->top_proxy); -/* Free the data block page itself */ -dblk_page = H5FL_FREE(H5FA_dblk_page_t, dblk_page); + /* Free the data block page itself */ + dblk_page = H5FL_FREE(H5FA_dblk_page_t, dblk_page); -CATCH + CATCH END_FUNC(PKG) /* end H5FA__dblk_page_dest() */ diff --git a/src/H5FAdblock.c b/src/H5FAdblock.c index 09585c5..1c0a2d7 100644 --- a/src/H5FAdblock.c +++ b/src/H5FAdblock.c @@ -90,70 +90,70 @@ H5FL_BLK_DEFINE(fa_page_init); */ BEGIN_FUNC(PKG, ERR, H5FA_dblock_t *, NULL, NULL, H5FA__dblock_alloc(H5FA_hdr_t *hdr)) -/* Local variables */ -H5FA_dblock_t *dblock = NULL; /* fixed array data block */ + /* Local variables */ + H5FA_dblock_t *dblock = NULL; /* fixed array data block */ -/* Check arguments */ -HDassert(hdr); -HDassert(hdr->cparam.nelmts > 0); + /* Check arguments */ + HDassert(hdr); + HDassert(hdr->cparam.nelmts > 0); -/* Allocate memory for the data block */ -if (NULL == (dblock = H5FL_CALLOC(H5FA_dblock_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block") + /* Allocate memory for the data block */ + if (NULL == (dblock = H5FL_CALLOC(H5FA_dblock_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block") -/* Share common array information */ -if (H5FA__hdr_incr(hdr) < 0) - H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") -dblock->hdr = hdr; + /* Share common array information */ + if (H5FA__hdr_incr(hdr) < 0) + H5E_THROW(H5E_CANTINC, "can't increment reference count on shared array header") + dblock->hdr = hdr; -/* Set non-zero internal fields */ -dblock->dblk_page_nelmts = (size_t)1 << hdr->cparam.max_dblk_page_nelmts_bits; + /* Set non-zero internal fields */ + dblock->dblk_page_nelmts = (size_t)1 << hdr->cparam.max_dblk_page_nelmts_bits; -/* Check if this data block should be paged */ -if (hdr->cparam.nelmts > dblock->dblk_page_nelmts) { - /* Compute number of pages */ - hsize_t npages = ((hdr->cparam.nelmts + dblock->dblk_page_nelmts) - 1) / dblock->dblk_page_nelmts; + /* Check if this data block should be paged */ + if (hdr->cparam.nelmts > dblock->dblk_page_nelmts) { + /* Compute number of pages */ + hsize_t npages = ((hdr->cparam.nelmts + dblock->dblk_page_nelmts) - 1) / dblock->dblk_page_nelmts; - /* Safely assign the number of pages */ - H5_CHECKED_ASSIGN(dblock->npages, size_t, npages, hsize_t); + /* Safely assign the number of pages */ + H5_CHECKED_ASSIGN(dblock->npages, size_t, npages, hsize_t); - /* Sanity check that we have at least 1 page */ - HDassert(dblock->npages > 0); + /* Sanity check that we have at least 1 page */ + HDassert(dblock->npages > 0); - /* Compute size of 'page init' flag array, in bytes */ - dblock->dblk_page_init_size = (dblock->npages + 7) / 8; - HDassert(dblock->dblk_page_init_size > 0); + /* Compute size of 'page init' flag array, in bytes */ + dblock->dblk_page_init_size = (dblock->npages + 7) / 8; + HDassert(dblock->dblk_page_init_size > 0); - /* Allocate space for 'page init' flags */ - if (NULL == (dblock->dblk_page_init = H5FL_BLK_CALLOC(fa_page_init, dblock->dblk_page_init_size))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for page init bitmask") + /* Allocate space for 'page init' flags */ + if (NULL == (dblock->dblk_page_init = H5FL_BLK_CALLOC(fa_page_init, dblock->dblk_page_init_size))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for page init bitmask") - /* Compute data block page size */ - dblock->dblk_page_size = (dblock->dblk_page_nelmts * hdr->cparam.raw_elmt_size) + H5FA_SIZEOF_CHKSUM; + /* Compute data block page size */ + dblock->dblk_page_size = (dblock->dblk_page_nelmts * hdr->cparam.raw_elmt_size) + H5FA_SIZEOF_CHKSUM; - /* Compute the # of elements on last page */ - if (0 == hdr->cparam.nelmts % dblock->dblk_page_nelmts) - dblock->last_page_nelmts = dblock->dblk_page_nelmts; - else - dblock->last_page_nelmts = (size_t)(hdr->cparam.nelmts % dblock->dblk_page_nelmts); -} /* end if */ -else { - hsize_t dblk_size = hdr->cparam.nelmts * hdr->cparam.cls->nat_elmt_size; + /* Compute the # of elements on last page */ + if (0 == hdr->cparam.nelmts % dblock->dblk_page_nelmts) + dblock->last_page_nelmts = dblock->dblk_page_nelmts; + else + dblock->last_page_nelmts = (size_t)(hdr->cparam.nelmts % dblock->dblk_page_nelmts); + } /* end if */ + else { + hsize_t dblk_size = hdr->cparam.nelmts * hdr->cparam.cls->nat_elmt_size; - /* Allocate buffer for elements in data block */ - H5_CHECK_OVERFLOW(dblk_size, /* From: */ hsize_t, /* To: */ size_t); - if (NULL == (dblock->elmts = H5FL_BLK_MALLOC(chunk_elmts, (size_t)dblk_size))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block element buffer") -} /* end else */ + /* Allocate buffer for elements in data block */ + H5_CHECK_OVERFLOW(dblk_size, /* From: */ hsize_t, /* To: */ size_t); + if (NULL == (dblock->elmts = H5FL_BLK_MALLOC(chunk_elmts, (size_t)dblk_size))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for data block element buffer") + } /* end else */ -/* Set the return value */ -ret_value = dblock; + /* Set the return value */ + ret_value = dblock; -CATCH + CATCH -if (!ret_value) - if (dblock && H5FA__dblock_dest(dblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block") + if (!ret_value) + if (dblock && H5FA__dblock_dest(dblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block") END_FUNC(PKG) /* end H5FA__dblock_alloc() */ @@ -172,70 +172,70 @@ END_FUNC(PKG) /* end H5FA__dblock_alloc() */ BEGIN_FUNC(PKG, ERR, haddr_t, HADDR_UNDEF, HADDR_UNDEF, H5FA__dblock_create(H5FA_hdr_t *hdr, hbool_t *hdr_dirty)) -/* Local variables */ -H5FA_dblock_t *dblock = NULL; /* Fixed array data block */ -haddr_t dblock_addr; /* Fixed array data block address */ -hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ - -/* Sanity check */ -HDassert(hdr); -HDassert(hdr_dirty); - -/* Allocate the data block */ -if (NULL == (dblock = H5FA__dblock_alloc(hdr))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block") - -/* Set size of data block on disk */ -hdr->stats.dblk_size = dblock->size = H5FA_DBLOCK_SIZE(dblock); - -/* Allocate space for the data block on disk */ -if (HADDR_UNDEF == (dblock_addr = H5MF_alloc(hdr->f, H5FD_MEM_FARRAY_DBLOCK, (hsize_t)dblock->size))) - H5E_THROW(H5E_CANTALLOC, "file allocation failed for fixed array data block") -dblock->addr = dblock_addr; - -/* Don't initialize elements if paged */ -if (!dblock->npages) - /* Clear any elements in data block to fill value */ - if ((hdr->cparam.cls->fill)(dblock->elmts, (size_t)hdr->cparam.nelmts) < 0) - H5E_THROW(H5E_CANTSET, "can't set fixed array data block elements to class's fill value") - -/* Cache the new fixed array data block */ -if (H5AC_insert_entry(hdr->f, H5AC_FARRAY_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTINSERT, "can't add fixed array data block to cache") -inserted = TRUE; - -/* Add data block as child of 'top' proxy */ -if (hdr->top_proxy) { - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblock) < 0) - H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") - dblock->top_proxy = hdr->top_proxy; -} /* end if */ - -/* Mark the header dirty (for updating statistics) */ -*hdr_dirty = TRUE; - -/* Set address of data block to return */ -ret_value = dblock_addr; - -CATCH - -if (!H5F_addr_defined(ret_value)) - if (dblock) { - /* Remove from cache, if inserted */ - if (inserted) - if (H5AC_remove_entry(dblock) < 0) - H5E_THROW(H5E_CANTREMOVE, "unable to remove fixed array data block from cache") - - /* Release data block's disk space */ - if (H5F_addr_defined(dblock->addr) && - H5MF_xfree(hdr->f, H5FD_MEM_FARRAY_DBLOCK, dblock->addr, (hsize_t)dblock->size) < 0) - H5E_THROW(H5E_CANTFREE, "unable to release fixed array data block") - - /* Destroy data block */ - if (H5FA__dblock_dest(dblock) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block") + /* Local variables */ + H5FA_dblock_t *dblock = NULL; /* Fixed array data block */ + haddr_t dblock_addr; /* Fixed array data block address */ + hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ + + /* Sanity check */ + HDassert(hdr); + HDassert(hdr_dirty); + + /* Allocate the data block */ + if (NULL == (dblock = H5FA__dblock_alloc(hdr))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for fixed array data block") + + /* Set size of data block on disk */ + hdr->stats.dblk_size = dblock->size = H5FA_DBLOCK_SIZE(dblock); + + /* Allocate space for the data block on disk */ + if (HADDR_UNDEF == (dblock_addr = H5MF_alloc(hdr->f, H5FD_MEM_FARRAY_DBLOCK, (hsize_t)dblock->size))) + H5E_THROW(H5E_CANTALLOC, "file allocation failed for fixed array data block") + dblock->addr = dblock_addr; + + /* Don't initialize elements if paged */ + if (!dblock->npages) + /* Clear any elements in data block to fill value */ + if ((hdr->cparam.cls->fill)(dblock->elmts, (size_t)hdr->cparam.nelmts) < 0) + H5E_THROW(H5E_CANTSET, "can't set fixed array data block elements to class's fill value") + + /* Cache the new fixed array data block */ + if (H5AC_insert_entry(hdr->f, H5AC_FARRAY_DBLOCK, dblock_addr, dblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTINSERT, "can't add fixed array data block to cache") + inserted = TRUE; + + /* Add data block as child of 'top' proxy */ + if (hdr->top_proxy) { + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblock) < 0) + H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") + dblock->top_proxy = hdr->top_proxy; } /* end if */ + /* Mark the header dirty (for updating statistics) */ + *hdr_dirty = TRUE; + + /* Set address of data block to return */ + ret_value = dblock_addr; + + CATCH + + if (!H5F_addr_defined(ret_value)) + if (dblock) { + /* Remove from cache, if inserted */ + if (inserted) + if (H5AC_remove_entry(dblock) < 0) + H5E_THROW(H5E_CANTREMOVE, "unable to remove fixed array data block from cache") + + /* Release data block's disk space */ + if (H5F_addr_defined(dblock->addr) && + H5MF_xfree(hdr->f, H5FD_MEM_FARRAY_DBLOCK, dblock->addr, (hsize_t)dblock->size) < 0) + H5E_THROW(H5E_CANTFREE, "unable to release fixed array data block") + + /* Destroy data block */ + if (H5FA__dblock_dest(dblock) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array data block") + } /* end if */ + END_FUNC(PKG) /* end H5FA__dblock_create() */ /*------------------------------------------------------------------------- @@ -253,45 +253,47 @@ END_FUNC(PKG) /* end H5FA__dblock_create() */ BEGIN_FUNC(PKG, ERR, H5FA_dblock_t *, NULL, NULL, H5FA__dblock_protect(H5FA_hdr_t *hdr, haddr_t dblk_addr, unsigned flags)) -/* Local variables */ -H5FA_dblock_t * dblock; /* Fixed array data block */ -H5FA_dblock_cache_ud_t udata; /* Information needed for loading data block */ - -/* Sanity check */ -HDassert(hdr); -HDassert(H5F_addr_defined(dblk_addr)); - -/* only the H5AC__READ_ONLY_FLAG flag is permitted */ -HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); - -/* Set up user data */ -udata.hdr = hdr; -udata.dblk_addr = dblk_addr; - -/* Protect the data block */ -if (NULL == (dblock = (H5FA_dblock_t *)H5AC_protect(hdr->f, H5AC_FARRAY_DBLOCK, dblk_addr, &udata, flags))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block, address = %llu", - (unsigned long long)dblk_addr) - -/* Create top proxy, if it doesn't exist */ -if (hdr->top_proxy && NULL == dblock->top_proxy) { - /* Add data block as child of 'top' proxy */ - if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblock) < 0) - H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") - dblock->top_proxy = hdr->top_proxy; -} /* end if */ + /* Local variables */ + H5FA_dblock_t * dblock; /* Fixed array data block */ + H5FA_dblock_cache_ud_t udata; /* Information needed for loading data block */ + + /* Sanity check */ + HDassert(hdr); + HDassert(H5F_addr_defined(dblk_addr)); + + /* only the H5AC__READ_ONLY_FLAG flag is permitted */ + HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); + + /* Set up user data */ + udata.hdr = hdr; + udata.dblk_addr = dblk_addr; + + /* Protect the data block */ + if (NULL == + (dblock = (H5FA_dblock_t *)H5AC_protect(hdr->f, H5AC_FARRAY_DBLOCK, dblk_addr, &udata, flags))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block, address = %llu", + (unsigned long long)dblk_addr) + + /* Create top proxy, if it doesn't exist */ + if (hdr->top_proxy && NULL == dblock->top_proxy) { + /* Add data block as child of 'top' proxy */ + if (H5AC_proxy_entry_add_child(hdr->top_proxy, hdr->f, dblock) < 0) + H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") + dblock->top_proxy = hdr->top_proxy; + } /* end if */ -/* Set return value */ -ret_value = dblock; + /* Set return value */ + ret_value = dblock; -CATCH + CATCH -/* Clean up on error */ -if (!ret_value) - /* Release the data block, if it was protected */ - if (dblock && H5AC_unprotect(hdr->f, H5AC_FARRAY_DBLOCK, dblock->addr, dblock, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect fixed array data block, address = %llu", - (unsigned long long)dblock->addr) + /* Clean up on error */ + if (!ret_value) + /* Release the data block, if it was protected */ + if (dblock && + H5AC_unprotect(hdr->f, H5AC_FARRAY_DBLOCK, dblock->addr, dblock, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect fixed array data block, address = %llu", + (unsigned long long)dblock->addr) END_FUNC(PKG) /* end H5FA__dblock_protect() */ @@ -310,17 +312,17 @@ END_FUNC(PKG) /* end H5FA__dblock_protect() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__dblock_unprotect(H5FA_dblock_t *dblock, unsigned cache_flags)) -/* Local variables */ + /* Local variables */ -/* Sanity check */ -HDassert(dblock); + /* Sanity check */ + HDassert(dblock); -/* Unprotect the data block */ -if (H5AC_unprotect(dblock->hdr->f, H5AC_FARRAY_DBLOCK, dblock->addr, dblock, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect fixed array data block, address = %llu", - (unsigned long long)dblock->addr) + /* Unprotect the data block */ + if (H5AC_unprotect(dblock->hdr->f, H5AC_FARRAY_DBLOCK, dblock->addr, dblock, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect fixed array data block, address = %llu", + (unsigned long long)dblock->addr) -CATCH + CATCH END_FUNC(PKG) /* end H5FA__dblock_unprotect() */ @@ -338,44 +340,44 @@ END_FUNC(PKG) /* end H5FA__dblock_unprotect() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__dblock_delete(H5FA_hdr_t *hdr, haddr_t dblk_addr)) -/* Local variables */ -H5FA_dblock_t *dblock = NULL; /* Pointer to data block */ + /* Local variables */ + H5FA_dblock_t *dblock = NULL; /* Pointer to data block */ -/* Sanity check */ -HDassert(hdr); -HDassert(H5F_addr_defined(dblk_addr)); + /* Sanity check */ + HDassert(hdr); + HDassert(H5F_addr_defined(dblk_addr)); -/* Protect data block */ -if (NULL == (dblock = H5FA__dblock_protect(hdr, dblk_addr, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block, address = %llu", - (unsigned long long)dblk_addr) + /* Protect data block */ + if (NULL == (dblock = H5FA__dblock_protect(hdr, dblk_addr, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array data block, address = %llu", + (unsigned long long)dblk_addr) -/* Check if data block is paged */ -if (dblock->npages) { - haddr_t dblk_page_addr; /* Address of each data block page */ - size_t u; /* Local index variable */ + /* Check if data block is paged */ + if (dblock->npages) { + haddr_t dblk_page_addr; /* Address of each data block page */ + size_t u; /* Local index variable */ - /* Set up initial state */ - dblk_page_addr = dblk_addr + H5FA_DBLOCK_PREFIX_SIZE(dblock); + /* Set up initial state */ + dblk_page_addr = dblk_addr + H5FA_DBLOCK_PREFIX_SIZE(dblock); - /* Iterate over pages in data block */ - for (u = 0; u < dblock->npages; u++) { - /* Evict the data block page from the metadata cache */ - /* (OK to call if it doesn't exist in the cache) */ - if (H5AC_expunge_entry(hdr->f, H5AC_FARRAY_DBLK_PAGE, dblk_page_addr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTEXPUNGE, "unable to remove array data block page from metadata cache") + /* Iterate over pages in data block */ + for (u = 0; u < dblock->npages; u++) { + /* Evict the data block page from the metadata cache */ + /* (OK to call if it doesn't exist in the cache) */ + if (H5AC_expunge_entry(hdr->f, H5AC_FARRAY_DBLK_PAGE, dblk_page_addr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTEXPUNGE, "unable to remove array data block page from metadata cache") - /* Advance to next page address */ - dblk_page_addr += dblock->dblk_page_size; - } /* end for */ -} /* end if */ + /* Advance to next page address */ + dblk_page_addr += dblock->dblk_page_size; + } /* end for */ + } /* end if */ -CATCH + CATCH -/* Finished deleting data block in metadata cache */ -if (dblock && - H5FA__dblock_unprotect(dblock, H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block") + /* Finished deleting data block in metadata cache */ + if (dblock && H5FA__dblock_unprotect(dblock, H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | + H5AC__FREE_FILE_SPACE_FLAG) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array data block") END_FUNC(PKG) /* end H5FA__dblock_delete() */ @@ -393,38 +395,38 @@ END_FUNC(PKG) /* end H5FA__dblock_delete() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__dblock_dest(H5FA_dblock_t *dblock)) -/* Sanity check */ -HDassert(dblock); - -/* Check if shared header field has been initialized */ -if (dblock->hdr) { - /* Check if we've got elements in the data block */ - if (dblock->elmts && !dblock->npages) { - /* Free buffer for data block elements */ - HDassert(dblock->hdr->cparam.nelmts > 0); - dblock->elmts = H5FL_BLK_FREE(chunk_elmts, dblock->elmts); + /* Sanity check */ + HDassert(dblock); + + /* Check if shared header field has been initialized */ + if (dblock->hdr) { + /* Check if we've got elements in the data block */ + if (dblock->elmts && !dblock->npages) { + /* Free buffer for data block elements */ + HDassert(dblock->hdr->cparam.nelmts > 0); + dblock->elmts = H5FL_BLK_FREE(chunk_elmts, dblock->elmts); + } /* end if */ + + /* Check if data block is paged */ + if (dblock->npages) { + /* Free buffer for 'page init' bitmask, if there is one */ + HDassert(dblock->dblk_page_init_size > 0); + if (dblock->dblk_page_init) + dblock->dblk_page_init = H5FL_BLK_FREE(fa_page_init, dblock->dblk_page_init); + } /* end if */ + + /* Decrement reference count on shared info */ + if (H5FA__hdr_decr(dblock->hdr) < 0) + H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") + dblock->hdr = NULL; } /* end if */ - /* Check if data block is paged */ - if (dblock->npages) { - /* Free buffer for 'page init' bitmask, if there is one */ - HDassert(dblock->dblk_page_init_size > 0); - if (dblock->dblk_page_init) - dblock->dblk_page_init = H5FL_BLK_FREE(fa_page_init, dblock->dblk_page_init); - } /* end if */ - - /* Decrement reference count on shared info */ - if (H5FA__hdr_decr(dblock->hdr) < 0) - H5E_THROW(H5E_CANTDEC, "can't decrement reference count on shared array header") - dblock->hdr = NULL; -} /* end if */ - -/* Sanity check */ -HDassert(NULL == dblock->top_proxy); + /* Sanity check */ + HDassert(NULL == dblock->top_proxy); -/* Free the data block itself */ -dblock = H5FL_FREE(H5FA_dblock_t, dblock); + /* Free the data block itself */ + dblock = H5FL_FREE(H5FA_dblock_t, dblock); -CATCH + CATCH END_FUNC(PKG) /* end H5FA__dblock_dest() */ diff --git a/src/H5FAhdr.c b/src/H5FAhdr.c index 9e9faee..f9049f8 100644 --- a/src/H5FAhdr.c +++ b/src/H5FAhdr.c @@ -84,33 +84,33 @@ H5FL_DEFINE_STATIC(H5FA_hdr_t); */ BEGIN_FUNC(PKG, ERR, H5FA_hdr_t *, NULL, NULL, H5FA__hdr_alloc(H5F_t *f)) -/* Local variables */ -H5FA_hdr_t *hdr = NULL; /* Shared Fixed Array header */ + /* Local variables */ + H5FA_hdr_t *hdr = NULL; /* Shared Fixed Array header */ -/* Check arguments */ -HDassert(f); + /* Check arguments */ + HDassert(f); -/* Allocate space for the shared information */ -if (NULL == (hdr = H5FL_CALLOC(H5FA_hdr_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for Fixed Array shared header") + /* Allocate space for the shared information */ + if (NULL == (hdr = H5FL_CALLOC(H5FA_hdr_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for Fixed Array shared header") -/* Set non-zero internal fields */ -hdr->addr = HADDR_UNDEF; + /* Set non-zero internal fields */ + hdr->addr = HADDR_UNDEF; -/* Set the internal parameters for the array */ -hdr->f = f; -hdr->swmr_write = (H5F_INTENT(f) & H5F_ACC_SWMR_WRITE) > 0; -hdr->sizeof_addr = H5F_SIZEOF_ADDR(f); -hdr->sizeof_size = H5F_SIZEOF_SIZE(f); + /* Set the internal parameters for the array */ + hdr->f = f; + hdr->swmr_write = (H5F_INTENT(f) & H5F_ACC_SWMR_WRITE) > 0; + hdr->sizeof_addr = H5F_SIZEOF_ADDR(f); + hdr->sizeof_size = H5F_SIZEOF_SIZE(f); -/* Set the return value */ -ret_value = hdr; + /* Set the return value */ + ret_value = hdr; -CATCH + CATCH -if (!ret_value) - if (hdr && H5FA__hdr_dest(hdr) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array header") + if (!ret_value) + if (hdr && H5FA__hdr_dest(hdr) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy fixed array header") END_FUNC(PKG) /* end H5FA__hdr_alloc() */ @@ -128,24 +128,24 @@ END_FUNC(PKG) /* end H5FA__hdr_alloc() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__hdr_init(H5FA_hdr_t *hdr, void *ctx_udata)) -/* Local variables */ + /* Local variables */ -/* Check arguments */ -HDassert(hdr); + /* Check arguments */ + HDassert(hdr); -/* Set size of header on disk (locally and in statistics) */ -hdr->stats.hdr_size = hdr->size = H5FA_HEADER_SIZE_HDR(hdr); + /* Set size of header on disk (locally and in statistics) */ + hdr->stats.hdr_size = hdr->size = H5FA_HEADER_SIZE_HDR(hdr); -/* Set number of elements for Fixed Array in statistics */ -hdr->stats.nelmts = hdr->cparam.nelmts; + /* Set number of elements for Fixed Array in statistics */ + hdr->stats.nelmts = hdr->cparam.nelmts; -/* Create the callback context, if there's one */ -if (hdr->cparam.cls->crt_context) { - if (NULL == (hdr->cb_ctx = (*hdr->cparam.cls->crt_context)(ctx_udata))) - H5E_THROW(H5E_CANTCREATE, "unable to create fixed array client callback context") -} /* end if */ + /* Create the callback context, if there's one */ + if (hdr->cparam.cls->crt_context) { + if (NULL == (hdr->cb_ctx = (*hdr->cparam.cls->crt_context)(ctx_udata))) + H5E_THROW(H5E_CANTCREATE, "unable to create fixed array client callback context") + } /* end if */ -CATCH + CATCH END_FUNC(PKG) /* end H5FA__hdr_init() */ @@ -164,79 +164,79 @@ END_FUNC(PKG) /* end H5FA__hdr_init() */ BEGIN_FUNC(PKG, ERR, haddr_t, HADDR_UNDEF, HADDR_UNDEF, H5FA__hdr_create(H5F_t *f, const H5FA_create_t *cparam, void *ctx_udata)) -/* Local variables */ -H5FA_hdr_t *hdr = NULL; /* Fixed array header */ -hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ + /* Local variables */ + H5FA_hdr_t *hdr = NULL; /* Fixed array header */ + hbool_t inserted = FALSE; /* Whether the header was inserted into cache */ -/* Check arguments */ -HDassert(f); -HDassert(cparam); + /* Check arguments */ + HDassert(f); + HDassert(cparam); #ifndef NDEBUG -{ - /* Check for valid parameters */ - if (cparam->raw_elmt_size == 0) - H5E_THROW(H5E_BADVALUE, "element size must be greater than zero") - if (cparam->max_dblk_page_nelmts_bits == 0) - H5E_THROW(H5E_BADVALUE, "max. # of elements bits must be greater than zero") - if (cparam->nelmts == 0) - H5E_THROW(H5E_BADVALUE, "# of elements must be greater than zero") -} + { + /* Check for valid parameters */ + if (cparam->raw_elmt_size == 0) + H5E_THROW(H5E_BADVALUE, "element size must be greater than zero") + if (cparam->max_dblk_page_nelmts_bits == 0) + H5E_THROW(H5E_BADVALUE, "max. # of elements bits must be greater than zero") + if (cparam->nelmts == 0) + H5E_THROW(H5E_BADVALUE, "# of elements must be greater than zero") + } #endif /* NDEBUG */ -/* Allocate space for the shared information */ -if (NULL == (hdr = H5FA__hdr_alloc(f))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for Fixed Array shared header") + /* Allocate space for the shared information */ + if (NULL == (hdr = H5FA__hdr_alloc(f))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for Fixed Array shared header") -hdr->dblk_addr = HADDR_UNDEF; + hdr->dblk_addr = HADDR_UNDEF; -/* Set the creation parameters for the array */ -H5MM_memcpy(&hdr->cparam, cparam, sizeof(hdr->cparam)); + /* Set the creation parameters for the array */ + H5MM_memcpy(&hdr->cparam, cparam, sizeof(hdr->cparam)); -/* Finish initializing fixed array header */ -if (H5FA__hdr_init(hdr, ctx_udata) < 0) - H5E_THROW(H5E_CANTINIT, "initialization failed for fixed array header") + /* Finish initializing fixed array header */ + if (H5FA__hdr_init(hdr, ctx_udata) < 0) + H5E_THROW(H5E_CANTINIT, "initialization failed for fixed array header") -/* Allocate space for the header on disk */ -if (HADDR_UNDEF == (hdr->addr = H5MF_alloc(f, H5FD_MEM_FARRAY_HDR, (hsize_t)hdr->size))) - H5E_THROW(H5E_CANTALLOC, "file allocation failed for Fixed Array header") + /* Allocate space for the header on disk */ + if (HADDR_UNDEF == (hdr->addr = H5MF_alloc(f, H5FD_MEM_FARRAY_HDR, (hsize_t)hdr->size))) + H5E_THROW(H5E_CANTALLOC, "file allocation failed for Fixed Array header") -/* Create 'top' proxy for extensible array entries */ -if (hdr->swmr_write) - if (NULL == (hdr->top_proxy = H5AC_proxy_entry_create())) - H5E_THROW(H5E_CANTCREATE, "can't create fixed array entry proxy") + /* Create 'top' proxy for extensible array entries */ + if (hdr->swmr_write) + if (NULL == (hdr->top_proxy = H5AC_proxy_entry_create())) + H5E_THROW(H5E_CANTCREATE, "can't create fixed array entry proxy") -/* Cache the new Fixed Array header */ -if (H5AC_insert_entry(f, H5AC_FARRAY_HDR, hdr->addr, hdr, H5AC__NO_FLAGS_SET) < 0) - H5E_THROW(H5E_CANTINSERT, "can't add fixed array header to cache") -inserted = TRUE; + /* Cache the new Fixed Array header */ + if (H5AC_insert_entry(f, H5AC_FARRAY_HDR, hdr->addr, hdr, H5AC__NO_FLAGS_SET) < 0) + H5E_THROW(H5E_CANTINSERT, "can't add fixed array header to cache") + inserted = TRUE; -/* Add header as child of 'top' proxy */ -if (hdr->top_proxy) - if (H5AC_proxy_entry_add_child(hdr->top_proxy, f, hdr) < 0) - H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") + /* Add header as child of 'top' proxy */ + if (hdr->top_proxy) + if (H5AC_proxy_entry_add_child(hdr->top_proxy, f, hdr) < 0) + H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") -/* Set address of array header to return */ -ret_value = hdr->addr; + /* Set address of array header to return */ + ret_value = hdr->addr; -CATCH + CATCH -if (!H5F_addr_defined(ret_value)) - if (hdr) { - /* Remove from cache, if inserted */ - if (inserted) - if (H5AC_remove_entry(hdr) < 0) - H5E_THROW(H5E_CANTREMOVE, "unable to remove fixed array header from cache") + if (!H5F_addr_defined(ret_value)) + if (hdr) { + /* Remove from cache, if inserted */ + if (inserted) + if (H5AC_remove_entry(hdr) < 0) + H5E_THROW(H5E_CANTREMOVE, "unable to remove fixed array header from cache") - /* Release header's disk space */ - if (H5F_addr_defined(hdr->addr) && - H5MF_xfree(f, H5FD_MEM_FARRAY_HDR, hdr->addr, (hsize_t)hdr->size) < 0) - H5E_THROW(H5E_CANTFREE, "unable to free Fixed Array header") + /* Release header's disk space */ + if (H5F_addr_defined(hdr->addr) && + H5MF_xfree(f, H5FD_MEM_FARRAY_HDR, hdr->addr, (hsize_t)hdr->size) < 0) + H5E_THROW(H5E_CANTFREE, "unable to free Fixed Array header") - /* Destroy header */ - if (H5FA__hdr_dest(hdr) < 0) - H5E_THROW(H5E_CANTFREE, "unable to destroy Fixed Array header") - } /* end if */ + /* Destroy header */ + if (H5FA__hdr_dest(hdr) < 0) + H5E_THROW(H5E_CANTFREE, "unable to destroy Fixed Array header") + } /* end if */ END_FUNC(PKG) /* end H5FA__hdr_create() */ @@ -254,18 +254,18 @@ END_FUNC(PKG) /* end H5FA__hdr_create() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__hdr_incr(H5FA_hdr_t *hdr)) -/* Sanity check */ -HDassert(hdr); + /* Sanity check */ + HDassert(hdr); -/* Mark header as un-evictable when something is depending on it */ -if (hdr->rc == 0) - if (H5AC_pin_protected_entry(hdr) < 0) - H5E_THROW(H5E_CANTPIN, "unable to pin fixed array header") + /* Mark header as un-evictable when something is depending on it */ + if (hdr->rc == 0) + if (H5AC_pin_protected_entry(hdr) < 0) + H5E_THROW(H5E_CANTPIN, "unable to pin fixed array header") -/* Increment reference count on shared header */ -hdr->rc++; + /* Increment reference count on shared header */ + hdr->rc++; -CATCH + CATCH END_FUNC(PKG) /* end H5FA__hdr_incr() */ @@ -283,21 +283,21 @@ END_FUNC(PKG) /* end H5FA__hdr_incr() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__hdr_decr(H5FA_hdr_t *hdr)) -/* Sanity check */ -HDassert(hdr); -HDassert(hdr->rc); + /* Sanity check */ + HDassert(hdr); + HDassert(hdr->rc); -/* Decrement reference count on shared header */ -hdr->rc--; + /* Decrement reference count on shared header */ + hdr->rc--; -/* Mark header as evictable again when nothing depend on it */ -if (hdr->rc == 0) { - HDassert(hdr->file_rc == 0); - if (H5AC_unpin_entry(hdr) < 0) - H5E_THROW(H5E_CANTUNPIN, "unable to unpin fixed array header") -} /* end if */ + /* Mark header as evictable again when nothing depend on it */ + if (hdr->rc == 0) { + HDassert(hdr->file_rc == 0); + if (H5AC_unpin_entry(hdr) < 0) + H5E_THROW(H5E_CANTUNPIN, "unable to unpin fixed array header") + } /* end if */ -CATCH + CATCH END_FUNC(PKG) /* end H5FA__hdr_decr() */ @@ -315,11 +315,11 @@ END_FUNC(PKG) /* end H5FA__hdr_decr() */ */ BEGIN_FUNC(PKG, NOERR, herr_t, SUCCEED, -, H5FA__hdr_fuse_incr(H5FA_hdr_t *hdr)) -/* Sanity check */ -HDassert(hdr); + /* Sanity check */ + HDassert(hdr); -/* Increment file reference count on shared header */ -hdr->file_rc++; + /* Increment file reference count on shared header */ + hdr->file_rc++; END_FUNC(PKG) /* end H5FA__hdr_fuse_incr() */ @@ -337,15 +337,15 @@ END_FUNC(PKG) /* end H5FA__hdr_fuse_incr() */ */ BEGIN_FUNC(PKG, NOERR, size_t, 0, -, H5FA__hdr_fuse_decr(H5FA_hdr_t *hdr)) -/* Sanity check */ -HDassert(hdr); -HDassert(hdr->file_rc); + /* Sanity check */ + HDassert(hdr); + HDassert(hdr->file_rc); -/* Decrement file reference count on shared header */ -hdr->file_rc--; + /* Decrement file reference count on shared header */ + hdr->file_rc--; -/* Set return value */ -ret_value = hdr->file_rc; + /* Set return value */ + ret_value = hdr->file_rc; END_FUNC(PKG) /* end H5FA__hdr_fuse_decr() */ @@ -363,14 +363,14 @@ END_FUNC(PKG) /* end H5FA__hdr_fuse_decr() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__hdr_modified(H5FA_hdr_t *hdr)) -/* Sanity check */ -HDassert(hdr); + /* Sanity check */ + HDassert(hdr); -/* Mark header as dirty in cache */ -if (H5AC_mark_entry_dirty(hdr) < 0) - H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark fixed array header as dirty") + /* Mark header as dirty in cache */ + if (H5AC_mark_entry_dirty(hdr) < 0) + H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark fixed array header as dirty") -CATCH + CATCH END_FUNC(PKG) /* end H5FA__hdr_modified() */ @@ -389,43 +389,43 @@ END_FUNC(PKG) /* end H5FA__hdr_modified() */ BEGIN_FUNC(PKG, ERR, H5FA_hdr_t *, NULL, NULL, H5FA__hdr_protect(H5F_t *f, haddr_t fa_addr, void *ctx_udata, unsigned flags)) -/* Local variables */ -H5FA_hdr_t * hdr; /* Fixed array header */ -H5FA_hdr_cache_ud_t udata; /* User data for cache callbacks */ - -/* Sanity check */ -HDassert(f); -HDassert(H5F_addr_defined(fa_addr)); - -/* only the H5AC__READ_ONLY_FLAG is permitted */ -HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); - -/* Set up user data for cache callbacks */ -udata.f = f; -udata.addr = fa_addr; -udata.ctx_udata = ctx_udata; - -/* Protect the header */ -if (NULL == (hdr = (H5FA_hdr_t *)H5AC_protect(f, H5AC_FARRAY_HDR, fa_addr, &udata, flags))) - H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array header, address = %llu", - (unsigned long long)fa_addr) -hdr->f = f; /* (Must be set again here, in case the header was already in the cache -QAK) */ - -/* Create top proxy, if it doesn't exist */ -if (hdr->swmr_write && NULL == hdr->top_proxy) { - /* Create 'top' proxy for fixed array entries */ - if (NULL == (hdr->top_proxy = H5AC_proxy_entry_create())) - H5E_THROW(H5E_CANTCREATE, "can't create fixed array entry proxy") - - /* Add header as child of 'top' proxy */ - if (H5AC_proxy_entry_add_child(hdr->top_proxy, f, hdr) < 0) - H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") -} /* end if */ + /* Local variables */ + H5FA_hdr_t * hdr; /* Fixed array header */ + H5FA_hdr_cache_ud_t udata; /* User data for cache callbacks */ + + /* Sanity check */ + HDassert(f); + HDassert(H5F_addr_defined(fa_addr)); + + /* only the H5AC__READ_ONLY_FLAG is permitted */ + HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); + + /* Set up user data for cache callbacks */ + udata.f = f; + udata.addr = fa_addr; + udata.ctx_udata = ctx_udata; + + /* Protect the header */ + if (NULL == (hdr = (H5FA_hdr_t *)H5AC_protect(f, H5AC_FARRAY_HDR, fa_addr, &udata, flags))) + H5E_THROW(H5E_CANTPROTECT, "unable to protect fixed array header, address = %llu", + (unsigned long long)fa_addr) + hdr->f = f; /* (Must be set again here, in case the header was already in the cache -QAK) */ + + /* Create top proxy, if it doesn't exist */ + if (hdr->swmr_write && NULL == hdr->top_proxy) { + /* Create 'top' proxy for fixed array entries */ + if (NULL == (hdr->top_proxy = H5AC_proxy_entry_create())) + H5E_THROW(H5E_CANTCREATE, "can't create fixed array entry proxy") + + /* Add header as child of 'top' proxy */ + if (H5AC_proxy_entry_add_child(hdr->top_proxy, f, hdr) < 0) + H5E_THROW(H5E_CANTSET, "unable to add fixed array entry as child of array proxy") + } /* end if */ -/* Set return value */ -ret_value = hdr; + /* Set return value */ + ret_value = hdr; -CATCH + CATCH END_FUNC(PKG) /* end H5FA__hdr_protect() */ @@ -443,17 +443,17 @@ END_FUNC(PKG) /* end H5FA__hdr_protect() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__hdr_unprotect(H5FA_hdr_t *hdr, unsigned cache_flags)) -/* Local variables */ + /* Local variables */ -/* Sanity check */ -HDassert(hdr); + /* Sanity check */ + HDassert(hdr); -/* Unprotect the header */ -if (H5AC_unprotect(hdr->f, H5AC_FARRAY_HDR, hdr->addr, hdr, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect fixed array hdr, address = %llu", - (unsigned long long)hdr->addr) + /* Unprotect the header */ + if (H5AC_unprotect(hdr->f, H5AC_FARRAY_HDR, hdr->addr, hdr, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to unprotect fixed array hdr, address = %llu", + (unsigned long long)hdr->addr) -CATCH + CATCH END_FUNC(PKG) /* end H5FA__hdr_unprotect() */ @@ -471,42 +471,42 @@ END_FUNC(PKG) /* end H5FA__hdr_unprotect() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__hdr_delete(H5FA_hdr_t *hdr)) -/* Local variables */ -unsigned cache_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotecting header */ + /* Local variables */ + unsigned cache_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotecting header */ -/* Sanity check */ -HDassert(hdr); -HDassert(!hdr->file_rc); + /* Sanity check */ + HDassert(hdr); + HDassert(!hdr->file_rc); #ifndef NDEBUG -{ - unsigned hdr_status = 0; /* Array header's status in the metadata cache */ + { + unsigned hdr_status = 0; /* Array header's status in the metadata cache */ - /* Check the array header's status in the metadata cache */ - if (H5AC_get_entry_status(hdr->f, hdr->addr, &hdr_status) < 0) - H5E_THROW(H5E_CANTGET, "unable to check metadata cache status for array header") + /* Check the array header's status in the metadata cache */ + if (H5AC_get_entry_status(hdr->f, hdr->addr, &hdr_status) < 0) + H5E_THROW(H5E_CANTGET, "unable to check metadata cache status for array header") - /* Sanity checks on array header */ - HDassert(hdr_status & H5AC_ES__IN_CACHE); - HDassert(hdr_status & H5AC_ES__IS_PROTECTED); -} /* end block */ + /* Sanity checks on array header */ + HDassert(hdr_status & H5AC_ES__IN_CACHE); + HDassert(hdr_status & H5AC_ES__IS_PROTECTED); + } /* end block */ #endif /* NDEBUG */ -/* Check for Fixed Array Data block */ -if (H5F_addr_defined(hdr->dblk_addr)) { - /* Delete Fixed Array Data block */ - if (H5FA__dblock_delete(hdr, hdr->dblk_addr) < 0) - H5E_THROW(H5E_CANTDELETE, "unable to delete fixed array data block") -} /* end if */ + /* Check for Fixed Array Data block */ + if (H5F_addr_defined(hdr->dblk_addr)) { + /* Delete Fixed Array Data block */ + if (H5FA__dblock_delete(hdr, hdr->dblk_addr) < 0) + H5E_THROW(H5E_CANTDELETE, "unable to delete fixed array data block") + } /* end if */ -/* Set flags to finish deleting header on unprotect */ -cache_flags |= H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG; + /* Set flags to finish deleting header on unprotect */ + cache_flags |= H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG; -CATCH + CATCH -/* Unprotect the header, deleting it if an error hasn't occurred */ -if (H5AC_unprotect(hdr->f, H5AC_FARRAY_HDR, hdr->addr, hdr, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array header") + /* Unprotect the header, deleting it if an error hasn't occurred */ + if (H5AC_unprotect(hdr->f, H5AC_FARRAY_HDR, hdr->addr, hdr, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release fixed array header") END_FUNC(PKG) /* end H5FA__hdr_delete() */ @@ -524,27 +524,27 @@ END_FUNC(PKG) /* end H5FA__hdr_delete() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__hdr_dest(H5FA_hdr_t *hdr)) -/* Check arguments */ -HDassert(hdr); -HDassert(hdr->rc == 0); + /* Check arguments */ + HDassert(hdr); + HDassert(hdr->rc == 0); -/* Destroy the callback context */ -if (hdr->cb_ctx) { - if ((*hdr->cparam.cls->dst_context)(hdr->cb_ctx) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to destroy fixed array client callback context") -} /* end if */ -hdr->cb_ctx = NULL; + /* Destroy the callback context */ + if (hdr->cb_ctx) { + if ((*hdr->cparam.cls->dst_context)(hdr->cb_ctx) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to destroy fixed array client callback context") + } /* end if */ + hdr->cb_ctx = NULL; -/* Destroy the 'top' proxy */ -if (hdr->top_proxy) { - if (H5AC_proxy_entry_dest(hdr->top_proxy) < 0) - H5E_THROW(H5E_CANTRELEASE, "unable to destroy fixed array 'top' proxy") - hdr->top_proxy = NULL; -} /* end if */ + /* Destroy the 'top' proxy */ + if (hdr->top_proxy) { + if (H5AC_proxy_entry_dest(hdr->top_proxy) < 0) + H5E_THROW(H5E_CANTRELEASE, "unable to destroy fixed array 'top' proxy") + hdr->top_proxy = NULL; + } /* end if */ -/* Free the shared info itself */ -hdr = H5FL_FREE(H5FA_hdr_t, hdr); + /* Free the shared info itself */ + hdr = H5FL_FREE(H5FA_hdr_t, hdr); -CATCH + CATCH END_FUNC(PKG) /* end H5FA__hdr_dest() */ diff --git a/src/H5FAint.c b/src/H5FAint.c index 7c357a9..c8e6826 100644 --- a/src/H5FAint.c +++ b/src/H5FAint.c @@ -82,15 +82,15 @@ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__create_flush_depend(H5AC_info_t *parent_entry, H5AC_info_t *child_entry)) -/* Sanity check */ -HDassert(parent_entry); -HDassert(child_entry); + /* Sanity check */ + HDassert(parent_entry); + HDassert(child_entry); -/* Create a flush dependency between parent and child entry */ -if (H5AC_create_flush_dependency(parent_entry, child_entry) < 0) - H5E_THROW(H5E_CANTDEPEND, "unable to create flush dependency") + /* Create a flush dependency between parent and child entry */ + if (H5AC_create_flush_dependency(parent_entry, child_entry) < 0) + H5E_THROW(H5E_CANTDEPEND, "unable to create flush dependency") -CATCH + CATCH END_FUNC(PKG) /* end H5FA__create_flush_depend() */ @@ -109,14 +109,14 @@ END_FUNC(PKG) /* end H5FA__create_flush_depend() */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5FA__destroy_flush_depend(H5AC_info_t *parent_entry, H5AC_info_t *child_entry)) -/* Sanity check */ -HDassert(parent_entry); -HDassert(child_entry); + /* Sanity check */ + HDassert(parent_entry); + HDassert(child_entry); -/* Destroy a flush dependency between parent and child entry */ -if (H5AC_destroy_flush_dependency(parent_entry, child_entry) < 0) - H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency") + /* Destroy a flush dependency between parent and child entry */ + if (H5AC_destroy_flush_dependency(parent_entry, child_entry) < 0) + H5E_THROW(H5E_CANTUNDEPEND, "unable to destroy flush dependency") -CATCH + CATCH END_FUNC(PKG) /* end H5FA__destroy_flush_depend() */ diff --git a/src/H5FAstat.c b/src/H5FAstat.c index 775acbc..a625d3a 100644 --- a/src/H5FAstat.c +++ b/src/H5FAstat.c @@ -83,16 +83,16 @@ BEGIN_FUNC(PRIV, NOERR, herr_t, SUCCEED, -, H5FA_get_stats(const H5FA_t *fa, H5F /* Local variables */ #ifdef H5FA_DEBUG -HDfprintf(stderr, "%s: Called\n", FUNC); + HDfprintf(stderr, "%s: Called\n", FUNC); #endif /* H5FA_DEBUG */ -/* - * Check arguments. - */ -HDassert(fa); -HDassert(stats); + /* + * Check arguments. + */ + HDassert(fa); + HDassert(stats); -/* Copy fixed array statistics */ -H5MM_memcpy(stats, &fa->hdr->stats, sizeof(fa->hdr->stats)); + /* Copy fixed array statistics */ + H5MM_memcpy(stats, &fa->hdr->stats, sizeof(fa->hdr->stats)); END_FUNC(PRIV) /* end H5FA_get_stats() */ diff --git a/src/H5FAtest.c b/src/H5FAtest.c index a6fd267..4da7d6f 100644 --- a/src/H5FAtest.c +++ b/src/H5FAtest.c @@ -114,20 +114,20 @@ H5FL_DEFINE_STATIC(H5FA__test_ctx_t); */ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5FA__test_crt_context(void H5_ATTR_UNUSED *udata)) -/* Local variables */ -H5FA__test_ctx_t *ctx; /* Context for callbacks */ + /* Local variables */ + H5FA__test_ctx_t *ctx; /* Context for callbacks */ -/* Allocate new context structure */ -if (NULL == (ctx = H5FL_MALLOC(H5FA__test_ctx_t))) - H5E_THROW(H5E_CANTALLOC, "can't allocate fixed array client callback context") + /* Allocate new context structure */ + if (NULL == (ctx = H5FL_MALLOC(H5FA__test_ctx_t))) + H5E_THROW(H5E_CANTALLOC, "can't allocate fixed array client callback context") -/* Initialize the context */ -ctx->bogus = H5FA__TEST_BOGUS_VAL; + /* Initialize the context */ + ctx->bogus = H5FA__TEST_BOGUS_VAL; -/* Set return value */ -ret_value = ctx; + /* Set return value */ + ret_value = ctx; -CATCH + CATCH END_FUNC(STATIC) /* end H5FA__test_crt_context() */ @@ -145,14 +145,14 @@ END_FUNC(STATIC) /* end H5FA__test_crt_context() */ */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__test_dst_context(void *_ctx)) -/* Local variables */ -H5FA__test_ctx_t *ctx = (H5FA__test_ctx_t *)_ctx; /* Callback context to destroy */ + /* Local variables */ + H5FA__test_ctx_t *ctx = (H5FA__test_ctx_t *)_ctx; /* Callback context to destroy */ -/* Sanity checks */ -HDassert(H5FA__TEST_BOGUS_VAL == ctx->bogus); + /* Sanity checks */ + HDassert(H5FA__TEST_BOGUS_VAL == ctx->bogus); -/* Release context structure */ -ctx = H5FL_FREE(H5FA__test_ctx_t, ctx); + /* Release context structure */ + ctx = H5FL_FREE(H5FA__test_ctx_t, ctx); END_FUNC(STATIC) /* end H5FA__test_dst_context() */ @@ -170,14 +170,14 @@ END_FUNC(STATIC) /* end H5FA__test_dst_context() */ */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__test_fill(void *nat_blk, size_t nelmts)) -/* Local variables */ -uint64_t fill_val = H5FA_TEST_FILL; /* Value to fill elements with */ + /* Local variables */ + uint64_t fill_val = H5FA_TEST_FILL; /* Value to fill elements with */ -/* Sanity checks */ -HDassert(nat_blk); -HDassert(nelmts); + /* Sanity checks */ + HDassert(nat_blk); + HDassert(nelmts); -H5VM_array_fill(nat_blk, &fill_val, sizeof(uint64_t), nelmts); + H5VM_array_fill(nat_blk, &fill_val, sizeof(uint64_t), nelmts); END_FUNC(STATIC) /* end H5FA__test_fill() */ @@ -198,28 +198,28 @@ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, /* Local variables */ #ifndef NDEBUG -H5FA__test_ctx_t *ctx = (H5FA__test_ctx_t *)_ctx; /* Callback context to destroy */ -#endif /* NDEBUG */ -const uint64_t *elmt = (const uint64_t *)_elmt; /* Convenience pointer to native elements */ + H5FA__test_ctx_t *ctx = (H5FA__test_ctx_t *)_ctx; /* Callback context to destroy */ +#endif /* NDEBUG */ + const uint64_t *elmt = (const uint64_t *)_elmt; /* Convenience pointer to native elements */ -/* Sanity checks */ -HDassert(raw); -HDassert(elmt); -HDassert(nelmts); -HDassert(H5FA__TEST_BOGUS_VAL == ctx->bogus); + /* Sanity checks */ + HDassert(raw); + HDassert(elmt); + HDassert(nelmts); + HDassert(H5FA__TEST_BOGUS_VAL == ctx->bogus); -/* Encode native elements into raw elements */ -while (nelmts) { - /* Encode element */ - /* (advances 'raw' pointer) */ - UINT64ENCODE(raw, *elmt); + /* Encode native elements into raw elements */ + while (nelmts) { + /* Encode element */ + /* (advances 'raw' pointer) */ + UINT64ENCODE(raw, *elmt); - /* Advance native element pointer */ - elmt++; + /* Advance native element pointer */ + elmt++; - /* Decrement # of elements to encode */ - nelmts--; -} /* end while */ + /* Decrement # of elements to encode */ + nelmts--; + } /* end while */ END_FUNC(STATIC) /* end H5FA__test_encode() */ @@ -240,29 +240,29 @@ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, /* Local variables */ #ifndef NDEBUG -H5FA__test_ctx_t *ctx = (H5FA__test_ctx_t *)_ctx; /* Callback context to destroy */ -#endif /* NDEBUG */ -uint64_t * elmt = (uint64_t *)_elmt; /* Convenience pointer to native elements */ -const uint8_t *raw = (const uint8_t *)_raw; /* Convenience pointer to raw elements */ - -/* Sanity checks */ -HDassert(raw); -HDassert(elmt); -HDassert(nelmts); -HDassert(H5FA__TEST_BOGUS_VAL == ctx->bogus); - -/* Decode raw elements into native elements */ -while (nelmts) { - /* Decode element */ - /* (advances 'raw' pointer) */ - UINT64DECODE(raw, *elmt); - - /* Advance native element pointer */ - elmt++; - - /* Decrement # of elements to decode */ - nelmts--; -} /* end while */ + H5FA__test_ctx_t *ctx = (H5FA__test_ctx_t *)_ctx; /* Callback context to destroy */ +#endif /* NDEBUG */ + uint64_t * elmt = (uint64_t *)_elmt; /* Convenience pointer to native elements */ + const uint8_t *raw = (const uint8_t *)_raw; /* Convenience pointer to raw elements */ + + /* Sanity checks */ + HDassert(raw); + HDassert(elmt); + HDassert(nelmts); + HDassert(H5FA__TEST_BOGUS_VAL == ctx->bogus); + + /* Decode raw elements into native elements */ + while (nelmts) { + /* Decode element */ + /* (advances 'raw' pointer) */ + UINT64DECODE(raw, *elmt); + + /* Advance native element pointer */ + elmt++; + + /* Decrement # of elements to decode */ + nelmts--; + } /* end while */ END_FUNC(STATIC) /* end H5FA__test_decode() */ @@ -281,17 +281,17 @@ END_FUNC(STATIC) /* end H5FA__test_decode() */ BEGIN_FUNC(STATIC, NOERR, herr_t, SUCCEED, -, H5FA__test_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const void *elmt)) -/* Local variables */ -char temp_str[128]; /* Temporary string, for formatting */ + /* Local variables */ + char temp_str[128]; /* Temporary string, for formatting */ -/* Sanity checks */ -HDassert(stream); -HDassert(elmt); + /* Sanity checks */ + HDassert(stream); + HDassert(elmt); -/* Print element */ -HDsprintf(temp_str, "Element #%llu:", (unsigned long long)idx); -HDfprintf(stream, "%*s%-*s %llu\n", indent, "", fwidth, temp_str, - (unsigned long long)*(const uint64_t *)elmt); + /* Print element */ + HDsprintf(temp_str, "Element #%llu:", (unsigned long long)idx); + HDfprintf(stream, "%*s%-*s %llu\n", indent, "", fwidth, temp_str, + (unsigned long long)*(const uint64_t *)elmt); END_FUNC(STATIC) /* end H5FA__test_debug() */ @@ -311,20 +311,20 @@ END_FUNC(STATIC) /* end H5FA__test_debug() */ BEGIN_FUNC(STATIC, ERR, void *, NULL, NULL, H5FA__test_crt_dbg_context(H5F_t H5_ATTR_UNUSED *f, haddr_t H5_ATTR_UNUSED obj_addr)) -/* Local variables */ -H5FA__test_ctx_t *ctx; /* Context for callbacks */ + /* Local variables */ + H5FA__test_ctx_t *ctx; /* Context for callbacks */ -/* Allocate new context structure */ -if (NULL == (ctx = H5FL_MALLOC(H5FA__test_ctx_t))) - H5E_THROW(H5E_CANTALLOC, "can't allocate fixed array client callback context") + /* Allocate new context structure */ + if (NULL == (ctx = H5FL_MALLOC(H5FA__test_ctx_t))) + H5E_THROW(H5E_CANTALLOC, "can't allocate fixed array client callback context") -/* Initialize the context */ -ctx->bogus = H5FA__TEST_BOGUS_VAL; + /* Initialize the context */ + ctx->bogus = H5FA__TEST_BOGUS_VAL; -/* Set return value */ -ret_value = ctx; + /* Set return value */ + ret_value = ctx; -CATCH + CATCH END_FUNC(STATIC) /* end H5FA__test_crt_dbg_context() */ @@ -342,13 +342,13 @@ END_FUNC(STATIC) /* end H5FA__test_crt_dbg_context() */ */ BEGIN_FUNC(PKG, NOERR, herr_t, SUCCEED, -, H5FA__get_cparam_test(const H5FA_t *fa, H5FA_create_t *cparam)) -/* Check arguments. */ -HDassert(fa); -HDassert(cparam); + /* Check arguments. */ + HDassert(fa); + HDassert(cparam); -/* Get fixed array creation parameters */ -cparam->raw_elmt_size = fa->hdr->cparam.raw_elmt_size; -cparam->nelmts = fa->hdr->cparam.nelmts; + /* Get fixed array creation parameters */ + cparam->raw_elmt_size = fa->hdr->cparam.raw_elmt_size; + cparam->nelmts = fa->hdr->cparam.nelmts; END_FUNC(PKG) /* end H5FA__get_cparam_test() */ @@ -367,16 +367,16 @@ END_FUNC(PKG) /* end H5FA__get_cparam_test() */ BEGIN_FUNC(PKG, ERRCATCH, int, 0, -, H5FA__cmp_cparam_test(const H5FA_create_t *cparam1, const H5FA_create_t *cparam2)) -/* Check arguments. */ -HDassert(cparam1); -HDassert(cparam2); + /* Check arguments. */ + HDassert(cparam1); + HDassert(cparam2); -/* Compare creation parameters for array */ -if (cparam1->raw_elmt_size < cparam2->raw_elmt_size) - H5_LEAVE(-1) -else if (cparam1->raw_elmt_size > cparam2->raw_elmt_size) - H5_LEAVE(1) + /* Compare creation parameters for array */ + if (cparam1->raw_elmt_size < cparam2->raw_elmt_size) + H5_LEAVE(-1) + else if (cparam1->raw_elmt_size > cparam2->raw_elmt_size) + H5_LEAVE(1) -CATCH + CATCH END_FUNC(PKG) /* end H5FA__cmp_cparam_test() */ @@ -100,78 +100,78 @@ H5FL_BLK_DEFINE(lheap_chunk); */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5HL_create(H5F_t *f, size_t size_hint, haddr_t *addr_p /*out*/)) -H5HL_t * heap = NULL; /* Heap created */ -H5HL_prfx_t *prfx = NULL; /* Heap prefix */ -hsize_t total_size = 0; /* Total heap size on disk */ - -/* check arguments */ -HDassert(f); -HDassert(addr_p); - -/* Adjust size hint as necessary */ -if (size_hint && size_hint < H5HL_SIZEOF_FREE(f)) - size_hint = H5HL_SIZEOF_FREE(f); -size_hint = H5HL_ALIGN(size_hint); - -/* Allocate new heap structure */ -if (NULL == (heap = H5HL__new(H5F_SIZEOF_SIZE(f), H5F_SIZEOF_ADDR(f), H5HL_SIZEOF_HDR(f)))) - H5E_THROW(H5E_CANTALLOC, "can't allocate new heap struct"); - -/* Allocate file space */ -total_size = heap->prfx_size + size_hint; -if (HADDR_UNDEF == (heap->prfx_addr = H5MF_alloc(f, H5FD_MEM_LHEAP, total_size))) - H5E_THROW(H5E_CANTALLOC, "unable to allocate file memory"); - -/* Initialize info */ -heap->single_cache_obj = TRUE; -heap->dblk_addr = heap->prfx_addr + (hsize_t)heap->prfx_size; -heap->dblk_size = size_hint; -if (size_hint) - if (NULL == (heap->dblk_image = H5FL_BLK_CALLOC(lheap_chunk, size_hint))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); - -/* free list */ -if (size_hint) { - if (NULL == (heap->freelist = H5FL_MALLOC(H5HL_free_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); - heap->freelist->offset = 0; - heap->freelist->size = size_hint; - heap->freelist->prev = heap->freelist->next = NULL; - heap->free_block = 0; -} /* end if */ -else { - heap->freelist = NULL; - heap->free_block = H5HL_FREE_NULL; -} /* end else */ - -/* Allocate the heap prefix */ -if (NULL == (prfx = H5HL__prfx_new(heap))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); - -/* Add to cache */ -if (FAIL == H5AC_insert_entry(f, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, H5AC__NO_FLAGS_SET)) - H5E_THROW(H5E_CANTINIT, "unable to cache local heap prefix"); - -/* Set address to return */ -*addr_p = heap->prfx_addr; - -CATCH -if (ret_value < 0) { - *addr_p = HADDR_UNDEF; - if (prfx) { - if (FAIL == H5HL__prfx_dest(prfx)) - H5E_THROW(H5E_CANTFREE, "unable to destroy local heap prefix"); + H5HL_t * heap = NULL; /* Heap created */ + H5HL_prfx_t *prfx = NULL; /* Heap prefix */ + hsize_t total_size = 0; /* Total heap size on disk */ + + /* check arguments */ + HDassert(f); + HDassert(addr_p); + + /* Adjust size hint as necessary */ + if (size_hint && size_hint < H5HL_SIZEOF_FREE(f)) + size_hint = H5HL_SIZEOF_FREE(f); + size_hint = H5HL_ALIGN(size_hint); + + /* Allocate new heap structure */ + if (NULL == (heap = H5HL__new(H5F_SIZEOF_SIZE(f), H5F_SIZEOF_ADDR(f), H5HL_SIZEOF_HDR(f)))) + H5E_THROW(H5E_CANTALLOC, "can't allocate new heap struct"); + + /* Allocate file space */ + total_size = heap->prfx_size + size_hint; + if (HADDR_UNDEF == (heap->prfx_addr = H5MF_alloc(f, H5FD_MEM_LHEAP, total_size))) + H5E_THROW(H5E_CANTALLOC, "unable to allocate file memory"); + + /* Initialize info */ + heap->single_cache_obj = TRUE; + heap->dblk_addr = heap->prfx_addr + (hsize_t)heap->prfx_size; + heap->dblk_size = size_hint; + if (size_hint) + if (NULL == (heap->dblk_image = H5FL_BLK_CALLOC(lheap_chunk, size_hint))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); + + /* free list */ + if (size_hint) { + if (NULL == (heap->freelist = H5FL_MALLOC(H5HL_free_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); + heap->freelist->offset = 0; + heap->freelist->size = size_hint; + heap->freelist->prev = heap->freelist->next = NULL; + heap->free_block = 0; } /* end if */ else { - if (heap) { - if (H5F_addr_defined(heap->prfx_addr)) - if (FAIL == H5MF_xfree(f, H5FD_MEM_LHEAP, heap->prfx_addr, total_size)) - H5E_THROW(H5E_CANTFREE, "can't release heap data?"); - if (FAIL == H5HL__dest(heap)) - H5E_THROW(H5E_CANTFREE, "unable to destroy local heap"); + heap->freelist = NULL; + heap->free_block = H5HL_FREE_NULL; + } /* end else */ + + /* Allocate the heap prefix */ + if (NULL == (prfx = H5HL__prfx_new(heap))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); + + /* Add to cache */ + if (FAIL == H5AC_insert_entry(f, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, H5AC__NO_FLAGS_SET)) + H5E_THROW(H5E_CANTINIT, "unable to cache local heap prefix"); + + /* Set address to return */ + *addr_p = heap->prfx_addr; + + CATCH + if (ret_value < 0) { + *addr_p = HADDR_UNDEF; + if (prfx) { + if (FAIL == H5HL__prfx_dest(prfx)) + H5E_THROW(H5E_CANTFREE, "unable to destroy local heap prefix"); } /* end if */ - } /* end else */ -} /* end if */ + else { + if (heap) { + if (H5F_addr_defined(heap->prfx_addr)) + if (FAIL == H5MF_xfree(f, H5FD_MEM_LHEAP, heap->prfx_addr, total_size)) + H5E_THROW(H5E_CANTFREE, "can't release heap data?"); + if (FAIL == H5HL__dest(heap)) + H5E_THROW(H5E_CANTFREE, "unable to destroy local heap"); + } /* end if */ + } /* end else */ + } /* end if */ END_FUNC(PRIV) /* end H5HL_create() */ @@ -190,103 +190,104 @@ END_FUNC(PRIV) /* end H5HL_create() */ */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5HL__minimize_heap_space(H5F_t *f, H5HL_t *heap)) -size_t new_heap_size = heap->dblk_size; /* New size of heap */ - -/* check args */ -HDassert(f); -HDassert(heap); + size_t new_heap_size = heap->dblk_size; /* New size of heap */ -/* - * Check to see if we can reduce the size of the heap in memory by - * eliminating free blocks at the tail of the buffer before flushing the - * buffer out. - */ -if (heap->freelist) { - H5HL_free_t *tmp_fl; - H5HL_free_t *last_fl = NULL; - - /* Search for a free block at the end of the buffer */ - for (tmp_fl = heap->freelist; tmp_fl; tmp_fl = tmp_fl->next) - /* Check if the end of this free block is at the end of the buffer */ - if (tmp_fl->offset + tmp_fl->size == heap->dblk_size) { - last_fl = tmp_fl; - break; - } /* end if */ + /* check args */ + HDassert(f); + HDassert(heap); /* - * Found free block at the end of the buffer, decide what to do - * about it + * Check to see if we can reduce the size of the heap in memory by + * eliminating free blocks at the tail of the buffer before flushing the + * buffer out. */ - if (last_fl) { + if (heap->freelist) { + H5HL_free_t *tmp_fl; + H5HL_free_t *last_fl = NULL; + + /* Search for a free block at the end of the buffer */ + for (tmp_fl = heap->freelist; tmp_fl; tmp_fl = tmp_fl->next) + /* Check if the end of this free block is at the end of the buffer */ + if (tmp_fl->offset + tmp_fl->size == heap->dblk_size) { + last_fl = tmp_fl; + break; + } /* end if */ + /* - * If the last free block's size is more than half the memory - * buffer size (and the memory buffer is larger than the - * minimum size), reduce or eliminate it. + * Found free block at the end of the buffer, decide what to do + * about it */ - if (last_fl->size >= (heap->dblk_size / 2) && heap->dblk_size > H5HL_MIN_HEAP) { - /* - * Reduce size of buffer until it's too small or would - * eliminate the free block - */ - while (new_heap_size > H5HL_MIN_HEAP && new_heap_size >= (last_fl->offset + H5HL_SIZEOF_FREE(f))) - new_heap_size /= 2; - + if (last_fl) { /* - * Check if reducing the memory buffer size would - * eliminate the free block + * If the last free block's size is more than half the memory + * buffer size (and the memory buffer is larger than the + * minimum size), reduce or eliminate it. */ - if (new_heap_size < (last_fl->offset + H5HL_SIZEOF_FREE(f))) { - /* Check if this is the only block on the free list */ - if (last_fl->prev == NULL && last_fl->next == NULL) { - /* Double the new memory size */ - new_heap_size *= 2; - + if (last_fl->size >= (heap->dblk_size / 2) && heap->dblk_size > H5HL_MIN_HEAP) { + /* + * Reduce size of buffer until it's too small or would + * eliminate the free block + */ + while (new_heap_size > H5HL_MIN_HEAP && + new_heap_size >= (last_fl->offset + H5HL_SIZEOF_FREE(f))) + new_heap_size /= 2; + + /* + * Check if reducing the memory buffer size would + * eliminate the free block + */ + if (new_heap_size < (last_fl->offset + H5HL_SIZEOF_FREE(f))) { + /* Check if this is the only block on the free list */ + if (last_fl->prev == NULL && last_fl->next == NULL) { + /* Double the new memory size */ + new_heap_size *= 2; + + /* Truncate the free block */ + last_fl->size = H5HL_ALIGN(new_heap_size - last_fl->offset); + new_heap_size = last_fl->offset + last_fl->size; + HDassert(last_fl->size >= H5HL_SIZEOF_FREE(f)); + } /* end if */ + else { + /* + * Set the size of the memory buffer to the start + * of the free list + */ + new_heap_size = last_fl->offset; + + /* Eliminate the free block from the list */ + last_fl = H5HL__remove_free(heap, last_fl); + } /* end else */ + } /* end if */ + else { /* Truncate the free block */ last_fl->size = H5HL_ALIGN(new_heap_size - last_fl->offset); new_heap_size = last_fl->offset + last_fl->size; HDassert(last_fl->size >= H5HL_SIZEOF_FREE(f)); - } /* end if */ - else { - /* - * Set the size of the memory buffer to the start - * of the free list - */ - new_heap_size = last_fl->offset; - - /* Eliminate the free block from the list */ - last_fl = H5HL__remove_free(heap, last_fl); + HDassert(last_fl->size == H5HL_ALIGN(last_fl->size)); } /* end else */ } /* end if */ - else { - /* Truncate the free block */ - last_fl->size = H5HL_ALIGN(new_heap_size - last_fl->offset); - new_heap_size = last_fl->offset + last_fl->size; - HDassert(last_fl->size >= H5HL_SIZEOF_FREE(f)); - HDassert(last_fl->size == H5HL_ALIGN(last_fl->size)); - } /* end else */ - } /* end if */ - } /* end if */ -} /* end if */ + } /* end if */ + } /* end if */ -/* - * If the heap grew smaller than disk storage then move the - * data segment of the heap to another contiguous block of disk - * storage. - */ -if (new_heap_size != heap->dblk_size) { - HDassert(new_heap_size < heap->dblk_size); + /* + * If the heap grew smaller than disk storage then move the + * data segment of the heap to another contiguous block of disk + * storage. + */ + if (new_heap_size != heap->dblk_size) { + HDassert(new_heap_size < heap->dblk_size); - /* Resize the memory buffer */ - if (NULL == (heap->dblk_image = H5FL_BLK_REALLOC(lheap_chunk, heap->dblk_image, new_heap_size))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); + /* Resize the memory buffer */ + if (NULL == (heap->dblk_image = H5FL_BLK_REALLOC(lheap_chunk, heap->dblk_image, new_heap_size))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); - /* Reallocate data block in file */ - if (FAIL == H5HL__dblk_realloc(f, heap, new_heap_size)) - H5E_THROW(H5E_CANTRESIZE, "reallocating data block failed"); -} /* end if */ + /* Reallocate data block in file */ + if (FAIL == H5HL__dblk_realloc(f, heap, new_heap_size)) + H5E_THROW(H5E_CANTRESIZE, "reallocating data block failed"); + } /* end if */ -CATCH -/* No special processing on errors */ + CATCH + /* No special processing on errors */ END_FUNC(STATIC) /* H5HL__minimize_heap_space() */ @@ -305,64 +306,65 @@ END_FUNC(STATIC) /* H5HL__minimize_heap_space() */ */ BEGIN_FUNC(PRIV, ERR, H5HL_t *, NULL, NULL, H5HL_protect(H5F_t *f, haddr_t addr, unsigned flags)) -H5HL_cache_prfx_ud_t prfx_udata; /* User data for protecting local heap prefix */ -H5HL_prfx_t * prfx = NULL; /* Local heap prefix */ -H5HL_dblk_t * dblk = NULL; /* Local heap data block */ -H5HL_t * heap = NULL; /* Heap data structure */ -unsigned prfx_cache_flags = H5AC__NO_FLAGS_SET; /* Cache flags for unprotecting prefix entry */ -unsigned dblk_cache_flags = H5AC__NO_FLAGS_SET; /* Cache flags for unprotecting data block entry */ - -/* check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); - -/* only the H5AC__READ_ONLY_FLAG may appear in flags */ -HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); - -/* Construct the user data for protect callback */ -prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f); -prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f); -prfx_udata.prfx_addr = addr; -prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f); - -/* Protect the local heap prefix */ -if (NULL == (prfx = (H5HL_prfx_t *)H5AC_protect(f, H5AC_LHEAP_PRFX, addr, &prfx_udata, flags))) - H5E_THROW(H5E_CANTPROTECT, "unable to load heap prefix"); - -/* Get the pointer to the heap */ -heap = prfx->heap; - -/* Check if the heap is already pinned in memory */ -/* (for re-entrant situation) */ -if (heap->prots == 0) { - /* Check if heap has separate data block */ - if (heap->single_cache_obj) - /* Set the flag for pinning the prefix when unprotecting it */ - prfx_cache_flags |= H5AC__PIN_ENTRY_FLAG; - else { - /* Protect the local heap data block */ - if (NULL == (dblk = (H5HL_dblk_t *)H5AC_protect(f, H5AC_LHEAP_DBLK, heap->dblk_addr, heap, flags))) - H5E_THROW(H5E_CANTPROTECT, "unable to load heap data block"); + H5HL_cache_prfx_ud_t prfx_udata; /* User data for protecting local heap prefix */ + H5HL_prfx_t * prfx = NULL; /* Local heap prefix */ + H5HL_dblk_t * dblk = NULL; /* Local heap data block */ + H5HL_t * heap = NULL; /* Heap data structure */ + unsigned prfx_cache_flags = H5AC__NO_FLAGS_SET; /* Cache flags for unprotecting prefix entry */ + unsigned dblk_cache_flags = H5AC__NO_FLAGS_SET; /* Cache flags for unprotecting data block entry */ + + /* check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + + /* only the H5AC__READ_ONLY_FLAG may appear in flags */ + HDassert((flags & (unsigned)(~H5AC__READ_ONLY_FLAG)) == 0); + + /* Construct the user data for protect callback */ + prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f); + prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f); + prfx_udata.prfx_addr = addr; + prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f); + + /* Protect the local heap prefix */ + if (NULL == (prfx = (H5HL_prfx_t *)H5AC_protect(f, H5AC_LHEAP_PRFX, addr, &prfx_udata, flags))) + H5E_THROW(H5E_CANTPROTECT, "unable to load heap prefix"); + + /* Get the pointer to the heap */ + heap = prfx->heap; + + /* Check if the heap is already pinned in memory */ + /* (for re-entrant situation) */ + if (heap->prots == 0) { + /* Check if heap has separate data block */ + if (heap->single_cache_obj) + /* Set the flag for pinning the prefix when unprotecting it */ + prfx_cache_flags |= H5AC__PIN_ENTRY_FLAG; + else { + /* Protect the local heap data block */ + if (NULL == + (dblk = (H5HL_dblk_t *)H5AC_protect(f, H5AC_LHEAP_DBLK, heap->dblk_addr, heap, flags))) + H5E_THROW(H5E_CANTPROTECT, "unable to load heap data block"); - /* Set the flag for pinning the data block when unprotecting it */ - dblk_cache_flags |= H5AC__PIN_ENTRY_FLAG; - } /* end if */ -} /* end if */ + /* Set the flag for pinning the data block when unprotecting it */ + dblk_cache_flags |= H5AC__PIN_ENTRY_FLAG; + } /* end if */ + } /* end if */ -/* Increment # of times heap is protected */ -heap->prots++; + /* Increment # of times heap is protected */ + heap->prots++; -/* Set return value */ -ret_value = heap; + /* Set return value */ + ret_value = heap; -CATCH -/* Release the prefix from the cache, now pinned */ -if (prfx && heap && H5AC_unprotect(f, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, prfx_cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap prefix"); + CATCH + /* Release the prefix from the cache, now pinned */ + if (prfx && heap && H5AC_unprotect(f, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, prfx_cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap prefix"); -/* Release the data block from the cache, now pinned */ -if (dblk && heap && H5AC_unprotect(f, H5AC_LHEAP_DBLK, heap->dblk_addr, dblk, dblk_cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap data block"); + /* Release the data block from the cache, now pinned */ + if (dblk && heap && H5AC_unprotect(f, H5AC_LHEAP_DBLK, heap->dblk_addr, dblk, dblk_cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap data block"); END_FUNC(PRIV) /* end H5HL_protect() */ @@ -382,14 +384,14 @@ END_FUNC(PRIV) /* end H5HL_protect() */ */ BEGIN_FUNC(PRIV, ERR, void *, NULL, NULL, H5HL_offset_into(const H5HL_t *heap, size_t offset)) -/* Sanity check */ -HDassert(heap); -if (offset >= heap->dblk_size) - H5E_THROW(H5E_CANTGET, "unable to offset into local heap data block"); + /* Sanity check */ + HDassert(heap); + if (offset >= heap->dblk_size) + H5E_THROW(H5E_CANTGET, "unable to offset into local heap data block"); -ret_value = heap->dblk_image + offset; + ret_value = heap->dblk_image + offset; -CATCH + CATCH /* No special processing on errors */ END_FUNC(PRIV) /* end H5HL_offset_into() */ @@ -407,33 +409,33 @@ END_FUNC(PRIV) /* end H5HL_offset_into() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5HL_unprotect(H5HL_t *heap)) -/* check arguments */ -HDassert(heap); + /* check arguments */ + HDassert(heap); -/* Decrement # of times heap is protected */ -heap->prots--; + /* Decrement # of times heap is protected */ + heap->prots--; -/* Check for last unprotection of heap */ -if (heap->prots == 0) { - /* Check for separate heap data block */ - if (heap->single_cache_obj) { - /* Mark local heap prefix as evictable again */ - if (FAIL == H5AC_unpin_entry(heap->prfx)) - H5E_THROW(H5E_CANTUNPIN, "unable to unpin local heap data block"); - } /* end if */ - else { - /* Sanity check */ - HDassert(heap->dblk); + /* Check for last unprotection of heap */ + if (heap->prots == 0) { + /* Check for separate heap data block */ + if (heap->single_cache_obj) { + /* Mark local heap prefix as evictable again */ + if (FAIL == H5AC_unpin_entry(heap->prfx)) + H5E_THROW(H5E_CANTUNPIN, "unable to unpin local heap data block"); + } /* end if */ + else { + /* Sanity check */ + HDassert(heap->dblk); - /* Mark local heap data block as evictable again */ - /* (data block still pins prefix) */ - if (FAIL == H5AC_unpin_entry(heap->dblk)) - H5E_THROW(H5E_CANTUNPIN, "unable to unpin local heap data block"); - } /* end else */ -} /* end if */ + /* Mark local heap data block as evictable again */ + /* (data block still pins prefix) */ + if (FAIL == H5AC_unpin_entry(heap->dblk)) + H5E_THROW(H5E_CANTUNPIN, "unable to unpin local heap data block"); + } /* end else */ + } /* end if */ -CATCH -/* No special processing on errors */ + CATCH + /* No special processing on errors */ END_FUNC(PRIV) /* end H5HL_unprotect() */ @@ -452,16 +454,16 @@ END_FUNC(PRIV) /* end H5HL_unprotect() */ */ BEGIN_FUNC(STATIC, NOERR, H5HL_free_t *, NULL, -, H5HL__remove_free(H5HL_t *heap, H5HL_free_t *fl)) -if (fl->prev) - fl->prev->next = fl->next; -if (fl->next) - fl->next->prev = fl->prev; + if (fl->prev) + fl->prev->next = fl->next; + if (fl->next) + fl->next->prev = fl->prev; -if (!fl->prev) - heap->freelist = fl->next; + if (!fl->prev) + heap->freelist = fl->next; -/* H5FL_FREE always returns NULL so we can't check for errors */ -ret_value = (H5HL_free_t *)H5FL_FREE(H5HL_free_t, fl); + /* H5FL_FREE always returns NULL so we can't check for errors */ + ret_value = (H5HL_free_t *)H5FL_FREE(H5HL_free_t, fl); END_FUNC(STATIC) /* end H5HL__remove_free() */ @@ -479,25 +481,25 @@ END_FUNC(STATIC) /* end H5HL__remove_free() */ */ BEGIN_FUNC(STATIC, ERR, herr_t, SUCCEED, FAIL, H5HL__dirty(H5HL_t *heap)) -/* check arguments */ -HDassert(heap); -HDassert(heap->prfx); + /* check arguments */ + HDassert(heap); + HDassert(heap->prfx); -/* Mark heap data block as dirty, if there is one */ -if (!heap->single_cache_obj) { - /* Sanity check */ - HDassert(heap->dblk); + /* Mark heap data block as dirty, if there is one */ + if (!heap->single_cache_obj) { + /* Sanity check */ + HDassert(heap->dblk); - if (FAIL == H5AC_mark_entry_dirty(heap->dblk)) - H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark heap data block as dirty"); -} /* end if */ + if (FAIL == H5AC_mark_entry_dirty(heap->dblk)) + H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark heap data block as dirty"); + } /* end if */ -/* Mark heap prefix as dirty */ -if (FAIL == H5AC_mark_entry_dirty(heap->prfx)) - H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark heap prefix as dirty"); + /* Mark heap prefix as dirty */ + if (FAIL == H5AC_mark_entry_dirty(heap->prfx)) + H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark heap prefix as dirty"); -CATCH -/* No special processing on errors */ + CATCH + /* No special processing on errors */ END_FUNC(STATIC) /* end H5HL__dirty() */ @@ -517,192 +519,192 @@ END_FUNC(STATIC) /* end H5HL__dirty() */ BEGIN_FUNC(PRIV, ERR, size_t, UFAIL, UFAIL, H5HL_insert(H5F_t *f, H5HL_t *heap, size_t buf_size, const void *buf)) -H5HL_free_t *fl = NULL, *last_fl = NULL; -size_t offset = 0; -size_t need_size; -hbool_t found; - -/* check arguments */ -HDassert(f); -HDassert(heap); -HDassert(buf_size > 0); -HDassert(buf); - -/* Mark heap as dirty in cache */ -/* (A bit early in the process, but it's difficult to determine in the - * code below where to mark the heap as dirty, especially in error cases, - * so we just accept that an extra flush of the heap info could occur - * if an error occurs -QAK) - */ -if (FAIL == H5HL__dirty(heap)) - H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark heap as dirty"); - -/* - * 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 = H5HL_ALIGN(buf_size); + H5HL_free_t *fl = NULL, *last_fl = NULL; + size_t offset = 0; + size_t need_size; + hbool_t found; + + /* check arguments */ + HDassert(f); + HDassert(heap); + HDassert(buf_size > 0); + HDassert(buf); + + /* Mark heap as dirty in cache */ + /* (A bit early in the process, but it's difficult to determine in the + * code below where to mark the heap as dirty, especially in error cases, + * so we just accept that an extra flush of the heap info could occur + * if an error occurs -QAK) + */ + if (FAIL == H5HL__dirty(heap)) + H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark heap as dirty"); -/* - * 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 > need_size && fl->size - need_size >= H5HL_SIZEOF_FREE(f)) { - /* a big enough free block was found */ - offset = fl->offset; - fl->offset += need_size; - fl->size -= need_size; - HDassert(fl->offset == H5HL_ALIGN(fl->offset)); - HDassert(fl->size == H5HL_ALIGN(fl->size)); - found = TRUE; - break; - } - else if (fl->size == need_size) { - /* free block of exact size found */ - offset = fl->offset; - fl = H5HL__remove_free(heap, fl); - found = TRUE; - break; - } - else if (!last_fl || last_fl->offset < fl->offset) { - /* track free space that's closest to end of heap */ - last_fl = fl; - } -} /* end for */ - -/* - * If no free chunk was large enough, then allocate more space and - * add it to the free list. If the heap ends with a free chunk, we - * can extend that free chunk. Otherwise we'll have to make another - * free chunk. If the heap must expand, we double its size. - */ -if (found == FALSE) { - size_t need_more; /* How much more space we need */ - size_t new_dblk_size; /* Final size of space allocated for heap data block */ - size_t old_dblk_size; /* Previous size of space allocated for heap data block */ - htri_t was_extended; /* Whether the local heap's data segment on disk was extended */ - - /* At least double the heap's size, making certain there's enough room - * for the new object */ - need_more = MAX(need_size, heap->dblk_size); - - /* If there is no last free block or it's not at the end of the heap, - * and the amount of space to allocate is not big enough to include at - * least the new object and a free-list info, trim down the amount of - * space requested to just the amount of space needed. (Generally - * speaking, this only occurs when the heap is small -QAK) + /* + * 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. */ - if (!(last_fl && last_fl->offset + last_fl->size == heap->dblk_size) && - (need_more < (need_size + H5HL_SIZEOF_FREE(f)))) - need_more = need_size; - - new_dblk_size = heap->dblk_size + need_more; - HDassert(heap->dblk_size < new_dblk_size); - old_dblk_size = heap->dblk_size; - H5_CHECK_OVERFLOW(heap->dblk_size, size_t, hsize_t); - H5_CHECK_OVERFLOW(new_dblk_size, size_t, hsize_t); - - /* Extend current heap if possible */ - was_extended = - H5MF_try_extend(f, H5FD_MEM_LHEAP, heap->dblk_addr, (hsize_t)(heap->dblk_size), (hsize_t)need_more); - if (FAIL == was_extended) - H5E_THROW(H5E_CANTEXTEND, "error trying to extend heap"); - - /* Check if we extended the heap data block in file */ - if (was_extended == TRUE) { - /* Check for prefix & data block contiguous */ - if (heap->single_cache_obj) { - /* Resize prefix+data block */ - if (FAIL == H5AC_resize_entry(heap->prfx, (size_t)(heap->prfx_size + new_dblk_size))) - H5E_THROW(H5E_CANTRESIZE, "unable to resize heap prefix in cache"); - } /* end if */ - else { - /* Resize 'standalone' data block */ - if (FAIL == H5AC_resize_entry(heap->dblk, (size_t)new_dblk_size)) - H5E_THROW(H5E_CANTRESIZE, "unable to resize heap data block in cache"); - } /* end else */ + need_size = H5HL_ALIGN(buf_size); - /* Note new size */ - heap->dblk_size = new_dblk_size; - } /* end if */ - else { /* ...if we can't, allocate a new chunk & release the old */ - /* Reallocate data block in file */ - if (FAIL == H5HL__dblk_realloc(f, heap, new_dblk_size)) - H5E_THROW(H5E_CANTRESIZE, "reallocating data block failed"); - } /* end if */ + /* + * 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 > need_size && fl->size - need_size >= H5HL_SIZEOF_FREE(f)) { + /* a big enough free block was found */ + offset = fl->offset; + fl->offset += need_size; + fl->size -= need_size; + HDassert(fl->offset == H5HL_ALIGN(fl->offset)); + HDassert(fl->size == H5HL_ALIGN(fl->size)); + found = TRUE; + break; + } + else if (fl->size == need_size) { + /* free block of exact size found */ + offset = fl->offset; + fl = H5HL__remove_free(heap, fl); + found = TRUE; + break; + } + else if (!last_fl || last_fl->offset < fl->offset) { + /* track free space that's closest to end of heap */ + last_fl = fl; + } + } /* end for */ - /* If the last free list in the heap is at the end of the heap, extend it */ - if (last_fl && last_fl->offset + last_fl->size == old_dblk_size) { - /* - * Increase the size of the last free block. + /* + * If no free chunk was large enough, then allocate more space and + * add it to the free list. If the heap ends with a free chunk, we + * can extend that free chunk. Otherwise we'll have to make another + * free chunk. If the heap must expand, we double its size. + */ + if (found == FALSE) { + size_t need_more; /* How much more space we need */ + size_t new_dblk_size; /* Final size of space allocated for heap data block */ + size_t old_dblk_size; /* Previous size of space allocated for heap data block */ + htri_t was_extended; /* Whether the local heap's data segment on disk was extended */ + + /* At least double the heap's size, making certain there's enough room + * for the new object */ + need_more = MAX(need_size, heap->dblk_size); + + /* If there is no last free block or it's not at the end of the heap, + * and the amount of space to allocate is not big enough to include at + * least the new object and a free-list info, trim down the amount of + * space requested to just the amount of space needed. (Generally + * speaking, this only occurs when the heap is small -QAK) */ - offset = last_fl->offset; - last_fl->offset += need_size; - last_fl->size += need_more - need_size; - HDassert(last_fl->offset == H5HL_ALIGN(last_fl->offset)); - HDassert(last_fl->size == H5HL_ALIGN(last_fl->size)); + if (!(last_fl && last_fl->offset + last_fl->size == heap->dblk_size) && + (need_more < (need_size + H5HL_SIZEOF_FREE(f)))) + need_more = need_size; + + new_dblk_size = heap->dblk_size + need_more; + HDassert(heap->dblk_size < new_dblk_size); + old_dblk_size = heap->dblk_size; + H5_CHECK_OVERFLOW(heap->dblk_size, size_t, hsize_t); + H5_CHECK_OVERFLOW(new_dblk_size, size_t, hsize_t); + + /* Extend current heap if possible */ + was_extended = H5MF_try_extend(f, H5FD_MEM_LHEAP, heap->dblk_addr, (hsize_t)(heap->dblk_size), + (hsize_t)need_more); + if (FAIL == was_extended) + H5E_THROW(H5E_CANTEXTEND, "error trying to extend heap"); + + /* Check if we extended the heap data block in file */ + if (was_extended == TRUE) { + /* Check for prefix & data block contiguous */ + if (heap->single_cache_obj) { + /* Resize prefix+data block */ + if (FAIL == H5AC_resize_entry(heap->prfx, (size_t)(heap->prfx_size + new_dblk_size))) + H5E_THROW(H5E_CANTRESIZE, "unable to resize heap prefix in cache"); + } /* end if */ + else { + /* Resize 'standalone' data block */ + if (FAIL == H5AC_resize_entry(heap->dblk, (size_t)new_dblk_size)) + H5E_THROW(H5E_CANTRESIZE, "unable to resize heap data block in cache"); + } /* end else */ + + /* Note new size */ + heap->dblk_size = new_dblk_size; + } /* end if */ + else { /* ...if we can't, allocate a new chunk & release the old */ + /* Reallocate data block in file */ + if (FAIL == H5HL__dblk_realloc(f, heap, new_dblk_size)) + H5E_THROW(H5E_CANTRESIZE, "reallocating data block failed"); + } /* end if */ - if (last_fl->size < H5HL_SIZEOF_FREE(f)) { + /* If the last free list in the heap is at the end of the heap, extend it */ + if (last_fl && last_fl->offset + last_fl->size == old_dblk_size) { + /* + * Increase the size of the last free block. + */ + offset = last_fl->offset; + last_fl->offset += need_size; + last_fl->size += need_more - need_size; + HDassert(last_fl->offset == H5HL_ALIGN(last_fl->offset)); + HDassert(last_fl->size == H5HL_ALIGN(last_fl->size)); + + if (last_fl->size < H5HL_SIZEOF_FREE(f)) { #ifdef H5HL_DEBUG - if (H5DEBUG(HL) && last_fl->size) { - HDfprintf(H5DEBUG(HL), "H5HL: lost %lu bytes at line %d\n", (unsigned long)(last_fl->size), - __LINE__); - } + if (H5DEBUG(HL) && last_fl->size) { + HDfprintf(H5DEBUG(HL), "H5HL: lost %lu bytes at line %d\n", + (unsigned long)(last_fl->size), __LINE__); + } #endif - last_fl = H5HL__remove_free(heap, last_fl); - } - } /* end if */ - else { - /* - * Create a new free list element large enough that we can - * take some space out of it right away. - */ - offset = old_dblk_size; - if (need_more - need_size >= H5HL_SIZEOF_FREE(f)) { - if (NULL == (fl = H5FL_MALLOC(H5HL_free_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); - fl->offset = old_dblk_size + need_size; - fl->size = need_more - need_size; - HDassert(fl->offset == H5HL_ALIGN(fl->offset)); - HDassert(fl->size == H5HL_ALIGN(fl->size)); - fl->prev = NULL; - fl->next = heap->freelist; - if (heap->freelist) - heap->freelist->prev = fl; - heap->freelist = fl; + last_fl = H5HL__remove_free(heap, last_fl); + } + } /* end if */ + else { + /* + * Create a new free list element large enough that we can + * take some space out of it right away. + */ + offset = old_dblk_size; + if (need_more - need_size >= H5HL_SIZEOF_FREE(f)) { + if (NULL == (fl = H5FL_MALLOC(H5HL_free_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); + fl->offset = old_dblk_size + need_size; + fl->size = need_more - need_size; + HDassert(fl->offset == H5HL_ALIGN(fl->offset)); + HDassert(fl->size == H5HL_ALIGN(fl->size)); + fl->prev = NULL; + fl->next = heap->freelist; + if (heap->freelist) + heap->freelist->prev = fl; + heap->freelist = fl; #ifdef H5HL_DEBUG - } - else if (H5DEBUG(HL) && need_more > need_size) { - HDfprintf(H5DEBUG(HL), "H5HL_insert: lost %lu bytes at line %d\n", - (unsigned long)(need_more - need_size), __LINE__); + } + else if (H5DEBUG(HL) && need_more > need_size) { + HDfprintf(H5DEBUG(HL), "H5HL_insert: lost %lu bytes at line %d\n", + (unsigned long)(need_more - need_size), __LINE__); #endif - } - } /* end else */ + } + } /* end else */ #ifdef H5HL_DEBUG - if (H5DEBUG(HL)) { - HDfprintf(H5DEBUG(HL), "H5HL: resize mem buf from %lu to %lu bytes\n", (unsigned long)(old_dblk_size), - (unsigned long)(old_dblk_size + need_more)); - } + if (H5DEBUG(HL)) { + HDfprintf(H5DEBUG(HL), "H5HL: resize mem buf from %lu to %lu bytes\n", + (unsigned long)(old_dblk_size), (unsigned long)(old_dblk_size + need_more)); + } #endif - if (NULL == (heap->dblk_image = H5FL_BLK_REALLOC(lheap_chunk, heap->dblk_image, heap->dblk_size))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); + if (NULL == (heap->dblk_image = H5FL_BLK_REALLOC(lheap_chunk, heap->dblk_image, heap->dblk_size))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); - /* Clear new section so junk doesn't appear in the file */ - /* (Avoid clearing section which will be overwritten with newly inserted data) */ - HDmemset(heap->dblk_image + offset + buf_size, 0, (new_dblk_size - (offset + buf_size))); -} /* end if */ + /* Clear new section so junk doesn't appear in the file */ + /* (Avoid clearing section which will be overwritten with newly inserted data) */ + HDmemset(heap->dblk_image + offset + buf_size, 0, (new_dblk_size - (offset + buf_size))); + } /* end if */ -/* Copy the data into the heap */ -H5MM_memcpy(heap->dblk_image + offset, buf, buf_size); + /* Copy the data into the heap */ + H5MM_memcpy(heap->dblk_image + offset, buf, buf_size); -/* Set return value */ -ret_value = offset; + /* Set return value */ + ret_value = offset; -CATCH -/* No special processing on errors */ + CATCH + /* No special processing on errors */ END_FUNC(PRIV) /* H5HL_insert() */ @@ -731,125 +733,125 @@ END_FUNC(PRIV) /* H5HL_insert() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5HL_remove(H5F_t *f, H5HL_t *heap, size_t offset, size_t size)) -H5HL_free_t *fl = NULL; + H5HL_free_t *fl = NULL; -/* check arguments */ -HDassert(f); -HDassert(heap); -HDassert(size > 0); -HDassert(offset == H5HL_ALIGN(offset)); + /* check arguments */ + HDassert(f); + HDassert(heap); + HDassert(size > 0); + HDassert(offset == H5HL_ALIGN(offset)); -size = H5HL_ALIGN(size); + size = H5HL_ALIGN(size); -HDassert(offset < heap->dblk_size); -HDassert(offset + size <= heap->dblk_size); + HDassert(offset < heap->dblk_size); + HDassert(offset + size <= heap->dblk_size); -/* Mark heap as dirty in cache */ -/* (A bit early in the process, but it's difficult to determine in the - * code below where to mark the heap as dirty, especially in error cases, - * so we just accept that an extra flush of the heap info could occur - * if an error occurs -QAK) - */ -if (FAIL == H5HL__dirty(heap)) - H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark heap as dirty"); + /* Mark heap as dirty in cache */ + /* (A bit early in the process, but it's difficult to determine in the + * code below where to mark the heap as dirty, especially in error cases, + * so we just accept that an extra flush of the heap info could occur + * if an error occurs -QAK) + */ + if (FAIL == H5HL__dirty(heap)) + H5E_THROW(H5E_CANTMARKDIRTY, "unable to mark heap as dirty"); -/* - * Check if this chunk can be prepended or appended to an already - * free chunk. It might also fall between two chunks in such a way - * that all three chunks can be combined into one. - */ -fl = heap->freelist; -while (fl) { - H5HL_free_t *fl2 = NULL; - - if ((offset + size) == fl->offset) { - fl->offset = offset; - fl->size += size; - HDassert(fl->offset == H5HL_ALIGN(fl->offset)); - HDassert(fl->size == H5HL_ALIGN(fl->size)); - fl2 = fl->next; - while (fl2) { - if ((fl2->offset + fl2->size) == fl->offset) { - fl->offset = fl2->offset; - fl->size += fl2->size; - HDassert(fl->offset == H5HL_ALIGN(fl->offset)); - HDassert(fl->size == H5HL_ALIGN(fl->size)); - fl2 = H5HL__remove_free(heap, fl2); - if (((fl->offset + fl->size) == heap->dblk_size) && ((2 * fl->size) > heap->dblk_size)) { - if (FAIL == H5HL__minimize_heap_space(f, heap)) - H5E_THROW(H5E_CANTFREE, "heap size minimization failed"); + /* + * Check if this chunk can be prepended or appended to an already + * free chunk. It might also fall between two chunks in such a way + * that all three chunks can be combined into one. + */ + fl = heap->freelist; + while (fl) { + H5HL_free_t *fl2 = NULL; + + if ((offset + size) == fl->offset) { + fl->offset = offset; + fl->size += size; + HDassert(fl->offset == H5HL_ALIGN(fl->offset)); + HDassert(fl->size == H5HL_ALIGN(fl->size)); + fl2 = fl->next; + while (fl2) { + if ((fl2->offset + fl2->size) == fl->offset) { + fl->offset = fl2->offset; + fl->size += fl2->size; + HDassert(fl->offset == H5HL_ALIGN(fl->offset)); + HDassert(fl->size == H5HL_ALIGN(fl->size)); + fl2 = H5HL__remove_free(heap, fl2); + if (((fl->offset + fl->size) == heap->dblk_size) && ((2 * fl->size) > heap->dblk_size)) { + if (FAIL == H5HL__minimize_heap_space(f, heap)) + H5E_THROW(H5E_CANTFREE, "heap size minimization failed"); + } + H5_LEAVE(SUCCEED); } - H5_LEAVE(SUCCEED); + fl2 = fl2->next; } - fl2 = fl2->next; - } - if (((fl->offset + fl->size) == heap->dblk_size) && ((2 * fl->size) > heap->dblk_size)) { - if (FAIL == H5HL__minimize_heap_space(f, heap)) - H5E_THROW(H5E_CANTFREE, "heap size minimization failed"); + if (((fl->offset + fl->size) == heap->dblk_size) && ((2 * fl->size) > heap->dblk_size)) { + if (FAIL == H5HL__minimize_heap_space(f, heap)) + H5E_THROW(H5E_CANTFREE, "heap size minimization failed"); + } + H5_LEAVE(SUCCEED); } - H5_LEAVE(SUCCEED); - } - else if (fl->offset + fl->size == offset) { - fl->size += size; - fl2 = fl->next; - HDassert(fl->size == H5HL_ALIGN(fl->size)); - while (fl2) { - if (fl->offset + fl->size == fl2->offset) { - fl->size += fl2->size; - HDassert(fl->size == H5HL_ALIGN(fl->size)); - fl2 = H5HL__remove_free(heap, fl2); - if (((fl->offset + fl->size) == heap->dblk_size) && ((2 * fl->size) > heap->dblk_size)) { - if (FAIL == H5HL__minimize_heap_space(f, heap)) - H5E_THROW(H5E_CANTFREE, "heap size minimization failed"); + else if (fl->offset + fl->size == offset) { + fl->size += size; + fl2 = fl->next; + HDassert(fl->size == H5HL_ALIGN(fl->size)); + while (fl2) { + if (fl->offset + fl->size == fl2->offset) { + fl->size += fl2->size; + HDassert(fl->size == H5HL_ALIGN(fl->size)); + fl2 = H5HL__remove_free(heap, fl2); + if (((fl->offset + fl->size) == heap->dblk_size) && ((2 * fl->size) > heap->dblk_size)) { + if (FAIL == H5HL__minimize_heap_space(f, heap)) + H5E_THROW(H5E_CANTFREE, "heap size minimization failed"); + } /* end if */ + H5_LEAVE(SUCCEED); } /* end if */ - H5_LEAVE(SUCCEED); + fl2 = fl2->next; + } /* end while */ + if (((fl->offset + fl->size) == heap->dblk_size) && ((2 * fl->size) > heap->dblk_size)) { + if (FAIL == H5HL__minimize_heap_space(f, heap)) + H5E_THROW(H5E_CANTFREE, "heap size minimization failed"); } /* end if */ - fl2 = fl2->next; - } /* end while */ - if (((fl->offset + fl->size) == heap->dblk_size) && ((2 * fl->size) > heap->dblk_size)) { - if (FAIL == H5HL__minimize_heap_space(f, heap)) - H5E_THROW(H5E_CANTFREE, "heap size minimization failed"); + H5_LEAVE(SUCCEED); } /* end if */ - H5_LEAVE(SUCCEED); - } /* end if */ - fl = fl->next; -} /* end while */ + fl = fl->next; + } /* end while */ -/* - * The amount which is being removed must be large enough to - * hold the free list data. If not, the freed chunk is forever - * lost. - */ -if (size < H5HL_SIZEOF_FREE(f)) { + /* + * The amount which is being removed must be large enough to + * hold the free list data. If not, the freed chunk is forever + * lost. + */ + if (size < H5HL_SIZEOF_FREE(f)) { #ifdef H5HL_DEBUG - if (H5DEBUG(HL)) { - HDfprintf(H5DEBUG(HL), "H5HL: lost %lu bytes\n", (unsigned long)size); - } + if (H5DEBUG(HL)) { + HDfprintf(H5DEBUG(HL), "H5HL: lost %lu bytes\n", (unsigned long)size); + } #endif - H5_LEAVE(SUCCEED); -} /* end if */ + H5_LEAVE(SUCCEED); + } /* end if */ -/* - * Add an entry to the free list. - */ -if (NULL == (fl = H5FL_MALLOC(H5HL_free_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); -fl->offset = offset; -fl->size = size; -HDassert(fl->offset == H5HL_ALIGN(fl->offset)); -HDassert(fl->size == H5HL_ALIGN(fl->size)); -fl->prev = NULL; -fl->next = heap->freelist; -if (heap->freelist) - heap->freelist->prev = fl; -heap->freelist = fl; - -if (((fl->offset + fl->size) == heap->dblk_size) && ((2 * fl->size) > heap->dblk_size)) - if (FAIL == H5HL__minimize_heap_space(f, heap)) - H5E_THROW(H5E_CANTFREE, "heap size minimization failed"); - -CATCH -/* No special processing on exit */ + /* + * Add an entry to the free list. + */ + if (NULL == (fl = H5FL_MALLOC(H5HL_free_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); + fl->offset = offset; + fl->size = size; + HDassert(fl->offset == H5HL_ALIGN(fl->offset)); + HDassert(fl->size == H5HL_ALIGN(fl->size)); + fl->prev = NULL; + fl->next = heap->freelist; + if (heap->freelist) + heap->freelist->prev = fl; + heap->freelist = fl; + + if (((fl->offset + fl->size) == heap->dblk_size) && ((2 * fl->size) > heap->dblk_size)) + if (FAIL == H5HL__minimize_heap_space(f, heap)) + H5E_THROW(H5E_CANTFREE, "heap size minimization failed"); + + CATCH + /* No special processing on exit */ END_FUNC(PRIV) /* end H5HL_remove() */ @@ -867,47 +869,48 @@ END_FUNC(PRIV) /* end H5HL_remove() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5HL_delete(H5F_t *f, haddr_t addr)) -H5HL_t * heap = NULL; /* Local heap to delete */ -H5HL_cache_prfx_ud_t prfx_udata; /* User data for protecting local heap prefix */ -H5HL_prfx_t * prfx = NULL; /* Local heap prefix */ -H5HL_dblk_t * dblk = NULL; /* Local heap data block */ -unsigned cache_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotecting heap */ + H5HL_t * heap = NULL; /* Local heap to delete */ + H5HL_cache_prfx_ud_t prfx_udata; /* User data for protecting local heap prefix */ + H5HL_prfx_t * prfx = NULL; /* Local heap prefix */ + H5HL_dblk_t * dblk = NULL; /* Local heap data block */ + unsigned cache_flags = H5AC__NO_FLAGS_SET; /* Flags for unprotecting heap */ -/* check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); + /* check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); -/* Construct the user data for protect callback */ -prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f); -prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f); -prfx_udata.prfx_addr = addr; -prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f); + /* Construct the user data for protect callback */ + prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f); + prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f); + prfx_udata.prfx_addr = addr; + prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f); -/* Protect the local heap prefix */ -if (NULL == (prfx = (H5HL_prfx_t *)H5AC_protect(f, H5AC_LHEAP_PRFX, addr, &prfx_udata, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTPROTECT, "unable to load heap prefix"); + /* Protect the local heap prefix */ + if (NULL == + (prfx = (H5HL_prfx_t *)H5AC_protect(f, H5AC_LHEAP_PRFX, addr, &prfx_udata, H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTPROTECT, "unable to load heap prefix"); -/* Get the pointer to the heap */ -heap = prfx->heap; + /* Get the pointer to the heap */ + heap = prfx->heap; -/* Check if heap has separate data block */ -if (!heap->single_cache_obj) - /* Protect the local heap data block */ - if (NULL == - (dblk = (H5HL_dblk_t *)H5AC_protect(f, H5AC_LHEAP_DBLK, heap->dblk_addr, heap, H5AC__NO_FLAGS_SET))) - H5E_THROW(H5E_CANTPROTECT, "unable to load heap data block"); + /* Check if heap has separate data block */ + if (!heap->single_cache_obj) + /* Protect the local heap data block */ + if (NULL == (dblk = (H5HL_dblk_t *)H5AC_protect(f, H5AC_LHEAP_DBLK, heap->dblk_addr, heap, + H5AC__NO_FLAGS_SET))) + H5E_THROW(H5E_CANTPROTECT, "unable to load heap data block"); -/* Set the flags for releasing the prefix and data block */ -cache_flags |= H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG; + /* Set the flags for releasing the prefix and data block */ + cache_flags |= H5AC__DIRTIED_FLAG | H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG; -CATCH -/* Release the data block from the cache, now deleted */ -if (dblk && heap && H5AC_unprotect(f, H5AC_LHEAP_DBLK, heap->dblk_addr, dblk, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap data block"); + CATCH + /* Release the data block from the cache, now deleted */ + if (dblk && heap && H5AC_unprotect(f, H5AC_LHEAP_DBLK, heap->dblk_addr, dblk, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap data block"); -/* Release the prefix from the cache, now deleted */ -if (prfx && heap && H5AC_unprotect(f, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, cache_flags) < 0) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap prefix"); + /* Release the prefix from the cache, now deleted */ + if (prfx && heap && H5AC_unprotect(f, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, cache_flags) < 0) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap prefix"); END_FUNC(PRIV) /* end H5HL_delete() */ @@ -925,34 +928,35 @@ END_FUNC(PRIV) /* end H5HL_delete() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5HL_get_size(H5F_t *f, haddr_t addr, size_t *size)) -H5HL_cache_prfx_ud_t prfx_udata; /* User data for protecting local heap prefix */ -H5HL_prfx_t * prfx = NULL; /* Local heap prefix */ -H5HL_t * heap; /* Heap data structure */ + H5HL_cache_prfx_ud_t prfx_udata; /* User data for protecting local heap prefix */ + H5HL_prfx_t * prfx = NULL; /* Local heap prefix */ + H5HL_t * heap; /* Heap data structure */ -/* check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); -HDassert(size); + /* check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + HDassert(size); -/* Construct the user data for protect callback */ -prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f); -prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f); -prfx_udata.prfx_addr = addr; -prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f); + /* Construct the user data for protect callback */ + prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f); + prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f); + prfx_udata.prfx_addr = addr; + prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f); -/* Protect the local heap prefix */ -if (NULL == (prfx = (H5HL_prfx_t *)H5AC_protect(f, H5AC_LHEAP_PRFX, addr, &prfx_udata, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load heap prefix"); + /* Protect the local heap prefix */ + if (NULL == + (prfx = (H5HL_prfx_t *)H5AC_protect(f, H5AC_LHEAP_PRFX, addr, &prfx_udata, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load heap prefix"); -/* Get the pointer to the heap */ -heap = prfx->heap; + /* Get the pointer to the heap */ + heap = prfx->heap; -/* Set the size to return */ -*size = heap->dblk_size; + /* Set the size to return */ + *size = heap->dblk_size; -CATCH -if (prfx && FAIL == H5AC_unprotect(f, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, H5AC__NO_FLAGS_SET)) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap prefix"); + CATCH + if (prfx && FAIL == H5AC_unprotect(f, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, H5AC__NO_FLAGS_SET)) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap prefix"); END_FUNC(PRIV) /* end H5HL_get_size() */ @@ -971,33 +975,34 @@ END_FUNC(PRIV) /* end H5HL_get_size() */ */ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5HL_heapsize(H5F_t *f, haddr_t addr, hsize_t *heap_size)) -H5HL_cache_prfx_ud_t prfx_udata; /* User data for protecting local heap prefix */ -H5HL_prfx_t * prfx = NULL; /* Local heap prefix */ -H5HL_t * heap; /* Heap data structure */ + H5HL_cache_prfx_ud_t prfx_udata; /* User data for protecting local heap prefix */ + H5HL_prfx_t * prfx = NULL; /* Local heap prefix */ + H5HL_t * heap; /* Heap data structure */ -/* check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); -HDassert(heap_size); + /* check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + HDassert(heap_size); -/* Construct the user data for protect callback */ -prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f); -prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f); -prfx_udata.prfx_addr = addr; -prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f); + /* Construct the user data for protect callback */ + prfx_udata.sizeof_size = H5F_SIZEOF_SIZE(f); + prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f); + prfx_udata.prfx_addr = addr; + prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f); -/* Protect the local heap prefix */ -if (NULL == (prfx = (H5HL_prfx_t *)H5AC_protect(f, H5AC_LHEAP_PRFX, addr, &prfx_udata, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load heap prefix"); + /* Protect the local heap prefix */ + if (NULL == + (prfx = (H5HL_prfx_t *)H5AC_protect(f, H5AC_LHEAP_PRFX, addr, &prfx_udata, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load heap prefix"); -/* Get the pointer to the heap */ -heap = prfx->heap; + /* Get the pointer to the heap */ + heap = prfx->heap; -/* Accumulate the size of the local heap */ -*heap_size += (hsize_t)(heap->prfx_size + heap->dblk_size); + /* Accumulate the size of the local heap */ + *heap_size += (hsize_t)(heap->prfx_size + heap->dblk_size); -CATCH -if (prfx && FAIL == H5AC_unprotect(f, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, H5AC__NO_FLAGS_SET)) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap prefix"); + CATCH + if (prfx && FAIL == H5AC_unprotect(f, H5AC_LHEAP_PRFX, heap->prfx_addr, prfx, H5AC__NO_FLAGS_SET)) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release local heap prefix"); END_FUNC(PRIV) /* end H5HL_heapsize() */ diff --git a/src/H5HLdbg.c b/src/H5HLdbg.c index 4638543..cf4c7dd 100644 --- a/src/H5HLdbg.c +++ b/src/H5HLdbg.c @@ -47,72 +47,72 @@ BEGIN_FUNC(PRIV, ERR, herr_t, SUCCEED, FAIL, H5HL_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth)) -H5HL_t * h = NULL; -int free_block; -H5HL_free_t *freelist; -uint8_t * marker = NULL; -size_t amount_free = 0; - -/* check arguments */ -HDassert(f); -HDassert(H5F_addr_defined(addr)); -HDassert(stream); -HDassert(indent >= 0); -HDassert(fwidth >= 0); - -if (NULL == (h = (H5HL_t *)H5HL_protect(f, addr, H5AC__READ_ONLY_FLAG))) - H5E_THROW(H5E_CANTPROTECT, "unable to load/protect local heap"); - -HDfprintf(stream, "%*sLocal Heap...\n", indent, ""); -HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, - "Header size (in bytes):", (unsigned long)h->prfx_size); -HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Address of heap data:", h->dblk_addr); -HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Data bytes allocated for heap:", h->dblk_size); - -/* Traverse the free list and check that all free blocks fall within - * the heap and that no two free blocks point to the same region of - * the heap. - */ -if (NULL == (marker = (uint8_t *)H5MM_calloc(h->dblk_size))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); - -HDfprintf(stream, "%*sFree Blocks (offset, size):\n", indent, ""); -for (free_block = 0, freelist = h->freelist; freelist; freelist = freelist->next, free_block++) { - char temp_str[32]; - - HDsnprintf(temp_str, sizeof(temp_str), "Block #%d:", free_block); - HDfprintf(stream, "%*s%-*s %8Zu, %8Zu\n", indent + 3, "", MAX(0, fwidth - 9), temp_str, freelist->offset, - freelist->size); - if ((freelist->offset + freelist->size) > h->dblk_size) - HDfprintf(stream, "***THAT FREE BLOCK IS OUT OF BOUNDS!\n"); - else { - int overlap = 0; - size_t i; - - for (i = 0; i < freelist->size; i++) { - if (marker[freelist->offset + i]) - overlap++; - marker[freelist->offset + i] = 1; - } /* end for */ - if (overlap) - HDfprintf(stream, "***THAT FREE BLOCK OVERLAPPED A PREVIOUS ONE!\n"); - else - amount_free += freelist->size; - } /* end else */ -} /* end for */ - -if (h->dblk_size) - HDfprintf(stream, "%*s%-*s %.2f%%\n", indent, "", fwidth, "Percent of heap used:", - ((double)100.0f * (double)(h->dblk_size - amount_free) / (double)h->dblk_size)); - -/* Print the data in a VMS-style octal dump */ -H5_buffer_dump(stream, indent, h->dblk_image, marker, (size_t)0, h->dblk_size); - -CATCH -if (h && FAIL == H5HL_unprotect(h)) - H5E_THROW(H5E_CANTUNPROTECT, "unable to release/unprotect local heap"); - -if (marker && NULL != (marker = (uint8_t *)H5MM_xfree(marker))) - H5E_THROW(H5E_CANTFREE, "can't free marker buffer"); + H5HL_t * h = NULL; + int free_block; + H5HL_free_t *freelist; + uint8_t * marker = NULL; + size_t amount_free = 0; + + /* check arguments */ + HDassert(f); + HDassert(H5F_addr_defined(addr)); + HDassert(stream); + HDassert(indent >= 0); + HDassert(fwidth >= 0); + + if (NULL == (h = (H5HL_t *)H5HL_protect(f, addr, H5AC__READ_ONLY_FLAG))) + H5E_THROW(H5E_CANTPROTECT, "unable to load/protect local heap"); + + HDfprintf(stream, "%*sLocal Heap...\n", indent, ""); + HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, + "Header size (in bytes):", (unsigned long)h->prfx_size); + HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Address of heap data:", h->dblk_addr); + HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth, "Data bytes allocated for heap:", h->dblk_size); + + /* Traverse the free list and check that all free blocks fall within + * the heap and that no two free blocks point to the same region of + * the heap. + */ + if (NULL == (marker = (uint8_t *)H5MM_calloc(h->dblk_size))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); + + HDfprintf(stream, "%*sFree Blocks (offset, size):\n", indent, ""); + for (free_block = 0, freelist = h->freelist; freelist; freelist = freelist->next, free_block++) { + char temp_str[32]; + + HDsnprintf(temp_str, sizeof(temp_str), "Block #%d:", free_block); + HDfprintf(stream, "%*s%-*s %8Zu, %8Zu\n", indent + 3, "", MAX(0, fwidth - 9), temp_str, + freelist->offset, freelist->size); + if ((freelist->offset + freelist->size) > h->dblk_size) + HDfprintf(stream, "***THAT FREE BLOCK IS OUT OF BOUNDS!\n"); + else { + int overlap = 0; + size_t i; + + for (i = 0; i < freelist->size; i++) { + if (marker[freelist->offset + i]) + overlap++; + marker[freelist->offset + i] = 1; + } /* end for */ + if (overlap) + HDfprintf(stream, "***THAT FREE BLOCK OVERLAPPED A PREVIOUS ONE!\n"); + else + amount_free += freelist->size; + } /* end else */ + } /* end for */ + + if (h->dblk_size) + HDfprintf(stream, "%*s%-*s %.2f%%\n", indent, "", fwidth, "Percent of heap used:", + ((double)100.0f * (double)(h->dblk_size - amount_free) / (double)h->dblk_size)); + + /* Print the data in a VMS-style octal dump */ + H5_buffer_dump(stream, indent, h->dblk_image, marker, (size_t)0, h->dblk_size); + + CATCH + if (h && FAIL == H5HL_unprotect(h)) + H5E_THROW(H5E_CANTUNPROTECT, "unable to release/unprotect local heap"); + + if (marker && NULL != (marker = (uint8_t *)H5MM_xfree(marker))) + H5E_THROW(H5E_CANTFREE, "can't free marker buffer"); END_FUNC(PRIV) /* end H5HL_debug() */ diff --git a/src/H5HLdblk.c b/src/H5HLdblk.c index 8c4f447..0081a47 100644 --- a/src/H5HLdblk.c +++ b/src/H5HLdblk.c @@ -83,31 +83,31 @@ H5FL_DEFINE_STATIC(H5HL_dblk_t); */ BEGIN_FUNC(PKG, ERR, H5HL_dblk_t *, NULL, NULL, H5HL__dblk_new(H5HL_t *heap)) -H5HL_dblk_t *dblk = NULL; /* New local heap data block */ + H5HL_dblk_t *dblk = NULL; /* New local heap data block */ -/* check arguments */ -HDassert(heap); + /* check arguments */ + HDassert(heap); -/* Allocate new local heap data block */ -if (NULL == (dblk = H5FL_CALLOC(H5HL_dblk_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for local heap data block") + /* Allocate new local heap data block */ + if (NULL == (dblk = H5FL_CALLOC(H5HL_dblk_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for local heap data block") -/* Increment ref. count on heap data structure */ -if (FAIL == H5HL__inc_rc(heap)) - H5E_THROW(H5E_CANTINC, "can't increment heap ref. count") + /* Increment ref. count on heap data structure */ + if (FAIL == H5HL__inc_rc(heap)) + H5E_THROW(H5E_CANTINC, "can't increment heap ref. count") -/* Link the heap & the data block */ -dblk->heap = heap; -heap->dblk = dblk; + /* Link the heap & the data block */ + dblk->heap = heap; + heap->dblk = dblk; -/* Set the return value */ -ret_value = dblk; + /* Set the return value */ + ret_value = dblk; -CATCH -/* Ensure that the data block memory is deallocated on errors */ -if (!ret_value && dblk != NULL) - /* H5FL_FREE always returns NULL so we can't check for errors */ - dblk = H5FL_FREE(H5HL_dblk_t, dblk); + CATCH + /* Ensure that the data block memory is deallocated on errors */ + if (!ret_value && dblk != NULL) + /* H5FL_FREE always returns NULL so we can't check for errors */ + dblk = H5FL_FREE(H5HL_dblk_t, dblk); END_FUNC(PKG) /* end H5HL__dblk_new() */ @@ -125,26 +125,26 @@ END_FUNC(PKG) /* end H5HL__dblk_new() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5HL__dblk_dest(H5HL_dblk_t *dblk)) -/* check arguments */ -HDassert(dblk); + /* check arguments */ + HDassert(dblk); -/* Check if data block was initialized */ -if (dblk->heap) { - /* Unlink data block from heap */ - dblk->heap->dblk = NULL; + /* Check if data block was initialized */ + if (dblk->heap) { + /* Unlink data block from heap */ + dblk->heap->dblk = NULL; - /* Decrement ref. count on heap data structure */ - if (FAIL == H5HL__dec_rc(dblk->heap)) - H5E_THROW(H5E_CANTDEC, "can't decrement heap ref. count") + /* Decrement ref. count on heap data structure */ + if (FAIL == H5HL__dec_rc(dblk->heap)) + H5E_THROW(H5E_CANTDEC, "can't decrement heap ref. count") - /* Unlink heap from data block */ - dblk->heap = NULL; -} /* end if */ + /* Unlink heap from data block */ + dblk->heap = NULL; + } /* end if */ -CATCH -/* Free local heap data block */ -/* H5FL_FREE always returns NULL so we can't check for errors */ -dblk = H5FL_FREE(H5HL_dblk_t, dblk); + CATCH + /* Free local heap data block */ + /* H5FL_FREE always returns NULL so we can't check for errors */ + dblk = H5FL_FREE(H5HL_dblk_t, dblk); END_FUNC(PKG) /* end H5HL__dblk_dest() */ @@ -162,94 +162,94 @@ END_FUNC(PKG) /* end H5HL__dblk_dest() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5HL__dblk_realloc(H5F_t *f, H5HL_t *heap, size_t new_heap_size)) -H5HL_dblk_t *dblk; /* Local heap data block */ -haddr_t old_addr; /* Old location of heap data block */ -haddr_t new_addr; /* New location of heap data block */ -size_t old_heap_size; /* Old size of heap data block */ - -/* check arguments */ -HDassert(heap); -HDassert(new_heap_size > 0); - -/* Release old space on disk */ -old_addr = heap->dblk_addr; -old_heap_size = heap->dblk_size; -H5_CHECK_OVERFLOW(old_heap_size, size_t, hsize_t); -if (FAIL == H5MF_xfree(f, H5FD_MEM_LHEAP, old_addr, (hsize_t)old_heap_size)) - H5E_THROW(H5E_CANTFREE, "can't free old local heap data"); - -/* Allocate new space on disk */ -H5_CHECK_OVERFLOW(new_heap_size, size_t, hsize_t); -if (HADDR_UNDEF == (new_addr = H5MF_alloc(f, H5FD_MEM_LHEAP, (hsize_t)new_heap_size))) - H5E_THROW(H5E_CANTALLOC, "unable to allocate file space for local heap"); - -/* Update heap info*/ -heap->dblk_addr = new_addr; -heap->dblk_size = new_heap_size; - -/* Check if heap data block actually moved in the file */ -if (H5F_addr_eq(old_addr, new_addr)) { - /* Check if heap data block is contiguous w/prefix */ - if (heap->single_cache_obj) { - /* Sanity check */ - HDassert(H5F_addr_eq(heap->prfx_addr + heap->prfx_size, old_addr)); - HDassert(heap->prfx); - - /* Resize the heap prefix in the cache */ - if (FAIL == H5AC_resize_entry(heap->prfx, (size_t)(heap->prfx_size + new_heap_size))) - H5E_THROW(H5E_CANTRESIZE, "unable to resize heap in cache"); - } /* end if */ + H5HL_dblk_t *dblk; /* Local heap data block */ + haddr_t old_addr; /* Old location of heap data block */ + haddr_t new_addr; /* New location of heap data block */ + size_t old_heap_size; /* Old size of heap data block */ + + /* check arguments */ + HDassert(heap); + HDassert(new_heap_size > 0); + + /* Release old space on disk */ + old_addr = heap->dblk_addr; + old_heap_size = heap->dblk_size; + H5_CHECK_OVERFLOW(old_heap_size, size_t, hsize_t); + if (FAIL == H5MF_xfree(f, H5FD_MEM_LHEAP, old_addr, (hsize_t)old_heap_size)) + H5E_THROW(H5E_CANTFREE, "can't free old local heap data"); + + /* Allocate new space on disk */ + H5_CHECK_OVERFLOW(new_heap_size, size_t, hsize_t); + if (HADDR_UNDEF == (new_addr = H5MF_alloc(f, H5FD_MEM_LHEAP, (hsize_t)new_heap_size))) + H5E_THROW(H5E_CANTALLOC, "unable to allocate file space for local heap"); + + /* Update heap info*/ + heap->dblk_addr = new_addr; + heap->dblk_size = new_heap_size; + + /* Check if heap data block actually moved in the file */ + if (H5F_addr_eq(old_addr, new_addr)) { + /* Check if heap data block is contiguous w/prefix */ + if (heap->single_cache_obj) { + /* Sanity check */ + HDassert(H5F_addr_eq(heap->prfx_addr + heap->prfx_size, old_addr)); + HDassert(heap->prfx); + + /* Resize the heap prefix in the cache */ + if (FAIL == H5AC_resize_entry(heap->prfx, (size_t)(heap->prfx_size + new_heap_size))) + H5E_THROW(H5E_CANTRESIZE, "unable to resize heap in cache"); + } /* end if */ + else { + /* Sanity check */ + HDassert(H5F_addr_ne(heap->prfx_addr + heap->prfx_size, old_addr)); + HDassert(heap->dblk); + + /* Resize the heap data block in the cache */ + if (H5AC_resize_entry(heap->dblk, (size_t)new_heap_size) < 0) + H5E_THROW(H5E_CANTRESIZE, "unable to resize heap (data block) in cache"); + } /* end else */ + } /* end if */ else { - /* Sanity check */ - HDassert(H5F_addr_ne(heap->prfx_addr + heap->prfx_size, old_addr)); - HDassert(heap->dblk); - - /* Resize the heap data block in the cache */ - if (H5AC_resize_entry(heap->dblk, (size_t)new_heap_size) < 0) - H5E_THROW(H5E_CANTRESIZE, "unable to resize heap (data block) in cache"); - } /* end else */ -} /* end if */ -else { - /* Check if heap data block was contiguous w/prefix previously */ - if (heap->single_cache_obj) { - /* Create new heap data block */ - if (NULL == (dblk = H5HL__dblk_new(heap))) - H5E_THROW(H5E_CANTALLOC, "unable to allocate local heap data block"); - - /* Resize current heap prefix */ - heap->prfx_size = H5HL_SIZEOF_HDR(f); - if (FAIL == H5AC_resize_entry(heap->prfx, (size_t)heap->prfx_size)) - H5E_THROW(H5E_CANTRESIZE, "unable to resize heap prefix in cache"); - - /* Insert data block into cache (pinned) */ - if (FAIL == H5AC_insert_entry(f, H5AC_LHEAP_DBLK, new_addr, dblk, H5AC__PIN_ENTRY_FLAG)) - H5E_THROW(H5E_CANTINIT, "unable to cache local heap data block"); - - dblk = NULL; - - /* Reset 'single cache object' flag */ - heap->single_cache_obj = FALSE; + /* Check if heap data block was contiguous w/prefix previously */ + if (heap->single_cache_obj) { + /* Create new heap data block */ + if (NULL == (dblk = H5HL__dblk_new(heap))) + H5E_THROW(H5E_CANTALLOC, "unable to allocate local heap data block"); + + /* Resize current heap prefix */ + heap->prfx_size = H5HL_SIZEOF_HDR(f); + if (FAIL == H5AC_resize_entry(heap->prfx, (size_t)heap->prfx_size)) + H5E_THROW(H5E_CANTRESIZE, "unable to resize heap prefix in cache"); + + /* Insert data block into cache (pinned) */ + if (FAIL == H5AC_insert_entry(f, H5AC_LHEAP_DBLK, new_addr, dblk, H5AC__PIN_ENTRY_FLAG)) + H5E_THROW(H5E_CANTINIT, "unable to cache local heap data block"); + + dblk = NULL; + + /* Reset 'single cache object' flag */ + heap->single_cache_obj = FALSE; + } /* end if */ + else { + /* Resize the heap data block in the cache */ + /* (ignore [unlikely] case where heap data block ends up + * contiguous w/heap prefix again. + */ + if (FAIL == H5AC_resize_entry(heap->dblk, (size_t)new_heap_size)) + H5E_THROW(H5E_CANTRESIZE, "unable to resize heap data block in cache"); + + /* Relocate the heap data block in the cache */ + if (FAIL == H5AC_move_entry(f, H5AC_LHEAP_DBLK, old_addr, new_addr)) + H5E_THROW(H5E_CANTMOVE, "unable to move heap data block in cache"); + + } /* end else */ + } /* end else */ + + CATCH + /* Restore old heap address & size on errors */ + if (FAIL == ret_value) { + heap->dblk_addr = old_addr; + heap->dblk_size = old_heap_size; } /* end if */ - else { - /* Resize the heap data block in the cache */ - /* (ignore [unlikely] case where heap data block ends up - * contiguous w/heap prefix again. - */ - if (FAIL == H5AC_resize_entry(heap->dblk, (size_t)new_heap_size)) - H5E_THROW(H5E_CANTRESIZE, "unable to resize heap data block in cache"); - - /* Relocate the heap data block in the cache */ - if (FAIL == H5AC_move_entry(f, H5AC_LHEAP_DBLK, old_addr, new_addr)) - H5E_THROW(H5E_CANTMOVE, "unable to move heap data block in cache"); - - } /* end else */ -} /* end else */ - -CATCH -/* Restore old heap address & size on errors */ -if (FAIL == ret_value) { - heap->dblk_addr = old_addr; - heap->dblk_size = old_heap_size; -} /* end if */ END_FUNC(PKG) /* end H5HL__dblk_realloc() */ diff --git a/src/H5HLint.c b/src/H5HLint.c index 9b6667f..ef5c712 100644 --- a/src/H5HLint.c +++ b/src/H5HLint.c @@ -83,29 +83,29 @@ H5FL_DEFINE_STATIC(H5HL_t); BEGIN_FUNC(PKG, ERR, H5HL_t *, NULL, NULL, H5HL__new(size_t sizeof_size, size_t sizeof_addr, size_t prfx_size)) -H5HL_t *heap = NULL; /* New local heap */ + H5HL_t *heap = NULL; /* New local heap */ -/* check arguments */ -HDassert(sizeof_size > 0); -HDassert(sizeof_addr > 0); -HDassert(prfx_size > 0); + /* check arguments */ + HDassert(sizeof_size > 0); + HDassert(sizeof_addr > 0); + HDassert(prfx_size > 0); -/* Allocate new local heap structure */ -if (NULL == (heap = H5FL_CALLOC(H5HL_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); + /* Allocate new local heap structure */ + if (NULL == (heap = H5FL_CALLOC(H5HL_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed"); -/* Initialize non-zero fields */ -heap->sizeof_size = sizeof_size; -heap->sizeof_addr = sizeof_addr; -heap->prfx_size = prfx_size; + /* Initialize non-zero fields */ + heap->sizeof_size = sizeof_size; + heap->sizeof_addr = sizeof_addr; + heap->prfx_size = prfx_size; -/* Set the return value */ -ret_value = heap; + /* Set the return value */ + ret_value = heap; -CATCH -if (!ret_value && heap != NULL) - if (NULL == (heap = H5FL_FREE(H5HL_t, heap))) - H5E_THROW(H5E_CANTFREE, "can't free heap memory"); + CATCH + if (!ret_value && heap != NULL) + if (NULL == (heap = H5FL_FREE(H5HL_t, heap))) + H5E_THROW(H5E_CANTFREE, "can't free heap memory"); END_FUNC(PKG) /* end H5HL__new() */ @@ -123,11 +123,11 @@ END_FUNC(PKG) /* end H5HL__new() */ */ BEGIN_FUNC(PKG, NOERR, herr_t, SUCCEED, -, H5HL__inc_rc(H5HL_t *heap)) -/* check arguments */ -HDassert(heap); + /* check arguments */ + HDassert(heap); -/* Increment heap's ref. count */ -heap->rc++; + /* Increment heap's ref. count */ + heap->rc++; END_FUNC(PKG) /* end H5HL__inc_rc() */ @@ -145,16 +145,16 @@ END_FUNC(PKG) /* end H5HL__inc_rc() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5HL__dec_rc(H5HL_t *heap)) -/* check arguments */ -HDassert(heap); + /* check arguments */ + HDassert(heap); -/* Decrement heap's ref. count */ -heap->rc--; + /* Decrement heap's ref. count */ + heap->rc--; -CATCH -/* Check if we should destroy the heap */ -if (heap->rc == 0 && FAIL == H5HL__dest(heap)) - H5E_THROW(H5E_CANTFREE, "unable to destroy local heap"); + CATCH + /* Check if we should destroy the heap */ + if (heap->rc == 0 && FAIL == H5HL__dest(heap)) + H5E_THROW(H5E_CANTFREE, "unable to destroy local heap"); END_FUNC(PKG) /* end H5HL__dec_rc() */ @@ -172,29 +172,29 @@ END_FUNC(PKG) /* end H5HL__dec_rc() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5HL__dest(H5HL_t *heap)) -/* check arguments */ -HDassert(heap); - -/* Verify that node is unused */ -HDassert(heap->prots == 0); -HDassert(heap->rc == 0); -HDassert(heap->prfx == NULL); -HDassert(heap->dblk == NULL); - -CATCH -if (heap->dblk_image) - if (NULL != (heap->dblk_image = H5FL_BLK_FREE(lheap_chunk, heap->dblk_image))) - H5E_THROW(H5E_CANTFREE, "unable to free local heap data block image"); -while (heap->freelist) { - H5HL_free_t *fl; - - fl = heap->freelist; - heap->freelist = fl->next; - if (NULL != (fl = H5FL_FREE(H5HL_free_t, fl))) - H5E_THROW(H5E_CANTFREE, "unable to free local heap free list"); -} /* end while */ - -if (NULL != (heap = H5FL_FREE(H5HL_t, heap))) - H5E_THROW(H5E_CANTFREE, "unable to free local heap"); + /* check arguments */ + HDassert(heap); + + /* Verify that node is unused */ + HDassert(heap->prots == 0); + HDassert(heap->rc == 0); + HDassert(heap->prfx == NULL); + HDassert(heap->dblk == NULL); + + CATCH + if (heap->dblk_image) + if (NULL != (heap->dblk_image = H5FL_BLK_FREE(lheap_chunk, heap->dblk_image))) + H5E_THROW(H5E_CANTFREE, "unable to free local heap data block image"); + while (heap->freelist) { + H5HL_free_t *fl; + + fl = heap->freelist; + heap->freelist = fl->next; + if (NULL != (fl = H5FL_FREE(H5HL_free_t, fl))) + H5E_THROW(H5E_CANTFREE, "unable to free local heap free list"); + } /* end while */ + + if (NULL != (heap = H5FL_FREE(H5HL_t, heap))) + H5E_THROW(H5E_CANTFREE, "unable to free local heap"); END_FUNC(PKG) /* end H5HL__dest() */ diff --git a/src/H5HLprfx.c b/src/H5HLprfx.c index d17e558..fedc11b 100644 --- a/src/H5HLprfx.c +++ b/src/H5HLprfx.c @@ -82,31 +82,31 @@ H5FL_DEFINE_STATIC(H5HL_prfx_t); */ BEGIN_FUNC(PKG, ERR, H5HL_prfx_t *, NULL, NULL, H5HL__prfx_new(H5HL_t *heap)) -H5HL_prfx_t *prfx = NULL; /* New local heap prefix */ + H5HL_prfx_t *prfx = NULL; /* New local heap prefix */ -/* check arguments */ -HDassert(heap); + /* check arguments */ + HDassert(heap); -/* Allocate new local heap prefix */ -if (NULL == (prfx = H5FL_CALLOC(H5HL_prfx_t))) - H5E_THROW(H5E_CANTALLOC, "memory allocation failed for local heap prefix") + /* Allocate new local heap prefix */ + if (NULL == (prfx = H5FL_CALLOC(H5HL_prfx_t))) + H5E_THROW(H5E_CANTALLOC, "memory allocation failed for local heap prefix") -/* Increment ref. count on heap data structure */ -if (FAIL == H5HL__inc_rc(heap)) - H5E_THROW(H5E_CANTINC, "can't increment heap ref. count") + /* Increment ref. count on heap data structure */ + if (FAIL == H5HL__inc_rc(heap)) + H5E_THROW(H5E_CANTINC, "can't increment heap ref. count") -/* Link the heap & the prefix */ -prfx->heap = heap; -heap->prfx = prfx; + /* Link the heap & the prefix */ + prfx->heap = heap; + heap->prfx = prfx; -/* Set the return value */ -ret_value = prfx; + /* Set the return value */ + ret_value = prfx; -CATCH -/* Ensure that the prefix memory is deallocated on errors */ -if (!ret_value && prfx != NULL) - /* H5FL_FREE always returns NULL so we can't check for errors */ - prfx = H5FL_FREE(H5HL_prfx_t, prfx); + CATCH + /* Ensure that the prefix memory is deallocated on errors */ + if (!ret_value && prfx != NULL) + /* H5FL_FREE always returns NULL so we can't check for errors */ + prfx = H5FL_FREE(H5HL_prfx_t, prfx); END_FUNC(PKG) /* end H5HL__prfx_new() */ @@ -124,25 +124,25 @@ END_FUNC(PKG) /* end H5HL__prfx_new() */ */ BEGIN_FUNC(PKG, ERR, herr_t, SUCCEED, FAIL, H5HL__prfx_dest(H5HL_prfx_t *prfx)) -/* check arguments */ -HDassert(prfx); + /* check arguments */ + HDassert(prfx); -/* Check if prefix was initialized */ -if (prfx->heap) { - /* Unlink prefix from heap */ - prfx->heap->prfx = NULL; + /* Check if prefix was initialized */ + if (prfx->heap) { + /* Unlink prefix from heap */ + prfx->heap->prfx = NULL; - /* Decrement ref. count on heap data structure */ - if (FAIL == H5HL__dec_rc(prfx->heap)) - H5E_THROW(H5E_CANTDEC, "can't decrement heap ref. count") + /* Decrement ref. count on heap data structure */ + if (FAIL == H5HL__dec_rc(prfx->heap)) + H5E_THROW(H5E_CANTDEC, "can't decrement heap ref. count") - /* Unlink heap from prefix */ - prfx->heap = NULL; -} /* end if */ + /* Unlink heap from prefix */ + prfx->heap = NULL; + } /* end if */ -CATCH -/* Free prefix memory */ -/* H5FL_FREE always returns NULL so we can't check for errors */ -prfx = H5FL_FREE(H5HL_prfx_t, prfx); + CATCH + /* Free prefix memory */ + /* H5FL_FREE always returns NULL so we can't check for errors */ + prfx = H5FL_FREE(H5HL_prfx_t, prfx); END_FUNC(PKG) /* end H5HL__prfx_dest() */ |