summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2008-06-30 19:02:04 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2008-06-30 19:02:04 (GMT)
commit1f1221f81cf6299ad0cddb929864f2c9f4938795 (patch)
treec8f37b9976399133d7300f3c5a4e85f6b6f9653f
parent24e63e73301f8e2500da891fc1c7cf6f6102a411 (diff)
downloadhdf5-1f1221f81cf6299ad0cddb929864f2c9f4938795.zip
hdf5-1f1221f81cf6299ad0cddb929864f2c9f4938795.tar.gz
hdf5-1f1221f81cf6299ad0cddb929864f2c9f4938795.tar.bz2
[svn-r15298] Bug fix for H5Tpack. The problem was that H5Tpack didn't act correctly with nested
compound datatype. The size of compound type's member type wasn't updated. It's fixed in this commit. Tested on smirom. The same change was tested on three systems for v1.9.
-rw-r--r--src/H5Tcompound.c6
-rw-r--r--test/dtypes.c108
2 files changed, 109 insertions, 5 deletions
diff --git a/src/H5Tcompound.c b/src/H5Tcompound.c
index 5aa3f61..32d102b 100644
--- a/src/H5Tcompound.c
+++ b/src/H5Tcompound.c
@@ -554,10 +554,14 @@ H5T_pack(const H5T_t *dt)
} /* end if */
else if(dt->shared->type==H5T_COMPOUND) {
/* Recursively pack the members */
- for (i=0; i<dt->shared->u.compnd.nmembs; i++)
+ 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 datatype")
+ /* Update the member size */
+ dt->shared->u.compnd.memb[i].size = dt->shared->u.compnd.memb[i].type->shared->size;
+ }
+
/* Remove padding between members */
if(H5T_sort_value(dt, NULL)<0)
HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOMPARE, FAIL, "value sort failed")
diff --git a/test/dtypes.c b/test/dtypes.c
index e7ac9c5..49ec973 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
/* Define if you want to see a count of overflows */
@@ -1404,7 +1404,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
@@ -1420,11 +1423,16 @@ test_compound_8(void)
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 data types");
+ /*------------------------------------------------------------
+ * Test H5Tpack for compound type
+ */
/* Create first compound datatype */
if((tid1 = H5Tcreate( H5T_COMPOUND, sizeof(struct s1)))<0) {
H5_FAILED(); AT();
@@ -1444,6 +1452,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();
@@ -1464,7 +1479,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();
@@ -1478,7 +1508,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;
@@ -1491,6 +1522,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();
@@ -1528,6 +1566,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, NULL)) < 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();