Skip to content

Commit 3f90c2e

Browse files
committed
Updates to provide:
(1) major must match (2) minor version backward compatibility check if minor versions don't match 2a, check if either version is in the incompatible list (e.g., develop) print incompatibility warning and HDF5_DISABLE_VERSION_CHECK options abort if version check not disabled 2b, check if header minor version is newer than library version print forward compatibility warning and HDF5_DISABLE_VERSION_CHECK options abort if version check not disabled (3) release (patch) versionnot checked (4) VERS_MINOR_EXCEPTIONS list now set to '999', and minor version '999' checked in test/tcheck_version.c. This check will always cause the -tm option to fail and can remain in release branches, eliminating need to change or remove WILL_FAIL true for release branches.
1 parent de3e556 commit 3f90c2e

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

src/H5.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ bool H5_PKG_INIT_VAR = false;
7272
/* Library Private Variables */
7373
/*****************************/
7474

75-
/* Library incompatible minor versions, develop releases are incompatible by design */
76-
static const unsigned VERS_MINOR_EXCEPTIONS[] = {0};
75+
/* Library known incompatible minor versions; develop releases are incompatible
76+
* by design. 999 is entered for testing an exception as a minor version that
77+
* will never occur. Any released minor version found to be truly incompatible
78+
* (this should never happen) should be added to the list with 999. 999 alone
79+
* in the list indicates that there are no incompatible minor versions. */
80+
static const unsigned VERS_MINOR_EXCEPTIONS[] = {999};
81+
/* The size should be set to the number of minor version exceptions in the list. */
7782
static const unsigned VERS_MINOR_EXCEPTIONS_SIZE = 1;
7883

7984
/* Library init / term status (global) */
@@ -832,6 +837,15 @@ H5get_libversion(unsigned *majnum /*out*/, unsigned *minnum /*out*/, unsigned *r
832837
"linked with an incompatible version of static or shared HDF5 library.\n" \
833838
"You should recompile the application or check your shared library related\n" \
834839
"settings such as 'LD_LIBRARY_PATH'.\n"
840+
#define MINOR_VERSION_FORWARD_COMPATIBLE_WARNING \
841+
"Warning! ***HDF5 library minor version forward compatibility error***\n" \
842+
"The HDF5 header files used to compile this application are from a newer\n" \
843+
"version of the HDF5 library than the one to which this application is linked.\n" \
844+
"Data corruption or segmentation faults may occur if the application continues.\n" \
845+
"This can happen when an application was compiled by a newer version of HDF5 but\n" \
846+
"linked with an older version of static or shared HDF5 library.\n" \
847+
"You should recompile the application or check your shared library related\n" \
848+
"settings such as 'LD_LIBRARY_PATH'.\n"
835849

836850
static herr_t
837851
H5_check_version(unsigned majnum, unsigned minnum, unsigned relnum)
@@ -842,6 +856,7 @@ H5_check_version(unsigned majnum, unsigned minnum, unsigned relnum)
842856
static unsigned int disable_version_check = 0; /* Set if the version check should be disabled */
843857
static const char *version_mismatch_warning = VERSION_MISMATCH_WARNING;
844858
static const char *minor_version_mismatch_warning = MINOR_VERSION_MISMATCH_WARNING;
859+
static const char *minor_version_forward_compatible_warning = MINOR_VERSION_FORWARD_COMPATIBLE_WARNING;
845860
herr_t ret_value = SUCCEED; /* Return value */
846861

847862
FUNC_ENTER_NOAPI_NOINIT_NOERR
@@ -938,6 +953,40 @@ H5_check_version(unsigned majnum, unsigned minnum, unsigned relnum)
938953

939954
} /* end for */
940955

956+
/* Check for forward compatibilty usage. */
957+
if (H5_VERS_MINOR > minnum) {
958+
switch (disable_version_check) {
959+
case 0:
960+
fprintf(stderr, "%s%s", minor_version_forward_compatible_warning,
961+
"You can, at your own risk, disable this warning by setting the environment\n"
962+
"variable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'.\n"
963+
"Setting it to 2 or higher will suppress the warning messages totally.\n");
964+
/* Mention the versions we are referring to */
965+
fprintf(stderr, "Headers are %u.%u.%u, library is %u.%u.%u\n", majnum, minnum, relnum,
966+
(unsigned)H5_VERS_MAJOR, (unsigned)H5_VERS_MINOR, (unsigned)H5_VERS_RELEASE);
967+
968+
/* Bail out now. */
969+
fputs("Bye...\n", stderr);
970+
abort();
971+
case 1:
972+
/* continue with a warning */
973+
/* Note that the warning message is embedded in the format string.*/
974+
fprintf(stderr,
975+
"%s'HDF5_DISABLE_VERSION_CHECK' "
976+
"environment variable is set to %d, application will\n"
977+
"continue at your own risk.\n",
978+
minor_version_forward_compatible_warning, disable_version_check);
979+
/* Mention the versions we are referring to */
980+
fprintf(stderr, "Headers are %u.%u.%u, library is %u.%u.%u\n", majnum, minnum, relnum,
981+
(unsigned)H5_VERS_MAJOR, (unsigned)H5_VERS_MINOR, (unsigned)H5_VERS_RELEASE);
982+
break;
983+
default:
984+
/* 2 or higher: continue silently */
985+
break;
986+
} /* end switch */
987+
988+
}
989+
941990
} /* end if (H5_VERS_MINOR != minnum) */
942991

943992
/* Indicate that the version check has been performed */

test/CMakeTests.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ set_tests_properties (H5TEST-tcheck_version-major PROPERTIES
654654
if ("H5TEST-tcheck_version-major" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
655655
set_tests_properties (H5TEST-tcheck_version-major PROPERTIES DISABLED true)
656656
endif ()
657-
# minor + 1 should pass on non-develop branches
657+
# The minor version test will test version 999 and always fail because it's listed in
658+
# VERS_MINOR_EXCEPTIONS. With WILL_FAIL "true" the failing test passes.
658659
add_test (NAME H5TEST-tcheck_version-minor COMMAND $<TARGET_FILE:tcheck_version> "-tm")
659660
set_tests_properties (H5TEST-tcheck_version-minor PROPERTIES
660661
WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR}/H5TEST
@@ -664,11 +665,12 @@ set_tests_properties (H5TEST-tcheck_version-minor PROPERTIES
664665
if ("H5TEST-tcheck_version-minor" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
665666
set_tests_properties (H5TEST-tcheck_version-minor PROPERTIES DISABLED true)
666667
endif ()
668+
# release + 1 should always pass (not checked)
667669
add_test (NAME H5TEST-tcheck_version-release COMMAND $<TARGET_FILE:tcheck_version> "-tr")
668670
set_tests_properties (H5TEST-tcheck_version-release PROPERTIES
669671
WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR}/H5TEST
670672
ENVIRONMENT "${CROSSCOMPILING_PATH}"
671-
)
673+
)
672674
if ("H5TEST-tcheck_version-release" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
673675
set_tests_properties (H5TEST-tcheck_version-release PROPERTIES DISABLED true)
674676
endif ()

test/tcheck_version.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ parse(int ac, char **av)
7070
major++;
7171
break;
7272
case 'm':
73-
minor++;
73+
minor = 999;
7474
break;
7575
case 'r':
7676
release++;

0 commit comments

Comments
 (0)