diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2009-01-27 23:09:35 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2009-01-27 23:09:35 (GMT) |
commit | 91c1a6df54836d585dcab57b6453867290da5eb8 (patch) | |
tree | 3179c22066f9880e7f09849e8a620ad398f68fa9 /src | |
parent | 05f1e4f778a3535135339293953d89cee8874854 (diff) | |
download | hdf5-91c1a6df54836d585dcab57b6453867290da5eb8.zip hdf5-91c1a6df54836d585dcab57b6453867290da5eb8.tar.gz hdf5-91c1a6df54836d585dcab57b6453867290da5eb8.tar.bz2 |
[svn-r16367] Description:
Refactor internal address encode/decode routines slightly, to allow for
more flexible use.
Tested on:
Mac OS X/32 (amazon)
FreeBSD/32 (duty)
(too minor to require h5committest)
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 e717b99..cd6bcd0 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -508,8 +508,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); |