diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2004-09-07 16:41:59 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2004-09-07 16:41:59 (GMT) |
commit | 0424d72fc14dd0e919f44717ba9ab747679a750f (patch) | |
tree | 90eb48f87a9c15bbb97cc88618ac87e1d784ce9d /src/H5Tnative.c | |
parent | cfd312161f2df11295c9fd1d05e87e00045ebfe7 (diff) | |
download | hdf5-0424d72fc14dd0e919f44717ba9ab747679a750f.zip hdf5-0424d72fc14dd0e919f44717ba9ab747679a750f.tar.gz hdf5-0424d72fc14dd0e919f44717ba9ab747679a750f.tar.bz2 |
[svn-r9212] Purpose:
bug fix
Description:
on the Cray SV1 an INT type was wrongly converted to a SHORT type
by the get_native_integer function
Choose the type based on the precision; this is to support cases
like the Cray SV1, where the size of short is 8 but precision is 32
(e.g an INT (size 8, prec 64) would be converted to a SHORT
(size 8, prec 32) if the size was the deciding factor)
Solution:
Platforms tested:
linux
solaris
aix
Misc. update:
Diffstat (limited to 'src/H5Tnative.c')
-rw-r--r-- | src/H5Tnative.c | 163 |
1 files changed, 86 insertions, 77 deletions
diff --git a/src/H5Tnative.c b/src/H5Tnative.c index c13d972..aeba729 100644 --- a/src/H5Tnative.c +++ b/src/H5Tnative.c @@ -36,7 +36,7 @@ /* Static local functions */ static H5T_t *H5T_get_native_type(H5T_t *dt, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size); -static H5T_t *H5T_get_native_integer(size_t size, H5T_sign_t sign, H5T_direction_t direction, +static H5T_t *H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size); static H5T_t *H5T_get_native_float(size_t size, H5T_direction_t direction, size_t *struct_align, size_t *offset, size_t *comp_size); @@ -157,6 +157,7 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig H5T_t *dt; /* Datatype to make native */ H5T_class_t h5_class; /* Class of datatype to make native */ size_t size; /* Size of datatype to make native */ + size_t prec; /* Precision of datatype to make native */ int snmemb; /* Number of members in compound & enum types */ unsigned nmemb; /* Number of members in compound & enum types */ H5T_t *super_type; /* Super type of VL, array and enum datatypes */ @@ -182,8 +183,10 @@ H5T_get_native_type(H5T_t *dtype, H5T_direction_t direction, size_t *struct_alig if((sign = H5T_get_sign(dtype))==H5T_SGN_ERROR) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a valid signess") + + prec = dtype->u.atomic.prec; - if((ret_value = H5T_get_native_integer(size, sign, direction, struct_align, offset, comp_size))==NULL) + if((ret_value = H5T_get_native_integer(prec, sign, direction, struct_align, offset, comp_size))==NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve integer type") } break; @@ -503,18 +506,23 @@ done: * Programmer: Raymond Lu * Oct 3, 2002 * - * Modifications: + * Modifications: Pedro Vicente + * Sep 4, 2004 + * Choose the type based on the precision; this is to support cases + * like the Cray SV1, where the size of short is 8 but precision is 32 + * (e.g an INT (size 8, prec 64) would be converted to a SHORT + * (size 8, prec 32) if the size was the deciding factor) * *------------------------------------------------------------------------- */ static H5T_t* -H5T_get_native_integer(size_t size, H5T_sign_t sign, H5T_direction_t direction, - size_t *struct_align, size_t *offset, size_t *comp_size) +H5T_get_native_integer(size_t prec, H5T_sign_t sign, H5T_direction_t direction, + size_t *struct_align, size_t *offset, size_t *comp_size) { H5T_t *dt; /* Appropriate native datatype to copy */ hid_t tid=(-1); /* Datatype ID of appropriate native datatype */ size_t align=0; /* Alignment necessary for native datatype */ - size_t native_size=0; /* Datatype size of the native type */ + size_t native_size=0; /* Datatype size of the native type */ enum match_type { /* The different kinds of integers we can match */ H5T_NATIVE_INT_MATCH_CHAR, H5T_NATIVE_INT_MATCH_SHORT, @@ -525,74 +533,73 @@ H5T_get_native_integer(size_t size, H5T_sign_t sign, H5T_direction_t direction, } match=H5T_NATIVE_INT_MATCH_UNKNOWN; H5T_t *ret_value; /* Return value */ - FUNC_ENTER_NOAPI(H5T_get_native_integer, NULL) - - assert(size>0); - - if(direction == H5T_DIR_DEFAULT || direction == H5T_DIR_ASCEND) { - if(size<=sizeof(char)) { - match=H5T_NATIVE_INT_MATCH_CHAR; - native_size = sizeof(char); - } else if(size<=sizeof(short)) { - match=H5T_NATIVE_INT_MATCH_SHORT; - native_size = sizeof(short); - } else if(size<=sizeof(int)) { - match=H5T_NATIVE_INT_MATCH_INT; - native_size = sizeof(int); - } else if(size<=sizeof(long)) { - match=H5T_NATIVE_INT_MATCH_LONG; - native_size = sizeof(long); - } else if(size<=sizeof(long_long)) { - match=H5T_NATIVE_INT_MATCH_LLONG; - native_size = sizeof(long_long); - } else { /* If no native type matches the querried datatype, simply choose the type of biggest size. */ - match=H5T_NATIVE_INT_MATCH_LLONG; - native_size = sizeof(long_long); - } + FUNC_ENTER_NOAPI(H5T_get_native_integer, NULL); + + if(direction == H5T_DIR_DEFAULT || direction == H5T_DIR_ASCEND) + { + if(prec<=H5Tget_precision(H5T_NATIVE_SCHAR)) { + match=H5T_NATIVE_INT_MATCH_CHAR; + native_size = sizeof(char); + } else if(prec<=H5Tget_precision(H5T_NATIVE_SHORT)) { + match=H5T_NATIVE_INT_MATCH_SHORT; + native_size = sizeof(short); + } else if(prec<=H5Tget_precision(H5T_NATIVE_INT)) { + match=H5T_NATIVE_INT_MATCH_INT; + native_size = sizeof(int); + } else if(prec<=H5Tget_precision(H5T_NATIVE_LONG)) { + match=H5T_NATIVE_INT_MATCH_LONG; + native_size = sizeof(long); + } else if(prec<=H5Tget_precision(H5T_NATIVE_LLONG)) { + match=H5T_NATIVE_INT_MATCH_LLONG; + native_size = sizeof(long_long); + } else { /* If no native type matches the querried datatype, simply choose the type of biggest size. */ + match=H5T_NATIVE_INT_MATCH_LLONG; + native_size = sizeof(long_long); + } } else if(direction == H5T_DIR_DESCEND) { - if(size>=sizeof(long_long)) { - match=H5T_NATIVE_INT_MATCH_LLONG; - native_size = sizeof(long_long); - } else if(size>=sizeof(long)) { - if(size==sizeof(long)) { - match=H5T_NATIVE_INT_MATCH_LONG; - native_size = sizeof(long); - } else { - match=H5T_NATIVE_INT_MATCH_LLONG; - native_size = sizeof(long_long); - } - } - else if(size>=sizeof(int)) { - if(size==sizeof(int)) { - match=H5T_NATIVE_INT_MATCH_INT; - native_size = sizeof(int); - } else { - match=H5T_NATIVE_INT_MATCH_LONG; - native_size = sizeof(long); - } - } - else if(size>=sizeof(short)) { - if(size==sizeof(short)) { - match=H5T_NATIVE_INT_MATCH_SHORT; - native_size = sizeof(short); - } else { - match=H5T_NATIVE_INT_MATCH_INT; - native_size = sizeof(int); - } - } - else if(size>=sizeof(char)) { - if(size==sizeof(char)) { - match=H5T_NATIVE_INT_MATCH_CHAR; - native_size = sizeof(char); - } else { - match=H5T_NATIVE_INT_MATCH_SHORT; - native_size = sizeof(short); - } - } - else { /* If no native type matches the querried datatype, simple choose the type of smallest size. */ - match=H5T_NATIVE_INT_MATCH_CHAR; - native_size = sizeof(char); - } + if(prec>=H5Tget_precision(H5T_NATIVE_LLONG)) { + match=H5T_NATIVE_INT_MATCH_LLONG; + native_size = sizeof(long_long); + } else if(prec>=H5Tget_precision(H5T_NATIVE_LONG)) { + if(prec==H5Tget_precision(H5T_NATIVE_LONG)) { + match=H5T_NATIVE_INT_MATCH_LONG; + native_size = sizeof(long); + } else { + match=H5T_NATIVE_INT_MATCH_LLONG; + native_size = sizeof(long_long); + } + } + else if(prec>=H5Tget_precision(H5T_NATIVE_INT)) { + if(prec==H5Tget_precision(H5T_NATIVE_INT)) { + match=H5T_NATIVE_INT_MATCH_INT; + native_size = sizeof(int); + } else { + match=H5T_NATIVE_INT_MATCH_LONG; + native_size = sizeof(long); + } + } + else if(prec>=H5Tget_precision(H5T_NATIVE_SHORT)) { + if(prec==H5Tget_precision(H5T_NATIVE_SHORT)) { + match=H5T_NATIVE_INT_MATCH_SHORT; + native_size = sizeof(short); + } else { + match=H5T_NATIVE_INT_MATCH_INT; + native_size = sizeof(int); + } + } + else if(prec>=H5Tget_precision(H5T_NATIVE_SCHAR)) { + if(prec==H5Tget_precision(H5T_NATIVE_SCHAR)) { + match=H5T_NATIVE_INT_MATCH_CHAR; + native_size = sizeof(char); + } else { + match=H5T_NATIVE_INT_MATCH_SHORT; + native_size = sizeof(short); + } + } + else { /* If no native type matches the querried datatype, simple choose the type of smallest size. */ + match=H5T_NATIVE_INT_MATCH_CHAR; + native_size = sizeof(char); + } } /* Set the appropriate native datatype information */ @@ -649,18 +656,20 @@ H5T_get_native_integer(size_t size, H5T_sign_t sign, H5T_direction_t direction, /* Create new native type */ assert(tid>=0); if(NULL==(dt=H5I_object(tid))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type") + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a data type"); + if((ret_value=H5T_copy(dt, H5T_COPY_TRANSIENT))==NULL) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot retrieve float type") + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot copy type"); /* compute size and offset of compound type member. */ if(H5T_cmp_offset(comp_size, offset, native_size, 1, align, struct_align)<0) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset") + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "cannot compute compound offset"); done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI(ret_value); } + /*------------------------------------------------------------------------- * Function: H5T_get_native_float |