From f9c3a359ed7afe92e561cfebb95baff59ab7e3b6 Mon Sep 17 00:00:00 2001 From: Jim Hague Date: Tue, 3 Mar 2020 17:28:34 +0000 Subject: [PATCH 1/2] Revise recent lookup3.c update to restore building on Windows. As we're now building with CMake, and CMake can supply endianness, just insist on using that. --- src/util/lookup3.c | 57 ++++++++++------------------------------------ 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/src/util/lookup3.c b/src/util/lookup3.c index bb25eb43..5a826193 100644 --- a/src/util/lookup3.c +++ b/src/util/lookup3.c @@ -53,21 +53,18 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. #include "util/storage/lookup3.h" #include /* defines printf for tests */ #include /* defines time_t for timings in the test */ -/*#include defines uint32_t etc (from config.h) */ -#include /* attempt to define endianness */ -#ifdef HAVE_SYS_TYPES_H -# include /* attempt to define endianness (solaris) */ -#endif -#if defined(linux) || defined(__OpenBSD__) -# ifdef HAVE_ENDIAN_H -# include /* attempt to define endianness */ -# else -# include /* on older OpenBSD */ -# endif -#endif -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) -#include /* attempt to define endianness */ -#endif + +#if defined(HAVE_TARGET_ENDIANNESS) +# if defined(TARGET_IS_BIG_ENDIAN) +# define HASH_LITTLE_ENDIAN 0 +# define HASH_BIG_ENDIAN 1 +# else +# define HASH_LITTLE_ENDIAN 1 +# define HASH_BIG_ENDIAN 0 +# endif +#else +# error "Target endianness required." +#endif /* defined(HAVE_TARGET_ENDIANNESS) */ /* random initial value */ static uint32_t raninit = (uint32_t)0xdeadbeef; @@ -78,36 +75,6 @@ hash_set_raninit(uint32_t v) raninit = v; } -/* - * My best guess at if you are big-endian or little-endian. This may - * need adjustment. - */ -#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \ - __BYTE_ORDER == __LITTLE_ENDIAN) || \ - (defined(i386) || defined(__i386__) || defined(__i486__) || \ - defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL) || defined(__x86)) -# define HASH_LITTLE_ENDIAN 1 -# define HASH_BIG_ENDIAN 0 -#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \ - __BYTE_ORDER == __BIG_ENDIAN) || \ - (defined(sparc) || defined(__sparc) || defined(__sparc__) || defined(POWERPC) || defined(mc68000) || defined(sel)) -# define HASH_LITTLE_ENDIAN 0 -# define HASH_BIG_ENDIAN 1 -#elif defined(_MACHINE_ENDIAN_H_) -/* test for machine_endian_h protects failure if some are empty strings */ -# if defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && _BYTE_ORDER == _BIG_ENDIAN -# define HASH_LITTLE_ENDIAN 0 -# define HASH_BIG_ENDIAN 1 -# endif -# if defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && _BYTE_ORDER == _LITTLE_ENDIAN -# define HASH_LITTLE_ENDIAN 1 -# define HASH_BIG_ENDIAN 0 -# endif /* _MACHINE_ENDIAN_H_ */ -#else -# define HASH_LITTLE_ENDIAN 0 -# define HASH_BIG_ENDIAN 0 -#endif - #define hashsize(n) ((uint32_t)1<<(n)) #define hashmask(n) (hashsize(n)-1) #define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) From fc62f8877c39e69e5221161b578293b67218fc20 Mon Sep 17 00:00:00 2001 From: Jim Hague Date: Thu, 27 May 2021 12:11:49 +0100 Subject: [PATCH 2/2] When cross-compiling, assume strptime() is POSIX unless told otherwise. But issue a warning when making that assumption. Add new option FORCE_COMPAT_STRPTIME to force the use of the compat version when cross-compiling and the target platform strptime() is not POSIX-compliant. Poster children for the latter are BSD platforms, including MacOS, where %t is not handled POSIXly. Fix #472 --- CMakeLists.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 811525d2..71e744e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,6 +166,8 @@ option(BUILD_LIBUV "Build libuv support library available." ON) option(USE_LIBIDN2 "Use libidn2 if available." ON) option(USE_GNUTLS "Use GnuTLS for TLS connections." OFF) +option(FORCE_COMPAT_STRPTIME "Force use of internal strptime when cross-compiling." OFF) + # Above names chosen for user consistency. Now define substituted names. set(REQ_DEBUG ${ENABLE_DEBUG_REQ}) set(SCHED_DEBUG ${ENABLE_DEBUG_SCHED}) @@ -533,8 +535,15 @@ set(STRPTIME_TEST_SOURCE "\n res = strptime(\"20070207111842\", \"%Y%m%d%H%M%S\", &tm);\n if (!res) return 1; return 0; }") -if (HAVE_STRPTIME AND NOT CMAKE_CROSSCOMPILING) - check_c_source_runs("${STRPTIME_TEST_SOURCE}" STRPTIME_WORKS) +if (HAVE_STRPTIME) + if (CMAKE_CROSSCOMPILING) + if (NOT FORCE_COMPAT_STRPTIME) + message(WARNING "Assuming strptime() is POSIX compliant with %t matching any white space. Specify FORCE_COMPAT_STRPTIME on non-compliant platforms e.g. BSD derived.") + set(STRPTIME_WORKS 1) + endif () + else () + check_c_source_runs("${STRPTIME_TEST_SOURCE}" STRPTIME_WORKS) + endif () endif () try_compile(HAVE___FUNC__