[前][次][番号順一覧][スレッド一覧]

ruby-changes:39170

From: nobu <ko1@a...>
Date: Wed, 15 Jul 2015 16:55:25 +0900 (JST)
Subject: [ruby-changes:39170] nobu:r51251 (trunk): encoding.c: drop dummy encoding flag

nobu	2015-07-15 16:55:08 +0900 (Wed, 15 Jul 2015)

  New Revision: 51251

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51251

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/encoding.c
    trunk/ext/-test-/string/enc_associate.c
    trunk/test/-ext-/string/test_enc_associate.rb
Index: encoding.c
===================================================================
--- encoding.c	(revision 51250)
+++ encoding.c	(revision 51251)
@@ -677,6 +677,7 @@ enc_autoload(rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/encoding.c#L677
 	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));
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51250)
+++ ChangeLog	(revision 51251)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 15 16:55:04 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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  <ko1@a...>
 
 	* vm.c (vm_make_env_each): add comments about env layout.
Index: ext/-test-/string/enc_associate.c
===================================================================
--- ext/-test-/string/enc_associate.c	(revision 51250)
+++ ext/-test-/string/enc_associate.c	(revision 51251)
@@ -7,8 +7,16 @@ bug_str_enc_associate(VALUE str, VALUE e https://github.com/ruby/ruby/blob/trunk/ext/-test-/string/enc_associate.c#L7
     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);
 }
Index: test/-ext-/string/test_enc_associate.rb
===================================================================
--- test/-ext-/string/test_enc_associate.rb	(revision 51250)
+++ test/-ext-/string/test_enc_associate.rb	(revision 51251)
@@ -9,4 +9,15 @@ class Test_StrEncAssociate < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_enc_associate.rb#L9
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]