Skip to content

Commit

Permalink
#87: update word size detection
Browse files Browse the repository at this point in the history
The detection for word size was dependent on `__LONG_WIDTH__` for at
least gcc Alpine Linux (probably other musl distros too).

This is not working with clang which does not define `__LONG_WIDTH__`.
Replace `__LONG_WIDTH__` by `__SIZE_WIDTH__`.

As this will not work as expected for x32 ABI, add robust x32 detection
first.

Closes #87.
  • Loading branch information
mayeut authored and aklomp committed Jun 5, 2022
1 parent 79eb06b commit 5ad5994
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@
#endif

// Detect word size:
#if defined(_INTEGRAL_MAX_BITS)
#if defined(__x86_64__)
// This also works for the x32 ABI, which has a 64-bit word size.
# define BASE64_WORDSIZE 64
#elif defined(_INTEGRAL_MAX_BITS)
# define BASE64_WORDSIZE _INTEGRAL_MAX_BITS
#elif defined(__WORDSIZE)
# define BASE64_WORDSIZE __WORDSIZE
#elif defined (__LONG_WIDTH__)
# define BASE64_WORDSIZE __LONG_WIDTH__
#elif defined (__SIZE_WIDTH__)
# define BASE64_WORDSIZE __SIZE_WIDTH__
#else
# error BASE64_WORDSIZE_NOT_DEFINED
#endif
Expand Down

0 comments on commit 5ad5994

Please sign in to comment.