diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5F.c | 156 | ||||
-rw-r--r-- | src/H5Fprivate.h | 5 |
2 files changed, 121 insertions, 40 deletions
@@ -2326,7 +2326,7 @@ H5F_decr_nopen_objs(H5F_t *f) /*------------------------------------------------------------------------- - * Function: H5F_addr_encode + * Function: H5F_addr_encode_len * * Purpose: Encodes an address into the buffer pointed to by *PP and * then increments the pointer to the first byte after the @@ -2337,35 +2337,65 @@ H5F_decr_nopen_objs(H5F_t *f) * Programmer: Robb Matzke * Friday, November 7, 1997 * - * Modifications: - * Robb Matzke, 1999-07-28 - * The ADDR argument is passed by value. *------------------------------------------------------------------------- */ void -H5F_addr_encode(const H5F_t *f, uint8_t **pp/*in,out*/, haddr_t addr) +H5F_addr_encode_len(size_t addr_len, uint8_t **pp/*in,out*/, haddr_t addr) { - unsigned i; + unsigned u; /* Local index variable */ + + /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_addr_encode_len) - assert(f); - assert(pp && *pp); + HDassert(addr_len); + HDassert(pp && *pp); - if (H5F_addr_defined(addr)) { - for (i=0; i<H5F_SIZEOF_ADDR(f); i++) { + if(H5F_addr_defined(addr)) { + for(u = 0; u < addr_len; u++) { *(*pp)++ = (uint8_t)(addr & 0xff); addr >>= 8; - } - assert("overflow" && 0 == addr); - - } else { - for (i=0; i<H5F_SIZEOF_ADDR(f); i++) + } /* end for */ + HDassert("overflow" && 0 == addr); + } /* end if */ + else { + for(u = 0; u < addr_len; u++) *(*pp)++ = 0xff; - } -} + } /* end else */ + + FUNC_LEAVE_NOAPI_VOID +} /* end H5F_addr_encode_len() */ /*------------------------------------------------------------------------- - * Function: H5F_addr_decode + * Function: H5F_addr_encode + * + * Purpose: Encodes an address into the buffer pointed to by *PP and + * then increments the pointer to the first byte after the + * address. An undefined value is stored as all 1's. + * + * Return: void + * + * Programmer: Robb Matzke + * Friday, November 7, 1997 + * + *------------------------------------------------------------------------- + */ +void +H5F_addr_encode(const H5F_t *f, uint8_t **pp/*in,out*/, haddr_t addr) +{ + /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_addr_encode) + + HDassert(f); + + H5F_addr_encode_len(H5F_SIZEOF_ADDR(f), pp, addr); + + FUNC_LEAVE_NOAPI_VOID +} /* end H5F_addr_encode() */ + + +/*------------------------------------------------------------------------- + * Function: H5F_addr_decode_len * * Purpose: Decodes an address from the buffer pointed to by *PP and * updates the pointer to point to the next byte after the @@ -2379,40 +2409,88 @@ H5F_addr_encode(const H5F_t *f, uint8_t **pp/*in,out*/, haddr_t addr) * Programmer: Robb Matzke * Friday, November 7, 1997 * - * Modifications: - * *------------------------------------------------------------------------- */ void -H5F_addr_decode(const H5F_t *f, const uint8_t **pp/*in,out*/, haddr_t *addr_p/*out*/) +H5F_addr_decode_len(size_t addr_len, const uint8_t **pp/*in,out*/, haddr_t *addr_p/*out*/) { - unsigned i; - haddr_t tmp; - uint8_t c; - hbool_t all_zero = TRUE; + hbool_t all_zero = TRUE; /* True if address was all zeroes */ + unsigned u; /* Local index variable */ - assert(f); - assert(pp && *pp); - assert(addr_p); + /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_addr_decode_len) + HDassert(addr_len); + HDassert(pp && *pp); + HDassert(addr_p); + + /* Reset value in destination */ *addr_p = 0; - for (i=0; i<H5F_SIZEOF_ADDR(f); i++) { + /* Decode bytes from address */ + for(u = 0; u < addr_len; u++) { + uint8_t c; /* Local decoded byte */ + + /* Get decoded byte (and advance pointer) */ c = *(*pp)++; - if (c != 0xff) + + /* Check for non-undefined address byte value */ + if(c != 0xff) all_zero = FALSE; - if (i<sizeof(*addr_p)) { - tmp = c; - tmp <<= (i * 8); /*use tmp to get casting right */ + if(u < sizeof(*addr_p)) { + haddr_t tmp = c; /* Local copy of address, for casting */ + + /* Shift decoded byte to correct position */ + tmp <<= (u * 8); /*use tmp to get casting right */ + + /* Merge into already decoded bytes */ *addr_p |= tmp; - } else if (!all_zero) { - assert(0 == **pp); /*overflow */ - } - } - if (all_zero) + } /* end if */ + else + if(!all_zero) + HDassert(0 == **pp); /*overflow */ + } /* end for */ + + /* If 'all_zero' is still TRUE, the address was entirely composed of '0xff' + * bytes, which is the encoded form of 'HADDR_UNDEF', so set the destination + * to that value */ + if(all_zero) *addr_p = HADDR_UNDEF; -} + + FUNC_LEAVE_NOAPI_VOID +} /* end H5F_addr_decode_len() */ + + +/*------------------------------------------------------------------------- + * Function: H5F_addr_decode + * + * Purpose: Decodes an address from the buffer pointed to by *PP and + * updates the pointer to point to the next byte after the + * address. + * + * If the value read is all 1's then the address is returned + * with an undefined value. + * + * Return: void + * + * Programmer: Robb Matzke + * Friday, November 7, 1997 + * + *------------------------------------------------------------------------- + */ +void +H5F_addr_decode(const H5F_t *f, const uint8_t **pp/*in,out*/, haddr_t *addr_p/*out*/) +{ + /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */ + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5F_addr_decode) + + HDassert(f); + + H5F_addr_decode_len(H5F_SIZEOF_ADDR(f), pp, addr_p); + + FUNC_LEAVE_NOAPI_VOID +} /* end H5F_addr_decode() */ /*------------------------------------------------------------------------- diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 26df262..4062505 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -507,8 +507,11 @@ H5_DLL herr_t H5F_block_write(const H5F_t *f, H5FD_mem_t type, haddr_t addr, /* Address-related functions */ H5_DLL void H5F_addr_encode(const H5F_t *, uint8_t** /*in,out*/, haddr_t); +H5_DLL void H5F_addr_encode_len(size_t addr_len, uint8_t** /*in,out*/, haddr_t); H5_DLL void H5F_addr_decode(const H5F_t *, const uint8_t** /*in,out*/, - haddr_t* /*out*/); + haddr_t* /*out*/); +H5_DLL void H5F_addr_decode_len(size_t addr_len, const uint8_t** /*in,out*/, + haddr_t* /*out*/); /* File access property list callbacks */ H5_DLL herr_t H5P_facc_close(hid_t dxpl_id, void *close_data); |