From 3141c1b2ccebd5bad30261719415e432c701de7d Mon Sep 17 00:00:00 2001 From: Wei-keng Liao Date: Mon, 16 Jul 2018 14:34:22 -0500 Subject: [PATCH] error out when conflicts with PnetCDF are detected --- CMakeLists.txt | 87 +++++++++++++++++++++++++++++-------------- configure.ac | 84 ++++++++++++++++++++--------------------- libnetcdf.settings.in | 1 + 3 files changed, 100 insertions(+), 72 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0afe01f7f..a7a800f42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1044,56 +1044,87 @@ IF(ENABLE_PNETCDF) ENDIF() # Options to enable use of fill values for elements causing NC_ERANGE -SET(STATUS_ERANGE_FILL "OFF") -OPTION(ENABLE_ERANGE_FILL "Enable use of fill value when out-of-range type conversion causes NC_ERANGE error." OF) -IF(ENABLE_ERANGE_FILL) - SET(STATUS_ERANGE_FILL "ON") - ADD_DEFINITIONS(-DERANGE_FILL) -ENDIF() +SET(ENABLE_ERANGE_FILL AUTO CACHE STRING "AUTO") +OPTION(ENABLE_ERANGE_FILL "Enable use of fill value when out-of-range type conversion causes NC_ERANGE error." OFF) +IF(ENABLE_ERANGE_FILL) # enable or auto + STRING(TOUPPER ${ENABLE_ERANGE_FILL} ENABLE_ERANGE_FILL) + IF(ENABLE_ERANGE_FILL AND NOT ENABLE_ERANGE_FILL STREQUAL "AUTO") + # explicitly enabled + SET(ENABLE_ERANGE_FILL ON) + ELSE() + IF(NOT ENABLE_ERANGE_FILL STREQUAL "AUTO") + SET(ENABLE_ERANGE_FILL OFF) + ENDIF() + ENDIF() +ENDIF(ENABLE_ERANGE_FILL) +# Now ENABLE_ERANGE_FILL is either AUTO, ON, or OFF # Options to use a more relaxed coordinate argument boundary check -SET(STATUS_RELAX_COORD_BOUND "OFF") +SET(ENABLE_ZERO_LENGTH_COORD_BOUND AUTO CACHE STRING "AUTO") OPTION(ENABLE_ZERO_LENGTH_COORD_BOUND "Enable a more relaxed boundary error check NC_EINVALCOORDS to allow coordinate start argument equal to dimension size when argument count is zero." OFF) -IF(ENABLE_ZERO_LENGTH_COORD_BOUND) - SET(STATUS_RELAX_COORD_BOUND "ON") -ENDIF() +IF(ENABLE_ZERO_LENGTH_COORD_BOUND) # enable or auto + STRING(TOUPPER ${ENABLE_ZERO_LENGTH_COORD_BOUND} ENABLE_ZERO_LENGTH_COORD_BOUND) + IF(ENABLE_ZERO_LENGTH_COORD_BOUND AND NOT ENABLE_ZERO_LENGTH_COORD_BOUND STREQUAL "AUTO") + # explicitly enabled + SET(ENABLE_ZERO_LENGTH_COORD_BOUND ON) + ELSE() + IF(NOT ENABLE_ZERO_LENGTH_COORD_BOUND STREQUAL "AUTO") + SET(ENABLE_ZERO_LENGTH_COORD_BOUND OFF) + ENDIF() + ENDIF() +ENDIF(ENABLE_ZERO_LENGTH_COORD_BOUND) +# Now ENABLE_ZERO_LENGTH_COORD_BOUND is either AUTO, ON, or OFF # check and conform with PnetCDF settings on ERANGE_FILL and RELAX_COORD_BOUND IF(STATUS_PNETCDF) file(STRINGS "${pnetcdf_h}" enable_erange_fill_pnetcdf REGEX "^#define PNETCDF_ERANGE_FILL") string(REGEX REPLACE "[^0-9]" "" erange_fill_pnetcdf "${enable_erange_fill_pnetcdf}") IF("x${erange_fill_pnetcdf}" STREQUAL "x1") - IF(NOT STATUS_ERANGE_FILL) - MESSAGE(WARNING "Enable erange-fill to conform with PnetCDF setting") - SET(STATUS_ERANGE_FILL "ON") - ENDIF() + SET(erange_fill_pnetcdf "ON") ELSE() - IF(STATUS_ERANGE_FILL) - MESSAGE(WARNING "Disable erange-fill to conform with PnetCDF setting") - SET(STATUS_ERANGE_FILL "OFF") + SET(erange_fill_pnetcdf "OFF") + ENDIF() + IF(ENABLE_ERANGE_FILL STREQUAL "AUTO") # not set on command line + SET(ENABLE_ERANGE_FILL "${erange_fill_pnetcdf}") + ELSE() + # user explicitly set this option on command line + IF(NOT ENABLE_ERANGE_FILL STREQUAL "${erange_fill_pnetcdf}") + IF(ENABLE_ERANGE_FILL) + MESSAGE(FATAL_ERROR "Enabling erange-fill conflicts with PnetCDF setting") + ELSE() + MESSAGE(FATAL_ERROR "Disabling erange-fill conflicts with PnetCDF setting") + ENDIF() ENDIF() ENDIF() + file(STRINGS "${pnetcdf_h}" relax_coord_bound_pnetcdf REGEX "^#define PNETCDF_RELAX_COORD_BOUND") string(REGEX REPLACE "[^0-9]" "" relax_coord_bound "${relax_coord_bound_pnetcdf}") IF("x${relax_coord_bound}" STREQUAL "x1") - IF(NOT STATUS_RELAX_COORD_BOUND) - MESSAGE(WARNING "Enable relax-coord-bound to conform with PnetCDF setting") - SET(STATUS_RELAX_COORD_BOUND "ON") - ENDIF() + SET(relax_coord_bound_pnetcdf "ON") ELSE() - IF(STATUS_RELAX_COORD_BOUND) - MESSAGE(WARNING "Disable relax-coord-bound to conform with PnetCDF setting") - SET(STATUS_RELAX_COORD_BOUND "OFF") + SET(relax_coord_bound_pnetcdf "OFF") + ENDIF() + IF(ENABLE_ZERO_LENGTH_COORD_BOUND STREQUAL "AUTO") # not set on command line + SET(ENABLE_ZERO_LENGTH_COORD_BOUND "${relax_coord_bound_pnetcdf}") + ELSE() + # user explicitly set this option on command line + IF(NOT ENABLE_ZERO_LENGTH_COORD_BOUND STREQUAL "${relax_coord_bound_pnetcdf}") + IF(ENABLE_ZERO_LENGTH_COORD_BOUND) + MESSAGE(FATAL_ERROR "Enabling relax-coord-bound conflicts with PnetCDF setting") + ELSE() + MESSAGE(FATAL_ERROR "Disabling relax-coord-bound conflicts with PnetCDF setting") + ENDIF() ENDIF() ENDIF() ENDIF() -IF(STATUS_ERANGE_FILL) +IF(ENABLE_ERANGE_FILL) + MESSAGE(STATUS "Enabling use of fill value when NC_ERANGE") SET(M4FLAGS "-DERANGE_FILL" CACHE STRING "") ENDIF() -IF(STATUS_RELAX_COORD_BOUND) - MESSAGE(STATUS "Enabling a more relatexed check for NC_EINVALCOORDS") +IF(ENABLE_ZERO_LENGTH_COORD_BOUND) + MESSAGE(STATUS "Enabling a more relatexed check when NC_EINVALCOORDS") ADD_DEFINITIONS(-DRELAX_COORD_BOUND) ENDIF() @@ -1879,7 +1910,7 @@ is_enabled(ENABLE_DAP4 HAS_DAP4) is_enabled(ENABLE_DISKLESS HAS_DISKLESS) is_enabled(USE_MMAP HAS_MMAP) is_enabled(JNA HAS_JNA) -is_enabled(STATUS_RELAX_COORD_BOUND RELAX_COORD_BOUND) +is_enabled(ENABLE_ZERO_LENGTH_COORD_BOUND RELAX_COORD_BOUND) is_enabled(USE_CDF5 HAS_CDF5) is_enabled(ENABLE_ERANGE_FILL HAS_ERANGE_FILL) diff --git a/configure.ac b/configure.ac index 6098a4467..034337de3 100644 --- a/configure.ac +++ b/configure.ac @@ -1157,15 +1157,15 @@ AC_ARG_ENABLE([erange_fill], [AS_HELP_STRING([--enable-erange-fill], [Enable use of fill value when out-of-range type conversion causes NC_ERANGE error. @<:@default: disabled@:>@])], - [enable_erange_fill=${enableval}], [enable_erange_fill=no] + [enable_erange_fill=${enableval}], [enable_erange_fill=auto] ) AC_ARG_ENABLE([zero-length-coord-bound], - [AS_HELP_STRING([--enable-zero-length-coord-bound], - [Enable a more relaxed boundary error check NC_EINVALCOORDS + [AS_HELP_STRING([--disable-zero-length-coord-bound], + [Disable a more relaxed boundary error check NC_EINVALCOORDS to allow coordinate start argument equal to dimension size - when argument count is zero. @<:@default: disabled@:>@])], - [enable_zero_length_coord_bound=${enableval}], [enable_zero_length_coord_bound=no] + when argument count is zero. @<:@default: enabled@:>@])], + [enable_zero_length_coord_bound=${enableval}], [enable_zero_length_coord_bound=auto] ) # check PnetCDF's settings on enable_erange_fill and relax_coord_bound @@ -1173,48 +1173,46 @@ if test "x$enable_pnetcdf" = xyes; then UD_CHECK_HEADER_PATH([pnetcdf.h]) AC_MSG_CHECKING([if erange-fill is enabled in PnetCDF]) - erange_fill_pnetcdf=`grep PNETCDF_ERANGE_FILL ${ac_cv_header_path_pnetcdf_h}` - if test "x$erange_fill_pnetcdf" = x; then - erange_fill_pnetcdf=no - else - erange_fill_pnetcdf=`echo ${erange_fill_pnetcdf} | cut -d' ' -f3` - if test "x$erange_fill_pnetcdf" = x0; then - enable_erange_fill_pnetcdf=no - else - enable_erange_fill_pnetcdf=yes - fi - fi + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ +#include +#if !defined(PNETCDF_ERANGE_FILL) || PNETCDF_ERANGE_FILL == 0 + choke me +#endif]])], [enable_erange_fill_pnetcdf=yes], [enable_erange_fill_pnetcdf=no]) AC_MSG_RESULT([$enable_erange_fill_pnetcdf]) - if test "$enable_erange_fill" != "$enable_erange_fill_pnetcdf"; then - if test "$enable_erange_fill_pnetcdf" = yes; then - AC_MSG_WARN([Enable erange-fill to conform with PnetCDF setting]) - else - AC_MSG_WARN([Disable erange-fill to conform with PnetCDF setting]) - fi + if test "x$enable_erange_fill" = xauto ; then enable_erange_fill=$enable_erange_fill_pnetcdf + elif test "$enable_erange_fill" != "$enable_erange_fill_pnetcdf"; then + if test "$enable_erange_fill" = yes; then + AC_MSG_ERROR([Enabling erange-fill conflicts with PnetCDF setting]) + else + AC_MSG_ERROR([Disabling erange-fill conflicts with PnetCDF setting]) + fi fi AC_MSG_CHECKING([if relax-coord-bound is enabled in PnetCDF]) - relax_coord_bound_pnetcdf=`grep PNETCDF_RELAX_COORD_BOUND ${ac_cv_header_path_pnetcdf_h}` - if test "x$relax_coord_bound_pnetcdf" = x; then - elax_coord_bound_pnetcdf=no - else - coord_bound_pnetcdf=`echo ${relax_coord_bound_pnetcdf} | cut -d' ' -f3` - if test "x$coord_bound_pnetcdf" = x0; then - relax_coord_bound_pnetcdf=no - else - relax_coord_bound_pnetcdf=yes - fi - fi + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ +#include +#if !defined(PNETCDF_RELAX_COORD_BOUND) || PNETCDF_RELAX_COORD_BOUND == 0 + choke me +#endif]])], [relax_coord_bound_pnetcdf=yes], [relax_coord_bound_pnetcdf=no]) AC_MSG_RESULT([$relax_coord_bound_pnetcdf]) - if test "$enable_zero_length_coord_bound" != "$relax_coord_bound_pnetcdf"; then - if test "$relax_coord_bound_pnetcdf" = yes; then - AC_MSG_WARN([Enable relax-coord-bound to conform with PnetCDF setting]) - else - AC_MSG_WARN([Disable relax-coord-bound to conform with PnetCDF setting]) - fi + if test "x$enable_zero_length_coord_bound" = xauto ; then enable_zero_length_coord_bound=$relax_coord_bound_pnetcdf + elif test "$enable_zero_length_coord_bound" != "$relax_coord_bound_pnetcdf"; then + if test "$enable_zero_length_coord_bound" = yes; then + AC_MSG_ERROR([Enabling relax-coord-bound conflicts with PnetCDF setting]) + else + AC_MSG_ERROR([Disabling relax-coord-bound conflicts with PnetCDF setting]) + fi fi +else + # default setting + enable_erange_fill=no + enable_zero_length_coord_bound=yes +fi + +if test "x$enable_zero_length_coord_bound" = xyes; then + AC_DEFINE([RELAX_COORD_BOUND], [1], [if true, NC_EINVALCOORDS check is more relaxed]) fi if test "x$enable_erange_fill" = xyes ; then @@ -1227,10 +1225,6 @@ if test "x$enable_erange_fill" = xyes ; then fi AC_SUBST(M4FLAGS) -if test "x$enable_zero_length_coord_bound" = xyes; then - AC_DEFINE([RELAX_COORD_BOUND], [1], [if true, NC_EINVALCOORDS check is more relaxed]) -fi - # Check for downloading/building fortran via postinstall script. if test "x$enable_remote_fortran_bootstrap" = xyes; then AC_DEFINE([BUILD_FORTRAN], 1, [If true, will attempt to download and build netcdf-fortran.]) @@ -1407,9 +1401,10 @@ AC_SUBST(HAS_PARALLEL4,[$enable_parallel4]) AC_SUBST(HAS_DISKLESS,[yes]) AC_SUBST(HAS_MMAP,[$enable_mmap]) AC_SUBST(HAS_JNA,[$enable_jna]) -AC_SUBST(RELAX_COORD_BOUND,[$enable_relax_coord_bound]) +AC_SUBST(RELAX_COORD_BOUND,[$enable_zero_length_coord_bound]) AC_SUBST(HAS_ERANGE_FILL,[$enable_erange_fill]) + # Include some specifics for netcdf on windows. #AH_VERBATIM([_WIN32_STRICMP], AH_BOTTOM( @@ -1476,6 +1471,7 @@ AX_SET_META([NC_HAS_PARALLEL],[$enable_parallel],[yes]) AX_SET_META([NC_HAS_PARALLEL4],[$enable_parallel4],[yes]) AX_SET_META([NC_HAS_CDF5],[$enable_cdf5],[yes]) AX_SET_META([NC_HAS_ERANGE_FILL], [$enable_erange_fill],[yes]) +AX_SET_META([NC_RELAX_COORD_BOUND], [$enable_zero_length_coord_bound],[yes]) # Automake says that this is always run in top_builddir # and that srcdir is defined (== top_srcdir) diff --git a/libnetcdf.settings.in b/libnetcdf.settings.in index 0384faca9..aa37ee0f7 100644 --- a/libnetcdf.settings.in +++ b/libnetcdf.settings.in @@ -36,3 +36,4 @@ MMap Support: @HAS_MMAP@ JNA Support: @HAS_JNA@ CDF5 Support: @HAS_CDF5@ ERANGE fill Support: @HAS_ERANGE_FILL@ +relaxed boundary check: @RELAX_COORD_BOUND@