diff options
author | Jonathan Kim <jkm@hdfgroup.org> | 2010-12-28 18:08:40 (GMT) |
---|---|---|
committer | Jonathan Kim <jkm@hdfgroup.org> | 2010-12-28 18:08:40 (GMT) |
commit | 562ba69f3573acb5dd910dc227ca337320bbae8b (patch) | |
tree | d1f50b1f175b2ee2bf3b308b2ffa6cb17d5d4a8a | |
parent | 60b5523f8d8b339880698691274772b3a786c1fe (diff) | |
download | hdf5-562ba69f3573acb5dd910dc227ca337320bbae8b.zip hdf5-562ba69f3573acb5dd910dc227ca337320bbae8b.tar.gz hdf5-562ba69f3573acb5dd910dc227ca337320bbae8b.tar.bz2 |
[svn-r19892] Purpose:
Bug 2089 - GMQS: h5diff segfault on a compound dataset with fixed length +
vlen string type order
Description:
This is fix for the segfault when h5diff compares a compound dataset with
combination of fixed length string types and vlen string types in certain
orders. Optimized vlariable length string handling codes. The fix is
referred from h5dump handling vlen strings.
For testing, several compound datasets were added with various combinations.
Previous failed cases:
- Vlen string, Fixed length string, Vlen string, Fixed length string
- Fixed length string, Fixed length string, Vlen string, Vlen string
- Fixed length string, Vlen string, Fixed length string, Vlen string
Tested:
jam (linux32-LE), amani (linux64-LE), heiwa (linuxppc64-BE), tejeda (mac32-LE), linew (solaris-BE)
-rw-r--r-- | release_docs/RELEASE.txt | 3 | ||||
-rw-r--r-- | tools/h5diff/h5diffgentest.c | 664 | ||||
-rw-r--r-- | tools/h5diff/testfiles/h5diff_530.txt | 28 | ||||
-rw-r--r-- | tools/h5diff/testfiles/h5diff_comp_vl_strs.h5 | bin | 8504 -> 18536 bytes | |||
-rwxr-xr-x | tools/h5diff/testh5diff.sh | 8 | ||||
-rw-r--r-- | tools/lib/h5diff_array.c | 349 |
6 files changed, 737 insertions, 315 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 7deef78..3251577 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -486,6 +486,9 @@ Bug Fixes since HDF5-1.8.0 release Tools ----- + - Fixed h5diff for the segfault when compares compound datasets + with combination of fixed length string types and vlen string types + in certain orders. bug#2089 (JKM 2010/12/28) - Improve h5diff performance. 1) use HDmemcmp() before comparing each elements. 2) replace expensive H5Tequals() calls 3) retrieve datatype information at dataset level not each element level for compound diff --git a/tools/h5diff/h5diffgentest.c b/tools/h5diff/h5diffgentest.c index fd4f2a9..c3a92cb 100644 --- a/tools/h5diff/h5diffgentest.c +++ b/tools/h5diff/h5diffgentest.c @@ -2934,12 +2934,12 @@ out: * *-------------------------------------------------------------------------*/ #define STR_RANK 1 -#define VLSTR1_DIM 1 -#define FLSTR2_SIZE 21 -#define FLSTR2_DIM 1 -#define VLSTRARRY3_DIM 3 -#define FLSTRARRY4_DIM 3 -#define FLSTRARRY4_SIZE 30 +#define VLEN_STR_DIM 1 +#define FIXLEN_STR_SIZE 21 +#define FIXLEN_STR_DIM 1 +#define VLEN_STR_ARRY_DIM 3 +#define FIXLEN_STR_ARRY_DIM 3 +#define FIXLEN_STR_ARRY_SIZE 30 #define COMP_RANK 1 #define COMP_DIM 1 static int test_comp_vlen_strings(const char *fname1) @@ -2948,88 +2948,292 @@ static int test_comp_vlen_strings(const char *fname1) hid_t fid1; /* file id */ - /* compound datatype */ - typedef struct comp_t - { - char *str1; /* vlen string */ - char *str1_again; /* vlen string */ - char str2[FLSTR2_SIZE]; /* fixed len string */ - char str2_again[FLSTR2_SIZE]; /* fixed len string */ - char *str3[VLSTRARRY3_DIM]; /* vlen string array */ - char *str3_again[VLSTRARRY3_DIM]; /* vlen string array */ - char str4[FLSTRARRY4_DIM][FLSTRARRY4_SIZE]; /* fixed len string array */ - char str4_again[FLSTRARRY4_DIM][FLSTRARRY4_SIZE]; /* fixed len string array */ - } comp_t; - - /* vlen string1 */ - hid_t sid_str1=0; /* dataspace ID */ - hid_t tid_str1=0; /* datatype ID */ - hid_t did_str1=0; /* dataset ID */ - const char vlstr1_buf[]= { + /* compound1 datatype */ + typedef struct comp1_t + { + char *str_vlen; /* vlen string */ + char *str_vlen_repeat; /* vlen string */ + char str_fixlen[FIXLEN_STR_SIZE]; /* fixed len string */ + char str_fixlen_repeat[FIXLEN_STR_SIZE]; /* fixed len string */ + char *str_array_vlen[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char *str_vlen_array_again[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_array_fixlen[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char str_fixlen_array_again[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + } comp1_t; + + /* compound2 datatype */ + typedef struct comp2_t + { + char *str_vlen; /* vlen string */ + char str_fixlen[FIXLEN_STR_SIZE]; /* fixed len string */ + char *str_vlen_repeat; /* vlen string */ + char str_fixlen_repeat[FIXLEN_STR_SIZE]; /* fixed len string */ + char *str_array_vlen[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_array_fixlen[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_vlen_array_again[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_fixlen_array_again[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + } comp2_t; + + /* compound3 datatype */ + typedef struct comp3_t + { + char str_fixlen[FIXLEN_STR_SIZE]; /* fixed len string */ + char str_fixlen_repeat[FIXLEN_STR_SIZE]; /* fixed len string */ + char *str_vlen; /* vlen string */ + char *str_vlen_repeat; /* vlen string */ + char str_array_fixlen[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char str_fixlen_array_again[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_array_vlen[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char *str_vlen_array_again[VLEN_STR_ARRY_DIM]; /* vlen string array */ + } comp3_t; + + /* compound4 datatype */ + typedef struct comp4_t + { + char str_fixlen[FIXLEN_STR_SIZE]; /* fixed len string */ + char *str_vlen; /* vlen string */ + char str_fixlen_repeat[FIXLEN_STR_SIZE]; /* fixed len string */ + char *str_vlen_repeat; /* vlen string */ + char str_array_fixlen[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_array_vlen[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_fixlen_array_again[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_vlen_array_again[VLEN_STR_ARRY_DIM]; /* vlen string array */ + } comp4_t; + + /* compound5 datatype */ + typedef struct comp5_t + { + char *str_array_vlen[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char *str_vlen_array_again[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_array_fixlen[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char str_fixlen_array_again[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_vlen; /* vlen string */ + char *str_vlen_repeat; /* vlen string */ + char str_fixlen[FIXLEN_STR_SIZE]; /* fixed len string */ + char str_fixlen_repeat[FIXLEN_STR_SIZE]; /* fixed len string */ + } comp5_t; + + /* compound6 datatype */ + typedef struct comp6_t + { + char *str_array_vlen[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_array_fixlen[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_vlen_array_again[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_fixlen_array_again[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_vlen; /* vlen string */ + char str_fixlen[FIXLEN_STR_SIZE]; /* fixed len string */ + char *str_vlen_repeat; /* vlen string */ + char str_fixlen_repeat[FIXLEN_STR_SIZE]; /* fixed len string */ + } comp6_t; + + /* compound7 datatype */ + typedef struct comp7_t + { + char str_array_fixlen[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char str_fixlen_array_again[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_array_vlen[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char *str_vlen_array_again[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_fixlen[FIXLEN_STR_SIZE]; /* fixed len string */ + char str_fixlen_repeat[FIXLEN_STR_SIZE]; /* fixed len string */ + char *str_vlen; /* vlen string */ + char *str_vlen_repeat; /* vlen string */ + } comp7_t; + + /* compound8 datatype */ + typedef struct comp8_t + { + char str_array_fixlen[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_array_vlen[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_fixlen_array_again[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_vlen_array_again[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_fixlen[FIXLEN_STR_SIZE]; /* fixed len string */ + char *str_vlen; /* vlen string */ + char str_fixlen_repeat[FIXLEN_STR_SIZE]; /* fixed len string */ + char *str_vlen_repeat; /* vlen string */ + } comp8_t; + + /* compound9 datatype */ + typedef struct comp9_t + { + char str_array_fixlen[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char str_fixlen_array_again[FIXLEN_STR_ARRY_DIM][FIXLEN_STR_ARRY_SIZE]; /* fixed len string array */ + char *str_array_vlen[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char *str_vlen_array_again[VLEN_STR_ARRY_DIM]; /* vlen string array */ + char str_fixlen[FIXLEN_STR_SIZE]; /* fixed len string */ + int int_data1; + hobj_ref_t objref1; /* reference */ + char str_fixlen_repeat[FIXLEN_STR_SIZE]; /* fixed len string */ + hobj_ref_t objref2; /* reference */ + char *str_vlen; /* vlen string */ + int int_data2; + char *str_vlen_repeat; /* vlen string */ + hobj_ref_t objref3; /* reference */ + int int_data3; + } comp9_t; + + /* vlen string */ + hid_t sid_vlen_str=0; /* dataspace ID */ + hid_t tid_vlen_str=0; /* datatype ID */ + const char vlen_str_buf[]= { "Variable length string" }; - hsize_t dims_str1[] = {VLSTR1_DIM}; + hsize_t dims_vlen_str[] = {VLEN_STR_DIM}; - /* fixlen string2 */ - hid_t sid_str2=0; /* dataspace ID */ - hid_t tid_str2=0; /* datatype ID */ - hid_t did_str2=0; /* dataset ID */ - const char flstr2_buf[FLSTR2_SIZE]= { + /* fixlen string */ + hid_t sid_fixlen_str=0; /* dataspace ID */ + hid_t tid_fixlen_str=0; /* datatype ID */ + const char fixlen_str_buf[FIXLEN_STR_SIZE]= { "Fixed length string" }; - hsize_t dims_str2[] = {FLSTR2_DIM}; - - /* vlen string3 array */ - hid_t sid_str3=0; /* dataspace ID */ - hid_t tid_str3=0; /* datatype ID */ - hid_t tid_str3_array=0; /* datatype ID */ - hid_t did_str3=0; /* dataset ID */ - const char *vlstr3_buf[VLSTRARRY3_DIM]= { + hsize_t dims_fixlen_str[] = {FIXLEN_STR_DIM}; + + /* vlen string array */ + hid_t sid_vlen_str_array=0; /* dataspace ID */ + hid_t tid_vlen_str_array_pre=0; /* datatype ID */ + hid_t tid_vlen_str_array=0; /* datatype ID */ + const char *vlen_str_array_buf[VLEN_STR_ARRY_DIM]= { "1 - Variable length string Array", "2 - Testing variable length string array in compound type", "3 - Four score and seven\n years ago our forefathers brought forth on this continent a new nation," }; - hsize_t dims_str3[] = {VLSTRARRY3_DIM}; - - /* fixlen string array 4 */ - hid_t sid_str4=0; /* dataspace ID */ - hid_t tid_str4=0; /* datatype ID */ - hid_t tid_str4_array=0; /* datatype ID */ - hid_t did_str4=0; /* dataset ID */ - const char *flstr4_buf[FLSTRARRY4_DIM]= { + hsize_t dims_vlen_str_array[] = {VLEN_STR_ARRY_DIM}; + + /* fixlen string array */ + hid_t sid_fixlen_str_array=0; /* dataspace ID */ + hid_t tid_fixlen_str_array_pre=0; /* datatype ID */ + hid_t tid_fixlen_str_array=0; /* datatype ID */ + const char *fixlen_str_array_buf[FIXLEN_STR_ARRY_DIM]= { "1 - Fixed length string Array", "2 - Fixed length string Array", "3 - Fixed length string Array" }; - hsize_t dims_str4[] = {FLSTRARRY4_DIM}; + hsize_t dims_fixlen_str_array[] = {FIXLEN_STR_ARRY_DIM}; + + /* objref */ + hsize_t objref_dims[1]={1}; /*------------------------------------------ * compound dataset *------------------------------------------*/ hid_t sid_comp=0; /* dataspace ID */ - hid_t tid_comp=0; /* datatype ID */ + hid_t tid1_comp=0; /* datatype ID */ + hid_t tid2_comp=0; /* datatype ID */ + hid_t tid3_comp=0; /* datatype ID */ + hid_t tid4_comp=0; /* datatype ID */ + hid_t tid5_comp=0; /* datatype ID */ + hid_t tid6_comp=0; /* datatype ID */ + hid_t tid7_comp=0; /* datatype ID */ + hid_t tid8_comp=0; /* datatype ID */ + hid_t tid9_comp=0; /* datatype ID */ hid_t did_comp=0; /* dataset ID */ hsize_t dims_comp[] = {COMP_DIM}; herr_t status = SUCCEED; /* make compound strings data */ - comp_t comp_buf; + comp1_t comp1_buf; + comp2_t comp2_buf; + comp3_t comp3_buf; + comp4_t comp4_buf; + comp5_t comp5_buf; + comp6_t comp6_buf; + comp7_t comp7_buf; + comp8_t comp8_buf; + comp9_t comp9_buf; + + /* copy vlen string data to compound buffers */ + comp1_buf.str_vlen = comp1_buf.str_vlen_repeat = vlen_str_buf; + comp2_buf.str_vlen = comp2_buf.str_vlen_repeat = vlen_str_buf; + comp3_buf.str_vlen = comp3_buf.str_vlen_repeat = vlen_str_buf; + comp4_buf.str_vlen = comp4_buf.str_vlen_repeat = vlen_str_buf; + comp5_buf.str_vlen = comp5_buf.str_vlen_repeat = vlen_str_buf; + comp6_buf.str_vlen = comp6_buf.str_vlen_repeat = vlen_str_buf; + comp7_buf.str_vlen = comp7_buf.str_vlen_repeat = vlen_str_buf; + comp8_buf.str_vlen = comp8_buf.str_vlen_repeat = vlen_str_buf; + comp9_buf.str_vlen = comp9_buf.str_vlen_repeat = vlen_str_buf; + + /* copy fixlen string data to compound buffers */ + HDstrcpy(comp1_buf.str_fixlen, fixlen_str_buf); + HDstrcpy(comp1_buf.str_fixlen_repeat, fixlen_str_buf); + + HDstrcpy(comp2_buf.str_fixlen, fixlen_str_buf); + HDstrcpy(comp2_buf.str_fixlen_repeat, fixlen_str_buf); + + HDstrcpy(comp3_buf.str_fixlen, fixlen_str_buf); + HDstrcpy(comp3_buf.str_fixlen_repeat, fixlen_str_buf); + + HDstrcpy(comp3_buf.str_fixlen, fixlen_str_buf); + HDstrcpy(comp3_buf.str_fixlen_repeat, fixlen_str_buf); + + HDstrcpy(comp4_buf.str_fixlen, fixlen_str_buf); + HDstrcpy(comp4_buf.str_fixlen_repeat, fixlen_str_buf); + + HDstrcpy(comp5_buf.str_fixlen, fixlen_str_buf); + HDstrcpy(comp5_buf.str_fixlen_repeat, fixlen_str_buf); + + HDstrcpy(comp6_buf.str_fixlen, fixlen_str_buf); + HDstrcpy(comp6_buf.str_fixlen_repeat, fixlen_str_buf); - /* copy string1 type to compound buffer */ - comp_buf.str1 = comp_buf.str1_again = vlstr1_buf; - /* copy string2 type to compound buffer */ - HDstrcpy(comp_buf.str2, flstr2_buf); - HDstrcpy(comp_buf.str2_again, flstr2_buf); - /* copy string3 type to compound buffer */ - for (i=0; i < VLSTRARRY3_DIM; i++) - comp_buf.str3[i] = comp_buf.str3_again[i] = vlstr3_buf[i]; - /* copy string4 type to compound buffer */ - for (i=0; i < FLSTRARRY4_DIM; i++) + HDstrcpy(comp7_buf.str_fixlen, fixlen_str_buf); + HDstrcpy(comp7_buf.str_fixlen_repeat, fixlen_str_buf); + + HDstrcpy(comp8_buf.str_fixlen, fixlen_str_buf); + HDstrcpy(comp8_buf.str_fixlen_repeat, fixlen_str_buf); + + HDstrcpy(comp9_buf.str_fixlen, fixlen_str_buf); + HDstrcpy(comp9_buf.str_fixlen_repeat, fixlen_str_buf); + + /* copy vlen string array data to compound buffers */ + for (i=0; i < VLEN_STR_ARRY_DIM; i++) { - HDstrcpy(comp_buf.str4[i], flstr4_buf[i]); - HDstrcpy(comp_buf.str4_again[i], flstr4_buf[i]); + comp1_buf.str_array_vlen[i] = comp1_buf.str_vlen_array_again[i] = vlen_str_array_buf[i]; + comp2_buf.str_array_vlen[i] = comp2_buf.str_vlen_array_again[i] = vlen_str_array_buf[i]; + comp3_buf.str_array_vlen[i] = comp3_buf.str_vlen_array_again[i] = vlen_str_array_buf[i]; + comp4_buf.str_array_vlen[i] = comp4_buf.str_vlen_array_again[i] = vlen_str_array_buf[i]; + comp5_buf.str_array_vlen[i] = comp5_buf.str_vlen_array_again[i] = vlen_str_array_buf[i]; + comp6_buf.str_array_vlen[i] = comp6_buf.str_vlen_array_again[i] = vlen_str_array_buf[i]; + comp7_buf.str_array_vlen[i] = comp7_buf.str_vlen_array_again[i] = vlen_str_array_buf[i]; + comp8_buf.str_array_vlen[i] = comp8_buf.str_vlen_array_again[i] = vlen_str_array_buf[i]; + comp9_buf.str_array_vlen[i] = comp9_buf.str_vlen_array_again[i] = vlen_str_array_buf[i]; + } + /* copy fixlen string attay data to compound buffers */ + for (i=0; i < FIXLEN_STR_ARRY_DIM; i++) + { + HDstrcpy(comp1_buf.str_array_fixlen[i], fixlen_str_array_buf[i]); + HDstrcpy(comp1_buf.str_fixlen_array_again[i], fixlen_str_array_buf[i]); + + HDstrcpy(comp2_buf.str_array_fixlen[i], fixlen_str_array_buf[i]); + HDstrcpy(comp2_buf.str_fixlen_array_again[i], fixlen_str_array_buf[i]); + + HDstrcpy(comp3_buf.str_array_fixlen[i], fixlen_str_array_buf[i]); + HDstrcpy(comp3_buf.str_fixlen_array_again[i], fixlen_str_array_buf[i]); + + HDstrcpy(comp4_buf.str_array_fixlen[i], fixlen_str_array_buf[i]); + HDstrcpy(comp4_buf.str_fixlen_array_again[i], fixlen_str_array_buf[i]); + + HDstrcpy(comp5_buf.str_array_fixlen[i], fixlen_str_array_buf[i]); + HDstrcpy(comp5_buf.str_fixlen_array_again[i], fixlen_str_array_buf[i]); + + HDstrcpy(comp6_buf.str_array_fixlen[i], fixlen_str_array_buf[i]); + HDstrcpy(comp6_buf.str_fixlen_array_again[i], fixlen_str_array_buf[i]); + + HDstrcpy(comp7_buf.str_array_fixlen[i], fixlen_str_array_buf[i]); + HDstrcpy(comp7_buf.str_fixlen_array_again[i], fixlen_str_array_buf[i]); + + HDstrcpy(comp8_buf.str_array_fixlen[i], fixlen_str_array_buf[i]); + HDstrcpy(comp8_buf.str_fixlen_array_again[i], fixlen_str_array_buf[i]); + + HDstrcpy(comp9_buf.str_array_fixlen[i], fixlen_str_array_buf[i]); + HDstrcpy(comp9_buf.str_fixlen_array_again[i], fixlen_str_array_buf[i]); + } + + /* int data */ + comp9_buf.int_data1 = 10; + comp9_buf.int_data2 = 20; + comp9_buf.int_data3 = 30; + + /*----------------------------------------------------------------------- * Create file(s) *------------------------------------------------------------------------*/ @@ -3044,16 +3248,16 @@ static int test_comp_vlen_strings(const char *fname1) /*----------------------------------------------------------------------- * Variable length String1 - Create space and type *------------------------------------------------------------------------*/ - sid_str1 = H5Screate_simple(STR_RANK, dims_str1, NULL); - if (sid_str1 < 0) + sid_vlen_str = H5Screate_simple(STR_RANK, dims_vlen_str, NULL); + if (sid_vlen_str < 0) { fprintf(stderr, "Error: %s> H5Screate_simple failed.\n", fname1); status = FAIL; goto out; } - tid_str1 = H5Tcopy(H5T_C_S1); - status = H5Tset_size(tid_str1, H5T_VARIABLE); + tid_vlen_str = H5Tcopy(H5T_C_S1); + status = H5Tset_size(tid_vlen_str, H5T_VARIABLE); if (status < 0) { fprintf(stderr, "Error: %s> H5Tset_size failed.\n", fname1); @@ -3064,16 +3268,16 @@ static int test_comp_vlen_strings(const char *fname1) /*----------------------------------------------------------------------- * Fixed length String2 - Create space and type *------------------------------------------------------------------------*/ - sid_str2 = H5Screate_simple(STR_RANK, dims_str2, NULL); - if (sid_str2 < 0) + sid_fixlen_str = H5Screate_simple(STR_RANK, dims_fixlen_str, NULL); + if (sid_fixlen_str < 0) { fprintf(stderr, "Error: %s> H5Screate_simple failed.\n", fname1); status = FAIL; goto out; } - tid_str2 = H5Tcopy(H5T_C_S1); - status = H5Tset_size(tid_str2, FLSTR2_SIZE); + tid_fixlen_str = H5Tcopy(H5T_C_S1); + status = H5Tset_size(tid_fixlen_str, FIXLEN_STR_SIZE); if (status < 0) { fprintf(stderr, "Error: %s> H5Tset_size failed.\n", fname1); @@ -3084,16 +3288,16 @@ static int test_comp_vlen_strings(const char *fname1) /*----------------------------------------------------------------------- * Fixed length String3 array - Create space and type *------------------------------------------------------------------------*/ - sid_str3 = H5Screate_simple(STR_RANK, dims_str3, NULL); - if (sid_str3 < 0) + sid_vlen_str_array = H5Screate_simple(STR_RANK, dims_vlen_str_array, NULL); + if (sid_vlen_str_array < 0) { fprintf(stderr, "Error: %s> H5Screate_simple failed.\n", fname1); status = FAIL; goto out; } - tid_str3 = H5Tcopy(H5T_C_S1); - status = H5Tset_size(tid_str3, H5T_VARIABLE); + tid_vlen_str_array_pre = H5Tcopy(H5T_C_S1); + status = H5Tset_size(tid_vlen_str_array_pre, H5T_VARIABLE); if (status < 0) { fprintf(stderr, "Error: %s> H5Tset_size failed.\n", fname1); @@ -3102,8 +3306,8 @@ static int test_comp_vlen_strings(const char *fname1) } /* Create the array data type for the string array */ - tid_str3_array = H5Tarray_create2(tid_str3, COMP_RANK, dims_str3); - if (tid_str3_array < 0) + tid_vlen_str_array = H5Tarray_create2(tid_vlen_str_array_pre, COMP_RANK, dims_vlen_str_array); + if (tid_vlen_str_array < 0) { fprintf(stderr, "Error: %s> H5Tarray_create2 failed.\n", fname1); status = FAIL; @@ -3113,16 +3317,16 @@ static int test_comp_vlen_strings(const char *fname1) /*----------------------------------------------------------------------- * Variable length String4 array - Create space and type *------------------------------------------------------------------------*/ - sid_str4 = H5Screate_simple(STR_RANK, dims_str4, NULL); - if (sid_str4 < 0) + sid_fixlen_str_array = H5Screate_simple(STR_RANK, dims_fixlen_str_array, NULL); + if (sid_fixlen_str_array < 0) { fprintf(stderr, "Error: %s> H5Screate_simple failed.\n", fname1); status = FAIL; goto out; } - tid_str4 = H5Tcopy(H5T_C_S1); - status = H5Tset_size(tid_str4, FLSTRARRY4_SIZE); + tid_fixlen_str_array_pre = H5Tcopy(H5T_C_S1); + status = H5Tset_size(tid_fixlen_str_array_pre, FIXLEN_STR_ARRY_SIZE); if (status < 0) { fprintf(stderr, "Error: %s> H5Tset_size failed.\n", fname1); @@ -3130,8 +3334,8 @@ static int test_comp_vlen_strings(const char *fname1) goto out; } /* Create the array data type for the string array */ - tid_str4_array = H5Tarray_create2(tid_str4, COMP_RANK, dims_str4); - if (tid_str4_array < 0) + tid_fixlen_str_array = H5Tarray_create2(tid_fixlen_str_array_pre, COMP_RANK, dims_fixlen_str_array); + if (tid_fixlen_str_array < 0) { fprintf(stderr, "Error: %s> H5Tarray_create2 failed.\n", fname1); status = FAIL; @@ -3148,66 +3352,270 @@ static int test_comp_vlen_strings(const char *fname1) status = FAIL; goto out; } - tid_comp = H5Tcreate (H5T_COMPOUND, sizeof(comp_t)); - H5Tinsert(tid_comp, "VLEN_STR1", HOFFSET(comp_t, str1), tid_str1 ); - H5Tinsert(tid_comp, "VLEN_STR2", HOFFSET(comp_t, str1_again), tid_str1 ); - H5Tinsert(tid_comp, "FIXLEN_STR1", HOFFSET(comp_t, str2), tid_str2 ); - H5Tinsert(tid_comp, "FIXLEN_STR2", HOFFSET(comp_t, str2_again), tid_str2 ); - H5Tinsert(tid_comp, "VLEN_STR_ARRAY1", HOFFSET(comp_t, str3), tid_str3_array); - H5Tinsert(tid_comp, "VLEN_STR_ARRAY2", HOFFSET(comp_t, str3_again), tid_str3_array); - H5Tinsert(tid_comp, "FIXLEN_STR_ARRAY1", HOFFSET(comp_t, str4), tid_str4_array); - H5Tinsert(tid_comp, "FIXLEN_STR_ARRAY2", HOFFSET(comp_t, str4_again), tid_str4_array); - - /* Write data to compound dataset buffer */ - did_comp = H5Dcreate2(fid1, "Compound_dset", tid_comp, sid_comp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - status = H5Dwrite(did_comp, tid_comp, H5S_ALL, H5S_ALL, H5P_DEFAULT, &comp_buf); + tid1_comp = H5Tcreate (H5T_COMPOUND, sizeof(comp1_t)); + tid2_comp = H5Tcreate (H5T_COMPOUND, sizeof(comp2_t)); + tid3_comp = H5Tcreate (H5T_COMPOUND, sizeof(comp3_t)); + tid4_comp = H5Tcreate (H5T_COMPOUND, sizeof(comp4_t)); + tid5_comp = H5Tcreate (H5T_COMPOUND, sizeof(comp5_t)); + tid6_comp = H5Tcreate (H5T_COMPOUND, sizeof(comp6_t)); + tid7_comp = H5Tcreate (H5T_COMPOUND, sizeof(comp7_t)); + tid8_comp = H5Tcreate (H5T_COMPOUND, sizeof(comp8_t)); + tid9_comp = H5Tcreate (H5T_COMPOUND, sizeof(comp9_t)); + + /* compound 1 */ + H5Tinsert(tid1_comp, "VLEN_STR1", HOFFSET(comp1_t, str_vlen), tid_vlen_str ); + H5Tinsert(tid1_comp, "VLEN_STR2", HOFFSET(comp1_t, str_vlen_repeat), tid_vlen_str ); + H5Tinsert(tid1_comp, "FIXLEN_STR1", HOFFSET(comp1_t, str_fixlen), tid_fixlen_str ); + H5Tinsert(tid1_comp, "FIXLEN_STR2", HOFFSET(comp1_t, str_fixlen_repeat), tid_fixlen_str ); + H5Tinsert(tid1_comp, "VLEN_STR_ARRAY1", HOFFSET(comp1_t, str_array_vlen), tid_vlen_str_array); + H5Tinsert(tid1_comp, "VLEN_STR_ARRAY2", HOFFSET(comp1_t, str_vlen_array_again), tid_vlen_str_array); + H5Tinsert(tid1_comp, "FIXLEN_STR_ARRAY1", HOFFSET(comp1_t, str_array_fixlen), tid_fixlen_str_array); + H5Tinsert(tid1_comp, "FIXLEN_STR_ARRAY2", HOFFSET(comp1_t, str_fixlen_array_again), tid_fixlen_str_array); + + /* compound 2 */ + H5Tinsert(tid2_comp, "VLEN_STR1", HOFFSET(comp2_t, str_vlen), tid_vlen_str ); + H5Tinsert(tid2_comp, "VLEN_STR2", HOFFSET(comp2_t, str_vlen_repeat), tid_vlen_str ); + H5Tinsert(tid2_comp, "FIXLEN_STR1", HOFFSET(comp2_t, str_fixlen), tid_fixlen_str ); + H5Tinsert(tid2_comp, "FIXLEN_STR2", HOFFSET(comp2_t, str_fixlen_repeat), tid_fixlen_str ); + H5Tinsert(tid2_comp, "VLEN_STR_ARRAY1", HOFFSET(comp2_t, str_array_vlen), tid_vlen_str_array); + H5Tinsert(tid2_comp, "VLEN_STR_ARRAY2", HOFFSET(comp2_t, str_vlen_array_again), tid_vlen_str_array); + H5Tinsert(tid2_comp, "FIXLEN_STR_ARRAY1", HOFFSET(comp2_t, str_array_fixlen), tid_fixlen_str_array); + H5Tinsert(tid2_comp, "FIXLEN_STR_ARRAY2", HOFFSET(comp2_t, str_fixlen_array_again), tid_fixlen_str_array); + + /* compound 3 */ + H5Tinsert(tid3_comp, "VLEN_STR1", HOFFSET(comp3_t, str_vlen), tid_vlen_str ); + H5Tinsert(tid3_comp, "VLEN_STR2", HOFFSET(comp3_t, str_vlen_repeat), tid_vlen_str ); + H5Tinsert(tid3_comp, "FIXLEN_STR1", HOFFSET(comp3_t, str_fixlen), tid_fixlen_str ); + H5Tinsert(tid3_comp, "FIXLEN_STR2", HOFFSET(comp3_t, str_fixlen_repeat), tid_fixlen_str ); + H5Tinsert(tid3_comp, "VLEN_STR_ARRAY1", HOFFSET(comp3_t, str_array_vlen), tid_vlen_str_array); + H5Tinsert(tid3_comp, "VLEN_STR_ARRAY2", HOFFSET(comp3_t, str_vlen_array_again), tid_vlen_str_array); + H5Tinsert(tid3_comp, "FIXLEN_STR_ARRAY1", HOFFSET(comp3_t, str_array_fixlen), tid_fixlen_str_array); + H5Tinsert(tid3_comp, "FIXLEN_STR_ARRAY2", HOFFSET(comp3_t, str_fixlen_array_again), tid_fixlen_str_array); + + /* compound 4 */ + H5Tinsert(tid4_comp, "VLEN_STR1", HOFFSET(comp4_t, str_vlen), tid_vlen_str ); + H5Tinsert(tid4_comp, "VLEN_STR2", HOFFSET(comp4_t, str_vlen_repeat), tid_vlen_str ); + H5Tinsert(tid4_comp, "FIXLEN_STR1", HOFFSET(comp4_t, str_fixlen), tid_fixlen_str ); + H5Tinsert(tid4_comp, "FIXLEN_STR2", HOFFSET(comp4_t, str_fixlen_repeat), tid_fixlen_str ); + H5Tinsert(tid4_comp, "VLEN_STR_ARRAY1", HOFFSET(comp4_t, str_array_vlen), tid_vlen_str_array); + H5Tinsert(tid4_comp, "VLEN_STR_ARRAY2", HOFFSET(comp4_t, str_vlen_array_again), tid_vlen_str_array); + H5Tinsert(tid4_comp, "FIXLEN_STR_ARRAY1", HOFFSET(comp4_t, str_array_fixlen), tid_fixlen_str_array); + H5Tinsert(tid4_comp, "FIXLEN_STR_ARRAY2", HOFFSET(comp4_t, str_fixlen_array_again), tid_fixlen_str_array); + + /* compound 5 */ + H5Tinsert(tid5_comp, "VLEN_STR1", HOFFSET(comp5_t, str_vlen), tid_vlen_str ); + H5Tinsert(tid5_comp, "VLEN_STR2", HOFFSET(comp5_t, str_vlen_repeat), tid_vlen_str ); + H5Tinsert(tid5_comp, "FIXLEN_STR1", HOFFSET(comp5_t, str_fixlen), tid_fixlen_str ); + H5Tinsert(tid5_comp, "FIXLEN_STR2", HOFFSET(comp5_t, str_fixlen_repeat), tid_fixlen_str ); + H5Tinsert(tid5_comp, "VLEN_STR_ARRAY1", HOFFSET(comp5_t, str_array_vlen), tid_vlen_str_array); + H5Tinsert(tid5_comp, "VLEN_STR_ARRAY2", HOFFSET(comp5_t, str_vlen_array_again), tid_vlen_str_array); + H5Tinsert(tid5_comp, "FIXLEN_STR_ARRAY1", HOFFSET(comp5_t, str_array_fixlen), tid_fixlen_str_array); + H5Tinsert(tid5_comp, "FIXLEN_STR_ARRAY2", HOFFSET(comp5_t, str_fixlen_array_again), tid_fixlen_str_array); + + /* compound 6 */ + H5Tinsert(tid6_comp, "VLEN_STR1", HOFFSET(comp6_t, str_vlen), tid_vlen_str ); + H5Tinsert(tid6_comp, "VLEN_STR2", HOFFSET(comp6_t, str_vlen_repeat), tid_vlen_str ); + H5Tinsert(tid6_comp, "FIXLEN_STR1", HOFFSET(comp6_t, str_fixlen), tid_fixlen_str ); + H5Tinsert(tid6_comp, "FIXLEN_STR2", HOFFSET(comp6_t, str_fixlen_repeat), tid_fixlen_str ); + H5Tinsert(tid6_comp, "VLEN_STR_ARRAY1", HOFFSET(comp6_t, str_array_vlen), tid_vlen_str_array); + H5Tinsert(tid6_comp, "VLEN_STR_ARRAY2", HOFFSET(comp6_t, str_vlen_array_again), tid_vlen_str_array); + H5Tinsert(tid6_comp, "FIXLEN_STR_ARRAY1", HOFFSET(comp6_t, str_array_fixlen), tid_fixlen_str_array); + H5Tinsert(tid6_comp, "FIXLEN_STR_ARRAY2", HOFFSET(comp6_t, str_fixlen_array_again), tid_fixlen_str_array); + + /* compound 7 */ + H5Tinsert(tid7_comp, "VLEN_STR1", HOFFSET(comp7_t, str_vlen), tid_vlen_str ); + H5Tinsert(tid7_comp, "VLEN_STR2", HOFFSET(comp7_t, str_vlen_repeat), tid_vlen_str ); + H5Tinsert(tid7_comp, "FIXLEN_STR1", HOFFSET(comp7_t, str_fixlen), tid_fixlen_str ); + H5Tinsert(tid7_comp, "FIXLEN_STR2", HOFFSET(comp7_t, str_fixlen_repeat), tid_fixlen_str ); + H5Tinsert(tid7_comp, "VLEN_STR_ARRAY1", HOFFSET(comp7_t, str_array_vlen), tid_vlen_str_array); + H5Tinsert(tid7_comp, "VLEN_STR_ARRAY2", HOFFSET(comp7_t, str_vlen_array_again), tid_vlen_str_array); + H5Tinsert(tid7_comp, "FIXLEN_STR_ARRAY1", HOFFSET(comp7_t, str_array_fixlen), tid_fixlen_str_array); + H5Tinsert(tid7_comp, "FIXLEN_STR_ARRAY2", HOFFSET(comp7_t, str_fixlen_array_again), tid_fixlen_str_array); + + /* compound 8 */ + H5Tinsert(tid8_comp, "VLEN_STR1", HOFFSET(comp8_t, str_vlen), tid_vlen_str ); + H5Tinsert(tid8_comp, "VLEN_STR2", HOFFSET(comp8_t, str_vlen_repeat), tid_vlen_str ); + H5Tinsert(tid8_comp, "FIXLEN_STR1", HOFFSET(comp8_t, str_fixlen), tid_fixlen_str ); + H5Tinsert(tid8_comp, "FIXLEN_STR2", HOFFSET(comp8_t, str_fixlen_repeat), tid_fixlen_str ); + H5Tinsert(tid8_comp, "VLEN_STR_ARRAY1", HOFFSET(comp8_t, str_array_vlen), tid_vlen_str_array); + H5Tinsert(tid8_comp, "VLEN_STR_ARRAY2", HOFFSET(comp8_t, str_vlen_array_again), tid_vlen_str_array); + H5Tinsert(tid8_comp, "FIXLEN_STR_ARRAY1", HOFFSET(comp8_t, str_array_fixlen), tid_fixlen_str_array); + H5Tinsert(tid8_comp, "FIXLEN_STR_ARRAY2", HOFFSET(comp8_t, str_fixlen_array_again), tid_fixlen_str_array); + + /* compound 9 */ + H5Tinsert(tid9_comp, "VLEN_STR1", HOFFSET(comp9_t, str_vlen), tid_vlen_str ); + H5Tinsert(tid9_comp, "VLEN_STR2", HOFFSET(comp9_t, str_vlen_repeat), tid_vlen_str ); + H5Tinsert(tid9_comp, "FIXLEN_STR1", HOFFSET(comp9_t, str_fixlen), tid_fixlen_str ); + H5Tinsert(tid9_comp, "FIXLEN_STR2", HOFFSET(comp9_t, str_fixlen_repeat), tid_fixlen_str ); + H5Tinsert(tid9_comp, "VLEN_STR_ARRAY1", HOFFSET(comp9_t, str_array_vlen), tid_vlen_str_array); + H5Tinsert(tid9_comp, "VLEN_STR_ARRAY2", HOFFSET(comp9_t, str_vlen_array_again), tid_vlen_str_array); + H5Tinsert(tid9_comp, "FIXLEN_STR_ARRAY1", HOFFSET(comp9_t, str_array_fixlen), tid_fixlen_str_array); + H5Tinsert(tid9_comp, "FIXLEN_STR_ARRAY2", HOFFSET(comp9_t, str_fixlen_array_again), tid_fixlen_str_array); + H5Tinsert(tid9_comp, "INT_DATA1", HOFFSET(comp9_t, int_data1), H5T_STD_I32LE); + H5Tinsert(tid9_comp, "INT_DATA2", HOFFSET(comp9_t, int_data2), H5T_STD_I32BE); + H5Tinsert(tid9_comp, "INT_DATA3", HOFFSET(comp9_t, int_data3), H5T_STD_I32LE); + H5Tinsert(tid9_comp, "OBJREF1", HOFFSET(comp9_t, objref1), H5T_STD_REF_OBJ); + H5Tinsert(tid9_comp, "OBJREF2", HOFFSET(comp9_t, objref2), H5T_STD_REF_OBJ); + H5Tinsert(tid9_comp, "OBJREF3", HOFFSET(comp9_t, objref3), H5T_STD_REF_OBJ); + + + /* Write data to compound 1 dataset buffer */ + did_comp = H5Dcreate2(fid1, "Compound_dset1", tid1_comp, sid_comp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + status = H5Dwrite(did_comp, tid1_comp, H5S_ALL, H5S_ALL, H5P_DEFAULT, &comp1_buf); if (status < 0) { fprintf(stderr, "Error: %s> H5Dwrite failed.\n", fname1); status = FAIL; goto out; } + H5Dclose(did_comp); + + /* Write data to compound 2 dataset buffer */ + did_comp = H5Dcreate2(fid1, "Compound_dset2", tid2_comp, sid_comp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + status = H5Dwrite(did_comp, tid2_comp, H5S_ALL, H5S_ALL, H5P_DEFAULT, &comp2_buf); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Dwrite failed.\n", fname1); + status = FAIL; + goto out; + } + H5Dclose(did_comp); + + /* Write data to compound 3 dataset buffer */ + did_comp = H5Dcreate2(fid1, "Compound_dset3", tid3_comp, sid_comp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + status = H5Dwrite(did_comp, tid3_comp, H5S_ALL, H5S_ALL, H5P_DEFAULT, &comp3_buf); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Dwrite failed.\n", fname1); + status = FAIL; + goto out; + } + H5Dclose(did_comp); + + /* Write data to compound 4 dataset buffer */ + did_comp = H5Dcreate2(fid1, "Compound_dset4", tid4_comp, sid_comp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + status = H5Dwrite(did_comp, tid4_comp, H5S_ALL, H5S_ALL, H5P_DEFAULT, &comp4_buf); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Dwrite failed.\n", fname1); + status = FAIL; + goto out; + } + H5Dclose(did_comp); + + /* Write data to compound 5 dataset buffer */ + did_comp = H5Dcreate2(fid1, "Compound_dset5", tid5_comp, sid_comp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + status = H5Dwrite(did_comp, tid5_comp, H5S_ALL, H5S_ALL, H5P_DEFAULT, &comp5_buf); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Dwrite failed.\n", fname1); + status = FAIL; + goto out; + } + H5Dclose(did_comp); + + /* Write data to compound 6 dataset buffer */ + did_comp = H5Dcreate2(fid1, "Compound_dset6", tid6_comp, sid_comp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + status = H5Dwrite(did_comp, tid6_comp, H5S_ALL, H5S_ALL, H5P_DEFAULT, &comp6_buf); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Dwrite failed.\n", fname1); + status = FAIL; + goto out; + } + H5Dclose(did_comp); + + /* Write data to compound 7 dataset buffer */ + did_comp = H5Dcreate2(fid1, "Compound_dset7", tid7_comp, sid_comp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + status = H5Dwrite(did_comp, tid7_comp, H5S_ALL, H5S_ALL, H5P_DEFAULT, &comp7_buf); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Dwrite failed.\n", fname1); + status = FAIL; + goto out; + } + H5Dclose(did_comp); + + /* Write data to compound 8 dataset buffer */ + did_comp = H5Dcreate2(fid1, "Compound_dset8", tid8_comp, sid_comp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + status = H5Dwrite(did_comp, tid8_comp, H5S_ALL, H5S_ALL, H5P_DEFAULT, &comp8_buf); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Dwrite failed.\n", fname1); + status = FAIL; + goto out; + } + H5Dclose(did_comp); + + /* Write data to compound 9 dataset buffer */ + did_comp = H5Dcreate2(fid1, "Compound_dset9", tid9_comp, sid_comp, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + + /* obj references */ + status=H5Rcreate(&(comp9_buf.objref1),fid1,"/Compound_dset2",H5R_OBJECT,-1); + status=H5Rcreate(&(comp9_buf.objref2),fid1,"/Compound_dset3",H5R_OBJECT,-1); + status=H5Rcreate(&(comp9_buf.objref3),fid1,"/Compound_dset4",H5R_OBJECT,-1); + + status = H5Dwrite(did_comp, tid9_comp, H5S_ALL, H5S_ALL, H5P_DEFAULT, &comp9_buf); + if (status < 0) + { + fprintf(stderr, "Error: %s> H5Dwrite failed.\n", fname1); + status = FAIL; + goto out; + } + + + H5Dclose(did_comp); + + did_comp=0; out: /*----------------------------------------------------------------------- * Close *-----------------------------------------------------------------------*/ if(fid1) H5Fclose(fid1); - /* string1 */ - if(tid_str1) - H5Tclose(tid_str1); - if(did_str1) - H5Dclose(did_str1); - if(sid_str1) - H5Sclose(sid_str1); - /* string2 */ - if(tid_str2) - H5Tclose(tid_str2); - if(did_str2) - H5Dclose(did_str2); - if(sid_str2) - H5Sclose(sid_str2); - /* string3 */ - if(tid_str3) - H5Tclose(tid_str3); - if(tid_str3_array) - H5Tclose(tid_str3_array); - if(did_str3) - H5Dclose(did_str3); - if(sid_str3) - H5Sclose(sid_str3); - /* string4 */ - if(tid_str4) - H5Tclose(tid_str4); - if(tid_str4_array) - H5Tclose(tid_str4_array); - if(did_str4) - H5Dclose(did_str4); - if(sid_str4) - H5Sclose(sid_str4); + /* vlen string */ + if(tid_vlen_str) + H5Tclose(tid_vlen_str); + if(sid_vlen_str) + H5Sclose(sid_vlen_str); + /* fixed len string */ + if(tid_fixlen_str) + H5Tclose(tid_fixlen_str); + if(sid_fixlen_str) + H5Sclose(sid_fixlen_str); + /* vlen string array */ + if(tid_vlen_str_array_pre) + H5Tclose(tid_vlen_str_array_pre); + if(tid_vlen_str_array) + H5Tclose(tid_vlen_str_array); + if(sid_vlen_str_array) + H5Sclose(sid_vlen_str_array); + /* fixed len string array */ + if(tid_fixlen_str_array_pre) + H5Tclose(tid_fixlen_str_array_pre); + if(tid_fixlen_str_array) + H5Tclose(tid_fixlen_str_array); + if(sid_fixlen_str_array) + H5Sclose(sid_fixlen_str_array); /* compound */ - if(tid_comp) - H5Tclose(tid_comp); + if(tid1_comp) + H5Tclose(tid1_comp); + if(tid2_comp) + H5Tclose(tid2_comp); + if(tid3_comp) + H5Tclose(tid3_comp); + if(tid4_comp) + H5Tclose(tid4_comp); + if(tid5_comp) + H5Tclose(tid5_comp); + if(tid6_comp) + H5Tclose(tid6_comp); + if(tid7_comp) + H5Tclose(tid7_comp); + if(tid8_comp) + H5Tclose(tid8_comp); + if(tid9_comp) + H5Tclose(tid9_comp); if(did_comp) H5Dclose(did_comp); if(sid_comp) diff --git a/tools/h5diff/testfiles/h5diff_530.txt b/tools/h5diff/testfiles/h5diff_530.txt index 6f7e08f..bd2b435 100644 --- a/tools/h5diff/testfiles/h5diff_530.txt +++ b/tools/h5diff/testfiles/h5diff_530.txt @@ -2,10 +2,34 @@ file1 file2 --------------------------------------- x x / - x x /Compound_dset + x x /Compound_dset1 + x x /Compound_dset2 + x x /Compound_dset3 + x x /Compound_dset4 + x x /Compound_dset5 + x x /Compound_dset6 + x x /Compound_dset7 + x x /Compound_dset8 + x x /Compound_dset9 group : </> and </> 0 differences found -dataset: </Compound_dset> and </Compound_dset> +dataset: </Compound_dset1> and </Compound_dset1> +0 differences found +dataset: </Compound_dset2> and </Compound_dset2> +0 differences found +dataset: </Compound_dset3> and </Compound_dset3> +0 differences found +dataset: </Compound_dset4> and </Compound_dset4> +0 differences found +dataset: </Compound_dset5> and </Compound_dset5> +0 differences found +dataset: </Compound_dset6> and </Compound_dset6> +0 differences found +dataset: </Compound_dset7> and </Compound_dset7> +0 differences found +dataset: </Compound_dset8> and </Compound_dset8> +0 differences found +dataset: </Compound_dset9> and </Compound_dset9> 0 differences found EXIT CODE: 0 diff --git a/tools/h5diff/testfiles/h5diff_comp_vl_strs.h5 b/tools/h5diff/testfiles/h5diff_comp_vl_strs.h5 Binary files differindex 348cfee..dac510f 100644 --- a/tools/h5diff/testfiles/h5diff_comp_vl_strs.h5 +++ b/tools/h5diff/testfiles/h5diff_comp_vl_strs.h5 diff --git a/tools/h5diff/testh5diff.sh b/tools/h5diff/testh5diff.sh index d46ec22..f818738 100755 --- a/tools/h5diff/testh5diff.sh +++ b/tools/h5diff/testh5diff.sh @@ -68,6 +68,8 @@ EXCLUDE_FILE1_2=h5diff_exclude1-2.h5 # different structure and obj names EXCLUDE_FILE2_1=h5diff_exclude2-1.h5 EXCLUDE_FILE2_2=h5diff_exclude2-2.h5 +# compound type with multiple vlen string types +COMP_VL_STRS_FILE=h5diff_comp_vl_strs.h5 TESTNAME=h5diff EXIT_SUCCESS=0 @@ -779,8 +781,12 @@ TOOLTEST h5diff_482.txt -v --exclude-path "/group1" --exclude-path "/dset1" $EXC TOOLTEST h5diff_483.txt -v --exclude-path "/group1" $EXCLUDE_FILE2_1 $EXCLUDE_FILE2_2 # Exclude from group compare -TOOLTEST h5diff_484.txt -v --exclude-path "/dset3" h5diff_exclude1-1.h5 h5diff_exclude1-2.h5 /group1 +TOOLTEST h5diff_484.txt -v --exclude-path "/dset3" $EXCLUDE_FILE1_1 $EXCLUDE_FILE1_2 /group1 +# ############################################################################## +# # diff various multiple vlen and fixed strings in a compound type dataset +# ############################################################################## +TOOLTEST h5diff_530.txt -v $COMP_VL_STRS_FILE $COMP_VL_STRS_FILE # ############################################################################## # # END diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index 353b37b..105462f 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -234,7 +234,15 @@ hsize_t diff_array( void *_mem1, size = H5Tget_size( m_type ); type_class = H5Tget_class(m_type); - if (type_class != H5T_REFERENCE && HDmemcmp(mem1, mem2, size*nelmts)==0) + /* Fast comparison first for atomic type by memcmp(). + * It is OK not to list non-atomic type here because it will not be caught + * by the confition, but it gives more clarity for code planning + */ + if (type_class != H5T_REFERENCE && + type_class != H5T_COMPOUND && + type_class != H5T_STRING && + type_class != H5T_VLEN && + HDmemcmp(mem1, mem2, size*nelmts)==0) return 0; if ( rank > 0 ) @@ -249,13 +257,74 @@ hsize_t diff_array( void *_mem1, pos[j]=0; } - if(H5Tis_variable_str(m_type)) + switch (type_class) { + default: + assert(0); + break; + + /*------------------------------------------------------------------------- + * float and integer atomic types + *------------------------------------------------------------------------- + */ + + case H5T_FLOAT: + + if (H5Tequal(m_type, H5T_NATIVE_FLOAT)) + nfound=diff_float(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + else if (H5Tequal(m_type, H5T_NATIVE_DOUBLE)) + nfound=diff_double(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); +#if H5_SIZEOF_LONG_DOUBLE !=0 + else if (H5Tequal(m_type, H5T_NATIVE_LDOUBLE)) + nfound=diff_ldouble(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); +#endif + break; + + case H5T_INTEGER: + + if (H5Tequal(m_type, H5T_NATIVE_SCHAR)) + nfound=diff_schar(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + else if (H5Tequal(m_type, H5T_NATIVE_UCHAR)) + nfound=diff_uchar(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + else if (H5Tequal(m_type, H5T_NATIVE_SHORT)) + nfound=diff_short(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + else if (H5Tequal(m_type, H5T_NATIVE_USHORT)) + nfound=diff_ushort(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + else if (H5Tequal(m_type, H5T_NATIVE_INT)) + nfound=diff_int(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + else if (H5Tequal(m_type, H5T_NATIVE_UINT)) + nfound=diff_uint(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + else if (H5Tequal(m_type, H5T_NATIVE_LONG)) + nfound=diff_long(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + else if (H5Tequal(m_type, H5T_NATIVE_ULONG)) + nfound=diff_ulong(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + else if (H5Tequal(m_type, H5T_NATIVE_LLONG)) + nfound=diff_llong(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + else if (H5Tequal(m_type, H5T_NATIVE_ULLONG)) + nfound=diff_ullong(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); + + break; + + /*------------------------------------------------------------------------- + * Other types than float and integer + *------------------------------------------------------------------------- + */ + + case H5T_COMPOUND: + case H5T_STRING: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_ENUM: + case H5T_ARRAY: + case H5T_VLEN: + case H5T_REFERENCE: + HDmemset(&members, 0, sizeof (mcomp_t)); + set_comp_members(m_type, &members); for ( i = 0; i < nelmts; i++) { nfound+=diff_datum( - ((unsigned char**)mem1)[(size_t)i], - ((unsigned char**)mem2)[(size_t)i], + mem1 + i * size, + mem2 + i * size, /* offset */ m_type, i, rank, @@ -267,103 +336,15 @@ hsize_t diff_array( void *_mem1, name2, container1_id, container2_id, - &ph, NULL); + &ph, &members); if (options->n && nfound>=options->count) + { + free_comp_members(&members); return nfound; + } } /* i */ - } - - else - { - switch (type_class) - { - default: - assert(0); - break; - - /*------------------------------------------------------------------------- - * float and integer atomic types - *------------------------------------------------------------------------- - */ - - case H5T_FLOAT: - - if (H5Tequal(m_type, H5T_NATIVE_FLOAT)) - nfound=diff_float(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - else if (H5Tequal(m_type, H5T_NATIVE_DOUBLE)) - nfound=diff_double(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); -#if H5_SIZEOF_LONG_DOUBLE !=0 - else if (H5Tequal(m_type, H5T_NATIVE_LDOUBLE)) - nfound=diff_ldouble(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); -#endif - break; - - case H5T_INTEGER: - - if (H5Tequal(m_type, H5T_NATIVE_SCHAR)) - nfound=diff_schar(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - else if (H5Tequal(m_type, H5T_NATIVE_UCHAR)) - nfound=diff_uchar(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - else if (H5Tequal(m_type, H5T_NATIVE_SHORT)) - nfound=diff_short(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - else if (H5Tequal(m_type, H5T_NATIVE_USHORT)) - nfound=diff_ushort(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - else if (H5Tequal(m_type, H5T_NATIVE_INT)) - nfound=diff_int(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - else if (H5Tequal(m_type, H5T_NATIVE_UINT)) - nfound=diff_uint(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - else if (H5Tequal(m_type, H5T_NATIVE_LONG)) - nfound=diff_long(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - else if (H5Tequal(m_type, H5T_NATIVE_ULONG)) - nfound=diff_ulong(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - else if (H5Tequal(m_type, H5T_NATIVE_LLONG)) - nfound=diff_llong(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - else if (H5Tequal(m_type, H5T_NATIVE_ULLONG)) - nfound=diff_ullong(mem1,mem2,nelmts,hyper_start,rank,dims,acc,pos,options,name1,name2,&ph); - - break; - - /*------------------------------------------------------------------------- - * Other types than float and integer - *------------------------------------------------------------------------- - */ - - case H5T_COMPOUND: - case H5T_STRING: - case H5T_BITFIELD: - case H5T_OPAQUE: - case H5T_ENUM: - case H5T_ARRAY: - case H5T_VLEN: - case H5T_REFERENCE: - HDmemset(&members, 0, sizeof (mcomp_t)); - set_comp_members(m_type, &members); - for ( i = 0; i < nelmts; i++) - { - nfound+=diff_datum( - mem1 + i * size, - mem2 + i * size, /* offset */ - m_type, - i, - rank, - dims, - acc, - pos, - options, - name1, - name2, - container1_id, - container2_id, - &ph, &members); - if (options->n && nfound>=options->count) - { - free_comp_members(&members); - return nfound; - } - } /* i */ - free_comp_members(&members); - } /* switch */ - } /* else */ + free_comp_members(&members); + } /* switch */ return nfound; } @@ -446,7 +427,15 @@ hsize_t diff_datum(void *_mem1, type_size = H5Tget_size( m_type ); type_class = H5Tget_class(m_type); - if (type_class!=H5T_REFERENCE && HDmemcmp(mem1, mem2, type_size)==0) + /* Fast comparison first for atomic type by memcmp(). + * It is OK not to list non-atomic type here because it will not be caught + * by the confition, but it gives more clarity for code planning + */ + if (type_class != H5T_REFERENCE && + type_class != H5T_COMPOUND && + type_class != H5T_STRING && + type_class != H5T_VLEN && + HDmemcmp(mem1, mem2, type_size)==0) return 0; switch (H5Tget_class(m_type)) @@ -466,47 +455,27 @@ hsize_t diff_datum(void *_mem1, nmembs = members->n; + for (j = 0; j < nmembs; j++) { offset = members->offsets[j]; memb_type = members->ids[j]; - /* if member type is vlen string */ - if(members->flags[j]) - { - nfound+=diff_datum( - ((unsigned char**)mem1)[j], - ((unsigned char**)mem2)[j], - memb_type, - i, - rank, - dims, - acc, - pos, - options, - obj1, - obj2, - container1_id, - container2_id, - ph, NULL); - } - else - { - nfound+=diff_datum( - mem1+offset, - mem2+offset, - memb_type, - i, - rank, - dims, - acc, - pos, - options, - obj1, - obj2, - container1_id, - container2_id, - ph, members->m[j]); - } + + nfound+=diff_datum( + mem1+offset, + mem2+offset, + memb_type, + i, + rank, + dims, + acc, + pos, + options, + obj1, + obj2, + container1_id, + container2_id, + ph, members->m[j]); } break; @@ -519,27 +488,61 @@ hsize_t diff_datum(void *_mem1, { H5T_str_t pad; char *s; + char *s1; + char *s2; + size_t size1; + size_t size2; - /* Get pointer to first string to compare */ - s = (char *)mem1; + /* if variable length string */ + if(H5Tis_variable_str(m_type)) + { + /* Get pointer to first string */ + s1 = *(char**) mem1; + size1 = HDstrlen(s1); + /* Get pointer to second string */ + s2 = *(char**) mem2; + size2 = HDstrlen(s2); + } + else + { + /* Get pointer to first string */ + s1 = mem1; + size1 = H5Tget_size(m_type); + /* Get pointer to second string */ + s2 = mem2; + size2 = H5Tget_size(m_type); + } + + /* + * compare for shorter string + * TODO: this code need to be improved to handle the difference + * of length of strings. + * For now mimic the previous way. + */ + if(size1 < size2) + { + size = size1; + s = s1; + } + else + { + size = size2; + s = s2; + } /* check for NULL pointer for string */ if(s!=NULL) { - if(H5Tis_variable_str(m_type)) { - size = HDstrlen(s); - if (HDmemcmp(mem1, mem2, size)==0) - break; - } - else - size = H5Tget_size(m_type); + /* try fast compare first */ + if (HDmemcmp(s1, s2, size)==0) + break; pad = H5Tget_strpad(m_type); for (u=0; u<size && (s[u] || pad!=H5T_STR_NULLTERM); u++) nfound+=character_compare( - mem1 + u, - mem2 + u, /* offset */ + s1 + u, + s2 + u, /* offset */ i, /* index position */ u, /* string character position */ rank, @@ -679,43 +682,21 @@ hsize_t diff_datum(void *_mem1, nelmts *= adims[u]; for (u = 0; u < nelmts; u++) { - /* if member type is vlen string */ - if(H5Tis_variable_str(memb_type)) - { - nfound+=diff_datum( - ((unsigned char**)mem1)[u], - ((unsigned char**)mem2)[u], - memb_type, - i, /* index position */ - rank, - dims, - acc, - pos, - options, - obj1, - obj2, - container1_id, - container2_id, - ph, NULL); - } - else - { - nfound+=diff_datum( - mem1 + u * size, - mem2 + u * size, /* offset */ - memb_type, - i, /* index position */ - rank, - dims, - acc, - pos, - options, - obj1, - obj2, - container1_id, - container2_id, - ph, NULL); - } + nfound+=diff_datum( + mem1 + u * size, + mem2 + u * size, /* offset */ + memb_type, + i, /* index position */ + rank, + dims, + acc, + pos, + options, + obj1, + obj2, + container1_id, + container2_id, + ph, NULL); } H5Tclose(memb_type); } |