ruby-changes:51959
From: eregon <ko1@a...>
Date: Fri, 3 Aug 2018 23:31:47 +0900 (JST)
Subject: [ruby-changes:51959] eregon:r64174 (trunk): Revert "encoding.c (rb_enc_get_index): return -1 for non-encoding capable objects"
eregon 2018-08-03 23:31:39 +0900 (Fri, 03 Aug 2018) New Revision: 64174 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64174 Log: Revert "encoding.c (rb_enc_get_index): return -1 for non-encoding capable objects" * This reverts commit fb253d2032e51f333e6577aa4fcf0c03f9c6fc02. * The CI is failing, this seems a bug in the JSON C extension. Modified files: trunk/encoding.c trunk/spec/ruby/optional/capi/encoding_spec.rb Index: encoding.c =================================================================== --- encoding.c (revision 64173) +++ encoding.c (revision 64174) @@ -793,26 +793,24 @@ rb_enc_get_index(VALUE obj) https://github.com/ruby/ruby/blob/trunk/encoding.c#L793 obj = rb_sym2str(obj); } switch (BUILTIN_TYPE(obj)) { + as_default: + default: case T_STRING: - case T_SYMBOL: case T_REGEXP: i = enc_get_index_str(obj); break; case T_FILE: tmp = rb_funcallv(obj, rb_intern("internal_encoding"), 0, 0); - if (NIL_P(tmp)) { - tmp = rb_funcallv(obj, rb_intern("external_encoding"), 0, 0); - } - if (is_data_encoding(tmp)) { - i = enc_check_encoding(tmp); - } - break; + if (NIL_P(tmp)) obj = rb_funcallv(obj, rb_intern("external_encoding"), 0, 0); + else obj = tmp; + if (NIL_P(obj)) break; case T_DATA: if (is_data_encoding(obj)) { i = enc_check_encoding(obj); } - break; - default: + else { + goto as_default; + } break; } return i; Index: spec/ruby/optional/capi/encoding_spec.rb =================================================================== --- spec/ruby/optional/capi/encoding_spec.rb (revision 64173) +++ spec/ruby/optional/capi/encoding_spec.rb (revision 64174) @@ -147,11 +147,6 @@ describe "C-API Encoding function" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/encoding_spec.rb#L147 it "returns -1 as the index for immediates" do @s.send(@method, 1).should == -1 end - - it "returns -1 for an object without an encoding" do - obj = Object.new - @s.send(@method, obj).should == -1 - end end describe "rb_enc_set_index" do -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/