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

ruby-changes:42202

From: usa <ko1@a...>
Date: Fri, 25 Mar 2016 18:29:36 +0900 (JST)
Subject: [ruby-changes:42202] usa:r54276 (ruby_2_1): merge revision(s) 53949: [Backport #9810]

usa	2016-03-25 18:29:32 +0900 (Fri, 25 Mar 2016)

  New Revision: 54276

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

  Log:
    merge revision(s) 53949: [Backport #9810]
    
    * numeric.c (num_step_scan_args): comparison String with Numeric
      should raise TypeError. it is an invalid type, but not a
      mismatch the number of arguments.  [ruby-core:62430] [Bug #9810]

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/numeric.c
    branches/ruby_2_1/test/ruby/test_float.rb
    branches/ruby_2_1/test/ruby/test_numeric.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 54275)
+++ ruby_2_1/ChangeLog	(revision 54276)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Fri Mar 25 18:26:40 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (num_step_scan_args): comparison String with Numeric
+	  should raise TypeError. it is an invalid type, but not a
+	  mismatch the number of arguments.  [ruby-core:62430] [Bug #9810]
+
 Fri Mar 25 18:24:04 2016  Victor Nawothnig  <Victor.Nawothnig@g...>
 
 	* parse.y (parse_numvar): NTH_REF must be less than a half of
Index: ruby_2_1/test/ruby/test_numeric.rb
===================================================================
--- ruby_2_1/test/ruby/test_numeric.rb	(revision 54275)
+++ ruby_2_1/test/ruby/test_numeric.rb	(revision 54276)
@@ -247,8 +247,8 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_numeric.rb#L247
     assert_raise(ArgumentError) { 1.step(10, 1, 0).size }
     assert_raise(ArgumentError) { 1.step(10, 0) { } }
     assert_raise(ArgumentError) { 1.step(10, 0).size }
-    assert_raise(ArgumentError) { 1.step(10, "1") { } }
-    assert_raise(ArgumentError) { 1.step(10, "1").size }
+    assert_raise(TypeError) { 1.step(10, "1") { } }
+    assert_raise(TypeError) { 1.step(10, "1").size }
     assert_raise(TypeError) { 1.step(10, nil) { } }
     assert_raise(TypeError) { 1.step(10, nil).size }
     assert_nothing_raised { 1.step(by: 0, to: nil) }
Index: ruby_2_1/test/ruby/test_float.rb
===================================================================
--- ruby_2_1/test/ruby/test_float.rb	(revision 54275)
+++ ruby_2_1/test/ruby/test_float.rb	(revision 54276)
@@ -558,7 +558,7 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_float.rb#L558
   end
 
   def test_num2dbl
-    assert_raise(ArgumentError) do
+    assert_raise(TypeError) do
       1.0.step(2.0, "0.5") {}
     end
     assert_raise(TypeError) do
Index: ruby_2_1/numeric.c
===================================================================
--- ruby_2_1/numeric.c	(revision 54275)
+++ ruby_2_1/numeric.c	(revision 54276)
@@ -253,6 +253,12 @@ coerce_rescue(VALUE *x) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L253
     return Qnil;		/* dummy */
 }
 
+static VALUE
+coerce_rescue_quiet(VALUE arg, VALUE errinfo)
+{
+    return Qundef;
+}
+
 static int
 do_coerce(VALUE *x, VALUE *y, int err)
 {
@@ -1864,6 +1870,34 @@ ruby_num_interval_step_size(VALUE from, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L1870
     }
 }
 
+static VALUE
+num_step_compare_with_zero(VALUE num)
+{
+    VALUE zero = INT2FIX(0);
+    return rb_check_funcall(num, '>', 1, &zero);
+}
+
+static int
+num_step_negative_p(VALUE num)
+{
+    const ID mid = '<';
+    VALUE r;
+
+    if (FIXNUM_P(num)) {
+	if (method_basic_p(rb_cFixnum))
+	    return (SIGNED_VALUE)num < 0;
+    }
+    else if (RB_TYPE_P(num, T_BIGNUM)) {
+	if (method_basic_p(rb_cBignum))
+	    return RBIGNUM_NEGATIVE_P(num);
+    }
+    r = rb_rescue(num_step_compare_with_zero, num, coerce_rescue_quiet, Qnil);
+    if (r == Qundef) {
+	coerce_failed(num, INT2FIX(0));
+    }
+    return !RTEST(r);
+}
+
 static int
 num_step_scan_args(int argc, const VALUE *argv, VALUE *to, VALUE *step)
 {
@@ -1898,7 +1932,7 @@ num_step_scan_args(int argc, const VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L1932
     if (NIL_P(*step)) {
 	*step = INT2FIX(1);
     }
-    desc = !positive_int_p(*step);
+    desc = num_step_negative_p(*step);
     if (NIL_P(*to)) {
 	*to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);
     }
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 54275)
+++ ruby_2_1/version.h	(revision 54276)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.9"
 #define RUBY_RELEASE_DATE "2016-03-25"
-#define RUBY_PATCHLEVEL 473
+#define RUBY_PATCHLEVEL 474
 
 #define RUBY_RELEASE_YEAR 2016
 #define RUBY_RELEASE_MONTH 3

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r53949


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

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