-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Define an internal locale API as a shim on top of the current one #114596
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
Merged
ldionne
merged 10 commits into
llvm:main
from
ldionne:review/locale-6-define-proper-shim-interface
Nov 6, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4622843
[libc++] Define an internal locale API as a shim on top of the curren…
ldionne 1f56b5e
Add missing include and don't modify locale_guard for now
ldionne a4c7142
Fix incorrect macro definition on GCC
ldionne 72207d4
Fix missing includes on Apple and FreeBSD
ldionne a3000b4
Avoid uselocale on Win32
ldionne 9f7252d
Add missing include ctype.h
ldionne 57935c4
Use __mb_len_max instead of __mb_cur_max, which is a macro on Windows
ldionne a64bfb2
Add guard for no wide characters
ldionne 9dcea9b
Add missing includes on Apple and FreeBSD
ldionne 2144d6b
Adjust for config site change
ldionne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this commit landed, symbols like
iswspace_l
were only referenced if_LIBCPP_WCTYPE_IS_MASK
was false. But now it looks like the guard here is_LIBCPP_HAS_WIDE_CHARACTERS
. Is this intentional/expected?If I made a patch to add
#if defined(_LIBCPP_HAS_WIDE_CHARACTERS) && !_LIBCPP_HAS_WIDE_CHARACTERS
to guard these implementations for__iswspace
and friends -- would that be acceptable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think it would be better if we tried to simplify this a bit. It looks like
_LIBCPP_WCTYPE_IS_MASK
andiswupper_l
& friends were introduced in 0081892. I don't fully understand what's the problem they were working around, but I thinkiswctype_l
should do the same thing on all platforms that provide it (contrary to the commit message). So instead I'd be curious to try assuming thatiswctype_l
behaves like it does on FreeBSD and Apple, and see what happens in that case. That would allow us to remove many of these__iswFOO
functions in one go, unconditionally. So, basically, I'd try reverting 0081892 and see what happens with the CI bots.Alternatively, if that doesn't work out, we could potentially move from
iswctype_l
to__iswFOO
on all platforms unconditionally.TLDR I'd like to try simplifying this instead of adding even more complexity by tweaking the locale base API using configuration options, since it's already quite a mess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually just tried that out locally and I don't think that helps a lot, since we still reference all of these
__iswFOO
functions even after ripping out_LIBCPP_WCTYPE_IS_MASK
.I actually fail to see that we were not referencing
iswspace_l
outside of_LIBCPP_WCTYPE_IS_MASK
before this patch. What's the actual issue you're running into and what's your configuration like?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, when we cherry-pick this commit downstream, it fails to compile libc++ now because our C library doesn't have
iswspace_l
et al.My assumptions regarding
_LIBCPP_WCTYPE_IS_MASK
were based on a brief inspection of the change here and maybe I misunderstood. Let me try to reduce the problem and confirm whether indeed_LIBCPP_WCTYPE_IS_MASK
is the critical factor or perhaps something else.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC we lack a platform-specific
__locale_dir/locale_base_api/foo.h
and that might be the source of our problem here. I will explore creating one of those that accepts the locale from these functions and discards it, calling the corresponding non-_l()
function for these missing ones.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, this series of changes aims to make it a lot easier for platforms to define the exact base API they want. It may result in a bit more lines of code than reusing the BSD-like code path, but in the end I'd expect it to be more robust and simpler to understand if you define the API for your downstream platform from scratch.