git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Detect endianness on more platforms that don't use BYTE_ORDER

From
Junio C Hamano <gitster@pobox.com>
Date
May 2, 2014, 16:48 UTC
Message-ID
<xmqqwqe4azyd.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1399017329-25645-1-git-send-email-cbailey32@bloomberg.net>
Charles Bailey <cbailey32@bloomberg.net> writes:
> ---
Please sign-off your patches ;-)

This swaps the precedence of BYTE_ORDER and __BYTE_ORDER from the original, which we may not want to. It is easy for me to swap the order of if/elif to restore it, so it is not a big deal, though.

Thanks.
Show 51 quoted lines
>  compat/bswap.h | 33 ++++++++++++++++++++++++---------
>  1 file changed, 24 insertions(+), 9 deletions(-)
>
> diff --git a/compat/bswap.h b/compat/bswap.h
> index 120c6c1..f08a9fe 100644
> --- a/compat/bswap.h
> +++ b/compat/bswap.h
> @@ -101,19 +101,34 @@ static inline uint64_t git_bswap64(uint64_t x)
>  #undef ntohll
>  #undef htonll
>  
> -#if !defined(__BYTE_ORDER)
> -# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
> -#  define __BYTE_ORDER BYTE_ORDER
> -#  define __LITTLE_ENDIAN LITTLE_ENDIAN
> -#  define __BIG_ENDIAN BIG_ENDIAN
> +#if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
> +
> +# define GIT_BYTE_ORDER BYTE_ORDER
> +# define GIT_LITTLE_ENDIAN LITTLE_ENDIAN
> +# define GIT_BIG_ENDIAN BIG_ENDIAN
> +
> +#elif defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
> +
> +# define GIT_BYTE_ORDER __BYTE_ORDER
> +# define GIT_LITTLE_ENDIAN __LITTLE_ENDIAN
> +# define GIT_BIG_ENDIAN __BIG_ENDIAN
> +
> +#else
> +
> +# define GIT_BIG_ENDIAN 4321
> +# define GIT_LITTLE_ENDIAN 1234
> +
> +# if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
> +#  define GIT_BYTE_ORDER GIT_BIG_ENDIAN
> +# elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
> +#  define GIT_BYTE_ORDER GIT_LITTLE_ENDIAN
> +# else
> +#  error "Cannot determine endianness"
>  # endif
> -#endif
>  
> -#if !defined(__BYTE_ORDER)
> -# error "Cannot determine endianness"
>  #endif
>  
> -#if __BYTE_ORDER == __BIG_ENDIAN
> +#if GIT_BYTE_ORDER == GIT_BIG_ENDIAN
>  # define ntohll(n) (n)
>  # define htonll(n) (n)
>  #else
Previous: Charles BaileyNext: Charles Bailey
Message 7 of 11 in “Add extra logic required to detect endianness on Solaris”
  1. Add extra logic required to detect endianness on SolarisCharles Bailey, May 1, 2014
  2. Junio C HamanoMay 1, 2014
  3. Junio C HamanoMay 1, 2014
  4. Junio C HamanoMay 1, 2014
  5. Charles BaileyMay 2, 2014
  6. Detect endianness on more platforms that don't use BYTE_ORDERCharles Bailey, May 2, 2014
  7. Junio C HamanoMay 2, 2014
  8. Charles BaileyMay 2, 2014
  9. Junio C HamanoMay 2, 2014
  10. Junio C HamanoMay 2, 2014
  11. Charles BaileyMay 2, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.