diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | encoding.c | 19 | ||||
-rw-r--r-- | ruby.c | 1 | ||||
-rw-r--r-- | test/ruby/test_encoding.rb | 10 |
4 files changed, 37 insertions, 5 deletions
@@ -1,3 +1,15 @@ +Wed Nov 18 12:33:42 2009 NARUSE, Yui <naruse@ruby-lang.org> + + * encoding.c (enc_set_default_encoding): reset filesytem + encoding because on resetting default_external because + Unix's filesystem encoding depends on default_external. + + * encoding.c (enc_set_filesystem_encoding): added. + + * ruby.c (process_options): don't call rb_filesystem_encoding + because filesystem encoding is reset when default_external + is reset. + Wed Nov 18 11:57:32 2009 TAKANO Mitsuhiro (takano32) <tak@no32.tk> * math.c (math_gamma): fix incorrect comparison expression. diff --git a/encoding.c b/encoding.c index 9d956337ee..bd73880944 100644 --- a/encoding.c +++ b/encoding.c @@ -1116,7 +1116,7 @@ rb_locale_encoding(void) } static int -rb_filesystem_encindex(void) +enc_set_filesystem_encoding(void) { int idx; #if defined NO_LOCALE_CHARMAP @@ -1132,8 +1132,16 @@ rb_filesystem_encindex(void) idx = rb_enc_to_index(rb_default_external_encoding()); #endif - if (rb_enc_registered("filesystem") < 0) enc_alias_internal("filesystem", idx); + enc_alias_internal("filesystem", idx); + return idx; +} +static int +rb_filesystem_encindex(void) +{ + int idx = rb_enc_registered("filesystem"); + if (idx < 0) + idx = enc_set_filesystem_encoding(); return idx; } @@ -1148,6 +1156,8 @@ struct default_encoding { rb_encoding *enc; }; +static struct default_encoding default_external = {0}; + static int enc_set_default_encoding(struct default_encoding *def, VALUE encoding, const char *name) { @@ -1169,11 +1179,12 @@ enc_set_default_encoding(struct default_encoding *def, VALUE encoding, const cha enc_alias_internal(name, def->index); } + if (def == &default_external) + enc_set_filesystem_encoding(); + return overridden; } -static struct default_encoding default_external = {0}; - rb_encoding * rb_default_external_encoding(void) { @@ -1324,7 +1324,6 @@ process_options(int argc, char **argv, struct cmdline_options *opt) enc = lenc; } rb_enc_set_default_external(rb_enc_from_encoding(enc)); - (void)rb_filesystem_encoding(); if (opt->intern.enc.index >= 0) { enc = rb_enc_from_index(opt->intern.enc.index); rb_enc_set_default_internal(rb_enc_from_encoding(enc)); diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb index 8034977f93..44419242d2 100644 --- a/test/ruby/test_encoding.rb +++ b/test/ruby/test_encoding.rb @@ -1,4 +1,5 @@ require 'test/unit' +require_relative 'envutil' class TestEncoding < Test::Unit::TestCase @@ -39,6 +40,15 @@ class TestEncoding < Test::Unit::TestCase assert_raise(ArgumentError) { Encoding.find("foobarbazqux") } assert_nothing_raised{Encoding.find("locale")} assert_nothing_raised{Encoding.find("filesystem")} + + if /(?:ms|dar)win/ !~ RUBY_PLATFORM + # Unix's filesystem encoding is default_external + assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS') + exit Encoding.find("filesystem") == Encoding::UTF_8 + Encoding.default_external = Encoding::EUC_JP + exit Encoding.find("filesystem") == Encoding::EUC_JP + EOS + end end def test_dummy_p |