summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/H5F.c3
-rw-r--r--src/H5Fprivate.h3
-rw-r--r--src/H5HL.c13
-rw-r--r--src/H5Iprivate.h1
-rw-r--r--src/H5Ipublic.h4
-rw-r--r--src/H5MF.c91
-rw-r--r--src/H5MFprivate.h4
-rw-r--r--src/H5O.c109
-rw-r--r--src/H5Oprivate.h26
-rw-r--r--src/H5T.c9
10 files changed, 140 insertions, 123 deletions
diff --git a/src/H5F.c b/src/H5F.c
index 66d8587..92b87c0 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -4347,7 +4347,6 @@ H5F_get_eoa(const H5F_t *f)
{
haddr_t ret_value;
- /* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
FUNC_ENTER_NOAPI(H5F_get_eoa, HADDR_UNDEF)
assert(f);
@@ -4359,7 +4358,7 @@ H5F_get_eoa(const H5F_t *f)
done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5F_get_base_addr() */
+} /* end H5F_get_eoa() */
#ifdef H5_HAVE_PARALLEL
diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h
index 2e92415..d516dc5 100644
--- a/src/H5Fprivate.h
+++ b/src/H5Fprivate.h
@@ -212,6 +212,8 @@ typedef struct H5F_t H5F_t;
#define H5F_HAS_FEATURE(F,FL) ((F)->shared->lf->feature_flags&(FL))
/* B-tree node raw page */
#define H5F_GRP_BTREE_SHARED(F) ((F)->shared->grp_btree_shared)
+/* Base address of file */
+#define H5F_BASE_ADDR(F) ((F)->shared->base_addr)
#else /* H5F_PACKAGE */
#define H5F_SIZEOF_ADDR(F) (H5F_sizeof_addr(F))
#define H5F_SIZEOF_SIZE(F) (H5F_sizeof_size(F))
@@ -222,6 +224,7 @@ typedef struct H5F_t H5F_t;
#define H5F_RDCC_W0(F) (H5F_rdcc_w0(F))
#define H5F_HAS_FEATURE(F,FL) (H5F_has_feature(F,FL))
#define H5F_GRP_BTREE_SHARED(F) (H5F_grp_btree_shared(F))
+#define H5F_BASE_ADDR(F) (H5F_base_addr(F))
#endif /* H5F_PACKAGE */
diff --git a/src/H5HL.c b/src/H5HL.c
index bfbb2ac..e0202f2 100644
--- a/src/H5HL.c
+++ b/src/H5HL.c
@@ -341,7 +341,7 @@ H5HL_minimize_heap_space(H5F_t *f, hid_t dxpl_id, H5HL_t *heap)
* When the heap is being flushed to disk, release the file space reserved
* for it.
*/
- H5MF_free_reserved(f, heap->disk_resrv);
+ H5MF_free_reserved(f, (hsize_t)heap->disk_resrv);
heap->disk_resrv = 0;
/*
@@ -1021,7 +1021,7 @@ H5HL_insert(H5F_t *f, hid_t dxpl_id, haddr_t addr, size_t buf_size, const void *
else
disk_resrv = heap->mem_alloc + need_more - heap->disk_resrv;
- if( H5MF_reserve(f, disk_resrv) < 0 )
+ if( H5MF_reserve(f, (hsize_t)disk_resrv) < 0 )
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, (size_t)(-1), "unable to reserve space in file");
/* Update heap's record of how much space it has reserved */
@@ -1359,8 +1359,15 @@ H5HL_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr)
HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to free local heap data");
} /* end else */
+ /* Release the local heap metadata from the cache */
+ if (H5AC_unprotect(f, dxpl_id, H5AC_LHEAP, addr, heap, TRUE)<0) {
+ heap = NULL;
+ HGOTO_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release local heap");
+ }
+ heap = NULL;
+
done:
- if (heap && H5AC_unprotect(f, dxpl_id, H5AC_LHEAP, addr, heap, TRUE)<0)
+ if (heap && H5AC_unprotect(f, dxpl_id, H5AC_LHEAP, addr, heap, FALSE)<0)
HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release local heap");
FUNC_LEAVE_NOAPI(ret_value);
diff --git a/src/H5Iprivate.h b/src/H5Iprivate.h
index 2f0bdb8..667af3d1 100644
--- a/src/H5Iprivate.h
+++ b/src/H5Iprivate.h
@@ -26,7 +26,6 @@
/* Private headers needed by this file */
#include "H5private.h"
-#include "H5Oprivate.h"
/* Macro to determine if a H5I_type_t is a "library type" */
#define H5I_IS_LIB_TYPE( type ) (type > 0 && type < H5I_NTYPES)
diff --git a/src/H5Ipublic.h b/src/H5Ipublic.h
index 9d76d63..d6ed95b 100644
--- a/src/H5Ipublic.h
+++ b/src/H5Ipublic.h
@@ -33,8 +33,8 @@
*
*/
typedef enum {
- H5I_UNINIT = (-2), /*uninitialized type */
- H5I_BADID = (-1), /*invalid Type */
+ H5I_UNINIT = (-2), /*uninitialized type */
+ H5I_BADID = (-1), /*invalid Type */
H5I_FILE = 1, /*type ID for File objects */
H5I_FILE_CLOSING, /*files pending close due to open objhdrs */
H5I_GROUP, /*type ID for Group objects */
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() */
-
diff --git a/src/H5MFprivate.h b/src/H5MFprivate.h
index 2a129ea..ee35c2a 100644
--- a/src/H5MFprivate.h
+++ b/src/H5MFprivate.h
@@ -49,8 +49,8 @@ H5_DLL herr_t H5MF_xfree(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr,
H5_DLL haddr_t H5MF_realloc(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, haddr_t old_addr,
hsize_t old_size, hsize_t new_size);
H5_DLL herr_t H5MF_reserve(H5F_t *f, hsize_t size);
-H5_DLL void H5MF_free_reserved(H5F_t *f, hsize_t size);
-H5_DLL int H5MF_alloc_overflow(H5F_t *f, hsize_t size);
+H5_DLL herr_t H5MF_free_reserved(H5F_t *f, hsize_t size);
+H5_DLL hbool_t H5MF_alloc_overflow(H5F_t *f, hsize_t size);
H5_DLL htri_t H5MF_can_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr,
hsize_t size, hsize_t extra_requested);
H5_DLL htri_t H5MF_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size,
diff --git a/src/H5O.c b/src/H5O.c
index 609b7c6..1515500 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -716,11 +716,10 @@ H5O_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5O_t *oh)
assert(!H5F_addr_defined(oh->chunk[cont->chunkno].addr));
cont->size = oh->chunk[cont->chunkno].size;
- /* Free the space we'd reserved in the file to hold this chunk */
- H5MF_free_reserved(f, cont->size);
+ /* Free the space we'd reserved in the file to hold this chunk */
+ H5MF_free_reserved(f, (hsize_t)cont->size);
- if (HADDR_UNDEF==(cont->addr=H5MF_alloc(f,
- H5FD_MEM_OHDR, dxpl_id, (hsize_t)cont->size)))
+ if (HADDR_UNDEF==(cont->addr=H5MF_alloc(f, H5FD_MEM_OHDR, dxpl_id, (hsize_t)cont->size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate space for object header data");
oh->chunk[cont->chunkno].addr = cont->addr;
}
@@ -970,7 +969,7 @@ H5O_compute_size(H5F_t *f, H5O_t *oh, size_t *size_ptr)
*-------------------------------------------------------------------------
*/
herr_t
-H5O_reset(hid_t type_id, void *native)
+H5O_reset(unsigned type_id, void *native)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
herr_t ret_value; /* Return value */
@@ -978,7 +977,7 @@ H5O_reset(hid_t type_id, void *native)
FUNC_ENTER_NOAPI(H5O_reset,FAIL);
/* check args */
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert(type);
@@ -1050,7 +1049,7 @@ done:
*-------------------------------------------------------------------------
*/
void *
-H5O_free (hid_t type_id, void *mesg)
+H5O_free (unsigned type_id, void *mesg)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
void * ret_value; /* Return value */
@@ -1058,7 +1057,7 @@ H5O_free (hid_t type_id, void *mesg)
FUNC_ENTER_NOAPI(H5O_free, NULL);
/* check args */
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert(type);
@@ -1131,7 +1130,7 @@ H5O_free_real(const H5O_class_t *type, void *mesg)
*-------------------------------------------------------------------------
*/
void *
-H5O_copy (hid_t type_id, const void *mesg, void *dst)
+H5O_copy (unsigned type_id, const void *mesg, void *dst)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
void *ret_value; /* Return value */
@@ -1139,7 +1138,7 @@ H5O_copy (hid_t type_id, const void *mesg, void *dst)
FUNC_ENTER_NOAPI(H5O_copy, NULL);
/* check args */
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert(type);
@@ -1307,7 +1306,7 @@ done:
*-------------------------------------------------------------------------
*/
int
-H5O_count (H5G_entry_t *ent, hid_t type_id, hid_t dxpl_id)
+H5O_count (H5G_entry_t *ent, unsigned type_id, hid_t dxpl_id)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
int ret_value; /* Return value */
@@ -1318,7 +1317,7 @@ H5O_count (H5G_entry_t *ent, hid_t type_id, hid_t dxpl_id)
assert (ent);
assert (ent->file);
assert (H5F_addr_defined(ent->header));
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert (type);
@@ -1409,7 +1408,7 @@ done:
*-------------------------------------------------------------------------
*/
htri_t
-H5O_exists(H5G_entry_t *ent, hid_t type_id, int sequence, hid_t dxpl_id)
+H5O_exists(H5G_entry_t *ent, unsigned type_id, int sequence, hid_t dxpl_id)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
htri_t ret_value; /* Return value */
@@ -1418,7 +1417,7 @@ H5O_exists(H5G_entry_t *ent, hid_t type_id, int sequence, hid_t dxpl_id)
assert(ent);
assert(ent->file);
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert(type);
assert(sequence>=0);
@@ -1519,7 +1518,7 @@ done:
*-------------------------------------------------------------------------
*/
void *
-H5O_read(H5G_entry_t *ent, hid_t type_id, int sequence, void *mesg, hid_t dxpl_id)
+H5O_read(H5G_entry_t *ent, unsigned type_id, int sequence, void *mesg, hid_t dxpl_id)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
void *ret_value; /* Return value */
@@ -1530,7 +1529,7 @@ H5O_read(H5G_entry_t *ent, hid_t type_id, int sequence, void *mesg, hid_t dxpl_i
assert(ent);
assert(ent->file);
assert(H5F_addr_defined(ent->header));
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert(type);
assert(sequence >= 0);
@@ -1764,7 +1763,7 @@ done:
*-------------------------------------------------------------------------
*/
int
-H5O_modify(H5G_entry_t *ent, hid_t type_id, int overwrite,
+H5O_modify(H5G_entry_t *ent, unsigned type_id, int overwrite,
unsigned flags, unsigned update_time, const void *mesg, hid_t dxpl_id)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
@@ -1776,7 +1775,7 @@ H5O_modify(H5G_entry_t *ent, hid_t type_id, int overwrite,
assert(ent);
assert(ent->file);
assert(H5F_addr_defined(ent->header));
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert(type);
assert(mesg);
@@ -2017,7 +2016,7 @@ done:
*-------------------------------------------------------------------------
*/
int
-H5O_append(H5F_t *f, hid_t dxpl_id, H5O_t *oh, hid_t type_id, unsigned flags,
+H5O_append(H5F_t *f, hid_t dxpl_id, H5O_t *oh, unsigned type_id, unsigned flags,
const void *mesg)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
@@ -2028,7 +2027,7 @@ H5O_append(H5F_t *f, hid_t dxpl_id, H5O_t *oh, hid_t type_id, unsigned flags,
/* check args */
assert(f);
assert(oh);
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert(type);
assert(0==(flags & ~H5O_FLAG_BITS));
@@ -2469,7 +2468,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5O_remove(H5G_entry_t *ent, hid_t type_id, int sequence, hid_t dxpl_id)
+H5O_remove(H5G_entry_t *ent, unsigned type_id, int sequence, hid_t dxpl_id)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
herr_t ret_value; /* Return value */
@@ -2480,7 +2479,7 @@ H5O_remove(H5G_entry_t *ent, hid_t type_id, int sequence, hid_t dxpl_id)
assert(ent);
assert(ent->file);
assert(H5F_addr_defined(ent->header));
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert(type);
@@ -2641,15 +2640,15 @@ H5O_alloc_extend_chunk(H5F_t *f, H5O_t *oh, unsigned chunkno, size_t size)
for (idx=0; idx<oh->nmesgs; idx++) {
if (oh->mesg[idx].chunkno==chunkno) {
if (H5O_NULL_ID == oh->mesg[idx].type->id &&
- (oh->mesg[idx].raw + oh->mesg[idx].raw_size ==
- oh->chunk[chunkno].image + oh->chunk[chunkno].size)) {
+ (oh->mesg[idx].raw + oh->mesg[idx].raw_size ==
+ oh->chunk[chunkno].image + oh->chunk[chunkno].size)) {
delta = MAX (H5O_MIN_SIZE, aligned_size - oh->mesg[idx].raw_size);
assert (delta=H5O_ALIGN (delta));
- /* Reserve space in the file to hold the increased chunk size */
- if( H5MF_reserve(f, delta) < 0 )
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, UFAIL, "unable to reserve space in file");
+ /* Reserve space in the file to hold the increased chunk size */
+ if( H5MF_reserve(f, (hsize_t)delta) < 0 )
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, UFAIL, "unable to reserve space in file");
oh->mesg[idx].dirty = TRUE;
oh->mesg[idx].raw_size += delta;
@@ -2678,12 +2677,12 @@ H5O_alloc_extend_chunk(H5F_t *f, H5O_t *oh, unsigned chunkno, size_t size)
} /* end if */
}
- /* Reserve space in the file */
+ /* Reserve space in the file */
delta = MAX(H5O_MIN_SIZE, aligned_size+H5O_SIZEOF_MSGHDR(f));
delta = H5O_ALIGN(delta);
- if( H5MF_reserve(f, delta) < 0 )
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, UFAIL, "unable to reserve space in file");
+ if( H5MF_reserve(f, (hsize_t)delta) < 0 )
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, UFAIL, "unable to reserve space in file");
/* create a new null message */
if (oh->nmesgs >= oh->alloc_nmesgs) {
@@ -2824,7 +2823,7 @@ H5O_alloc_new_chunk(H5F_t *f, H5O_t *oh, size_t size)
assert (size == H5O_ALIGN (size));
/* Reserve space in the file to hold the new chunk */
- if( H5MF_reserve(f, size) < 0 )
+ if( H5MF_reserve(f, (hsize_t)size) < 0 )
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, UFAIL, "unable to reserve space in file for new chunk");
/*
@@ -3128,7 +3127,7 @@ done:
*-------------------------------------------------------------------------
*/
size_t
-H5O_raw_size(hid_t type_id, H5F_t *f, const void *mesg)
+H5O_raw_size(unsigned type_id, H5F_t *f, const void *mesg)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
size_t ret_value; /* Return value */
@@ -3136,7 +3135,7 @@ H5O_raw_size(hid_t type_id, H5F_t *f, const void *mesg)
FUNC_ENTER_NOAPI(H5O_raw_size,0);
/* Check args */
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert (type);
assert (type->raw_size);
@@ -3172,7 +3171,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5O_get_share(hid_t type_id, H5F_t *f, const void *mesg, H5O_shared_t *share)
+H5O_get_share(unsigned type_id, H5F_t *f, const void *mesg, H5O_shared_t *share)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
herr_t ret_value; /* Return value */
@@ -3180,7 +3179,7 @@ H5O_get_share(hid_t type_id, H5F_t *f, const void *mesg, H5O_shared_t *share)
FUNC_ENTER_NOAPI(H5O_get_share,FAIL);
/* Check args */
- assert(type_id>=0 && type_id<(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])));
+ assert(type_id<NELMTS(message_type_g));
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert (type);
assert (type->get_share);
@@ -3445,7 +3444,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, hid_t type_id)
+H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, unsigned type_id)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
size_t size; /* size of the message*/
@@ -3454,26 +3453,22 @@ H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, hid_t type_id)
FUNC_ENTER_NOAPI(H5O_encode,FAIL);
/* check args */
- if(type_id<0 || type_id>=(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])))
- HGOTO_ERROR (H5E_ARGS, H5E_BADRANGE, FAIL, "invalid object type");
-
- /* map the type ID to the actual type object */
- if((type=message_type_g[type_id])==NULL)
- HGOTO_ERROR (H5E_OHDR, H5E_BADTYPE, FAIL, "unable to find object type");
+ assert(type_id<NELMTS(message_type_g));
+ type=message_type_g[type_id]; /* map the type ID to the actual type object */
+ assert(type);
/* check buffer size */
- if ((size=(type->raw_size)(NULL, obj))<0)
+ if ((size=(type->raw_size)(NULL, obj))<=0)
HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message");
/* Don't encode if buffer size isn't big enough */
- if(!buf || *nalloc<size) {
+ if(!buf || *nalloc<size)
*nalloc = size;
- HGOTO_DONE(ret_value);
- }
-
- /* Encode */
- if ((type->encode)(NULL, buf, obj)<0)
- HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message");
+ else {
+ /* Encode */
+ if ((type->encode)(NULL, buf, obj)<0)
+ HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message");
+ } /* end else */
done:
FUNC_LEAVE_NOAPI(ret_value);
@@ -3499,21 +3494,17 @@ done:
*-------------------------------------------------------------------------
*/
void*
-H5O_decode(unsigned char *buf, hid_t type_id)
+H5O_decode(unsigned char *buf, unsigned type_id)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
- size_t size; /* size of the message*/
- void *ret_value=NULL; /* Return value */
+ void *ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5O_decode,NULL);
/* check args */
- if(type_id<0 || type_id>=(hid_t)(sizeof(message_type_g)/sizeof(message_type_g[0])))
- HGOTO_ERROR (H5E_ARGS, H5E_BADRANGE, NULL, "invalid object type");
-
- /* map the type ID to the actual type object */
- if((type=message_type_g[type_id])==NULL)
- HGOTO_ERROR (H5E_OHDR, H5E_BADTYPE, NULL, "unable to find object type");
+ assert(type_id<NELMTS(message_type_g));
+ type=message_type_g[type_id]; /* map the type ID to the actual type object */
+ assert(type);
/* decode */
ret_value = (type->decode)(NULL, 0, buf, NULL);
diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h
index ab52171..a18820a 100644
--- a/src/H5Oprivate.h
+++ b/src/H5Oprivate.h
@@ -228,16 +228,16 @@ H5_DLL herr_t H5O_create(H5F_t *f, hid_t dxpl_id, size_t size_hint,
H5_DLL herr_t H5O_open(H5G_entry_t *ent);
H5_DLL herr_t H5O_close(H5G_entry_t *ent);
H5_DLL int H5O_link(const H5G_entry_t *ent, int adjust, hid_t dxpl_id);
-H5_DLL int H5O_count(H5G_entry_t *ent, hid_t type_id, hid_t dxpl_id);
-H5_DLL htri_t H5O_exists(H5G_entry_t *ent, hid_t type_id, int sequence,
+H5_DLL int H5O_count(H5G_entry_t *ent, unsigned type_id, hid_t dxpl_id);
+H5_DLL htri_t H5O_exists(H5G_entry_t *ent, unsigned type_id, int sequence,
hid_t dxpl_id);
-H5_DLL void *H5O_read(H5G_entry_t *ent, hid_t type_id, int sequence,
+H5_DLL void *H5O_read(H5G_entry_t *ent, unsigned type_id, int sequence,
void *mesg, hid_t dxpl_id);
-H5_DLL int H5O_modify(H5G_entry_t *ent, hid_t type_id,
+H5_DLL int H5O_modify(H5G_entry_t *ent, unsigned type_id,
int overwrite, unsigned flags, unsigned update_time, const void *mesg, hid_t dxpl_id);
H5_DLL struct H5O_t * H5O_protect(H5G_entry_t *ent, hid_t dxpl_id);
H5_DLL herr_t H5O_unprotect(H5G_entry_t *ent, struct H5O_t *oh, hid_t dxpl_id);
-H5_DLL int H5O_append(H5F_t *f, hid_t dxpl_id, struct H5O_t *oh, hid_t type_id,
+H5_DLL int H5O_append(H5F_t *f, hid_t dxpl_id, struct H5O_t *oh, unsigned type_id,
unsigned flags, const void *mesg);
H5_DLL herr_t H5O_touch(H5G_entry_t *ent, hbool_t force, hid_t dxpl_id);
H5_DLL herr_t H5O_touch_oh(H5F_t *f, struct H5O_t *oh, hbool_t force);
@@ -245,15 +245,15 @@ H5_DLL herr_t H5O_touch_oh(H5F_t *f, struct H5O_t *oh, hbool_t force);
H5_DLL herr_t H5O_bogus(H5G_entry_t *ent, hid_t dxpl_id);
H5_DLL herr_t H5O_bogus_oh(H5F_t *f, struct H5O_t *oh);
#endif /* H5O_ENABLE_BOGUS */
-H5_DLL herr_t H5O_remove(H5G_entry_t *ent, hid_t type_id, int sequence,
+H5_DLL herr_t H5O_remove(H5G_entry_t *ent, unsigned type_id, int sequence,
hid_t dxpl_id);
-H5_DLL herr_t H5O_reset(hid_t type_id, void *native);
-H5_DLL void *H5O_free(hid_t type_id, void *mesg);
-H5_DLL herr_t H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, hid_t type_id);
-H5_DLL void* H5O_decode(unsigned char *buf, hid_t type_id);
-H5_DLL void *H5O_copy(hid_t type_id, const void *mesg, void *dst);
-H5_DLL size_t H5O_raw_size(hid_t type_id, H5F_t *f, const void *mesg);
-H5_DLL herr_t H5O_get_share(hid_t type_id, H5F_t *f, const void *mesg, H5O_shared_t *share);
+H5_DLL herr_t H5O_reset(unsigned type_id, void *native);
+H5_DLL void *H5O_free(unsigned type_id, void *mesg);
+H5_DLL herr_t H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, unsigned type_id);
+H5_DLL void* H5O_decode(unsigned char *buf, unsigned type_id);
+H5_DLL void *H5O_copy(unsigned type_id, const void *mesg, void *dst);
+H5_DLL size_t H5O_raw_size(unsigned type_id, H5F_t *f, const void *mesg);
+H5_DLL herr_t H5O_get_share(unsigned type_id, H5F_t *f, const void *mesg, H5O_shared_t *share);
H5_DLL herr_t H5O_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr);
H5_DLL herr_t H5O_get_info(H5G_entry_t *ent, H5O_stat_t *ostat, hid_t dxpl_id);
H5_DLL herr_t H5O_debug_id(hid_t type_id, H5F_t *f, hid_t dxpl_id, const void *mesg, FILE *stream, int indent, int fwidth);
diff --git a/src/H5T.c b/src/H5T.c
index 26cc8c3..4d9b032 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -2573,15 +2573,18 @@ herr_t
H5Tencode(hid_t obj_id, unsigned char* buf, size_t* nalloc)
{
H5T_t *dtype;
- herr_t ret_value;
+ herr_t ret_value=SUCCEED;
FUNC_ENTER_API (H5Tencode, FAIL);
/* Check argument and retrieve object */
if (NULL==(dtype=H5I_object_verify(obj_id, H5I_DATATYPE)))
HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
+ if (nalloc==NULL)
+ HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "NULL pointer for buffer size")
- ret_value = H5T_encode(dtype, buf, nalloc);
+ if(H5T_encode(dtype, buf, nalloc)<0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode datatype");
done:
FUNC_LEAVE_API(ret_value);
@@ -2615,7 +2618,7 @@ H5Tdecode(unsigned char* buf)
FUNC_ENTER_API (H5Tdecode, FAIL);
if (buf==NULL)
- HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "empty buffer")
+ HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "NULL pointer for buffer")
if((dt = H5T_decode(buf))==NULL)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "can't decode object");