locale.c: Fix compilation on platforms with only a C locale #22569
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.
Reported downstream in: https://bugs.gentoo.org/939014. The bug is about being impossible to bootstrap a Gentoo prefix with perl-5.40.0.
A Gentoo prefix is a Linux installation under some custom directory, modifiable by a non-root user. Bootstrapping such an installation starts with a host compiler and a shell and builds packages until the full installation is complete. Because of the nature of perl, it ends up being compiled relatively early during the whole process, before the installation is complete and the user has had the chance to select which locales to generate.
In this situation perl ends up being compiled on a bare system with only the C locale. The code in
Configure
perl5/Configure
Lines 17672 to 17675 in 67e8521
LC_ALL
which then takes the secondcase
branchperl5/Configure
Lines 17812 to 17834 in 67e8521
PERL_LC_ALL_USES_NAME_VALUE_PAIRS
,PERL_LC_ALL_SEPARATOR
, andPERL_LC_ALL_CATEGORY_POSITIONS_INIT
end up being undefined. Thelocale.c
code, however, assumes that eitherPERL_LC_ALL_USES_NAME_VALUE_PAIRS
or the other two macros are defined which leads to a compilation failure because of the usage ofPERL_LC_ALL_CATEGORY_POSITIONS_INIT
:There is already code:
perl5/locale.c
Lines 649 to 658 in 67e8521
PERL_LC_ALL_SEPARATOR
. This is a similar situation in purpose but, becausePERL_LC_ALL_CATEGORY_POSITIONS_INIT
is suppose to be an array initializer and, if generated inside the code, it would require a#include "locale_table.h"
I think it's simpler to replace its single usage point. Themap_LC_ALL_position_to_index
array should still be initialized, even with logically wrong values, to prevent possible out-of-bounds errors in other parts of the code.