summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-10-29 15:53:50 -0600
committerKarl Williamson <khw@cpan.org>2020-10-30 09:27:01 -0600
commit23f9d84eaa7d7d8312722a6266e48f4ebaeb234d (patch)
treed1b4edad64f802efa4eea85b6a7e26ea95b8975f
parentf29568991a1e703f13874b907c3f51df944a8f4f (diff)
downloadperl-23f9d84eaa7d7d8312722a6266e48f4ebaeb234d.tar.gz
loc_tools.pl: Fix locales_enabled()
This commit properly returns the new list it is supposed to, clarifies the documentation. Fixes GH #18245
-rw-r--r--t/loc_tools.pl56
1 files changed, 35 insertions, 21 deletions
diff --git a/t/loc_tools.pl b/t/loc_tools.pl
index 927f0254a5..f4b99775e1 100644
--- a/t/loc_tools.pl
+++ b/t/loc_tools.pl
@@ -187,26 +187,35 @@ sub valid_locale_categories() {
}
sub locales_enabled(;$) {
- # Returns 0 if no locale handling is available on this platform; otherwise
- # 1.
+ # If no parameter is specified, the function returns 1 if there is any
+ # "safe" locale handling available to the caller; otherwise 0. Safeness
+ # is defined here as the caller operating in the main thread of a program,
+ # or if threaded locales are safe on the platform and Configured to be
+ # used. This sub is used for testing purposes, and for those, this
+ # definition of safety is sufficient, and necessary to get some tests to
+ # run on certain configurations on certain platforms. But beware that the
+ # main thread can change the locale of any subthreads unless
+ # ${^SAFE_LOCALES} is non-zero.
#
- # The optional parameter is a reference to a list of individual POSIX
- # locale categories. If any of the individual categories specified by the
- # optional parameter is all digits (and an optional leading minus), it is
- # taken to be the C enum for the category (e.g., &POSIX::LC_CTYPE).
- # Otherwise it should be a string name of the category, like 'LC_TIME'.
- # The initial 'LC_' is optional. It is a fatal error to call this with
- # something that isn't a known category to this file.
+ # Use the optional parameter to discover if a particular category or
+ # categories are available on the system. 1 is returned if the global
+ # criteria described in the previous paragraph are true, AND if all the
+ # specified categories are available on the platform and Configured to be
+ # used. Otherwise 0 is returned. The parameter is either a single POSIX
+ # locale category or a reference to a list of them. Each category must be
+ # its name as a string, like 'LC_TIME' (the initial 'LC_' is optional), or
+ # the number this platform uses to signify the category (e.g.,
+ # 'locales_enabled(&POSIX::LC_CTYPE)'
#
- # This optional parameter denotes which POSIX locale categories must be
- # available on the platform. If any aren't available, this function
- # returns 0; otherwise it returns 1 and changes the list for the caller so
- # that any category names are converted into their equivalent numbers, and
- # sorts it to match the expectations of _trylocale.
+ # When the function returns 1 and a parameter was specified as a list
+ # reference, the reference will be altered on return to point to an
+ # equivalent list such that the categories are numeric instead of strings
+ # and sorted to meet the input expectations of _trylocale().
#
- # It is acceptable for the second parameter to be just a simple scalar
- # denoting a single category (either name or number). No conversion into
- # a number is done in this case.
+ # It is a fatal error to call this with something that isn't a known
+ # category to this file. If this happens, look first for a typo, and
+ # second if you are using a category unknown to Perl. In the latter case
+ # a bug report should be submitted.
# khw cargo-culted the '?' in the pattern on the next line.
return 0 if $Config{ccflags} =~ /\bD?NO_LOCALE\b/;
@@ -235,7 +244,7 @@ sub locales_enabled(;$) {
# Done with the global possibilities. Now check if any passed in category
# is disabled.
- my $categories_ref = shift;
+ my $categories_ref = $_[0];
my $return_categories_numbers = 0;
my @categories_numbers;
my $has_LC_ALL = 0;
@@ -244,10 +253,15 @@ sub locales_enabled(;$) {
if (defined $categories_ref) {
my @local_categories_copy;
- if (ref $categories_ref) {
- @local_categories_copy = @$$categories_ref;
+ my $reftype = ref $categories_ref;
+ if ($reftype eq 'ARRAY') {
+ @local_categories_copy = @$categories_ref;
$return_categories_numbers = 1;
}
+ elsif ($reftype ne "") {
+ die "Parameter to locales_enabled() must be an ARRAY;"
+ . " instead you used a $reftype";
+ }
else { # Single category passed in
@local_categories_copy = $categories_ref;
}
@@ -306,7 +320,7 @@ sub locales_enabled(;$) {
if ($has_LC_ALL) {
push @categories_numbers, $category_number{'ALL'};
}
- $$categories_ref = \@categories_numbers;
+ $_[0]->@* = @categories_numbers;
}
return 1;