[svn-r18648] In H5T_get_native_type of H5Tnative.c, I changed the way that the offset, alignment, and

size of nested compound type are calculated by using H5T_cmp_offset.  The old way had a bug 
in it (see bug #1850).

Tested on jam.  I tested the same change for 1.8 on amani, linew, and jam.
This commit is contained in:
Raymond Lu 2010-04-27 16:35:53 -05:00
parent daddb56a02
commit 6c5e42a967
6 changed files with 65 additions and 32 deletions

5
configure vendored
View File

@ -1,5 +1,5 @@
#! /bin/sh
# From configure.in Id: configure.in 18589 2010-04-18 13:59:45Z hdftest .
# From configure.in Id: configure.in 18634 2010-04-27 18:25:31Z koziol .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.65 for HDF5 1.9.68.
#
@ -27594,6 +27594,9 @@ else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <stdlib.h>
#include <string.h>
int main(void)
{
/* General variables */

View File

@ -3405,6 +3405,9 @@ if test ${ac_cv_sizeof_long_double} = 0; then
else
AC_CACHE_VAL([hdf5_cv_ullong_to_ldouble_precision],
[AC_TRY_RUN([
#include <stdlib.h>
#include <string.h>
int main(void)
{
/* General variables */

View File

@ -4588,7 +4588,7 @@ done:
/*-------------------------------------------------------------------------
* Function: H5D_chunk_bh_size
* Function: H5D_chunk_bh_info
*
* Purpose: Retrieve the amount of index storage for chunked dataset
*

View File

@ -148,6 +148,11 @@ done:
* Oct 3, 2002
*
* Modifications:
* Raymond Lu
* 27 April 2010
* I changed the way that the offset, alignment, and size of
* nested compound type are calculated by using H5T_cmp_offset.
* The old way had a bug in it (see bug #1850).
*
*-------------------------------------------------------------------------
*/
@ -312,12 +317,11 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot insert member to compound datatype")
}
/* Update size, offset and compound alignment for parent. */
if(offset)
*offset = *comp_size;
if(struct_align && *struct_align < children_st_align)
*struct_align = children_st_align;
*comp_size += children_size;
/* Update size, offset and compound alignment for parent in the case of
* nested compound type. */
if(H5T_cmp_offset(comp_size, offset, children_size, (size_t)1, children_st_align,
struct_align) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset")
/* Close member data type */
for(i=0; i<nmemb; i++) {

View File

@ -298,6 +298,7 @@ test_compound_dtype2(hid_t file)
typedef struct s2 {
short c2;
long l2;
long long ll2;
} s2;
typedef struct s1 {
char c;
@ -329,7 +330,8 @@ test_compound_dtype2(hid_t file)
temp_point->i = n++;
temp_point->st.c2 = (short)(i + j);
temp_point->st.l2 = (i * 5 + j * 50) * n;
temp_point->l = (unsigned long long)((i * 10 + j * 100) * n);
temp_point->st.ll2 = (i * 10 + j * 100) * n;
temp_point->l = (unsigned long long)((i * 100 + j * 1000) * n);
} /* end for */
} /* end for */
@ -339,37 +341,40 @@ test_compound_dtype2(hid_t file)
if((space = H5Screate_simple(2, dims, NULL)) < 0) TEST_ERROR;
/* Create compound datatype for disk storage */
#if H5_SIZEOF_LONG==4
if((tid2=H5Tcreate(H5T_COMPOUND, 6)) < 0) TEST_ERROR;
if((tid=H5Tcreate(H5T_COMPOUND, 19)) < 0) TEST_ERROR;
#elif H5_SIZEOF_LONG==8
if((tid2=H5Tcreate(H5T_COMPOUND, 10)) < 0) TEST_ERROR;
if((tid=H5Tcreate(H5T_COMPOUND, 23)) < 0) TEST_ERROR;
#else
#error "Unknown 'long' size"
#endif
if((tid2=H5Tcreate(H5T_COMPOUND, sizeof(s2))) < 0) TEST_ERROR;
if((tid=H5Tcreate(H5T_COMPOUND, sizeof(s1))) < 0) TEST_ERROR;
/* Insert and pack members */
if(H5Tinsert(tid2, "c2", 0, H5T_STD_I16BE) < 0) TEST_ERROR;
if(H5Tinsert(tid2, "c2", HOFFSET(s2, c2), H5T_STD_I16BE) < 0) TEST_ERROR;
#if H5_SIZEOF_LONG == 4
if(H5Tinsert(tid2, "l2", 2, H5T_STD_I32LE) < 0) TEST_ERROR;
if(H5Tinsert(tid2, "l2", HOFFSET(s2, l2), H5T_STD_I32LE) < 0) TEST_ERROR;
#elif H5_SIZEOF_LONG == 8
if(H5Tinsert(tid2, "l2", 2, H5T_STD_I64LE) < 0) TEST_ERROR;
if(H5Tinsert(tid2, "l2", HOFFSET(s2, l2), H5T_STD_I64LE) < 0) TEST_ERROR;
#else
#error "Unknown 'long' size"
#endif
#if H5_SIZEOF_LONG_LONG == 4
if(H5Tinsert(tid2, "ll2", HOFFSET(s2, ll2), H5T_STD_I32BE) < 0) TEST_ERROR;
#elif H5_SIZEOF_LONG_LONG == 8
if(H5Tinsert(tid2, "ll2", HOFFSET(s2, ll2), H5T_STD_I64BE) < 0) TEST_ERROR;
#else
#error "Unknown 'long long' size"
#endif
if(H5Tinsert(tid, "c", 0, H5T_STD_U8LE) < 0) TEST_ERROR;
if(H5Tinsert(tid, "i", 1, H5T_STD_I32LE) < 0) TEST_ERROR;
if(H5Tinsert(tid, "st", 5, tid2) < 0) TEST_ERROR;
#if H5_SIZEOF_LONG == 4
if(H5Tinsert(tid, "l", 11, H5T_STD_U64BE) < 0) TEST_ERROR;
#elif H5_SIZEOF_LONG == 8
if(H5Tinsert(tid, "l", 15, H5T_STD_U64BE) < 0) TEST_ERROR;
if(H5Tinsert(tid, "c", HOFFSET(s1, c), H5T_STD_U8LE) < 0) TEST_ERROR;
if(H5Tinsert(tid, "i", HOFFSET(s1, i), H5T_STD_I32LE) < 0) TEST_ERROR;
if(H5Tinsert(tid, "st", HOFFSET(s1, st), tid2) < 0) TEST_ERROR;
#if H5_SIZEOF_LONG_LONG == 4
if(H5Tinsert(tid, "l", HOFFSET(s1, l), H5T_STD_U32BE) < 0) TEST_ERROR;
#elif H5_SIZEOF_LONG_LONG == 8
if(H5Tinsert(tid, "l", HOFFSET(s1, l), H5T_STD_U64BE) < 0) TEST_ERROR;
#else
#error "Unknown 'long' size"
#error "Unknown 'long long' size"
#endif
/* Take away the paddings */
if(H5Tpack(tid) < 0) TEST_ERROR;
/* Create the dataset */
if((dataset = H5Dcreate2(file, DSET_COMPOUND_NAME_2, tid, space,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
@ -382,6 +387,7 @@ test_compound_dtype2(hid_t file)
/* Insert members */
if(H5Tinsert(tid_m2, "c2", HOFFSET(s2, c2), H5T_NATIVE_SHORT) < 0) TEST_ERROR;
if(H5Tinsert(tid_m2, "l2", HOFFSET(s2, l2), H5T_NATIVE_LONG) < 0) TEST_ERROR;
if(H5Tinsert(tid_m2, "ll2", HOFFSET(s2, ll2), H5T_NATIVE_LLONG) < 0) TEST_ERROR;
if(H5Tinsert(tid_m, "c", HOFFSET(s1, c), H5T_NATIVE_UCHAR) < 0) TEST_ERROR;
if(H5Tinsert(tid_m, "i", HOFFSET(s1, i), H5T_NATIVE_INT) < 0) TEST_ERROR;
if(H5Tinsert(tid_m, "st", HOFFSET(s1, st), tid_m2) < 0) TEST_ERROR;
@ -410,9 +416,9 @@ test_compound_dtype2(hid_t file)
/* check the char member */
if((mem_id = H5Tget_member_type(native_type, 0)) < 0)
TEST_ERROR;
if(H5Tget_order(mem_id) != H5Tget_order(H5T_NATIVE_UCHAR))
if(H5Tget_order(mem_id) != H5Tget_order(H5T_NATIVE_SCHAR))
TEST_ERROR;
if(H5Tget_size(mem_id) < H5Tget_size(H5T_STD_U8LE))
if(H5Tget_size(mem_id) < H5Tget_size(H5T_STD_I8LE))
TEST_ERROR;
if(H5T_INTEGER != H5Tget_class(mem_id))
TEST_ERROR;
@ -429,7 +435,7 @@ test_compound_dtype2(hid_t file)
TEST_ERROR;
H5Tclose(mem_id);
/* check the long long member */
/* check the unsigned long long member */
if((mem_id = H5Tget_member_type(native_type, 3)) < 0)
TEST_ERROR;
if(H5Tget_order(mem_id) != H5Tget_order(H5T_NATIVE_ULLONG))
@ -469,6 +475,21 @@ test_compound_dtype2(hid_t file)
TEST_ERROR;
H5Tclose(mem_id);
if((mem_id = H5Tget_member_type(nest_mem_id, 2)) < 0)
TEST_ERROR;
if(H5Tget_order(mem_id) != H5Tget_order(H5T_NATIVE_LLONG))
TEST_ERROR;
#if H5_SIZEOF_LONG_LONG==4
if(H5Tget_size(mem_id) < H5Tget_size(H5T_STD_I32LE)) TEST_ERROR;
#elif H5_SIZEOF_LONG_LONG==8
if(H5Tget_size(mem_id) < H5Tget_size(H5T_STD_I64LE)) TEST_ERROR;
#else
#error "Unknown 'long long' size"
#endif
if(H5T_INTEGER!=H5Tget_class(mem_id))
TEST_ERROR;
H5Tclose(mem_id);
/* Read the dataset back. Temporary buffer is for special platforms like
* Cray */
if(NULL == (tmp = HDmalloc(DIM0 * DIM1 * H5Tget_size(native_type))))
@ -496,6 +517,7 @@ test_compound_dtype2(hid_t file)
temp_point->i != temp_check->i ||
temp_point->st.c2 != temp_check->st.c2 ||
temp_point->st.l2 != temp_check->st.l2 ||
temp_point->st.ll2 != temp_check->st.ll2 ||
temp_point->l != temp_check->l ) {
H5_FAILED();
printf(" Read different values than written.\n");

View File

@ -2403,6 +2403,7 @@ main(int argc, const char *argv[])
break;
*oname = '\0';
} /* end while */
if(file < 0) {
fprintf(stderr, "%s: unable to open file\n", argv[argno-1]);
HDfree(fname);