diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2002-08-08 16:52:55 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2002-08-08 16:52:55 (GMT) |
commit | d8397a6f426227d09d20e647ce8b12b8c6295b2d (patch) | |
tree | 2943fbfd2bfb66cf167eb642835fdb4deb3afd3c /src/H5MF.c | |
parent | 573307786a1f5f7ce597e5191ea08c3bbd95b66c (diff) | |
download | hdf5-d8397a6f426227d09d20e647ce8b12b8c6295b2d.zip hdf5-d8397a6f426227d09d20e647ce8b12b8c6295b2d.tar.gz hdf5-d8397a6f426227d09d20e647ce8b12b8c6295b2d.tar.bz2 |
[svn-r5842] Purpose:
Code cleanup
Description:
Change most (all?) HRETURN_ERROR macros to HGOTO_ERROR macros, along with
HRETURN macros to HGOTO_DONE macros. This unifies the error return path
from functions and reduces the size of the library by up to 10% on some
platforms.
Additionally, I improved a lot of the error cleanup code in many routines.
Platforms tested:
FreeBSD 4.6 (sleipnir) serial & parallel and IRIX64 6.5 (modi4) serial &
parallel.
Diffstat (limited to 'src/H5MF.c')
-rw-r--r-- | src/H5MF.c | 37 |
1 files changed, 20 insertions, 17 deletions
@@ -59,7 +59,7 @@ static int interface_initialize_g = 0; haddr_t H5MF_alloc(H5F_t *f, H5FD_mem_t type, hsize_t size) { - haddr_t ret_value=HADDR_UNDEF; + haddr_t ret_value; FUNC_ENTER_NOAPI(H5MF_alloc, HADDR_UNDEF); @@ -68,20 +68,20 @@ H5MF_alloc(H5F_t *f, H5FD_mem_t type, hsize_t size) assert(size > 0); /* Fail if we don't have write access */ - if (0==(f->intent & H5F_ACC_RDWR)) { - HRETURN_ERROR(H5E_RESOURCE, H5E_CANTINIT, HADDR_UNDEF, "file is read-only"); - } + if (0==(f->intent & H5F_ACC_RDWR)) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, HADDR_UNDEF, "file is read-only"); /* Allocate space from the virtual file layer */ - if (HADDR_UNDEF==(ret_value=H5FD_alloc(f->shared->lf, type, size))) { - HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, - "file allocation failed"); - } + if (HADDR_UNDEF==(ret_value=H5FD_alloc(f->shared->lf, type, size))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "file allocation failed"); /* Convert absolute file address to relative file address */ assert(ret_value>=f->shared->base_addr); + + /* Set return value */ ret_value -= f->shared->base_addr; +done: FUNC_LEAVE(ret_value); } @@ -109,13 +109,14 @@ H5MF_alloc(H5F_t *f, H5FD_mem_t type, hsize_t size) herr_t H5MF_xfree(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size) { + herr_t ret_value=SUCCEED; /* Return value */ + FUNC_ENTER_NOAPI(H5MF_xfree, FAIL); /* check arguments */ assert(f); - if (!H5F_addr_defined(addr) || 0 == size) { - HRETURN(SUCCEED); - } + if (!H5F_addr_defined(addr) || 0 == size) + HGOTO_DONE(SUCCEED); assert(addr!=0); /* Convert relative address to absolute address */ @@ -132,7 +133,8 @@ H5MF_xfree(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size) #endif } - FUNC_LEAVE(SUCCEED); +done: + FUNC_LEAVE(ret_value); } @@ -175,7 +177,7 @@ haddr_t H5MF_realloc(H5F_t *f, H5FD_mem_t type, haddr_t old_addr, hsize_t old_size, hsize_t new_size) { - haddr_t ret_value=HADDR_UNDEF; + haddr_t ret_value; FUNC_ENTER_NOAPI(H5MF_realloc, HADDR_UNDEF); @@ -185,14 +187,15 @@ H5MF_realloc(H5F_t *f, H5FD_mem_t type, haddr_t old_addr, hsize_t old_size, /* Reallocate memory from the virtual file layer */ ret_value = H5FD_realloc(f->shared->lf, type, old_addr, old_size, new_size); - if (HADDR_UNDEF==ret_value) { - HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, - "unable to allocate new file memory"); - } + if (HADDR_UNDEF==ret_value) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "unable to allocate new file memory"); /* Convert return value to relative address */ assert(ret_value>=f->shared->base_addr); + + /* Set return value */ ret_value -= f->shared->base_addr; +done: FUNC_LEAVE(ret_value); } |