summaryrefslogtreecommitdiffstats
path: root/src/H5MF.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-07-16 20:48:40 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-07-16 20:48:40 (GMT)
commitc97fddc786356a1832e6cb3ac3f28b781d01584d (patch)
treee9ea99bbf3387f45b18d3b6503597a1c63662cab /src/H5MF.c
parentcb516077680041aecc338936d1aa3f84347e0e0d (diff)
downloadhdf5-c97fddc786356a1832e6cb3ac3f28b781d01584d.zip
hdf5-c97fddc786356a1832e6cb3ac3f28b781d01584d.tar.gz
hdf5-c97fddc786356a1832e6cb3ac3f28b781d01584d.tar.bz2
[svn-r8892] Purpose:
Code cleanup Description: Clean up a bunch of warnings and bring new code better inline with current library coding practice. Platforms tested: FreeBSD 4.10 (sleipnir) w/parallel Too minor to require h5committest Misc. update:
Diffstat (limited to 'src/H5MF.c')
-rw-r--r--src/H5MF.c91
1 files changed, 53 insertions, 38 deletions
diff --git a/src/H5MF.c b/src/H5MF.c
index 7761796..3de5afe 100644
--- a/src/H5MF.c
+++ b/src/H5MF.c
@@ -78,13 +78,14 @@ H5MF_alloc(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, hsize_t size)
/* Fail if we don't have write access */
if (0==(f->intent & H5F_ACC_RDWR))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, HADDR_UNDEF, "file is read-only");
+
/* Check that the file can address the new space */
- if( H5MF_alloc_overflow(f, size) != 0 )
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "not enough address space in file");
+ if( H5MF_alloc_overflow(f, size) )
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "not enough address space in file");
/* Allocate space from the virtual file layer */
if (HADDR_UNDEF==(ret_value=H5FD_alloc(f->shared->lf, type, dxpl_id, size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "file allocation failed");
+ 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);
@@ -195,10 +196,10 @@ H5MF_realloc(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, haddr_t old_addr, hsize_t
/* Convert old relative address to absolute address */
old_addr += f->shared->base_addr;
- /* Check that the file can address the new space. */
- /* In the worst case, this means adding new_size bytes to the end of the file. */
- if( H5MF_alloc_overflow(f, new_size) != 0 )
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "not enough address space in file");
+ /* Check that the file can address the new space. */
+ /* In the worst case, this means adding new_size bytes to the end of the file. */
+ if( H5MF_alloc_overflow(f, new_size) )
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "not enough address space in file");
/* Reallocate memory from the virtual file layer */
ret_value = H5FD_realloc(f->shared->lf, type, dxpl_id, old_addr, old_size,
@@ -216,7 +217,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value);
}
-
/*-------------------------------------------------------------------------
* Function: H5MF_reserve
*
@@ -238,22 +238,24 @@ done:
* Modifications:
*-------------------------------------------------------------------------
*/
-herr_t H5MF_reserve(H5F_t *f, hsize_t size)
+herr_t
+H5MF_reserve(H5F_t *f, hsize_t size)
{
- herr_t ret_value = SUCCEED;
+ herr_t ret_value = SUCCEED;
+
FUNC_ENTER_NOAPI(H5MF_reserve, FAIL);
- /* Check arguments */
- assert(f);
+ /* Check arguments */
+ assert(f);
- /* Check that there is room in the file to reserve this space */
- if( H5MF_alloc_overflow( f, size ) != 0)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "not enough address space in file");
+ /* Check that there is room in the file to reserve this space */
+ if( H5MF_alloc_overflow( f, size ) )
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "not enough address space in file");
- f->shared->lf->reserved_alloc += size;
+ f->shared->lf->reserved_alloc += size;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value);
}
/*-------------------------------------------------------------------------
@@ -272,17 +274,22 @@ done:
* Modifications:
*-------------------------------------------------------------------------
*/
-void H5MF_free_reserved(H5F_t *f, hsize_t size)
+herr_t
+H5MF_free_reserved(H5F_t *f, hsize_t size)
{
- /* Check arguments */
- assert(f);
+ FUNC_ENTER_NOAPI_NOFUNC(H5MF_free_reserved)
+
+ /* Check arguments */
+ assert(f);
+
+ /* If this assert breaks, it means that HDF5 is trying to free file space
+ * that was never reserved.
+ */
+ assert(size <= f->shared->lf->reserved_alloc);
- /* If this assert breaks, it means that HDF5 is trying to free file space
- * that was never reserved.
- */
- assert(size <= f->shared->lf->reserved_alloc);
+ f->shared->lf->reserved_alloc -= size;
- f->shared->lf->reserved_alloc -= size;
+ FUNC_LEAVE_NOAPI(SUCCEED)
}
/*-------------------------------------------------------------------------
@@ -302,20 +309,25 @@ void H5MF_free_reserved(H5F_t *f, hsize_t size)
* Modifications:
*-------------------------------------------------------------------------
*/
-int H5MF_alloc_overflow(H5F_t *f, hsize_t size)
+hbool_t
+H5MF_alloc_overflow(H5F_t *f, hsize_t size)
{
- hsize_t space_needed; /* Accumulator variable */
- size_t c;
+ hsize_t space_needed; /* Accumulator variable */
+ size_t c; /* Local index variable */
+ hbool_t ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOFUNC(H5MF_alloc_overflow)
/* Start with the current end of the file's address. */
- space_needed = f->shared->lf->cls->get_eoa(f->shared->lf);
+ space_needed = (hsize_t)H5F_get_eoa(f);
+ HDassert(H5F_addr_defined(space_needed));
/* Subtract the file's base address to get the actual amount of
* space being used:
* (end of allocated space - beginning of allocated space)
*/
- assert(f->shared->base_addr < space_needed);
- space_needed -= f->shared->base_addr;
+ HDassert(H5F_BASE_ADDR(f) < space_needed);
+ space_needed -= (hsize_t)H5F_BASE_ADDR(f);
/* Add the amount of space requested for this allocation */
space_needed += size;
@@ -338,9 +350,11 @@ int H5MF_alloc_overflow(H5F_t *f, hsize_t size)
space_needed = space_needed >> 16;
if(space_needed != 0)
- return 1;
+ ret_value=TRUE;
else
- return 0;
+ ret_value=FALSE;
+
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -369,10 +383,11 @@ htri_t
H5MF_can_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size, hsize_t extra_requested)
{
htri_t ret_value; /* Return value */
+
FUNC_ENTER_NOAPI(H5MF_can_extend, FAIL);
/* Convert old relative address to absolute address */
- addr += f->shared->base_addr;
+ addr += H5F_BASE_ADDR(f);
/* Pass the request down to the virtual file layer */
if((ret_value=H5FD_can_extend(f->shared->lf, type, addr, size, extra_requested))<0)
@@ -407,15 +422,16 @@ htri_t
H5MF_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size, hsize_t extra_requested)
{
htri_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5MF_extend, FAIL);
- /* Convert old relative address to absolute address */
- addr += f->shared->base_addr;
+ FUNC_ENTER_NOAPI(H5MF_extend, FAIL);
/* Make sure there is enough addressable space to satisfy the request */
if ( H5MF_alloc_overflow(f, extra_requested) )
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate new file memory: out of address space");
+ /* Convert old relative address to absolute address */
+ addr += H5F_BASE_ADDR(f);
+
/* Pass the request down to the virtual file layer */
if((ret_value=H5FD_extend(f->shared->lf, type, addr, size, extra_requested))<0)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate new file memory");
@@ -423,4 +439,3 @@ H5MF_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size, hsize_t extra
done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5MF_extend() */
-