From 17304d042186dc49856c1d7de82eec15ea5856de Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 9 Feb 2022 03:06:02 -0500 Subject: [PATCH] Portability improvements for new random number generator. On HP-UX 11, the ldexp function requires linking against libm. Moreover, instead of strtoull declared in we have __strtoull declared in . Add configure tests to find these. --- Makefile.am | 6 +++--- NEWS | 1 + configure.ac | 1 + m4/.gitignore | 1 + m4/gnulib-cache.m4 | 2 ++ test/rng.c | 16 +++++++++++++++- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 3d6107a..bef5f01 100644 --- a/Makefile.am +++ b/Makefile.am @@ -66,11 +66,11 @@ $(libmain_a_OBJECTS): src/options.h check_PROGRAMS = test/crossparse test/normalize test/randomdecl check_LIBRARIES = libtest.a -libtest_a_SOURCES = test/testlib.c test/rng.c common/src/help.c +libtest_a_SOURCES = test/testlib.c common/src/help.c $(libtest_a_OBJECTS): $(gnulib_headers) -test_randomdecl_SOURCES = test/randomdecl.c test/declgen.c -test_randomdecl_LDADD = libtest.a libcdecl.la libgnu.la +test_randomdecl_SOURCES = test/randomdecl.c test/declgen.c test/rng.c +test_randomdecl_LDADD = libtest.a libcdecl.la libgnu.la $(LDEXP_LIBM) $(test_randomdecl_OBJECTS): $(gnulib_headers) test_crossparse_LDADD = libtest.a libcdecl.la libgnu.la diff --git a/NEWS b/NEWS index 782a8f2..7bf3e14 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ Release 1.1a: + * Improved portability of the test suite. * Various bug fixes and improvements. Release 1.1: diff --git a/configure.ac b/configure.ac index 506e295..a615f98 100644 --- a/configure.ac +++ b/configure.ac @@ -85,6 +85,7 @@ AH_BOTTOM([#include ]) AC_CONFIG_TESTDIR([.], [test:.]) DX_PROG_AUTOTEST AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"]) +AC_CHECK_FUNCS_ONCE([strtoull __strtoull]) AC_CONFIG_FILES([ Makefile diff --git a/m4/.gitignore b/m4/.gitignore index c87e520..53d1fb2 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -26,6 +26,7 @@ /intmax_t.m4 /inttypes.m4 /inttypes_h.m4 +/ldexp.m4 /lib-ld.m4 /lib-link.m4 /lib-prefix.m4 diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 index 8b8af8f..ae908ee 100644 --- a/m4/gnulib-cache.m4 +++ b/m4/gnulib-cache.m4 @@ -43,6 +43,7 @@ # getopt-gnu \ # gettext-h \ # gitlog-to-changelog \ +# ldexp \ # localcharset \ # lock \ # mbswidth \ @@ -58,6 +59,7 @@ gl_MODULES([ getopt-gnu gettext-h gitlog-to-changelog + ldexp localcharset lock mbswidth diff --git a/test/rng.c b/test/rng.c index 884d981..d86b623 100644 --- a/test/rng.c +++ b/test/rng.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,19 @@ static unsigned long long splitmix64(unsigned long long *state) return z ^ (z >> 31); } +#if HAVE_STRTOULL +# define STRTOULL strtoull +#elif HAVE___STRTOULL +/* HP-UX 11 has __strtoull in */ +# define STRTOULL __strtoull +#else +/* + * Just fall back to strtoul -- in the worst case we just lose the ability + * to set all 64 bits of the seed. + */ +# define STRTOULL strtoul +#endif + struct test_rng *test_rng_alloc(const char *seed_str) { unsigned long long seed; @@ -78,7 +92,7 @@ struct test_rng *test_rng_alloc(const char *seed_str) char *end; errno = 0; - seed = strtoull(seed_str, &end, 0); + seed = STRTOULL(seed_str, &end, 0); if (*end != 0) { fprintf(stderr, "%s: invalid seed\n", seed_str); return NULL; -- 2.43.2