Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Detect platform word size based on SIZE_MAX #125

Conversation

BurningEnlightenment
Copy link
Contributor

The native word size on a platform matches the size of size_t with a few rare exceptions like the x32 ABI on linux. Therefore we can derive a general cross platform value for BASE64_WORDSIZE based on SIZE_MAX which the C99 standard guarantees to be available and well defined.

This fixes the misdection of x86/arm32 win32 as a 64bit platform, i.e. it is an alternative to #123
@mayeut I think this should also cover the __WORDSIZE and __SIZE_WIDTH__ cases. Can you verify this? If that indeed is the case I would like remove those branches, too.

See also https://en.cppreference.com/w/c/types/limits

The native word size on a platform matches the size of `size_t` with a
few rare exceptions like the x32 ABI on linux. Therefore we can derive a
general cross platform value for `BASE64_WORDSIZE` based on `SIZE_MAX`
which the C99 standard guarantees to be available and well defined.

This fixes the misdection of x86/arm32 win32 as a 64bit platform.

See also https://en.cppreference.com/w/c/types/limits
#elif defined (__WORDSIZE)
# define BASE64_WORDSIZE __WORDSIZE
#elif defined (__SIZE_WIDTH__)
# define BASE64_WORDSIZE __SIZE_WIDTH__
#elif SIZE_MAX == 0xffffffff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#elif SIZE_MAX == 0xffffffff
#elif SIZE_MAX == UINT32_MAX

#elif defined (__WORDSIZE)
# define BASE64_WORDSIZE __WORDSIZE
#elif defined (__SIZE_WIDTH__)
# define BASE64_WORDSIZE __SIZE_WIDTH__
#elif SIZE_MAX == 0xffffffff
# define BASE64_WORDSIZE 32
#elif SIZE_MAX == 0xffffffffffffffff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#elif SIZE_MAX == 0xffffffffffffffff
#elif SIZE_MAX == UINT64_MAX

@mayeut
Copy link
Contributor

mayeut commented Jan 6, 2024

@BurningEnlightenment, I did not write anything related to __WORDSIZE. For __SIZE_WIDTH__, it was directly as bit-size for Alpine but indeed, using SIZE_MAX is equivalent.

@BurningEnlightenment
Copy link
Contributor Author

@mayeut sorry w.r.t. the __WORDSIZE misattribution--the git-blame was a bit misleading due to 955e9ad. Apparently the __WORDSIZE usage goes all the way back to 41b1b77. So I will go ahead and remove those branches.

@aklomp
Copy link
Owner

aklomp commented Jan 8, 2024

Merged with the fixes proposed by @mayeut.

@BurningEnlightenment I slightly modified the commit title to add the issue number, and I modified the commit body to mark this issue and #123 as resolved. Hope you don't mind.

@BurningEnlightenment
Copy link
Contributor Author

BurningEnlightenment commented Jan 8, 2024

@aklomp I additionally wanted to remove these four lines as they became redundant with this change

base64/lib/env.h

Lines 51 to 54 in 88607fe

#elif defined (__WORDSIZE)
# define BASE64_WORDSIZE __WORDSIZE
#elif defined (__SIZE_WIDTH__)
# define BASE64_WORDSIZE __SIZE_WIDTH__

should I open a new PR?

@aklomp
Copy link
Owner

aklomp commented Jan 8, 2024

@BurningEnlightenment I think it's a bit too late now to force-push to the master branch, so yes, please open a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants