diff --git a/config/cmake/H5pubconf.h.in b/config/cmake/H5pubconf.h.in index 120c023cb9f..325e7d3f669 100644 --- a/config/cmake/H5pubconf.h.in +++ b/config/cmake/H5pubconf.h.in @@ -134,6 +134,9 @@ /* Define if library information should be embedded in the executables */ #cmakedefine H5_HAVE_EMBEDDED_LIBINFO @H5_HAVE_EMBEDDED_LIBINFO@ +/* Define to 1 if you have the header file. */ +#cmakedefine H5_HAVE_ENDIAN_H @H5_HAVE_ENDIAN_H@ + /* Define to 1 if you have the `fcntl' function. */ #cmakedefine H5_HAVE_FCNTL @H5_HAVE_FCNTL@ diff --git a/config/cmake_ext_mod/ConfigureChecks.cmake b/config/cmake_ext_mod/ConfigureChecks.cmake index abc88eddf60..c2e073e6b6d 100644 --- a/config/cmake_ext_mod/ConfigureChecks.cmake +++ b/config/cmake_ext_mod/ConfigureChecks.cmake @@ -134,6 +134,7 @@ CHECK_INCLUDE_FILE_CONCAT ("sys/time.h" ${HDF_PREFIX}_HAVE_SYS_TIME_H) CHECK_INCLUDE_FILE_CONCAT ("sys/types.h" ${HDF_PREFIX}_HAVE_SYS_TYPES_H) CHECK_INCLUDE_FILE_CONCAT ("features.h" ${HDF_PREFIX}_HAVE_FEATURES_H) CHECK_INCLUDE_FILE_CONCAT ("dirent.h" ${HDF_PREFIX}_HAVE_DIRENT_H) +CHECK_INCLUDE_FILE_CONCAT ("endian.h" ${HDF_PREFIX}_HAVE_ENDIAN_H) CHECK_INCLUDE_FILE_CONCAT ("setjmp.h" ${HDF_PREFIX}_HAVE_SETJMP_H) CHECK_INCLUDE_FILE_CONCAT ("stddef.h" ${HDF_PREFIX}_HAVE_STDDEF_H) CHECK_INCLUDE_FILE_CONCAT ("stdint.h" ${HDF_PREFIX}_HAVE_STDINT_H) diff --git a/configure.ac b/configure.ac index b4308f6a967..9c8d794c1b2 100644 --- a/configure.ac +++ b/configure.ac @@ -1082,6 +1082,7 @@ AC_CHECK_HEADERS([sys/socket.h sys/types.h sys/file.h]) AC_CHECK_HEADERS([stddef.h setjmp.h features.h]) AC_CHECK_HEADERS([dirent.h]) AC_CHECK_HEADERS([stdint.h], [C9x=yes]) +AC_CHECK_HEADERS([endian.h]) AC_CHECK_HEADERS([stdbool.h]) ## Darwin diff --git a/src/H5Abtree2.c b/src/H5Abtree2.c index 3377aa263df..a6e2d1bef44 100644 --- a/src/H5Abtree2.c +++ b/src/H5Abtree2.c @@ -322,8 +322,8 @@ H5A__dense_btree2_name_encode(uint8_t *raw, const void *_nrecord, void H5_ATTR_U H5MM_memcpy(raw, nrecord->id.id, (size_t)H5O_FHEAP_ID_LEN); raw += H5O_FHEAP_ID_LEN; *raw++ = nrecord->flags; - UINT32ENCODE(raw, nrecord->corder) - UINT32ENCODE(raw, nrecord->hash) + UINT32ENCODE(raw, nrecord->corder); + UINT32ENCODE(raw, nrecord->hash); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5A__dense_btree2_name_encode() */ @@ -353,8 +353,8 @@ H5A__dense_btree2_name_decode(const uint8_t *raw, void *_nrecord, void H5_ATTR_U H5MM_memcpy(nrecord->id.id, raw, (size_t)H5O_FHEAP_ID_LEN); raw += H5O_FHEAP_ID_LEN; nrecord->flags = *raw++; - UINT32DECODE(raw, nrecord->corder) - UINT32DECODE(raw, nrecord->hash) + UINT32DECODE(raw, nrecord->corder); + UINT32DECODE(raw, nrecord->hash); FUNC_LEAVE_NOAPI(SUCCEED) } /* H5A__dense_btree2_name_decode() */ diff --git a/src/H5Dvirtual.c b/src/H5Dvirtual.c index 53640e7fbd8..38a0d687f17 100644 --- a/src/H5Dvirtual.c +++ b/src/H5Dvirtual.c @@ -522,7 +522,7 @@ H5D__virtual_store_layout(H5F_t *f, H5O_layout_t *layout) /* Checksum */ chksum = H5_checksum_metadata(heap_block, block_size - (size_t)4, 0); - UINT32ENCODE(heap_block_p, chksum) + UINT32ENCODE(heap_block_p, chksum); /* Insert block into global heap */ if(H5HG_insert(f, block_size, heap_block, &(layout->storage.u.virt.serial_list_hobjid)) < 0) /* Casting away const OK --NAF */ diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 8c7066339b1..b2bcba1b3e1 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -39,35 +39,6 @@ typedef struct H5F_t H5F_t; /* Library Private Macros */ /**************************/ -/* - * Encode and decode macros for file meta-data. - * Currently, all file meta-data is little-endian. - */ - -# define INT16ENCODE(p, i) { \ - *(p) = (uint8_t)( (unsigned)(i) & 0xff); (p)++; \ - *(p) = (uint8_t)(((unsigned)(i) >> 8) & 0xff); (p)++; \ -} - -# define UINT16ENCODE(p, i) { \ - *(p) = (uint8_t)( (unsigned)(i) & 0xff); (p)++; \ - *(p) = (uint8_t)(((unsigned)(i) >> 8) & 0xff); (p)++; \ -} - -# define INT32ENCODE(p, i) { \ - *(p) = (uint8_t)( (uint32_t)(i) & 0xff); (p)++; \ - *(p) = (uint8_t)(((uint32_t)(i) >> 8) & 0xff); (p)++; \ - *(p) = (uint8_t)(((uint32_t)(i) >> 16) & 0xff); (p)++; \ - *(p) = (uint8_t)(((uint32_t)(i) >> 24) & 0xff); (p)++; \ -} - -# define UINT32ENCODE(p, i) { \ - *(p) = (uint8_t)( (i) & 0xff); (p)++; \ - *(p) = (uint8_t)(((i) >> 8) & 0xff); (p)++; \ - *(p) = (uint8_t)(((i) >> 16) & 0xff); (p)++; \ - *(p) = (uint8_t)(((i) >> 24) & 0xff); (p)++; \ -} - /* Encode an unsigned integer into a variable-sized buffer */ /* (Assumes that the high bits of the integer are zero) */ # define ENCODE_VAR(p, typ, n, l) { \ @@ -84,30 +55,6 @@ typedef struct H5F_t H5F_t; /* (Assumes that the high bits of the integer are zero) */ # define UINT32ENCODE_VAR(p, n, l) ENCODE_VAR(p, uint32_t, n, l) -# define INT64ENCODE(p, n) { \ - int64_t _n = (n); \ - size_t _i; \ - uint8_t *_p = (uint8_t*)(p); \ - \ - for (_i = 0; _i < sizeof(int64_t); _i++, _n >>= 8) \ - *_p++ = (uint8_t)(_n & 0xff); \ - for (/*void*/; _i < 8; _i++) \ - *_p++ = (n) < 0 ? 0xff : 0; \ - (p) = (uint8_t*)(p)+8; \ -} - -# define UINT64ENCODE(p, n) { \ - uint64_t _n = (n); \ - size_t _i; \ - uint8_t *_p = (uint8_t*)(p); \ - \ - for (_i = 0; _i < sizeof(uint64_t); _i++, _n >>= 8) \ - *_p++ = (uint8_t)(_n & 0xff); \ - for (/*void*/; _i < 8; _i++) \ - *_p++ = 0; \ - (p) = (uint8_t*)(p) + 8; \ -} - /* Encode a 64-bit unsigned integer into a variable-sized buffer */ /* (Assumes that the high bits of the integer are zero) */ # define UINT64ENCODE_VAR(p, n, l) ENCODE_VAR(p, uint64_t, n, l) @@ -124,7 +71,7 @@ typedef struct H5F_t H5F_t; # define H5_ENCODE_UNSIGNED(p, n) { \ HDcompile_assert(sizeof(unsigned) == sizeof(uint32_t)); \ - UINT32ENCODE(p, n) \ + UINT32ENCODE(p, n); \ } /* Assumes the endianness of uint64_t is the same as double */ @@ -141,40 +88,6 @@ typedef struct H5F_t H5F_t; (p) = (uint8_t *)(p) + 8; \ } -/* DECODE converts little endian bytes pointed by p to integer values and store - * it in i. For signed values, need to do sign-extension when converting - * the last byte which carries the sign bit. - * The macros does not require i be of a certain byte sizes. It just requires - * i be big enough to hold the intended value range. E.g. INT16DECODE works - * correctly even if i is actually a 64bit int like in a Cray. - */ - -# define INT16DECODE(p, i) { \ - (i) = (int16_t)((*(p) & 0xff)); (p)++; \ - (i) |= (int16_t)(((*(p) & 0xff) << 8) | \ - ((*(p) & 0x80) ? ~0xffff : 0x0)); (p)++; \ -} - -# define UINT16DECODE(p, i) { \ - (i) = (uint16_t) (*(p) & 0xff); (p)++; \ - (i) |= (uint16_t)((*(p) & 0xff) << 8); (p)++; \ -} - -# define INT32DECODE(p, i) { \ - (i) = ((int32_t)(*(p) & 0xff)); (p)++; \ - (i) |= ((int32_t)(*(p) & 0xff) << 8); (p)++; \ - (i) |= ((int32_t)(*(p) & 0xff) << 16); (p)++; \ - (i) |= ((int32_t)(((*(p) & (unsigned)0xff) << 24) | \ - ((*(p) & 0x80) ? ~0xffffffffULL : 0x0ULL))); (p)++; \ -} - -# define UINT32DECODE(p, i) { \ - (i) = (uint32_t)(*(p) & 0xff); (p)++; \ - (i) |= ((uint32_t)(*(p) & 0xff) << 8); (p)++; \ - (i) |= ((uint32_t)(*(p) & 0xff) << 16); (p)++; \ - (i) |= ((uint32_t)(*(p) & 0xff) << 24); (p)++; \ -} - /* Decode a variable-sized buffer */ /* (Assumes that the high bits of the integer will be zero) */ # define DECODE_VAR(p, n, l) { \ @@ -191,28 +104,6 @@ typedef struct H5F_t H5F_t; /* (Assumes that the high bits of the integer will be zero) */ # define UINT32DECODE_VAR(p, n, l) DECODE_VAR(p, n, l) -# define INT64DECODE(p, n) { \ - /* WE DON'T CHECK FOR OVERFLOW! */ \ - size_t _i; \ - \ - n = 0; \ - (p) += 8; \ - for (_i = 0; _i < sizeof(int64_t); _i++) \ - n = (n << 8) | *(--p); \ - (p) += 8; \ -} - -# define UINT64DECODE(p, n) { \ - /* WE DON'T CHECK FOR OVERFLOW! */ \ - size_t _i; \ - \ - n = 0; \ - (p) += 8; \ - for (_i = 0; _i < sizeof(uint64_t); _i++) \ - n = (n << 8) | *(--p); \ - (p) += 8; \ -} - /* Decode a variable-sized buffer into a 64-bit unsigned integer */ /* (Assumes that the high bits of the integer will be zero) */ # define UINT64DECODE_VAR(p, n, l) DECODE_VAR(p, n, l) @@ -227,7 +118,7 @@ typedef struct H5F_t H5F_t; # define H5_DECODE_UNSIGNED(p, n) { \ HDcompile_assert(sizeof(unsigned) == sizeof(uint32_t)); \ - UINT32DECODE(p, n) \ + UINT32DECODE(p, n); \ } /* Assumes the endianness of uint64_t is the same as double */ diff --git a/src/H5Gbtree2.c b/src/H5Gbtree2.c index 71e0b2db2da..b463f4ed080 100644 --- a/src/H5Gbtree2.c +++ b/src/H5Gbtree2.c @@ -305,7 +305,7 @@ H5G_dense_btree2_name_encode(uint8_t *raw, const void *_nrecord, void H5_ATTR_UN FUNC_ENTER_NOAPI_NOINIT_NOERR /* Encode the record's fields */ - UINT32ENCODE(raw, nrecord->hash) + UINT32ENCODE(raw, nrecord->hash); H5MM_memcpy(raw, nrecord->id, (size_t)H5G_DENSE_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) @@ -333,7 +333,7 @@ H5G_dense_btree2_name_decode(const uint8_t *raw, void *_nrecord, void H5_ATTR_UN FUNC_ENTER_NOAPI_NOINIT_NOERR /* Decode the record's fields */ - UINT32DECODE(raw, nrecord->hash) + UINT32DECODE(raw, nrecord->hash); H5MM_memcpy(nrecord->id, raw, (size_t)H5G_DENSE_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) @@ -469,7 +469,7 @@ H5G_dense_btree2_corder_encode(uint8_t *raw, const void *_nrecord, void H5_ATTR_ FUNC_ENTER_NOAPI_NOINIT_NOERR /* Encode the record's fields */ - INT64ENCODE(raw, nrecord->corder) + INT64ENCODE(raw, nrecord->corder); H5MM_memcpy(raw, nrecord->id, (size_t)H5G_DENSE_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) @@ -497,7 +497,7 @@ H5G_dense_btree2_corder_decode(const uint8_t *raw, void *_nrecord, void H5_ATTR_ FUNC_ENTER_NOAPI_NOINIT_NOERR /* Decode the record's fields */ - INT64DECODE(raw, nrecord->corder) + INT64DECODE(raw, nrecord->corder); H5MM_memcpy(nrecord->id, raw, (size_t)H5G_DENSE_FHEAP_ID_LEN); FUNC_LEAVE_NOAPI(SUCCEED) diff --git a/src/H5HFcache.c b/src/H5HFcache.c index 2d1c1f2b6c1..5d09b0a2262 100644 --- a/src/H5HFcache.c +++ b/src/H5HFcache.c @@ -1707,7 +1707,7 @@ H5HF__cache_dblock_verify_chksum(const void *_image, size_t len, void *_udata) computed_chksum = H5_checksum_metadata(read_buf, len, 0); /* Restore the checksum */ - UINT32ENCODE(chk_p, stored_chksum) + UINT32ENCODE(chk_p, stored_chksum); /* Verify checksum */ if(stored_chksum != computed_chksum) diff --git a/src/H5Oainfo.c b/src/H5Oainfo.c index 7f4f17f2a18..63cd47a43c4 100644 --- a/src/H5Oainfo.c +++ b/src/H5Oainfo.c @@ -137,7 +137,7 @@ H5O__ainfo_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, /* Max. creation order value for the object */ if(ainfo->track_corder) - UINT16DECODE(p, ainfo->max_crt_idx) + UINT16DECODE(p, ainfo->max_crt_idx); else ainfo->max_crt_idx = H5O_MAX_CRT_ORDER_IDX; diff --git a/src/H5Ocache.c b/src/H5Ocache.c index 683d1555a15..3e184317878 100644 --- a/src/H5Ocache.c +++ b/src/H5Ocache.c @@ -517,7 +517,7 @@ H5O__cache_serialize(const H5F_t *f, void *image, size_t len, void *_thing) /* Number of messages */ #ifdef H5O_ENABLE_BAD_MESG_COUNT if(oh->store_bad_mesg_count) - UINT16ENCODE(chunk_image, (oh->nmesgs - 1)) + UINT16ENCODE(chunk_image, (oh->nmesgs - 1)); else #endif /* H5O_ENABLE_BAD_MESG_COUNT */ UINT16ENCODE(chunk_image, oh->nmesgs); @@ -1385,7 +1385,7 @@ H5O__chunk_deserialize(H5O_t *oh, haddr_t addr, size_t len, const uint8_t *image /* Version # */ if(oh->version == H5O_VERSION_1) - UINT16DECODE(chunk_image, id) + UINT16DECODE(chunk_image, id); else id = *chunk_image++; diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 8f301af9abc..5bd822b2001 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -300,7 +300,7 @@ H5O_dtype_decode_helper(H5F_t *f, unsigned *ioflags/*in,out*/, const uint8_t **p if(version >= H5O_DTYPE_VERSION_3) UINT32DECODE_VAR(*pp, dt->shared->u.compnd.memb[i].offset, offset_nbytes) else - UINT32DECODE(*pp, dt->shared->u.compnd.memb[i].offset) + UINT32DECODE(*pp, dt->shared->u.compnd.memb[i].offset); /* Older versions of the library allowed a field to have * intrinsic 'arrayness'. Newer versions of the library @@ -927,7 +927,7 @@ H5O_dtype_encode_helper(const H5F_t *f, uint8_t **pp, const H5T_t *dt) if(dt->shared->version >= H5O_DTYPE_VERSION_3) UINT32ENCODE_VAR(*pp, (uint32_t)dt->shared->u.compnd.memb[i].offset, offset_nbytes) else - UINT32ENCODE(*pp, dt->shared->u.compnd.memb[i].offset) + UINT32ENCODE(*pp, dt->shared->u.compnd.memb[i].offset); /* If we don't have any array fields, write out the old style * member information, for better backward compatibility diff --git a/src/H5Oginfo.c b/src/H5Oginfo.c index 4b34a52b89a..6d1ae4d8572 100644 --- a/src/H5Oginfo.c +++ b/src/H5Oginfo.c @@ -124,8 +124,8 @@ H5O_ginfo_decode(H5F_t H5_ATTR_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh, /* Get the max. # of links to store compactly & the min. # of links to store densely */ if(ginfo->store_link_phase_change) { - UINT16DECODE(p, ginfo->max_compact) - UINT16DECODE(p, ginfo->min_dense) + UINT16DECODE(p, ginfo->max_compact); + UINT16DECODE(p, ginfo->min_dense); } /* end if */ else { ginfo->max_compact = H5G_CRT_GINFO_MAX_COMPACT; @@ -134,8 +134,8 @@ H5O_ginfo_decode(H5F_t H5_ATTR_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh, /* Get the estimated # of entries & name lengths */ if(ginfo->store_est_entry_info) { - UINT16DECODE(p, ginfo->est_num_entries) - UINT16DECODE(p, ginfo->est_name_len) + UINT16DECODE(p, ginfo->est_num_entries); + UINT16DECODE(p, ginfo->est_name_len); } /* end if */ else { ginfo->est_num_entries = H5G_CRT_GINFO_EST_NUM_ENTRIES; @@ -189,14 +189,14 @@ H5O_ginfo_encode(H5F_t H5_ATTR_UNUSED *f, hbool_t H5_ATTR_UNUSED disable_shared, /* Store the max. # of links to store compactly & the min. # of links to store densely */ if(ginfo->store_link_phase_change) { - UINT16ENCODE(p, ginfo->max_compact) - UINT16ENCODE(p, ginfo->min_dense) + UINT16ENCODE(p, ginfo->max_compact); + UINT16ENCODE(p, ginfo->min_dense); } /* end if */ /* Estimated # of entries & name lengths */ if(ginfo->store_est_entry_info) { - UINT16ENCODE(p, ginfo->est_num_entries) - UINT16ENCODE(p, ginfo->est_name_len) + UINT16ENCODE(p, ginfo->est_num_entries); + UINT16ENCODE(p, ginfo->est_name_len); } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED) diff --git a/src/H5Olayout.c b/src/H5Olayout.c index 138f21994d9..74d55a71bf9 100644 --- a/src/H5Olayout.c +++ b/src/H5Olayout.c @@ -491,7 +491,7 @@ H5O__layout_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, } /* end for */ /* Read stored checksum */ - UINT32DECODE(heap_block_p, stored_chksum) + UINT32DECODE(heap_block_p, stored_chksum); /* Compute checksum */ computed_chksum = H5_checksum_metadata(heap_block, block_size - (size_t)4, 0); diff --git a/src/H5Olinfo.c b/src/H5Olinfo.c index 9827b6a9fd3..baa5ef2f24f 100644 --- a/src/H5Olinfo.c +++ b/src/H5Olinfo.c @@ -145,7 +145,7 @@ H5O__linfo_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, /* Max. link creation order value for the group, if tracked */ if(linfo->track_corder) - INT64DECODE(p, linfo->max_corder) + INT64DECODE(p, linfo->max_corder); else linfo->max_corder = 0; @@ -209,7 +209,7 @@ H5O_linfo_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, co /* Max. link creation order value for the group, if tracked */ if(linfo->track_corder) - INT64ENCODE(p, linfo->max_corder) + INT64ENCODE(p, linfo->max_corder); /* Address of fractal heap to store "dense" links */ H5F_addr_encode(f, &p, linfo->fheap_addr); diff --git a/src/H5Olink.c b/src/H5Olink.c index 4bd952bd859..2c9f858f57a 100644 --- a/src/H5Olink.c +++ b/src/H5Olink.c @@ -157,7 +157,7 @@ H5O__link_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, /* Get the link creation time from the file */ if(link_flags & H5O_LINK_STORE_CORDER) { - INT64DECODE(p, lnk->corder) + INT64DECODE(p, lnk->corder); lnk->corder_valid = TRUE; } /* end if */ else { @@ -215,7 +215,7 @@ H5O__link_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, case H5L_TYPE_SOFT: /* Get the link value */ - UINT16DECODE(p, len) + UINT16DECODE(p, len); if(len == 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "invalid link length") if(NULL == (lnk->u.soft.name = (char *)H5MM_malloc((size_t)len + 1))) @@ -234,7 +234,7 @@ H5O__link_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "unknown link type") /* A UD link. Get the user-supplied data */ - UINT16DECODE(p, len) + UINT16DECODE(p, len); lnk->u.ud.size = len; if(len > 0) { @@ -320,7 +320,7 @@ H5O_link_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, con /* Store the link creation order in the file, if its valid */ if(lnk->corder_valid) - INT64ENCODE(p, lnk->corder) + INT64ENCODE(p, lnk->corder); /* Store a non-default link name character set */ if(link_flags & H5O_LINK_STORE_NAME_CSET) @@ -363,7 +363,7 @@ H5O_link_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, con /* Store the link value */ len = (uint16_t)HDstrlen(lnk->u.soft.name); HDassert(len > 0); - UINT16ENCODE(p, len) + UINT16ENCODE(p, len); H5MM_memcpy(p, lnk->u.soft.name, (size_t)len); p += len; break; @@ -377,7 +377,7 @@ H5O_link_encode(H5F_t *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p, con /* Store the user-supplied data, however long it is */ len = (uint16_t)lnk->u.ud.size; - UINT16ENCODE(p, len) + UINT16ENCODE(p, len); if(len > 0) { H5MM_memcpy(p, lnk->u.ud.udata, (size_t)len); diff --git a/src/H5Omessage.c b/src/H5Omessage.c index 18f3706d311..cfbd44ec3dd 100644 --- a/src/H5Omessage.c +++ b/src/H5Omessage.c @@ -2139,7 +2139,7 @@ H5O_msg_flush(H5F_t *f, H5O_t *oh, H5O_mesg_t *mesg) /* Encode the message prefix */ if(oh->version == H5O_VERSION_1) - UINT16ENCODE(p, msg_id) + UINT16ENCODE(p, msg_id); else *p++ = (uint8_t)msg_id; HDassert(mesg->raw_size < H5O_MESG_MAX_SIZE); diff --git a/src/H5Opline.c b/src/H5Opline.c index eae7cd614b3..7193ed8bdd5 100644 --- a/src/H5Opline.c +++ b/src/H5Opline.c @@ -220,7 +220,7 @@ H5O__pline_decode(H5F_t H5_ATTR_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh, */ for (j = 0; j < filter->cd_nelmts; j++) { if (p + 4 - 1 <= p_end) - UINT32DECODE(p, filter->cd_values[j]) + UINT32DECODE(p, filter->cd_values[j]); else HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "ran off the end of the buffer: current p = %p, p_size = %zu, p_end = %p", p, p_size, p_end) } diff --git a/src/H5Orefcount.c b/src/H5Orefcount.c index 66b79bbfaf9..eef763cff2a 100644 --- a/src/H5Orefcount.c +++ b/src/H5Orefcount.c @@ -111,7 +111,7 @@ H5O__refcount_decode(H5F_t H5_ATTR_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh, HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* Get ref. count for object */ - UINT32DECODE(p, *refcount) + UINT32DECODE(p, *refcount); /* Set return value */ ret_value = refcount; diff --git a/src/H5Pdcpl.c b/src/H5Pdcpl.c index 721ba893c8d..8046017f12c 100644 --- a/src/H5Pdcpl.c +++ b/src/H5Pdcpl.c @@ -406,7 +406,7 @@ H5P__dcrt_layout_enc(const void *value, void **_pp, size_t *size) /* Encode chunk dims */ HDcompile_assert(sizeof(uint32_t) == sizeof(layout->u.chunk.dim[0])); for(u = 0; u < (size_t)layout->u.chunk.ndims; u++) { - UINT32ENCODE(*pp, layout->u.chunk.dim[u]) + UINT32ENCODE(*pp, layout->u.chunk.dim[u]); *size += sizeof(uint32_t); } /* end for */ } /* end if */ @@ -414,7 +414,7 @@ H5P__dcrt_layout_enc(const void *value, void **_pp, size_t *size) uint64_t nentries = (uint64_t)layout->storage.u.virt.list_nused; /* Encode number of entries */ - UINT64ENCODE(*pp, nentries) + UINT64ENCODE(*pp, nentries); *size += (size_t)8; /* Iterate over entries */ @@ -560,7 +560,7 @@ H5P__dcrt_layout_dec(const void **_pp, void *value) /* Set rank & dimensions */ tmp_layout.u.chunk.ndims = (unsigned)ndims; for(u = 0; u < ndims; u++) - UINT32DECODE(*pp, tmp_layout.u.chunk.dim[u]) + UINT32DECODE(*pp, tmp_layout.u.chunk.dim[u]); /* Point at the newly set up struct */ layout = &tmp_layout; @@ -573,7 +573,7 @@ H5P__dcrt_layout_dec(const void **_pp, void *value) uint64_t nentries; /* Number of VDS mappings */ /* Decode number of entries */ - UINT64DECODE(*pp, nentries) + UINT64DECODE(*pp, nentries); if(nentries == (uint64_t)0) /* Just use the default struct */ @@ -1013,7 +1013,7 @@ H5P__dcrt_fill_value_enc(const void *value, void **_pp, size_t *size) *(*pp)++ = (uint8_t)fill->fill_time; /* Encode size of fill value */ - INT64ENCODE(*pp, fill->size) + INT64ENCODE(*pp, fill->size); /* Encode the fill value & datatype */ if(fill->size > 0) { @@ -1104,7 +1104,7 @@ H5P__dcrt_fill_value_dec(const void **_pp, void *_value) fill->fill_time = (H5D_fill_time_t)*(*pp)++; /* Decode fill size */ - INT64DECODE(*pp, fill->size) + INT64DECODE(*pp, fill->size); /* Check if there's a fill value */ if(fill->size > 0) { diff --git a/src/H5Pencdec.c b/src/H5Pencdec.c index 2a07a67e5c6..2ee56d5b3d5 100644 --- a/src/H5Pencdec.c +++ b/src/H5Pencdec.c @@ -188,7 +188,7 @@ H5P__encode_unsigned(const void *value, void **_pp, size_t *size) *(*pp)++ = (uint8_t)sizeof(unsigned); /* Encode the value */ - H5_ENCODE_UNSIGNED(*pp, *(const unsigned *)value) + H5_ENCODE_UNSIGNED(*pp, *(const unsigned *)value); } /* end if */ /* Set size needed for encoding */ @@ -298,7 +298,7 @@ H5P__encode_double(const void *value, void **_pp, size_t *size) *(*pp)++ = (uint8_t)sizeof(double); /* Encode the value */ - H5_ENCODE_DOUBLE(*pp, *(const double *)value) + H5_ENCODE_DOUBLE(*pp, *(const double *)value); } /* end if */ /* Set size needed for encoding */ @@ -559,7 +559,7 @@ H5P__decode_unsigned(const void **_pp, void *_value) if(enc_size != sizeof(unsigned)) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "unsigned value can't be decoded") - H5_DECODE_UNSIGNED(*pp, *value) + H5_DECODE_UNSIGNED(*pp, *value); done: FUNC_LEAVE_NOAPI(ret_value) @@ -667,7 +667,7 @@ H5P__decode_double(const void **_pp, void *_value) if(enc_size != sizeof(double)) HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "double value can't be decoded") - H5_DECODE_DOUBLE(*pp, *value) + H5_DECODE_DOUBLE(*pp, *value); done: FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5Pgcpl.c b/src/H5Pgcpl.c index e2fdcea5a07..3f7dc3af12a 100644 --- a/src/H5Pgcpl.c +++ b/src/H5Pgcpl.c @@ -554,11 +554,11 @@ H5P__gcrt_group_info_enc(const void *value, void **_pp, size_t *size) FUNC_ENTER_STATIC_NOERR if(NULL != *pp) { - UINT32ENCODE(*pp, ginfo->lheap_size_hint) - UINT16ENCODE(*pp, ginfo->max_compact) - UINT16ENCODE(*pp, ginfo->min_dense) - UINT16ENCODE(*pp, ginfo->est_num_entries) - UINT16ENCODE(*pp, ginfo->est_name_len) + UINT32ENCODE(*pp, ginfo->lheap_size_hint); + UINT16ENCODE(*pp, ginfo->max_compact); + UINT16ENCODE(*pp, ginfo->min_dense); + UINT16ENCODE(*pp, ginfo->est_num_entries); + UINT16ENCODE(*pp, ginfo->est_name_len); } /* end if */ *size += sizeof(uint16_t) * 4 + sizeof(uint32_t); @@ -595,11 +595,11 @@ H5P__gcrt_group_info_dec(const void **_pp, void *_value) HDmemset(ginfo, 0, sizeof(H5O_ginfo_t)); *ginfo = H5G_def_ginfo_g; - UINT32DECODE(*pp, ginfo->lheap_size_hint) - UINT16DECODE(*pp, ginfo->max_compact) - UINT16DECODE(*pp, ginfo->min_dense) - UINT16DECODE(*pp, ginfo->est_num_entries) - UINT16DECODE(*pp, ginfo->est_name_len) + UINT32DECODE(*pp, ginfo->lheap_size_hint); + UINT16DECODE(*pp, ginfo->max_compact); + UINT16DECODE(*pp, ginfo->min_dense); + UINT16DECODE(*pp, ginfo->est_num_entries); + UINT16DECODE(*pp, ginfo->est_name_len); /* Update fields */ if(ginfo->max_compact != H5G_CRT_GINFO_MAX_COMPACT || @@ -651,7 +651,7 @@ H5P__gcrt_link_info_enc(const void *value, void **_pp, size_t *size) *(*pp)++ = (uint8_t)sizeof(unsigned); /* Encode the value */ - H5_ENCODE_UNSIGNED(*pp, crt_order_flags) + H5_ENCODE_UNSIGNED(*pp, crt_order_flags); } /* end if */ *size += (1 + sizeof(unsigned)); @@ -694,7 +694,7 @@ H5P__gcrt_link_info_dec(const void **_pp, void *_value) HDmemset(linfo, 0, sizeof(H5O_linfo_t)); *linfo = H5G_def_linfo_g; - H5_DECODE_UNSIGNED(*pp, crt_order_flags) + H5_DECODE_UNSIGNED(*pp, crt_order_flags); /* Update fields */ linfo->track_corder = (hbool_t)((crt_order_flags & H5P_CRT_ORDER_TRACKED) ? TRUE : FALSE); diff --git a/src/H5Pocpl.c b/src/H5Pocpl.c index a60c593645d..4c45f0b1e60 100644 --- a/src/H5Pocpl.c +++ b/src/H5Pocpl.c @@ -1490,10 +1490,10 @@ H5P__ocrt_pipeline_enc(const void *value, void **_pp, size_t *size) unsigned v; /* Local index variable */ /* encode filter ID */ - INT32ENCODE(*pp, pline->filter[u].id) + INT32ENCODE(*pp, pline->filter[u].id); /* encode filter flags */ - H5_ENCODE_UNSIGNED(*pp, pline->filter[u].flags) + H5_ENCODE_UNSIGNED(*pp, pline->filter[u].flags); /* encode filter name if it exists */ if(NULL != pline->filter[u].name) { @@ -1517,7 +1517,7 @@ H5P__ocrt_pipeline_enc(const void *value, void **_pp, size_t *size) /* encode all values */ for(v = 0; v < pline->filter[u].cd_nelmts; v++) - H5_ENCODE_UNSIGNED(*pp, pline->filter[u].cd_values[v]) + H5_ENCODE_UNSIGNED(*pp, pline->filter[u].cd_values[v]); } /* end for */ } /* end if */ @@ -1587,10 +1587,10 @@ H5P__ocrt_pipeline_dec(const void **_pp, void *_value) unsigned v; /* Local index variable */ /* decode filter id */ - INT32DECODE(*pp, filter.id) + INT32DECODE(*pp, filter.id); /* decode filter flags */ - H5_DECODE_UNSIGNED(*pp, filter.flags) + H5_DECODE_UNSIGNED(*pp, filter.flags); /* decode value indicating if the name is encoded */ has_name = *(*pp)++; @@ -1617,7 +1617,7 @@ H5P__ocrt_pipeline_dec(const void **_pp, void *_value) /* decode values */ for(v = 0; v < filter.cd_nelmts; v++) - H5_DECODE_UNSIGNED(*pp, filter.cd_values[v]) + H5_DECODE_UNSIGNED(*pp, filter.cd_values[v]); /* Add the filter to the I/O pipeline */ if(H5Z_append(pline, filter.id, filter.flags, filter.cd_nelmts, filter.cd_values) < 0) diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 153f4be7602..62960b2f4a7 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -4016,13 +4016,13 @@ H5S__hyper_serialize(const H5S_t *space, uint8_t **p) UINT16ENCODE(pp, diminfo[u].start); UINT16ENCODE(pp, diminfo[u].stride); if(diminfo[u].count == H5S_UNLIMITED) - UINT16ENCODE(pp, H5S_UINT16_MAX) + UINT16ENCODE(pp, H5S_UINT16_MAX); else - UINT16ENCODE(pp, diminfo[u].count) + UINT16ENCODE(pp, diminfo[u].count); if(diminfo[u].block == H5S_UNLIMITED) - UINT16ENCODE(pp, H5S_UINT16_MAX) + UINT16ENCODE(pp, H5S_UINT16_MAX); else - UINT16ENCODE(pp, diminfo[u].block) + UINT16ENCODE(pp, diminfo[u].block); } /* end for */ break; @@ -4032,13 +4032,13 @@ H5S__hyper_serialize(const H5S_t *space, uint8_t **p) UINT32ENCODE(pp, diminfo[u].start); UINT32ENCODE(pp, diminfo[u].stride); if(diminfo[u].count == H5S_UNLIMITED) - UINT32ENCODE(pp, H5S_UINT32_MAX) + UINT32ENCODE(pp, H5S_UINT32_MAX); else - UINT32ENCODE(pp, diminfo[u].count) + UINT32ENCODE(pp, diminfo[u].count); if(diminfo[u].block == H5S_UNLIMITED) - UINT32ENCODE(pp, H5S_UINT32_MAX) + UINT32ENCODE(pp, H5S_UINT32_MAX); else - UINT32ENCODE(pp, diminfo[u].block) + UINT32ENCODE(pp, diminfo[u].block); } /* end for */ break; @@ -4048,13 +4048,13 @@ H5S__hyper_serialize(const H5S_t *space, uint8_t **p) UINT64ENCODE(pp, diminfo[u].start); UINT64ENCODE(pp, diminfo[u].stride); if(diminfo[u].count == H5S_UNLIMITED) - UINT64ENCODE(pp, H5S_UINT64_MAX) + UINT64ENCODE(pp, H5S_UINT64_MAX); else - UINT64ENCODE(pp, diminfo[u].count) + UINT64ENCODE(pp, diminfo[u].count); if(diminfo[u].block == H5S_UNLIMITED) - UINT64ENCODE(pp, H5S_UINT64_MAX) + UINT64ENCODE(pp, H5S_UINT64_MAX); else - UINT64ENCODE(pp, diminfo[u].block) + UINT64ENCODE(pp, diminfo[u].block); } /* end for */ if(version == H5S_HYPER_VERSION_2) len += (4 * space->extent.rank * 8); diff --git a/src/H5private.h b/src/H5private.h index bb2a2eb35c6..c0522205b21 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -462,6 +462,144 @@ # error "nothing appropriate for int32_t" #endif +/* + * Encode and decode macros for file meta-data. + * Currently, all file meta-data is little-endian. + */ +#ifdef H5_HAVE_ENDIAN_H +# include +/* Encode macros for std integer types */ +# define INT16ENCODE(p, i) do { \ + *((uint16_t *)p) = htole16((uint16_t)i); (p) += H5_SIZEOF_INT16_T; \ +} while(0) +# define UINT16ENCODE(p, i) do { \ + *((uint16_t *)p) = htole16(i); (p) += H5_SIZEOF_UINT16_T; \ +} while(0) +# define INT32ENCODE(p, i) do { \ + *((uint32_t *)p) = htole32((uint32_t)i); (p) += H5_SIZEOF_INT32_T; \ +} while(0) +# define UINT32ENCODE(p, i) do { \ + *((uint32_t *)p) = htole32(i); (p) += H5_SIZEOF_UINT32_T; \ +} while(0) +# define INT64ENCODE(p, i) do { \ + *((uint64_t *)p) = htole64((uint64_t)i); (p) += H5_SIZEOF_INT64_T; \ +} while(0) +# define UINT64ENCODE(p, i) do { \ + *((uint64_t *)p) = htole64(i); (p) += H5_SIZEOF_UINT64_T; \ +} while(0) +/* Decode macros for std integer types */ +# define INT16DECODE(p, i) do { \ + i = (int16_t)le16toh(*(uint16_t *)p); (p) += H5_SIZEOF_INT16_T; \ +} while(0) +# define UINT16DECODE(p, i) do { \ + i = le16toh(*(uint16_t *)p); (p) += H5_SIZEOF_UINT16_T; \ +} while(0) +# define INT32DECODE(p, i) do { \ + i = (int32_t)le32toh(*(uint32_t *)p); (p) += H5_SIZEOF_INT32_T; \ +} while(0) +# define UINT32DECODE(p, i) do { \ + i = le32toh(*(uint32_t *)p); (p) += H5_SIZEOF_UINT32_T; \ +} while(0) +# define INT64DECODE(p, i) do { \ + i = (int64_t)le64toh(*(uint64_t *)p); (p) += H5_SIZEOF_INT64_T; \ +} while(0) +# define UINT64DECODE(p, i) do { \ + i = le64toh(*(uint64_t *)p); (p) += H5_SIZEOF_UINT64_T; \ +} while(0) +#else /* H5_HAVE_ENDIAN_H */ +# define INT16ENCODE(p, i) do { \ + *(p) = (uint8_t)( (unsigned)(i) & 0xff); (p)++; \ + *(p) = (uint8_t)(((unsigned)(i) >> 8) & 0xff); (p)++; \ +} while(0) +# define UINT16ENCODE(p, i) do { \ + *(p) = (uint8_t)( (unsigned)(i) & 0xff); (p)++; \ + *(p) = (uint8_t)(((unsigned)(i) >> 8) & 0xff); (p)++; \ +} while(0) +# define INT32ENCODE(p, i) do { \ + *(p) = (uint8_t)( (uint32_t)(i) & 0xff); (p)++; \ + *(p) = (uint8_t)(((uint32_t)(i) >> 8) & 0xff); (p)++; \ + *(p) = (uint8_t)(((uint32_t)(i) >> 16) & 0xff); (p)++; \ + *(p) = (uint8_t)(((uint32_t)(i) >> 24) & 0xff); (p)++; \ +} while(0) +# define UINT32ENCODE(p, i) do { \ + *(p) = (uint8_t)( (i) & 0xff); (p)++; \ + *(p) = (uint8_t)(((i) >> 8) & 0xff); (p)++; \ + *(p) = (uint8_t)(((i) >> 16) & 0xff); (p)++; \ + *(p) = (uint8_t)(((i) >> 24) & 0xff); (p)++; \ +} while(0) +# define INT64ENCODE(p, n) do { \ + int64_t _n = (n); \ + size_t _i; \ + uint8_t *_p = (uint8_t*)(p); \ + \ + for (_i = 0; _i < sizeof(int64_t); _i++, _n >>= 8) \ + *_p++ = (uint8_t)(_n & 0xff); \ + for (/*void*/; _i < 8; _i++) \ + *_p++ = (n) < 0 ? 0xff : 0; \ + (p) = (uint8_t*)(p)+8; \ +} while(0) +# define UINT64ENCODE(p, n) do { \ + uint64_t _n = (n); \ + size_t _i; \ + uint8_t *_p = (uint8_t*)(p); \ + \ + for (_i = 0; _i < sizeof(uint64_t); _i++, _n >>= 8) \ + *_p++ = (uint8_t)(_n & 0xff); \ + for (/*void*/; _i < 8; _i++) \ + *_p++ = 0; \ + (p) = (uint8_t*)(p) + 8; \ +} while(0) +/* DECODE converts little endian bytes pointed by p to integer values and store + * it in i. For signed values, need to do sign-extension when converting + * the last byte which carries the sign bit. + * The macros does not require i be of a certain byte sizes. It just requires + * i be big enough to hold the intended value range. E.g. INT16DECODE works + * correctly even if it is actually a 64bit int like in a Cray. + */ +# define INT16DECODE(p, i) do { \ + (i) = (int16_t)((*(p) & 0xff)); (p)++; \ + (i) |= (int16_t)(((*(p) & 0xff) << 8) | \ + ((*(p) & 0x80) ? ~0xffff : 0x0)); (p)++; \ +} while(0) +# define UINT16DECODE(p, i) do { \ + (i) = (uint16_t) (*(p) & 0xff); (p)++; \ + (i) |= (uint16_t)((*(p) & 0xff) << 8); (p)++; \ +} while(0) +# define INT32DECODE(p, i) do { \ + (i) = ((int32_t)(*(p) & 0xff)); (p)++; \ + (i) |= ((int32_t)(*(p) & 0xff) << 8); (p)++; \ + (i) |= ((int32_t)(*(p) & 0xff) << 16); (p)++; \ + (i) |= ((int32_t)(((*(p) & (unsigned)0xff) << 24) | \ + ((*(p) & 0x80) ? ~0xffffffffULL : 0x0ULL))); (p)++; \ +} while(0) +# define UINT32DECODE(p, i) do { \ + (i) = (uint32_t)(*(p) & 0xff); (p)++; \ + (i) |= ((uint32_t)(*(p) & 0xff) << 8); (p)++; \ + (i) |= ((uint32_t)(*(p) & 0xff) << 16); (p)++; \ + (i) |= ((uint32_t)(*(p) & 0xff) << 24); (p)++; \ +} while(0) +# define INT64DECODE(p, n) do { \ + /* WE DON'T CHECK FOR OVERFLOW! */ \ + size_t _i; \ + \ + n = 0; \ + (p) += 8; \ + for (_i = 0; _i < sizeof(int64_t); _i++) \ + n = (n << 8) | *(--p); \ + (p) += 8; \ +} while(0) +# define UINT64DECODE(p, n) do { \ + /* WE DON'T CHECK FOR OVERFLOW! */ \ + size_t _i; \ + \ + n = 0; \ + (p) += 8; \ + for (_i = 0; _i < sizeof(uint64_t); _i++) \ + n = (n << 8) | *(--p); \ + (p) += 8; \ +} while(0) +#endif /* H5_HAVE_ENDIAN_H */ + /* * Maximum and minimum values. These should be defined in for the * most part.