diff options
-rw-r--r-- | release_docs/RELEASE.txt | 2 | ||||
-rw-r--r-- | src/H5Tcompound.c | 9 | ||||
-rw-r--r-- | test/dtypes.c | 126 |
3 files changed, 133 insertions, 4 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index f7f9a52..19911d3 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -113,6 +113,8 @@ Bug Fixes since HDF5-1.8.2 Library ------- + - Fixed a bug where H5Tpack wouldn't remove trailing space from an otherwise + packed compound type. NAF - 2009/01/14 - Fixed up some old v2 btree assertions that get run in debug mode that were previously failing on compilation, and removed some of the more heavily outdated and non-rewritable ones. MAM - 2008/12/15 diff --git a/src/H5Tcompound.c b/src/H5Tcompound.c index d9b5974..68de174 100644 --- a/src/H5Tcompound.c +++ b/src/H5Tcompound.c @@ -631,8 +631,13 @@ H5T_is_packed(const H5T_t *dt) dt = dt->shared->parent; /* If this is a compound datatype, check if it is packed */ - if(dt->shared->type == H5T_COMPOUND) - ret_value = (htri_t)dt->shared->u.compnd.packed; + if(dt->shared->type == H5T_COMPOUND) { + H5T_compnd_t *compnd = &(dt->shared->u.compnd); /* Convenience pointer to compound info */ + ret_value = (htri_t)(compnd->packed + && compnd->memb[compnd->nmembs - 1].offset + + compnd->memb[compnd->nmembs - 1].size + == dt->shared->size); + } FUNC_LEAVE_NOAPI(ret_value) } /* end H5T_is_packed() */ diff --git a/test/dtypes.c b/test/dtypes.c index 3d0ac26..f4e0305 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -2959,8 +2959,6 @@ test_compound_16(void) } cmpd_struct; cmpd_struct wdata1 = {1254, 5471}; - cmpd_struct rdata; - int wdata2[2] = {1, 2}; int obj_count; hid_t file; hid_t cmpd_m_tid, cmpd_f_tid, int_id; @@ -3027,6 +3025,129 @@ error: /*------------------------------------------------------------------------- + * Function: test_compound_17 + * + * Purpose: Tests that compound types are packed correctly when they + * only have extra space at the end. The compounds are + * "hidden" inside arrays to make sure that they are still + * detected correctly. + * + * Return: Success: 0 + * + * Failure: number of errors + * + * Programmer: Neil Fortner + * Tuesday, January 13, 2009 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_compound_17(void) +{ + hid_t file; + hid_t cmpd_int, arr_int, cmpd_ext, arr_ext, tmp_dt; + hsize_t dims[1] = {2}; + char filename[1024]; + + TESTING("that H5Tpack removes trailing bytes"); + + /* Create inner compound datatype. This type will be "packed" according + * to the internal field, but will have trailing space at the end. */ + if((cmpd_int = H5Tcreate(H5T_COMPOUND, 4)) < 0) TEST_ERROR + if(H5Tinsert(cmpd_int, "c", 0, H5T_NATIVE_CHAR) < 0) TEST_ERROR + + /* Create inner array datatype */ + if((arr_int = H5Tarray_create2(cmpd_int, 1, dims)) < 0) TEST_ERROR + + /* Create outer compound datatype. This type will be truly packed, with no + * trailing space. However, the internal compound contained within is not + * packed. */ + if((cmpd_ext = H5Tcreate(H5T_COMPOUND, 8)) < 0) TEST_ERROR + if(H5Tinsert(cmpd_ext, "arr", 0, arr_int) < 0) TEST_ERROR + + /* Create outer array datatype */ + if((arr_ext = H5Tarray_create2(cmpd_ext, 1, dims)) < 0) TEST_ERROR + + /* Try packing the internal array. Size should be 2 after packing. */ + if((tmp_dt = H5Tcopy(arr_int)) < 0) TEST_ERROR + if(H5Tpack(tmp_dt) < 0) TEST_ERROR + if(2 != H5Tget_size(tmp_dt)) { + H5_FAILED(); AT(); + printf(" Size after packing: %d; expected: 2\n", H5Tget_size(tmp_dt)); + goto error; + } + if(H5Tclose(tmp_dt) < 0) TEST_ERROR + + /* Try packing the external array. Size should be 4 after packing. */ + if((tmp_dt = H5Tcopy(arr_ext)) < 0) TEST_ERROR + if(H5Tpack(tmp_dt) < 0) TEST_ERROR + if(4 != H5Tget_size(tmp_dt)) { + H5_FAILED(); AT(); + printf(" Size after packing: %d; expected: 4\n", H5Tget_size(tmp_dt)); + goto error; + } + if(H5Tclose(tmp_dt) < 0) TEST_ERROR + + /* Now we will commit arr_int and arr_ext to a file, and verify that they + * are still packed correctly after opening them from the file */ + /* Create File */ + h5_fixname(FILENAME[3], H5P_DEFAULT, filename, sizeof filename); + if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* Commit the datatypes. Note that they are still unpacked. */ + if(H5Tcommit2(file, "arr_int", arr_int, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + if(H5Tcommit2(file, "arr_ext", arr_ext, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Close IDs */ + if(H5Tclose(cmpd_int) < 0) TEST_ERROR + if(H5Tclose(arr_int) < 0) TEST_ERROR + if(H5Tclose(cmpd_ext) < 0) TEST_ERROR + if(H5Tclose(arr_ext) < 0) TEST_ERROR + if(H5Fclose(file) < 0) TEST_ERROR + + /* Reopen file */ + if((file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR + + /* Open committed array datatypes */ + if((arr_int = H5Topen2(file, "arr_int", H5P_DEFAULT)) < 0) TEST_ERROR + if((arr_ext = H5Topen2(file, "arr_ext", H5P_DEFAULT)) < 0) TEST_ERROR + + /* Try packing the internal array. Size should be 2 after packing. */ + if((tmp_dt = H5Tcopy(arr_int)) < 0) TEST_ERROR + if(H5Tpack(tmp_dt) < 0) TEST_ERROR + if(2 != H5Tget_size(tmp_dt)) { + H5_FAILED(); AT(); + printf(" Size after packing: %d; expected: 2\n", H5Tget_size(tmp_dt)); + goto error; + } + if(H5Tclose(tmp_dt) < 0) TEST_ERROR + + /* Try packing the external array. Size should be 4 after packing. */ + if((tmp_dt = H5Tcopy(arr_ext)) < 0) TEST_ERROR + if(H5Tpack(tmp_dt) < 0) TEST_ERROR + if(4 != H5Tget_size(tmp_dt)) { + H5_FAILED(); AT(); + printf(" Size after packing: %d; expected: 4\n", H5Tget_size(tmp_dt)); + goto error; + } + if(H5Tclose(tmp_dt) < 0) TEST_ERROR + + /* Close IDs */ + if(H5Tclose(arr_int) < 0) TEST_ERROR + if(H5Tclose(arr_ext) < 0) TEST_ERROR + if(H5Fclose(file) < 0) TEST_ERROR + + PASSED(); + return 0; + +error: + return 1; +} /* end test_compound_17() */ + + +/*------------------------------------------------------------------------- * Function: test_query * * Purpose: Tests query functions of compound and enumeration types. @@ -5720,6 +5841,7 @@ main(void) nerrors += test_compound_14(); nerrors += test_compound_15(); nerrors += test_compound_16(); + nerrors += test_compound_17(); nerrors += test_conv_enum_1(); nerrors += test_conv_enum_2(); nerrors += test_conv_bitfield(); |