diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2020-10-01 16:47:45 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2020-10-01 16:47:45 (GMT) |
commit | 1ba1f2f3222cbe8df0bf601929a4bffd478d7e02 (patch) | |
tree | ae51dfc33cf40432dad25a5088767115a98f195e /src/H5Gent.c | |
parent | 8eef7d295cc3dd134aef0a826f1de4287629996d (diff) | |
download | hdf5-1ba1f2f3222cbe8df0bf601929a4bffd478d7e02.zip hdf5-1ba1f2f3222cbe8df0bf601929a4bffd478d7e02.tar.gz hdf5-1ba1f2f3222cbe8df0bf601929a4bffd478d7e02.tar.bz2 |
Source formatted
Diffstat (limited to 'src/H5Gent.c')
-rw-r--r-- | src/H5Gent.c | 206 |
1 files changed, 87 insertions, 119 deletions
diff --git a/src/H5Gent.c b/src/H5Gent.c index 1bd8e63..641e9ef 100644 --- a/src/H5Gent.c +++ b/src/H5Gent.c @@ -20,40 +20,34 @@ /* Module Setup */ /****************/ -#define H5G_PACKAGE /*suppress error about including H5Gpkg */ - +#define H5G_PACKAGE /*suppress error about including H5Gpkg */ /***********/ /* Headers */ /***********/ -#include "H5private.h" /* Generic Functions */ -#include "H5Eprivate.h" /* Error handling */ -#include "H5Fprivate.h" /* File access */ -#include "H5FLprivate.h" /* Free Lists */ -#include "H5Gpkg.h" /* Groups */ -#include "H5HLprivate.h" /* Local Heaps */ - +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5Fprivate.h" /* File access */ +#include "H5FLprivate.h" /* Free Lists */ +#include "H5Gpkg.h" /* Groups */ +#include "H5HLprivate.h" /* Local Heaps */ /****************/ /* Local Macros */ /****************/ - /******************/ /* Local Typedefs */ /******************/ - /********************/ /* Package Typedefs */ /********************/ - /********************/ /* Local Prototypes */ /********************/ - /*********************/ /* Package Variables */ /*********************/ @@ -61,18 +55,14 @@ /* Declare extern the PQ free list for the wrapped strings */ H5FL_BLK_EXTERN(str_buf); - /*****************************/ /* Library Private Variables */ /*****************************/ - /*******************/ /* Local Variables */ /*******************/ - - /*------------------------------------------------------------------------- * Function: H5G__ent_decode_vec * @@ -91,11 +81,10 @@ H5FL_BLK_EXTERN(str_buf); *------------------------------------------------------------------------- */ herr_t -H5G__ent_decode_vec(const H5F_t *f, const uint8_t **pp, const uint8_t *p_end, - H5G_entry_t *ent, unsigned n) +H5G__ent_decode_vec(const H5F_t *f, const uint8_t **pp, const uint8_t *p_end, H5G_entry_t *ent, unsigned n) { - unsigned u; /* Local index variable */ - herr_t ret_value = SUCCEED; /* Return value */ + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -105,10 +94,10 @@ H5G__ent_decode_vec(const H5F_t *f, const uint8_t **pp, const uint8_t *p_end, HDassert(ent); /* decode entries */ - for(u = 0; u < n; u++) { - if(*pp > p_end) + for (u = 0; u < n; u++) { + if (*pp > p_end) HGOTO_ERROR(H5E_SYM, H5E_CANTDECODE, FAIL, "ran off the end of the buffer") - if(H5G_ent_decode(f, pp, ent + u) < 0) + if (H5G_ent_decode(f, pp, ent + u) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTDECODE, FAIL, "can't decode") } @@ -116,7 +105,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5G__ent_decode_vec() */ - /*------------------------------------------------------------------------- * Function: H5G_ent_decode * @@ -136,9 +124,9 @@ done: herr_t H5G_ent_decode(const H5F_t *f, const uint8_t **pp, H5G_entry_t *ent) { - const uint8_t *p_ret = *pp; - uint32_t tmp; - herr_t ret_value = SUCCEED; /* Return value */ + const uint8_t *p_ret = *pp; + uint32_t tmp; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -155,7 +143,7 @@ H5G_ent_decode(const H5F_t *f, const uint8_t **pp, H5G_entry_t *ent) ent->type = (H5G_cache_type_t)tmp; /* decode scratch-pad */ - switch(ent->type) { + switch (ent->type) { case H5G_NOTHING_CACHED: break; @@ -181,7 +169,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5G_ent_decode() */ - /*------------------------------------------------------------------------- * Function: H5G__ent_encode_vec * @@ -202,8 +189,8 @@ done: herr_t H5G__ent_encode_vec(const H5F_t *f, uint8_t **pp, const H5G_entry_t *ent, unsigned n) { - unsigned u; /* Local index variable */ - herr_t ret_value = SUCCEED; /* Return value */ + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -213,15 +200,14 @@ H5G__ent_encode_vec(const H5F_t *f, uint8_t **pp, const H5G_entry_t *ent, unsign HDassert(ent); /* encode entries */ - for(u = 0; u < n; u++) - if(H5G_ent_encode(f, pp, ent + u) < 0) + for (u = 0; u < n; u++) + if (H5G_ent_encode(f, pp, ent + u) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTENCODE, FAIL, "can't encode") done: FUNC_LEAVE_NOAPI(ret_value) } /* H5G__ent_encode_vec() */ - /*------------------------------------------------------------------------- * Function: H5G_ent_encode * @@ -242,8 +228,8 @@ done: herr_t H5G_ent_encode(const H5F_t *f, uint8_t **pp, const H5G_entry_t *ent) { - uint8_t *p_ret = *pp + H5G_SIZEOF_ENTRY(f); - herr_t ret_value = SUCCEED; /* Return value */ + uint8_t *p_ret = *pp + H5G_SIZEOF_ENTRY(f); + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -252,15 +238,15 @@ H5G_ent_encode(const H5F_t *f, uint8_t **pp, const H5G_entry_t *ent) HDassert(pp); /* Check for actual entry to encode */ - if(ent) { + if (ent) { /* encode header */ H5F_ENCODE_LENGTH(f, *pp, ent->name_off); H5F_addr_encode(f, pp, ent->header); UINT32ENCODE(*pp, ent->type); - UINT32ENCODE(*pp, 0); /*reserved*/ + UINT32ENCODE(*pp, 0); /*reserved*/ /* encode scratch-pad */ - switch(ent->type) { + switch (ent->type) { case H5G_NOTHING_CACHED: break; @@ -279,16 +265,16 @@ H5G_ent_encode(const H5F_t *f, uint8_t **pp, const H5G_entry_t *ent) default: HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "unknown symbol table entry cache type") } /* end switch */ - } /* end if */ + } /* end if */ else { H5F_ENCODE_LENGTH(f, *pp, 0); H5F_addr_encode(f, pp, HADDR_UNDEF); UINT32ENCODE(*pp, H5G_NOTHING_CACHED); - UINT32ENCODE(*pp, 0); /*reserved*/ - } /* end else */ + UINT32ENCODE(*pp, 0); /*reserved*/ + } /* end else */ /* fill with zero */ - if(*pp < p_ret) + if (*pp < p_ret) HDmemset(*pp, 0, (size_t)(p_ret - *pp)); *pp = p_ret; @@ -296,7 +282,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5G_ent_encode() */ - /*------------------------------------------------------------------------- * Function: H5G__ent_copy * @@ -335,10 +320,11 @@ H5G__ent_copy(H5G_entry_t *dst, const H5G_entry_t *src, H5_copy_depth_t depth) HDmemcpy(dst, src, sizeof(H5G_entry_t)); /* Deep copy the names */ - if(depth == H5_COPY_DEEP) { + if (depth == H5_COPY_DEEP) { /* Nothing currently */ ; - } else if(depth == H5_COPY_SHALLOW) { + } + else if (depth == H5_COPY_SHALLOW) { /* Discarding 'const' qualifier OK - QAK */ H5G__ent_reset((H5G_entry_t *)src); } /* end if */ @@ -346,7 +332,6 @@ H5G__ent_copy(H5G_entry_t *dst, const H5G_entry_t *src, H5_copy_depth_t depth) FUNC_LEAVE_NOAPI_VOID } /* end H5G__ent_copy() */ - /*------------------------------------------------------------------------- * Function: H5G__ent_reset * @@ -375,7 +360,6 @@ H5G__ent_reset(H5G_entry_t *ent) FUNC_LEAVE_NOAPI_VOID } /* end H5G__ent_reset() */ - /*------------------------------------------------------------------------- * Function: H5G__ent_convert * @@ -391,12 +375,11 @@ H5G__ent_reset(H5G_entry_t *ent) *------------------------------------------------------------------------- */ herr_t -H5G__ent_convert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, const char *name, - const H5O_link_t *lnk, H5O_type_t obj_type, const void *crt_info, - H5G_entry_t *ent) +H5G__ent_convert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, const char *name, const H5O_link_t *lnk, + H5O_type_t obj_type, const void *crt_info, H5G_entry_t *ent) { - size_t name_offset; /* Offset of name in heap */ - herr_t ret_value = SUCCEED; /* Return value */ + size_t name_offset; /* Offset of name in heap */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -413,87 +396,82 @@ H5G__ent_convert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, const char *name, * Add the new name to the heap. */ name_offset = H5HL_insert(f, dxpl_id, heap, HDstrlen(name) + 1, name); - if(0 == name_offset || (size_t)(-1) == name_offset) - HGOTO_ERROR(H5E_SYM, H5E_CANTINSERT, FAIL, "unable to insert symbol name into heap") + if (0 == name_offset || (size_t)(-1) == name_offset) + HGOTO_ERROR(H5E_SYM, H5E_CANTINSERT, FAIL, "unable to insert symbol name into heap") ent->name_off = name_offset; /* Build correct information for symbol table entry based on link type */ - switch(lnk->type) { + switch (lnk->type) { case H5L_TYPE_HARD: - if(obj_type == H5O_TYPE_GROUP) { + if (obj_type == H5O_TYPE_GROUP) { const H5G_obj_create_t *gcrt_info = (const H5G_obj_create_t *)crt_info; ent->type = gcrt_info->cache_type; - if(ent->type != H5G_NOTHING_CACHED) + if (ent->type != H5G_NOTHING_CACHED) ent->cache = gcrt_info->cache; #ifndef NDEBUG else { /* Make sure there is no stab message in the target object */ - H5O_loc_t targ_oloc; /* Location of link target */ - htri_t stab_exists; /* Whether the target symbol table exists */ + H5O_loc_t targ_oloc; /* Location of link target */ + htri_t stab_exists; /* Whether the target symbol table exists */ /* Build target object location */ - if(H5O_loc_reset(&targ_oloc) < 0) + if (H5O_loc_reset(&targ_oloc) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTRESET, FAIL, "unable to initialize target location") targ_oloc.file = f; targ_oloc.addr = lnk->u.hard.addr; /* Check if a symbol table message exists */ - if((stab_exists = H5O_msg_exists(&targ_oloc, H5O_STAB_ID, - dxpl_id)) < 0) + if ((stab_exists = H5O_msg_exists(&targ_oloc, H5O_STAB_ID, dxpl_id)) < 0) HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "unable to check for STAB message") HDassert(!stab_exists); } /* end else */ -#endif /* NDEBUG */ - } /* end if */ - else if(obj_type == H5O_TYPE_UNKNOWN){ +#endif /* NDEBUG */ + } /* end if */ + else if (obj_type == H5O_TYPE_UNKNOWN) { /* Try to retrieve symbol table information for caching */ - H5O_loc_t targ_oloc; /* Location of link target */ - H5O_t *oh; /* Link target object header */ - H5O_stab_t stab; /* Link target symbol table */ - htri_t stab_exists; /* Whether the target symbol table exists */ + H5O_loc_t targ_oloc; /* Location of link target */ + H5O_t * oh; /* Link target object header */ + H5O_stab_t stab; /* Link target symbol table */ + htri_t stab_exists; /* Whether the target symbol table exists */ /* Build target object location */ - if(H5O_loc_reset(&targ_oloc) < 0) + if (H5O_loc_reset(&targ_oloc) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTRESET, FAIL, "unable to initialize target location") targ_oloc.file = f; targ_oloc.addr = lnk->u.hard.addr; /* Get the object header */ - if(NULL == (oh = H5O_protect(&targ_oloc, dxpl_id, H5AC_READ))) + if (NULL == (oh = H5O_protect(&targ_oloc, dxpl_id, H5AC_READ))) HGOTO_ERROR(H5E_SYM, H5E_CANTPROTECT, FAIL, "unable to protect target object header") /* Check if a symbol table message exists */ - if((stab_exists = H5O_msg_exists_oh(oh, H5O_STAB_ID)) < 0) { - if(H5O_unprotect(&targ_oloc, dxpl_id, oh, H5AC__NO_FLAGS_SET) - < 0) + if ((stab_exists = H5O_msg_exists_oh(oh, H5O_STAB_ID)) < 0) { + if (H5O_unprotect(&targ_oloc, dxpl_id, oh, H5AC__NO_FLAGS_SET) < 0) HERROR(H5E_SYM, H5E_CANTUNPROTECT, "unable to release object header"); HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "unable to check for STAB message") } /* end if */ - if(stab_exists) { + if (stab_exists) { /* Read symbol table message */ - if(NULL == H5O_msg_read_oh(f, dxpl_id, oh, H5O_STAB_ID, - &stab)) { - if(H5O_unprotect(&targ_oloc, dxpl_id, oh, - H5AC__NO_FLAGS_SET) < 0) + if (NULL == H5O_msg_read_oh(f, dxpl_id, oh, H5O_STAB_ID, &stab)) { + if (H5O_unprotect(&targ_oloc, dxpl_id, oh, H5AC__NO_FLAGS_SET) < 0) HERROR(H5E_SYM, H5E_CANTUNPROTECT, "unable to release object header"); HGOTO_ERROR(H5E_SYM, H5E_CANTGET, FAIL, "unable to read STAB message") } /* end if */ /* Cache symbol table message */ - ent->type = H5G_CACHED_STAB; + ent->type = H5G_CACHED_STAB; ent->cache.stab.btree_addr = stab.btree_addr; - ent->cache.stab.heap_addr = stab.heap_addr; + ent->cache.stab.heap_addr = stab.heap_addr; } /* end if */ else /* No symbol table message, don't cache anything */ ent->type = H5G_NOTHING_CACHED; - if(H5O_unprotect(&targ_oloc, dxpl_id, oh, H5AC__NO_FLAGS_SET) - < 0) + if (H5O_unprotect(&targ_oloc, dxpl_id, oh, H5AC__NO_FLAGS_SET) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTUNPROTECT, FAIL, "unable to release object header") } /* end else */ else @@ -502,32 +480,30 @@ H5G__ent_convert(H5F_t *f, hid_t dxpl_id, H5HL_t *heap, const char *name, ent->header = lnk->u.hard.addr; break; - case H5L_TYPE_SOFT: - { - size_t lnk_offset; /* Offset to sym-link value */ + case H5L_TYPE_SOFT: { + size_t lnk_offset; /* Offset to sym-link value */ - /* Insert link value into local heap */ - if((size_t)(-1) == (lnk_offset = H5HL_insert(f, dxpl_id, heap, - HDstrlen(lnk->u.soft.name) + 1, lnk->u.soft.name))) - HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to write link value to local heap") + /* Insert link value into local heap */ + if ((size_t)(-1) == (lnk_offset = H5HL_insert(f, dxpl_id, heap, HDstrlen(lnk->u.soft.name) + 1, + lnk->u.soft.name))) + HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to write link value to local heap") - ent->type = H5G_CACHED_SLINK; - ent->cache.slink.lval_offset = lnk_offset; - } /* end case */ - break; + ent->type = H5G_CACHED_SLINK; + ent->cache.slink.lval_offset = lnk_offset; + } /* end case */ + break; case H5L_TYPE_ERROR: case H5L_TYPE_EXTERNAL: case H5L_TYPE_MAX: default: - HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "unrecognized link type") + HGOTO_ERROR(H5E_SYM, H5E_BADVALUE, FAIL, "unrecognized link type") } /* end switch */ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5G__ent_convert() */ - /*------------------------------------------------------------------------- * Function: H5G__ent_debug * @@ -542,10 +518,9 @@ done: *------------------------------------------------------------------------- */ herr_t -H5G__ent_debug(const H5G_entry_t *ent, FILE *stream, int indent, int fwidth, - const H5HL_t *heap) +H5G__ent_debug(const H5G_entry_t *ent, FILE *stream, int indent, int fwidth, const H5HL_t *heap) { - const char *lval = NULL; + const char *lval = NULL; int nested_indent, nested_fwidth; FUNC_ENTER_PACKAGE_NOERR @@ -555,15 +530,12 @@ H5G__ent_debug(const H5G_entry_t *ent, FILE *stream, int indent, int fwidth, nested_fwidth = MAX(0, fwidth - 3); HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth, - "Name offset into private heap:", - (unsigned long) (ent->name_off)); + "Name offset into private heap:", (unsigned long)(ent->name_off)); - HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, - "Object header address:", ent->header); + HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth, "Object header address:", ent->header); - HDfprintf(stream, "%*s%-*s ", indent, "", fwidth, - "Cache info type:"); - switch(ent->type) { + HDfprintf(stream, "%*s%-*s ", indent, "", fwidth, "Cache info type:"); + switch (ent->type) { case H5G_NOTHING_CACHED: HDfprintf(stream, "Nothing Cached\n"); break; @@ -571,8 +543,7 @@ H5G__ent_debug(const H5G_entry_t *ent, FILE *stream, int indent, int fwidth, case H5G_CACHED_STAB: HDfprintf(stream, "Symbol Table\n"); - HDfprintf(stream, "%*s%-*s\n", indent, "", fwidth, - "Cached entry information:"); + HDfprintf(stream, "%*s%-*s\n", indent, "", fwidth, "Cached entry information:"); HDfprintf(stream, "%*s%-*s %a\n", nested_indent, "", nested_fwidth, "B-tree address:", ent->cache.stab.btree_addr); @@ -582,19 +553,17 @@ H5G__ent_debug(const H5G_entry_t *ent, FILE *stream, int indent, int fwidth, case H5G_CACHED_SLINK: HDfprintf(stream, "Symbolic Link\n"); - HDfprintf(stream, "%*s%-*s\n", indent, "", fwidth, - "Cached information:"); + HDfprintf(stream, "%*s%-*s\n", indent, "", fwidth, "Cached information:"); HDfprintf(stream, "%*s%-*s %lu\n", nested_indent, "", nested_fwidth, - "Link value offset:", - (unsigned long)(ent->cache.slink.lval_offset)); - if(heap) { + "Link value offset:", (unsigned long)(ent->cache.slink.lval_offset)); + if (heap) { lval = (const char *)H5HL_offset_into(heap, ent->cache.slink.lval_offset); HDfprintf(stream, "%*s%-*s %s\n", nested_indent, "", nested_fwidth, - "Link value:", - (lval == NULL) ? "" : lval); + "Link value:", (lval == NULL) ? "" : lval); } /* end if */ else - HDfprintf(stream, "%*s%-*s\n", nested_indent, "", nested_fwidth, "Warning: Invalid heap address given, name not displayed!"); + HDfprintf(stream, "%*s%-*s\n", nested_indent, "", nested_fwidth, + "Warning: Invalid heap address given, name not displayed!"); break; case H5G_CACHED_ERROR: @@ -606,4 +575,3 @@ H5G__ent_debug(const H5G_entry_t *ent, FILE *stream, int indent, int fwidth, FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5G__ent_debug() */ - |