4 # This file tests interactions with locale and threads
10 require './loc_tools.pl';
11 skip_all("No locales") unless locales_enabled();
12 skip_all_without_config('useithreads');
14 eval { require POSIX; POSIX->import(qw(locale_h unistd_h)) };
16 skip_all("could not load the POSIX module"); # running minitest?
20 # reset the locale environment
21 local @ENV{'LANG', (grep /^LC_/, keys %ENV)};
23 SKIP: { # perl #127708
24 my @locales = grep { $_ !~ / ^ C \b | POSIX /x } find_locales('LC_MESSAGES');
25 skip("No valid locale to test with", 1) unless @locales;
27 local $ENV{LC_MESSAGES} = $locales[0];
29 # We're going to try with all possible error numbers on this platform
30 my $error_count = keys(%!) + 1;
39 my \@threads = map +threads->create(sub {
43 \$errnum = (\$errnum + 1) % $error_count;
46 # no-op to trigger stringification
47 next if \"\$!\" eq \"\";
50 \$_->join for splice \@threads;",
54 pass("Didn't segfault");
58 skip("POSIX version doesn't support thread-safe locale operations", 1)
59 unless ${^SAFE_LOCALES};
61 my @locales = find_locales( 'LC_NUMERIC' );
62 skip("No LC_NUMERIC locales available", 1) unless @locales;
66 for (@locales) { # prefer C for the base if available
68 setlocale(LC_NUMERIC, $_) or next;
69 my $in = 4.2; # avoid any constant folding bugs
70 if ((my $s = sprintf("%g", $in)) eq "4.2") {
73 my $radix = localeconv()->{decimal_point};
74 $comma ||= $_ if $radix eq ',';
77 last if $dot && $comma;
80 # See if multiple threads can simultaneously change the locale, and give
81 # the expected radix results. On systems without a comma radix locale,
82 # run this anyway skipping the use of that, to verify that we don't
88 use POSIX qw(locale_h);
92 my \@threads = map +threads->create(sub {
96 my \$in = 4.2; # avoid any constant folding bugs
99 setlocale(&LC_NUMERIC, '$comma');
101 \$s = sprintf('%g', \$in);
102 return 0 if (\$s ne '4,2');
105 setlocale(&LC_NUMERIC, '$dot');
106 \$s = sprintf('%g', \$in);
107 return 0 if (\$s ne '4.2');
113 \$result &= \$_->join for splice \@threads;
115 1, {}, "Verify there were no failures with simultaneous running threads"