summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2008-06-27 18:46:32 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2008-06-27 18:46:32 (GMT)
commit8776008f6648362656cf5a9208e67382137cc40b (patch)
treebd7ab157d083ec9e6cb4f6b58fa3f4125da35165
parentef6ebe54bbd60a7d4e259bff92decd2ead0510de (diff)
downloadhdf5-8776008f6648362656cf5a9208e67382137cc40b.zip
hdf5-8776008f6648362656cf5a9208e67382137cc40b.tar.gz
hdf5-8776008f6648362656cf5a9208e67382137cc40b.tar.bz2
[svn-r15290] H5Tpack didn't act correctly with nested compound datatype. The new size of the type in the
inner nest wasn't passed to the outer nest. This has been fixed. Tested on kagiso, linew, smirom.
-rw-r--r--src/H5Gname.c1
-rw-r--r--src/H5Tcompound.c14
-rw-r--r--test/dtypes.c109
3 files changed, 113 insertions, 11 deletions
diff --git a/src/H5Gname.c b/src/H5Gname.c
index 1efb91e..185da21 100644
--- a/src/H5Gname.c
+++ b/src/H5Gname.c
@@ -1173,4 +1173,3 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_get_name_by_addr() */
-
diff --git a/src/H5Tcompound.c b/src/H5Tcompound.c
index 9942ea1..3c9831b 100644
--- a/src/H5Tcompound.c
+++ b/src/H5Tcompound.c
@@ -31,7 +31,7 @@
#include "H5Tpkg.h" /*data-type functions */
/* Static local functions */
-static herr_t H5T_pack(const H5T_t *dt);
+static herr_t H5T_pack(const H5T_t *dt, size_t *new_size);
/*--------------------------------------------------------------------------
@@ -386,7 +386,7 @@ H5Tpack(hid_t type_id)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a compound datatype")
/* Pack */
- if (H5T_pack(dt) < 0)
+ if (H5T_pack(dt, NULL) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack compound datatype")
done:
@@ -524,7 +524,7 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5T_pack(const H5T_t *dt)
+H5T_pack(const H5T_t *dt, size_t *new_size)
{
unsigned i;
size_t offset;
@@ -544,7 +544,7 @@ H5T_pack(const H5T_t *dt)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "datatype is read-only")
if(dt->shared->parent) {
- if (H5T_pack(dt->shared->parent) < 0)
+ if (H5T_pack(dt->shared->parent, NULL) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack parent of datatype")
/* Adjust size of datatype appropriately */
@@ -556,7 +556,7 @@ H5T_pack(const H5T_t *dt)
else if(dt->shared->type==H5T_COMPOUND) {
/* 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)
+ if (H5T_pack(dt->shared->u.compnd.memb[i].type, &(dt->shared->u.compnd.memb[i].size)) < 0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to pack part of a compound datatype")
/* Remove padding between members */
@@ -570,6 +570,10 @@ H5T_pack(const H5T_t *dt)
/* Change total size */
dt->shared->size = MAX(1, offset);
+ /* Update the member size of compound type in higher level */
+ if(new_size)
+ *new_size = MAX(1, offset);
+
/* Mark the type as packed now */
dt->shared->u.compnd.packed=TRUE;
} /* end if */
diff --git a/test/dtypes.c b/test/dtypes.c
index 3dc5338..9b7e674 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -30,7 +30,7 @@
/* Number of elements in each test */
#define NTESTELEM 100000
-/* For test_compound_10 */
+/* For test_compound_8 and test_compound_10 */
#define ARRAY_DIM 4
/* Epsilon for floating-point comparisons */
@@ -1354,7 +1354,10 @@ test_compound_7(void)
* Wednesday, January 7, 1998
*
* Modifications:
- *
+ * Raymond Lu
+ * 27 June 2008
+ * Added verification of compound type size for H5Tpack and
+ * test for array of nested compound type.
*-------------------------------------------------------------------------
*/
static int
@@ -1369,12 +1372,16 @@ test_compound_8(void)
char c;
s1 d;
} s2;
-
- hid_t tid1, tid2, tid3;
+ hid_t tid1, tid1_copy, tid2, tid2_copy, tid3, arr_tid;
+ size_t tsize;
+ hsize_t dims[1] = {ARRAY_DIM};
herr_t ret;
TESTING("packing compound datatypes");
+ /*------------------------------------------------------------
+ * Test H5Tpack for compound type
+ */
/* Create first compound datatype */
if((tid1 = H5Tcreate( H5T_COMPOUND, sizeof(struct s1))) < 0) {
H5_FAILED(); AT();
@@ -1394,6 +1401,13 @@ test_compound_8(void)
goto error;
} /* end if */
+ /* Make a copy of the type for later use */
+ if((tid1_copy = H5Tcopy(tid1)) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't copy type #1\n");
+ goto error;
+ } /* end if */
+
/* Test H5Tpack for the first compound type */
if(H5Tpack(tid1) < 0) {
H5_FAILED(); AT();
@@ -1414,7 +1428,22 @@ test_compound_8(void)
goto error;
} /* end if */
+ /* Verify the size of packed compound type */
+ if((tsize = H5Tget_size(tid1)) == 0) {
+ H5_FAILED(); AT();
+ printf("Can't get size of the compound datatype\n");
+ goto error;
+ } /* end if */
+
+ if(tsize != (sizeof(char) + sizeof(int))) {
+ H5_FAILED(); AT();
+ printf("The size of the packed compound datatype is incorrect\n");
+ goto error;
+ } /* end if */
+ /*------------------------------------------------------------
+ * Test H5Tpack for nested compound type
+ */
/* Create second compound datatype */
if((tid2 = H5Tcreate( H5T_COMPOUND, sizeof(struct s2))) < 0) {
H5_FAILED(); AT();
@@ -1428,7 +1457,8 @@ test_compound_8(void)
goto error;
} /* end if */
- if(H5Tinsert(tid2,"d",HOFFSET(struct s2,d),tid1) < 0) {
+ /* Insert the member of unpacked compound type */
+ if(H5Tinsert(tid2,"d",HOFFSET(struct s2,d),tid1_copy) < 0) {
H5_FAILED(); AT();
printf("Can't insert field 'd'\n");
goto error;
@@ -1441,6 +1471,13 @@ test_compound_8(void)
goto error;
} /* end if */
+ /* Make a copy of the type for later */
+ if((tid2_copy = H5Tcopy(tid2)) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't copy type #2\n");
+ goto error;
+ } /* end if */
+
/* Test H5Tpack for the second compound type */
if(H5Tpack(tid2) < 0) {
H5_FAILED(); AT();
@@ -1478,6 +1515,68 @@ test_compound_8(void)
goto error;
} /* end if */
+ /* Verify the size of packed compound type */
+ if((tsize = H5Tget_size(tid2)) == 0) {
+ H5_FAILED(); AT();
+ printf("Can't get size of the compound datatype\n");
+ goto error;
+ } /* end if */
+
+ if(tsize != (sizeof(char) + sizeof(char) + sizeof(int))) {
+ H5_FAILED(); AT();
+ printf("The size of the packed compound datatype is incorrect\n");
+ goto error;
+ } /* end if */
+
+ /*------------------------------------------------------------
+ * Test H5Tpack for array type of nested compound type
+ */
+ /* Create an array type of compound type */
+ if((arr_tid = H5Tarray_create(tid2_copy, 1, dims)) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't create an array datatype\n");
+ goto error;
+ } /* end if */
+
+ /* Test H5Tpack for the array type */
+ if(H5Tpack(arr_tid) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't pack the array datatype\n");
+ goto error;
+ } /* end if */
+
+ /* Verify the size of packed compound type */
+ if((tsize = H5Tget_size(arr_tid)) == 0) {
+ H5_FAILED(); AT();
+ printf("Can't get size of the array datatype\n");
+ goto error;
+ } /* end if */
+
+ if(tsize != ARRAY_DIM * (sizeof(char) + sizeof(char) + sizeof(int))) {
+ H5_FAILED(); AT();
+ printf("The size of the packed array datatype is incorrect\n");
+ goto error;
+ } /* end if */
+
+
+ if(H5Tclose(tid1_copy) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't close the compound datatype\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tclose(tid2_copy) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't close the compound datatype\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tclose(arr_tid) < 0) {
+ H5_FAILED(); AT();
+ printf("Can't close the array datatype\n");
+ goto error;
+ } /* end if */
+
/* Can't release resources - they are locked */
PASSED();