From 695d8cea17bb7eb755899ffbfd01ed91e3cce576 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> Date: Sun, 5 Jul 2020 19:52:22 +0900 Subject: [PATCH] Define ngtcp2_ntohl64 and ngtcp2_htonl64 as noop for bigendian system --- CMakeLists.txt | 3 +++ configure.ac | 5 +++++ lib/ngtcp2_conv.h | 25 +++++++++++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23fbc571..93705dd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,7 @@ check_include_file("string.h" HAVE_STRING_H) check_include_file("unistd.h" HAVE_UNISTD_H) check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H) check_include_file("endian.h" HAVE_ENDIAN_H) +check_include_file("byteswap.h" HAVE_BYTESWAP_H) include(CheckTypeSize) # Checks for typedefs, structures, and compiler characteristics. @@ -161,6 +162,8 @@ if(HAVE_SYS_ENDIAN_H) check_symbol_exists(be64toh "sys/endian.h" HAVE_BE64TOH) endif() +check_symbol_exists(bswap_64 "byteswap.h" HAVE_BSWAP_64) + include(ExtractValidFlags) set(WARNCFLAGS) set(WARNCXXFLAGS) diff --git a/configure.ac b/configure.ac index 34924e67..b645eab9 100644 --- a/configure.ac +++ b/configure.ac @@ -294,6 +294,7 @@ AC_CHECK_HEADERS([ \ unistd.h \ sys/endian.h \ endian.h \ + byteswap.h \ ]) # Checks for typedefs, structures, and compiler characteristics. @@ -331,6 +332,10 @@ AC_CHECK_DECLS([be64toh], [], [], [[ #endif ]]) +AC_CHECK_DECLS([bswap_64], [], [], [[ +#include <byteswap.h> +]]) + # More compiler flags from nghttp2. save_CFLAGS=$CFLAGS save_CXXFLAGS=$CXXFLAGS diff --git a/lib/ngtcp2_conv.h b/lib/ngtcp2_conv.h index f3336f44..ebb264d0 100644 --- a/lib/ngtcp2_conv.h +++ b/lib/ngtcp2_conv.h @@ -37,6 +37,10 @@ # include <netinet/in.h> #endif /* HAVE_NETINET_IN_H */ +#ifdef HAVE_BYTESWAP_H +# include <byteswap.h> +#endif /* HAVE_BYTESWAP_H */ + #ifdef HAVE_ENDIAN_H # include <endian.h> #endif /* HAVE_ENDIAN_H */ @@ -47,16 +51,25 @@ #include <ngtcp2/ngtcp2.h> +#if defined HAVE_BSWAP_64 || HAVE_DECL_BSWAP_64 +# define ngtcp2_bswap64 bswap_64 +#else /* !HAVE_BSWAP_64 */ +# define ngtcp2_bswap64(N) \ + ((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32))) +#endif /* !HAVE_BSWAP_64 */ + #if defined HAVE_BE64TOH || HAVE_DECL_BE64TOH # define ngtcp2_ntohl64(N) be64toh(N) # define ngtcp2_htonl64(N) htobe64(N) #else /* !HAVE_BE64TOH */ -# define ngtcp2_bswap64(N) \ - ((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32))) -# define ngtcp2_ntohl64(N) ngtcp2_bswap64(N) -# define ngtcp2_htonl64(N) ngtcp2_bswap64(N) -#endif /* !HAVE_BE64TOH */ - +# if defined WORDS_BIGENDIAN +# define ngtcp2_ntohl64(N) (N) +# define ngtcp2_htonl64(N) (N) +# else /* !WORDS_BIGENDIAN */ +# define ngtcp2_ntohl64(N) ngtcp2_bswap64(N) +# define ngtcp2_htonl64(N) ngtcp2_bswap64(N) +# endif /* !WORDS_BIGENDIAN */ +#endif /* !HAVE_BE64TOH */ #if defined(WIN32) /* Windows requires ws2_32 library for ntonl family functions. We define inline functions for those function so that we don't have -- GitLab