From 3ca585e46cf4dd53be7eaded5484a9ff496d2312 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Mon, 7 Feb 2005 12:56:20 -0500 Subject: [svn-r9951] Purpose: Minor bug fix. Description: The byte order for all 1-byte integer types was fixed as little-endian even on a big-endian machine. This's corrected in h5detect.c. When types are only 1 byte long, a native int is used substitute the type to detect byte order. Some tools like h5dump and h5repack are also corrected in this case. Platforms tested: fuss, copper, sol.(There're some failures from the recent configure change). Misc. update: Information in the RELEASE.txt. --- release_docs/RELEASE.txt | 3 ++ src/H5detect.c | 26 +++++++++++++---- tools/h5dump/h5dump.c | 58 +++++++++++++++++++++++++++++--------- tools/h5repack/testh5repack_dset.c | 2 +- 4 files changed, 68 insertions(+), 21 deletions(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 3b20d33..c1faa5c 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -201,6 +201,9 @@ Bug Fixes since HDF5-1.6.0 release Library ------- + - The byte order of 1-byte integer types was fixed as little endian + even on a big-endian machine. This has been corrected. SLU - + 2005/02/07 - Fix segmentation fault when calling H5Fflush with an attribute that hasn't had a value written to it open. QAK - 2004/10/18 - Back up supporting bitfield and time types in H5Tget_native_type. diff --git a/src/H5detect.c b/src/H5detect.c index b79911d..73ded41 100644 --- a/src/H5detect.c +++ b/src/H5detect.c @@ -195,17 +195,31 @@ precision (detected_t *d) */ #define DETECT_I(TYPE,VAR,INFO) { \ TYPE _v; \ + int _int_v; \ int _i, _j; \ unsigned char *_x; \ + \ memset (&INFO, 0, sizeof(INFO)); \ INFO.varname = #VAR; \ INFO.size = sizeof(TYPE); \ - for (_i=sizeof(TYPE),_v=0; _i>0; --_i) _v = (_v<<8) + _i; \ - for (_i=0,_x=(unsigned char *)&_v; _i<(signed)sizeof(TYPE); _i++) { \ - _j = (*_x++)-1; \ - assert (_j<(signed)sizeof(TYPE)); \ - INFO.perm[_i] = _j; \ - } \ + \ + if(sizeof(TYPE)!=1) { \ + for (_i=sizeof(TYPE),_v=0; _i>0; --_i) _v = (_v<<8) + _i; \ + for (_i=0,_x=(unsigned char *)&_v; _i<(signed)sizeof(TYPE); _i++) { \ + _j = (*_x++)-1; \ + assert (_j<(signed)sizeof(TYPE)); \ + INFO.perm[_i] = _j; \ + } \ + } else { /*Not able to detect order if type size is 1 byte. Use native int \ + *instead. No effect on data, just make it look correct. */ \ + for (_i=sizeof(int),_int_v=0; _i>0; --_i) _int_v = (_int_v<<8) + _i; \ + for (_i=0,_x=(unsigned char *)&_int_v; _i<(signed)sizeof(int); _i++) { \ + _j = (*_x++)-1; \ + assert (_j<(signed)sizeof(int)); \ + INFO.perm[_i] = _j; \ + } \ + } \ + \ INFO.sign = ('U'!=*(#VAR)); \ precision (&(INFO)); \ ALIGNMENT(TYPE, INFO); \ diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 06aaae0..6a617c7 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -655,6 +655,7 @@ print_datatype(hid_t type,unsigned in_group) H5T_str_t str_pad; H5T_cset_t cset; H5G_stat_t statbuf; + H5T_order_t order; hid_t super; hid_t tmp_type; htri_t is_vlstr=FALSE; @@ -808,26 +809,55 @@ print_datatype(hid_t type,unsigned in_group) indentation(indent + COL); printf("%s ", CTYPE); + /* Check C variable-length string first. Are the two types equal? */ if (H5Tequal(tmp_type, str_type)) { printf("H5T_C_S1;\n"); - H5Tclose(str_type); - } else { - H5Tclose(str_type); - str_type = H5Tcopy(H5T_FORTRAN_S1); - H5Tset_cset(str_type, cset); - H5Tset_size(str_type, size); - H5Tset_strpad(str_type, str_pad); + goto done; + } - if (H5Tequal(tmp_type, str_type)) { - printf("H5T_FORTRAN_S1;\n"); - } else { - printf("unknown_one_character_type;\n "); - d_status = EXIT_FAILURE; - } + /* Change the endianness and see if they're equal. */ + order = H5Tget_order(tmp_type); + if(order==H5T_ORDER_LE) + H5Tset_order(str_type, H5T_ORDER_LE); + else if(order==H5T_ORDER_BE) + H5Tset_order(str_type, H5T_ORDER_BE); - H5Tclose(str_type); + if (H5Tequal(tmp_type, str_type)) { + printf("H5T_C_S1;\n"); + goto done; + } + + /* If not equal to C variable-length string, check Fortran type. */ + H5Tclose(str_type); + str_type = H5Tcopy(H5T_FORTRAN_S1); + H5Tset_cset(str_type, cset); + H5Tset_size(str_type, size); + H5Tset_strpad(str_type, str_pad); + + /* Are the two types equal? */ + if (H5Tequal(tmp_type, str_type)) { + printf("H5T_FORTRAN_S1;\n"); + goto done; + } + + /* Change the endianness and see if they're equal. */ + order = H5Tget_order(tmp_type); + if(order==H5T_ORDER_LE) + H5Tset_order(str_type, H5T_ORDER_LE); + else if(order==H5T_ORDER_BE) + H5Tset_order(str_type, H5T_ORDER_BE); + + if (H5Tequal(tmp_type, str_type)) { + printf("H5T_FORTRAN_S1;\n"); + goto done; } + /* Type doesn't match any of above. */ + printf("unknown_one_character_type;\n "); + d_status = EXIT_FAILURE; + +done: + H5Tclose(str_type); H5Tclose(tmp_type); indent -= COL; diff --git a/tools/h5repack/testh5repack_dset.c b/tools/h5repack/testh5repack_dset.c index 299c044..8781ae7 100644 --- a/tools/h5repack/testh5repack_dset.c +++ b/tools/h5repack/testh5repack_dset.c @@ -655,7 +655,7 @@ static void make_dset_reg_ref(hid_t loc_id) sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL); /* Create a dataset */ - dset2=H5Dcreate(loc_id,"dsetreg",H5T_STD_U8LE,sid2,H5P_DEFAULT); + dset2=H5Dcreate(loc_id,"dsetreg",H5T_NATIVE_UCHAR,sid2,H5P_DEFAULT); for(i=0; i