summaryrefslogtreecommitdiffstats
path: root/src/H5T.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1997-12-16 21:08:26 (GMT)
committerRobb Matzke <matzke@llnl.gov>1997-12-16 21:08:26 (GMT)
commite615fc7a982c1817cf7d4c24adf9323604692310 (patch)
tree5dab77c6c1a4476ab5b5953c45f1ea6a1b5d994e /src/H5T.c
parentfaca6fbaa8c557b18d6b264841fc8717d1e73816 (diff)
downloadhdf5-e615fc7a982c1817cf7d4c24adf9323604692310.zip
hdf5-e615fc7a982c1817cf7d4c24adf9323604692310.tar.gz
hdf5-e615fc7a982c1817cf7d4c24adf9323604692310.tar.bz2
[svn-r146] ./src/H5.c
Changes to error handling. ./src/H5B.c Increased size of internal static buffers. ./src/H5C.c Fixed syntax error when NDEBUG is defined. ./src/H5E.c ./src/H5Eprivate.h ./src/H5Epublic.h Errors can now be printed with H5Eprint(). Other minor changes to names and arg types. ./src/H5F.c The base address is now stored in the boot block. The user block size and the base address are synonyms. ./src/H5Fstdio.c Fixed a bug with a return value from fseek(). ./src/H5H.c Added alignment constraints to get rid of unaligned access errors on the DEC alpha having to do with the heap free list. ./src/H5P.c ./src/H5Ppublic.h Changed some size arguments from int to size_t and fixed memory allocation calls. ./src/H5T.c ./src/H5Tpublic.h Changed the order of functions so all the public ones are at the top of the file. Other minor changes. ./src/H5detect.c Added a newline to a string constant.
Diffstat (limited to 'src/H5T.c')
-rw-r--r--src/H5T.c447
1 files changed, 230 insertions, 217 deletions
diff --git a/src/H5T.c b/src/H5T.c
index 2618f14..414349a 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -139,74 +139,140 @@ H5Tcreate (H5T_class_t type, size_t size)
/*-------------------------------------------------------------------------
- * Function: H5T_create
+ * Function: H5Tcopy
*
- * Purpose: Creates a new data type and initializes it to reasonable
- * values. The new data type is SIZE bytes and an instance of
- * the class TYPE.
+ * Purpose: Copies a data type. The resulting data type is not locked.
+ * The data type should be closed when no longer needed by
+ * calling H5Tclose().
*
- * Return: Success: Pointer to the new type.
+ * Return: Success: The ID of a new data type.
*
- * Failure: NULL
+ * Failure: FAIL
*
* Programmer: Robb Matzke
- * Friday, December 5, 1997
+ * Tuesday, December 9, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
-H5T_t *
-H5T_create (H5T_class_t type, size_t size)
+hid_t
+H5Tcopy (hid_t type_id)
{
H5T_t *dt = NULL;
+ H5T_t *new_dt = NULL;
+ hid_t ret_value = FAIL;
- FUNC_ENTER (H5T_create, NULL);
+ FUNC_ENTER (H5Tcopy, FAIL);
+ H5ECLEAR;
- assert (size>0);
+ /* check args */
+ if (H5_DATATYPE!=H5Aatom_group (type_id) ||
+ NULL==(dt=H5Aatom_object (type_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+ }
- switch (type) {
- case H5T_FIXED:
- /* Default type is a native `int' */
- if (NULL==(dt=H5T_copy (H5Aatom_object (H5T_NATIVE_INT)))) {
- HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, NULL,
- "can't derive type from native int");
- }
- break;
+ /* copy */
+ if (NULL==(new_dt = H5T_copy (dt))) {
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't copy");
+ }
- case H5T_FLOAT:
- /* Default type is a native `double' */
- if (NULL==(dt=H5T_copy (H5Aatom_object (H5T_NATIVE_DOUBLE)))) {
- HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, NULL,
- "can't derive type from native double");
- }
- break;
+ /* atomize result */
+ if ((ret_value=H5Aregister_atom (H5_DATATYPE, new_dt))<0) {
+ H5T_close (new_dt);
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
+ "can't register data type atom");
+ }
- case H5T_DATE:
- case H5T_STRING:
- case H5T_BITFIELD:
- case H5T_OPAQUE:
- assert ("not implemented yet" && 0);
- HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, NULL,
- "not implemented yet");
+ FUNC_LEAVE (ret_value);
+}
- case H5T_COMPOUND:
- dt = H5MM_xcalloc (1, sizeof(H5T_t));
- dt->type = type;
- break;
+
+/*-------------------------------------------------------------------------
+ * Function: H5Tclose
+ *
+ * Purpose: Frees a data type and all associated memory.
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Robb Matzke
+ * Tuesday, December 9, 1997
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5Tclose (hid_t type_id)
+{
+ H5T_t *dt = NULL;
+
+ FUNC_ENTER (H5Tclose, FAIL);
+ H5ECLEAR;
- default:
- HRETURN_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, NULL,
- "unknown data type class");
+ /* check args */
+ if (H5_DATATYPE!=H5Aatom_group (type_id) ||
+ NULL==(dt=H5Aatom_object (type_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+ }
+ if (dt->locked) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "predefined data type");
}
- dt->size = size;
- FUNC_LEAVE (dt);
+ /* When the reference count reaches zero the resources are freed */
+ if (H5A_dec_ref (type_id)<0) {
+ HRETURN_ERROR (H5E_ATOM, H5E_BADATOM, FAIL, "problem freeing id");
+ }
+
+ FUNC_LEAVE (SUCCEED);
}
/*-------------------------------------------------------------------------
- * Function: H5Tget_num_members
+ * Function: H5Tequal
+ *
+ * Purpose: Determines if two data types are equal.
+ *
+ * Return: Success: TRUE if equal, FALSE if unequal
+ *
+ * Failure: FAIL
+ *
+ * Errors:
+ *
+ * Programmer: Robb Matzke
+ * Wednesday, December 10, 1997
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hbool_t
+H5Tequal (hid_t type1_id, hid_t type2_id)
+{
+ const H5T_t *dt1 = NULL;
+ const H5T_t *dt2 = NULL;
+ hbool_t ret_value = FAIL;
+
+ FUNC_ENTER (H5Tequal, FAIL);
+
+ /* check args */
+ if (H5_DATATYPE!=H5Aatom_group (type1_id) ||
+ NULL==(dt1=H5Aatom_object (type1_id)) ||
+ H5_DATATYPE!=H5Aatom_group (type2_id) ||
+ NULL==(dt2=H5Aatom_object (type2_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+ }
+
+ ret_value = (0==H5T_cmp (dt1, dt2));
+
+ FUNC_LEAVE (ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5Tget_nmembers
*
* Purpose: Determines how many members compound data type TYPE_ID has.
*
@@ -225,7 +291,7 @@ H5T_create (H5T_class_t type, size_t size)
*-------------------------------------------------------------------------
*/
intn
-H5Tget_num_members (hid_t type_id)
+H5Tget_nmembers (hid_t type_id)
{
H5T_t *dt = NULL;
@@ -278,7 +344,6 @@ H5Tget_class (hid_t type_id)
FUNC_LEAVE (dt->type);
}
-
/*-------------------------------------------------------------------------
* Function: H5Tget_size
@@ -321,36 +386,6 @@ H5Tget_size (hid_t type_id)
/*-------------------------------------------------------------------------
- * Function: H5T_get_size
- *
- * Purpose: Determines the total size of a data type in bytes.
- *
- * Return: Success: Size of the data type in bytes. The size of
- * the data type is the size of an instance of
- * that data type.
- *
- * Failure: 0 (valid data types are never zero size)
- *
- * Programmer: Robb Matzke
- * Tuesday, December 9, 1997
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-size_t
-H5T_get_size (const H5T_t *dt)
-{
- FUNC_ENTER (H5T_get_size, 0);
-
- /* check args */
- assert (dt);
-
- FUNC_LEAVE (dt->size);
-}
-
-
-/*-------------------------------------------------------------------------
* Function: H5Tinsert_member
*
* Purpose: Adds another member to the compound data type PARENT_ID. The
@@ -414,116 +449,83 @@ H5Tinsert_member (hid_t parent_id, const char *name, off_t offset,
FUNC_LEAVE (SUCCEED);
}
-
+
+
/*-------------------------------------------------------------------------
- * Function: H5T_insert_member
- *
- * Purpose: Adds a new MEMBER to the compound data type 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.
- *
- * Return: Success: SUCCEED
- *
- * Failure: FAIL
- *
- * Programmer: Robb Matzke
- * Monday, December 8, 1997
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
+ * API functions are above; library-private functions are below...
+ *-------------------------------------------------------------------------
*/
-herr_t
-H5T_insert_member (H5T_t *parent, const char *name, off_t offset,
- const H5T_t *member)
-{
- intn i;
- H5T_t *tmp = NULL;
-
- FUNC_ENTER (H5T_insert_member, FAIL);
- /* check args */
- assert (parent && H5T_COMPOUND==parent->type);
- assert (!parent->locked);
- assert (member && H5T_COMPOUND!=member->type);
- assert (name && *name);
- /* Does NAME already exist in PARENT? */
- for (i=0; i<parent->u.compnd.nmembs; i++) {
- if (!HDstrcmp (parent->u.compnd.memb[i].name, name)) {
- HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINSERT, FAIL,
- "member name is not unique");
- }
- }
- /* Increase member array if necessary */
- if (parent->u.compnd.nmembs>=parent->u.compnd.nalloc) {
- parent->u.compnd.nalloc += H5T_COMPND_INC;
- parent->u.compnd.memb = H5MM_xrealloc (parent->u.compnd.memb,
- (parent->u.compnd.nalloc*
- sizeof(H5T_member_t)));
- }
- /* Add member to end of member array */
- i = parent->u.compnd.nmembs;
- parent->u.compnd.memb[i].name = H5MM_xstrdup (name);
- parent->u.compnd.memb[i].offset = offset;
- parent->u.compnd.memb[i].ndims = 0; /*defaults to scalar*/
-
- tmp = H5T_copy (member);
- parent->u.compnd.memb[i].type = *tmp;
- H5MM_xfree (tmp);
- FUNC_LEAVE (SUCCEED);
-}
/*-------------------------------------------------------------------------
- * Function: H5Tcopy
+ * Function: H5T_create
*
- * Purpose: Copies a data type. The resulting data type is not locked.
+ * Purpose: Creates a new data type and initializes it to reasonable
+ * values. The new data type is SIZE bytes and an instance of
+ * the class TYPE.
*
- * Return: Success: The ID of a new data type.
+ * Return: Success: Pointer to the new type.
*
- * Failure: FAIL
+ * Failure: NULL
*
* Programmer: Robb Matzke
- * Tuesday, December 9, 1997
+ * Friday, December 5, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
-hid_t
-H5Tcopy (hid_t type_id)
+H5T_t *
+H5T_create (H5T_class_t type, size_t size)
{
H5T_t *dt = NULL;
- H5T_t *new_dt = NULL;
- hid_t ret_value = FAIL;
- FUNC_ENTER (H5Tcopy, FAIL);
- H5ECLEAR;
+ FUNC_ENTER (H5T_create, NULL);
- /* check args */
- if (H5_DATATYPE!=H5Aatom_group (type_id) ||
- NULL==(dt=H5Aatom_object (type_id))) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
- }
+ assert (size>0);
- /* copy */
- if (NULL==(new_dt = H5T_copy (dt))) {
- HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't copy");
- }
+ switch (type) {
+ case H5T_FIXED:
+ /* Default type is a native `int' */
+ if (NULL==(dt=H5T_copy (H5Aatom_object (H5T_NATIVE_INT)))) {
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, NULL,
+ "can't derive type from native int");
+ }
+ break;
- /* atomize result */
- if ((ret_value=H5Aregister_atom (H5_DATATYPE, new_dt))<0) {
- H5T_close (new_dt);
- HRETURN_ERROR (H5E_DATATYPE, H5E_CANTREGISTER, FAIL,
- "can't register data type atom");
+ case H5T_FLOAT:
+ /* Default type is a native `double' */
+ if (NULL==(dt=H5T_copy (H5Aatom_object (H5T_NATIVE_DOUBLE)))) {
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, NULL,
+ "can't derive type from native double");
+ }
+ break;
+
+ case H5T_DATE:
+ case H5T_STRING:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ assert ("not implemented yet" && 0);
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, NULL,
+ "not implemented yet");
+
+ case H5T_COMPOUND:
+ dt = H5MM_xcalloc (1, sizeof(H5T_t));
+ dt->type = type;
+ break;
+
+ default:
+ HRETURN_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, NULL,
+ "unknown data type class");
}
- FUNC_LEAVE (ret_value);
+ dt->size = size;
+ FUNC_LEAVE (dt);
}
@@ -577,7 +579,7 @@ H5T_copy (const H5T_t *old_dt)
/*-------------------------------------------------------------------------
- * Function: H5Tclose
+ * Function: H5T_close
*
* Purpose: Frees a data type and all associated memory.
*
@@ -586,32 +588,31 @@ H5T_copy (const H5T_t *old_dt)
* Failure: FAIL
*
* Programmer: Robb Matzke
- * Tuesday, December 9, 1997
+ * Monday, December 8, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
-H5Tclose (hid_t type_id)
+H5T_close (H5T_t *dt)
{
- H5T_t *dt = NULL;
+ intn i;
- FUNC_ENTER (H5Tclose, FAIL);
- H5ECLEAR;
+ FUNC_ENTER (H5T_close, FAIL);
- /* check args */
- if (H5_DATATYPE!=H5Aatom_group (type_id) ||
- NULL==(dt=H5Aatom_object (type_id))) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
- }
- if (dt->locked) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "predefined data type");
- }
+ assert (dt);
+ assert (!dt->locked);
- /* When the reference count reaches zero the resources are freed */
- if (H5A_dec_ref (type_id)<0) {
- HRETURN_ERROR (H5E_ATOM, H5E_BADATOM, FAIL, "problem freeing id");
+ if (dt && H5T_COMPOUND==dt->type) {
+ for (i=0; i<dt->u.compnd.nmembs; i++) {
+ H5MM_xfree (dt->u.compnd.memb[i].name);
+ }
+ H5MM_xfree (dt->u.compnd.memb);
+ H5MM_xfree (dt);
+
+ } else if (dt) {
+ H5MM_xfree (dt);
}
FUNC_LEAVE (SUCCEED);
@@ -619,85 +620,96 @@ H5Tclose (hid_t type_id)
/*-------------------------------------------------------------------------
- * Function: H5T_close
+ * Function: H5T_get_size
*
- * Purpose: Frees a data type and all associated memory.
+ * Purpose: Determines the total size of a data type in bytes.
*
- * Return: Success: SUCCEED
+ * Return: Success: Size of the data type in bytes. The size of
+ * the data type is the size of an instance of
+ * that data type.
*
- * Failure: FAIL
+ * Failure: 0 (valid data types are never zero size)
*
* Programmer: Robb Matzke
- * Monday, December 8, 1997
+ * Tuesday, December 9, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
-herr_t
-H5T_close (H5T_t *dt)
+size_t
+H5T_get_size (const H5T_t *dt)
{
- intn i;
-
- FUNC_ENTER (H5T_close, FAIL);
+ FUNC_ENTER (H5T_get_size, 0);
+ /* check args */
assert (dt);
- assert (!dt->locked);
- if (dt && H5T_COMPOUND==dt->type) {
- for (i=0; i<dt->u.compnd.nmembs; i++) {
- H5MM_xfree (dt->u.compnd.memb[i].name);
- }
- H5MM_xfree (dt->u.compnd.memb);
- H5MM_xfree (dt);
-
- } else if (dt) {
- H5MM_xfree (dt);
- }
-
- FUNC_LEAVE (SUCCEED);
+ FUNC_LEAVE (dt->size);
}
-
/*-------------------------------------------------------------------------
- * Function: H5Tequal
+ * Function: H5T_insert_member
*
- * Purpose: Determines if two data types are equal.
+ * Purpose: Adds a new MEMBER to the compound data type 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.
*
- * Return: Success: TRUE if equal, FALSE if unequal
+ * Return: Success: SUCCEED
*
* Failure: FAIL
*
- * Errors:
- *
* Programmer: Robb Matzke
- * Wednesday, December 10, 1997
+ * Monday, December 8, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
-hbool_t
-H5Tequal (hid_t type1_id, hid_t type2_id)
+herr_t
+H5T_insert_member (H5T_t *parent, const char *name, off_t offset,
+ const H5T_t *member)
{
- const H5T_t *dt1 = NULL;
- const H5T_t *dt2 = NULL;
- hbool_t ret_value = FAIL;
+ intn i;
+ H5T_t *tmp = NULL;
- FUNC_ENTER (H5Tequal, FAIL);
+ FUNC_ENTER (H5T_insert_member, FAIL);
/* check args */
- if (H5_DATATYPE!=H5Aatom_group (type1_id) ||
- NULL==(dt1=H5Aatom_object (type1_id)) ||
- H5_DATATYPE!=H5Aatom_group (type2_id) ||
- NULL==(dt2=H5Aatom_object (type2_id))) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data type");
+ assert (parent && H5T_COMPOUND==parent->type);
+ assert (!parent->locked);
+ assert (member && H5T_COMPOUND!=member->type);
+ assert (name && *name);
+
+ /* Does NAME already exist in PARENT? */
+ for (i=0; i<parent->u.compnd.nmembs; i++) {
+ if (!HDstrcmp (parent->u.compnd.memb[i].name, name)) {
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINSERT, FAIL,
+ "member name is not unique");
+ }
}
- ret_value = (0==H5T_cmp (dt1, dt2));
+ /* Increase member array if necessary */
+ if (parent->u.compnd.nmembs>=parent->u.compnd.nalloc) {
+ parent->u.compnd.nalloc += H5T_COMPND_INC;
+ parent->u.compnd.memb = H5MM_xrealloc (parent->u.compnd.memb,
+ (parent->u.compnd.nalloc*
+ sizeof(H5T_member_t)));
+ }
- FUNC_LEAVE (ret_value);
+ /* Add member to end of member array */
+ i = parent->u.compnd.nmembs;
+ parent->u.compnd.memb[i].name = H5MM_xstrdup (name);
+ parent->u.compnd.memb[i].offset = offset;
+ parent->u.compnd.memb[i].ndims = 0; /*defaults to scalar*/
+
+ tmp = H5T_copy (member);
+ parent->u.compnd.memb[i].type = *tmp;
+ H5MM_xfree (tmp);
+
+ FUNC_LEAVE (SUCCEED);
}
@@ -778,6 +790,7 @@ H5T_cmp (const H5T_t *dt1, const H5T_t *dt2)
}
#ifndef NDEBUG
+ /* I don't quite trust the code above yet :-) --RPM */
for (i=0; i<dt1->u.compnd.nmembs; i++) {
assert (HDstrcmp (dt1->u.compnd.memb[idx1[i]].name,
dt1->u.compnd.memb[idx1[i+1]].name));