Skip to content

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
merged 12 commits into from
Oct 10, 2022

Conversation

khwilliamson
Copy link
Contributor

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

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.
@khwilliamson khwilliamson merged commit 4f50c78 into Perl:blead Oct 10, 2022
@khwilliamson khwilliamson deleted the wsetlocale branch October 10, 2022 19:12
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.

2 participants