From 53f5793d38fe137cd32fec38f8686bd21452d46f Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Tue, 27 Apr 2010 15:55:33 -0500 Subject: [svn-r18646] 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 amani, linew, and jam. --- bin/chkconfigure | 2 +- configure | 5 +++- configure.in | 3 +++ src/H5Dchunk.c | 2 +- src/H5Tnative.c | 16 ++++++++----- test/ntypes.c | 70 ++++++++++++++++++++++++++++++++++++------------------- tools/h5ls/h5ls.c | 1 + 7 files changed, 66 insertions(+), 33 deletions(-) diff --git a/bin/chkconfigure b/bin/chkconfigure index 67733ca..f819816 100755 --- a/bin/chkconfigure +++ b/bin/chkconfigure @@ -23,7 +23,7 @@ # variable initialization nerrors=0 -AUTOCONFVERSION=2.64 +AUTOCONFVERSION=2.65 AUTOCONFVERSIONLEAD='Generated by GNU Autoconf' CONFIGUREFILES="configure" diff --git a/configure b/configure index 671503f..ea7adf4 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Id: configure.in 18591 2010-04-19 00:22:22Z hdftest . +# From configure.in Id: configure.in 18434 2010-03-22 00:51:16Z hdftest . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.65 for HDF5 1.8.4-snap20. # @@ -27599,6 +27599,9 @@ else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ + #include + #include + int main(void) { /* General variables */ diff --git a/configure.in b/configure.in index 3149713..a1d77ac 100644 --- a/configure.in +++ b/configure.in @@ -3415,6 +3415,9 @@ if test ${ac_cv_sizeof_long_double} = 0; then else AC_CACHE_VAL([hdf5_cv_ullong_to_ldouble_precision], [AC_TRY_RUN([ + #include + #include + int main(void) { /* General variables */ diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index aad39ee..2e0b096 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -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 * diff --git a/src/H5Tnative.c b/src/H5Tnative.c index b22e3e5..ce2c141 100644 --- a/src/H5Tnative.c +++ b/src/H5Tnative.c @@ -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; ii = 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"); diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index c6eee3f..ab3a110 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -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); -- cgit v0.12