summaryrefslogtreecommitdiffstats
path: root/src/H5Tcompound.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-10-06 16:35:23 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-10-06 16:35:23 (GMT)
commitd963b5dee027ec12d8ca119327bb8c6192148fc9 (patch)
tree5e31c370c1b873af15716c952e7738404f8da07d /src/H5Tcompound.c
parentc26518498b432684e99a564f1b4f66c3583c2a05 (diff)
downloadhdf5-d963b5dee027ec12d8ca119327bb8c6192148fc9.zip
hdf5-d963b5dee027ec12d8ca119327bb8c6192148fc9.tar.gz
hdf5-d963b5dee027ec12d8ca119327bb8c6192148fc9.tar.bz2
[svn-r9376] Purpose:
Bug fix Description: Close a couple of memory leaks Platforms tested: FreeBSD 4.10 (sleipnir) Solaris 2.7 (arabica) w/purify Linux 2.4 (verbena) too minor for h5committest
Diffstat (limited to 'src/H5Tcompound.c')
-rw-r--r--src/H5Tcompound.c170
1 files changed, 103 insertions, 67 deletions
diff --git a/src/H5Tcompound.c b/src/H5Tcompound.c
index f9c0035..b6718c6 100644
--- a/src/H5Tcompound.c
+++ b/src/H5Tcompound.c
@@ -21,7 +21,7 @@
/* Pablo information */
/* (Put before include files to avoid problems with inline functions) */
-#define PABLO_MASK H5Tcompound_mask
+#define PABLO_MASK H5T_compound_mask
#include "H5private.h" /*generic functions */
#include "H5Eprivate.h" /*error handling */
@@ -57,9 +57,9 @@ DESCRIPTION
static herr_t
H5T_init_compound_interface(void)
{
- FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_init_compound_interface);
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_init_compound_interface)
- FUNC_LEAVE_NOAPI(H5T_init());
+ FUNC_LEAVE_NOAPI(H5T_init())
} /* H5T_init_compound_interface() */
@@ -67,7 +67,7 @@ H5T_init_compound_interface(void)
* Function: H5Tget_member_offset
*
* Purpose: Returns the byte offset of the beginning of a member with
- * respect to the beginning of the compound data type datum.
+ * respect to the beginning of the compound datatype datum.
*
* Return: Success: Byte offset.
*
@@ -89,20 +89,20 @@ H5Tget_member_offset(hid_t type_id, int membno)
H5T_t *dt = NULL;
size_t ret_value;
- FUNC_ENTER_API(H5Tget_member_offset, 0);
- H5TRACE2("z","iIs",type_id,membno);
+ FUNC_ENTER_API(H5Tget_member_offset, 0)
+ H5TRACE2("z","iIs",type_id,membno)
/* Check args */
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)) || H5T_COMPOUND != dt->shared->type)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a compound data type");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a compound datatype")
if (membno < 0 || membno >= dt->shared->u.compnd.nmembs)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid member number");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid member number")
/* Value */
ret_value = H5T_get_member_offset(dt, membno);
done:
- FUNC_LEAVE_API(ret_value);
+ FUNC_LEAVE_API(ret_value)
}
@@ -110,8 +110,8 @@ done:
* Function: H5T_get_member_offset
*
* Purpose: Private function for H5Tget_member_offset. Returns the byte
- * offset of the beginning of a member with respect to the i
- * beginning of the compound data type datum.
+ * offset of the beginning of a member with respect to the
+ * beginning of the compound datatype datum.
*
* Return: Success: Byte offset.
*
@@ -132,7 +132,7 @@ H5T_get_member_offset(H5T_t *dt, int membno)
{
size_t ret_value;
- FUNC_ENTER_NOAPI(H5T_get_member_offset, 0);
+ FUNC_ENTER_NOAPI(H5T_get_member_offset, 0)
assert(dt);
assert(membno >= 0 && membno < dt->shared->u.compnd.nmembs);
@@ -141,7 +141,7 @@ H5T_get_member_offset(H5T_t *dt, int membno)
ret_value = dt->shared->u.compnd.memb[membno].offset;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -167,32 +167,32 @@ H5Tget_member_class(hid_t type_id, int membno)
H5T_t *dt = NULL;
H5T_class_t ret_value;
- FUNC_ENTER_API(H5Tget_member_class, H5T_NO_CLASS);
- H5TRACE2("Tt","iIs",type_id,membno);
+ FUNC_ENTER_API(H5Tget_member_class, H5T_NO_CLASS)
+ H5TRACE2("Tt","iIs",type_id,membno)
/* Check args */
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)) || H5T_COMPOUND != dt->shared->type)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_NO_CLASS, "not a compound data type");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5T_NO_CLASS, "not a compound datatype")
if (membno < 0 || membno >= dt->shared->u.compnd.nmembs)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5T_NO_CLASS, "invalid member number");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, H5T_NO_CLASS, "invalid member number")
/* Value */
ret_value = dt->shared->u.compnd.memb[membno].type->shared->type;
done:
- FUNC_LEAVE_API(ret_value);
+ FUNC_LEAVE_API(ret_value)
} /* end H5Tget_member_class() */
/*-------------------------------------------------------------------------
* Function: H5Tget_member_type
*
- * Purpose: Returns the data type of the specified member. The caller
+ * Purpose: Returns the datatype of the specified member. The caller
* should invoke H5Tclose() to release resources associated with
* the type.
*
- * Return: Success: An OID of a copy of the member data type;
- * modifying the returned data type does not
+ * Return: Success: An OID of a copy of the member datatype;
+ * modifying the returned datatype does not
* modify the member type.
*
* Failure: Negative
@@ -214,26 +214,27 @@ H5Tget_member_type(hid_t type_id, int membno)
H5T_t *dt = NULL, *memb_dt = NULL;
hid_t ret_value;
- FUNC_ENTER_API(H5Tget_member_type, FAIL);
+ FUNC_ENTER_API(H5Tget_member_type, FAIL)
H5TRACE2("i","iIs",type_id,membno);
/* Check args */
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)) || H5T_COMPOUND != dt->shared->type)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound data type");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound datatype")
if (membno < 0 || membno >= dt->shared->u.compnd.nmembs)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid member number");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid member number")
if ((memb_dt=H5T_get_member_type(dt, membno))==NULL)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to retrieve member type");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to retrieve member type")
if ((ret_value = H5I_register(H5I_DATATYPE, memb_dt)) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable register data type atom");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable register datatype atom")
done:
if(ret_value<0) {
if(memb_dt!=NULL)
- H5T_close(memb_dt);
+ if(H5T_close(memb_dt)<0)
+ HDONE_ERROR(H5E_DATATYPE, H5E_CANTCLOSEOBJ, FAIL, "can't close datatype")
} /* end if */
- FUNC_LEAVE_API(ret_value);
+ FUNC_LEAVE_API(ret_value)
}
@@ -243,8 +244,8 @@ done:
* Purpose: Private function for H5Tget_member_type. Returns the data
* type of the specified member.
*
- * Return: Success: A copy of the member data type;
- * modifying the returned data type does not
+ * Return: Success: A copy of the member datatype;
+ * modifying the returned datatype does not
* modify the member type.
*
* Failure: NULL
@@ -261,15 +262,49 @@ H5T_get_member_type(H5T_t *dt, int membno)
{
H5T_t *ret_value = NULL;
- FUNC_ENTER_NOAPI(H5T_get_member_type, NULL);
+ FUNC_ENTER_NOAPI(H5T_get_member_type, NULL)
assert(dt);
assert(membno >=0 && membno < dt->shared->u.compnd.nmembs);
- /* Copy data type into an atom */
+ /* Copy datatype into an atom */
if (NULL == (ret_value = H5T_copy(dt->shared->u.compnd.memb[membno].type, H5T_COPY_REOPEN)))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy member data type");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy member datatype")
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_get_member_size
+ *
+ * Purpose: Returns the size of the specified member.
+ *
+ * Return: Success: The size in bytes of the member's datatype.
+ *
+ * Failure: 0
+ *
+ * Programmer: Quincey Koziol
+ * October 4, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+size_t
+H5T_get_member_size(H5T_t *dt, int membno)
+{
+ size_t ret_value = 0;
+
+ FUNC_ENTER_NOAPI(H5T_get_member_size, 0);
+
+ assert(dt);
+ assert(membno >=0 && membno < dt->shared->u.compnd.nmembs);
+ /* Value */
+ ret_value = dt->shared->u.compnd.memb[membno].type->shared->size;
+
done:
FUNC_LEAVE_NOAPI(ret_value);
}
@@ -278,10 +313,10 @@ done:
/*-------------------------------------------------------------------------
* Function: H5Tinsert
*
- * Purpose: Adds another member to the compound data type PARENT_ID. The
+ * Purpose: Adds another member to the compound datatype PARENT_ID. The
* new member has a NAME which must be unique within the
- * compound data type. The OFFSET argument defines the start of
- * the member in an instance of the compound data type, and
+ * compound datatype. The OFFSET argument defines the start of
+ * the member in an instance of the compound datatype, and
* MEMBER_ID is the type of the new member.
*
* Return: Success: Non-negative, the PARENT_ID compound data
@@ -302,38 +337,38 @@ done:
herr_t
H5Tinsert(hid_t parent_id, const char *name, size_t offset, hid_t member_id)
{
- H5T_t *parent = NULL; /*the compound parent data type */
+ H5T_t *parent = NULL; /*the compound parent datatype */
H5T_t *member = NULL; /*the atomic member type */
herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_API(H5Tinsert, FAIL);
+ FUNC_ENTER_API(H5Tinsert, FAIL)
H5TRACE4("e","iszi",parent_id,name,offset,member_id);
/* Check args */
if (parent_id==member_id)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "can't insert compound datatype within itself");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "can't insert compound datatype within itself")
if (NULL == (parent = H5I_object_verify(parent_id,H5I_DATATYPE)) || H5T_COMPOUND != parent->shared->type)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound data type");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound datatype")
if (H5T_STATE_TRANSIENT!=parent->shared->state)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "parent type read-only");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "parent type read-only")
if (!name || !*name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no member name");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no member name")
if (NULL == (member = H5I_object_verify(member_id,H5I_DATATYPE)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
/* Insert */
if (H5T_insert(parent, name, offset, member) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "unable to insert member");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "unable to insert member")
done:
- FUNC_LEAVE_API(ret_value);
+ FUNC_LEAVE_API(ret_value)
}
/*-------------------------------------------------------------------------
* Function: H5Tpack
*
- * Purpose: Recursively removes padding from within a compound data type
+ * Purpose: Recursively removes padding from within a compound datatype
* to make it more efficient (space-wise) to store that data.
*
* Return: Non-negative on success/Negative on failure
@@ -351,26 +386,26 @@ H5Tpack(hid_t type_id)
H5T_t *dt = NULL;
herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_API(H5Tpack, FAIL);
+ FUNC_ENTER_API(H5Tpack, FAIL)
H5TRACE1("e","i",type_id);
/* Check args */
if (NULL == (dt = H5I_object_verify(type_id,H5I_DATATYPE)) || H5T_detect_class(dt,H5T_COMPOUND)<=0)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound data type");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound datatype")
/* Pack */
if (H5T_pack(dt) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack compound data type");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack compound datatype")
done:
- FUNC_LEAVE_API(ret_value);
+ FUNC_LEAVE_API(ret_value)
}
/*-------------------------------------------------------------------------
* Function: H5T_insert
*
- * Purpose: Adds a new MEMBER to the compound data type PARENT. The new
+ * Purpose: Adds a new MEMBER to the compound datatype PARENT. The new
* member will have a NAME that is unique within PARENT and an
* instance of PARENT will have the member begin at byte offset
* OFFSET from the beginning.
@@ -389,10 +424,10 @@ herr_t
H5T_insert(H5T_t *parent, const char *name, size_t offset, const H5T_t *member)
{
int idx, i;
- size_t total_size;
+ size_t total_size;
herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5T_insert, FAIL);
+ FUNC_ENTER_NOAPI(H5T_insert, FAIL)
/* check args */
assert(parent && H5T_COMPOUND == parent->shared->type);
@@ -403,7 +438,7 @@ H5T_insert(H5T_t *parent, const char *name, size_t offset, const H5T_t *member)
/* Does NAME already exist in PARENT? */
for (i=0; i<parent->shared->u.compnd.nmembs; i++) {
if (!HDstrcmp(parent->shared->u.compnd.memb[i].name, name))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "member name is not unique");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "member name is not unique")
}
/* Does the new member overlap any existing member ? */
@@ -414,12 +449,12 @@ H5T_insert(H5T_t *parent, const char *name, size_t offset, const H5T_t *member)
(parent->shared->u.compnd.memb[i].offset <= offset &&
parent->shared->u.compnd.memb[i].offset +
parent->shared->u.compnd.memb[i].size > offset))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "member overlaps with another member");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "member overlaps with another member")
}
/* Does the new member overlap the end of the compound type? */
if(offset+total_size>parent->shared->size)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "member extends past end of compound type");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, FAIL, "member extends past end of compound type")
/* Increase member array if necessary */
if (parent->shared->u.compnd.nmembs >= parent->shared->u.compnd.nalloc) {
@@ -428,7 +463,7 @@ H5T_insert(H5T_t *parent, const char *name, size_t offset, const H5T_t *member)
na * sizeof(H5T_cmemb_t));
if (!x)
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed");
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
parent->shared->u.compnd.nalloc = (int)na;
parent->shared->u.compnd.memb = x;
}
@@ -473,14 +508,14 @@ H5T_insert(H5T_t *parent, const char *name, size_t offset, const H5T_t *member)
parent->shared->force_conv=TRUE;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
/*-------------------------------------------------------------------------
* Function: H5T_pack
*
- * Purpose: Recursively packs a compound data type by removing padding
+ * Purpose: Recursively packs a compound datatype by removing padding
* bytes. This is done in place (that is, destructively).
*
* Return: Non-negative on success/Negative on failure
@@ -499,7 +534,7 @@ H5T_pack(H5T_t *dt)
size_t offset;
herr_t ret_value=SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5T_pack);
+ FUNC_ENTER_NOAPI_NOINIT(H5T_pack)
assert(dt);
@@ -510,11 +545,11 @@ H5T_pack(H5T_t *dt)
/* Check for packing unmodifiable datatype */
if (H5T_STATE_TRANSIENT!=dt->shared->state)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "datatype is read-only");
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "datatype is read-only")
if(dt->shared->parent) {
if (H5T_pack(dt->shared->parent) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack parent of datatype");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack parent of datatype")
/* Adjust size of datatype appropriately */
if(dt->shared->type==H5T_ARRAY)
@@ -526,10 +561,11 @@ H5T_pack(H5T_t *dt)
/* Recursively pack the members */
for (i=0; i<dt->shared->u.compnd.nmembs; i++)
if (H5T_pack(dt->shared->u.compnd.memb[i].type) < 0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack part of a compound data type");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack part of a compound datatype")
/* Remove padding between members */
- H5T_sort_value(dt, NULL);
+ if(H5T_sort_value(dt, NULL)<0)
+ HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOMPARE, FAIL, "value sort failed")
for (i=0, offset=0; i<dt->shared->u.compnd.nmembs; i++) {
dt->shared->u.compnd.memb[i].offset = offset;
offset += dt->shared->u.compnd.memb[i].size;
@@ -544,7 +580,7 @@ H5T_pack(H5T_t *dt)
} /* end if */
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
}
@@ -568,7 +604,7 @@ H5T_is_packed(H5T_t *dt)
{
htri_t ret_value=TRUE; /* Return value */
- FUNC_ENTER_NOAPI(H5T_is_packed,FAIL);
+ FUNC_ENTER_NOAPI(H5T_is_packed,FAIL)
assert(dt);
@@ -581,6 +617,6 @@ H5T_is_packed(H5T_t *dt)
ret_value=dt->shared->u.compnd.packed;
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T_is_packed() */