[svn-r16308] Purpose: Fix problem with H5Tpack

Description:
If a compound type was packed except for some extra space at the end, H5Tpack
would not modify the type and the extra space would remain.  Changed
H5T_is_packed to fix this behaviour.

Tested: jam, smirom (h5committest - linew down)
This commit is contained in:
Neil Fortner 2009-01-14 10:30:51 -05:00
parent a365f0e6aa
commit 6564dbcfaa
3 changed files with 140 additions and 11 deletions

View File

@ -141,6 +141,8 @@ Bug Fixes since HDF5-1.8.0 release
Library 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 - Fixed up some old v2 btree assertions that get run in debug mode that
were previously failing on compilation, and removed some of the were previously failing on compilation, and removed some of the
more heavily outdated and non-rewritable ones. (MAM - 2008/12/15) more heavily outdated and non-rewritable ones. (MAM - 2008/12/15)

View File

@ -631,8 +631,13 @@ H5T_is_packed(const H5T_t *dt)
dt = dt->shared->parent; dt = dt->shared->parent;
/* If this is a compound datatype, check if it is packed */ /* If this is a compound datatype, check if it is packed */
if(dt->shared->type == H5T_COMPOUND) if(dt->shared->type == H5T_COMPOUND) {
ret_value = (htri_t)dt->shared->u.compnd.packed; 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) FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T_is_packed() */ } /* end H5T_is_packed() */

View File

@ -2958,8 +2958,6 @@ test_compound_16(void)
} cmpd_struct; } cmpd_struct;
cmpd_struct wdata1 = {1254, 5471}; cmpd_struct wdata1 = {1254, 5471};
cmpd_struct rdata;
int wdata2[2] = {1, 2};
int obj_count; int obj_count;
hid_t file; hid_t file;
hid_t cmpd_m_tid, cmpd_f_tid, int_id; hid_t cmpd_m_tid, cmpd_f_tid, int_id;
@ -3024,6 +3022,129 @@ error:
return 1; return 1;
} /* end test_compound_16() */ } /* end test_compound_16() */
/*-------------------------------------------------------------------------
* 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 * Function: test_query
@ -5719,6 +5840,7 @@ main(void)
nerrors += test_compound_14(); nerrors += test_compound_14();
nerrors += test_compound_15(); nerrors += test_compound_15();
nerrors += test_compound_16(); nerrors += test_compound_16();
nerrors += test_compound_17();
nerrors += test_conv_enum_1(); nerrors += test_conv_enum_1();
nerrors += test_conv_enum_2(); nerrors += test_conv_enum_2();
nerrors += test_conv_bitfield(); nerrors += test_conv_bitfield();