Skip to content

Loading…

POSIX::setlocale fails on system without locales (Android) #442

Merged
merged 2 commits into from

3 participants

@dex4er

I'm getting an error on Android. This system has poor support for locales, so the Perl is usually compiled with -Ui_locale flag.

t/Plack-Middleware/simple_logger.t ................. 1/? 
#   Failed test at t/Plack-Middleware/simple_logger.t line 24.
#                   'Your vendor has not defined POSIX macro LC_ALL, used at /storage/sdcard0/home/.cpanm/work/1389472371.9142/Plack-1.0030/blib/lib/Plack/Middleware/SimpleLogger.pm line 32
# '
#     doesn't match '(?^:This is info)'
# Looks like you failed 1 test of 2.
t/Plack-Middleware/simple_logger.t ................. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests 

It is built cleanly with this patch.

Unfortunately, Plack still doesn't work well on Android because there is some other problem which test units didn't detect:

$ plackup -e 'sub {[200, [$^O], []]}' -E test
Use of uninitialized value $v in concatenation (.) or string at /data/perl/lib/site_perl/5.18.2/HTTP/Server/PSGI.pm line 204.

returns

$ telnet htc-one-s 5000
Trying 192.168.1.84...
Connected to htc-one-s.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.0 200 OK
Date: Sat, 11 Jan 2014 21:05:53 GMT
Server: HTTP::Server::PSGI
linux: Content-Length
0: 

Connection closed by foreign host.

I'll provide proper patch if I track this problem.

@coveralls

Coverage Status

Coverage decreased (-0.04%) when pulling 59877cf on dex4er:porting/no_locale into b17e171 on plack:master.

@dex4er

Oh god, I'm stupid :)

$ plackup -e 'sub {[200, [], [$^O]]}'

and

$ GET http://htc-one-s:5000/
linux

It means that Plack DOES work on Android correctly :)

@dex4er

Another attempt to fix this issue is to check $Config{d_setocale} and call POSIX::setlocale if it is true.

See https://rt.cpan.org/Public/Bug/Display.html?id=92051 for details.

@miyagawa
plack member

I understand and support the intent of the patch, but am not sure if i support the three uses of eval when theoretically only one is necessary.

@dex4er

There can be more clean way. I'll provide proper fixes real soon.

@dex4er

More safe handling of missing locales applied. Regards.

@coveralls

Coverage Status

Coverage decreased (-0.23%) when pulling 7908e03 on dex4er:porting/no_locale into b17e171 on plack:master.

@miyagawa miyagawa merged commit c5a3896 into plack:master

1 check passed

Details default The Travis CI build passed
@dex4er

Thank you!

If you want to play with Perl on Android, there is a small howto: https://github.com/dex4er/perl5-android/wiki

@dex4er dex4er deleted the dex4er:porting/no_locale branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 11, 2014
  1. @dex4er
Commits on Jan 16, 2014
  1. @dex4er
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/Plack/Middleware/SimpleLogger.pm
View
12 lib/Plack/Middleware/SimpleLogger.pm
@@ -1,6 +1,7 @@
package Plack::Middleware::SimpleLogger;
use strict;
use parent qw(Plack::Middleware);
+use Config ();
use Plack::Util::Accessor qw(level);
use POSIX ();
use Scalar::Util ();
@@ -29,10 +30,15 @@ sub call {
}
sub format_time {
- my $old_locale = POSIX::setlocale(&POSIX::LC_ALL);
- POSIX::setlocale(&POSIX::LC_ALL, 'C');
+ my $old_locale;
+ if ( $Config::config{d_setlocale} ) {
+ $old_locale = POSIX::setlocale(&POSIX::LC_ALL);
+ POSIX::setlocale(&POSIX::LC_ALL, 'C');
+ }
my $out = POSIX::strftime(@_);
- POSIX::setlocale(&POSIX::LC_ALL, $old_locale);
+ if ( $Config::config{d_setlocale} ) {
+ POSIX::setlocale(&POSIX::LC_ALL, $old_locale);
+ };
return $out;
}
Something went wrong with that request. Please try again.