From 28c42b4c25c48f65cd559018678a5cf34d387c24 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 15 Jul 2015 07:55:08 +0000 Subject: [PATCH] encoding.c: drop dummy encoding flag * encoding.c (enc_autoload): drop dummy encoding flag from the loaded encoding index. this flag is used only in this source. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51251 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ encoding.c | 1 + ext/-test-/string/enc_associate.c | 8 ++++++++ test/-ext-/string/test_enc_associate.rb | 11 +++++++++++ 4 files changed, 26 insertions(+) diff --git a/ChangeLog b/ChangeLog index b292f8a31a..be1936dbea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jul 15 16:55:04 2015 Nobuyoshi Nakada + + * encoding.c (enc_autoload): drop dummy encoding flag from + the loaded encoding index. this flag is used only in this + source. + Wed Jul 15 14:39:29 2015 Koichi Sasada * vm.c (vm_make_env_each): add comments about env layout. diff --git a/encoding.c b/encoding.c index fd3344b0ea..b4ee0c8de2 100644 --- a/encoding.c +++ b/encoding.c @@ -677,6 +677,7 @@ enc_autoload(rb_encoding *enc) i = enc->ruby_encoding_index; enc_register_at(i & ENC_INDEX_MASK, rb_enc_name(enc), base); ((rb_raw_encoding *)enc)->ruby_encoding_index = i; + i &= ENC_INDEX_MASK; } else { i = load_encoding(rb_enc_name(enc)); diff --git a/ext/-test-/string/enc_associate.c b/ext/-test-/string/enc_associate.c index d6614fb298..53811620a0 100644 --- a/ext/-test-/string/enc_associate.c +++ b/ext/-test-/string/enc_associate.c @@ -7,8 +7,16 @@ bug_str_enc_associate(VALUE str, VALUE enc) return rb_enc_associate(str, rb_to_encoding(enc)); } +VALUE +bug_str_encoding_index(VALUE self, VALUE str) +{ + int idx = rb_enc_get_index(str); + return INT2NUM(idx); +} + void Init_enc_associate(VALUE klass) { rb_define_method(klass, "associate_encoding!", bug_str_enc_associate, 1); + rb_define_singleton_method(klass, "encoding_index", bug_str_encoding_index, 1); } diff --git a/test/-ext-/string/test_enc_associate.rb b/test/-ext-/string/test_enc_associate.rb index 9e9c14820d..2c84f49db1 100644 --- a/test/-ext-/string/test_enc_associate.rb +++ b/test/-ext-/string/test_enc_associate.rb @@ -9,4 +9,15 @@ class Test_StrEncAssociate < Test::Unit::TestCase assert_raise(RuntimeError) {s.associate_encoding!(Encoding::US_ASCII)} assert_raise(RuntimeError) {s.associate_encoding!(Encoding::UTF_8)} end + + Encoding.list.select(&:dummy?).each do |enc| + enc = enc.name.tr('-', '_') + define_method("test_dummy_encoding_index_#{enc}") do + assert_separately(["-r-test-/string", "-", enc], <<-"end;") #do + enc = Encoding.const_get(ARGV[0]) + index = Bug::String.encoding_index(enc) + assert(index < 0xffff, "<%#x> expected but was\n<%#x>" % [index & 0xffff, index]) + end; + end + end end