From a7db2c1efdbf8fc96d06f4b5692d93941ccec606 Mon Sep 17 00:00:00 2001 From: naruse Date: Wed, 18 Nov 2009 03:38:20 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 12 ++++++++++++ encoding.c | 19 +++++++++++++++---- ruby.c | 1 - test/ruby/test_encoding.rb | 10 ++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3c34ffe9a..048dc7e53d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Wed Nov 18 12:33:42 2009 NARUSE, Yui + + * 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) * 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) { diff --git a/ruby.c b/ruby.c index e471abedb5..a9632e153b 100644 --- a/ruby.c +++ b/ruby.c @@ -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