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

ruby-changes:44422

From: nobu <ko1@a...>
Date: Thu, 27 Oct 2016 09:12:54 +0900 (JST)
Subject: [ruby-changes:44422] nobu:r56495 (trunk): object.c: use converted string

nobu	2016-10-27 09:12:33 +0900 (Thu, 27 Oct 2016)

  New Revision: 56495

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

  Log:
    object.c: use converted string
    
    * object.c (rb_convert_to_integer): should not drop the converted
      string.

  Modified files:
    trunk/ChangeLog
    trunk/object.c
    trunk/test/ruby/test_integer.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56494)
+++ ChangeLog	(revision 56495)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Oct 27 09:12:32 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* object.c (rb_convert_to_integer): should not drop the converted
+	  string.
+
 Wed Oct 26 17:09:59 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/ruby.h (rb_intern): use prefixed version macro
Index: object.c
===================================================================
--- object.c	(revision 56494)
+++ object.c	(revision 56495)
@@ -2699,7 +2699,6 @@ rb_convert_to_integer(VALUE val, int bas https://github.com/ruby/ruby/blob/trunk/object.c#L2699
 	return val;
 
       case T_STRING:
-      string_conv:
 	return rb_str_to_inum(val, base, TRUE);
 
       case T_NIL:
@@ -2712,7 +2711,7 @@ rb_convert_to_integer(VALUE val, int bas https://github.com/ruby/ruby/blob/trunk/object.c#L2711
     }
     if (base != 0) {
 	tmp = rb_check_string_type(val);
-	if (!NIL_P(tmp)) goto string_conv;
+	if (!NIL_P(tmp)) return rb_str_to_inum(tmp, base, TRUE);
       arg_error:
 	rb_raise(rb_eArgError, "base specified for non string value");
     }
Index: test/ruby/test_integer.rb
===================================================================
--- test/ruby/test_integer.rb	(revision 56494)
+++ test/ruby/test_integer.rb	(revision 56495)
@@ -100,6 +100,10 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_integer.rb#L100
     assert_raise(Encoding::CompatibilityError, bug6192) {Integer("0".encode("iso-2022-jp"))}
 
     assert_raise_with_message(ArgumentError, /\u{1f4a1}/) {Integer("\u{1f4a1}")}
+
+    obj = Struct.new(:s).new(%w[42 not-an-integer])
+    def obj.to_str; s.shift; end
+    assert_equal(42, Integer(obj, 10))
   end
 
   def test_int_p

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

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