]> git.draconx.ca Git - cdecl99.git/commitdiff
Portability improvements for new random number generator.
authorNick Bowler <nbowler@draconx.ca>
Wed, 9 Feb 2022 08:06:02 +0000 (03:06 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 10 Feb 2022 01:52:49 +0000 (20:52 -0500)
On HP-UX 11, the ldexp function requires linking against libm.
Moreover, instead of strtoull declared in <stdlib.h> we have
__strtoull declared in <inttypes.h>.  Add configure tests to
find these.

Makefile.am
NEWS
configure.ac
m4/.gitignore
m4/gnulib-cache.m4
test/rng.c

index 3d6107a38b8474fcaa0c7d1769489908974460ff..bef5f018d19fea158c46f6dff23ee11aac1654d5 100644 (file)
@@ -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 782a8f29061de4e4bd48e1775354df963a5baa74..7bf3e141eeb4c901433b9aa1718ddf1a70973645 100644 (file)
--- 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:
index 506e295ee1be394aa044ca15dff669736cddbf0a..a615f98a75404e3a921a661e4bacf87b932b0ad3 100644 (file)
@@ -85,6 +85,7 @@ AH_BOTTOM([#include <conf_post.h>])
 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
index c87e5200fbb3eff997d93e148704312bd59a29aa..53d1fb2c3b993038b5ed0d795abd8c0ec8020aa3 100644 (file)
@@ -26,6 +26,7 @@
 /intmax_t.m4
 /inttypes.m4
 /inttypes_h.m4
+/ldexp.m4
 /lib-ld.m4
 /lib-link.m4
 /lib-prefix.m4
index 8b8af8f4d353e5315d877eb552280cba6e702dca..ae908ee24653dd61a217af535ebed444a8908c57 100644 (file)
@@ -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
index 884d981767f9a09b3becef08f3506540adc516ec..d86b623233ba88abfc069404ba149be5f1b5e62b 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <inttypes.h>
 #include <errno.h>
 #include <limits.h>
 #include <float.h>
@@ -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 <inttypes.h> */
+#  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;