summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2015-09-06 10:24:45 -0600
committerKarl Williamson <khw@cpan.org>2015-09-08 10:05:56 -0600
commit51cdbd7cf1dd4d8b5b25f19d5d60fa1f1b672468 (patch)
tree6168cbcd1d58feda6022d97f07259c5c99d305fa
parentbbc981342c254b86d5bc82e5175169b68f0e59ce (diff)
downloadperl-51cdbd7cf1dd4d8b5b25f19d5d60fa1f1b672468.tar.gz
lib/locale.pm: Add an assertion
It turns out that the code assumes that the values for LC_CTYPE, LC_MESSAGES, ... are small non-negative numbers, as a bit position is reserved for each of these. It's better to make this assumption explicit rather than getting hard-to-find failures. (LC_ALL doesn't have to be of this form, and is in fact -1 on AIX)
-rw-r--r--lib/locale.pm14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/locale.pm b/lib/locale.pm
index 9cc243f86c..53c01ffd37 100644
--- a/lib/locale.pm
+++ b/lib/locale.pm
@@ -102,10 +102,20 @@ sub import {
}
# Map our names to the ones defined by POSIX
- $arg = "LC_" . uc($arg);
+ my $LC = "LC_" . uc($arg);
- my $bit = eval "&POSIX::$arg";
+ my $bit = eval "&POSIX::$LC";
if (defined $bit) {
+
+ # Verify our assumption.
+ if (! ($bit >= 0 && $bit < 31)) {
+ require Carp;
+ Carp::croak("Cannot have ':$arg' parameter to 'use locale'"
+ . " on this platform. Use the 'perlbug' utility"
+ . " to report this problem, or send email to"
+ . " 'perlbug\@perl.org'. $LC=$bit");
+ }
+
# 1 is added so that the pseudo-category :characters, which is
# -1, comes out 0.
$^H{locale} |= 1 << ($bit + 1);