diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5AC.c | 11 | ||||
-rw-r--r-- | src/H5B2int.c | 8 | ||||
-rw-r--r-- | src/H5FD.c | 6 | ||||
-rw-r--r-- | src/H5FDcore.c | 4 | ||||
-rw-r--r-- | src/H5FDfamily.c | 8 | ||||
-rw-r--r-- | src/H5FDmulti.c | 4 | ||||
-rw-r--r-- | src/H5FDprivate.h | 2 | ||||
-rw-r--r-- | src/H5FDpublic.h | 4 | ||||
-rw-r--r-- | src/H5FDstdio.c | 4 | ||||
-rw-r--r-- | src/H5MM.c | 8 | ||||
-rw-r--r-- | src/H5PL.c | 2 | ||||
-rw-r--r-- | src/H5T.c | 2 | ||||
-rw-r--r-- | src/H5Znbit.c | 836 | ||||
-rw-r--r-- | src/H5Zscaleoffset.c | 211 | ||||
-rw-r--r-- | src/H5Ztrans.c | 141 | ||||
-rw-r--r-- | src/H5detect.c | 2 | ||||
-rw-r--r-- | src/H5private.h | 33 | ||||
-rw-r--r-- | src/H5public.h | 19 |
18 files changed, 717 insertions, 588 deletions
@@ -183,13 +183,13 @@ done: herr_t H5AC__init_package(void) { +#ifdef H5_DEBUG_BUILD H5P_genplist_t *xfer_plist; /* Dataset transfer property list object */ + H5FD_dxpl_type_t dxpl_type; /* Property indicating the type of the internal dxpl */ +#endif /* H5_DEBUG_BUILD */ #ifdef H5_HAVE_PARALLEL H5P_coll_md_read_flag_t coll_meta_read; #endif /* H5_HAVE_PARALLEL */ -#ifdef H5_DEBUG_BUILD - H5FD_dxpl_type_t dxpl_type; /* Property indicating the type of the internal dxpl */ -#endif /* H5_DEBUG_BUILD */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -201,9 +201,8 @@ H5AC__init_package(void) const char *s; /* String for environment variables */ s = HDgetenv("H5_COLL_API_SANITY_CHECK"); - if(s && HDisdigit(*s)) { + if(s && HDisdigit(*s)) H5_coll_api_sanity_check_g = (hbool_t)HDstrtol(s, NULL, 0); - } } #endif /* H5_HAVE_PARALLEL */ @@ -278,7 +277,9 @@ H5AC__init_package(void) H5AC_rawdata_dxpl_id = H5P_DATASET_XFER_DEFAULT; #endif /* defined(H5_HAVE_PARALLEL) || defined(H5_DEBUG_BUILD) */ +#if defined(H5_DEBUG_BUILD) | defined(H5_HAVE_PARALLEL) done: +#endif /* defined(H5_DEBUG_BUILD) | defined(H5_HAVE_PARALLEL) */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5AC__init_package() */ diff --git a/src/H5B2int.c b/src/H5B2int.c index e877a17..3bd788c 100644 --- a/src/H5B2int.c +++ b/src/H5B2int.c @@ -3612,7 +3612,7 @@ done: * *------------------------------------------------------------------------- */ -static herr_t +H5_ATTR_PURE static herr_t H5B2__assert_leaf(const H5B2_hdr_t *hdr, const H5B2_leaf_t *leaf) { /* General sanity checking on node */ @@ -3635,7 +3635,7 @@ H5B2__assert_leaf(const H5B2_hdr_t *hdr, const H5B2_leaf_t *leaf) * *------------------------------------------------------------------------- */ -static herr_t +H5_ATTR_PURE static herr_t H5B2__assert_leaf2(const H5B2_hdr_t *hdr, const H5B2_leaf_t *leaf, const H5B2_leaf_t H5_ATTR_UNUSED *leaf2) { /* General sanity checking on node */ @@ -3658,7 +3658,7 @@ H5B2__assert_leaf2(const H5B2_hdr_t *hdr, const H5B2_leaf_t *leaf, const H5B2_le * *------------------------------------------------------------------------- */ -static herr_t +H5_ATTR_PURE static herr_t H5B2__assert_internal(hsize_t parent_all_nrec, const H5B2_hdr_t *hdr, const H5B2_internal_t *internal) { hsize_t tot_all_nrec; /* Total number of records at or below this node */ @@ -3699,7 +3699,7 @@ H5B2__assert_internal(hsize_t parent_all_nrec, const H5B2_hdr_t *hdr, const H5B2 * *------------------------------------------------------------------------- */ -static herr_t +H5_ATTR_PURE static herr_t H5B2__assert_internal2(hsize_t parent_all_nrec, const H5B2_hdr_t *hdr, const H5B2_internal_t *internal, const H5B2_internal_t *internal2) { hsize_t tot_all_nrec; /* Total number of records at or below this node */ @@ -1608,12 +1608,12 @@ done: *------------------------------------------------------------------------- */ herr_t -H5FDflush(H5FD_t *file, hid_t dxpl_id, unsigned closing) +H5FDflush(H5FD_t *file, hid_t dxpl_id, hbool_t closing) { herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) - H5TRACE3("e", "*xiIu", file, dxpl_id, closing); + H5TRACE3("e", "*xib", file, dxpl_id, closing); /* Check args */ if(!file || !file->cls) @@ -1647,7 +1647,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5FD_flush(H5FD_t *file, hid_t dxpl_id, unsigned closing) +H5FD_flush(H5FD_t *file, hid_t dxpl_id, hbool_t closing) { herr_t ret_value = SUCCEED; /* Return value */ diff --git a/src/H5FDcore.c b/src/H5FDcore.c index 865a29e..5ce6560 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -139,7 +139,7 @@ static herr_t H5FD__core_read(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, had size_t size, void *buf); static herr_t H5FD__core_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, size_t size, const void *buf); -static herr_t H5FD__core_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing); +static herr_t H5FD__core_flush(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); static herr_t H5FD__core_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); static herr_t H5FD_core_lock(H5FD_t *_file, hbool_t rw); static herr_t H5FD_core_unlock(H5FD_t *_file); @@ -1335,7 +1335,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5FD__core_flush(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, unsigned H5_ATTR_UNUSED closing) +H5FD__core_flush(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, hbool_t H5_ATTR_UNUSED closing) { H5FD_core_t *file = (H5FD_core_t*)_file; herr_t ret_value = SUCCEED; /* Return value */ diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c index b92a685..3b38836 100644 --- a/src/H5FDfamily.c +++ b/src/H5FDfamily.c @@ -104,8 +104,8 @@ static herr_t H5FD_family_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, ha size_t size, void *_buf/*out*/); static herr_t H5FD_family_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size, const void *_buf); -static herr_t H5FD_family_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing); -static herr_t H5FD_family_truncate(H5FD_t *_file, hid_t dxpl_id, unsigned closing); +static herr_t H5FD_family_flush(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); +static herr_t H5FD_family_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); static herr_t H5FD_family_lock(H5FD_t *_file, hbool_t rw); static herr_t H5FD_family_unlock(H5FD_t *_file); @@ -1249,7 +1249,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5FD_family_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing) +H5FD_family_flush(H5FD_t *_file, hid_t dxpl_id, hbool_t closing) { H5FD_family_t *file = (H5FD_family_t*)_file; unsigned u, nerrors = 0; @@ -1284,7 +1284,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5FD_family_truncate(H5FD_t *_file, hid_t dxpl_id, unsigned closing) +H5FD_family_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing) { H5FD_family_t *file = (H5FD_family_t*)_file; unsigned u, nerrors = 0; diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c index bf27b1a..0e49813 100644 --- a/src/H5FDmulti.c +++ b/src/H5FDmulti.c @@ -133,7 +133,7 @@ static herr_t H5FD_multi_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, had size_t size, void *_buf/*out*/); static herr_t H5FD_multi_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size, const void *_buf); -static herr_t H5FD_multi_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing); +static herr_t H5FD_multi_flush(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); static herr_t H5FD_multi_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); static herr_t H5FD_multi_lock(H5FD_t *_file, hbool_t rw); static herr_t H5FD_multi_unlock(H5FD_t *_file); @@ -1686,7 +1686,7 @@ H5FD_multi_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, *------------------------------------------------------------------------- */ static herr_t -H5FD_multi_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing) +H5FD_multi_flush(H5FD_t *_file, hid_t dxpl_id, hbool_t closing) { H5FD_multi_t *file = (H5FD_multi_t*)_file; H5FD_mem_t mt; diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h index 639f3eb..915f7e1 100644 --- a/src/H5FDprivate.h +++ b/src/H5FDprivate.h @@ -158,7 +158,7 @@ H5_DLL herr_t H5FD_read(H5FD_t *file, const H5P_genplist_t *dxpl, H5FD_mem_t typ haddr_t addr, size_t size, void *buf/*out*/); H5_DLL herr_t H5FD_write(H5FD_t *file, const H5P_genplist_t *dxpl, H5FD_mem_t type, haddr_t addr, size_t size, const void *buf); -H5_DLL herr_t H5FD_flush(H5FD_t *file, hid_t dxpl_id, unsigned closing); +H5_DLL herr_t H5FD_flush(H5FD_t *file, hid_t dxpl_id, hbool_t closing); H5_DLL herr_t H5FD_truncate(H5FD_t *file, hid_t dxpl_id, hbool_t closing); H5_DLL herr_t H5FD_lock(H5FD_t *file, hbool_t rw); H5_DLL herr_t H5FD_unlock(H5FD_t *file); diff --git a/src/H5FDpublic.h b/src/H5FDpublic.h index 4183d14..4931e0f 100644 --- a/src/H5FDpublic.h +++ b/src/H5FDpublic.h @@ -272,7 +272,7 @@ typedef struct H5FD_class_t { haddr_t addr, size_t size, void *buffer); herr_t (*write)(H5FD_t *file, H5FD_mem_t type, hid_t dxpl, haddr_t addr, size_t size, const void *buffer); - herr_t (*flush)(H5FD_t *file, hid_t dxpl_id, unsigned closing); + herr_t (*flush)(H5FD_t *file, hid_t dxpl_id, hbool_t closing); herr_t (*truncate)(H5FD_t *file, hid_t dxpl_id, hbool_t closing); herr_t (*lock)(H5FD_t *file, hbool_t rw); herr_t (*unlock)(H5FD_t *file); @@ -353,7 +353,7 @@ H5_DLL herr_t H5FDread(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size, void *buf/*out*/); H5_DLL herr_t H5FDwrite(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size, const void *buf); -H5_DLL herr_t H5FDflush(H5FD_t *file, hid_t dxpl_id, unsigned closing); +H5_DLL herr_t H5FDflush(H5FD_t *file, hid_t dxpl_id, hbool_t closing); H5_DLL herr_t H5FDtruncate(H5FD_t *file, hid_t dxpl_id, hbool_t closing); H5_DLL herr_t H5FDlock(H5FD_t *file, hbool_t rw); H5_DLL herr_t H5FDunlock(H5FD_t *file); diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c index bc85c74..0168ff4 100644 --- a/src/H5FDstdio.c +++ b/src/H5FDstdio.c @@ -173,7 +173,7 @@ static herr_t H5FD_stdio_read(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr_ size_t size, void *buf); static herr_t H5FD_stdio_write(H5FD_t *lf, H5FD_mem_t type, hid_t fapl_id, haddr_t addr, size_t size, const void *buf); -static herr_t H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, unsigned closing); +static herr_t H5FD_stdio_flush(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); static herr_t H5FD_stdio_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing); static herr_t H5FD_stdio_lock(H5FD_t *_file, hbool_t rw); static herr_t H5FD_stdio_unlock(H5FD_t *_file); @@ -955,7 +955,7 @@ H5FD_stdio_write(H5FD_t *_file, H5FD_mem_t /*UNUSED*/ type, hid_t /*UNUSED*/ dxp *------------------------------------------------------------------------- */ static herr_t -H5FD_stdio_flush(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, unsigned closing) +H5FD_stdio_flush(H5FD_t *_file, hid_t /*UNUSED*/ dxpl_id, hbool_t closing) { H5FD_stdio_t *file = (H5FD_stdio_t*)_file; static const char *func = "H5FD_stdio_flush"; /* Function Name for error reporting */ @@ -156,7 +156,7 @@ H5MM__is_our_block(void *mem) * *------------------------------------------------------------------------- */ -static void +H5_ATTR_PURE static void H5MM__sanity_check_block(const H5MM_block_t *block) { HDassert(block->u.info.size > 0); @@ -182,7 +182,7 @@ H5MM__sanity_check_block(const H5MM_block_t *block) * *------------------------------------------------------------------------- */ -static void +H5_ATTR_PURE static void H5MM__sanity_check(void *mem) { H5MM_block_t *block = H5MM_BLOCK_FROM_BUF(mem); @@ -203,7 +203,7 @@ H5MM__sanity_check(void *mem) * *------------------------------------------------------------------------- */ -void +H5_ATTR_PURE void H5MM_sanity_check_all(void) { H5MM_block_t *curr = NULL; @@ -228,7 +228,7 @@ H5MM_sanity_check_all(void) * *------------------------------------------------------------------------- */ -void +H5_ATTR_PURE void H5MM_final_sanity_check(void) { HDassert(0 == H5MM_curr_alloc_bytes_s); @@ -704,7 +704,7 @@ H5PL__search_table(H5PL_type_t plugin_type, int type_id, const void **info) const H5Z_class2_t *plugin_info; if(NULL == (get_plugin_info = (H5PL_get_plugin_info_t)H5PL_GET_LIB_FUNC((H5PL_table_g[i]).handle, "H5PLget_plugin_info"))) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get function for H5PLget_plugin_info") + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get function for H5PLget_plugin_info") if(NULL == (plugin_info = (const H5Z_class2_t *)(*get_plugin_info)())) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "can't get plugin info") @@ -3036,8 +3036,10 @@ H5T__create(H5T_class_t type, size_t size) subtype = H5T_NATIVE_INT_g; else if(sizeof(long) == size) subtype = H5T_NATIVE_LONG_g; +#if H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG else if(sizeof(long long) == size) subtype = H5T_NATIVE_LLONG_g; +#endif /* H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG */ else HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "no applicable native integer type") if(NULL == (dt = H5T__alloc())) diff --git a/src/H5Znbit.c b/src/H5Znbit.c index e2fb300..04e8869 100644 --- a/src/H5Znbit.c +++ b/src/H5Znbit.c @@ -29,10 +29,10 @@ * one nbit atomic datatype: integer or floating-point */ typedef struct { - size_t size; /* size of datatype */ - int order; /* datatype endianness order */ - int precision; /* datatype precision */ - int offset; /* datatype offset */ + unsigned size; /* size of datatype */ + unsigned order; /* datatype endianness order */ + unsigned precision; /* datatype precision */ + unsigned offset; /* datatype offset */ } parms_atomic; /* Local function prototypes */ @@ -41,41 +41,50 @@ static herr_t H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id); static size_t H5Z_filter_nbit(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], size_t nbytes, size_t *buf_size, void **buf); -static void H5Z_calc_parms_nooptype(void); -static void H5Z_calc_parms_atomic(void); -static herr_t H5Z_calc_parms_array(const H5T_t *type); -static herr_t H5Z_calc_parms_compound(const H5T_t *type); - -static herr_t H5Z_set_parms_nooptype(const H5T_t *type, unsigned cd_values[]); -static herr_t H5Z_set_parms_atomic(const H5T_t *type, unsigned cd_values[]); -static herr_t H5Z_set_parms_array(const H5T_t *type, unsigned cd_values[]); -static herr_t H5Z_set_parms_compound(const H5T_t *type, unsigned cd_values[]); - -static void H5Z_nbit_next_byte(size_t *j, int *buf_len); -static void H5Z_nbit_decompress_one_byte(unsigned char *data, size_t data_offset, int k, int begin_i, -int end_i, unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p, int datatype_len); -static void H5Z_nbit_compress_one_byte(unsigned char *data, size_t data_offset, int k, int begin_i, -int end_i, unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p, int datatype_len); +static void H5Z_calc_parms_nooptype(size_t *cd_values_actual_nparms); +static void H5Z_calc_parms_atomic(size_t *cd_values_actual_nparms); +static herr_t H5Z_calc_parms_array(const H5T_t *type, size_t *cd_values_actual_nparms); +static herr_t H5Z_calc_parms_compound(const H5T_t *type, size_t *cd_values_actual_nparms); + +static herr_t H5Z_set_parms_nooptype(const H5T_t *type, unsigned *cd_values_index, + unsigned cd_values[]); +static herr_t H5Z_set_parms_atomic(const H5T_t *type, unsigned *cd_values_index, + unsigned cd_values[], hbool_t *need_not_compress); +static herr_t H5Z_set_parms_array(const H5T_t *type, unsigned *cd_values_index, + unsigned cd_values[], hbool_t *need_not_compress); +static herr_t H5Z_set_parms_compound(const H5T_t *type, unsigned *cd_values_index, + unsigned cd_values[], hbool_t *need_not_compress); + +static void H5Z_nbit_next_byte(size_t *j, size_t *buf_len); +static void H5Z_nbit_decompress_one_byte(unsigned char *data, size_t data_offset, + unsigned k, unsigned begin_i, unsigned end_i, unsigned char *buffer, size_t *j, + size_t *buf_len, const parms_atomic *p, size_t datatype_len); +static void H5Z_nbit_compress_one_byte(unsigned char *data, size_t data_offset, unsigned k, unsigned begin_i, + unsigned end_i, unsigned char *buffer, size_t *j, size_t *buf_len, const parms_atomic *p, size_t datatype_len); static void H5Z_nbit_decompress_one_nooptype(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, unsigned size); + unsigned char *buffer, size_t *j, size_t *buf_len, unsigned size); static void H5Z_nbit_decompress_one_atomic(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p); + unsigned char *buffer, size_t *j, size_t *buf_len, const parms_atomic *p); static void H5Z_nbit_decompress_one_array(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, const unsigned parms[]); + unsigned char *buffer, size_t *j, size_t *buf_len, const unsigned parms[], + unsigned *parms_index); static void H5Z_nbit_decompress_one_compound(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, const unsigned parms[]); + unsigned char *buffer, size_t *j, size_t *buf_len, const unsigned parms[], + unsigned *parms_index); static void H5Z_nbit_decompress(unsigned char *data, unsigned d_nelmts, unsigned char *buffer, - const unsigned parms[]); + const unsigned parms[]); static void H5Z_nbit_compress_one_nooptype(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, unsigned size); + unsigned char *buffer, size_t *j, size_t *buf_len, unsigned size); static void H5Z_nbit_compress_one_atomic(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p); + unsigned char *buffer, size_t *j, size_t *buf_len, const parms_atomic *p); static void H5Z_nbit_compress_one_array(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, const unsigned parms[]); + unsigned char *buffer, size_t *j, size_t *buf_len, const unsigned parms[], + unsigned *parms_index); static void H5Z_nbit_compress_one_compound(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, const unsigned parms[]); + unsigned char *buffer, size_t *j, size_t *buf_len, const unsigned parms[], + unsigned *parms_index); static void H5Z_nbit_compress(unsigned char *data, unsigned d_nelmts, unsigned char *buffer, - size_t *buffer_size, const unsigned parms[]); + size_t *buffer_size, const unsigned parms[]); /* This message derives from H5Z */ H5Z_class2_t H5Z_NBIT[1] = {{ @@ -99,16 +108,6 @@ H5Z_class2_t H5Z_NBIT[1] = {{ #define H5Z_NBIT_ORDER_BE 1 /* Big endian for datatype byte order */ /* Local variables */ -/* - * cd_values_index: index of array cd_values inside function H5Z_set_local_nbit - * cd_values_actual_nparms: number of parameters in array cd_values[] - * need_not_compress: flag if TRUE indicating no need to do nbit compression - * parms_index: index of array parms used by compression/decompression functions - */ -static unsigned cd_values_index = 0; -static size_t cd_values_actual_nparms = 0; -static unsigned char need_not_compress = FALSE; -static unsigned parms_index = 0; /*------------------------------------------------------------------------- @@ -166,13 +165,14 @@ done: * *------------------------------------------------------------------------- */ -static void H5Z_calc_parms_nooptype(void) +static void +H5Z_calc_parms_nooptype(size_t *cd_values_actual_nparms) { /* Store datatype class code */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* Store datatype size */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; } @@ -190,22 +190,23 @@ static void H5Z_calc_parms_nooptype(void) * *------------------------------------------------------------------------- */ -static void H5Z_calc_parms_atomic(void) +static void +H5Z_calc_parms_atomic(size_t *cd_values_actual_nparms) { /* Store datatype class code */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* Store datatype size */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* Store datatype endianness */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* Store datatype's precision */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* Store datatype's offset */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; } @@ -227,7 +228,7 @@ static void H5Z_calc_parms_atomic(void) *------------------------------------------------------------------------- */ static herr_t -H5Z_calc_parms_array(const H5T_t *type) +H5Z_calc_parms_array(const H5T_t *type, size_t *cd_values_actual_nparms) { H5T_t *dtype_base = NULL; /* Array datatype's base datatype */ H5T_class_t dtype_base_class; /* Array datatype's base datatype's class */ @@ -236,10 +237,10 @@ H5Z_calc_parms_array(const H5T_t *type) FUNC_ENTER_NOAPI_NOINIT /* Store datatype class code */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* Store array datatype's size */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* Get array datatype's base datatype */ if(NULL == (dtype_base = H5T_get_super(type))) @@ -253,16 +254,16 @@ H5Z_calc_parms_array(const H5T_t *type) switch(dtype_base_class) { case H5T_INTEGER: case H5T_FLOAT: - H5Z_calc_parms_atomic(); + H5Z_calc_parms_atomic(cd_values_actual_nparms); break; case H5T_ARRAY: - if(H5Z_calc_parms_array(dtype_base) == FAIL) + if(H5Z_calc_parms_array(dtype_base, cd_values_actual_nparms) == FAIL) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot compute parameters for datatype") break; case H5T_COMPOUND: - if(H5Z_calc_parms_compound(dtype_base) == FAIL) + if(H5Z_calc_parms_compound(dtype_base, cd_values_actual_nparms) == FAIL) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot compute parameters for datatype") break; @@ -274,7 +275,7 @@ H5Z_calc_parms_array(const H5T_t *type) case H5T_ENUM: case H5T_VLEN: /* Other datatype classes: nbit does no compression */ - H5Z_calc_parms_nooptype(); + H5Z_calc_parms_nooptype(cd_values_actual_nparms); break; case H5T_NO_CLASS: @@ -312,31 +313,32 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5Z_calc_parms_compound(const H5T_t *type) +H5Z_calc_parms_compound(const H5T_t *type, size_t *cd_values_actual_nparms) { int nmembers; /* Compound datatype's number of members */ H5T_t *dtype_member = NULL; /* Compound datatype's member datatype */ - H5T_class_t dtype_member_class; /* Compound datatype's member datatype's class */ unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* Store compound datatype class code */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* Store compound datatype's size */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* Get number of members */ if((nmembers = H5T_get_nmembers(type)) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype number of members") /* Store number of members */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* For each member, calculate parameters */ for(u = 0; u < (unsigned)nmembers; u++) { + H5T_class_t dtype_member_class; /* Compound datatype's member datatype's class */ + /* Get member datatype */ if(NULL == (dtype_member = H5T_get_member_type(type, u, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad member datatype") @@ -346,22 +348,22 @@ H5Z_calc_parms_compound(const H5T_t *type) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad member datatype class") /* Store member offset */ - ++cd_values_actual_nparms; + *cd_values_actual_nparms += 1; /* Calculate parameters according to member's datatype class */ switch(dtype_member_class) { case H5T_INTEGER: case H5T_FLOAT: - H5Z_calc_parms_atomic(); + H5Z_calc_parms_atomic(cd_values_actual_nparms); break; case H5T_ARRAY: - if(H5Z_calc_parms_array(dtype_member) == FAIL) + if(H5Z_calc_parms_array(dtype_member, cd_values_actual_nparms) == FAIL) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot compute parameters for datatype") break; case H5T_COMPOUND: - if(H5Z_calc_parms_compound(dtype_member) == FAIL) + if(H5Z_calc_parms_compound(dtype_member, cd_values_actual_nparms) == FAIL) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot compute parameters for datatype") break; @@ -373,7 +375,7 @@ H5Z_calc_parms_compound(const H5T_t *type) case H5T_ENUM: case H5T_VLEN: /* Other datatype classes: nbit does no compression */ - H5Z_calc_parms_nooptype(); + H5Z_calc_parms_nooptype(cd_values_actual_nparms); break; case H5T_NO_CLASS: @@ -418,7 +420,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5Z_set_parms_nooptype(const H5T_t *type, unsigned cd_values[]) +H5Z_set_parms_nooptype(const H5T_t *type, unsigned *cd_values_index, unsigned cd_values[]) { size_t dtype_size; /* No-op datatype's size (in bytes) */ herr_t ret_value = SUCCEED; /* Return value */ @@ -426,14 +428,15 @@ H5Z_set_parms_nooptype(const H5T_t *type, unsigned cd_values[]) FUNC_ENTER_NOAPI_NOINIT /* Set datatype class code */ - cd_values[cd_values_index++] = H5Z_NBIT_NOOPTYPE; + cd_values[(*cd_values_index)++] = H5Z_NBIT_NOOPTYPE; /* Get datatype's size */ if((dtype_size = H5T_get_size(type)) == 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype size") /* Set "local" parameter for datatype size */ - cd_values[cd_values_index++] = dtype_size; + H5_CHECK_OVERFLOW(dtype_size, size_t, unsigned); + cd_values[(*cd_values_index)++] = (unsigned)dtype_size; done: FUNC_LEAVE_NOAPI(ret_value) @@ -457,25 +460,28 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5Z_set_parms_atomic(const H5T_t *type, unsigned cd_values[]) +H5Z_set_parms_atomic(const H5T_t *type, unsigned *cd_values_index, + unsigned cd_values[], hbool_t *need_not_compress) { H5T_order_t dtype_order; /* Atomic datatype's endianness order */ size_t dtype_size; /* Atomic datatype's size (in bytes) */ size_t dtype_precision; /* Atomic datatype's precision (in bits) */ - int dtype_offset; /* Atomic datatype's offset (in bits) */ + int sdtype_offset; /* Atomic datatype's offset (in bits) */ + unsigned dtype_offset; /* Atomic datatype's offset (in bits) */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* Set datatype class code */ - cd_values[cd_values_index++] = H5Z_NBIT_ATOMIC; + cd_values[(*cd_values_index)++] = H5Z_NBIT_ATOMIC; /* Get datatype's size */ if((dtype_size = H5T_get_size(type)) == 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype size") /* Set "local" parameter for datatype size */ - cd_values[cd_values_index++] = dtype_size; + H5_CHECK_OVERFLOW(dtype_size, size_t, unsigned); + cd_values[(*cd_values_index)++] = (unsigned)dtype_size; /* Get datatype's endianness order */ if((dtype_order = H5T_get_order(type)) == H5T_ORDER_ERROR) @@ -484,11 +490,11 @@ H5Z_set_parms_atomic(const H5T_t *type, unsigned cd_values[]) /* Set "local" parameter for datatype endianness */ switch(dtype_order) { case H5T_ORDER_LE: /* Little-endian byte order */ - cd_values[cd_values_index++] = H5Z_NBIT_ORDER_LE; + cd_values[(*cd_values_index)++] = H5Z_NBIT_ORDER_LE; break; case H5T_ORDER_BE: /* Big-endian byte order */ - cd_values[cd_values_index++] = H5Z_NBIT_ORDER_BE; + cd_values[(*cd_values_index)++] = H5Z_NBIT_ORDER_BE; break; case H5T_ORDER_VAX: @@ -504,27 +510,28 @@ H5Z_set_parms_atomic(const H5T_t *type, unsigned cd_values[]) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype precision") /* Get datatype's offset */ - if((dtype_offset = H5T_get_offset(type)) < 0) + if((sdtype_offset = H5T_get_offset(type)) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype offset") + dtype_offset = (unsigned)sdtype_offset; /* Check values of precision and offset */ - if(dtype_precision > dtype_size * 8 || (dtype_precision + dtype_offset) > dtype_size * 8 - || dtype_precision <= 0 || dtype_offset < 0) + if(dtype_precision > dtype_size * 8 || (dtype_precision + dtype_offset) > dtype_size * 8) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "invalid datatype precision/offset") /* Set "local" parameter for datatype precision */ - cd_values[cd_values_index++] = dtype_precision; + H5_CHECK_OVERFLOW(dtype_precision, size_t, unsigned); + cd_values[(*cd_values_index)++] = (unsigned)dtype_precision; /* Set "local" parameter for datatype offset */ - cd_values[cd_values_index++] = dtype_offset; + cd_values[(*cd_values_index)++] = dtype_offset; /* If before this point, there is no need to compress, check the need to * compress at this point. If current datatype is not full-precision, * flag need_not_compress should be set to FALSE. */ - if(need_not_compress) /* so far no need to compress */ + if(*need_not_compress) /* so far no need to compress */ if(dtype_offset != 0 || dtype_precision != dtype_size * 8) - need_not_compress = FALSE; + *need_not_compress = FALSE; done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5Z_set_parms_atomic() */ @@ -547,7 +554,8 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5Z_set_parms_array(const H5T_t *type, unsigned cd_values[]) +H5Z_set_parms_array(const H5T_t *type, unsigned *cd_values_index, + unsigned cd_values[], hbool_t *need_not_compress) { H5T_t *dtype_base = NULL; /* Array datatype's base datatype */ H5T_class_t dtype_base_class; /* Array datatype's base datatype's class */ @@ -558,14 +566,15 @@ H5Z_set_parms_array(const H5T_t *type, unsigned cd_values[]) FUNC_ENTER_NOAPI_NOINIT /* Set datatype class code */ - cd_values[cd_values_index++] = H5Z_NBIT_ARRAY; + cd_values[(*cd_values_index)++] = H5Z_NBIT_ARRAY; /* Get array datatype's size */ if((dtype_size = H5T_get_size(type)) == 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype size") /* Set "local" parameter for array datatype's size */ - cd_values[cd_values_index++]=dtype_size; + H5_CHECK_OVERFLOW(dtype_size, size_t, unsigned); + cd_values[(*cd_values_index)++] = (unsigned)dtype_size; /* Get array datatype's base datatype */ if(NULL == (dtype_base = H5T_get_super(type))) @@ -579,17 +588,17 @@ H5Z_set_parms_array(const H5T_t *type, unsigned cd_values[]) switch(dtype_base_class) { case H5T_INTEGER: case H5T_FLOAT: - if(H5Z_set_parms_atomic(dtype_base, cd_values) == FAIL) + if(H5Z_set_parms_atomic(dtype_base, cd_values_index, cd_values, need_not_compress) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; case H5T_ARRAY: - if(H5Z_set_parms_array(dtype_base, cd_values) == FAIL) + if(H5Z_set_parms_array(dtype_base, cd_values_index, cd_values, need_not_compress) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; case H5T_COMPOUND: - if(H5Z_set_parms_compound(dtype_base, cd_values) == FAIL) + if(H5Z_set_parms_compound(dtype_base, cd_values_index, cd_values, need_not_compress) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; @@ -602,7 +611,7 @@ H5Z_set_parms_array(const H5T_t *type, unsigned cd_values[]) if(dtype_base_class == H5T_VLEN || is_vlstring) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "datatype not supported by nbit") - if(H5Z_set_parms_nooptype(dtype_base, cd_values) == FAIL) + if(H5Z_set_parms_nooptype(dtype_base, cd_values_index, cd_values) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; @@ -612,7 +621,7 @@ H5Z_set_parms_array(const H5T_t *type, unsigned cd_values[]) case H5T_OPAQUE: case H5T_REFERENCE: case H5T_ENUM: - if(H5Z_set_parms_nooptype(dtype_base, cd_values) == FAIL) + if(H5Z_set_parms_nooptype(dtype_base, cd_values_index, cd_values) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; @@ -650,9 +659,11 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5Z_set_parms_compound(const H5T_t *type, unsigned cd_values[]) +H5Z_set_parms_compound(const H5T_t *type, unsigned *cd_values_index, + unsigned cd_values[], hbool_t *need_not_compress) { - int nmembers; /* Compound datatype's number of members */ + int snmembers; /* Compound datatype's number of members */ + unsigned nmembers; /* Compound datatype's number of members */ H5T_t *dtype_member = NULL; /* Compound datatype's member datatype */ H5T_class_t dtype_member_class; /* Compound datatype's member datatype's class */ size_t dtype_member_offset; /* Compound datatype's current member datatype's offset (in bytes) */ @@ -665,24 +676,26 @@ H5Z_set_parms_compound(const H5T_t *type, unsigned cd_values[]) FUNC_ENTER_NOAPI_NOINIT /* Set "local" parameter for compound datatype class code */ - cd_values[cd_values_index++] = H5Z_NBIT_COMPOUND; + cd_values[(*cd_values_index)++] = H5Z_NBIT_COMPOUND; /* Get datatype's size */ if((dtype_size = H5T_get_size(type)) == 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype size") /* Set "local" parameter for compound datatype size */ - cd_values[cd_values_index++] = dtype_size; + H5_CHECK_OVERFLOW(dtype_size, size_t, unsigned); + cd_values[(*cd_values_index)++] = (unsigned)dtype_size; /* Get number of members */ - if((nmembers = H5T_get_nmembers(type)) < 0) + if((snmembers = H5T_get_nmembers(type)) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype number of members") + nmembers = (unsigned)snmembers; /* Set "local" parameter for number of members */ - cd_values[cd_values_index++] = nmembers; + cd_values[(*cd_values_index)++] = nmembers; /* For each member, set parameters */ - for(u = 0; u < (unsigned)nmembers; u++) { + for(u = 0; u < nmembers; u++) { /* Get member datatype */ if(NULL == (dtype_member = H5T_get_member_type(type, u, H5T_COPY_TRANSIENT))) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad member datatype") @@ -695,23 +708,24 @@ H5Z_set_parms_compound(const H5T_t *type, unsigned cd_values[]) dtype_member_offset = H5T_get_member_offset(type, u); /* Set "local" parameter for member offset */ - cd_values[cd_values_index++] = dtype_member_offset; + H5_CHECK_OVERFLOW(dtype_member_offset, size_t, unsigned); + cd_values[(*cd_values_index)++] = (unsigned)dtype_member_offset; /* Call appropriate function according to member's datatype class */ switch(dtype_member_class) { case H5T_INTEGER: case H5T_FLOAT: - if(H5Z_set_parms_atomic(dtype_member, cd_values) == FAIL) + if(H5Z_set_parms_atomic(dtype_member, cd_values_index, cd_values, need_not_compress) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; case H5T_ARRAY: - if(H5Z_set_parms_array(dtype_member, cd_values) == FAIL) + if(H5Z_set_parms_array(dtype_member, cd_values_index, cd_values, need_not_compress) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; case H5T_COMPOUND: - if(H5Z_set_parms_compound(dtype_member, cd_values) == FAIL) + if(H5Z_set_parms_compound(dtype_member, cd_values_index, cd_values, need_not_compress) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; @@ -721,22 +735,24 @@ H5Z_set_parms_compound(const H5T_t *type, unsigned cd_values[]) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot determine if datatype is a variable-length string") /* Because for some no-op datatype (VL datatype and VL string datatype), its - * size can not be retrieved correctly by using function call H5T_get_size, - * special handling is needed for getting the size. Here the difference between + * size can not be retrieved correctly by using function call H5T_get_size, + * special handling is needed for getting the size. Here the difference between * adjacent member offset is used (if alignment is present, the result can be - * larger, but it does not affect the nbit filter's correctness). + * larger, but it does not affect the nbit filter's correctness). */ if(dtype_member_class == H5T_VLEN || is_vlstring) { /* Set datatype class code */ - cd_values[cd_values_index++] = H5Z_NBIT_NOOPTYPE; + cd_values[(*cd_values_index)++] = H5Z_NBIT_NOOPTYPE; - if(u != (unsigned)nmembers - 1) + if(u != nmembers - 1) dtype_next_member_offset = H5T_get_member_offset(type, u + 1); else /* current member is the last member */ dtype_next_member_offset = dtype_size; /* Set "local" parameter for datatype size */ - cd_values[cd_values_index++] = dtype_next_member_offset - dtype_member_offset; + H5_CHECK_OVERFLOW(dtype_member_offset, size_t, unsigned); + H5_CHECK_OVERFLOW(dtype_next_member_offset, size_t, unsigned); + cd_values[(*cd_values_index)++] = (unsigned)dtype_next_member_offset - (unsigned)dtype_member_offset; } break; @@ -747,7 +763,7 @@ H5Z_set_parms_compound(const H5T_t *type, unsigned cd_values[]) case H5T_REFERENCE: case H5T_ENUM: /* other datatype that nbit does no compression */ - if(H5Z_set_parms_nooptype(dtype_member, cd_values) == FAIL) + if(H5Z_set_parms_nooptype(dtype_member, cd_values_index, cd_values) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; @@ -796,10 +812,13 @@ H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id) const H5T_t *type; /* Datatype */ const H5S_t *ds; /* Dataspace */ unsigned flags; /* Filter flags */ + unsigned cd_values_index; /* Index of array cd_values */ + size_t cd_values_actual_nparms; /* Number of parameters in array cd_values[] */ size_t cd_nelmts = H5Z_NBIT_USER_NPARMS; /* Number of filter parameters */ unsigned *cd_values = NULL; /* Filter parameters */ hssize_t npoints; /* Number of points in the dataspace */ H5T_class_t dtype_class; /* Datatype's class */ + hbool_t need_not_compress; /* Flag if TRUE indicating no need to do nbit compression */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -822,16 +841,16 @@ H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id) switch(dtype_class) { case H5T_INTEGER: case H5T_FLOAT: - H5Z_calc_parms_atomic(); + H5Z_calc_parms_atomic(&cd_values_actual_nparms); break; case H5T_ARRAY: - if(H5Z_calc_parms_array(type) == FAIL) + if(H5Z_calc_parms_array(type, &cd_values_actual_nparms) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot compute parameters for datatype") break; case H5T_COMPOUND: - if(H5Z_calc_parms_compound(type) == FAIL) + if(H5Z_calc_parms_compound(type, &cd_values_actual_nparms) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot compute parameters for datatype") break; @@ -882,7 +901,8 @@ H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id) cd_values_index = 2; /* Set "local" parameter for number of elements in the chunk */ - H5_CHECKED_ASSIGN(cd_values[cd_values_index++], unsigned, npoints, hssize_t); + H5_CHECK_OVERFLOW(npoints, hssize_t, unsigned); + cd_values[cd_values_index++] = (unsigned)npoints; /* Assume no need to compress now, will be changed to FALSE later if not */ need_not_compress = TRUE; @@ -891,17 +911,17 @@ H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id) switch(dtype_class) { case H5T_INTEGER: case H5T_FLOAT: - if(H5Z_set_parms_atomic(type, cd_values) < 0) + if(H5Z_set_parms_atomic(type, &cd_values_index, cd_values, &need_not_compress) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; case H5T_ARRAY: - if(H5Z_set_parms_array(type, cd_values) < 0) + if(H5Z_set_parms_array(type, &cd_values_index, cd_values, &need_not_compress) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; case H5T_COMPOUND: - if(H5Z_set_parms_compound(type, cd_values) < 0) + if(H5Z_set_parms_compound(type, &cd_values_index, cd_values, &need_not_compress) < 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "nbit cannot set parameters for datatype") break; @@ -927,8 +947,9 @@ H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id) HDassert(cd_values_actual_nparms == cd_values_index); /* Finally set the first two entries of cd_values[] */ - cd_values[0] = cd_values_actual_nparms; - cd_values[1] = need_not_compress; + H5_CHECK_OVERFLOW(cd_values_actual_nparms, size_t, unsigned); + cd_values[0] = (unsigned)cd_values_actual_nparms; + cd_values[1] = (unsigned)need_not_compress; /* Modify the filter's parameters for this dataset */ if(H5P_modify_filter(dcpl_plist, H5Z_FILTER_NBIT, flags, cd_values_actual_nparms, cd_values) < 0) @@ -957,7 +978,7 @@ done: */ static size_t H5Z_filter_nbit(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], - size_t nbytes, size_t *buf_size, void **buf) + size_t nbytes, size_t *buf_size, void **buf) { unsigned char *outbuf; /* pointer to new output buffer */ size_t size_out = 0; /* size of output buffer */ @@ -1027,63 +1048,64 @@ done: */ static void -H5Z_nbit_next_byte(size_t *j, int *buf_len) +H5Z_nbit_next_byte(size_t *j, size_t *buf_len) { ++(*j); *buf_len = 8 * sizeof(unsigned char); } static void -H5Z_nbit_decompress_one_byte(unsigned char *data, size_t data_offset, int k, - int begin_i, int end_i, unsigned char *buffer, size_t *j, int *buf_len, - parms_atomic p, int datatype_len) +H5Z_nbit_decompress_one_byte(unsigned char *data, size_t data_offset, unsigned k, + unsigned begin_i, unsigned end_i, unsigned char *buffer, size_t *j, size_t *buf_len, + const parms_atomic *p, size_t datatype_len) { - int dat_len; /* dat_len is the number of bits to be copied in each data byte */ - int uchar_offset; + size_t dat_len; /* dat_len is the number of bits to be copied in each data byte */ + size_t dat_offset; unsigned char val; /* value to be copied in each data byte */ /* initialize value and bits of unsigned char to be copied */ val = buffer[*j]; - uchar_offset = 0; + dat_offset = 0; if(begin_i != end_i) { /* significant bits occupy >1 unsigned char */ if(k == begin_i) - dat_len = 8 - (datatype_len - p.precision - p.offset) % 8; + dat_len = 8 - (datatype_len - p->precision - p->offset) % 8; else if(k == end_i) { - dat_len = 8 - p.offset %8; - uchar_offset = 8 - dat_len; + dat_len = 8 - p->offset % 8; + dat_offset = 8 - dat_len; } else dat_len = 8; } else { /* all significant bits in one unsigned char */ - uchar_offset = p.offset % 8; - dat_len = p.precision; + dat_offset = p->offset % 8; + dat_len = p->precision; } if(*buf_len > dat_len) { - data[data_offset + k] = - ((val >> (*buf_len - dat_len)) & ~(~0 << dat_len)) << uchar_offset; + data[data_offset + k] = (unsigned char)( + ((unsigned)(val >> (*buf_len - dat_len)) & (unsigned)(~((unsigned)(~0) << dat_len))) << dat_offset); *buf_len -= dat_len; } else { - data[data_offset + k] = - ((val & ~(~0 << *buf_len)) << (dat_len - *buf_len)) << uchar_offset; + data[data_offset + k] = (unsigned char)( + ((val & ~((unsigned)(~0) << *buf_len)) << (dat_len - *buf_len)) << dat_offset); dat_len -= *buf_len; H5Z_nbit_next_byte(j, buf_len); - if(dat_len == 0) return; + if(dat_len == 0) + return; val = buffer[*j]; - data[data_offset + k] |= - ((val >> (*buf_len - dat_len)) & ~(~0 << dat_len)) << uchar_offset; + data[data_offset + k] |= (unsigned char)( + ((unsigned)(val >> (*buf_len - dat_len)) & (unsigned)(~((unsigned)(~0) << dat_len))) << dat_offset); *buf_len -= dat_len; } } static void H5Z_nbit_decompress_one_nooptype(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, unsigned size) + unsigned char *buffer, size_t *j, size_t *buf_len, unsigned size) { unsigned i; /* index */ - unsigned dat_len; /* dat_len is the number of bits to be copied in each data byte */ + size_t dat_len; /* dat_len is the number of bits to be copied in each data byte */ unsigned char val; /* value to be copied in each data byte */ for(i = 0; i < size; i++) { @@ -1091,99 +1113,109 @@ H5Z_nbit_decompress_one_nooptype(unsigned char *data, size_t data_offset, val = buffer[*j]; dat_len = sizeof(unsigned char) * 8; - data[data_offset + i] = ((val & ~(~0 << *buf_len)) << (dat_len - *buf_len)); + data[data_offset + i] = (unsigned char)(((val & ~((unsigned)(~0) << *buf_len)) << (dat_len - *buf_len))); dat_len -= *buf_len; H5Z_nbit_next_byte(j, buf_len); - if(dat_len == 0) continue; + if(dat_len == 0) + continue; val = buffer[*j]; - data[data_offset + i] |= ((val >> (*buf_len - dat_len)) & ~(~0 << dat_len)); + data[data_offset + i] |= (unsigned char)((unsigned)(val >> (*buf_len - dat_len)) & (unsigned)(~((unsigned)(~0) << dat_len))); *buf_len -= dat_len; } } static void H5Z_nbit_decompress_one_atomic(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p) + unsigned char *buffer, size_t *j, size_t *buf_len, const parms_atomic *p) { - /* begin_i: the index of byte having first significant bit - end_i: the index of byte having last significant bit */ - int k, begin_i, end_i, datatype_len; - - datatype_len = p.size * 8; - - if(p.order == H5Z_NBIT_ORDER_LE) { /* little endian */ - /* calculate begin_i and end_i */ - if((p.precision + p.offset) % 8 != 0) - begin_i = (p.precision + p.offset) / 8; - else - begin_i = (p.precision + p.offset) / 8 - 1; - end_i = p.offset / 8; - - for(k = begin_i; k >= end_i; k--) - H5Z_nbit_decompress_one_byte(data, data_offset, k, begin_i, end_i, - buffer, j, buf_len, p, datatype_len); - } - - if(p.order == H5Z_NBIT_ORDER_BE) { /* big endian */ - /* calculate begin_i and end_i */ - begin_i = (datatype_len - p.precision - p.offset) / 8; - if(p.offset % 8 != 0) - end_i = (datatype_len - p.offset) / 8; - else - end_i = (datatype_len - p.offset) / 8 - 1; - - for(k = begin_i; k <= end_i; k++) - H5Z_nbit_decompress_one_byte(data, data_offset, k, begin_i, end_i, - buffer, j, buf_len, p, datatype_len); - } + /* begin_i: the index of byte having first significant bit + end_i: the index of byte having last significant bit */ + int k; + unsigned begin_i, end_i; + size_t datatype_len; + + datatype_len = p->size * 8; + + if(p->order == H5Z_NBIT_ORDER_LE) { /* little endian */ + /* calculate begin_i and end_i */ + if((p->precision + p->offset) % 8 != 0) + begin_i = (p->precision + p->offset) / 8; + else + begin_i = (p->precision + p->offset) / 8 - 1; + end_i = p->offset / 8; + + for(k = (int)begin_i; k >= (int)end_i; k--) + H5Z_nbit_decompress_one_byte(data, data_offset, (unsigned)k, begin_i, end_i, + buffer, j, buf_len, p, datatype_len); + } + else { /* big endian */ + /* Sanity check */ + HDassert(p->order == H5Z_NBIT_ORDER_BE); + + /* calculate begin_i and end_i */ + begin_i = ((unsigned)datatype_len - p->precision - p->offset) / 8; + if(p->offset % 8 != 0) + end_i = ((unsigned)datatype_len - p->offset) / 8; + else + end_i = ((unsigned)datatype_len - p->offset) / 8 - 1; + + for(k = (int)begin_i; k <= (int)end_i; k++) + H5Z_nbit_decompress_one_byte(data, data_offset, (unsigned)k, begin_i, end_i, + buffer, j, buf_len, p, datatype_len); + } } static void H5Z_nbit_decompress_one_array(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, const unsigned parms[]) + unsigned char *buffer, size_t *j, size_t *buf_len, const unsigned parms[], + unsigned *parms_index) { unsigned i, total_size, base_class, base_size, n, begin_index; parms_atomic p; - total_size = parms[parms_index++]; - base_class = parms[parms_index++]; + total_size = parms[(*parms_index)++]; + base_class = parms[(*parms_index)++]; switch(base_class) { case H5Z_NBIT_ATOMIC: - p.size = parms[parms_index++]; - p.order = parms[parms_index++]; - p.precision = parms[parms_index++]; - p.offset = parms[parms_index++]; - n = total_size/p.size; + p.size = parms[(*parms_index)++]; + p.order = parms[(*parms_index)++]; + p.precision = parms[(*parms_index)++]; + p.offset = parms[(*parms_index)++]; + n = total_size / p.size; for(i = 0; i < n; i++) - H5Z_nbit_decompress_one_atomic(data, data_offset + i*p.size, - buffer, j, buf_len, p); + H5Z_nbit_decompress_one_atomic(data, data_offset + i * p.size, + buffer, j, buf_len, &p); break; + case H5Z_NBIT_ARRAY: - base_size = parms[parms_index]; /* read in advance */ - n = total_size/base_size; /* number of base_type elements inside the array datatype */ - begin_index = parms_index; + base_size = parms[*parms_index]; /* read in advance */ + n = total_size / base_size; /* number of base_type elements inside the array datatype */ + begin_index = *parms_index; for(i = 0; i < n; i++) { - H5Z_nbit_decompress_one_array(data, data_offset + i*base_size, - buffer, j, buf_len, parms); - parms_index = begin_index; + H5Z_nbit_decompress_one_array(data, data_offset + i * base_size, + buffer, j, buf_len, parms, parms_index); + *parms_index = begin_index; } break; + case H5Z_NBIT_COMPOUND: - base_size = parms[parms_index]; /* read in advance */ - n = total_size/base_size; /* number of base_type elements inside the array datatype */ - begin_index = parms_index; + base_size = parms[*parms_index]; /* read in advance */ + n = total_size / base_size; /* number of base_type elements inside the array datatype */ + begin_index = *parms_index; for(i = 0; i < n; i++) { - H5Z_nbit_decompress_one_compound(data, data_offset + i*base_size, - buffer, j, buf_len, parms); - parms_index = begin_index; + H5Z_nbit_decompress_one_compound(data, data_offset + i * base_size, + buffer, j, buf_len, parms, parms_index); + *parms_index = begin_index; } break; + case H5Z_NBIT_NOOPTYPE: - parms_index++; /* skip size of no-op type */ + (*parms_index)++; /* skip size of no-op type */ H5Z_nbit_decompress_one_nooptype(data, data_offset, buffer, j, buf_len, total_size); break; + default: HDassert(0 && "This Should never be executed!"); } /* end switch */ @@ -1191,39 +1223,44 @@ H5Z_nbit_decompress_one_array(unsigned char *data, size_t data_offset, static void H5Z_nbit_decompress_one_compound(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, const unsigned parms[]) + unsigned char *buffer, size_t *j, size_t *buf_len, const unsigned parms[], + unsigned *parms_index) { unsigned i, nmembers, member_offset, member_class, size; parms_atomic p; - parms_index++; /* skip total size of compound datatype */ - nmembers = parms[parms_index++]; + (*parms_index)++; /* skip total size of compound datatype */ + nmembers = parms[(*parms_index)++]; for(i = 0; i < nmembers; i++) { - member_offset = parms[parms_index++]; - member_class = parms[parms_index++]; + member_offset = parms[(*parms_index)++]; + member_class = parms[(*parms_index)++]; switch(member_class) { case H5Z_NBIT_ATOMIC: - p.size = parms[parms_index++]; - p.order = parms[parms_index++]; - p.precision = parms[parms_index++]; - p.offset = parms[parms_index++]; + p.size = parms[(*parms_index)++]; + p.order = parms[(*parms_index)++]; + p.precision = parms[(*parms_index)++]; + p.offset = parms[(*parms_index)++]; H5Z_nbit_decompress_one_atomic(data, data_offset + member_offset, - buffer, j, buf_len, p); + buffer, j, buf_len, &p); break; + case H5Z_NBIT_ARRAY: H5Z_nbit_decompress_one_array(data, data_offset + member_offset, - buffer, j, buf_len, parms); + buffer, j, buf_len, parms, parms_index); break; + case H5Z_NBIT_COMPOUND: H5Z_nbit_decompress_one_compound(data, data_offset+member_offset, - buffer, j, buf_len, parms); + buffer, j, buf_len, parms, parms_index); break; + case H5Z_NBIT_NOOPTYPE: - size = parms[parms_index++]; + size = parms[(*parms_index)++]; H5Z_nbit_decompress_one_nooptype(data, data_offset+member_offset, buffer, j, buf_len, size); break; + default: HDassert(0 && "This Should never be executed!"); } /* end switch */ @@ -1232,94 +1269,101 @@ H5Z_nbit_decompress_one_compound(unsigned char *data, size_t data_offset, static void H5Z_nbit_decompress(unsigned char *data, unsigned d_nelmts, unsigned char *buffer, - const unsigned parms[]) + const unsigned parms[]) { - /* i: index of data, j: index of buffer, - buf_len: number of bits to be filled in current byte */ - size_t i, j, size; - int buf_len; - parms_atomic p; + /* i: index of data, j: index of buffer, + buf_len: number of bits to be filled in current byte */ + unsigned i; + size_t j, size; + size_t buf_len; + parms_atomic p; + unsigned parms_index; /* index in array parms used by compression/decompression functions */ + + /* may not have to initialize to zeros */ + HDmemset(data, 0, d_nelmts * parms[4]); + + /* initialization before the loop */ + j = 0; + buf_len = sizeof(unsigned char) * 8; + + switch(parms[3]) { + case H5Z_NBIT_ATOMIC: + p.size = parms[4]; + p.order = parms[5]; + p.precision = parms[6]; + p.offset = parms[7]; + for(i = 0; i < d_nelmts; i++) + H5Z_nbit_decompress_one_atomic(data, i * p.size, buffer, &j, &buf_len, &p); + break; - /* may not have to initialize to zeros */ - for(i = 0; i < d_nelmts*parms[4]; i++) data[i] = 0; + case H5Z_NBIT_ARRAY: + size = parms[4]; + parms_index = 4; /* set the index before goto function call */ + for(i = 0; i < d_nelmts; i++) { + H5Z_nbit_decompress_one_array(data, i * size, buffer, &j, &buf_len, parms, &parms_index); + parms_index = 4; + } + break; - /* initialization before the loop */ - j = 0; - buf_len = sizeof(unsigned char) * 8; + case H5Z_NBIT_COMPOUND: + size = parms[4]; + parms_index = 4; /* set the index before goto function call */ + for(i = 0; i < d_nelmts; i++) { + H5Z_nbit_decompress_one_compound(data, i * size, buffer, &j, &buf_len, parms, &parms_index); + parms_index = 4; + } + break; - switch(parms[3]) { - case H5Z_NBIT_ATOMIC: - /* set the index before goto function call */ - p.size = parms[4]; - p.order = parms[5]; - p.precision = parms[6]; - p.offset = parms[7]; - for(i = 0; i < d_nelmts; i++) { - H5Z_nbit_decompress_one_atomic(data, i*p.size, buffer, &j, &buf_len, p); - } - break; - case H5Z_NBIT_ARRAY: - size = parms[4]; - parms_index = 4; - for(i = 0; i < d_nelmts; i++) { - H5Z_nbit_decompress_one_array(data, i*size, buffer, &j, &buf_len, parms); - parms_index = 4; - } - break; - case H5Z_NBIT_COMPOUND: - size = parms[4]; - parms_index = 4; - for(i = 0; i < d_nelmts; i++) { - H5Z_nbit_decompress_one_compound(data, i*size, buffer, &j, &buf_len, parms); - parms_index = 4; - } - break; - default: - HDassert(0 && "This Should never be executed!"); - } /* end switch */ + default: + HDassert(0 && "This Should never be executed!"); + } /* end switch */ } -static void H5Z_nbit_compress_one_byte(unsigned char *data, size_t data_offset, int k, int begin_i, -int end_i, unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p, int datatype_len) +static void +H5Z_nbit_compress_one_byte(unsigned char *data, size_t data_offset, unsigned k, + unsigned begin_i, unsigned end_i, unsigned char *buffer, size_t *j, size_t *buf_len, + const parms_atomic *p, size_t datatype_len) { - int dat_len; /* dat_len is the number of bits to be copied in each data byte */ + size_t dat_len; /* dat_len is the number of bits to be copied in each data byte */ unsigned char val; /* value to be copied in each data byte */ /* initialize value and bits of unsigned char to be copied */ val = data[data_offset + k]; if(begin_i != end_i) { /* significant bits occupy >1 unsigned char */ if(k == begin_i) - dat_len = 8 - (datatype_len - p.precision - p.offset) % 8; + dat_len = 8 - (datatype_len - p->precision - p->offset) % 8; else if(k == end_i) { - dat_len = 8 - p.offset % 8; - val >>= 8 - dat_len; + dat_len = 8 - p->offset % 8; + val = (unsigned char)(val >> (8 - dat_len)); } else dat_len = 8; } else { /* all significant bits in one unsigned char */ - val >>= p.offset % 8; - dat_len = p.precision; + val = (unsigned char)(val >> (p->offset % 8)); + dat_len = p->precision; } if(*buf_len > dat_len) { - buffer[*j] |= (val & ~(~0 << dat_len)) << (*buf_len - dat_len); + buffer[*j] |= (unsigned char)((val & ~((unsigned)(~0) << dat_len)) << (*buf_len - dat_len)); *buf_len -= dat_len; } else { - buffer[*j] |= (val >> (dat_len - *buf_len)) & ~(~0 << *buf_len); + buffer[*j] |= (unsigned char)((unsigned)(val >> (dat_len - *buf_len)) & ~((unsigned)(~0) << *buf_len)); dat_len -= *buf_len; H5Z_nbit_next_byte(j, buf_len); - if(dat_len == 0) return; + if(dat_len == 0) + return; - buffer[*j] = (val & ~(~0 << dat_len)) << (*buf_len - dat_len); + buffer[*j] = (unsigned char)((val & ~((unsigned)(~0) << dat_len)) << (*buf_len - dat_len)); *buf_len -= dat_len; } } -static void H5Z_nbit_compress_one_nooptype(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, unsigned size) +static void +H5Z_nbit_compress_one_nooptype(unsigned char *data, size_t data_offset, + unsigned char *buffer, size_t *j, size_t *buf_len, unsigned size) { unsigned i; /* index */ - unsigned dat_len; /* dat_len is the number of bits to be copied in each data byte */ + size_t dat_len; /* dat_len is the number of bits to be copied in each data byte */ unsigned char val; /* value to be copied in each data byte */ for(i = 0; i < size; i++) { @@ -1327,192 +1371,214 @@ static void H5Z_nbit_compress_one_nooptype(unsigned char *data, size_t data_offs val = data[data_offset + i]; dat_len = sizeof(unsigned char) * 8; - buffer[*j] |= (val >> (dat_len - *buf_len)) & ~(~0 << *buf_len); + buffer[*j] |= (unsigned char)((unsigned)(val >> (dat_len - *buf_len)) & ~((unsigned)(~0) << *buf_len)); dat_len -= *buf_len; H5Z_nbit_next_byte(j, buf_len); - if(dat_len == 0) continue; + if(dat_len == 0) + continue; - buffer[*j] = (val & ~(~0 << dat_len)) << (*buf_len - dat_len); + buffer[*j] = (unsigned char)((val & ~((unsigned)(~0) << dat_len)) << (*buf_len - dat_len)); *buf_len -= dat_len; } } -static void H5Z_nbit_compress_one_atomic(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p) +static void +H5Z_nbit_compress_one_atomic(unsigned char *data, size_t data_offset, + unsigned char *buffer, size_t *j, size_t *buf_len, const parms_atomic *p) { - /* begin_i: the index of byte having first significant bit - end_i: the index of byte having last significant bit */ - int k, begin_i, end_i, datatype_len; - - datatype_len = p.size * 8; - - if(p.order == H5Z_NBIT_ORDER_LE) { /* little endian */ - /* calculate begin_i and end_i */ - if((p.precision + p.offset) % 8 != 0) - begin_i = (p.precision + p.offset) / 8; - else - begin_i = (p.precision + p.offset) / 8 - 1; - end_i = p.offset / 8; - - for(k = begin_i; k >= end_i; k--) - H5Z_nbit_compress_one_byte(data, data_offset, k, begin_i, end_i, - buffer, j, buf_len, p, datatype_len); - } - - if(p.order == H5Z_NBIT_ORDER_BE) { /* big endian */ - /* calculate begin_i and end_i */ - begin_i = (datatype_len - p.precision - p.offset) / 8; - if(p.offset % 8 != 0) - end_i = (datatype_len - p.offset) / 8; - else - end_i = (datatype_len - p.offset) / 8 - 1; - - for(k = begin_i; k <= end_i; k++) - H5Z_nbit_compress_one_byte(data, data_offset, k, begin_i, end_i, - buffer, j, buf_len, p, datatype_len); - } + /* begin_i: the index of byte having first significant bit + end_i: the index of byte having last significant bit */ + int k; + unsigned begin_i, end_i; + size_t datatype_len; + + datatype_len = p->size * 8; + + if(p->order == H5Z_NBIT_ORDER_LE) { /* little endian */ + /* calculate begin_i and end_i */ + if((p->precision + p->offset) % 8 != 0) + begin_i = (p->precision + p->offset) / 8; + else + begin_i = (p->precision + p->offset) / 8 - 1; + end_i = p->offset / 8; + + for(k = (int)begin_i; k >= (int)end_i; k--) + H5Z_nbit_compress_one_byte(data, data_offset, (unsigned)k, begin_i, end_i, + buffer, j, buf_len, p, datatype_len); + } + else { /* big endian */ + /* Sanity check */ + HDassert(p->order == H5Z_NBIT_ORDER_BE); + + /* calculate begin_i and end_i */ + begin_i = ((unsigned)datatype_len - p->precision - p->offset) / 8; + if(p->offset % 8 != 0) + end_i = ((unsigned)datatype_len - p->offset) / 8; + else + end_i = ((unsigned)datatype_len - p->offset) / 8 - 1; + + for(k = (int)begin_i; k <= (int)end_i; k++) + H5Z_nbit_compress_one_byte(data, data_offset, (unsigned)k, begin_i, end_i, + buffer, j, buf_len, p, datatype_len); + } } -static void H5Z_nbit_compress_one_array(unsigned char *data, size_t data_offset, unsigned char *buffer, - size_t *j, int *buf_len, const unsigned parms[]) +static void +H5Z_nbit_compress_one_array(unsigned char *data, size_t data_offset, + unsigned char *buffer, size_t *j, size_t *buf_len, const unsigned parms[], + unsigned *parms_index) { unsigned i, total_size, base_class, base_size, n, begin_index; parms_atomic p; - total_size = parms[parms_index++]; - base_class = parms[parms_index++]; + total_size = parms[(*parms_index)++]; + base_class = parms[(*parms_index)++]; switch(base_class) { case H5Z_NBIT_ATOMIC: - p.size = parms[parms_index++]; - p.order = parms[parms_index++]; - p.precision = parms[parms_index++]; - p.offset = parms[parms_index++]; - n = total_size/p.size; + p.size = parms[(*parms_index)++]; + p.order = parms[(*parms_index)++]; + p.precision = parms[(*parms_index)++]; + p.offset = parms[(*parms_index)++]; + n = total_size / p.size; for(i = 0; i < n; i++) - H5Z_nbit_compress_one_atomic(data, data_offset + i*p.size, - buffer, j, buf_len, p); + H5Z_nbit_compress_one_atomic(data, data_offset + i * p.size, + buffer, j, buf_len, &p); break; + case H5Z_NBIT_ARRAY: - base_size = parms[parms_index]; /* read in advance */ - n = total_size/base_size; /* number of base_type elements inside the array datatype */ - begin_index = parms_index; + base_size = parms[*parms_index]; /* read in advance */ + n = total_size / base_size; /* number of base_type elements inside the array datatype */ + begin_index = *parms_index; for(i = 0; i < n; i++) { - H5Z_nbit_compress_one_array(data, data_offset + i*base_size, - buffer, j, buf_len, parms); - parms_index = begin_index; + H5Z_nbit_compress_one_array(data, data_offset + i * base_size, + buffer, j, buf_len, parms, parms_index); + *parms_index = begin_index; } break; + case H5Z_NBIT_COMPOUND: - base_size = parms[parms_index]; /* read in advance */ - n = total_size/base_size; /* number of base_type elements inside the array datatype */ - begin_index = parms_index; + base_size = parms[*parms_index]; /* read in advance */ + n = total_size / base_size; /* number of base_type elements inside the array datatype */ + begin_index = *parms_index; for(i = 0; i < n; i++) { - H5Z_nbit_compress_one_compound(data, data_offset + i*base_size, - buffer, j, buf_len, parms); - parms_index = begin_index; + H5Z_nbit_compress_one_compound(data, data_offset + i * base_size, + buffer, j, buf_len, parms, parms_index); + *parms_index = begin_index; } break; + case H5Z_NBIT_NOOPTYPE: - parms_index++; /* skip size of no-op type */ + (*parms_index)++; /* skip size of no-op type */ H5Z_nbit_compress_one_nooptype(data, data_offset, buffer, j, buf_len, total_size); break; + default: HDassert(0 && "This Should never be executed!"); } /* end switch */ } -static void H5Z_nbit_compress_one_compound(unsigned char *data, size_t data_offset, - unsigned char *buffer, size_t *j, int *buf_len, const unsigned parms[]) +static void +H5Z_nbit_compress_one_compound(unsigned char *data, size_t data_offset, + unsigned char *buffer, size_t *j, size_t *buf_len, const unsigned parms[], + unsigned *parms_index) { unsigned i, nmembers, member_offset, member_class, size; parms_atomic p; - parms_index++; /* skip size of compound datatype */ - nmembers = parms[parms_index++]; + (*parms_index)++; /* skip size of compound datatype */ + nmembers = parms[(*parms_index)++]; for(i = 0; i < nmembers; i++) { - member_offset = parms[parms_index++]; - member_class = parms[parms_index++]; + member_offset = parms[(*parms_index)++]; + member_class = parms[(*parms_index)++]; switch(member_class) { case H5Z_NBIT_ATOMIC: - p.size = parms[parms_index++]; - p.order = parms[parms_index++]; - p.precision = parms[parms_index++]; - p.offset = parms[parms_index++]; + p.size = parms[(*parms_index)++]; + p.order = parms[(*parms_index)++]; + p.precision = parms[(*parms_index)++]; + p.offset = parms[(*parms_index)++]; H5Z_nbit_compress_one_atomic(data, data_offset + member_offset, - buffer, j, buf_len, p); + buffer, j, buf_len, &p); break; + case H5Z_NBIT_ARRAY: H5Z_nbit_compress_one_array(data, data_offset + member_offset, - buffer, j, buf_len, parms); + buffer, j, buf_len, parms, parms_index); break; + case H5Z_NBIT_COMPOUND: H5Z_nbit_compress_one_compound(data, data_offset+member_offset, - buffer, j, buf_len, parms); + buffer, j, buf_len, parms, parms_index); break; + case H5Z_NBIT_NOOPTYPE: - size = parms[parms_index++]; + size = parms[(*parms_index)++]; H5Z_nbit_compress_one_nooptype(data, data_offset+member_offset, buffer, j, buf_len, size); break; + default: HDassert(0 && "This Should never be executed!"); } /* end switch */ } } -static void H5Z_nbit_compress(unsigned char *data, unsigned d_nelmts, unsigned char *buffer, - size_t *buffer_size, const unsigned parms[]) +static void +H5Z_nbit_compress(unsigned char *data, unsigned d_nelmts, unsigned char *buffer, + size_t *buffer_size, const unsigned parms[]) { - /* i: index of data, new_size: index of buffer, - buf_len: number of bits to be filled in current byte */ - size_t i, size; - size_t new_size = 0; - int buf_len; - parms_atomic p; + /* i: index of data, new_size: index of buffer, + buf_len: number of bits to be filled in current byte */ + unsigned i; + size_t size; + size_t new_size = 0; + size_t buf_len; + parms_atomic p; + unsigned parms_index; /* index in array parms used by compression/decompression functions */ + + /* must initialize buffer to be zeros */ + HDmemset(buffer, 0, *buffer_size); + + /* initialization before the loop */ + buf_len = sizeof(unsigned char) * 8; + + switch(parms[3]) { + case H5Z_NBIT_ATOMIC: + p.size = parms[4]; + p.order = parms[5]; + p.precision = parms[6]; + p.offset = parms[7]; + + for(i = 0; i < d_nelmts; i++) + H5Z_nbit_compress_one_atomic(data, i * p.size, buffer, &new_size, &buf_len, &p); + break; - /* must initialize buffer to be zeros */ - HDmemset(buffer, 0, *buffer_size); + case H5Z_NBIT_ARRAY: + size = parms[4]; + parms_index = 4; + for(i = 0; i < d_nelmts; i++) { + H5Z_nbit_compress_one_array(data, i * size, buffer, &new_size, &buf_len, parms, &parms_index); + parms_index = 4; + } + break; - /* initialization before the loop */ - buf_len = sizeof(unsigned char) * 8; + case H5Z_NBIT_COMPOUND: + size = parms[4]; + parms_index = 4; + for(i = 0; i < d_nelmts; i++) { + H5Z_nbit_compress_one_compound(data, i * size, buffer, &new_size, &buf_len, parms, &parms_index); + parms_index = 4; + } + break; - switch(parms[3]) { - case H5Z_NBIT_ATOMIC: - /* set the index before goto function call */ - p.size = parms[4]; - p.order = parms[5]; - p.precision = parms[6]; - p.offset = parms[7]; - - for(i = 0; i < d_nelmts; i++) { - H5Z_nbit_compress_one_atomic(data, i*p.size, buffer, &new_size, &buf_len, p); - } - break; - case H5Z_NBIT_ARRAY: - size = parms[4]; - parms_index = 4; - for(i = 0; i < d_nelmts; i++) { - H5Z_nbit_compress_one_array(data, i*size, buffer, &new_size, &buf_len, parms); - parms_index = 4; - } - break; - case H5Z_NBIT_COMPOUND: - size = parms[4]; - parms_index = 4; - for(i = 0; i < d_nelmts; i++) { - H5Z_nbit_compress_one_compound(data, i*size, buffer, &new_size, &buf_len, parms); - parms_index = 4; - } - break; - default: - HDassert(0 && "This Should never be executed!"); - } /* end switch */ + default: + HDassert(0 && "This Should never be executed!"); + } /* end switch */ - /* Update the size to the new value after compression. If there are any bits hanging over in - * the last byte, increment the value by 1. */ - *buffer_size = new_size + 1; + /* Update the size to the new value after compression. If there are any bits hanging over in + * the last byte, increment the value by 1. */ + *buffer_size = new_size + 1; } diff --git a/src/H5Zscaleoffset.c b/src/H5Zscaleoffset.c index 7c9dbf9..1cca9b1 100644 --- a/src/H5Zscaleoffset.c +++ b/src/H5Zscaleoffset.c @@ -28,7 +28,7 @@ /* Struct of parameters needed for compressing/decompressing one atomic datatype */ typedef struct { - size_t size; /* datatype size */ + unsigned size; /* datatype size */ uint32_t minbits; /* minimum bits to compress one value of such datatype */ unsigned mem_order; /* current memory endianness order */ } parms_atomic; @@ -38,7 +38,6 @@ enum H5Z_scaleoffset_t {t_bad=0, t_uchar=1, t_ushort, t_uint, t_ulong, t_ulong_l t_float, t_double}; /* Local function prototypes */ -static double H5Z_scaleoffset_rnd(double val); static htri_t H5Z_can_apply_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id); static enum H5Z_scaleoffset_t H5Z_scaleoffset_get_type(unsigned dtype_class, unsigned dtype_size, unsigned dtype_sign); @@ -48,7 +47,7 @@ static herr_t H5Z_scaleoffset_set_parms_fillval(H5P_genplist_t *dcpl_plist, static herr_t H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id); static size_t H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], size_t nbytes, size_t *buf_size, void **buf); -static void H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, size_t dtype_size); +static void H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, unsigned dtype_size); static H5_ATTR_CONST unsigned H5Z_scaleoffset_log2(unsigned long long num); static void H5Z_scaleoffset_precompress_i(void *data, unsigned d_nelmts, enum H5Z_scaleoffset_t type, unsigned filavail, const unsigned cd_values[], @@ -389,25 +388,28 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ } /* Check and handle special situation for floating-point type */ -#define H5Z_scaleoffset_check_3(i, type, max, min, minbits, D_val) \ +#define H5Z_scaleoffset_check_3(i, type, pow_fun, round_fun, max, min, minbits, D_val) \ { \ - if(sizeof(type)==sizeof(int)) { \ - if(H5Z_scaleoffset_rnd(max*HDpow(10.0f, D_val) - min*HDpow(10.0f, D_val)) \ - > HDpow(2.0f, (double)(sizeof(int)*8 - 1))) { \ - *minbits = sizeof(int)*8; goto done; \ - } \ - } else if(sizeof(type)==sizeof(long)) { \ - if(H5Z_scaleoffset_rnd(max*HDpow(10.0f, D_val) - min*HDpow(10.0f, D_val)) \ - > HDpow(2.0f, (double)(sizeof(long)*8 - 1))) { \ - *minbits = sizeof(long)*8; goto done; \ - } \ - } else if(sizeof(type)==sizeof(long long)) { \ - if(H5Z_scaleoffset_rnd(max*HDpow(10.0f, D_val) - min*HDpow(10.0f, D_val)) \ - > HDpow(2.0f, (double)(sizeof(long long)*8 - 1))) { \ - *minbits = sizeof(long long)*8; goto done; \ - } \ - } else \ - HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype")\ + if(sizeof(type) == sizeof(int)) { \ + if(round_fun(max * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)) \ + > pow_fun(2.0f, (type)(sizeof(int) * 8 - 1))) { \ + *minbits = sizeof(int) * 8; \ + goto done; \ + } \ + } else if(sizeof(type) == sizeof(long)) { \ + if(round_fun(max * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)) \ + > pow_fun(2.0f, (type)(sizeof(long) * 8 - 1))) { \ + *minbits = sizeof(long) * 8; \ + goto done; \ + } \ + } else if(sizeof(type) == sizeof(long long)) { \ + if(round_fun(max * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)) \ + > pow_fun(2.0f, (type)(sizeof(long long) * 8 - 1))) { \ + *minbits = sizeof(long long) * 8; \ + goto done; \ + } \ + } else \ + HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype") \ } /* Precompress for unsigned integer type */ @@ -477,53 +479,47 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ } /* Modify values of data in precompression if fill value defined for floating-point type */ -#define H5Z_scaleoffset_modify_1(i, type, buf, d_nelmts, filval, minbits, min, D_val) \ +#define H5Z_scaleoffset_modify_1(i, type, pow_fun, abs_fun, lround_fun, llround_fun, buf, d_nelmts, filval, minbits, min, D_val) \ { \ - if(sizeof(type)==sizeof(int)) \ + if(sizeof(type) == sizeof(int)) \ for(i = 0; i < d_nelmts; i++) { \ - if(HDfabs(buf[i] - filval) < HDpow(10.0f, -D_val)) \ + if(abs_fun(buf[i] - filval) < pow_fun(10.0f, (type)-D_val)) \ *(int *)&buf[i] = (int)(((unsigned int)1 << *minbits) - 1); \ else \ - *(int *)&buf[i] = H5Z_scaleoffset_rnd( \ - buf[i]*HDpow(10.0f, D_val) - min*HDpow(10.0f, D_val)); \ + *(int *)&buf[i] = (int)lround_fun(buf[i] * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)); \ } \ - else if(sizeof(type)==sizeof(long)) \ + else if(sizeof(type) == sizeof(long)) \ for(i = 0; i < d_nelmts; i++) { \ - if(HDfabs(buf[i] - filval) < HDpow(10.0f, -D_val)) \ + if(abs_fun(buf[i] - filval) < pow_fun(10.0f, (type)-D_val)) \ *(long *)&buf[i] = (long)(((unsigned long)1 << *minbits) - 1); \ else \ - *(long *)&buf[i] = H5Z_scaleoffset_rnd( \ - buf[i]*HDpow(10.0f, D_val) - min*HDpow(10.0f, D_val)); \ + *(long *)&buf[i] = lround_fun(buf[i] * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)); \ } \ - else if(sizeof(type)==sizeof(long long)) \ + else if(sizeof(type) == sizeof(long long)) \ for(i = 0; i < d_nelmts; i++) { \ - if(HDfabs(buf[i] - filval) < HDpow(10.0f, -D_val)) \ + if(abs_fun(buf[i] - filval) < pow_fun(10.0f, (type)-D_val)) \ *(long long *)&buf[i] = (long long)(((unsigned long long)1 << *minbits) - 1); \ else \ - *(long long *)&buf[i] = H5Z_scaleoffset_rnd( \ - buf[i]*HDpow(10.0f, D_val) - min*HDpow(10.0f, D_val)); \ + *(long long *)&buf[i] = llround_fun(buf[i] * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)); \ } \ else \ - HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype")\ + HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype") \ } /* Modify values of data in precompression if fill value undefined for floating-point type */ -#define H5Z_scaleoffset_modify_2(i, type, buf, d_nelmts, min, D_val) \ +#define H5Z_scaleoffset_modify_2(i, type, pow_fun, lround_fun, llround_fun, buf, d_nelmts, min, D_val) \ { \ - if(sizeof(type)==sizeof(int)) \ + if(sizeof(type) == sizeof(int)) \ for(i = 0; i < d_nelmts; i++) \ - *(int *)&buf[i] = H5Z_scaleoffset_rnd( \ - buf[i]*HDpow(10.0f, D_val) - min*HDpow(10.0f, D_val)); \ - else if(sizeof(type)==sizeof(long)) \ + *(int *)&buf[i] = (int)lround_fun(buf[i] * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)); \ + else if(sizeof(type) == sizeof(long)) \ for(i = 0; i < d_nelmts; i++) \ - *(long *)&buf[i] = H5Z_scaleoffset_rnd( \ - buf[i]*HDpow(10.0f, D_val) - min*HDpow(10.0f, D_val)); \ - else if(sizeof(type)==sizeof(long long)) \ + *(long *)&buf[i] = lround_fun(buf[i] * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)); \ + else if(sizeof(type) == sizeof(long long)) \ for(i = 0; i < d_nelmts; i++) \ - *(long long *)&buf[i] = H5Z_scaleoffset_rnd( \ - buf[i]*HDpow(10.0f, D_val) - min*HDpow(10.0f, D_val)); \ + *(long long *)&buf[i] = llround_fun(buf[i] * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)); \ else \ - HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype")\ + HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype") \ } /* Save the minimum value for floating-point type */ @@ -546,7 +542,7 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ } /* Precompress for floating-point type using variable-minimum-bits method */ -#define H5Z_scaleoffset_precompress_3(type, data, d_nelmts, filavail, cd_values, \ +#define H5Z_scaleoffset_precompress_3(type, pow_fun, abs_fun, round_fun, lround_fun, llround_fun, data, d_nelmts, filavail, cd_values, \ minbits, minval, D_val) \ { \ type *buf = (type *)data, min = 0, max = 0, filval = 0; \ @@ -557,18 +553,18 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */ \ H5Z_scaleoffset_get_filval_2(type, cd_values, filval) \ H5Z_scaleoffset_max_min_3(i, d_nelmts, buf, filval, max, min, D_val) \ - H5Z_scaleoffset_check_3(i, type, max, min, minbits, D_val) \ - span = H5Z_scaleoffset_rnd(max * HDpow(10.0f, D_val) - min * HDpow(10.0f, D_val)) + 1; \ - *minbits = H5Z_scaleoffset_log2((unsigned long long)(span + 1)); \ + H5Z_scaleoffset_check_3(i, type, pow_fun, round_fun, max, min, minbits, D_val) \ + span = (unsigned long long)(llround_fun(max * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)) + 1); \ + *minbits = H5Z_scaleoffset_log2(span + 1); \ if(*minbits != sizeof(type) * 8) /* change values if minbits != full precision */ \ - H5Z_scaleoffset_modify_1(i, type, buf, d_nelmts, filval, minbits, min, D_val) \ + H5Z_scaleoffset_modify_1(i, type, pow_fun, abs_fun, lround_fun, llround_fun, buf, d_nelmts, filval, minbits, min, D_val) \ } else { /* fill value undefined */ \ H5Z_scaleoffset_max_min_2(i, d_nelmts, buf, max, min) \ - H5Z_scaleoffset_check_3(i, type, max, min, minbits, D_val) \ - span = H5Z_scaleoffset_rnd(max * HDpow(10.0f, D_val) - min * HDpow(10.0f, D_val)) + 1; \ - *minbits = H5Z_scaleoffset_log2((unsigned long long)span); \ + H5Z_scaleoffset_check_3(i, type, pow_fun, round_fun, max, min, minbits, D_val) \ + span = (unsigned long long)(llround_fun(max * pow_fun(10.0f, (type)D_val) - min * pow_fun(10.0f, (type)D_val)) + 1); \ + *minbits = H5Z_scaleoffset_log2(span); \ if(*minbits != sizeof(type) * 8) /* change values if minbits != full precision */ \ - H5Z_scaleoffset_modify_2(i, type, buf, d_nelmts, min, D_val) \ + H5Z_scaleoffset_modify_2(i, type, pow_fun, lround_fun, llround_fun, buf, d_nelmts, min, D_val) \ } \ H5Z_scaleoffset_save_min(i, type, minval, min) \ } @@ -621,42 +617,42 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ } /* Modify values of data in postdecompression if fill value defined for floating-point type */ -#define H5Z_scaleoffset_modify_3(i, type, buf, d_nelmts, filval, minbits, min, D_val) \ +#define H5Z_scaleoffset_modify_3(i, type, pow_fun, buf, d_nelmts, filval, minbits, min, D_val) \ { \ - if(sizeof(type)==sizeof(int)) \ + if(sizeof(type) == sizeof(int)) \ for(i = 0; i < d_nelmts; i++) \ buf[i] = (type)((*(int *)&buf[i] == (int)(((unsigned int)1 << minbits) - 1)) ? \ - filval : (double)(*(int *)&buf[i]) / HDpow(10.0f, D_val) + min); \ - else if(sizeof(type)==sizeof(long)) \ + filval : (type)(*(int *)&buf[i]) / pow_fun(10.0f, (type)D_val) + min); \ + else if(sizeof(type) == sizeof(long)) \ for(i = 0; i < d_nelmts; i++) \ buf[i] = (type)((*(long *)&buf[i] == (long)(((unsigned long)1 << minbits) - 1)) ? \ - filval : (double)(*(long *)&buf[i]) / HDpow(10.0f, D_val) + min); \ - else if(sizeof(type)==sizeof(long long)) \ + filval : (type)(*(long *)&buf[i]) / pow_fun(10.0f, (type)D_val) + min); \ + else if(sizeof(type) == sizeof(long long)) \ for(i = 0; i < d_nelmts; i++) \ buf[i] = (type)((*(long long *)&buf[i] == (long long)(((unsigned long long)1 << minbits) - 1)) ? \ - filval : (double)(*(long long *)&buf[i]) / HDpow(10.0f, D_val) + min); \ + filval : (type)(*(long long *)&buf[i]) / pow_fun(10.0f, (type)D_val) + min); \ else \ HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype") \ } /* Modify values of data in postdecompression if fill value undefined for floating-point type */ -#define H5Z_scaleoffset_modify_4(i, type, buf, d_nelmts, min, D_val) \ +#define H5Z_scaleoffset_modify_4(i, type, pow_fun, buf, d_nelmts, min, D_val) \ { \ if(sizeof(type)==sizeof(int)) \ for(i = 0; i < d_nelmts; i++) \ - buf[i] = (type)((double)(*(int *)&buf[i]) / HDpow(10.0f, D_val) + min); \ + buf[i] = ((type)(*(int *)&buf[i]) / pow_fun(10.0f, (type)D_val) + min); \ else if(sizeof(type)==sizeof(long)) \ for(i = 0; i < d_nelmts; i++) \ - buf[i] = (type)((double)(*(long *)&buf[i]) / HDpow(10.0f, D_val) + min); \ + buf[i] = ((type)(*(long *)&buf[i]) / pow_fun(10.0f, (type)D_val) + min); \ else if(sizeof(type)==sizeof(long long)) \ for(i = 0; i < d_nelmts; i++) \ - buf[i] = (type)((double)(*(long long *)&buf[i]) / HDpow(10.0f, D_val) + min); \ + buf[i] = ((type)(*(long long *)&buf[i]) / pow_fun(10.0f, (type)D_val) + min); \ else \ HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype") \ } /* Postdecompress for floating-point type using variable-minimum-bits method */ -#define H5Z_scaleoffset_postdecompress_3(type, data, d_nelmts, filavail, cd_values, \ +#define H5Z_scaleoffset_postdecompress_3(type, pow_fun, data, d_nelmts, filavail, cd_values, \ minbits, minval, D_val) \ { \ type *buf = (type *)data, filval = 0, min = 0; \ @@ -666,9 +662,9 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ \ if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */ \ H5Z_scaleoffset_get_filval_2(type, cd_values, filval) \ - H5Z_scaleoffset_modify_3(i, type, buf, d_nelmts, filval, minbits, min, D_val) \ + H5Z_scaleoffset_modify_3(i, type, pow_fun, buf, d_nelmts, filval, minbits, min, D_val) \ } else /* fill value undefined */ \ - H5Z_scaleoffset_modify_4(i, type, buf, d_nelmts, min, D_val) \ + H5Z_scaleoffset_modify_4(i, type, pow_fun, buf, d_nelmts, min, D_val) \ } @@ -756,7 +752,9 @@ H5Z_scaleoffset_get_type(unsigned dtype_class, unsigned dtype_size, unsigned dty else if(dtype_size == sizeof(unsigned short)) type = t_ushort; else if(dtype_size == sizeof(unsigned int)) type = t_uint; else if(dtype_size == sizeof(unsigned long)) type = t_ulong; +#if H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG else if(dtype_size == sizeof(unsigned long long)) type = t_ulong_long; +#endif /* H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG */ else HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, t_bad, "cannot find matched memory dataype") } @@ -766,7 +764,9 @@ H5Z_scaleoffset_get_type(unsigned dtype_class, unsigned dtype_size, unsigned dty else if(dtype_size == sizeof(short)) type = t_short; else if(dtype_size == sizeof(int)) type = t_int; else if(dtype_size == sizeof(long)) type = t_long; +#if H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG else if(dtype_size == sizeof(long long)) type = t_long_long; +#endif /* H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG */ else HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, t_bad, "cannot find matched memory dataype") } @@ -935,7 +935,8 @@ H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype size") /* Set "local" parameter for datatype size */ - cd_values[H5Z_SCALEOFFSET_PARM_SIZE] = dtype_size; + H5_CHECK_OVERFLOW(dtype_size, size_t, unsigned); + cd_values[H5Z_SCALEOFFSET_PARM_SIZE] = (unsigned)dtype_size; if(dtype_class == H5T_INTEGER) { /* Get datatype's sign */ @@ -1196,7 +1197,7 @@ H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_value } /* before postprocess, get memory type */ - if((type = H5Z_scaleoffset_get_type(dtype_class, (unsigned)p.size, dtype_sign)) == 0) + if((type = H5Z_scaleoffset_get_type(dtype_class, p.size, dtype_sign)) == 0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, 0, "cannot use C integer datatype for cast") /* postprocess after decompression */ @@ -1224,7 +1225,7 @@ H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_value H5Z_scaleoffset_convert(*buf, d_nelmts, p.size); /* before preprocess, get memory type */ - if((type = H5Z_scaleoffset_get_type(dtype_class, (unsigned)p.size, dtype_sign))==0) + if((type = H5Z_scaleoffset_get_type(dtype_class, p.size, dtype_sign))==0) HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, 0, "cannot use C integer datatype for cast") /* preprocess before compression */ @@ -1316,10 +1317,10 @@ done: * or from big-endian to little-endian 2/21/2005 */ static void -H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, size_t dtype_size) +H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, unsigned dtype_size) { if(dtype_size > 1) { - unsigned i, j; + size_t i, j; unsigned char *buffer, temp; buffer = (unsigned char *)buf; @@ -1333,32 +1334,6 @@ H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, size_t dtype_size) } /* end if */ } /* end H5Z_scaleoffset_convert() */ -/* Round a floating-point value to the nearest integer value 4/19/05 */ -/* rounding to the bigger absolute value if val is in the middle, - 0.5 -> 1, -0.5 ->-1 -5/9/05, KY */ -static double -H5Z_scaleoffset_rnd(double val) -{ - double u_val, l_val; - - u_val = HDceil(val); - l_val = HDfloor(val); - - if(val > 0) { - if((u_val - val) <= (val - l_val)) - return u_val; - else - return l_val; - } /* end if */ - else { - if((val - l_val) <= (u_val - val)) - return l_val; - else - return u_val; - } -} /* H5Z_scaleoffset_rnd() */ - /* return ceiling of floating-point log2 function * receive unsigned integer as argument 3/10/2005 */ @@ -1507,19 +1482,19 @@ H5Z_scaleoffset_precompress_fd(void *data, unsigned d_nelmts, enum H5Z_scaleoffs unsigned filavail, const unsigned cd_values[], uint32_t *minbits, unsigned long long *minval, double D_val) { - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT + FUNC_ENTER_NOAPI_NOINIT - if(type == t_float) - H5Z_scaleoffset_precompress_3(float, data, d_nelmts, - filavail, cd_values, minbits, minval, D_val) - else if(type == t_double) - H5Z_scaleoffset_precompress_3(double, data, d_nelmts, - filavail, cd_values, minbits, minval, D_val) + if(type == t_float) + H5Z_scaleoffset_precompress_3(float, HDpowf, HDfabsf, HDroundf, HDlroundf, HDllroundf, data, d_nelmts, + filavail, cd_values, minbits, minval, D_val) + else if(type == t_double) + H5Z_scaleoffset_precompress_3(double, HDpow, HDfabs, HDround, HDlround, HDllround, data, d_nelmts, + filavail, cd_values, minbits, minval, D_val) done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI(ret_value) } /* postdecompress for floating-point type, variable-minimum-bits method @@ -1535,10 +1510,10 @@ H5Z_scaleoffset_postdecompress_fd(void *data, unsigned d_nelmts, enum H5Z_scaleo FUNC_ENTER_NOAPI_NOINIT if(type == t_float) - H5Z_scaleoffset_postdecompress_3(float, data, d_nelmts, filavail, + H5Z_scaleoffset_postdecompress_3(float, HDpowf, data, d_nelmts, filavail, cd_values, minbits, sminval, D_val) else if(type == t_double) - H5Z_scaleoffset_postdecompress_3(double, data, d_nelmts, filavail, + H5Z_scaleoffset_postdecompress_3(double, HDpow, data, d_nelmts, filavail, cd_values, minbits, sminval, D_val) done: @@ -1568,18 +1543,18 @@ H5Z_scaleoffset_decompress_one_byte(unsigned char *data, size_t data_offset, dat_len = 8; if(*buf_len > dat_len) { - data[data_offset + k] = (unsigned char)((val >> (*buf_len - dat_len)) & ~(~0 << dat_len)); + data[data_offset + k] = (unsigned char)((unsigned)(val >> (*buf_len - dat_len)) & (unsigned)(~((unsigned)~0 << dat_len))); *buf_len -= dat_len; } /* end if */ else { - data[data_offset + k] = (unsigned char)((val & ~(~0 << *buf_len)) << (dat_len - *buf_len)); + data[data_offset + k] = (unsigned char)((val & ~((unsigned)(~0) << *buf_len)) << (dat_len - *buf_len)); dat_len -= *buf_len; H5Z_scaleoffset_next_byte(j, buf_len); if(dat_len == 0) return; val = buffer[*j]; - data[data_offset + k] |= (unsigned char)((val >> (*buf_len - dat_len)) & ~(~0 << dat_len)); + data[data_offset + k] |= (unsigned char)((unsigned)(val >> (*buf_len - dat_len)) & ~((unsigned)(~0) << dat_len)); *buf_len -= dat_len; } /* end else */ } @@ -1625,7 +1600,7 @@ H5Z_scaleoffset_decompress(unsigned char *data, unsigned d_nelmts, unsigned buf_len; /* must initialize to zeros */ - for(i = 0; i < d_nelmts*p.size; i++) + for(i = 0; i < d_nelmts * p.size; i++) data[i] = 0; /* initialization before the loop */ @@ -1653,16 +1628,16 @@ H5Z_scaleoffset_compress_one_byte(unsigned char *data, size_t data_offset, dat_len = 8; if(*buf_len > dat_len) { - buffer[*j] |= (unsigned char)((val & ~(~0 << dat_len)) << (*buf_len - dat_len)); + buffer[*j] |= (unsigned char)((val & ~((unsigned)(~0) << dat_len)) << (*buf_len - dat_len)); *buf_len -= dat_len; } else { - buffer[*j] |= (unsigned char)((val >> (dat_len - *buf_len)) & ~(~0 << *buf_len)); + buffer[*j] |= (unsigned char)((unsigned)(val >> (dat_len - *buf_len)) & ~((unsigned)(~0) << *buf_len)); dat_len -= *buf_len; H5Z_scaleoffset_next_byte(j, buf_len); if(dat_len == 0) return; - buffer[*j] = (unsigned char)((val & ~(~0 << dat_len)) << (*buf_len - dat_len)); + buffer[*j] = (unsigned char)((val & ~((unsigned)(~0) << dat_len)) << (*buf_len - dat_len)); *buf_len -= dat_len; } /* end else */ } diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c index 2627a29..f30f0b2 100644 --- a/src/H5Ztrans.c +++ b/src/H5Ztrans.c @@ -124,8 +124,8 @@ static void H5Z_print(H5Z_node *tree, FILE *stream); tree_val = ((RESR).type==H5Z_XFORM_INTEGER ? (double)(RESR).value.int_val : (RESR).value.float_val); \ p = (TYPE*)(RESL).value.dat_val; \ \ - for(u=0; u<(SIZE); u++) { \ - *p = *p OP tree_val; \ + for(u = 0; u < (SIZE); u++) { \ + *p = (TYPE)((double)*p OP tree_val); \ p++; \ } \ } \ @@ -141,32 +141,31 @@ static void H5Z_print(H5Z_node *tree, FILE *stream); tree_val = ((RESL).type==H5Z_XFORM_INTEGER ? (double)(RESL).value.int_val : (RESL).value.float_val); \ \ p = (TYPE*)(RESR).value.dat_val; \ - for(u=0; u<(SIZE); u++) { \ - *p = tree_val OP *p; \ + for(u = 0; u < (SIZE); u++) { \ + *p = (TYPE)(tree_val OP (double)*p); \ p++; \ } \ } \ - else if( ((RESL).type == H5Z_XFORM_SYMBOL) && ((RESR).type==H5Z_XFORM_SYMBOL)) \ - { \ - TYPE* pl = (TYPE*)(RESL).value.dat_val; \ - TYPE* pr = (TYPE*)(RESR).value.dat_val; \ - \ - for(u=0; u<(SIZE); u++) { \ - *pl = *pl OP *pr; \ - pl++; pr++; \ - } \ - } \ - else \ + else if( ((RESL).type == H5Z_XFORM_SYMBOL) && ((RESR).type == H5Z_XFORM_SYMBOL)) \ + { \ + TYPE* pl = (TYPE*)(RESL).value.dat_val; \ + TYPE* pr = (TYPE*)(RESR).value.dat_val; \ + \ + for(u = 0; u < (SIZE); u++) { \ + *pl = (TYPE)(*pl OP *pr); \ + pl++; pr++; \ + } \ + } \ + else \ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Unexpected type conversion operation") \ } -#if H5_SIZEOF_LONG_DOUBLE !=0 +#if H5_SIZEOF_LONG_DOUBLE != 0 +#if CHAR_MIN >= 0 #define H5Z_XFORM_TYPE_OP(RESL,RESR,TYPE,OP,SIZE) \ { \ if((TYPE) == H5T_NATIVE_CHAR) \ H5Z_XFORM_DO_OP1((RESL), (RESR), char, OP, (SIZE)) \ - else if((TYPE) == H5T_NATIVE_UCHAR) \ - H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned char, OP, (SIZE)) \ else if((TYPE) == H5T_NATIVE_SCHAR) \ H5Z_XFORM_DO_OP1((RESL), (RESR), signed char, OP, (SIZE)) \ else if((TYPE) == H5T_NATIVE_SHORT) \ @@ -182,7 +181,7 @@ static void H5Z_print(H5Z_node *tree, FILE *stream); else if((TYPE) == H5T_NATIVE_ULONG) \ H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned long, OP, (SIZE)) \ else if((TYPE) == H5T_NATIVE_LLONG) \ - H5Z_XFORM_DO_OP1((RESL), (RESR), long long, OP, (SIZE)) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), long long, OP, (SIZE)) \ else if((TYPE) == H5T_NATIVE_ULLONG) \ H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned long long, OP, (SIZE)) \ else if((TYPE) == H5T_NATIVE_FLOAT) \ @@ -192,13 +191,43 @@ static void H5Z_print(H5Z_node *tree, FILE *stream); else if((TYPE) == H5T_NATIVE_LDOUBLE) \ H5Z_XFORM_DO_OP1((RESL), (RESR), long double, OP, (SIZE)) \ } -#else +#else /* CHAR_MIN >= 0 */ #define H5Z_XFORM_TYPE_OP(RESL,RESR,TYPE,OP,SIZE) \ { \ if((TYPE) == H5T_NATIVE_CHAR) \ H5Z_XFORM_DO_OP1((RESL), (RESR), char, OP, (SIZE)) \ else if((TYPE) == H5T_NATIVE_UCHAR) \ H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned char, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_SHORT) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), short, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_USHORT) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned short, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_INT) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), int, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_UINT) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned int, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_LONG) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), long, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_ULONG) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned long, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_LLONG) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), long long, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_ULLONG) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned long long, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_FLOAT) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), float, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_DOUBLE) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), double, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_LDOUBLE) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), long double, OP, (SIZE)) \ +} +#endif /* CHAR_MIN >= 0 */ +#else +#if CHAR_MIN >= 0 +#define H5Z_XFORM_TYPE_OP(RESL,RESR,TYPE,OP,SIZE) \ +{ \ + if((TYPE) == H5T_NATIVE_CHAR) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), char, OP, (SIZE)) \ else if((TYPE) == H5T_NATIVE_SCHAR) \ H5Z_XFORM_DO_OP1((RESL), (RESR), signed char, OP, (SIZE)) \ else if((TYPE) == H5T_NATIVE_SHORT) \ @@ -222,6 +251,35 @@ static void H5Z_print(H5Z_node *tree, FILE *stream); else if((TYPE) == H5T_NATIVE_DOUBLE) \ H5Z_XFORM_DO_OP1((RESL), (RESR), double, OP, (SIZE)) \ } +#else /* CHAR_MIN >= 0 */ +#define H5Z_XFORM_TYPE_OP(RESL,RESR,TYPE,OP,SIZE) \ +{ \ + if((TYPE) == H5T_NATIVE_CHAR) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), char, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_UCHAR) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned char, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_SHORT) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), short, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_USHORT) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned short, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_INT) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), int, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_UINT) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned int, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_LONG) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), long, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_ULONG) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned long, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_LLONG) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), long long, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_ULLONG) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), unsigned long long, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_FLOAT) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), float, OP, (SIZE)) \ + else if((TYPE) == H5T_NATIVE_DOUBLE) \ + H5Z_XFORM_DO_OP1((RESL), (RESR), double, OP, (SIZE)) \ +} +#endif /* CHAR_MIN >= 0 */ #endif /*H5_SIZEOF_LONG_DOUBLE */ #define H5Z_XFORM_DO_OP3(OP) \ @@ -977,17 +1035,20 @@ H5Z_xform_eval(H5Z_data_xform_t *data_xform_prop, void* array, size_t array_size if(tree->type == H5Z_XFORM_INTEGER || tree->type == H5Z_XFORM_FLOAT) { if(array_type == H5T_NATIVE_CHAR) H5Z_XFORM_DO_OP5(char, array_size) - else if(array_type == H5T_NATIVE_UCHAR) - H5Z_XFORM_DO_OP5(unsigned char, array_size) +#if CHAR_MIN >= 0 else if(array_type == H5T_NATIVE_SCHAR) H5Z_XFORM_DO_OP5(signed char, array_size) +#else /* CHAR_MIN >= 0 */ + else if(array_type == H5T_NATIVE_UCHAR) + H5Z_XFORM_DO_OP5(unsigned char, array_size) +#endif /* CHAR_MIN >= 0 */ else if(array_type == H5T_NATIVE_SHORT) H5Z_XFORM_DO_OP5(short, array_size) else if(array_type == H5T_NATIVE_USHORT) H5Z_XFORM_DO_OP5(unsigned short, array_size) else if(array_type == H5T_NATIVE_INT) H5Z_XFORM_DO_OP5(int, array_size) - else if(array_type == H5T_NATIVE_UINT) + else if(array_type == H5T_NATIVE_UINT) H5Z_XFORM_DO_OP5(unsigned int, array_size) else if(array_type == H5T_NATIVE_LONG) H5Z_XFORM_DO_OP5(long, array_size) @@ -1106,34 +1167,32 @@ H5Z_xform_eval_full(H5Z_node *tree, const size_t array_size, const hid_t array_ * 1. See if "x" is on left hand side, right hand side, or if both sides are "x" * 2. Figure out what type of data we're going to be manipulating * 3. Do the operation on the data. */ - - switch (tree->type) { case H5Z_XFORM_PLUS: - H5Z_XFORM_TYPE_OP(resl, resr, array_type, +, array_size) - break; + H5Z_XFORM_TYPE_OP(resl, resr, array_type, +, array_size) + break; case H5Z_XFORM_MINUS: - H5Z_XFORM_TYPE_OP(resl, resr, array_type, -, array_size) - break; + H5Z_XFORM_TYPE_OP(resl, resr, array_type, -, array_size) + break; case H5Z_XFORM_MULT: - H5Z_XFORM_TYPE_OP(resl, resr, array_type, *, array_size) - break; + H5Z_XFORM_TYPE_OP(resl, resr, array_type, *, array_size) + break; case H5Z_XFORM_DIVIDE: - H5Z_XFORM_TYPE_OP(resl, resr, array_type, /, array_size) - break; + H5Z_XFORM_TYPE_OP(resl, resr, array_type, /, array_size) + break; - case H5Z_XFORM_ERROR: - case H5Z_XFORM_INTEGER: - case H5Z_XFORM_FLOAT: - case H5Z_XFORM_SYMBOL: - case H5Z_XFORM_LPAREN: - case H5Z_XFORM_RPAREN: - case H5Z_XFORM_END: + case H5Z_XFORM_ERROR: + case H5Z_XFORM_INTEGER: + case H5Z_XFORM_FLOAT: + case H5Z_XFORM_SYMBOL: + case H5Z_XFORM_LPAREN: + case H5Z_XFORM_RPAREN: + case H5Z_XFORM_END: default: - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Invalid expression tree") + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Invalid expression tree") } /* end switch */ /* The result stores a pointer to the new data */ diff --git a/src/H5detect.c b/src/H5detect.c index ee02c52..94e841e 100644 --- a/src/H5detect.c +++ b/src/H5detect.c @@ -1177,7 +1177,7 @@ imp_bit(unsigned int n, int *perm, void *_a, void *_b, const unsigned char *pad_ * *------------------------------------------------------------------------- */ -static unsigned int +H5_ATTR_PURE static unsigned int find_bias(unsigned int epos, unsigned int esize, int *perm, void *_a) { unsigned char *a = (unsigned char *) _a; diff --git a/src/H5private.h b/src/H5private.h index d400469..6a677bb 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -657,6 +657,9 @@ typedef struct { #ifndef HDatol #define HDatol(S) atol(S) #endif /* HDatol */ +#ifndef HDatoll + #define HDatoll(S) atoll(S) +#endif /* HDatol */ #ifndef HDbsearch #define HDbsearch(K,B,N,Z,F) bsearch(K,B,N,Z,F) #endif /* HDbsearch */ @@ -1029,6 +1032,15 @@ typedef off_t h5_stat_size_t; #ifndef HDlink #define HDlink(OLD,NEW) link(OLD,NEW) #endif /* HDlink */ +#ifndef HDllround + #define HDllround(V) llround(V) +#endif /* HDround */ +#ifndef HDllroundf + #define HDllroundf(V) llroundf(V) +#endif /* HDllroundf */ +#ifndef HDllroundl + #define HDllroundl(V) llroundl(V) +#endif /* HDllroundl */ #ifndef HDlocaleconv #define HDlocaleconv() localeconv() #endif /* HDlocaleconv */ @@ -1044,6 +1056,15 @@ typedef off_t h5_stat_size_t; #ifndef HDlongjmp #define HDlongjmp(J,N) longjmp(J,N) #endif /* HDlongjmp */ +#ifndef HDlround + #define HDlround(V) lround(V) +#endif /* HDround */ +#ifndef HDlroundf + #define HDlroundf(V) lroundf(V) +#endif /* HDlroundf */ +#ifndef HDlroundl + #define HDlroundl(V) lroundl(V) +#endif /* HDroundl */ #ifndef HDlseek #define HDlseek(F,O,W) lseek(F,O,W) #endif /* HDlseek */ @@ -1118,6 +1139,9 @@ typedef off_t h5_stat_size_t; #ifndef HDpow #define HDpow(X,Y) pow(X,Y) #endif /* HDpow */ +#ifndef HDpowf + #define HDpowf(X,Y) powf(X,Y) +#endif /* HDpowf */ /* printf() variable arguments */ #ifndef HDputc #define HDputc(C,F) putc(C,F) @@ -1180,6 +1204,15 @@ typedef off_t h5_stat_size_t; #ifndef HDrewinddir #define HDrewinddir(D) rewinddir(D) #endif /* HDrewinddir */ +#ifndef HDround + #define HDround(V) round(V) +#endif /* HDround */ +#ifndef HDroundf + #define HDroundf(V) roundf(V) +#endif /* HDroundf */ +#ifndef HDroundl + #define HDroundl(V) roundl(V) +#endif /* HDroundl */ #ifndef HDrmdir #define HDrmdir(S) rmdir(S) #endif /* HDrmdir */ diff --git a/src/H5public.h b/src/H5public.h index 554ad26..2f21648 100644 --- a/src/H5public.h +++ b/src/H5public.h @@ -194,28 +194,21 @@ H5_GCC_DIAG_ON(long-long) /* * File addresses have their own types. */ -#if H5_SIZEOF_INT64_T>=8 - typedef uint64_t haddr_t; -# define HADDR_UNDEF ((haddr_t)(int64_t)(-1)) -# define H5_SIZEOF_HADDR_T H5_SIZEOF_INT64_T -# ifdef H5_HAVE_PARALLEL -# define HADDR_AS_MPI_TYPE MPI_LONG_LONG_INT -# endif /* H5_HAVE_PARALLEL */ -#elif H5_SIZEOF_INT>=8 +#if H5_SIZEOF_INT >= 8 typedef unsigned haddr_t; # define HADDR_UNDEF ((haddr_t)(-1)) # define H5_SIZEOF_HADDR_T H5_SIZEOF_INT # ifdef H5_HAVE_PARALLEL # define HADDR_AS_MPI_TYPE MPI_UNSIGNED # endif /* H5_HAVE_PARALLEL */ -#elif H5_SIZEOF_LONG>=8 +#elif H5_SIZEOF_LONG >= 8 typedef unsigned long haddr_t; # define HADDR_UNDEF ((haddr_t)(long)(-1)) # define H5_SIZEOF_HADDR_T H5_SIZEOF_LONG # ifdef H5_HAVE_PARALLEL # define HADDR_AS_MPI_TYPE MPI_UNSIGNED_LONG # endif /* H5_HAVE_PARALLEL */ -#elif H5_SIZEOF_LONG_LONG>=8 +#elif H5_SIZEOF_LONG_LONG >= 8 typedef unsigned long long haddr_t; # define HADDR_UNDEF ((haddr_t)(long long)(-1)) # define H5_SIZEOF_HADDR_T H5_SIZEOF_LONG_LONG @@ -225,11 +218,11 @@ H5_GCC_DIAG_ON(long-long) #else # error "nothing appropriate for haddr_t" #endif -#if H5_SIZEOF_HADDR_T ==H5_SIZEOF_INT +#if H5_SIZEOF_HADDR_T == H5_SIZEOF_INT # define H5_PRINTF_HADDR_FMT "%u" -#elif H5_SIZEOF_HADDR_T ==H5_SIZEOF_LONG +#elif H5_SIZEOF_HADDR_T == H5_SIZEOF_LONG # define H5_PRINTF_HADDR_FMT "%lu" -#elif H5_SIZEOF_HADDR_T ==H5_SIZEOF_LONG_LONG +#elif H5_SIZEOF_HADDR_T == H5_SIZEOF_LONG_LONG # define H5_PRINTF_HADDR_FMT "%" H5_PRINTF_LL_WIDTH "u" #else # error "nothing appropriate for H5_PRINTF_HADDR_FMT" |