-
Notifications
You must be signed in to change notification settings - Fork 577
Meld Windows and non-Windows setlocale(..., "") into a single function, and tidy #20370
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
Conversation
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 makes the calls to it cleaner.
This is in preparation for this function to be used under more circumstances.
This changes this function a bit to make the next commit easier, which will extend the function to being usable from Windows. This also moves declarations closer to first use, as now allowed in C99.
There is code in locale.c to emulate POSIX 'setlocale(foo, "")'. And there is separate code to emulate this on Windows. This commit collapses them, ensuring the same algorithm is used on both systems.
The previous commit changed find_locale_from_environment() to work on Windows, and took care to not make the function have side effects. But in the only use of this function so far (and likely forever), those side effects are fine. Changing to allow them simplifies things.
This gets the trivial case out of the way, and can use plain setlocale, as the locale string is non-existent, so doesn't need to handle different character sets.
The wide setlocale function in Windows has been in the field since 5.32, long enough, that we won't be forced to discontinue its use. So can remove the never-used overrides, cleaning it up slightly
These are non-API, used in this file, and because of #ifdefs, not accessible outside it, so there is no current need to make them publicly available. If we were ever to need them to be accessible more widely, they would not belong in this file.
This changes these functions to take the code page as input, instead of being just UTF-8. Macros are created to call them with UTF-8. I'm doing this because there is no loss of efficiency, and it is somewhat jarring, given Perl terminology, to call a function with 'Byte' in the name with a parameter with 'utf8' in the name.
And move declarations closer to first use as allowed in C99
Add a bit of safety, and makes it correspond to the other setlocale returns we use.
C99 allows declarations to be closer to their first use. This also removes a redundant conditional that would set a variable to what it already was initialized to.
tonycoz
approved these changes
Oct 9, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This series of commits collapses duplicate functionality into one, and tidies up the Windows-specific locale functions, with regard to constness, and returning temp scalars. A particular buffer now is always used, which is freed on destruction