From 9211ec92646b86169a65147a79f9bb69f442b728 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 08:03:19 -0700 Subject: [PATCH 01/23] Hard-code H5Tinit.c code as H5Tinit_float.c * Moves H5Tinit.c code to H5Tinit_float.c in preparation for moving H5detect.c code in (values are hard-coded - will only build on Intel LE Linux!) * Change Autotools and CMake to not build H5detect or compile H5Tinit.c * Remove all mention of H5detect, H5Tinit.c, and generation from docs Have NOT removed H5detect.c at this time --- src/CMakeLists.txt | 111 ++--------------------- src/H5T.c | 19 ++-- src/H5Tinit_float.c | 216 ++++++++++++++++++++++++++++++++++++++++++++ src/H5Tmodule.h | 13 +-- src/H5Tpkg.h | 2 +- src/H5Tpublic.h | 3 +- src/Makefile.am | 25 +---- 7 files changed, 241 insertions(+), 148 deletions(-) create mode 100644 src/H5Tinit_float.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 70c8cc37cf6..3c53ad6da5d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -638,6 +638,7 @@ set (H5T_SOURCES ${HDF5_SRC_DIR}/H5Tfields.c ${HDF5_SRC_DIR}/H5Tfixed.c ${HDF5_SRC_DIR}/H5Tfloat.c + ${HDF5_SRC_DIR}/H5Tinit_float.c ${HDF5_SRC_DIR}/H5Tnative.c ${HDF5_SRC_DIR}/H5Toffset.c ${HDF5_SRC_DIR}/H5Toh.c @@ -1036,8 +1037,7 @@ if (HDF5_GENERATE_HEADERS) endif () #----------------------------------------------------------------------------- -# Setup the H5detect utility which generates H5Tinit with platform -# specific type checks inside +# Set up source generators #----------------------------------------------------------------------------- if (HDF5_USE_PREGEN) set (HDF5_GENERATED_SOURCE_DIR ${HDF5_USE_PREGEN_DIR}) @@ -1078,101 +1078,6 @@ if (LOCAL_BATCH_TEST) endif () endif () -#### make the H5detect program -set (lib_prog_deps) -add_executable (H5detect ${HDF5_SRC_DIR}/H5detect.c) -target_include_directories (H5detect PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") -target_compile_definitions(H5detect PUBLIC ${HDF_EXTRA_C_FLAGS} ${HDF_EXTRA_FLAGS}) -TARGET_C_PROPERTIES (H5detect STATIC) -target_link_libraries (H5detect - PRIVATE "$<$:MPI::MPI_C>" $<$,$>:ws2_32.lib> -) -target_compile_options(H5detect - PRIVATE "$<$:-O0>" -) -set (lib_prog_deps ${lib_prog_deps} H5detect) - -# check if a pregenerated H5Tinit.c file is present -if (NOT EXISTS "${HDF5_GENERATED_SOURCE_DIR}/H5Tinit.c") - # execute the H5detect program - if (HDF5_BATCH_H5DETECT) - configure_file ( - ${HDF5_SOURCE_DIR}/bin/batch/${HDF5_BATCH_H5DETECT_SCRIPT}.in.cmake - ${HDF5_BINARY_DIR}/${HDF5_BATCH_H5DETECT_SCRIPT} ESCAPE_QUOTES @ONLY - ) - add_custom_command ( - OUTPUT gen_SRCS.stamp1 - BYPRODUCTS H5Tinit.c - COMMAND ${HDF5_BATCH_CMD} - ARGS ${HDF5_BINARY_DIR}/${HDF5_BATCH_H5DETECT_SCRIPT} - COMMAND ${CMAKE_COMMAND} - ARGS -E echo "Executed batch command to create H5Tinit.c" - COMMAND ${CMAKE_COMMAND} - ARGS -E touch gen_SRCS.stamp1 - DEPENDS H5detect - WORKING_DIRECTORY ${HDF5_GENERATED_SOURCE_DIR} - ) - add_custom_target (gen_H5Tinit - COMMAND ${CMAKE_COMMAND} -P ${HDF5_SOURCE_DIR}/config/cmake/wait_H5Tinit.cmake - ) - else () - add_custom_command ( - OUTPUT gen_SRCS.stamp1 - BYPRODUCTS H5Tinit.c - COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $ - ARGS H5Tinit.c - COMMAND ${CMAKE_COMMAND} - ARGS -E touch gen_SRCS.stamp1 - DEPENDS H5detect - WORKING_DIRECTORY ${HDF5_GENERATED_SOURCE_DIR} - COMMENT "Create H5Tinit.c" - ) - if (BUILD_SHARED_LIBS) - add_custom_command ( - OUTPUT shared/shared_gen_SRCS.stamp1 - BYPRODUCTS shared/H5Tinit.c - COMMAND ${CMAKE_COMMAND} - ARGS -E copy_if_different H5Tinit.c shared/H5Tinit.c - COMMAND ${CMAKE_COMMAND} - ARGS -E touch shared/shared_gen_SRCS.stamp1 - DEPENDS H5detect gen_SRCS.stamp1 - WORKING_DIRECTORY ${HDF5_GENERATED_SOURCE_DIR} - COMMENT "Copy H5Tinit.c to shared folder" - ) - endif () - endif () -else () - add_custom_command ( - OUTPUT gen_SRCS.stamp1 - COMMAND ${CMAKE_COMMAND} - ARGS -E touch gen_SRCS.stamp1 - DEPENDS H5Tinit.c - WORKING_DIRECTORY ${HDF5_GENERATED_SOURCE_DIR} - COMMENT "Touch existing H5Tinit.c" - ) - set_source_files_properties (${HDF5_GENERATED_SOURCE_DIR}/H5Tinit.c PROPERTIES GENERATED TRUE) - if (BUILD_SHARED_LIBS) - add_custom_command ( - OUTPUT shared/shared_gen_SRCS.stamp1 - BYPRODUCTS shared/H5Tinit.c - COMMAND ${CMAKE_COMMAND} - ARGS -E copy_if_different H5Tinit.c shared/H5Tinit.c - COMMAND ${CMAKE_COMMAND} - ARGS -E touch shared/shared_gen_SRCS.stamp1 - DEPENDS H5Tinit.c gen_SRCS.stamp1 - WORKING_DIRECTORY ${HDF5_GENERATED_SOURCE_DIR} - COMMENT "Copy existing H5Tinit.c to shared folder" - ) - endif () -endif () - -#----------------------------------------------------------------------------- -# Add Target to clang-format -#----------------------------------------------------------------------------- -if (HDF5_ENABLE_FORMATTERS) - clang_format (HDF5_SRC_DETECT_FORMAT ${HDF5_SRC_DIR}/H5detect.c) -endif () - # make the H5make_libsettings program add_executable (H5make_libsettings ${HDF5_SRC_DIR}/H5make_libsettings.c) target_include_directories (H5make_libsettings PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") @@ -1221,12 +1126,12 @@ if (BUILD_SHARED_LIBS) endif () #----------------------------------------------------------------------------- -# Add H5Tinit source to build - generated by H5detect/CMake at configure time +# Add generated source to build #----------------------------------------------------------------------------- if (BUILD_STATIC_LIBS) - set (gen_SRCS ${HDF5_GENERATED_SOURCE_DIR}/H5Tinit.c ${HDF5_SRC_BINARY_DIR}/H5lib_settings.c) + set (gen_SRCS ${HDF5_SRC_BINARY_DIR}/H5lib_settings.c) add_custom_target (gen_${HDF5_LIB_TARGET} ALL - DEPENDS ${lib_prog_deps} ${HDF5_GENERATED_SOURCE_DIR}/gen_SRCS.stamp1 ${HDF5_SRC_BINARY_DIR}/gen_SRCS.stamp2 + DEPENDS ${lib_prog_deps} ${HDF5_SRC_BINARY_DIR}/gen_SRCS.stamp2 COMMENT "Generation target files" ) @@ -1264,9 +1169,9 @@ if (BUILD_STATIC_LIBS) endif () if (BUILD_SHARED_LIBS) - set (shared_gen_SRCS ${HDF5_GENERATED_SOURCE_DIR}/shared/H5Tinit.c ${HDF5_SRC_BINARY_DIR}/shared/H5lib_settings.c) + set (shared_gen_SRCS ${HDF5_SRC_BINARY_DIR}/shared/H5lib_settings.c) add_custom_target (gen_${HDF5_LIBSH_TARGET} ALL - DEPENDS ${lib_prog_deps} ${HDF5_GENERATED_SOURCE_DIR}/shared/shared_gen_SRCS.stamp1 ${HDF5_SRC_BINARY_DIR}/shared/shared_gen_SRCS.stamp2 + DEPENDS ${lib_prog_deps} ${HDF5_SRC_BINARY_DIR}/shared/shared_gen_SRCS.stamp2 COMMENT "Shared generation target files" ) @@ -1449,7 +1354,7 @@ if (DOXYGEN_FOUND) # Replace variables inside @@ with the current values add_custom_target (hdf5lib_doc ALL COMMAND ${DOXYGEN_EXECUTABLE} ${HDF5_BINARY_DIR}/Doxyfile - DEPENDS ${HDF5_GENERATED_SOURCE_DIR}/H5Tinit.c ${HDF5_SRC_BINARY_DIR}/H5lib_settings.c + DEPENDS ${HDF5_SRC_BINARY_DIR}/H5lib_settings.c WORKING_DIRECTORY ${HDF5_SRC_DIR} COMMENT "Generating HDF5 library Source API documentation with Doxygen" VERBATIM ) diff --git a/src/H5T.c b/src/H5T.c index e2debd48f35..cafb7475839 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -368,8 +368,7 @@ H5T_order_t H5T_native_order_g = H5T_ORDER_ERROR; /*********************/ /* - * Predefined data types. These are initialized at runtime in H5Tinit.c and - * by H5T_init() in this source file. + * Predefined data types. These are initialized at runtime by H5T_init(). * * If more of these are added, the new ones must be added to the list of * types to reset in H5T_term_package(). @@ -501,11 +500,7 @@ size_t H5T_NATIVE_FLOAT_ALIGN_g = 0; size_t H5T_NATIVE_DOUBLE_ALIGN_g = 0; size_t H5T_NATIVE_LDOUBLE_ALIGN_g = 0; -/* - * Alignment constraints for C9x types. These are initialized at run time in - * H5Tinit.c if the types are provided by the system. Otherwise we set their - * values to 0 here (no alignment calculated). - */ +/* Alignment constraints for C99 types */ size_t H5T_NATIVE_INT8_ALIGN_g = 0; size_t H5T_NATIVE_UINT8_ALIGN_g = 0; size_t H5T_NATIVE_INT_LEAST8_ALIGN_g = 0; @@ -756,13 +751,11 @@ H5T_init(void) /* Only 16 (numbered 0-15) are supported in the current file format */ HDcompile_assert(H5T_NCLASSES < 16); - /* - * Initialize pre-defined native datatypes from code generated during - * the library configuration by H5detect. - */ - if (H5T__init_native() < 0) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize interface") + /* Initialize native floating-point datatypes */ + if (H5T__init_native_float_types() < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize floating-point types") + /* Initialize all other native types */ if (H5T__init_native_internal() < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize integers") diff --git a/src/H5Tinit_float.c b/src/H5Tinit_float.c new file mode 100644 index 00000000000..8d3ca9224b9 --- /dev/null +++ b/src/H5Tinit_float.c @@ -0,0 +1,216 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://www.hdfgroup.org/licenses. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Purpose: Initialize native floating-point datatypes + */ + +/* + * Each of the numeric formats listed below are + * printed from most significant bit to least + * significant bit even though the actual bytes + * might be stored in a different order in + * memory. The integers above each binary byte + * indicate the relative order of the bytes in + * memory; little-endian machines have + * decreasing numbers while big-endian machines + * have increasing numbers. + * + * The fields of the numbers are printed as + * letters with `S' for the mantissa sign bit, + * `M' for the mantissa magnitude, and `E' for + * the exponent. The exponent has an associated + * bias which can be subtracted to find the + * true exponent. The radix point is assumed + * to be before the first `M' bit. Any bit + * of a floating-point value not falling into one + * of these categories is printed as a question + * mark. Bits of integer types are printed as + * `I' for 2's complement and `U' for magnitude. + * + * If the most significant bit of the normalized + * mantissa (always a `1' except for `0.0') is + * not stored then an `implicit=yes' appears + * under the field description. In this case, + * the radix point is still assumed to be + * before the first `M' but after the implicit + * bit. + * + */ + +/****************/ +/* Module Setup */ +/****************/ + +#include "H5Tmodule.h" /* This source code file is part of the H5T module */ + +/***********/ +/* Headers */ +/***********/ +#include "H5private.h" /* Generic Functions */ +#include "H5Eprivate.h" /* Error handling */ +#include "H5FLprivate.h" /* Free Lists */ +#include "H5Iprivate.h" /* IDs */ +#include "H5Tpkg.h" /* Datatypes */ + +/****************/ +/* Local Macros */ +/****************/ + +/******************/ +/* Local Typedefs */ +/******************/ + +/********************/ +/* Package Typedefs */ +/********************/ + +/********************/ +/* Local Prototypes */ +/********************/ + +/********************/ +/* Public Variables */ +/********************/ + +/*****************************/ +/* Library Private Variables */ +/*****************************/ + +/*********************/ +/* Package Variables */ +/*********************/ + +/*******************/ +/* Local Variables */ +/*******************/ + +/*------------------------------------------------------------------------- + * Function: H5T__init_native_float_types + * + * Purpose: Initialize native floating-point datatypes + * + * Return: Success: non-negative + * Failure: negative + *------------------------------------------------------------------------- + */ +herr_t +H5T__init_native_float_types(void) +{ + H5T_t *dt = NULL; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_PACKAGE + + /* + * 3 2 1 0 + * SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM + * Implicit bit? yes + */ + /* H5T_NATIVE_FLOAT */ + if (NULL == (dt = H5T__alloc())) + HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") + dt->shared->state = H5T_STATE_IMMUTABLE; + dt->shared->type = H5T_FLOAT; + dt->shared->size = 4; + dt->shared->u.atomic.order = H5T_ORDER_LE; + dt->shared->u.atomic.offset = 0; + dt->shared->u.atomic.prec = 32; + dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO; + dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO; + dt->shared->u.atomic.u.f.sign = 31; + dt->shared->u.atomic.u.f.epos = 23; + dt->shared->u.atomic.u.f.esize = 8; + dt->shared->u.atomic.u.f.ebias = 0x0000007f; + dt->shared->u.atomic.u.f.mpos = 0; + dt->shared->u.atomic.u.f.msize = 23; + dt->shared->u.atomic.u.f.norm = H5T_NORM_IMPLIED; + dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; + if ((H5T_NATIVE_FLOAT_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") + H5T_NATIVE_FLOAT_ALIGN_g = 4; + + /* + * 7 6 5 4 + * SEEEEEEE EEEEMMMM MMMMMMMM MMMMMMMM + * 3 2 1 0 + * MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM + * Implicit bit? yes + */ + /* H5T_NATIVE_DOUBLE */ + if (NULL == (dt = H5T__alloc())) + HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") + dt->shared->state = H5T_STATE_IMMUTABLE; + dt->shared->type = H5T_FLOAT; + dt->shared->size = 8; + dt->shared->u.atomic.order = H5T_ORDER_LE; + dt->shared->u.atomic.offset = 0; + dt->shared->u.atomic.prec = 64; + dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO; + dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO; + dt->shared->u.atomic.u.f.sign = 63; + dt->shared->u.atomic.u.f.epos = 52; + dt->shared->u.atomic.u.f.esize = 11; + dt->shared->u.atomic.u.f.ebias = 0x000003ff; + dt->shared->u.atomic.u.f.mpos = 0; + dt->shared->u.atomic.u.f.msize = 52; + dt->shared->u.atomic.u.f.norm = H5T_NORM_IMPLIED; + dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; + if ((H5T_NATIVE_DOUBLE_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") + H5T_NATIVE_DOUBLE_ALIGN_g = 8; + + /* + * 15 14 13 12 + * ???????? ???????? ???????? ???????? + * 11 10 9 8 + * ???????? ???????? SEEEEEEE EEEEEEEE + * 7 6 5 4 + * MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM + * 3 2 1 0 + * MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM + * Implicit bit? no + */ + /* H5T_NATIVE_LDOUBLE */ + if (NULL == (dt = H5T__alloc())) + HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") + dt->shared->state = H5T_STATE_IMMUTABLE; + dt->shared->type = H5T_FLOAT; + dt->shared->size = 16; + dt->shared->u.atomic.order = H5T_ORDER_LE; + dt->shared->u.atomic.offset = 0; + dt->shared->u.atomic.prec = 80; + dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO; + dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO; + dt->shared->u.atomic.u.f.sign = 79; + dt->shared->u.atomic.u.f.epos = 64; + dt->shared->u.atomic.u.f.esize = 15; + dt->shared->u.atomic.u.f.ebias = 0x00003fff; + dt->shared->u.atomic.u.f.mpos = 0; + dt->shared->u.atomic.u.f.msize = 64; + dt->shared->u.atomic.u.f.norm = H5T_NORM_NONE; + dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; + if ((H5T_NATIVE_LDOUBLE_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") + H5T_NATIVE_LDOUBLE_ALIGN_g = 16; + H5T_native_order_g = H5T_ORDER_LE; + +done: + if (ret_value < 0) { + if (dt != NULL) { + dt->shared = H5FL_FREE(H5T_shared_t, dt->shared); + dt = H5FL_FREE(H5T_t, dt); + } + } + + FUNC_LEAVE_NOAPI(ret_value); +} /* end H5T__init_native_float_types() */ diff --git a/src/H5Tmodule.h b/src/H5Tmodule.h index c059d6e5c4c..805198f36c9 100644 --- a/src/H5Tmodule.h +++ b/src/H5Tmodule.h @@ -408,11 +408,9 @@ * NATIVE * * - * This architecture contains C-like datatypes for the machine on which - * the library was compiled. The types were actually defined by running - * the H5detect program when the library was compiled. In order to be - * portable, applications should almost always use this architecture - * to describe things in memory. + * This architecture contains C-like datatypes for the machine for which + * the library was compiled. In order to be portable, applications should + * almost always use this architecture to describe things in memory. * * * @@ -3921,9 +3919,8 @@ filled according to the value of this property. The padding can be: * * \defgroup PDTNAT Native Datatypes * \ingroup PDT - * \details These are the datatypes detected during library \Emph{compilation} - * by \c H5detect(). Their names differ from other HDF5 datatype names - * as follows: + * \details These are the C-like datatypes for the platform. Their names differ + * from other HDF5 datatype names as follows: * \li Instead of a class name, precision and byte order as the last * component, they have a C-like type name. * \li If the type begins with \c U then it is the unsigned version of diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h index 504f756adde..23fa960db0b 100644 --- a/src/H5Tpkg.h +++ b/src/H5Tpkg.h @@ -464,7 +464,7 @@ H5FL_EXTERN(H5T_t); H5FL_EXTERN(H5T_shared_t); /* Common functions */ -H5_DLL herr_t H5T__init_native(void); +H5_DLL herr_t H5T__init_native_float_types(void); H5_DLL herr_t H5T__init_native_internal(void); H5_DLL H5T_t *H5T__create(H5T_class_t type, size_t size); H5_DLL H5T_t *H5T__alloc(void); diff --git a/src/H5Tpublic.h b/src/H5Tpublic.h index c28266acdb9..e813c2f0fd3 100644 --- a/src/H5Tpublic.h +++ b/src/H5Tpublic.h @@ -728,8 +728,7 @@ H5_DLLVAR hid_t H5T_VAX_F32_g; H5_DLLVAR hid_t H5T_VAX_F64_g; /* - * The predefined native types. These are the types detected by H5detect and - * they violate the naming scheme a little. Instead of a class name, + * The predefined native types for this platform. Instead of a class name, * precision and byte order as the last component, they have a C-like type * name. If the type begins with `U' then it is the unsigned version of the * integer type; other integer types are signed. The type LLONG corresponds diff --git a/src/Makefile.am b/src/Makefile.am index a1c21e3984a..89eafc72ec3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,11 +18,7 @@ include $(top_srcdir)/config/commence.am include $(top_srcdir)/config/lt_vers.am -# How to build H5detect for number format detection. -# Use -g to force no optimization since many compilers (e.g., Intel) takes -# a long time to compile it with any optimization on. H5detect is used -# to generate H5Tinit.c once. So, optimization is not critical. -noinst_PROGRAMS = H5detect H5make_libsettings +noinst_PROGRAMS = H5make_libsettings # Our main target, the HDF5 library lib_LTLIBRARIES=libhdf5.la @@ -30,8 +26,8 @@ lib_LTLIBRARIES=libhdf5.la # Add libtool numbers to the HDF5 library (from config/lt_vers.am) libhdf5_la_LDFLAGS= -version-info $(LT_VERS_INTERFACE):$(LT_VERS_REVISION):$(LT_VERS_AGE) $(AM_LDFLAGS) -# H5Tinit.c and H5lib_settings.c are generated files and should be cleaned. -MOSTLYCLEANFILES=H5Tinit.c H5lib_settings.c $(DX_CLEANFILES) +# H5lib_settings.c is a generated file and should be cleaned. +MOSTLYCLEANFILES=H5lib_settings.c $(DX_CLEANFILES) # H5pubconf.h is generated by configure, and should be cleaned. DISTCLEANFILES=H5pubconf.h @@ -101,7 +97,7 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5lib_settings.c H5system.c \ H5SM.c H5SMbtree2.c H5SMcache.c H5SMmessage.c H5SMtest.c \ H5T.c H5Tarray.c H5Tbit.c H5Tcommit.c H5Tcompound.c H5Tconv.c \ H5Tcset.c H5Tdbg.c H5Tdeprec.c H5Tenum.c H5Tfields.c H5Tfixed.c \ - H5Tfloat.c H5Tinit.c H5Tnative.c H5Toffset.c H5Toh.c H5Topaque.c \ + H5Tfloat.c H5Tinit_float.c H5Tnative.c H5Toffset.c H5Toh.c H5Topaque.c \ H5Torder.c H5Tref.c H5Tpad.c H5Tprecis.c H5Tstrpad.c H5Tvisit.c \ H5Tvlen.c \ H5TS.c \ @@ -190,19 +186,6 @@ endif settingsdir=$(libdir) settings_DATA=libhdf5.settings -# Number format detection -# The LD_LIBRARY_PATH setting is a kludge. -# Things should have been all set during H5detect making. -# Remove the generated .c file if errors occur unless HDF5_Make_Ignore -# is set to ignore the error. -H5Tinit.c: H5detect$(EXEEXT) - @if $(AM_V_P); then set -x; else echo " GEN H5Tinit.c"; fi; \ - LD_LIBRARY_PATH="$$LD_LIBRARY_PATH`echo $(LDFLAGS) | \ - sed -e 's/-L/:/g' -e 's/ //g'`" \ - $(RUNSERIAL) ./H5detect$(EXEEXT) $@ || \ - (test $$HDF5_Make_Ignore && echo "*** Error ignored") || \ - ($(RM) $@ ; exit 1) - # Build configuration header file generation # The LD_LIBRARY_PATH setting is a kludge. # Things should have been all set during H5make_libsettings making. From 95ea389c78c4acc414101dab033725d437ad3bea Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 09:34:49 -0700 Subject: [PATCH 02/23] Move macros and functionality from H5detect Still doesn't dynamically set type characteristics, but at least everything compiles and executes without failing. --- src/H5Tinit_float.c | 418 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 392 insertions(+), 26 deletions(-) diff --git a/src/H5Tinit_float.c b/src/H5Tinit_float.c index 8d3ca9224b9..b6394558755 100644 --- a/src/H5Tinit_float.c +++ b/src/H5Tinit_float.c @@ -66,10 +66,146 @@ /* Local Macros */ /****************/ +/* This could also go in H5private.h, but this is the only place we + * need to turn off the sanitizers and we don't want to encourage + * this. + */ +#if defined(__has_attribute) +#if __has_attribute(no_sanitize) +#define H5_NO_UBSAN __attribute__((no_sanitize("undefined"))) +#else +#define H5_NO_UBSAN +#endif +#else +#define H5_NO_UBSAN +#endif + +/*------------------------------------------------------------------------- + * Function: DETECT_F + * + * Purpose: This macro takes a floating point type like `double' and + * a base name like `natd' and detects byte order, mantissa + * location, exponent location, sign bit location, presence or + * absence of implicit mantissa bit, and exponent bias and + * initializes a detected_t structure with those properties. + *------------------------------------------------------------------------- + */ +#define DETECT_F(TYPE, VAR, INFO) \ + { \ + TYPE _v1, _v2, _v3; \ + unsigned char _buf1[sizeof(TYPE)], _buf3[sizeof(TYPE)]; \ + unsigned char _pad_mask[sizeof(TYPE)]; \ + unsigned char _byte_mask; \ + int _i, _j, _last = (-1); \ + const char *_mesg; \ + \ + memset(&INFO, 0, sizeof(INFO)); \ + INFO.varname = #VAR; \ + INFO.size = sizeof(TYPE); \ + \ + /* Initialize padding mask */ \ + memset(_pad_mask, 0, sizeof(_pad_mask)); \ + \ + /* Padding bits. Set a variable to 4.0, then flip each bit and see if \ + * the modified variable is equal ("==") to the original. Build a \ + * padding bitmask to indicate which bits in the type are padding (i.e. \ + * have no effect on the value and should be ignored by subsequent \ + * steps). This is necessary because padding bits can change arbitrarily \ + * and interfere with detection of the various properties below unless we \ + * know to ignore them. */ \ + _v1 = (TYPE)4.0L; \ + memcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \ + for (_i = 0; _i < (int)sizeof(TYPE); _i++) \ + for (_byte_mask = (unsigned char)1; _byte_mask; _byte_mask = (unsigned char)(_byte_mask << 1)) { \ + _buf1[_i] ^= _byte_mask; \ + memcpy((void *)&_v2, (const void *)_buf1, sizeof(TYPE)); \ + H5_GCC_CLANG_DIAG_OFF("float-equal") \ + if (_v1 != _v2) \ + _pad_mask[_i] |= _byte_mask; \ + H5_GCC_CLANG_DIAG_ON("float-equal") \ + _buf1[_i] ^= _byte_mask; \ + } \ + \ + /* Byte Order */ \ + for (_i = 0, _v1 = (TYPE)0.0L, _v2 = (TYPE)1.0L; _i < (int)sizeof(TYPE); _i++) { \ + _v3 = _v1; \ + _v1 += _v2; \ + _v2 /= (TYPE)256.0L; \ + memcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \ + memcpy(_buf3, (const void *)&_v3, sizeof(TYPE)); \ + _j = H5T__byte_cmp(sizeof(TYPE), _buf3, _buf1, _pad_mask); \ + if (_j >= 0) { \ + INFO.perm[_i] = _j; \ + _last = _i; \ + } \ + } \ + H5T__fix_order(sizeof(TYPE), _last, INFO.perm, (const char **)&_mesg); \ + \ + if (!strcmp(_mesg, "VAX")) \ + INFO.is_vax = TRUE; \ + \ + /* Implicit mantissa bit */ \ + _v1 = (TYPE)0.5L; \ + _v2 = (TYPE)1.0L; \ + INFO.imp = H5T__imp_bit(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ + \ + /* Sign bit */ \ + _v1 = (TYPE)1.0L; \ + _v2 = (TYPE)-1.0L; \ + INFO.sign = H5T__bit_cmp(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ + \ + /* Mantissa */ \ + INFO.mpos = 0; \ + \ + _v1 = (TYPE)1.0L; \ + _v2 = (TYPE)1.5L; \ + INFO.msize = H5T__bit_cmp(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ + INFO.msize += 1 + (unsigned int)(INFO.imp ? 0 : 1) - INFO.mpos; \ + \ + /* Exponent */ \ + INFO.epos = INFO.mpos + INFO.msize; \ + \ + INFO.esize = INFO.sign - INFO.epos; \ + \ + _v1 = (TYPE)1.0L; \ + INFO.bias = H5T__find_bias(INFO.epos, INFO.esize, INFO.perm, &_v1); \ + H5T__precision(&(INFO)); \ + if (!strcmp(INFO.varname, "FLOAT") || !strcmp(INFO.varname, "DOUBLE") || \ + !strcmp(INFO.varname, "LDOUBLE")) { \ + COMP_ALIGNMENT(TYPE, INFO.comp_align); \ + } \ + } + +/* Detect alignment for C structure */ +#define COMP_ALIGNMENT(TYPE, COMP_ALIGN) \ + { \ + struct { \ + char c; \ + TYPE x; \ + } s; \ + \ + COMP_ALIGN = (unsigned int)((char *)(&(s.x)) - (char *)(&s)); \ + } + /******************/ /* Local Typedefs */ /******************/ +/* Holds detected information about a native floating-point type */ +typedef struct H5T_fpoint_det_t { + const char *varname; + unsigned int size; /* Total byte size */ + unsigned int precision; /* Meaningful bits */ + unsigned int offset; /* Bit offset to meaningful bits */ + int perm[32]; /* For detection of byte order */ + hbool_t is_vax; /* For VAX (float & double) only */ + unsigned int sign; /* Location of sign bit */ + unsigned int mpos, msize, imp; /* Information about mantissa */ + unsigned int epos, esize; /* Information about exponent */ + unsigned long bias; /* Exponent bias for floating point */ + unsigned int comp_align; /* Alignment for structure */ +} H5T_fpoint_det_t; + /********************/ /* Package Typedefs */ /********************/ @@ -94,6 +230,229 @@ /* Local Variables */ /*******************/ +/* Functions used in the DETECT_F() macro */ +static int H5T__byte_cmp(int, const void *, const void *, const unsigned char *); +static unsigned int H5T__bit_cmp(unsigned int, int *, void *, void *, const unsigned char *); +static void H5T__fix_order(int, int, int *, const char **); +static unsigned int H5T__imp_bit(unsigned int, int *, void *, void *, const unsigned char *); +static unsigned int H5T__find_bias(unsigned int, unsigned int, int *, void *); +static void H5T__precision(H5T_fpoint_det_t *); + +/*------------------------------------------------------------------------- + * Function: H5T__byte_cmp + * + * Purpose: Compares two chunks of memory A and B and returns the + * byte index into those arrays of the first byte that + * differs between A and B. Ignores differences where the + * corresponding bit in pad_mask is set to 0. + * + * Return: Success: Index of differing byte. + * Failure: -1 if all bytes are the same. + *------------------------------------------------------------------------- + */ +static int +H5T__byte_cmp(int n, const void *_a, const void *_b, const unsigned char *pad_mask) +{ + int i; + const unsigned char *a = (const unsigned char *)_a; + const unsigned char *b = (const unsigned char *)_b; + + for (i = 0; i < n; i++) + if ((a[i] & pad_mask[i]) != (b[i] & pad_mask[i])) + return i; + + return -1; +} + +/*------------------------------------------------------------------------- + * Function: H5T__bit_cmp + * + * Purpose: Compares two bit vectors and returns the index for the + * first bit that differs between the two vectors. The + * size of the vector is NBYTES. PERM is a mapping from + * actual order to little endian. Ignores differences where + * the corresponding bit in pad_mask is set to 0. + * + * Return: Index of first differing bit. + *------------------------------------------------------------------------- + */ +static unsigned int +H5T__bit_cmp(unsigned int nbytes, int *perm, void *_a, void *_b, const unsigned char *pad_mask) +{ + unsigned int i; + unsigned char *a = (unsigned char *)_a; + unsigned char *b = (unsigned char *)_b; + unsigned char aa, bb; + + for (i = 0; i < nbytes; i++) { + assert(perm[i] < (int)nbytes); + if ((aa = (unsigned char)(a[perm[i]] & pad_mask[perm[i]])) != + (bb = (unsigned char)(b[perm[i]] & pad_mask[perm[i]]))) { + unsigned int j; + + for (j = 0; j < 8; j++, aa >>= 1, bb >>= 1) { + if ((aa & 1) != (bb & 1)) + return i * 8 + j; + } + fprintf(stderr, "INTERNAL ERROR"); + abort(); + } + } + fprintf(stderr, "INTERNAL ERROR"); + abort(); + return 0; +} + +/*------------------------------------------------------------------------- + * Function: H5T__fix_order + * + * Purpose: Given an array PERM with elements FIRST through LAST + * initialized with zero origin byte numbers, this function + * creates a permutation vector that maps the actual order + * of a floating point number to little-endian. + * + * This function assumes that the mantissa byte ordering + * implies the total ordering. + * + * Return: void + *------------------------------------------------------------------------- + */ +static void +H5T__fix_order(int n, int last, int *perm, const char **mesg) +{ + int i; + + if (last > 1) { + + /* We have at least three points to consider */ + if (perm[last] < perm[last - 1] && perm[last - 1] < perm[last - 2]) { + /* Little endian */ + if (mesg) + *mesg = "Little-endian"; + for (i = 0; i < n; i++) + perm[i] = i; + } + else if (perm[last] > perm[last - 1] && perm[last - 1] > perm[last - 2]) { + /* Big endian */ + if (mesg) + *mesg = "Big-endian"; + for (i = 0; i < n; i++) + perm[i] = (n - 1) - i; + } + else { + /* Undetermined endianness (e.g., bi-endian like in VAX) */ + assert(0 == n % 2); + if (mesg) + *mesg = "VAX"; + for (i = 0; i < n; i += 2) { + perm[i] = (n - 2) - i; + perm[i + 1] = (n - 1) - i; + } + } + } + else { + fprintf(stderr, "Failed to detect byte order of %d-byte floating point.\n", n); + exit(EXIT_FAILURE); + } +} + +/*------------------------------------------------------------------------- + * Function: H5T__imp_bit + * + * Purpose: Looks for an implicit bit in the mantissa. The value + * of _A should be 1.0 and the value of _B should be 0.5. + * Some floating-point formats discard the most significant + * bit of the mantissa after normalizing since it will always + * be a one (except for 0.0). If this is true for the native + * floating point values stored in _A and _B then the function + * returns non-zero. + * + * This function assumes that the exponent occupies higher + * order bits than the mantissa and that the most significant + * bit of the mantissa is next to the least significant bit + * of the exponent. + * + * + * Return: Success: Non-zero if the most significant bit + * of the mantissa is discarded (ie, the + * mantissa has an implicit `one' as the + * most significant bit). Otherwise, + * returns zero. + * + * Failure: 1 + *------------------------------------------------------------------------- + */ +static unsigned int +H5T__imp_bit(unsigned int n, int *perm, void *_a, void *_b, const unsigned char *pad_mask) +{ + unsigned char *a = (unsigned char *)_a; + unsigned char *b = (unsigned char *)_b; + unsigned int changed; + unsigned int major; + unsigned int minor; + unsigned int msmb; /* Most significant mantissa bit */ + + /* Look for the least significant bit that has changed between + * A and B. This is the least significant bit of the exponent. + */ + changed = H5T__bit_cmp(n, perm, a, b, pad_mask); + + /* The bit to the right (less significant) of the changed bit should + * be the most significant bit of the mantissa. If it is non-zero + * then the format does not remove the leading `1' of the mantissa. + */ + msmb = changed - 1; + major = msmb / 8; + minor = msmb % 8; + + return (a[perm[major]] >> minor) & 0x01 ? 0 : 1; +} + +/*------------------------------------------------------------------------- + * Function: find_bias + * + * Purpose: Determines the bias of the exponent. This function should + * be called with _A having a value of `1'. + * + * Return: The exponent bias + *------------------------------------------------------------------------- + */ +H5_ATTR_PURE static unsigned int +H5T__find_bias(unsigned int epos, unsigned int esize, int *perm, void *_a) +{ + unsigned char *a = (unsigned char *)_a; + unsigned char mask; + unsigned int b, shift = 0, nbits, bias = 0; + + while (esize > 0) { + nbits = MIN(esize, (8 - epos % 8)); + mask = (unsigned char)((1 << nbits) - 1); + b = (unsigned int)(a[perm[epos / 8]] >> (epos % 8)) & mask; + bias |= b << shift; + + shift += nbits; + esize -= nbits; + epos += nbits; + } + return bias; +} + +/*------------------------------------------------------------------------- + * Function: H5T__precision + * + * Purpose: Determine the precision and offset + * + * Return: void + *------------------------------------------------------------------------- + */ +static void +H5T__precision(H5T_fpoint_det_t *d) +{ + /* A floating point */ + d->offset = MIN3(d->mpos, d->epos, d->sign); + d->precision = d->msize + d->esize + 1; +} + /*------------------------------------------------------------------------- * Function: H5T__init_native_float_types * @@ -103,20 +462,27 @@ * Failure: negative *------------------------------------------------------------------------- */ -herr_t +herr_t H5_NO_UBSAN H5T__init_native_float_types(void) { - H5T_t *dt = NULL; - herr_t ret_value = SUCCEED; + H5T_fpoint_det_t float_det; + H5T_fpoint_det_t double_det; + H5T_fpoint_det_t long_double_det; + H5T_t *dt = NULL; + herr_t ret_value = SUCCEED; FUNC_ENTER_PACKAGE - /* - * 3 2 1 0 - * SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM - * Implicit bit? yes - */ + memset(&float_det, 0, sizeof(H5T_fpoint_det_t)); + memset(&double_det, 0, sizeof(H5T_fpoint_det_t)); + memset(&long_double_det, 0, sizeof(H5T_fpoint_det_t)); + /* H5T_NATIVE_FLOAT */ + + /* Get the type's characteristics */ + DETECT_F(float, FLOAT, float_det); + + /* Allocate and fill type structure */ if (NULL == (dt = H5T__alloc())) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") dt->shared->state = H5T_STATE_IMMUTABLE; @@ -135,18 +501,18 @@ H5T__init_native_float_types(void) dt->shared->u.atomic.u.f.msize = 23; dt->shared->u.atomic.u.f.norm = H5T_NORM_IMPLIED; dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; + + /* Register the type and set global variables */ if ((H5T_NATIVE_FLOAT_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") H5T_NATIVE_FLOAT_ALIGN_g = 4; - /* - * 7 6 5 4 - * SEEEEEEE EEEEMMMM MMMMMMMM MMMMMMMM - * 3 2 1 0 - * MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM - * Implicit bit? yes - */ /* H5T_NATIVE_DOUBLE */ + + /* Get the type's characteristics */ + DETECT_F(double, DOUBLE, double_det); + + /* Allocate and fill type structure */ if (NULL == (dt = H5T__alloc())) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") dt->shared->state = H5T_STATE_IMMUTABLE; @@ -165,22 +531,18 @@ H5T__init_native_float_types(void) dt->shared->u.atomic.u.f.msize = 52; dt->shared->u.atomic.u.f.norm = H5T_NORM_IMPLIED; dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; + + /* Register the type and set global variables */ if ((H5T_NATIVE_DOUBLE_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") H5T_NATIVE_DOUBLE_ALIGN_g = 8; - /* - * 15 14 13 12 - * ???????? ???????? ???????? ???????? - * 11 10 9 8 - * ???????? ???????? SEEEEEEE EEEEEEEE - * 7 6 5 4 - * MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM - * 3 2 1 0 - * MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM - * Implicit bit? no - */ /* H5T_NATIVE_LDOUBLE */ + + /* Get the type's characteristics */ + DETECT_F(long double, LDOUBLE, long_double_det); + + /* Allocate and fill type structure */ if (NULL == (dt = H5T__alloc())) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") dt->shared->state = H5T_STATE_IMMUTABLE; @@ -199,9 +561,13 @@ H5T__init_native_float_types(void) dt->shared->u.atomic.u.f.msize = 64; dt->shared->u.atomic.u.f.norm = H5T_NORM_NONE; dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; + + /* Register the type and set global variables */ if ((H5T_NATIVE_LDOUBLE_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") H5T_NATIVE_LDOUBLE_ALIGN_g = 16; + + /* Set the platform's alignment */ H5T_native_order_g = H5T_ORDER_LE; done: From 7aa8f26ba0883456649ceea9480e621b390a710c Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 09:52:04 -0700 Subject: [PATCH 03/23] Set most fields dynamically --- src/H5Tinit_float.c | 60 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/H5Tinit_float.c b/src/H5Tinit_float.c index b6394558755..a3978e8db9d 100644 --- a/src/H5Tinit_float.c +++ b/src/H5Tinit_float.c @@ -487,25 +487,25 @@ H5T__init_native_float_types(void) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") dt->shared->state = H5T_STATE_IMMUTABLE; dt->shared->type = H5T_FLOAT; - dt->shared->size = 4; - dt->shared->u.atomic.order = H5T_ORDER_LE; - dt->shared->u.atomic.offset = 0; - dt->shared->u.atomic.prec = 32; + dt->shared->size = float_det.size; + dt->shared->u.atomic.order = H5T_ORDER_LE; /* HERE */ + dt->shared->u.atomic.offset = float_det.offset; + dt->shared->u.atomic.prec = float_det.precision; dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO; dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO; - dt->shared->u.atomic.u.f.sign = 31; - dt->shared->u.atomic.u.f.epos = 23; - dt->shared->u.atomic.u.f.esize = 8; - dt->shared->u.atomic.u.f.ebias = 0x0000007f; - dt->shared->u.atomic.u.f.mpos = 0; - dt->shared->u.atomic.u.f.msize = 23; - dt->shared->u.atomic.u.f.norm = H5T_NORM_IMPLIED; + dt->shared->u.atomic.u.f.sign = float_det.sign; + dt->shared->u.atomic.u.f.epos = float_det.epos; + dt->shared->u.atomic.u.f.esize = float_det.esize; + dt->shared->u.atomic.u.f.ebias = 0x0000007f; /* HERE */ + dt->shared->u.atomic.u.f.mpos = float_det.mpos; + dt->shared->u.atomic.u.f.msize = float_det.msize; + dt->shared->u.atomic.u.f.norm = H5T_NORM_IMPLIED; /* HERE */ dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; /* Register the type and set global variables */ if ((H5T_NATIVE_FLOAT_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") - H5T_NATIVE_FLOAT_ALIGN_g = 4; + H5T_NATIVE_FLOAT_ALIGN_g = float_det.comp_align; /* H5T_NATIVE_DOUBLE */ @@ -517,25 +517,25 @@ H5T__init_native_float_types(void) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") dt->shared->state = H5T_STATE_IMMUTABLE; dt->shared->type = H5T_FLOAT; - dt->shared->size = 8; + dt->shared->size = double_det.size; dt->shared->u.atomic.order = H5T_ORDER_LE; - dt->shared->u.atomic.offset = 0; - dt->shared->u.atomic.prec = 64; + dt->shared->u.atomic.offset = double_det.offset; + dt->shared->u.atomic.prec = double_det.precision; dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO; dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO; - dt->shared->u.atomic.u.f.sign = 63; - dt->shared->u.atomic.u.f.epos = 52; - dt->shared->u.atomic.u.f.esize = 11; + dt->shared->u.atomic.u.f.sign = double_det.sign; + dt->shared->u.atomic.u.f.epos = double_det.epos; + dt->shared->u.atomic.u.f.esize = double_det.esize; dt->shared->u.atomic.u.f.ebias = 0x000003ff; - dt->shared->u.atomic.u.f.mpos = 0; - dt->shared->u.atomic.u.f.msize = 52; + dt->shared->u.atomic.u.f.mpos = double_det.mpos; + dt->shared->u.atomic.u.f.msize = double_det.msize; dt->shared->u.atomic.u.f.norm = H5T_NORM_IMPLIED; dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; /* Register the type and set global variables */ if ((H5T_NATIVE_DOUBLE_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") - H5T_NATIVE_DOUBLE_ALIGN_g = 8; + H5T_NATIVE_DOUBLE_ALIGN_g = double_det.comp_align; /* H5T_NATIVE_LDOUBLE */ @@ -547,25 +547,25 @@ H5T__init_native_float_types(void) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") dt->shared->state = H5T_STATE_IMMUTABLE; dt->shared->type = H5T_FLOAT; - dt->shared->size = 16; + dt->shared->size = long_double_det.size; dt->shared->u.atomic.order = H5T_ORDER_LE; - dt->shared->u.atomic.offset = 0; - dt->shared->u.atomic.prec = 80; + dt->shared->u.atomic.offset = long_double_det.offset; + dt->shared->u.atomic.prec = long_double_det.precision; dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO; dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO; - dt->shared->u.atomic.u.f.sign = 79; - dt->shared->u.atomic.u.f.epos = 64; - dt->shared->u.atomic.u.f.esize = 15; + dt->shared->u.atomic.u.f.sign = long_double_det.sign; + dt->shared->u.atomic.u.f.epos = long_double_det.epos; + dt->shared->u.atomic.u.f.esize = long_double_det.esize; dt->shared->u.atomic.u.f.ebias = 0x00003fff; - dt->shared->u.atomic.u.f.mpos = 0; - dt->shared->u.atomic.u.f.msize = 64; + dt->shared->u.atomic.u.f.mpos = long_double_det.mpos; + dt->shared->u.atomic.u.f.msize = long_double_det.msize; dt->shared->u.atomic.u.f.norm = H5T_NORM_NONE; dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; /* Register the type and set global variables */ if ((H5T_NATIVE_LDOUBLE_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") - H5T_NATIVE_LDOUBLE_ALIGN_g = 16; + H5T_NATIVE_LDOUBLE_ALIGN_g = long_double_det.comp_align; /* Set the platform's alignment */ H5T_native_order_g = H5T_ORDER_LE; From 48e9580e20c5f1d81a80af240c4cd29a5b08e1b6 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 09:54:04 -0700 Subject: [PATCH 04/23] Remove varname --- src/H5Tinit_float.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/H5Tinit_float.c b/src/H5Tinit_float.c index a3978e8db9d..4280b82fbff 100644 --- a/src/H5Tinit_float.c +++ b/src/H5Tinit_float.c @@ -100,7 +100,6 @@ const char *_mesg; \ \ memset(&INFO, 0, sizeof(INFO)); \ - INFO.varname = #VAR; \ INFO.size = sizeof(TYPE); \ \ /* Initialize padding mask */ \ @@ -170,10 +169,7 @@ _v1 = (TYPE)1.0L; \ INFO.bias = H5T__find_bias(INFO.epos, INFO.esize, INFO.perm, &_v1); \ H5T__precision(&(INFO)); \ - if (!strcmp(INFO.varname, "FLOAT") || !strcmp(INFO.varname, "DOUBLE") || \ - !strcmp(INFO.varname, "LDOUBLE")) { \ - COMP_ALIGNMENT(TYPE, INFO.comp_align); \ - } \ + COMP_ALIGNMENT(TYPE, INFO.comp_align); \ } /* Detect alignment for C structure */ @@ -193,7 +189,6 @@ /* Holds detected information about a native floating-point type */ typedef struct H5T_fpoint_det_t { - const char *varname; unsigned int size; /* Total byte size */ unsigned int precision; /* Meaningful bits */ unsigned int offset; /* Bit offset to meaningful bits */ From e5593824df3843d8075a5b096e18cbf4fd75894a Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 11:05:30 -0700 Subject: [PATCH 05/23] Cleaned up H5Tinit_float.c --- src/H5Tinit_float.c | 265 ++++++++++++++++++++------------------------ 1 file changed, 120 insertions(+), 145 deletions(-) diff --git a/src/H5Tinit_float.c b/src/H5Tinit_float.c index 4280b82fbff..7ef116a6670 100644 --- a/src/H5Tinit_float.c +++ b/src/H5Tinit_float.c @@ -14,39 +14,6 @@ * Purpose: Initialize native floating-point datatypes */ -/* - * Each of the numeric formats listed below are - * printed from most significant bit to least - * significant bit even though the actual bytes - * might be stored in a different order in - * memory. The integers above each binary byte - * indicate the relative order of the bytes in - * memory; little-endian machines have - * decreasing numbers while big-endian machines - * have increasing numbers. - * - * The fields of the numbers are printed as - * letters with `S' for the mantissa sign bit, - * `M' for the mantissa magnitude, and `E' for - * the exponent. The exponent has an associated - * bias which can be subtracted to find the - * true exponent. The radix point is assumed - * to be before the first `M' bit. Any bit - * of a floating-point value not falling into one - * of these categories is printed as a question - * mark. Bits of integer types are printed as - * `I' for 2's complement and `U' for magnitude. - * - * If the most significant bit of the normalized - * mantissa (always a `1' except for `0.0') is - * not stored then an `implicit=yes' appears - * under the field description. In this case, - * the radix point is still assumed to be - * before the first `M' but after the implicit - * bit. - * - */ - /****************/ /* Module Setup */ /****************/ @@ -97,7 +64,6 @@ unsigned char _pad_mask[sizeof(TYPE)]; \ unsigned char _byte_mask; \ int _i, _j, _last = (-1); \ - const char *_mesg; \ \ memset(&INFO, 0, sizeof(INFO)); \ INFO.size = sizeof(TYPE); \ @@ -138,15 +104,13 @@ _last = _i; \ } \ } \ - H5T__fix_order(sizeof(TYPE), _last, INFO.perm, (const char **)&_mesg); \ - \ - if (!strcmp(_mesg, "VAX")) \ - INFO.is_vax = TRUE; \ + H5T__fix_order(sizeof(TYPE), _last, INFO.perm, &INFO.order); \ \ /* Implicit mantissa bit */ \ - _v1 = (TYPE)0.5L; \ - _v2 = (TYPE)1.0L; \ - INFO.imp = H5T__imp_bit(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ + _v1 = (TYPE)0.5L; \ + _v2 = (TYPE)1.0L; \ + INFO.imp = H5T__imp_bit(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ + INFO.norm = INFO.imp ? H5T_NORM_IMPLIED : H5T_NORM_NONE; \ \ /* Sign bit */ \ _v1 = (TYPE)1.0L; \ @@ -166,9 +130,9 @@ \ INFO.esize = INFO.sign - INFO.epos; \ \ - _v1 = (TYPE)1.0L; \ - INFO.bias = H5T__find_bias(INFO.epos, INFO.esize, INFO.perm, &_v1); \ - H5T__precision(&(INFO)); \ + _v1 = (TYPE)1.0L; \ + INFO.ebias = H5T__find_bias(INFO.epos, INFO.esize, INFO.perm, &_v1); \ + H5T__set_precision(&(INFO)); \ COMP_ALIGNMENT(TYPE, INFO.comp_align); \ } @@ -190,14 +154,15 @@ /* Holds detected information about a native floating-point type */ typedef struct H5T_fpoint_det_t { unsigned int size; /* Total byte size */ - unsigned int precision; /* Meaningful bits */ + unsigned int prec; /* Meaningful bits */ unsigned int offset; /* Bit offset to meaningful bits */ int perm[32]; /* For detection of byte order */ - hbool_t is_vax; /* For VAX (float & double) only */ + H5T_order_t order; /* byte order */ unsigned int sign; /* Location of sign bit */ unsigned int mpos, msize, imp; /* Information about mantissa */ + H5T_norm_t norm; /* Information about mantissa */ unsigned int epos, esize; /* Information about exponent */ - unsigned long bias; /* Exponent bias for floating point */ + unsigned long ebias; /* Exponent bias for floating point */ unsigned int comp_align; /* Alignment for structure */ } H5T_fpoint_det_t; @@ -228,10 +193,10 @@ typedef struct H5T_fpoint_det_t { /* Functions used in the DETECT_F() macro */ static int H5T__byte_cmp(int, const void *, const void *, const unsigned char *); static unsigned int H5T__bit_cmp(unsigned int, int *, void *, void *, const unsigned char *); -static void H5T__fix_order(int, int, int *, const char **); +static void H5T__fix_order(int, int, int *, H5T_order_t *); static unsigned int H5T__imp_bit(unsigned int, int *, void *, void *, const unsigned char *); static unsigned int H5T__find_bias(unsigned int, unsigned int, int *, void *); -static void H5T__precision(H5T_fpoint_det_t *); +static void H5T__set_precision(H5T_fpoint_det_t *); /*------------------------------------------------------------------------- * Function: H5T__byte_cmp @@ -248,15 +213,18 @@ static void H5T__precision(H5T_fpoint_det_t *); static int H5T__byte_cmp(int n, const void *_a, const void *_b, const unsigned char *pad_mask) { - int i; - const unsigned char *a = (const unsigned char *)_a; - const unsigned char *b = (const unsigned char *)_b; + const unsigned char *a = (const unsigned char *)_a; + const unsigned char *b = (const unsigned char *)_b; + int ret_value = -1; + + FUNC_ENTER_PACKAGE_NOERR - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) if ((a[i] & pad_mask[i]) != (b[i] & pad_mask[i])) - return i; + HGOTO_DONE(i); - return -1; +done: + FUNC_LEAVE_NOAPI(ret_value); } /*------------------------------------------------------------------------- @@ -278,6 +246,9 @@ H5T__bit_cmp(unsigned int nbytes, int *perm, void *_a, void *_b, const unsigned unsigned char *a = (unsigned char *)_a; unsigned char *b = (unsigned char *)_b; unsigned char aa, bb; + unsigned int ret_value = 0; + + FUNC_ENTER_PACKAGE_NOERR for (i = 0; i < nbytes; i++) { assert(perm[i] < (int)nbytes); @@ -287,15 +258,13 @@ H5T__bit_cmp(unsigned int nbytes, int *perm, void *_a, void *_b, const unsigned for (j = 0; j < 8; j++, aa >>= 1, bb >>= 1) { if ((aa & 1) != (bb & 1)) - return i * 8 + j; + HGOTO_DONE(i * 8 + j); } - fprintf(stderr, "INTERNAL ERROR"); - abort(); } } - fprintf(stderr, "INTERNAL ERROR"); - abort(); - return 0; + +done: + FUNC_LEAVE_NOAPI(ret_value); } /*------------------------------------------------------------------------- @@ -313,42 +282,41 @@ H5T__bit_cmp(unsigned int nbytes, int *perm, void *_a, void *_b, const unsigned *------------------------------------------------------------------------- */ static void -H5T__fix_order(int n, int last, int *perm, const char **mesg) +H5T__fix_order(int n, int last, int *perm, H5T_order_t *order) { int i; - if (last > 1) { + FUNC_ENTER_PACKAGE_NOERR - /* We have at least three points to consider */ - if (perm[last] < perm[last - 1] && perm[last - 1] < perm[last - 2]) { - /* Little endian */ - if (mesg) - *mesg = "Little-endian"; - for (i = 0; i < n; i++) - perm[i] = i; - } - else if (perm[last] > perm[last - 1] && perm[last - 1] > perm[last - 2]) { - /* Big endian */ - if (mesg) - *mesg = "Big-endian"; - for (i = 0; i < n; i++) - perm[i] = (n - 1) - i; - } - else { - /* Undetermined endianness (e.g., bi-endian like in VAX) */ - assert(0 == n % 2); - if (mesg) - *mesg = "VAX"; - for (i = 0; i < n; i += 2) { - perm[i] = (n - 2) - i; - perm[i + 1] = (n - 1) - i; - } - } + assert(last > 1); + + /* We have at least three points to consider */ + if (perm[last] < perm[last - 1] && perm[last - 1] < perm[last - 2]) { + /* Little endian */ + *order = H5T_ORDER_LE; + for (i = 0; i < n; i++) + perm[i] = i; + } + else if (perm[last] > perm[last - 1] && perm[last - 1] > perm[last - 2]) { + /* Big endian */ + *order = H5T_ORDER_BE; + for (i = 0; i < n; i++) + perm[i] = (n - 1) - i; } else { - fprintf(stderr, "Failed to detect byte order of %d-byte floating point.\n", n); - exit(EXIT_FAILURE); + /* Undetermined endianness - defaults to 'VAX' for historical + * reasons, but there are other mixed-endian systems (like ARM + * in rare cases) + */ + assert(0 == n % 2); + *order = H5T_ORDER_VAX; + for (i = 0; i < n; i += 2) { + perm[i] = (n - 2) - i; + perm[i + 1] = (n - 1) - i; + } } + + FUNC_LEAVE_NOAPI_VOID } /*------------------------------------------------------------------------- @@ -387,6 +355,8 @@ H5T__imp_bit(unsigned int n, int *perm, void *_a, void *_b, const unsigned char unsigned int minor; unsigned int msmb; /* Most significant mantissa bit */ + FUNC_ENTER_PACKAGE_NOERR + /* Look for the least significant bit that has changed between * A and B. This is the least significant bit of the exponent. */ @@ -400,7 +370,7 @@ H5T__imp_bit(unsigned int n, int *perm, void *_a, void *_b, const unsigned char major = msmb / 8; minor = msmb % 8; - return (a[perm[major]] >> minor) & 0x01 ? 0 : 1; + FUNC_LEAVE_NOAPI((a[perm[major]] >> minor) & 0x01 ? 0 : 1); } /*------------------------------------------------------------------------- @@ -419,6 +389,8 @@ H5T__find_bias(unsigned int epos, unsigned int esize, int *perm, void *_a) unsigned char mask; unsigned int b, shift = 0, nbits, bias = 0; + FUNC_ENTER_PACKAGE_NOERR + while (esize > 0) { nbits = MIN(esize, (8 - epos % 8)); mask = (unsigned char)((1 << nbits) - 1); @@ -429,11 +401,12 @@ H5T__find_bias(unsigned int epos, unsigned int esize, int *perm, void *_a) esize -= nbits; epos += nbits; } - return bias; + + FUNC_LEAVE_NOAPI(bias); } /*------------------------------------------------------------------------- - * Function: H5T__precision + * Function: H5T__set_precision * * Purpose: Determine the precision and offset * @@ -441,11 +414,14 @@ H5T__find_bias(unsigned int epos, unsigned int esize, int *perm, void *_a) *------------------------------------------------------------------------- */ static void -H5T__precision(H5T_fpoint_det_t *d) +H5T__set_precision(H5T_fpoint_det_t *d) { - /* A floating point */ - d->offset = MIN3(d->mpos, d->epos, d->sign); - d->precision = d->msize + d->esize + 1; + FUNC_ENTER_PACKAGE_NOERR + + d->offset = MIN3(d->mpos, d->epos, d->sign); + d->prec = d->msize + d->esize + 1; + + FUNC_LEAVE_NOAPI_VOID } /*------------------------------------------------------------------------- @@ -460,110 +436,109 @@ H5T__precision(H5T_fpoint_det_t *d) herr_t H5_NO_UBSAN H5T__init_native_float_types(void) { - H5T_fpoint_det_t float_det; - H5T_fpoint_det_t double_det; - H5T_fpoint_det_t long_double_det; + H5T_fpoint_det_t det; H5T_t *dt = NULL; herr_t ret_value = SUCCEED; FUNC_ENTER_PACKAGE - memset(&float_det, 0, sizeof(H5T_fpoint_det_t)); - memset(&double_det, 0, sizeof(H5T_fpoint_det_t)); - memset(&long_double_det, 0, sizeof(H5T_fpoint_det_t)); - /* H5T_NATIVE_FLOAT */ /* Get the type's characteristics */ - DETECT_F(float, FLOAT, float_det); + memset(&det, 0, sizeof(H5T_fpoint_det_t)); + DETECT_F(float, FLOAT, det); /* Allocate and fill type structure */ if (NULL == (dt = H5T__alloc())) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") dt->shared->state = H5T_STATE_IMMUTABLE; dt->shared->type = H5T_FLOAT; - dt->shared->size = float_det.size; - dt->shared->u.atomic.order = H5T_ORDER_LE; /* HERE */ - dt->shared->u.atomic.offset = float_det.offset; - dt->shared->u.atomic.prec = float_det.precision; + dt->shared->size = det.size; + dt->shared->u.atomic.order = det.order; + dt->shared->u.atomic.offset = det.offset; + dt->shared->u.atomic.prec = det.prec; dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO; dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO; - dt->shared->u.atomic.u.f.sign = float_det.sign; - dt->shared->u.atomic.u.f.epos = float_det.epos; - dt->shared->u.atomic.u.f.esize = float_det.esize; - dt->shared->u.atomic.u.f.ebias = 0x0000007f; /* HERE */ - dt->shared->u.atomic.u.f.mpos = float_det.mpos; - dt->shared->u.atomic.u.f.msize = float_det.msize; - dt->shared->u.atomic.u.f.norm = H5T_NORM_IMPLIED; /* HERE */ + dt->shared->u.atomic.u.f.sign = det.sign; + dt->shared->u.atomic.u.f.epos = det.epos; + dt->shared->u.atomic.u.f.esize = det.esize; + dt->shared->u.atomic.u.f.ebias = det.ebias; + dt->shared->u.atomic.u.f.mpos = det.mpos; + dt->shared->u.atomic.u.f.msize = det.msize; + dt->shared->u.atomic.u.f.norm = det.norm; dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; /* Register the type and set global variables */ if ((H5T_NATIVE_FLOAT_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") - H5T_NATIVE_FLOAT_ALIGN_g = float_det.comp_align; + H5T_NATIVE_FLOAT_ALIGN_g = det.comp_align; /* H5T_NATIVE_DOUBLE */ /* Get the type's characteristics */ - DETECT_F(double, DOUBLE, double_det); + memset(&det, 0, sizeof(H5T_fpoint_det_t)); + DETECT_F(double, DOUBLE, det); /* Allocate and fill type structure */ if (NULL == (dt = H5T__alloc())) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") dt->shared->state = H5T_STATE_IMMUTABLE; dt->shared->type = H5T_FLOAT; - dt->shared->size = double_det.size; - dt->shared->u.atomic.order = H5T_ORDER_LE; - dt->shared->u.atomic.offset = double_det.offset; - dt->shared->u.atomic.prec = double_det.precision; + dt->shared->size = det.size; + dt->shared->u.atomic.order = det.order; + dt->shared->u.atomic.offset = det.offset; + dt->shared->u.atomic.prec = det.prec; dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO; dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO; - dt->shared->u.atomic.u.f.sign = double_det.sign; - dt->shared->u.atomic.u.f.epos = double_det.epos; - dt->shared->u.atomic.u.f.esize = double_det.esize; - dt->shared->u.atomic.u.f.ebias = 0x000003ff; - dt->shared->u.atomic.u.f.mpos = double_det.mpos; - dt->shared->u.atomic.u.f.msize = double_det.msize; - dt->shared->u.atomic.u.f.norm = H5T_NORM_IMPLIED; + dt->shared->u.atomic.u.f.sign = det.sign; + dt->shared->u.atomic.u.f.epos = det.epos; + dt->shared->u.atomic.u.f.esize = det.esize; + dt->shared->u.atomic.u.f.ebias = det.ebias; + dt->shared->u.atomic.u.f.mpos = det.mpos; + dt->shared->u.atomic.u.f.msize = det.msize; + dt->shared->u.atomic.u.f.norm = det.norm; dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; /* Register the type and set global variables */ if ((H5T_NATIVE_DOUBLE_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") - H5T_NATIVE_DOUBLE_ALIGN_g = double_det.comp_align; + H5T_NATIVE_DOUBLE_ALIGN_g = det.comp_align; /* H5T_NATIVE_LDOUBLE */ /* Get the type's characteristics */ - DETECT_F(long double, LDOUBLE, long_double_det); + memset(&det, 0, sizeof(H5T_fpoint_det_t)); + DETECT_F(long double, LDOUBLE, det); /* Allocate and fill type structure */ if (NULL == (dt = H5T__alloc())) HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, "datatype allocation failed") dt->shared->state = H5T_STATE_IMMUTABLE; dt->shared->type = H5T_FLOAT; - dt->shared->size = long_double_det.size; - dt->shared->u.atomic.order = H5T_ORDER_LE; - dt->shared->u.atomic.offset = long_double_det.offset; - dt->shared->u.atomic.prec = long_double_det.precision; + dt->shared->size = det.size; + dt->shared->u.atomic.order = det.order; + dt->shared->u.atomic.offset = det.offset; + dt->shared->u.atomic.prec = det.prec; dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO; dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO; - dt->shared->u.atomic.u.f.sign = long_double_det.sign; - dt->shared->u.atomic.u.f.epos = long_double_det.epos; - dt->shared->u.atomic.u.f.esize = long_double_det.esize; - dt->shared->u.atomic.u.f.ebias = 0x00003fff; - dt->shared->u.atomic.u.f.mpos = long_double_det.mpos; - dt->shared->u.atomic.u.f.msize = long_double_det.msize; - dt->shared->u.atomic.u.f.norm = H5T_NORM_NONE; + dt->shared->u.atomic.u.f.sign = det.sign; + dt->shared->u.atomic.u.f.epos = det.epos; + dt->shared->u.atomic.u.f.esize = det.esize; + dt->shared->u.atomic.u.f.ebias = det.ebias; + dt->shared->u.atomic.u.f.mpos = det.mpos; + dt->shared->u.atomic.u.f.msize = det.msize; + dt->shared->u.atomic.u.f.norm = det.norm; dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO; /* Register the type and set global variables */ if ((H5T_NATIVE_LDOUBLE_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "can't register ID for built-in datatype") - H5T_NATIVE_LDOUBLE_ALIGN_g = long_double_det.comp_align; + H5T_NATIVE_LDOUBLE_ALIGN_g = det.comp_align; - /* Set the platform's alignment */ - H5T_native_order_g = H5T_ORDER_LE; + /* Set the platform's alignment (assumes long double's order + * is true for all types) + */ + H5T_native_order_g = det.order; done: if (ret_value < 0) { From 55cde0ed808add3b70d1cb7950b60ae75ed72ee3 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 11:05:51 -0700 Subject: [PATCH 06/23] Removed H5detect.c --- src/H5detect.c | 904 ------------------------------------------------- 1 file changed, 904 deletions(-) delete mode 100644 src/H5detect.c diff --git a/src/H5detect.c b/src/H5detect.c deleted file mode 100644 index 8fb3887334f..00000000000 --- a/src/H5detect.c +++ /dev/null @@ -1,904 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* Keep this declaration near the top of this file */ -static const char *FileHeader = "\n\ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\ - * Copyright by The HDF Group. *\n\ - * All rights reserved. *\n\ - * *\n\ - * This file is part of HDF5. The full HDF5 copyright notice, including *\n\ - * terms governing use, modification, and redistribution, is contained in *\n\ - * the COPYING file, which can be found at the root of the source code *\n\ - * distribution tree, or in https://www.hdfgroup.org/licenses. *\n\ - * If you do not have access to either file, you may request a copy from *\n\ - * help@hdfgroup.org. *\n\ - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"; -/* - * Purpose: This code was borrowed heavily from the `detect.c' - * program in the AIO distribution from Lawrence - * Livermore National Laboratory. - * - * Detects machine byte order and floating point - * format and generates a C source file (H5Tinit.c) - * to describe those parameters. - * - * Assumptions: We have an ANSI compiler. We're on a Unix like - * system or configure has detected those Unix - * features which aren't available. We're not - * running on a Vax or other machine with mixed - * endianness. - *------------------------------------------------------------------------- - */ -#undef NDEBUG -#include "H5private.h" -#include "H5Tpublic.h" -#include "H5Rpublic.h" - -#if defined(__has_attribute) -#if __has_attribute(no_sanitize) -#define HDF_NO_UBSAN __attribute__((no_sanitize("undefined"))) -#else -#define HDF_NO_UBSAN -#endif -#else -#define HDF_NO_UBSAN -#endif - -#define MAXDETECT 64 - -/* This structure holds information about a type that was detected */ -typedef struct detected_t { - const char *varname; - unsigned int size; /* total byte size */ - unsigned int precision; /* meaningful bits */ - unsigned int offset; /* bit offset to meaningful bits */ - int perm[32]; /* for detection of byte order */ - hbool_t is_vax; /* for vax (float & double) only */ - unsigned int sign; /* location of sign bit */ - unsigned int mpos, msize, imp; /* information about mantissa */ - unsigned int epos, esize; /* information about exponent */ - unsigned long bias; /* exponent bias for floating pt */ - unsigned int comp_align; /* alignment for structure */ -} detected_t; - -FILE *rawoutstream = NULL; - -/* Global variables types detection code */ -H5_GCC_DIAG_OFF("larger-than=") -static detected_t d_g[MAXDETECT]; -H5_GCC_DIAG_ON("larger-than=") -static volatile int nd_g = 0; - -static void print_results(int nd, detected_t *d); -static void iprint(detected_t *); -static int byte_cmp(int, const void *, const void *, const unsigned char *); -static unsigned int bit_cmp(unsigned int, int *, void *, void *, const unsigned char *); -static void fix_order(int, int, int *, const char **); -static unsigned int imp_bit(unsigned int, int *, void *, void *, const unsigned char *); -static unsigned int find_bias(unsigned int, unsigned int, int *, void *); -static void precision(detected_t *); -static void print_header(void); -static void detect_C89_floats(void); -static void detect_C99_floats(void); - -/*------------------------------------------------------------------------- - * Function: precision - * - * Purpose: Determine the precision and offset - * - * Return: void - *------------------------------------------------------------------------- - */ -static void -precision(detected_t *d) -{ - /* A floating point */ - d->offset = MIN3(d->mpos, d->epos, d->sign); - d->precision = d->msize + d->esize + 1; -} - -/*------------------------------------------------------------------------- - * Function: DETECT_F - * - * Purpose: This macro takes a floating point type like `double' and - * a base name like `natd' and detects byte order, mantissa - * location, exponent location, sign bit location, presence or - * absence of implicit mantissa bit, and exponent bias and - * initializes a detected_t structure with those properties. - *------------------------------------------------------------------------- - */ -#define DETECT_F(TYPE, VAR, INFO) \ - { \ - TYPE _v1, _v2, _v3; \ - unsigned char _buf1[sizeof(TYPE)], _buf3[sizeof(TYPE)]; \ - unsigned char _pad_mask[sizeof(TYPE)]; \ - unsigned char _byte_mask; \ - int _i, _j, _last = (-1); \ - const char *_mesg; \ - \ - memset(&INFO, 0, sizeof(INFO)); \ - INFO.varname = #VAR; \ - INFO.size = sizeof(TYPE); \ - \ - /* Initialize padding mask */ \ - memset(_pad_mask, 0, sizeof(_pad_mask)); \ - \ - /* Padding bits. Set a variable to 4.0, then flip each bit and see if \ - * the modified variable is equal ("==") to the original. Build a \ - * padding bitmask to indicate which bits in the type are padding (i.e. \ - * have no effect on the value and should be ignored by subsequent \ - * steps). This is necessary because padding bits can change arbitrarily \ - * and interfere with detection of the various properties below unless we \ - * know to ignore them. */ \ - _v1 = (TYPE)4.0L; \ - memcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \ - for (_i = 0; _i < (int)sizeof(TYPE); _i++) \ - for (_byte_mask = (unsigned char)1; _byte_mask; _byte_mask = (unsigned char)(_byte_mask << 1)) { \ - _buf1[_i] ^= _byte_mask; \ - memcpy((void *)&_v2, (const void *)_buf1, sizeof(TYPE)); \ - H5_GCC_CLANG_DIAG_OFF("float-equal") \ - if (_v1 != _v2) \ - _pad_mask[_i] |= _byte_mask; \ - H5_GCC_CLANG_DIAG_ON("float-equal") \ - _buf1[_i] ^= _byte_mask; \ - } \ - \ - /* Byte Order */ \ - for (_i = 0, _v1 = (TYPE)0.0L, _v2 = (TYPE)1.0L; _i < (int)sizeof(TYPE); _i++) { \ - _v3 = _v1; \ - _v1 += _v2; \ - _v2 /= (TYPE)256.0L; \ - memcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \ - memcpy(_buf3, (const void *)&_v3, sizeof(TYPE)); \ - _j = byte_cmp(sizeof(TYPE), _buf3, _buf1, _pad_mask); \ - if (_j >= 0) { \ - INFO.perm[_i] = _j; \ - _last = _i; \ - } \ - } \ - fix_order(sizeof(TYPE), _last, INFO.perm, (const char **)&_mesg); \ - \ - if (!strcmp(_mesg, "VAX")) \ - INFO.is_vax = TRUE; \ - \ - /* Implicit mantissa bit */ \ - _v1 = (TYPE)0.5L; \ - _v2 = (TYPE)1.0L; \ - INFO.imp = imp_bit(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ - \ - /* Sign bit */ \ - _v1 = (TYPE)1.0L; \ - _v2 = (TYPE)-1.0L; \ - INFO.sign = bit_cmp(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ - \ - /* Mantissa */ \ - INFO.mpos = 0; \ - \ - _v1 = (TYPE)1.0L; \ - _v2 = (TYPE)1.5L; \ - INFO.msize = bit_cmp(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ - INFO.msize += 1 + (unsigned int)(INFO.imp ? 0 : 1) - INFO.mpos; \ - \ - /* Exponent */ \ - INFO.epos = INFO.mpos + INFO.msize; \ - \ - INFO.esize = INFO.sign - INFO.epos; \ - \ - _v1 = (TYPE)1.0L; \ - INFO.bias = find_bias(INFO.epos, INFO.esize, INFO.perm, &_v1); \ - precision(&(INFO)); \ - if (!strcmp(INFO.varname, "FLOAT") || !strcmp(INFO.varname, "DOUBLE") || \ - !strcmp(INFO.varname, "LDOUBLE")) { \ - COMP_ALIGNMENT(TYPE, INFO.comp_align); \ - } \ - } - -/* Detect alignment for C structure */ -#define COMP_ALIGNMENT(TYPE, COMP_ALIGN) \ - { \ - struct { \ - char c; \ - TYPE x; \ - } s; \ - \ - COMP_ALIGN = (unsigned int)((char *)(&(s.x)) - (char *)(&s)); \ - } - -/*------------------------------------------------------------------------- - * Function: print_results - * - * Purpose: Prints information about the detected data types. - * - * Return: void - *------------------------------------------------------------------------- - */ -static void -print_results(int nd, detected_t *d) -{ - int byte_order = 0; /* byte order of data types */ - int i, j; - - /* Include files */ - fprintf(rawoutstream, "\ -/****************/\n\ -/* Module Setup */\n\ -/****************/\n\ -\n\ -#include \"H5Tmodule.h\" /* This source code file is part of the H5T module */\n\ -\n\ -\n\ -/***********/\n\ -/* Headers */\n\ -/***********/\n\ -#include \"H5private.h\" /* Generic Functions */\n\ -#include \"H5Eprivate.h\" /* Error handling */\n\ -#include \"H5FLprivate.h\" /* Free Lists */\n\ -#include \"H5Iprivate.h\" /* IDs */\n\ -#include \"H5Tpkg.h\" /* Datatypes */\n\ -\n\ -\n\ -/****************/\n\ -/* Local Macros */\n\ -/****************/\n\ -\n\ -\n\ -/******************/\n\ -/* Local Typedefs */\n\ -/******************/\n\ -\n\ -\n\ -/********************/\n\ -/* Package Typedefs */\n\ -/********************/\n\ -\n\ -\n\ -/********************/\n\ -/* Local Prototypes */\n\ -/********************/\n\ -\n\ -\n\ -/********************/\n\ -/* Public Variables */\n\ -/********************/\n\ -\n\ -\n\ -/*****************************/\n\ -/* Library Private Variables */\n\ -/*****************************/\n\ -\n\ -\n\ -/*********************/\n\ -/* Package Variables */\n\ -/*********************/\n\ -\n\ -\n"); - fprintf(rawoutstream, "\n\ -/*******************/\n\ -/* Local Variables */\n\ -/*******************/\n\ -\n"); - - /* The interface initialization function */ - fprintf(rawoutstream, "\n\ -\n\ -/*-------------------------------------------------------------------------\n\ - * Function: H5T__init_native\n\ - *\n\ - * Purpose: Initialize pre-defined native datatypes from code generated\n\ - * during the library configuration by H5detect\n\ - *\n\ - * Return: Success: non-negative\n\ - * Failure: negative\n\ - *-------------------------------------------------------------------------\n\ - */\n\ -herr_t\n\ -H5T__init_native(void)\n\ -{\n\ - H5T_t *dt = NULL;\n\ - herr_t ret_value = SUCCEED;\n\ -\n\ - FUNC_ENTER_PACKAGE\n"); - - for (i = 0; i < nd; i++) { - /* The native endianness of this machine */ - /* The INFO.perm now contains `-1' for bytes that aren't used and - * are always zero. This happens on the Cray for `short' where - * sizeof(short) is 8, but only the low-order 4 bytes are ever used. - */ - if (d[i].is_vax) /* The type is a VAX floating number */ - byte_order = -1; - else { - for (j = 0; j < 32; j++) { - /* Find the 1st containing valid data */ - if (d[i].perm[j] > -1) { - byte_order = d[i].perm[j]; - break; - } - } - } - - /* Print a comment to describe this section of definitions. */ - fprintf(rawoutstream, "\n /*\n"); - iprint(d + i); - fprintf(rawoutstream, " */\n"); - - /* The part common to fixed and floating types */ - fprintf(rawoutstream, "\ - if(NULL == (dt = H5T__alloc()))\n\ - HGOTO_ERROR(H5E_DATATYPE, H5E_NOSPACE, FAIL, \"datatype allocation failed\")\n\ - dt->shared->state = H5T_STATE_IMMUTABLE;\n\ - dt->shared->type = H5T_FLOAT;\n\ - dt->shared->size = %d;\n", - d[i].size); /* Size */ - - if (byte_order == -1) - fprintf(rawoutstream, "\ - dt->shared->u.atomic.order = H5T_ORDER_VAX;\n"); - else if (byte_order == 0) - fprintf(rawoutstream, "\ - dt->shared->u.atomic.order = H5T_ORDER_LE;\n"); - else - fprintf(rawoutstream, "\ - dt->shared->u.atomic.order = H5T_ORDER_BE;\n"); - - fprintf(rawoutstream, "\ - dt->shared->u.atomic.offset = %d;\n\ - dt->shared->u.atomic.prec = %d;\n\ - dt->shared->u.atomic.lsb_pad = H5T_PAD_ZERO;\n\ - dt->shared->u.atomic.msb_pad = H5T_PAD_ZERO;\n", - d[i].offset, /* Offset */ - d[i].precision); /* Precision */ - - /* The part unique to floating point types */ - fprintf(rawoutstream, "\ - dt->shared->u.atomic.u.f.sign = %d;\n\ - dt->shared->u.atomic.u.f.epos = %d;\n\ - dt->shared->u.atomic.u.f.esize = %d;\n\ - dt->shared->u.atomic.u.f.ebias = 0x%08lx;\n\ - dt->shared->u.atomic.u.f.mpos = %d;\n\ - dt->shared->u.atomic.u.f.msize = %d;\n\ - dt->shared->u.atomic.u.f.norm = H5T_NORM_%s;\n\ - dt->shared->u.atomic.u.f.pad = H5T_PAD_ZERO;\n", - d[i].sign, /* Sign location */ - d[i].epos, /* Exponent loc */ - d[i].esize, /* Exponent size */ - (unsigned long)(d[i].bias), /* Exponent bias */ - d[i].mpos, /* Mantissa loc */ - d[i].msize, /* Mantissa size */ - d[i].imp ? "IMPLIED" : "NONE"); /* Normalization */ - - /* Register the type */ - fprintf(rawoutstream, "\ - if((H5T_NATIVE_%s_g = H5I_register(H5I_DATATYPE, dt, FALSE)) < 0)\n\ - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, \"can't register ID for built-in datatype\")\n", - d[i].varname); - - /* Variables for alignment of compound datatype */ - if (!strcmp(d[i].varname, "SCHAR") || !strcmp(d[i].varname, "SHORT") || - !strcmp(d[i].varname, "INT") || !strcmp(d[i].varname, "LONG") || !strcmp(d[i].varname, "LLONG") || - !strcmp(d[i].varname, "FLOAT") || !strcmp(d[i].varname, "DOUBLE") || - !strcmp(d[i].varname, "LDOUBLE")) { - fprintf(rawoutstream, " H5T_NATIVE_%s_ALIGN_g = %lu;\n", d[i].varname, - (unsigned long)(d[i].comp_align)); - } - } - - /* Consider VAX a little-endian machine */ - if (byte_order == 0 || byte_order == -1) { - fprintf(rawoutstream, "\n\ - /* Set the native order for this machine */\n\ - H5T_native_order_g = H5T_ORDER_%s;\n", - "LE"); - } - else { - fprintf(rawoutstream, "\n\ - /* Set the native order for this machine */\n\ - H5T_native_order_g = H5T_ORDER_%s;\n", - "BE"); - } - - fprintf(rawoutstream, "\ -\n\ -done:\n\ - if(ret_value < 0) {\n\ - if(dt != NULL) {\n\ - dt->shared = H5FL_FREE(H5T_shared_t, dt->shared);\n\ - dt = H5FL_FREE(H5T_t, dt);\n\ - }\n\ - }\n\ -\n\ - FUNC_LEAVE_NOAPI(ret_value);\n} /* end H5T__init_native() */\n"); - -} /* end print_results() */ - -/*------------------------------------------------------------------------- - * Function: iprint - * - * Purpose: Prints information about the fields of a floating point format - * - * Return: void - *------------------------------------------------------------------------- - */ -static void -iprint(detected_t *d) -{ - unsigned int pass; - - for (pass = (d->size - 1) / 4;; --pass) { - unsigned int i, k; - - /* Print the byte ordering above the bit fields */ - fprintf(rawoutstream, " * "); - for (i = MIN(pass * 4 + 3, d->size - 1); i >= pass * 4; --i) { - fprintf(rawoutstream, "%4d", d->perm[i]); - if (i > pass * 4) - fputs(" ", rawoutstream); - if (!i) - break; - } - - /* Print the bit fields */ - fprintf(rawoutstream, "\n * "); - for (i = MIN(pass * 4 + 3, d->size - 1), k = MIN(pass * 32 + 31, 8 * d->size - 1); i >= pass * 4; - --i) { - unsigned int j; - - for (j = 8; j > 0; --j) { - if (k == d->sign) { - fputc('S', rawoutstream); - } - else if (k >= d->epos && k < d->epos + d->esize) { - fputc('E', rawoutstream); - } - else if (k >= d->mpos && k < d->mpos + d->msize) { - fputc('M', rawoutstream); - } - else { - fputc('?', rawoutstream); /* Unknown floating point bit */ - } - --k; - } - if (i > pass * 4) - fputc(' ', rawoutstream); - if (!i) - break; - } - fputc('\n', rawoutstream); - if (!pass) - break; - } - - /* Is there an implicit bit in the mantissa? */ - fprintf(rawoutstream, " * Implicit bit? %s\n", d->imp ? "yes" : "no"); -} - -/*------------------------------------------------------------------------- - * Function: byte_cmp - * - * Purpose: Compares two chunks of memory A and B and returns the - * byte index into those arrays of the first byte that - * differs between A and B. Ignores differences where the - * corresponding bit in pad_mask is set to 0. - * - * Return: Success: Index of differing byte. - * Failure: -1 if all bytes are the same. - *------------------------------------------------------------------------- - */ -static int -byte_cmp(int n, const void *_a, const void *_b, const unsigned char *pad_mask) -{ - int i; - const unsigned char *a = (const unsigned char *)_a; - const unsigned char *b = (const unsigned char *)_b; - - for (i = 0; i < n; i++) - if ((a[i] & pad_mask[i]) != (b[i] & pad_mask[i])) - return i; - - return -1; -} - -/*------------------------------------------------------------------------- - * Function: bit_cmp - * - * Purpose: Compares two bit vectors and returns the index for the - * first bit that differs between the two vectors. The - * size of the vector is NBYTES. PERM is a mapping from - * actual order to little endian. Ignores differences where - * the corresponding bit in pad_mask is set to 0. - * - * Return: Index of first differing bit. - *------------------------------------------------------------------------- - */ -static unsigned int -bit_cmp(unsigned int nbytes, int *perm, void *_a, void *_b, const unsigned char *pad_mask) -{ - unsigned int i; - unsigned char *a = (unsigned char *)_a; - unsigned char *b = (unsigned char *)_b; - unsigned char aa, bb; - - for (i = 0; i < nbytes; i++) { - assert(perm[i] < (int)nbytes); - if ((aa = (unsigned char)(a[perm[i]] & pad_mask[perm[i]])) != - (bb = (unsigned char)(b[perm[i]] & pad_mask[perm[i]]))) { - unsigned int j; - - for (j = 0; j < 8; j++, aa >>= 1, bb >>= 1) { - if ((aa & 1) != (bb & 1)) - return i * 8 + j; - } - fprintf(stderr, "INTERNAL ERROR"); - abort(); - } - } - fprintf(stderr, "INTERNAL ERROR"); - abort(); - return 0; -} - -/*------------------------------------------------------------------------- - * Function: fix_order - * - * Purpose: Given an array PERM with elements FIRST through LAST - * initialized with zero origin byte numbers, this function - * creates a permutation vector that maps the actual order - * of a floating point number to little-endian. - * - * This function assumes that the mantissa byte ordering - * implies the total ordering. - * - * Return: void - *------------------------------------------------------------------------- - */ -static void -fix_order(int n, int last, int *perm, const char **mesg) -{ - int i; - - if (last > 1) { - - /* We have at least three points to consider */ - if (perm[last] < perm[last - 1] && perm[last - 1] < perm[last - 2]) { - /* Little endian */ - if (mesg) - *mesg = "Little-endian"; - for (i = 0; i < n; i++) - perm[i] = i; - } - else if (perm[last] > perm[last - 1] && perm[last - 1] > perm[last - 2]) { - /* Big endian */ - if (mesg) - *mesg = "Big-endian"; - for (i = 0; i < n; i++) - perm[i] = (n - 1) - i; - } - else { - /* Bi-endian machines like VAX - * (NOTE: This is not an actual determination of the VAX-endianness. - * It could have some other endianness and fall into this case. - */ - assert(0 == n % 2); - if (mesg) - *mesg = "VAX"; - for (i = 0; i < n; i += 2) { - perm[i] = (n - 2) - i; - perm[i + 1] = (n - 1) - i; - } - } - } - else { - fprintf(stderr, "Failed to detect byte order of %d-byte floating point.\n", n); - exit(EXIT_FAILURE); - } -} - -/*------------------------------------------------------------------------- - * Function: imp_bit - * - * Purpose: Looks for an implicit bit in the mantissa. The value - * of _A should be 1.0 and the value of _B should be 0.5. - * Some floating-point formats discard the most significant - * bit of the mantissa after normalizing since it will always - * be a one (except for 0.0). If this is true for the native - * floating point values stored in _A and _B then the function - * returns non-zero. - * - * This function assumes that the exponent occupies higher - * order bits than the mantissa and that the most significant - * bit of the mantissa is next to the least significant bit - * of the exponent. - * - * - * Return: Success: Non-zero if the most significant bit - * of the mantissa is discarded (ie, the - * mantissa has an implicit `one' as the - * most significant bit). Otherwise, - * returns zero. - * - * Failure: 1 - *------------------------------------------------------------------------- - */ -static unsigned int -imp_bit(unsigned int n, int *perm, void *_a, void *_b, const unsigned char *pad_mask) -{ - unsigned char *a = (unsigned char *)_a; - unsigned char *b = (unsigned char *)_b; - unsigned int changed, major, minor; - unsigned int msmb; /* Most significant mantissa bit */ - - /* Look for the least significant bit that has changed between - * A and B. This is the least significant bit of the exponent. - */ - changed = bit_cmp(n, perm, a, b, pad_mask); - - /* The bit to the right (less significant) of the changed bit should - * be the most significant bit of the mantissa. If it is non-zero - * then the format does not remove the leading `1' of the mantissa. - */ - msmb = changed - 1; - major = msmb / 8; - minor = msmb % 8; - - return (a[perm[major]] >> minor) & 0x01 ? 0 : 1; -} - -/*------------------------------------------------------------------------- - * Function: find_bias - * - * Purpose: Determines the bias of the exponent. This function should - * be called with _A having a value of `1'. - * - * Return: The exponent bias - *------------------------------------------------------------------------- - */ -H5_ATTR_PURE static unsigned int -find_bias(unsigned int epos, unsigned int esize, int *perm, void *_a) -{ - unsigned char *a = (unsigned char *)_a; - unsigned char mask; - unsigned int b, shift = 0, nbits, bias = 0; - - while (esize > 0) { - nbits = MIN(esize, (8 - epos % 8)); - mask = (unsigned char)((1 << nbits) - 1); - b = (unsigned int)(a[perm[epos / 8]] >> (epos % 8)) & mask; - bias |= b << shift; - - shift += nbits; - esize -= nbits; - epos += nbits; - } - return bias; -} - -/*------------------------------------------------------------------------- - * Function: print_header - * - * Purpose: Prints the C file header for the generated file. - * - * Return: void - *------------------------------------------------------------------------- - */ -static void -print_header(void) -{ - time_t now = time(NULL); - struct tm *tm = localtime(&now); - char real_name[30]; - char host_name[256]; - int i; - const char *s; -#ifdef H5_HAVE_GETPWUID - struct passwd *pwd = NULL; -#else - int pwd = 1; -#endif - static const char *month_name[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - static const char *purpose = "\ -This machine-generated source code contains\n\ -information about the various integer and\n\ -floating point numeric formats found on this\n\ -architecture. The parameters below should be\n\ -checked carefully and errors reported to the\n\ -HDF5 maintainer.\n\ -\n\ -Each of the numeric formats listed below are\n\ -printed from most significant bit to least\n\ -significant bit even though the actual bytes\n\ -might be stored in a different order in\n\ -memory. The integers above each binary byte\n\ -indicate the relative order of the bytes in\n\ -memory; little-endian machines have\n\ -decreasing numbers while big-endian machines\n\ -have increasing numbers.\n\ -\n\ -The fields of the numbers are printed as\n\ -letters with `S' for the mantissa sign bit,\n\ -`M' for the mantissa magnitude, and `E' for\n\ -the exponent. The exponent has an associated\n\ -bias which can be subtracted to find the\n\ -true exponent. The radix point is assumed\n\ -to be before the first `M' bit. Any bit\n\ -of a floating-point value not falling into one\n\ -of these categories is printed as a question\n\ -mark. Bits of integer types are printed as\n\ -`I' for 2's complement and `U' for magnitude.\n\ -\n\ -If the most significant bit of the normalized\n\ -mantissa (always a `1' except for `0.0') is\n\ -not stored then an `implicit=yes' appears\n\ -under the field description. In this case,\n\ -the radix point is still assumed to be\n\ -before the first `M' but after the implicit\n\ -bit.\n"; - - /* The real name is the first item from the passwd gecos field */ -#ifdef H5_HAVE_GETPWUID - { - size_t n; - char *comma; - if ((pwd = getpwuid(getuid()))) { - if ((comma = strchr(pwd->pw_gecos, ','))) { - n = MIN(sizeof(real_name) - 1, (unsigned)(comma - pwd->pw_gecos)); - strncpy(real_name, pwd->pw_gecos, n); - real_name[n] = '\0'; - } - else { - strncpy(real_name, pwd->pw_gecos, sizeof(real_name)); - real_name[sizeof(real_name) - 1] = '\0'; - } - } - else - real_name[0] = '\0'; - } -#else - real_name[0] = '\0'; -#endif - - /* The FQDM of this host or the empty string */ -#ifdef H5_HAVE_GETHOSTNAME - if (gethostname(host_name, sizeof(host_name)) < 0) { - host_name[0] = '\0'; - } -#else - host_name[0] = '\0'; -#endif - - /* The file header: warning, copyright notice, build information */ - fprintf(rawoutstream, "/* Generated automatically by H5detect -- DO NOT EDIT! */\n\n\n"); - fputs(FileHeader, rawoutstream); /* The copyright notice -- see top of this file */ - - fprintf(rawoutstream, " *\n * Created:\t\t%s %2d, %4d\n", month_name[tm->tm_mon], tm->tm_mday, - 1900 + tm->tm_year); - if (pwd || real_name[0] || host_name[0]) { - fprintf(rawoutstream, " *\t\t\t"); - if (real_name[0]) - fprintf(rawoutstream, "%s <", real_name); -#ifdef H5_HAVE_GETPWUID - if (pwd) - fputs(pwd->pw_name, rawoutstream); -#endif - if (host_name[0]) - fprintf(rawoutstream, "@%s", host_name); - if (real_name[0]) - fprintf(rawoutstream, ">"); - fputc('\n', rawoutstream); - } - fprintf(rawoutstream, " *\n * Purpose:\t\t"); - for (s = purpose; *s; s++) { - fputc(*s, rawoutstream); - if ('\n' == *s && s[1]) - fprintf(rawoutstream, " *\t\t\t"); - } - - fprintf(rawoutstream, " *\n"); - fprintf(rawoutstream, " *\tDO NOT MAKE MODIFICATIONS TO THIS FILE!\n"); - fprintf(rawoutstream, " *\tIt was generated by code in `H5detect.c'.\n"); - - fprintf(rawoutstream, " *\n *"); - for (i = 0; i < 73; i++) - fputc('-', rawoutstream); - fprintf(rawoutstream, "\n */\n\n"); -} - -/*------------------------------------------------------------------------- - * Function: detect_C89_floats - * - * Purpose: Detect C89 floating point types - * - * Return: void - *------------------------------------------------------------------------- - */ -static void HDF_NO_UBSAN -detect_C89_floats(void) -{ - DETECT_F(float, FLOAT, d_g[nd_g]); - nd_g++; - DETECT_F(double, DOUBLE, d_g[nd_g]); - nd_g++; -} - -/*------------------------------------------------------------------------- - * Function: detect_C99_floats - * - * Purpose: Detect C99 floating point types - * - * Return: void - *------------------------------------------------------------------------- - */ -static void HDF_NO_UBSAN -detect_C99_floats(void) -{ -#if H5_SIZEOF_DOUBLE == H5_SIZEOF_LONG_DOUBLE - /* - * If sizeof(double)==sizeof(long double) then assume that `long double' - * isn't supported and use `double' instead. This suppresses warnings on - * some systems and `long double' is probably the same as `double' here - * anyway. - */ - DETECT_F(double, LDOUBLE, d_g[nd_g]); - nd_g++; -#else - DETECT_F(long double, LDOUBLE, d_g[nd_g]); - nd_g++; -#endif -} - -/*------------------------------------------------------------------------- - * Function: main - * - * Purpose: Main entry point - * - * Return: EXIT_SUCCESS/EXIT_FAILURE - * - *------------------------------------------------------------------------- - */ -int HDF_NO_UBSAN -main(int argc, char *argv[]) -{ - char *fname = NULL; - FILE *f; /* Temporary holding place for the stream pointer - * so that rawoutstream is changed only when succeeded */ - - if (argc > 1) - fname = argv[1]; - - /* First check if filename is string "NULL" */ - if (fname != NULL) { - if ((f = fopen(fname, "w")) != NULL) - rawoutstream = f; - } - if (!rawoutstream) - rawoutstream = stdout; - - print_header(); - - /* C89 floating point types */ - detect_C89_floats(); - - /* C99 floating point types */ - detect_C99_floats(); - - print_results(nd_g, d_g); - - if (rawoutstream && rawoutstream != stdout) { - if (fclose(rawoutstream)) - fprintf(stderr, "closing rawoutstream"); - else - rawoutstream = NULL; - } - - return EXIT_SUCCESS; -} From 71d0535163915f29a4bb4a824179f2cac4db5858 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 11:07:56 -0700 Subject: [PATCH 07/23] Format source --- src/H5Tinit_float.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/H5Tinit_float.c b/src/H5Tinit_float.c index 7ef116a6670..717ceb5a545 100644 --- a/src/H5Tinit_float.c +++ b/src/H5Tinit_float.c @@ -66,7 +66,7 @@ int _i, _j, _last = (-1); \ \ memset(&INFO, 0, sizeof(INFO)); \ - INFO.size = sizeof(TYPE); \ + INFO.size = sizeof(TYPE); \ \ /* Initialize padding mask */ \ memset(_pad_mask, 0, sizeof(_pad_mask)); \ From daaf916ff06436236926e58118e335d5b5f65a07 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 11:49:30 -0700 Subject: [PATCH 08/23] Add RELEASE.txt note --- release_docs/RELEASE.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 7153c4e8851..9482364a452 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -47,6 +47,11 @@ New Features Configuration: ------------- + - Running H5detect is no longer required for cross-compiling + + The functionality of H5detect is now exercised at library startup, + so H5detect has been removed. + - Updated HDF5 API tests CMake code to support VOL connectors * Implemented support for fetching, building and testing HDF5 From e0a91eb7b778e985ac79aded01dcffb0d5a5a276 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 14:31:31 -0700 Subject: [PATCH 09/23] Yank H5make_libsettings from Autotools * H5make_libsettings.c still exists for CMake * Works with enabled/disabled embedded library info --- configure.ac | 7 +- src/H5.c | 8 +- src/H5build_settings.autotools.c.in | 119 ++++++++++++++++++++++++++++ src/H5build_settings.off.c.in | 21 +++++ src/H5private.h | 5 +- src/Makefile.am | 15 ---- 6 files changed, 152 insertions(+), 23 deletions(-) create mode 100644 src/H5build_settings.autotools.c.in create mode 100644 src/H5build_settings.off.c.in diff --git a/configure.ac b/configure.ac index a5454350f7e..7560c680f6f 100644 --- a/configure.ac +++ b/configure.ac @@ -3893,9 +3893,11 @@ AC_ARG_ENABLE([embedded-libinfo], if test "${enable_embedded_libinfo}" = "yes"; then AC_MSG_RESULT([yes]) + BUILD_SETTINGS_FILE="src/H5build_settings.autotools.c.in" AC_DEFINE([HAVE_EMBEDDED_LIBINFO], [1], [Define if library information should be embedded in the executables]) else + BUILD_SETTINGS_FILE="src/H5build_settings.off.c.in" AC_MSG_RESULT([no]) fi @@ -4028,10 +4030,11 @@ fi ## AM_CONDITIONAL([HAVE_SHARED_CONDITIONAL], [test "X$enable_shared" = "Xyes"]) -AC_CONFIG_FILES([src/libhdf5.settings - Makefile +AC_CONFIG_FILES([Makefile doxygen/Doxyfile src/Makefile + src/libhdf5.settings + src/H5build_settings.c:${BUILD_SETTINGS_FILE} test/Makefile test/H5srcdir_str.h test/test_abort_fail.sh diff --git a/src/H5.c b/src/H5.c index e0db6b9e6a5..daaaf663042 100644 --- a/src/H5.c +++ b/src/H5.c @@ -903,8 +903,8 @@ H5check_version(unsigned majnum, unsigned minnum, unsigned relnum) /* Mention the versions we are referring to */ HDfprintf(stderr, "Headers are %u.%u.%u, library is %u.%u.%u\n", majnum, minnum, relnum, (unsigned)H5_VERS_MAJOR, (unsigned)H5_VERS_MINOR, (unsigned)H5_VERS_RELEASE); - /* Show library settings if available */ - HDfprintf(stderr, "%s", H5libhdf5_settings); + /* Show library build settings if available */ + HDfprintf(stderr, "%s", H5build_settings); /* Bail out now. */ HDfputs("Bye...\n", stderr); @@ -920,8 +920,8 @@ H5check_version(unsigned majnum, unsigned minnum, unsigned relnum) /* Mention the versions we are referring to */ HDfprintf(stderr, "Headers are %u.%u.%u, library is %u.%u.%u\n", majnum, minnum, relnum, (unsigned)H5_VERS_MAJOR, (unsigned)H5_VERS_MINOR, (unsigned)H5_VERS_RELEASE); - /* Show library settings if available */ - HDfprintf(stderr, "%s", H5libhdf5_settings); + /* Show library build settings if available */ + HDfprintf(stderr, "%s", H5build_settings); break; default: /* 2 or higher: continue silently */ diff --git a/src/H5build_settings.autotools.c.in b/src/H5build_settings.autotools.c.in new file mode 100644 index 00000000000..782a2787abc --- /dev/null +++ b/src/H5build_settings.autotools.c.in @@ -0,0 +1,119 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://www.hdfgroup.org/licenses. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "H5private.h" + +H5_GCC_DIAG_OFF("larger-than=") +H5_CLANG_DIAG_OFF("overlength-strings") + +/* clang-format off */ +const char H5build_settings[]= + " SUMMARY OF THE HDF5 CONFIGURATION\n" + " =================================\n" + "\n" + "General Information:\n" + "-------------------\n" + " HDF5 Version: @H5_VERSION@\n" + " Configured on: @CONFIG_DATE@\n" + " Configured by: @CONFIG_USER@\n" + " Host system: @host_cpu@-@host_vendor@-@host_os@\n" + " Uname information: @UNAME_INFO@\n" + " Byte sex: @BYTESEX@\n" + " Installation point: @prefix@\n" + "\n" + "Compiling Options:\n" + "------------------\n" + " Build Mode: @BUILD_MODE@\n" + " Debugging Symbols: @SYMBOLS@\n" + " Asserts: @ASSERTS@\n" + " Profiling: @PROFILING@\n" + " Optimization Level: @OPTIMIZATION@\n" + "\n" + "Linking Options:\n" + "----------------\n" + " Libraries: @STATIC_SHARED@\n" + " Statically Linked Executables: @LT_STATIC_EXEC@\n" + " LDFLAGS: @LDFLAGS@\n" + " H5_LDFLAGS: @H5_LDFLAGS@\n" + " AM_LDFLAGS: @AM_LDFLAGS@\n" + " Extra libraries: @LIBS@\n" + " Archiver: @AR@\n" + " AR_FLAGS: @AR_FLAGS@\n" + " Ranlib: @RANLIB@\n" + "\n" + "Languages:\n" + "----------\n" + " C: \n" + " C Compiler: \n" + " CPPFLAGS: \n" + " H5_CPPFLAGS: \n" + " AM_CPPFLAGS: \n" + " C Flags: \n" + " H5 C Flags: \n" + " AM C Flags: \n" + " Shared C Library: \n" + " Static C Library: \n" + "\n" + "\n" + " Fortran: @HDF_FORTRAN@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Fortran Compiler: @FC_VERSION@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Fortran Flags: @FCFLAGS@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " H5 Fortran Flags: @H5_FCFLAGS@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " AM Fortran Flags: @AM_FCFLAGS@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Shared Fortran Library: @H5_FORTRAN_SHARED@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Static Fortran Library: @enable_static@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Module Directory: @fmoddir@\n" + "\n" + " C++: @HDF_CXX@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " C++ Compiler: @CXX_VERSION@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " C++ Flags: @CXXFLAGS@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " H5 C++ Flags: @H5_CXXFLAGS@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " AM C++ Flags: @AM_CXXFLAGS@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " Shared C++ Library: @enable_shared@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " Static C++ Library: @enable_static@\n" + "\n" + " Java: @HDF_JAVA@\n" +@BUILD_JAVA_CONDITIONAL_TRUE@ " Java Compiler: @JAVA_VERSION@\n" + "\n" + "\n" + "Features:\n" + "---------\n" + " Parallel HDF5: @PARALLEL@\n" + " Parallel Filtered Dataset Writes: @PARALLEL_FILTERED_WRITES@\n" + " Large Parallel I/O: @LARGE_PARALLEL_IO@\n" + " High-level library: @HDF5_HL@\n" + "Dimension scales w/ new references: @DIMENSION_SCALES_WITH_NEW_REF@\n" + " Build HDF5 Tests: @HDF5_TESTS@\n" + " Build HDF5 Tools: @HDF5_TOOLS@\n" + " Build GIF Tools: @HDF5_HL_GIF_TOOLS@\n" + " Threadsafety: @THREADSAFE@\n" + " Default API mapping: @DEFAULT_API_VERSION@\n" + " With deprecated public symbols: @DEPRECATED_SYMBOLS@\n" + " I/O filters (external): @EXTERNAL_FILTERS@\n" + " Map (H5M) API: @MAP_API@\n" + " Direct VFD: @DIRECT_VFD@\n" + " Mirror VFD: @MIRROR_VFD@\n" + " Subfiling VFD: @SUBFILING_VFD@\n" + " (Read-Only) S3 VFD: @ROS3_VFD@\n" + " (Read-Only) HDFS VFD: @HAVE_LIBHDFS@\n" + " Packages w/ extra debug output: @INTERNAL_DEBUG_OUTPUT@\n" + " API tracing: @TRACE_API@\n" + " Using memory checker: @USINGMEMCHECKER@\n" + " Function stack tracing: @CODESTACK@\n" + " Use file locking: @DESIRED_FILE_LOCKING@\n" + " Strict file format checks: @STRICT_FORMAT_CHECKS@\n" + " Optimization instrumentation: @INSTRUMENT_LIBRARY@\n" +; +/* clang-format on */ + +H5_GCC_DIAG_ON("larger-than=") +H5_CLANG_DIAG_OFF("overlength-strings") diff --git a/src/H5build_settings.off.c.in b/src/H5build_settings.off.c.in new file mode 100644 index 00000000000..c677dd3395c --- /dev/null +++ b/src/H5build_settings.off.c.in @@ -0,0 +1,21 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://www.hdfgroup.org/licenses. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "H5private.h" + +H5_GCC_DIAG_OFF("larger-than=") +H5_CLANG_DIAG_OFF("overlength-strings") + +const char H5build_settings[]=""; + +H5_GCC_DIAG_ON("larger-than=") +H5_CLANG_DIAG_OFF("overlength-strings") diff --git a/src/H5private.h b/src/H5private.h index b138301738c..f923376f678 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1771,8 +1771,9 @@ extern hbool_t H5_coll_api_sanity_check_g; extern H5_debug_t H5_debug_g; #define H5DEBUG(X) (H5_debug_g.pkg[H5_PKG_##X].stream) -/* Do not use const else AIX strings does not show it. */ -extern char H5libhdf5_settings[]; /* embedded library information */ + +/* Embedded build information */ +extern const char H5build_settings[]; /*------------------------------------------------------------------------- * Purpose: These macros are inserted automatically just after the diff --git a/src/Makefile.am b/src/Makefile.am index 89eafc72ec3..e0d10113449 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,8 +18,6 @@ include $(top_srcdir)/config/commence.am include $(top_srcdir)/config/lt_vers.am -noinst_PROGRAMS = H5make_libsettings - # Our main target, the HDF5 library lib_LTLIBRARIES=libhdf5.la @@ -186,19 +184,6 @@ endif settingsdir=$(libdir) settings_DATA=libhdf5.settings -# Build configuration header file generation -# The LD_LIBRARY_PATH setting is a kludge. -# Things should have been all set during H5make_libsettings making. -# Remove the generated .c file if errors occur unless HDF5_Make_Ignore -# is set to ignore the error. -H5lib_settings.c: H5make_libsettings$(EXEEXT) libhdf5.settings - @if $(AM_V_P); then set -x; else echo " GEN H5lib_settings.c"; fi; \ - LD_LIBRARY_PATH="$$LD_LIBRARY_PATH`echo $(LDFLAGS) | \ - sed -e 's/-L/:/g' -e 's/ //g'`" \ - $(RUNSERIAL) ./H5make_libsettings$(EXEEXT) $@ || \ - (test $$HDF5_Make_Ignore && echo "*** Error ignored") || \ - ($(RM) $@ ; exit 1) - # Error header generation # # Actually, H5Einit.h, H5Eterm.h, H5Edefin.h and H5Epubgen.h all From bc5789acb8c8e6923fc84ba33ef79ccd6cfa2d3e Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 14:34:56 -0700 Subject: [PATCH 10/23] Remove leftover generated file cruft * KNL script to run H5detect * Filter out H5detect, etc. from bin/checkposix --- bin/batch/knl_H5detect.sl.in.cmake | 20 -------------------- bin/checkposix | 6 +----- 2 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 bin/batch/knl_H5detect.sl.in.cmake diff --git a/bin/batch/knl_H5detect.sl.in.cmake b/bin/batch/knl_H5detect.sl.in.cmake deleted file mode 100644 index 39a3ef3f623..00000000000 --- a/bin/batch/knl_H5detect.sl.in.cmake +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -#SBATCH -p knl -C quad -#SBATCH --nodes=1 -#SBATCH -t 00:10:00 -#SBATCH --mail-type=BEGIN,END,FAIL -#SBATCH --mail-user=@sandia.gov -#SBATCH --export=ALL -#SBATCH --job-name=knl_h5detect - - -# Inputs: Build directory, output file name, executable file name (username/email if available). -PROGNAME=H5detect -OUTPUT=H5Tinit.c - -CMD="@HDF5_BINARY_DIR@/bin/${PROGNAME} @HDF5_GENERATED_SOURCE_DIR@/${OUTPUT}" -echo "Run $CMD" -srun -n 1 $CMD -echo "Done running $CMD" - diff --git a/bin/checkposix b/bin/checkposix index bb6b81bae7d..4daa0e0b34a 100755 --- a/bin/checkposix +++ b/bin/checkposix @@ -37,17 +37,13 @@ foreach $arg (@ARGV) { # Skip files that don't include H5private.h # H5system. has to be inspected by hand since it wraps POSIX files # - # H5detect and H5make_libsettings are created before the library exists - # so calls that link to function replacements won't work. We'll ignore - # it here. - # # If a user specifies one file, process it no matter what so people # can inspect files we normally skip (like H5system.c). $ignore = 0; # Ignored files in src/ - if($#ARGV gt 0 and $filename =~ /H5FDmulti|H5FDstdio|H5VLpassthru|H5system|H5detect|H5make_libsettings/) { + if($#ARGV gt 0 and $filename =~ /H5FDmulti|H5FDstdio|H5VLpassthru|H5system/) { $ignore = 1; } # Ignored atomic test files in test/ From 5eaf6abb674603a2392501a04a0bbca1a1e9bdab Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 15:08:12 -0700 Subject: [PATCH 11/23] Add missing fields to CMake libsettings file --- config/cmake/libhdf5.settings.cmake.in | 2 + src/H5build_settings.cmake.c.in | 103 +++++++++ src/H5make_libsettings.c | 300 ------------------------- 3 files changed, 105 insertions(+), 300 deletions(-) create mode 100644 src/H5build_settings.cmake.c.in delete mode 100644 src/H5make_libsettings.c diff --git a/config/cmake/libhdf5.settings.cmake.in b/config/cmake/libhdf5.settings.cmake.in index 00ae980c2b9..fdfef691c54 100644 --- a/config/cmake/libhdf5.settings.cmake.in +++ b/config/cmake/libhdf5.settings.cmake.in @@ -28,6 +28,7 @@ Linking Options: AM_LDFLAGS: @AM_LDFLAGS@ Extra libraries: @LINK_LIBS@ Archiver: @CMAKE_AR@ + AR_FLAGS: Ranlib: @CMAKE_RANLIB@ Languages: @@ -77,6 +78,7 @@ Dimension scales w/ new references: @DIMENSION_SCALES_WITH_NEW_REF@ Default API mapping: @DEFAULT_API_VERSION@ With deprecated public symbols: @HDF5_ENABLE_DEPRECATED_SYMBOLS@ I/O filters (external): @EXTERNAL_FILTERS@ + Map (H5M) API: @H5_HAVE_MAP_API@ Direct VFD: @H5_HAVE_DIRECT@ Mirror VFD: @H5_HAVE_MIRROR_VFD@ Subfiling VFD: @H5_HAVE_SUBFILING_VFD@ diff --git a/src/H5build_settings.cmake.c.in b/src/H5build_settings.cmake.c.in new file mode 100644 index 00000000000..a2ceb7d0355 --- /dev/null +++ b/src/H5build_settings.cmake.c.in @@ -0,0 +1,103 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://www.hdfgroup.org/licenses. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "H5private.h" + +H5_GCC_DIAG_OFF("larger-than=") +H5_CLANG_DIAG_OFF("overlength-strings") + +const char H5build_settings[]= + " SUMMARY OF THE HDF5 CONFIGURATION\n" + " =================================\n" + "\n" + "General Information:\n" + "-------------------\n" + " HDF5 Version: @H5_VERSION@\n" + " Configured on: @CONFIG_DATE@\n" + " Configured by: @CONFIG_USER@\n" + " Host system: @host_cpu@-@host_vendor@-@host_os@\n" + " Uname information: @UNAME_INFO@\n" + " Byte sex: @BYTESEX@\n" + " Installation point: @prefix@\n" + "\n" + "Compiling Options:\n" + "------------------\n" + " Build Mode: @BUILD_MODE@\n" + " Debugging Symbols: @SYMBOLS@\n" + " Asserts: @ASSERTS@\n" + " Profiling: @PROFILING@\n" + " Optimization Level: @OPTIMIZATION@\n" + "\n" + "Linking Options:\n" + "----------------\n" + " Libraries: \n" + " Statically Linked Executables: \n" + " LDFLAGS: \n" + " H5_LDFLAGS: \n" + " AM_LDFLAGS: \n" + " Extra libraries: \n" + " Archiver: \n" + " AR_FLAGS: \n" + " Ranlib: \n" + "\n" + "Languages:\n" + "----------\n" + " C: \n" + " C Compiler: \n" + " CPPFLAGS: \n" + " H5_CPPFLAGS: \n" + " AM_CPPFLAGS: \n" + " C Flags: \n" + " H5 C Flags: \n" + " AM C Flags: \n" + " Shared C Library: yes\n" + " Static C Library: yes\n" + "\n" + "\n" + " Fortran: no\n" + "\n" + " C++: no\n" + "\n" + " Java: no\n" + "\n" + "\n" + "Features:\n" + "---------\n" + " Parallel HDF5: no\n" + " Parallel Filtered Dataset Writes: no\n" + " Large Parallel I/O: no\n" + " High-level library: yes\n" + "Dimension scales w/ new references: no\n" + " Build HDF5 Tests: yes\n" + " Build HDF5 Tools: yes\n" + " Build GIF Tools: no\n" + " Threadsafety: no\n" + " Default API mapping: v116\n" + " With deprecated public symbols: yes\n" + " I/O filters (external): deflate(zlib)\n" + " Map (H5M) API: no\n" + " Direct VFD: no\n" + " Mirror VFD: no\n" + " Subfiling VFD: no\n" + " (Read-Only) S3 VFD: no\n" + " (Read-Only) HDFS VFD: no\n" + " Packages w/ extra debug output: AC,B2,CX,D,F,HL,I,O,S,T,Z\n" + " API tracing: yes\n" + " Using memory checker: no\n" + " Function stack tracing: no\n" + " Use file locking: best-effort\n" + " Strict file format checks: yes\n" + " Optimization instrumentation: no\n" +; + +H5_GCC_DIAG_ON("larger-than=") +H5_CLANG_DIAG_OFF("overlength-strings") diff --git a/src/H5make_libsettings.c b/src/H5make_libsettings.c deleted file mode 100644 index 88a6d7dea4b..00000000000 --- a/src/H5make_libsettings.c +++ /dev/null @@ -1,300 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* Keep this declaration near the top of this file */ -static const char *FileHeader = "\n\ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\ - * Copyright by The HDF Group. *\n\ - * All rights reserved. *\n\ - * *\n\ - * This file is part of HDF5. The full HDF5 copyright notice, including *\n\ - * terms governing use, modification, and redistribution, is contained in *\n\ - * the COPYING file, which can be found at the root of the source code *\n\ - * distribution tree, or in https://www.hdfgroup.org/licenses. *\n\ - * If you do not have access to either file, you may request a copy from *\n\ - * help@hdfgroup.org. *\n\ - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"; -/* - * Purpose: Generate the H5libsettings.c file from the - * libhdf5.settings file. - * - *------------------------------------------------------------------------- - */ - -#include "H5private.h" - -/* Do NOT use HDfprintf in this file as it is not linked with the library, - * which contains the H5system.c file in which the function is defined. - */ - -#define LIBSETTINGSFNAME "libhdf5.settings" - -FILE *rawoutstream = NULL; - -/*------------------------------------------------------------------------- - * Function: insert_libhdf5_settings - * - * Purpose: insert the contents of libhdf5.settings into a file - * represented by flibinfo. - * Make it an empty string if H5_HAVE_EMBEDDED_LIBINFO is not - * defined, i.e., not enabled. - * - * Return: void - *------------------------------------------------------------------------- - */ -static void -insert_libhdf5_settings(FILE *flibinfo) -{ -#ifdef H5_HAVE_EMBEDDED_LIBINFO - FILE *fsettings; /* for files libhdf5.settings */ - int inchar; - int bol = 0; /* indicates the beginning of a new line */ - - if (NULL == (fsettings = HDfopen(LIBSETTINGSFNAME, "r"))) { - HDperror(LIBSETTINGSFNAME); - HDexit(EXIT_FAILURE); - } - - /* Turn off warnings for large arrays. If the library info string is - * a problem, people can build without the embedded library info. - */ - HDfprintf(flibinfo, "#include \"H5private.h\"\n"); - HDfprintf(flibinfo, "H5_GCC_DIAG_OFF(\"larger-than=\")\n\n"); - HDfprintf(flibinfo, "H5_CLANG_DIAG_OFF(\"overlength-strings\")\n\n"); - - /* Print variable definition and the string. Do not use const or some - * platforms (AIX?) will have issues. - */ - HDfprintf(flibinfo, "char H5libhdf5_settings[]=\n"); - bol++; - while (EOF != (inchar = HDgetc(fsettings))) { - if (bol) { - /* Start a new line */ - HDfprintf(flibinfo, "\t\""); - bol = 0; - } - if (inchar == '\n') { - /* end of a line */ - HDfprintf(flibinfo, "\\n\"\n"); - bol++; - } - else - HDputc(inchar, flibinfo); - } - - if (HDfeof(fsettings)) { - /* wrap up */ - if (!bol) - /* EOF found without a new line */ - HDfprintf(flibinfo, "\\n\"\n"); - HDfprintf(flibinfo, ";\n\n"); - } - else { - HDfprintf(stderr, "Read errors encountered with %s\n", LIBSETTINGSFNAME); - HDexit(EXIT_FAILURE); - } - if (0 != HDfclose(fsettings)) { - HDperror(LIBSETTINGSFNAME); - HDexit(EXIT_FAILURE); - } - - /* Re-enable warnings for large arrays */ - HDfprintf(rawoutstream, "H5_GCC_DIAG_ON(\"larger-than=\")\n"); - HDfprintf(rawoutstream, "H5_CLANG_DIAG_OFF(\"overlength-strings\")\n"); -#else - /* Print variable definition and an empty string. Do not use const or some - * platforms (AIX?) will have issues. - */ - HDfprintf(flibinfo, "char H5libhdf5_settings[]=\"\";\n"); -#endif -} /* insert_libhdf5_settings() */ - -/*------------------------------------------------------------------------- - * Function: make_libinfo - * - * Purpose: Create the embedded library information definition. - * This sets up for a potential extension that the declaration - * is printed to a file different from stdout. - * - * Return: void - *------------------------------------------------------------------------- - */ -static void -make_libinfo(void) -{ - /* Print variable definition and then the string as a macro */ - insert_libhdf5_settings(rawoutstream); -} - -/*------------------------------------------------------------------------- - * Function: print_header - * - * Purpose: Prints the header for the generated file. - * - * Return: void - *------------------------------------------------------------------------- - */ -static void -print_header(void) -{ - time_t now = HDtime(NULL); - struct tm *tm = HDlocaltime(&now); - char real_name[30]; - char host_name[256]; - int i; - const char *s; -#ifdef H5_HAVE_GETPWUID - struct passwd *pwd = NULL; -#else - int pwd = 1; -#endif - static const char *month_name[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - static const char *purpose = "\ -This machine-generated source code contains\n\ -information about the library build configuration\n"; - - /* - * The real name is the first item from the passwd gecos field. - */ -#ifdef H5_HAVE_GETPWUID - { - size_t n; - char *comma; - - if ((pwd = HDgetpwuid(HDgetuid()))) { - if ((comma = HDstrchr(pwd->pw_gecos, ','))) { - n = MIN(sizeof(real_name) - 1, (unsigned)(comma - pwd->pw_gecos)); - HDstrncpy(real_name, pwd->pw_gecos, n); - real_name[n] = '\0'; - } - else { - HDstrncpy(real_name, pwd->pw_gecos, sizeof(real_name)); - real_name[sizeof(real_name) - 1] = '\0'; - } - } - else - real_name[0] = '\0'; - } -#else - real_name[0] = '\0'; -#endif - - /* - * The FQDM of this host or the empty string. - */ -#ifdef H5_HAVE_GETHOSTNAME - if (HDgethostname(host_name, sizeof(host_name)) < 0) - host_name[0] = '\0'; -#else - host_name[0] = '\0'; -#endif - - /* - * The file header: warning, copyright notice, build information. - */ - HDfprintf(rawoutstream, "/* Generated automatically by H5make_libsettings -- do not edit */\n\n\n"); - HDfputs(FileHeader, rawoutstream); /*the copyright notice--see top of this file */ - - HDfprintf(rawoutstream, " *\n * Created:\t\t%s %2d, %4d\n", month_name[tm->tm_mon], tm->tm_mday, - 1900 + tm->tm_year); - if (pwd || real_name[0] || host_name[0]) { - HDfprintf(rawoutstream, " *\t\t\t"); - if (real_name[0]) - HDfprintf(rawoutstream, "%s <", real_name); -#ifdef H5_HAVE_GETPWUID - if (pwd) - HDfputs(pwd->pw_name, rawoutstream); -#endif - if (host_name[0]) - HDfprintf(rawoutstream, "@%s", host_name); - if (real_name[0]) - HDfprintf(rawoutstream, ">"); - HDfputc('\n', rawoutstream); - } - - HDfprintf(rawoutstream, " *\n * Purpose:\t\t"); - - for (s = purpose; *s; s++) { - HDfputc(*s, rawoutstream); - if ('\n' == *s && s[1]) - HDfprintf(rawoutstream, " *\t\t\t"); - } - - HDfprintf(rawoutstream, " *\n"); - HDfprintf(rawoutstream, " *\tDO NOT MAKE MODIFICATIONS TO THIS FILE!\n"); - HDfprintf(rawoutstream, " *\tIt was generated by code in `H5make_libsettings.c'.\n"); - - HDfprintf(rawoutstream, " *\n *"); - for (i = 0; i < 73; i++) - HDfputc('-', rawoutstream); - HDfprintf(rawoutstream, "\n */\n\n"); -} - -/*------------------------------------------------------------------------- - * Function: print_footer - * - * Purpose: Prints the file footer for the generated file. - * - * Return: void - *------------------------------------------------------------------------- - */ -static void -print_footer(void) -{ - /* nothing */ -} - -/*------------------------------------------------------------------------- - * Function: main - * - * Purpose: Main entry point. - * - * Return: Success: EXIT_SUCCESS - *------------------------------------------------------------------------- - */ -int -main(int argc, char *argv[]) -{ - char *fname = NULL; - FILE *f; /* temporary holding place for the stream pointer - * so that rawoutstream is changed only when succeeded - */ - - if (argc > 1) - fname = argv[1]; - - /* First check if filename is string "NULL" */ - if (fname != NULL) { - /* binary output */ - if ((f = HDfopen(fname, "w")) != NULL) - rawoutstream = f; - } - if (!rawoutstream) - rawoutstream = stdout; - - print_header(); - - /* Generate embedded library information variable definition */ - make_libinfo(); - - print_footer(); - - if (rawoutstream && rawoutstream != stdout) { - if (HDfclose(rawoutstream)) - HDfprintf(stderr, "closing rawoutstream"); - else - rawoutstream = NULL; - } - - HDexit(EXIT_SUCCESS); -} From d59515b46dedfe96d8d7f0a4d1f57239c6f2a903 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 15:08:57 -0700 Subject: [PATCH 12/23] Add missing Autotools content from past commit --- src/CMakeLists.txt | 130 +------------------- src/H5build_settings.autotools.c.in | 20 ++-- src/H5build_settings.cmake.c.in | 176 +++++++++++++++------------- src/Makefile.am | 8 +- 4 files changed, 109 insertions(+), 225 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c53ad6da5d..133bc2179ef 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ project (HDF5_SRC C) #----------------------------------------------------------------------------- set (H5_SOURCES ${HDF5_SRC_DIR}/H5.c + ${HDF5_SRC_DIR}/H5build_settings.c ${HDF5_SRC_DIR}/H5checksum.c ${HDF5_SRC_DIR}/H5dbg.c ${HDF5_SRC_DIR}/H5mpi.c @@ -1078,135 +1079,6 @@ if (LOCAL_BATCH_TEST) endif () endif () -# make the H5make_libsettings program -add_executable (H5make_libsettings ${HDF5_SRC_DIR}/H5make_libsettings.c) -target_include_directories (H5make_libsettings PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") -target_compile_definitions(H5make_libsettings PUBLIC ${HDF_EXTRA_C_FLAGS} ${HDF_EXTRA_FLAGS}) -TARGET_C_PROPERTIES (H5make_libsettings STATIC) -target_link_libraries (H5make_libsettings - PRIVATE "$<$:MPI::MPI_C>" $<$,$>:ws2_32.lib> -) -target_compile_options(H5make_libsettings - PRIVATE "$<$:-O0>" -) -set (lib_prog_deps ${lib_prog_deps} H5make_libsettings) - -#----------------------------------------------------------------------------- -# Add Target to clang-format -#----------------------------------------------------------------------------- -if (HDF5_ENABLE_FORMATTERS) - clang_format (HDF5_SRC_LIBSETTINGS_FORMAT H5make_libsettings) -endif () - -# execute the H5make_libsettings program -add_custom_command ( - OUTPUT gen_SRCS.stamp2 - BYPRODUCTS H5lib_settings.c - COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $ - ARGS H5lib_settings.c - COMMAND ${CMAKE_COMMAND} - ARGS -E touch gen_SRCS.stamp2 - DEPENDS H5make_libsettings - WORKING_DIRECTORY ${HDF5_SRC_BINARY_DIR} - COMMENT "Create H5lib_settings.c" -) -set_source_files_properties (${HDF5_SRC_BINARY_DIR}/H5lib_settings.c PROPERTIES GENERATED TRUE) -if (BUILD_SHARED_LIBS) - add_custom_command ( - OUTPUT shared/shared_gen_SRCS.stamp2 - BYPRODUCTS shared/H5lib_settings.c - COMMAND ${CMAKE_COMMAND} - ARGS -E copy_if_different H5lib_settings.c shared/H5lib_settings.c - COMMAND ${CMAKE_COMMAND} - ARGS -E touch shared/shared_gen_SRCS.stamp2 - DEPENDS H5make_libsettings gen_SRCS.stamp2 - WORKING_DIRECTORY ${HDF5_SRC_BINARY_DIR} - COMMENT "Copy H5lib_settings.c to shared folder" - ) -endif () - -#----------------------------------------------------------------------------- -# Add generated source to build -#----------------------------------------------------------------------------- -if (BUILD_STATIC_LIBS) - set (gen_SRCS ${HDF5_SRC_BINARY_DIR}/H5lib_settings.c) - add_custom_target (gen_${HDF5_LIB_TARGET} ALL - DEPENDS ${lib_prog_deps} ${HDF5_SRC_BINARY_DIR}/gen_SRCS.stamp2 - COMMENT "Generation target files" - ) - - add_library (${HDF5_LIB_TARGET} STATIC ${common_SRCS} ${gen_SRCS} ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS} ${H5_GENERATED_HEADERS} ${H5_MODULE_HEADERS}) - target_include_directories (${HDF5_LIB_TARGET} - PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>" - INTERFACE "$/include>;$" - ) - target_compile_options(${HDF5_LIB_TARGET} PRIVATE "${HDF5_CMAKE_C_FLAGS}") - target_compile_definitions(${HDF5_LIB_TARGET} - PUBLIC - ${HDF_EXTRA_C_FLAGS} - ${HDF_EXTRA_FLAGS} - PRIVATE - "$<$:H5_DEBUG_API>" # Enable tracing of the API - "$<$:${HDF5_DEBUG_APIS}>" - "$<$:${HDF5_DEVELOPER_DEFS}>" - ) - TARGET_C_PROPERTIES (${HDF5_LIB_TARGET} STATIC) - target_link_libraries (${HDF5_LIB_TARGET} - PRIVATE ${LINK_LIBS} ${LINK_COMP_LIBS} - PUBLIC "$<$>:${CMAKE_DL_LIBS}>" "$<$:MPI::MPI_C>" - ) - if (NOT WIN32) - target_link_libraries (${HDF5_LIB_TARGET} - PRIVATE "$<$,$>:Threads::Threads>" - ) - endif () - set_global_variable (HDF5_LIBRARIES_TO_EXPORT ${HDF5_LIB_TARGET}) - H5_SET_LIB_OPTIONS (${HDF5_LIB_TARGET} ${HDF5_LIB_NAME} STATIC 0) - set_target_properties (${HDF5_LIB_TARGET} PROPERTIES FOLDER libraries) - add_dependencies (${HDF5_LIB_TARGET} gen_${HDF5_LIB_TARGET}) - - set (install_targets ${HDF5_LIB_TARGET}) -endif () - -if (BUILD_SHARED_LIBS) - set (shared_gen_SRCS ${HDF5_SRC_BINARY_DIR}/shared/H5lib_settings.c) - add_custom_target (gen_${HDF5_LIBSH_TARGET} ALL - DEPENDS ${lib_prog_deps} ${HDF5_SRC_BINARY_DIR}/shared/shared_gen_SRCS.stamp2 - COMMENT "Shared generation target files" - ) - - add_library (${HDF5_LIBSH_TARGET} SHARED ${common_SRCS} ${shared_gen_SRCS} ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS} ${H5_GENERATED_HEADERS} ${H5_MODULE_HEADERS}) - target_include_directories (${HDF5_LIBSH_TARGET} - PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>" - PUBLIC "$<$:${HDFS_INCLUDE_DIR}>" - INTERFACE "$/include>;$" - ) - target_compile_options(${HDF5_LIBSH_TARGET} PRIVATE "${HDF5_CMAKE_C_FLAGS}") - target_compile_definitions(${HDF5_LIBSH_TARGET} - PUBLIC - "H5_BUILT_AS_DYNAMIC_LIB" - ${HDF_EXTRA_C_FLAGS} - ${HDF_EXTRA_FLAGS} - PRIVATE - "$<$:H5_HAVE_THREADSAFE>" - "$<$:H5_DEBUG_API>" # Enable tracing of the API - "$<$:${HDF5_DEBUG_APIS}>" - "$<$:${HDF5_DEVELOPER_DEFS}>" - ) - TARGET_C_PROPERTIES (${HDF5_LIBSH_TARGET} SHARED) - target_link_libraries (${HDF5_LIBSH_TARGET} - PRIVATE ${LINK_LIBS} ${LINK_COMP_LIBS} - "$<$,$>:Threads::Threads>" - PUBLIC "$<$>:${CMAKE_DL_LIBS}>" "$<$:MPI::MPI_C>" - ) - set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_LIBSH_TARGET}") - H5_SET_LIB_OPTIONS (${HDF5_LIBSH_TARGET} ${HDF5_LIB_NAME} SHARED "LIB") - set_target_properties (${HDF5_LIBSH_TARGET} PROPERTIES FOLDER libraries) - add_dependencies (${HDF5_LIBSH_TARGET} gen_${HDF5_LIBSH_TARGET}) - - set (install_targets ${install_targets} ${HDF5_LIBSH_TARGET}) -endif () - #----------------------------------------------------------------------------- # Add Target to clang-format #----------------------------------------------------------------------------- diff --git a/src/H5build_settings.autotools.c.in b/src/H5build_settings.autotools.c.in index 782a2787abc..497588763d2 100644 --- a/src/H5build_settings.autotools.c.in +++ b/src/H5build_settings.autotools.c.in @@ -52,16 +52,16 @@ const char H5build_settings[]= "\n" "Languages:\n" "----------\n" - " C: \n" - " C Compiler: \n" - " CPPFLAGS: \n" - " H5_CPPFLAGS: \n" - " AM_CPPFLAGS: \n" - " C Flags: \n" - " H5 C Flags: \n" - " AM C Flags: \n" - " Shared C Library: \n" - " Static C Library: \n" + " C: yes\n" + " C Compiler: @CC_VERSION@\n" + " CPPFLAGS: @CPPFLAGS@\n" + " H5_CPPFLAGS: @H5_CPPFLAGS@\n" + " AM_CPPFLAGS: @AM_CPPFLAGS@\n" + " C Flags: @CFLAGS@\n" + " H5 C Flags: @H5_CFLAGS@\n" + " AM C Flags: @AM_CFLAGS@\n" + " Shared C Library: @enable_shared@\n" + " Static C Library: @enable_static@\n" "\n" "\n" " Fortran: @HDF_FORTRAN@\n" diff --git a/src/H5build_settings.cmake.c.in b/src/H5build_settings.cmake.c.in index a2ceb7d0355..2893d902923 100644 --- a/src/H5build_settings.cmake.c.in +++ b/src/H5build_settings.cmake.c.in @@ -16,87 +16,101 @@ H5_GCC_DIAG_OFF("larger-than=") H5_CLANG_DIAG_OFF("overlength-strings") const char H5build_settings[]= - " SUMMARY OF THE HDF5 CONFIGURATION\n" - " =================================\n" - "\n" - "General Information:\n" - "-------------------\n" - " HDF5 Version: @H5_VERSION@\n" - " Configured on: @CONFIG_DATE@\n" - " Configured by: @CONFIG_USER@\n" - " Host system: @host_cpu@-@host_vendor@-@host_os@\n" - " Uname information: @UNAME_INFO@\n" - " Byte sex: @BYTESEX@\n" - " Installation point: @prefix@\n" - "\n" - "Compiling Options:\n" - "------------------\n" - " Build Mode: @BUILD_MODE@\n" - " Debugging Symbols: @SYMBOLS@\n" - " Asserts: @ASSERTS@\n" - " Profiling: @PROFILING@\n" - " Optimization Level: @OPTIMIZATION@\n" - "\n" - "Linking Options:\n" - "----------------\n" - " Libraries: \n" - " Statically Linked Executables: \n" - " LDFLAGS: \n" - " H5_LDFLAGS: \n" - " AM_LDFLAGS: \n" - " Extra libraries: \n" - " Archiver: \n" - " AR_FLAGS: \n" - " Ranlib: \n" - "\n" - "Languages:\n" - "----------\n" - " C: \n" - " C Compiler: \n" - " CPPFLAGS: \n" - " H5_CPPFLAGS: \n" - " AM_CPPFLAGS: \n" - " C Flags: \n" - " H5 C Flags: \n" - " AM C Flags: \n" - " Shared C Library: yes\n" - " Static C Library: yes\n" - "\n" - "\n" - " Fortran: no\n" - "\n" - " C++: no\n" - "\n" - " Java: no\n" - "\n" - "\n" - "Features:\n" - "---------\n" - " Parallel HDF5: no\n" - " Parallel Filtered Dataset Writes: no\n" - " Large Parallel I/O: no\n" - " High-level library: yes\n" - "Dimension scales w/ new references: no\n" - " Build HDF5 Tests: yes\n" - " Build HDF5 Tools: yes\n" - " Build GIF Tools: no\n" - " Threadsafety: no\n" - " Default API mapping: v116\n" - " With deprecated public symbols: yes\n" - " I/O filters (external): deflate(zlib)\n" - " Map (H5M) API: no\n" - " Direct VFD: no\n" - " Mirror VFD: no\n" - " Subfiling VFD: no\n" - " (Read-Only) S3 VFD: no\n" - " (Read-Only) HDFS VFD: no\n" - " Packages w/ extra debug output: AC,B2,CX,D,F,HL,I,O,S,T,Z\n" - " API tracing: yes\n" - " Using memory checker: no\n" - " Function stack tracing: no\n" - " Use file locking: best-effort\n" - " Strict file format checks: yes\n" - " Optimization instrumentation: no\n" + " SUMMARY OF THE HDF5 CONFIGURATION\n" + " =================================\n" + "\n" + "General Information:\n" + "-------------------\n" + " HDF5 Version: @HDF5_PACKAGE_VERSION_STRING@\n" + " Configured on: @CONFIG_DATE@\n" + " Configured by: @CMAKE_GENERATOR@\n" + " Host system: @CMAKE_HOST_SYSTEM@\n" + " Uname information: @CMAKE_SYSTEM_NAME@\n" + " Byte sex: @BYTESEX@\n" + " Installation point: @CMAKE_INSTALL_PREFIX@\n" + "\n" + "Compiling Options:\n" + "------------------\n" + " Build Mode: @HDF_CFG_NAME@\n" + " Debugging Symbols: @HDF5_ENABLE_SYMBOLS@\n" + " Asserts: @HDF5_ENABLE_ASSERTS@\n" + " Profiling: @HDF5_ENABLE_PROFILING@\n" + " Optimization Level: @HDF5_ENABLE_OPTIMIZATION@\n" + "\n" + "Linking Options:\n" + "----------------\n" + " Libraries: @BUILD_NAME_EXT@\n" + " Statically Linked Executables: @BUILD_STATIC_EXECS@\n" + " LDFLAGS: @CMAKE_SHARED_LINKER_FLAGS@\n" + " H5_LDFLAGS: @H5_LDFLAGS@\n" + " AM_LDFLAGS: @AM_LDFLAGS@\n" + " Extra libraries: @LINK_LIBS@\n" + " Archiver: @CMAKE_AR@\n" + " AR_FLAGS: \n" + " Ranlib: @CMAKE_RANLIB@\n" + "\n" + "Languages:\n" + "----------\n" + " C: YES\n" + " C Compiler: @CMAKE_C_COMPILER@ @CMAKE_C_COMPILER_VERSION@\n" + " CPPFLAGS: @CPPFLAGS@\n" + " H5_CPPFLAGS: @H5_CPPFLAGS@\n" + " AM_CPPFLAGS: @AM_CPPFLAGS@\n" + " C Flags: @CMAKE_C_FLAGS@\n" + " H5 C Flags: @HDF5_CMAKE_C_FLAGS@\n" + " AM C Flags: @AM_CFLAGS@\n" + " Shared C Library: @H5_ENABLE_SHARED_LIB@\n" + " Static C Library: @H5_ENABLE_STATIC_LIB@\n" + "\n" + "\n" + " Fortran: @HDF5_BUILD_FORTRAN@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Fortran Compiler: @CMAKE_Fortran_COMPILER@ @CMAKE_Fortran_COMPILER_VERSION@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Fortran Flags: @CMAKE_Fortran_FLAGS@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " H5 Fortran Flags: @HDF5_CMAKE_Fortran_FLAGS@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " AM Fortran Flags: @AM_FCFLAGS@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Shared Fortran Library: @H5_ENABLE_SHARED_LIB@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Static Fortran Library: @H5_ENABLE_STATIC_LIB@\n" +@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Module Directory: @CMAKE_Fortran_MODULE_DIRECTORY@\n" + "\n" + " C++: @HDF5_BUILD_CPP_LIB@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " C++ Compiler: @CMAKE_CXX_COMPILER@ @CMAKE_CXX_COMPILER_VERSION@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " C++ Flags: @CMAKE_CXX_FLAGS@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " H5 C++ Flags: @HDF5_CMAKE_CXX_FLAGS@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " AM C++ Flags: @AM_CXXFLAGS@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " Shared C++ Library: @H5_ENABLE_SHARED_LIB@\n" +@BUILD_CXX_CONDITIONAL_TRUE@ " Static C++ Library: @H5_ENABLE_STATIC_LIB@\n" + "\n" + " Java: @HDF5_BUILD_JAVA@\n" +@BUILD_JAVA_CONDITIONAL_TRUE@ " Java Compiler: @CMAKE_Java_COMPILER@ @Java_VERSION@\n" + "\n" + "\n" + "Features:\n" + "---------\n" + " Parallel HDF5: @HDF5_ENABLE_PARALLEL@\n" + " Parallel Filtered Dataset Writes: @PARALLEL_FILTERED_WRITES@\n" + " Large Parallel I/O: @LARGE_PARALLEL_IO@\n" + " High-level library: @HDF5_BUILD_HL_LIB@\n" + "Dimension scales w/ new references: @DIMENSION_SCALES_WITH_NEW_REF@\n" + " Build HDF5 Tests: @BUILD_TESTING@\n" + " Build HDF5 Tools: @HDF5_BUILD_TOOLS@\n" + " Build GIF Tools: @HDF5_BUILD_HL_GIF_TOOLS@\n" + " Threadsafety: @HDF5_ENABLE_THREADSAFE@\n" + " Default API mapping: @DEFAULT_API_VERSION@\n" + " With deprecated public symbols: @HDF5_ENABLE_DEPRECATED_SYMBOLS@\n" + " I/O filters (external): @EXTERNAL_FILTERS@\n" + " Map (H5M) API: @H5_HAVE_MAP_API@\n" + " Direct VFD: @H5_HAVE_DIRECT@\n" + " Mirror VFD: @H5_HAVE_MIRROR_VFD@\n" + " Subfiling VFD: @H5_HAVE_SUBFILING_VFD@\n" + " (Read-Only) S3 VFD: @H5_HAVE_ROS3_VFD@\n" + " (Read-Only) HDFS VFD: @H5_HAVE_LIBHDFS@\n" + " Packages w/ extra debug output: @INTERNAL_DEBUG_OUTPUT@\n" + " API tracing: @HDF5_ENABLE_TRACE@\n" + " Using memory checker: @HDF5_ENABLE_USING_MEMCHECKER@\n" + " Function stack tracing: @HDF5_ENABLE_CODESTACK@\n" + " Use file locking: @HDF5_FILE_LOCKING_SETTING@\n" + " Strict file format checks: @HDF5_STRICT_FORMAT_CHECKS@\n" + " Optimization instrumentation: @HDF5_Enable_Instrument@\n" ; H5_GCC_DIAG_ON("larger-than=") diff --git a/src/Makefile.am b/src/Makefile.am index e0d10113449..e92a71c96b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,13 +24,11 @@ lib_LTLIBRARIES=libhdf5.la # Add libtool numbers to the HDF5 library (from config/lt_vers.am) libhdf5_la_LDFLAGS= -version-info $(LT_VERS_INTERFACE):$(LT_VERS_REVISION):$(LT_VERS_AGE) $(AM_LDFLAGS) -# H5lib_settings.c is a generated file and should be cleaned. -MOSTLYCLEANFILES=H5lib_settings.c $(DX_CLEANFILES) -# H5pubconf.h is generated by configure, and should be cleaned. -DISTCLEANFILES=H5pubconf.h +# These files are generated by configure, and should be cleaned +DISTCLEANFILES=H5pubconf.h H5build_settings.c # library sources -libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5lib_settings.c H5system.c \ +libhdf5_la_SOURCES= H5.c H5build_settings.c H5checksum.c H5dbg.c H5system.c \ H5timer.c H5trace.c \ H5A.c H5Abtree2.c H5Adense.c H5Adeprec.c H5Aint.c H5Atest.c \ H5AC.c H5ACdbg.c H5ACproxy_entry.c \ From 51ca096b8989e7545ca45641c620dc4e003c6ef0 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 15:38:52 -0700 Subject: [PATCH 13/23] CMake works --- CMakeLists.txt | 5 +++ src/CMakeLists.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0801e0fa704..0136dd38124 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1224,6 +1224,11 @@ endif () #----------------------------------------------------------------------------- configure_file (${HDF_RESOURCES_DIR}/H5pubconf.h.in ${HDF5_SRC_BINARY_DIR}/H5pubconf.h @ONLY) +#----------------------------------------------------------------------------- +# Generate the H5build_settings.c file +#----------------------------------------------------------------------------- +configure_file (${HDF5_SOURCE_DIR}/src/H5build_settings.cmake.c.in ${HDF5_SRC_BINARY_DIR}/H5build_settings.c @ONLY) + #----------------------------------------------------------------------------- # Options for use by cross compiling and toolchains #----------------------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 133bc2179ef..3595b2640d0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,7 @@ project (HDF5_SRC C) #----------------------------------------------------------------------------- set (H5_SOURCES ${HDF5_SRC_DIR}/H5.c - ${HDF5_SRC_DIR}/H5build_settings.c + ${HDF5_SRC_BINARY_DIR}/H5build_settings.c ${HDF5_SRC_DIR}/H5checksum.c ${HDF5_SRC_DIR}/H5dbg.c ${HDF5_SRC_DIR}/H5mpi.c @@ -1079,6 +1079,88 @@ if (LOCAL_BATCH_TEST) endif () endif () +#----------------------------------------------------------------------------- +# Set up library builds +#----------------------------------------------------------------------------- +if (BUILD_STATIC_LIBS) + set (gen_SRCS ${HDF5_SRC_BINARY_DIR}/H5build_settings.c) + add_custom_target (gen_${HDF5_LIB_TARGET} ALL + DEPENDS ${lib_prog_deps} + COMMENT "Generation target files" + ) + + add_library (${HDF5_LIB_TARGET} STATIC ${common_SRCS} ${gen_SRCS} ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS} ${H5_GENERATED_HEADERS} ${H5_MODULE_HEADERS}) + target_include_directories (${HDF5_LIB_TARGET} + PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>" + INTERFACE "$/include>;$" + ) + target_compile_options(${HDF5_LIB_TARGET} PRIVATE "${HDF5_CMAKE_C_FLAGS}") + target_compile_definitions(${HDF5_LIB_TARGET} + PUBLIC + ${HDF_EXTRA_C_FLAGS} + ${HDF_EXTRA_FLAGS} + PRIVATE + "$<$:H5_DEBUG_API>" # Enable tracing of the API + "$<$:${HDF5_DEBUG_APIS}>" + "$<$:${HDF5_DEVELOPER_DEFS}>" + ) + TARGET_C_PROPERTIES (${HDF5_LIB_TARGET} STATIC) + target_link_libraries (${HDF5_LIB_TARGET} + PRIVATE ${LINK_LIBS} ${LINK_COMP_LIBS} + PUBLIC "$<$>:${CMAKE_DL_LIBS}>" "$<$:MPI::MPI_C>" + ) + if (NOT WIN32) + target_link_libraries (${HDF5_LIB_TARGET} + PRIVATE "$<$,$>:Threads::Threads>" + ) + endif () + set_global_variable (HDF5_LIBRARIES_TO_EXPORT ${HDF5_LIB_TARGET}) + H5_SET_LIB_OPTIONS (${HDF5_LIB_TARGET} ${HDF5_LIB_NAME} STATIC 0) + set_target_properties (${HDF5_LIB_TARGET} PROPERTIES FOLDER libraries) + add_dependencies (${HDF5_LIB_TARGET} gen_${HDF5_LIB_TARGET}) + + set (install_targets ${HDF5_LIB_TARGET}) +endif () + +if (BUILD_SHARED_LIBS) + set (shared_gen_SRCS ${HDF5_SRC_BINARY_DIR}/H5build_settings.c) + add_custom_target (gen_${HDF5_LIBSH_TARGET} ALL + DEPENDS ${lib_prog_deps} + COMMENT "Shared generation target files" + ) + + add_library (${HDF5_LIBSH_TARGET} SHARED ${common_SRCS} ${shared_gen_SRCS} ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS} ${H5_GENERATED_HEADERS} ${H5_MODULE_HEADERS}) + target_include_directories (${HDF5_LIBSH_TARGET} + PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>" + PUBLIC "$<$:${HDFS_INCLUDE_DIR}>" + INTERFACE "$/include>;$" + ) + target_compile_options(${HDF5_LIBSH_TARGET} PRIVATE "${HDF5_CMAKE_C_FLAGS}") + target_compile_definitions(${HDF5_LIBSH_TARGET} + PUBLIC + "H5_BUILT_AS_DYNAMIC_LIB" + ${HDF_EXTRA_C_FLAGS} + ${HDF_EXTRA_FLAGS} + PRIVATE + "$<$:H5_HAVE_THREADSAFE>" + "$<$:H5_DEBUG_API>" # Enable tracing of the API + "$<$:${HDF5_DEBUG_APIS}>" + "$<$:${HDF5_DEVELOPER_DEFS}>" + ) + TARGET_C_PROPERTIES (${HDF5_LIBSH_TARGET} SHARED) + target_link_libraries (${HDF5_LIBSH_TARGET} + PRIVATE ${LINK_LIBS} ${LINK_COMP_LIBS} + "$<$,$>:Threads::Threads>" + PUBLIC "$<$>:${CMAKE_DL_LIBS}>" "$<$:MPI::MPI_C>" + ) + set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_LIBSH_TARGET}") + H5_SET_LIB_OPTIONS (${HDF5_LIBSH_TARGET} ${HDF5_LIB_NAME} SHARED "LIB") + set_target_properties (${HDF5_LIBSH_TARGET} PROPERTIES FOLDER libraries) + add_dependencies (${HDF5_LIBSH_TARGET} gen_${HDF5_LIBSH_TARGET}) + + set (install_targets ${install_targets} ${HDF5_LIBSH_TARGET}) +endif () + #----------------------------------------------------------------------------- # Add Target to clang-format #----------------------------------------------------------------------------- @@ -1226,7 +1308,7 @@ if (DOXYGEN_FOUND) # Replace variables inside @@ with the current values add_custom_target (hdf5lib_doc ALL COMMAND ${DOXYGEN_EXECUTABLE} ${HDF5_BINARY_DIR}/Doxyfile - DEPENDS ${HDF5_SRC_BINARY_DIR}/H5lib_settings.c + DEPENDS ${HDF5_SRC_BINARY_DIR}/H5build_settings.c WORKING_DIRECTORY ${HDF5_SRC_DIR} COMMENT "Generating HDF5 library Source API documentation with Doxygen" VERBATIM ) From 197084975b9293c415d8447deacebd30b6f778dc Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 15:40:01 -0700 Subject: [PATCH 14/23] Added a release note about H5make_libsettings --- release_docs/RELEASE.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 9482364a452..72d205f76ef 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -47,6 +47,11 @@ New Features Configuration: ------------- + - Running H5make_libsettings is no longer required for cross-compiling + + The functionality of H5make_libsettings is now handled via template files, + so H5make_libsettings has been removed. + - Running H5detect is no longer required for cross-compiling The functionality of H5detect is now exercised at library startup, From 9876338b4883634f665ff3f6ca1d3642db1856b8 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 15:52:26 -0700 Subject: [PATCH 15/23] Removed unused CMake cross-compile variables --- CMakeLists.txt | 6 ------ release_docs/INSTALL_CMake.txt | 9 --------- release_docs/README_HPC | 19 ------------------- release_docs/RELEASE.txt | 8 ++++++++ src/CMakeLists.txt | 6 +----- 5 files changed, 9 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0136dd38124..17a4c39d5f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1229,10 +1229,4 @@ configure_file (${HDF_RESOURCES_DIR}/H5pubconf.h.in ${HDF5_SRC_BINARY_DIR}/H5pub #----------------------------------------------------------------------------- configure_file (${HDF5_SOURCE_DIR}/src/H5build_settings.cmake.c.in ${HDF5_SRC_BINARY_DIR}/H5build_settings.c @ONLY) -#----------------------------------------------------------------------------- -# Options for use by cross compiling and toolchains -#----------------------------------------------------------------------------- -option (HDF5_USE_PREGEN "Use pre-generated Files" OFF) -option (HDF5_BATCH_H5DETECT "Use a batch command for running h5detect" OFF) - include (CMakeInstallation.cmake) diff --git a/release_docs/INSTALL_CMake.txt b/release_docs/INSTALL_CMake.txt index 1ec7615b16c..6816b1a7ec2 100644 --- a/release_docs/INSTALL_CMake.txt +++ b/release_docs/INSTALL_CMake.txt @@ -1031,15 +1031,6 @@ References: https://stackoverflow.com/questions/54539682/how-to-set-up-cmake-to-cross-compile-with-clang-for-arm-embedded-on-windows?rq=1 https://developer.android.com/ndk/guides/cmake -Predefine H5Tinit.c file -------------------------------- -The one file that needs to be pre-generated is the H5Tinit.c file. The variables -indicated in the error log (see above) are the variables that need to match the target system. - -The HDF5 CMake variables; - HDF5_USE_PREGEN: set this to true - HDF5_USE_PREGEN_DIR: set this path to the preset H5Tinit.c file - ======================================================================== X: Using CMakePresets.json for compiling diff --git a/release_docs/README_HPC b/release_docs/README_HPC index 27dc32ce706..576e019becf 100644 --- a/release_docs/README_HPC +++ b/release_docs/README_HPC @@ -9,7 +9,6 @@ Section II: Obtain HDF5 source Section III: Using ctest command to build and test Section IV: Cross compiling Section V: Manual alternatives -Section VI: Other cross compiling options ************************************************************************ @@ -184,21 +183,3 @@ or for parallel builds. Tests on machines using LSF will typically use "bsub ctestS.lsf", etc. - -======================================================================== -VI. Other cross compiling options -======================================================================== -Settings for two other cross-compiling options are also in the config/toolchain -files which do not seem to be necessary with the Cray PrgEnv-* modules - -1. HDF5_USE_PREGEN. This option, along with the HDF5_USE_PREGEN_DIR CMake - variable would allow the use of an appropriate H5Tinit.c file with type - information generated on a compute node to be used when cross compiling - for those compute nodes. The use of the variables in lines 110 and 111 - of HDF5options.cmake file seem to preclude needing this option with the - available Cray modules and CMake option. - -2. HDF5_BATCH_H5DETECT and associated CMake variables. This option when - properly configured will run H5detect in a batch job on a compute node - at the beginning of the CMake build process. It was also found to be - unnecessary with the available Cray modules and CMake options. diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 72d205f76ef..7bf3035859c 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -47,6 +47,14 @@ New Features Configuration: ------------- + - Removed CMake cross-compiling variables + + * HDF5_USE_PREGEN + * HDF5_BATCH_H5DETECT + + These were used to work around H5detect and H5make_libsettings and + are no longer required. + - Running H5make_libsettings is no longer required for cross-compiling The functionality of H5make_libsettings is now handled via template files, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3595b2640d0..a00ba08eb1d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1040,11 +1040,7 @@ endif () #----------------------------------------------------------------------------- # Set up source generators #----------------------------------------------------------------------------- -if (HDF5_USE_PREGEN) - set (HDF5_GENERATED_SOURCE_DIR ${HDF5_USE_PREGEN_DIR}) -else () - set (HDF5_GENERATED_SOURCE_DIR ${HDF5_SRC_BINARY_DIR}) -endif () +set (HDF5_GENERATED_SOURCE_DIR ${HDF5_SRC_BINARY_DIR}) if (BUILD_SHARED_LIBS) file (MAKE_DIRECTORY "${HDF5_SRC_BINARY_DIR}/shared") From c008c9d09737abe48752fce23f0c5eaa713105b1 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 16:29:19 -0700 Subject: [PATCH 16/23] Fix missing conditional cleanup in Autotools --- configure.ac | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 7560c680f6f..bae5bc06de6 100644 --- a/configure.ac +++ b/configure.ac @@ -81,14 +81,21 @@ AM_MAINTAINER_MODE([enable]) ## This allows multiple src-dir builds within one host. AC_PREFIX_DEFAULT([`pwd`/hdf5]) -## Run post processing on files created by configure. +## Run post processing on files created by configure +## ## src/H5pubconf.h: ## Generate src/H5pubconf.h from src/H5config.h by prepending H5_ to all ## macro names. This avoid name conflict between HDF5 macro names and those ## generated by another software package that uses the HDF5 library. +## ## src/libhdf5.settings: -## Remove all lines begun with "#" which are generated by CONDITIONAL's of -## configure. +## Remove all lines beginning with "#" which are generated by CONDITIONAL's +## of configure. +## +## src/H5build_settings.c +## Remove all lines beginning with "#" which are generated by CONDITIONAL's +## of configure. This uses a check for whitespace after the pound sign +## to avoid clobbering include statements. AC_CONFIG_COMMANDS([pubconf], [ echo "creating src/H5pubconf.h" sed 's/#define /#define H5_/' libhdf5.settings.TMP cp libhdf5.settings.TMP src/libhdf5.settings rm -f libhdf5.settings.TMP + echo "Post process src/H5build_settings.c" + sed '/^# /d' < src/H5build_settings.c > H5build_settings.TMP + cp H5build_settings.TMP src/H5build_settings.c + rm -f H5build_settings.TMP ]) ## It's possible to configure for a host other than the one on which From bf2b7c584056ddca23efa4ccb0488d02960506ce Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 16:38:05 -0700 Subject: [PATCH 17/23] Remove useless Automake conditionals from CMake --- config/cmake/libhdf5.settings.cmake.in | 30 +++++++++++++------------- src/H5build_settings.autotools.c.in | 2 +- src/H5build_settings.cmake.c.in | 28 ++++++++++++------------ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/config/cmake/libhdf5.settings.cmake.in b/config/cmake/libhdf5.settings.cmake.in index fdfef691c54..f60f0def177 100644 --- a/config/cmake/libhdf5.settings.cmake.in +++ b/config/cmake/libhdf5.settings.cmake.in @@ -45,24 +45,24 @@ Languages: Static C Library: @H5_ENABLE_STATIC_LIB@ Fortran: @HDF5_BUILD_FORTRAN@ -@BUILD_FORTRAN_CONDITIONAL_TRUE@ Fortran Compiler: @CMAKE_Fortran_COMPILER@ @CMAKE_Fortran_COMPILER_VERSION@ -@BUILD_FORTRAN_CONDITIONAL_TRUE@ Fortran Flags: @CMAKE_Fortran_FLAGS@ -@BUILD_FORTRAN_CONDITIONAL_TRUE@ H5 Fortran Flags: @HDF5_CMAKE_Fortran_FLAGS@ -@BUILD_FORTRAN_CONDITIONAL_TRUE@ AM Fortran Flags: @AM_FCFLAGS@ -@BUILD_FORTRAN_CONDITIONAL_TRUE@ Shared Fortran Library: @H5_ENABLE_SHARED_LIB@ -@BUILD_FORTRAN_CONDITIONAL_TRUE@ Static Fortran Library: @H5_ENABLE_STATIC_LIB@ -@BUILD_FORTRAN_CONDITIONAL_TRUE@ Module Directory: @CMAKE_Fortran_MODULE_DIRECTORY@ + Fortran Compiler: @CMAKE_Fortran_COMPILER@ @CMAKE_Fortran_COMPILER_VERSION@ + Fortran Flags: @CMAKE_Fortran_FLAGS@ + H5 Fortran Flags: @HDF5_CMAKE_Fortran_FLAGS@ + AM Fortran Flags: @AM_FCFLAGS@ + Shared Fortran Library: @H5_ENABLE_SHARED_LIB@ + Static Fortran Library: @H5_ENABLE_STATIC_LIB@ + Module Directory: @CMAKE_Fortran_MODULE_DIRECTORY@ C++: @HDF5_BUILD_CPP_LIB@ -@BUILD_CXX_CONDITIONAL_TRUE@ C++ Compiler: @CMAKE_CXX_COMPILER@ @CMAKE_CXX_COMPILER_VERSION@ -@BUILD_CXX_CONDITIONAL_TRUE@ C++ Flags: @CMAKE_CXX_FLAGS@ -@BUILD_CXX_CONDITIONAL_TRUE@ H5 C++ Flags: @HDF5_CMAKE_CXX_FLAGS@ -@BUILD_CXX_CONDITIONAL_TRUE@ AM C++ Flags: @AM_CXXFLAGS@ -@BUILD_CXX_CONDITIONAL_TRUE@ Shared C++ Library: @H5_ENABLE_SHARED_LIB@ -@BUILD_CXX_CONDITIONAL_TRUE@ Static C++ Library: @H5_ENABLE_STATIC_LIB@ + C++ Compiler: @CMAKE_CXX_COMPILER@ @CMAKE_CXX_COMPILER_VERSION@ + C++ Flags: @CMAKE_CXX_FLAGS@ + H5 C++ Flags: @HDF5_CMAKE_CXX_FLAGS@ + AM C++ Flags: @AM_CXXFLAGS@ + Shared C++ Library: @H5_ENABLE_SHARED_LIB@ + Static C++ Library: @H5_ENABLE_STATIC_LIB@ - JAVA: @HDF5_BUILD_JAVA@ -@BUILD_JAVA_CONDITIONAL_TRUE@ JAVA Compiler: @CMAKE_Java_COMPILER@ @Java_VERSION@ + JAVA: @HDF5_BUILD_JAVA@ + JAVA Compiler: @CMAKE_Java_COMPILER@ @Java_VERSION@ Features: --------- diff --git a/src/H5build_settings.autotools.c.in b/src/H5build_settings.autotools.c.in index 497588763d2..3b4a5c33772 100644 --- a/src/H5build_settings.autotools.c.in +++ b/src/H5build_settings.autotools.c.in @@ -82,7 +82,7 @@ const char H5build_settings[]= @BUILD_CXX_CONDITIONAL_TRUE@ " Static C++ Library: @enable_static@\n" "\n" " Java: @HDF_JAVA@\n" -@BUILD_JAVA_CONDITIONAL_TRUE@ " Java Compiler: @JAVA_VERSION@\n" +@BUILD_JAVA_CONDITIONAL_TRUE@ " Java Compiler: @JAVA_VERSION@\n" "\n" "\n" "Features:\n" diff --git a/src/H5build_settings.cmake.c.in b/src/H5build_settings.cmake.c.in index 2893d902923..67ebec7e45d 100644 --- a/src/H5build_settings.cmake.c.in +++ b/src/H5build_settings.cmake.c.in @@ -64,24 +64,24 @@ const char H5build_settings[]= "\n" "\n" " Fortran: @HDF5_BUILD_FORTRAN@\n" -@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Fortran Compiler: @CMAKE_Fortran_COMPILER@ @CMAKE_Fortran_COMPILER_VERSION@\n" -@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Fortran Flags: @CMAKE_Fortran_FLAGS@\n" -@BUILD_FORTRAN_CONDITIONAL_TRUE@ " H5 Fortran Flags: @HDF5_CMAKE_Fortran_FLAGS@\n" -@BUILD_FORTRAN_CONDITIONAL_TRUE@ " AM Fortran Flags: @AM_FCFLAGS@\n" -@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Shared Fortran Library: @H5_ENABLE_SHARED_LIB@\n" -@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Static Fortran Library: @H5_ENABLE_STATIC_LIB@\n" -@BUILD_FORTRAN_CONDITIONAL_TRUE@ " Module Directory: @CMAKE_Fortran_MODULE_DIRECTORY@\n" + " Fortran Compiler: @CMAKE_Fortran_COMPILER@ @CMAKE_Fortran_COMPILER_VERSION@\n" + " Fortran Flags: @CMAKE_Fortran_FLAGS@\n" + " H5 Fortran Flags: @HDF5_CMAKE_Fortran_FLAGS@\n" + " AM Fortran Flags: @AM_FCFLAGS@\n" + " Shared Fortran Library: @H5_ENABLE_SHARED_LIB@\n" + " Static Fortran Library: @H5_ENABLE_STATIC_LIB@\n" + " Module Directory: @CMAKE_Fortran_MODULE_DIRECTORY@\n" "\n" " C++: @HDF5_BUILD_CPP_LIB@\n" -@BUILD_CXX_CONDITIONAL_TRUE@ " C++ Compiler: @CMAKE_CXX_COMPILER@ @CMAKE_CXX_COMPILER_VERSION@\n" -@BUILD_CXX_CONDITIONAL_TRUE@ " C++ Flags: @CMAKE_CXX_FLAGS@\n" -@BUILD_CXX_CONDITIONAL_TRUE@ " H5 C++ Flags: @HDF5_CMAKE_CXX_FLAGS@\n" -@BUILD_CXX_CONDITIONAL_TRUE@ " AM C++ Flags: @AM_CXXFLAGS@\n" -@BUILD_CXX_CONDITIONAL_TRUE@ " Shared C++ Library: @H5_ENABLE_SHARED_LIB@\n" -@BUILD_CXX_CONDITIONAL_TRUE@ " Static C++ Library: @H5_ENABLE_STATIC_LIB@\n" + " C++ Compiler: @CMAKE_CXX_COMPILER@ @CMAKE_CXX_COMPILER_VERSION@\n" + " C++ Flags: @CMAKE_CXX_FLAGS@\n" + " H5 C++ Flags: @HDF5_CMAKE_CXX_FLAGS@\n" + " AM C++ Flags: @AM_CXXFLAGS@\n" + " Shared C++ Library: @H5_ENABLE_SHARED_LIB@\n" + " Static C++ Library: @H5_ENABLE_STATIC_LIB@\n" "\n" " Java: @HDF5_BUILD_JAVA@\n" -@BUILD_JAVA_CONDITIONAL_TRUE@ " Java Compiler: @CMAKE_Java_COMPILER@ @Java_VERSION@\n" + " Java Compiler: @CMAKE_Java_COMPILER@ @Java_VERSION@\n" "\n" "\n" "Features:\n" From e3df34ae65bc5411ec6749020ef138edbd9856a5 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 11 Jun 2023 16:58:00 -0700 Subject: [PATCH 18/23] Fix incredibly fragile version test --- src/H5build_settings.autotools.c.in | 4 ++-- src/libhdf5.settings.in | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/H5build_settings.autotools.c.in b/src/H5build_settings.autotools.c.in index 3b4a5c33772..abdc53a9cd3 100644 --- a/src/H5build_settings.autotools.c.in +++ b/src/H5build_settings.autotools.c.in @@ -17,8 +17,8 @@ H5_CLANG_DIAG_OFF("overlength-strings") /* clang-format off */ const char H5build_settings[]= - " SUMMARY OF THE HDF5 CONFIGURATION\n" - " =================================\n" + " SUMMARY OF THE HDF5 CONFIGURATION\n" + " =================================\n" "\n" "General Information:\n" "-------------------\n" diff --git a/src/libhdf5.settings.in b/src/libhdf5.settings.in index 32c82b93147..f9e7928e7e1 100644 --- a/src/libhdf5.settings.in +++ b/src/libhdf5.settings.in @@ -1,5 +1,5 @@ - SUMMARY OF THE HDF5 CONFIGURATION - ================================= + SUMMARY OF THE HDF5 CONFIGURATION + ================================= General Information: ------------------- From fcd1563ccb61fd8d93c965fe396a4fde0fc0ba42 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Mon, 12 Jun 2023 13:43:37 -0700 Subject: [PATCH 19/23] CMake changes to address PR issues --- CMakeLists.txt | 5 ----- src/CMakeLists.txt | 34 +++++----------------------------- 2 files changed, 5 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17a4c39d5f1..dfef64654b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1224,9 +1224,4 @@ endif () #----------------------------------------------------------------------------- configure_file (${HDF_RESOURCES_DIR}/H5pubconf.h.in ${HDF5_SRC_BINARY_DIR}/H5pubconf.h @ONLY) -#----------------------------------------------------------------------------- -# Generate the H5build_settings.c file -#----------------------------------------------------------------------------- -configure_file (${HDF5_SOURCE_DIR}/src/H5build_settings.cmake.c.in ${HDF5_SRC_BINARY_DIR}/H5build_settings.c @ONLY) - include (CMakeInstallation.cmake) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a00ba08eb1d..cf23f1fb8a8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1038,9 +1038,9 @@ if (HDF5_GENERATE_HEADERS) endif () #----------------------------------------------------------------------------- -# Set up source generators +# Generate the H5build_settings.c file #----------------------------------------------------------------------------- -set (HDF5_GENERATED_SOURCE_DIR ${HDF5_SRC_BINARY_DIR}) +configure_file (${HDF5_SOURCE_DIR}/src/H5build_settings.cmake.c.in ${HDF5_SRC_BINARY_DIR}/H5build_settings.c @ONLY) if (BUILD_SHARED_LIBS) file (MAKE_DIRECTORY "${HDF5_SRC_BINARY_DIR}/shared") @@ -1079,13 +1079,7 @@ endif () # Set up library builds #----------------------------------------------------------------------------- if (BUILD_STATIC_LIBS) - set (gen_SRCS ${HDF5_SRC_BINARY_DIR}/H5build_settings.c) - add_custom_target (gen_${HDF5_LIB_TARGET} ALL - DEPENDS ${lib_prog_deps} - COMMENT "Generation target files" - ) - - add_library (${HDF5_LIB_TARGET} STATIC ${common_SRCS} ${gen_SRCS} ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS} ${H5_GENERATED_HEADERS} ${H5_MODULE_HEADERS}) + add_library (${HDF5_LIB_TARGET} STATIC ${common_SRCS} H5build_settings.c ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS} ${H5_GENERATED_HEADERS} ${H5_MODULE_HEADERS}) target_include_directories (${HDF5_LIB_TARGET} PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>" INTERFACE "$/include>;$" @@ -1113,19 +1107,12 @@ if (BUILD_STATIC_LIBS) set_global_variable (HDF5_LIBRARIES_TO_EXPORT ${HDF5_LIB_TARGET}) H5_SET_LIB_OPTIONS (${HDF5_LIB_TARGET} ${HDF5_LIB_NAME} STATIC 0) set_target_properties (${HDF5_LIB_TARGET} PROPERTIES FOLDER libraries) - add_dependencies (${HDF5_LIB_TARGET} gen_${HDF5_LIB_TARGET}) set (install_targets ${HDF5_LIB_TARGET}) endif () if (BUILD_SHARED_LIBS) - set (shared_gen_SRCS ${HDF5_SRC_BINARY_DIR}/H5build_settings.c) - add_custom_target (gen_${HDF5_LIBSH_TARGET} ALL - DEPENDS ${lib_prog_deps} - COMMENT "Shared generation target files" - ) - - add_library (${HDF5_LIBSH_TARGET} SHARED ${common_SRCS} ${shared_gen_SRCS} ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS} ${H5_GENERATED_HEADERS} ${H5_MODULE_HEADERS}) + add_library (${HDF5_LIBSH_TARGET} SHARED ${common_SRCS} H5build_settings.c ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS} ${H5_GENERATED_HEADERS} ${H5_MODULE_HEADERS}) target_include_directories (${HDF5_LIBSH_TARGET} PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>" PUBLIC "$<$:${HDFS_INCLUDE_DIR}>" @@ -1152,7 +1139,6 @@ if (BUILD_SHARED_LIBS) set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_LIBSH_TARGET}") H5_SET_LIB_OPTIONS (${HDF5_LIBSH_TARGET} ${HDF5_LIB_NAME} SHARED "LIB") set_target_properties (${HDF5_LIBSH_TARGET} PROPERTIES FOLDER libraries) - add_dependencies (${HDF5_LIBSH_TARGET} gen_${HDF5_LIBSH_TARGET}) set (install_targets ${install_targets} ${HDF5_LIBSH_TARGET}) endif () @@ -1290,17 +1276,7 @@ endif () # Option to build documentation #----------------------------------------------------------------------------- if (DOXYGEN_FOUND) -# This cmake function requires that the non-default doxyfile settings are provided with set (DOXYGEN_xxx) commands -# In addition the doxyfile aliases @INCLUDE option is not supported and would need to be provided in a set (DOXYGEN_ALIASES) command. -# doxygen_add_docs (hdf5lib_doc -## ${common_SRCS} ${shared_gen_SRCS} ${H5_PUBLIC_HEADERS} ${H5_PRIVATE_HEADERS} ${H5_GENERATED_HEADERS} ${HDF5_DOXYGEN_DIR}/dox -# ${DOXYGEN_INPUT_DIRECTORY} -# ALL -# WORKING_DIRECTORY ${HDF5_SRC_DIR} -# COMMENT "Generating HDF5 library Source Documentation" -# ) - -# This custom target and doxygen/configure work together + # This custom target and doxygen/configure work together # Replace variables inside @@ with the current values add_custom_target (hdf5lib_doc ALL COMMAND ${DOXYGEN_EXECUTABLE} ${HDF5_BINARY_DIR}/Doxyfile From dd2a8bdbbfbcbf2f8fe66c4ab327e05fe8298bf9 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Mon, 12 Jun 2023 16:55:19 -0700 Subject: [PATCH 20/23] Remove warning hax --- src/H5build_settings.off.c.in | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/H5build_settings.off.c.in b/src/H5build_settings.off.c.in index c677dd3395c..2464e9fabec 100644 --- a/src/H5build_settings.off.c.in +++ b/src/H5build_settings.off.c.in @@ -10,12 +10,4 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "H5private.h" - -H5_GCC_DIAG_OFF("larger-than=") -H5_CLANG_DIAG_OFF("overlength-strings") - const char H5build_settings[]=""; - -H5_GCC_DIAG_ON("larger-than=") -H5_CLANG_DIAG_OFF("overlength-strings") From ccbcb4f4255e3feb1cfbc2e000554b58811fc7b1 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Mon, 12 Jun 2023 16:55:45 -0700 Subject: [PATCH 21/23] Add error checks to H5Tinit_float.c --- src/H5Tinit_float.c | 144 +++++++++++++++++++++++++------------------- 1 file changed, 82 insertions(+), 62 deletions(-) diff --git a/src/H5Tinit_float.c b/src/H5Tinit_float.c index 717ceb5a545..be3a4c9326f 100644 --- a/src/H5Tinit_float.c +++ b/src/H5Tinit_float.c @@ -104,26 +104,30 @@ _last = _i; \ } \ } \ - H5T__fix_order(sizeof(TYPE), _last, INFO.perm, &INFO.order); \ + if (H5T__fix_order(sizeof(TYPE), _last, INFO.perm, &INFO.order) < 0) \ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "failed to detect byte order") \ \ /* Implicit mantissa bit */ \ _v1 = (TYPE)0.5L; \ _v2 = (TYPE)1.0L; \ - INFO.imp = H5T__imp_bit(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ + if (H5T__imp_bit(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask, &(INFO.imp)) < 0) \ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "failed to determine implicit bit") \ INFO.norm = INFO.imp ? H5T_NORM_IMPLIED : H5T_NORM_NONE; \ \ /* Sign bit */ \ _v1 = (TYPE)1.0L; \ _v2 = (TYPE)-1.0L; \ - INFO.sign = H5T__bit_cmp(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ + if (H5T__bit_cmp(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask, &(INFO.sign)) < 0) \ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "failed to detect byte order") \ \ /* Mantissa */ \ INFO.mpos = 0; \ \ _v1 = (TYPE)1.0L; \ _v2 = (TYPE)1.5L; \ - INFO.msize = H5T__bit_cmp(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ - INFO.msize += 1 + (unsigned int)(INFO.imp ? 0 : 1) - INFO.mpos; \ + if (H5T__bit_cmp(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask, &(INFO.msize)) < 0) \ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "failed to detect byte order") \ + INFO.msize += 1 + (unsigned)(INFO.imp ? 0 : 1) - INFO.mpos; \ \ /* Exponent */ \ INFO.epos = INFO.mpos + INFO.msize; \ @@ -144,7 +148,7 @@ TYPE x; \ } s; \ \ - COMP_ALIGN = (unsigned int)((char *)(&(s.x)) - (char *)(&s)); \ + COMP_ALIGN = (unsigned)((char *)(&(s.x)) - (char *)(&s)); \ } /******************/ @@ -153,17 +157,17 @@ /* Holds detected information about a native floating-point type */ typedef struct H5T_fpoint_det_t { - unsigned int size; /* Total byte size */ - unsigned int prec; /* Meaningful bits */ - unsigned int offset; /* Bit offset to meaningful bits */ - int perm[32]; /* For detection of byte order */ - H5T_order_t order; /* byte order */ - unsigned int sign; /* Location of sign bit */ - unsigned int mpos, msize, imp; /* Information about mantissa */ - H5T_norm_t norm; /* Information about mantissa */ - unsigned int epos, esize; /* Information about exponent */ - unsigned long ebias; /* Exponent bias for floating point */ - unsigned int comp_align; /* Alignment for structure */ + unsigned size; /* Total byte size */ + unsigned prec; /* Meaningful bits */ + unsigned offset; /* Bit offset to meaningful bits */ + int perm[32]; /* For detection of byte order */ + H5T_order_t order; /* byte order */ + unsigned sign; /* Location of sign bit */ + unsigned mpos, msize, imp; /* Information about mantissa */ + H5T_norm_t norm; /* Information about mantissa */ + unsigned epos, esize; /* Information about exponent */ + unsigned long ebias; /* Exponent bias for floating point */ + unsigned comp_align; /* Alignment for structure */ } H5T_fpoint_det_t; /********************/ @@ -192,10 +196,10 @@ typedef struct H5T_fpoint_det_t { /* Functions used in the DETECT_F() macro */ static int H5T__byte_cmp(int, const void *, const void *, const unsigned char *); -static unsigned int H5T__bit_cmp(unsigned int, int *, void *, void *, const unsigned char *); -static void H5T__fix_order(int, int, int *, H5T_order_t *); -static unsigned int H5T__imp_bit(unsigned int, int *, void *, void *, const unsigned char *); -static unsigned int H5T__find_bias(unsigned int, unsigned int, int *, void *); +static herr_t H5T__bit_cmp(unsigned, int *, void *, void *, const unsigned char *, unsigned *); +static herr_t H5T__fix_order(int, int, int *, H5T_order_t *); +static herr_t H5T__imp_bit(unsigned, int *, void *, void *, const unsigned char *, unsigned *); +static unsigned H5T__find_bias(unsigned, unsigned, int *, void *); static void H5T__set_precision(H5T_fpoint_det_t *); /*------------------------------------------------------------------------- @@ -236,33 +240,41 @@ H5T__byte_cmp(int n, const void *_a, const void *_b, const unsigned char *pad_ma * actual order to little endian. Ignores differences where * the corresponding bit in pad_mask is set to 0. * - * Return: Index of first differing bit. + * Sets `first` to the index of the first differing bit + * + * Return: SUCCEED/FAIL *------------------------------------------------------------------------- */ -static unsigned int -H5T__bit_cmp(unsigned int nbytes, int *perm, void *_a, void *_b, const unsigned char *pad_mask) +static herr_t +H5T__bit_cmp(unsigned nbytes, int *perm, void *_a, void *_b, const unsigned char *pad_mask, unsigned *first) { - unsigned int i; unsigned char *a = (unsigned char *)_a; unsigned char *b = (unsigned char *)_b; unsigned char aa, bb; - unsigned int ret_value = 0; + herr_t ret_value = SUCCEED;; - FUNC_ENTER_PACKAGE_NOERR + FUNC_ENTER_PACKAGE - for (i = 0; i < nbytes; i++) { - assert(perm[i] < (int)nbytes); + *first = 0; + + for (unsigned i = 0; i < nbytes; i++) { + if (perm[i] >= (int)nbytes) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "failure in bit comparison") if ((aa = (unsigned char)(a[perm[i]] & pad_mask[perm[i]])) != (bb = (unsigned char)(b[perm[i]] & pad_mask[perm[i]]))) { - unsigned int j; - for (j = 0; j < 8; j++, aa >>= 1, bb >>= 1) { - if ((aa & 1) != (bb & 1)) - HGOTO_DONE(i * 8 + j); + for (unsigned j = 0; j < 8; j++, aa >>= 1, bb >>= 1) { + if ((aa & 1) != (bb & 1)) { + *first = i * 8 + j; + HGOTO_DONE(SUCCEED); + } } } } + /* If we got here and didn't set a value, error out */ + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "didn't find a value for `first`") + done: FUNC_LEAVE_NOAPI(ret_value); } @@ -278,29 +290,30 @@ H5T__bit_cmp(unsigned int nbytes, int *perm, void *_a, void *_b, const unsigned * This function assumes that the mantissa byte ordering * implies the total ordering. * - * Return: void + * Return: SUCCEED/FAIL *------------------------------------------------------------------------- */ -static void +static herr_t H5T__fix_order(int n, int last, int *perm, H5T_order_t *order) { - int i; + herr_t ret_value = SUCCEED; - FUNC_ENTER_PACKAGE_NOERR + FUNC_ENTER_PACKAGE - assert(last > 1); + if (last <= 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "failed to detect byte order") /* We have at least three points to consider */ if (perm[last] < perm[last - 1] && perm[last - 1] < perm[last - 2]) { /* Little endian */ *order = H5T_ORDER_LE; - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) perm[i] = i; } else if (perm[last] > perm[last - 1] && perm[last - 1] > perm[last - 2]) { /* Big endian */ *order = H5T_ORDER_BE; - for (i = 0; i < n; i++) + for (int i = 0; i < n; i++) perm[i] = (n - 1) - i; } else { @@ -308,15 +321,18 @@ H5T__fix_order(int n, int last, int *perm, H5T_order_t *order) * reasons, but there are other mixed-endian systems (like ARM * in rare cases) */ - assert(0 == n % 2); + if (0 != n % 2) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "n is not a power of 2") + *order = H5T_ORDER_VAX; - for (i = 0; i < n; i += 2) { + for (int i = 0; i < n; i += 2) { perm[i] = (n - 2) - i; perm[i + 1] = (n - 1) - i; } } - FUNC_LEAVE_NOAPI_VOID +done: + FUNC_LEAVE_NOAPI(ret_value); } /*------------------------------------------------------------------------- @@ -336,31 +352,32 @@ H5T__fix_order(int n, int last, int *perm, H5T_order_t *order) * of the exponent. * * - * Return: Success: Non-zero if the most significant bit - * of the mantissa is discarded (ie, the - * mantissa has an implicit `one' as the - * most significant bit). Otherwise, - * returns zero. + * Return: imp_bit will be set to 1 if the most significant bit + * of the mantissa is discarded (ie, the mantissa has an + * implicit `one' as the most significant bit). Otherwise, + * imp_bit will be set to zero zero. * - * Failure: 1 + * SUCCEED/FAIL *------------------------------------------------------------------------- */ -static unsigned int -H5T__imp_bit(unsigned int n, int *perm, void *_a, void *_b, const unsigned char *pad_mask) +static herr_t +H5T__imp_bit(unsigned n, int *perm, void *_a, void *_b, const unsigned char *pad_mask, unsigned *imp_bit) { unsigned char *a = (unsigned char *)_a; unsigned char *b = (unsigned char *)_b; - unsigned int changed; - unsigned int major; - unsigned int minor; - unsigned int msmb; /* Most significant mantissa bit */ + unsigned changed; + unsigned major; + unsigned minor; + unsigned msmb; /* Most significant mantissa bit */ + herr_t ret_value = SUCCEED; - FUNC_ENTER_PACKAGE_NOERR + FUNC_ENTER_PACKAGE /* Look for the least significant bit that has changed between * A and B. This is the least significant bit of the exponent. */ - changed = H5T__bit_cmp(n, perm, a, b, pad_mask); + if (H5T__bit_cmp(n, perm, a, b, pad_mask, &changed) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "couldn't find LSB") /* The bit to the right (less significant) of the changed bit should * be the most significant bit of the mantissa. If it is non-zero @@ -370,7 +387,10 @@ H5T__imp_bit(unsigned int n, int *perm, void *_a, void *_b, const unsigned char major = msmb / 8; minor = msmb % 8; - FUNC_LEAVE_NOAPI((a[perm[major]] >> minor) & 0x01 ? 0 : 1); + *imp_bit = (a[perm[major]] >> minor) & 0x01 ? 0 : 1; + +done: + FUNC_LEAVE_NOAPI(ret_value) } /*------------------------------------------------------------------------- @@ -382,19 +402,19 @@ H5T__imp_bit(unsigned int n, int *perm, void *_a, void *_b, const unsigned char * Return: The exponent bias *------------------------------------------------------------------------- */ -H5_ATTR_PURE static unsigned int -H5T__find_bias(unsigned int epos, unsigned int esize, int *perm, void *_a) +H5_ATTR_PURE static unsigned +H5T__find_bias(unsigned epos, unsigned esize, int *perm, void *_a) { unsigned char *a = (unsigned char *)_a; unsigned char mask; - unsigned int b, shift = 0, nbits, bias = 0; + unsigned b, shift = 0, nbits, bias = 0; FUNC_ENTER_PACKAGE_NOERR while (esize > 0) { nbits = MIN(esize, (8 - epos % 8)); mask = (unsigned char)((1 << nbits) - 1); - b = (unsigned int)(a[perm[epos / 8]] >> (epos % 8)) & mask; + b = (unsigned)(a[perm[epos / 8]] >> (epos % 8)) & mask; bias |= b << shift; shift += nbits; From 664ab30a9d775ab753caad8a9077140bc31f0f90 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Mon, 12 Jun 2023 16:56:48 -0700 Subject: [PATCH 22/23] Format source --- src/H5Tinit_float.c | 49 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/H5Tinit_float.c b/src/H5Tinit_float.c index be3a4c9326f..f147ca1cda5 100644 --- a/src/H5Tinit_float.c +++ b/src/H5Tinit_float.c @@ -108,23 +108,23 @@ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "failed to detect byte order") \ \ /* Implicit mantissa bit */ \ - _v1 = (TYPE)0.5L; \ - _v2 = (TYPE)1.0L; \ + _v1 = (TYPE)0.5L; \ + _v2 = (TYPE)1.0L; \ if (H5T__imp_bit(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask, &(INFO.imp)) < 0) \ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "failed to determine implicit bit") \ INFO.norm = INFO.imp ? H5T_NORM_IMPLIED : H5T_NORM_NONE; \ \ /* Sign bit */ \ - _v1 = (TYPE)1.0L; \ - _v2 = (TYPE)-1.0L; \ + _v1 = (TYPE)1.0L; \ + _v2 = (TYPE)-1.0L; \ if (H5T__bit_cmp(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask, &(INFO.sign)) < 0) \ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "failed to detect byte order") \ \ /* Mantissa */ \ INFO.mpos = 0; \ \ - _v1 = (TYPE)1.0L; \ - _v2 = (TYPE)1.5L; \ + _v1 = (TYPE)1.0L; \ + _v2 = (TYPE)1.5L; \ if (H5T__bit_cmp(sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask, &(INFO.msize)) < 0) \ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "failed to detect byte order") \ INFO.msize += 1 + (unsigned)(INFO.imp ? 0 : 1) - INFO.mpos; \ @@ -157,17 +157,17 @@ /* Holds detected information about a native floating-point type */ typedef struct H5T_fpoint_det_t { - unsigned size; /* Total byte size */ - unsigned prec; /* Meaningful bits */ - unsigned offset; /* Bit offset to meaningful bits */ - int perm[32]; /* For detection of byte order */ - H5T_order_t order; /* byte order */ - unsigned sign; /* Location of sign bit */ - unsigned mpos, msize, imp; /* Information about mantissa */ - H5T_norm_t norm; /* Information about mantissa */ - unsigned epos, esize; /* Information about exponent */ - unsigned long ebias; /* Exponent bias for floating point */ - unsigned comp_align; /* Alignment for structure */ + unsigned size; /* Total byte size */ + unsigned prec; /* Meaningful bits */ + unsigned offset; /* Bit offset to meaningful bits */ + int perm[32]; /* For detection of byte order */ + H5T_order_t order; /* byte order */ + unsigned sign; /* Location of sign bit */ + unsigned mpos, msize, imp; /* Information about mantissa */ + H5T_norm_t norm; /* Information about mantissa */ + unsigned epos, esize; /* Information about exponent */ + unsigned long ebias; /* Exponent bias for floating point */ + unsigned comp_align; /* Alignment for structure */ } H5T_fpoint_det_t; /********************/ @@ -195,12 +195,12 @@ typedef struct H5T_fpoint_det_t { /*******************/ /* Functions used in the DETECT_F() macro */ -static int H5T__byte_cmp(int, const void *, const void *, const unsigned char *); -static herr_t H5T__bit_cmp(unsigned, int *, void *, void *, const unsigned char *, unsigned *); -static herr_t H5T__fix_order(int, int, int *, H5T_order_t *); -static herr_t H5T__imp_bit(unsigned, int *, void *, void *, const unsigned char *, unsigned *); -static unsigned H5T__find_bias(unsigned, unsigned, int *, void *); -static void H5T__set_precision(H5T_fpoint_det_t *); +static int H5T__byte_cmp(int, const void *, const void *, const unsigned char *); +static herr_t H5T__bit_cmp(unsigned, int *, void *, void *, const unsigned char *, unsigned *); +static herr_t H5T__fix_order(int, int, int *, H5T_order_t *); +static herr_t H5T__imp_bit(unsigned, int *, void *, void *, const unsigned char *, unsigned *); +static unsigned H5T__find_bias(unsigned, unsigned, int *, void *); +static void H5T__set_precision(H5T_fpoint_det_t *); /*------------------------------------------------------------------------- * Function: H5T__byte_cmp @@ -251,7 +251,8 @@ H5T__bit_cmp(unsigned nbytes, int *perm, void *_a, void *_b, const unsigned char unsigned char *a = (unsigned char *)_a; unsigned char *b = (unsigned char *)_b; unsigned char aa, bb; - herr_t ret_value = SUCCEED;; + herr_t ret_value = SUCCEED; + ; FUNC_ENTER_PACKAGE From 7b64137b053efa1022b9df77328b1bb135b57558 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Tue, 13 Jun 2023 07:50:13 -0700 Subject: [PATCH 23/23] Remove extra semicolon --- src/H5Tinit_float.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/H5Tinit_float.c b/src/H5Tinit_float.c index f147ca1cda5..5b2b83d3f3b 100644 --- a/src/H5Tinit_float.c +++ b/src/H5Tinit_float.c @@ -252,7 +252,6 @@ H5T__bit_cmp(unsigned nbytes, int *perm, void *_a, void *_b, const unsigned char unsigned char *b = (unsigned char *)_b; unsigned char aa, bb; herr_t ret_value = SUCCEED; - ; FUNC_ENTER_PACKAGE