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

ruby-changes:34580

From: nagachika <ko1@a...>
Date: Thu, 3 Jul 2014 01:27:33 +0900 (JST)
Subject: [ruby-changes:34580] nagachika:r46661 (ruby_2_1): merge revision(s) r45858, r45859, r45860, r45861, r46638: [Backport #9811]

nagachika	2014-07-03 01:27:21 +0900 (Thu, 03 Jul 2014)

  New Revision: 46661

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

  Log:
    merge revision(s) r45858,r45859,r45860,r45861,r46638: [Backport #9811]
    
    numeric.c: indent
    
    * numeric.c (ruby_num_interval_step_size): adjust indent.
    * numeric.c (num_step_scan_args): check keyword arguments and fail
      if they conflict with positional arguments.
      [ruby-dev:48177] [Bug #9811]
    
    * numeric.c (num_step_scan_args): table argument of rb_get_kwargs() is
      array of IDs, not Symbols. [ruby-dev:48353] [Bug #9811]

  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_numeric.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 46660)
+++ ruby_2_1/ChangeLog	(revision 46661)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Thu Jul  3 01:19:50 2014  CHIKANAGA Tomoyuki  <nagachika@r...>
+
+	* numeric.c (num_step_scan_args): table argument of rb_get_kwargs() is
+	  array of IDs, not Symbols. [ruby-dev:48353] [Bug #9811]
+
+Thu Jul  3 01:19:50 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (num_step_scan_args): check keyword arguments and fail
+	  if they conflict with positional arguments.
+	  [ruby-dev:48177] [Bug #9811]
+
 Tue Jul  1 03:05:22 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* io.c (read_all): truncate the buffer before appending read data,
Index: ruby_2_1/numeric.c
===================================================================
--- ruby_2_1/numeric.c	(revision 46660)
+++ ruby_2_1/numeric.c	(revision 46661)
@@ -119,7 +119,7 @@ VALUE rb_cFixnum; https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L119
 VALUE rb_eZeroDivError;
 VALUE rb_eFloatDomainError;
 
-static VALUE sym_to, sym_by;
+static ID id_to, id_by;
 
 void
 rb_num_zerodiv(void)
@@ -1841,8 +1841,8 @@ ruby_num_interval_step_size(VALUE from, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L1841
 	VALUE result;
 	ID cmp = '>';
 	switch (rb_cmpint(rb_num_coerce_cmp(step, INT2FIX(0), id_cmp), step, INT2FIX(0))) {
-	    case 0: return DBL2NUM(INFINITY);
-	    case -1: cmp = '<'; break;
+	  case 0: return DBL2NUM(INFINITY);
+	  case -1: cmp = '<'; break;
 	}
 	if (RTEST(rb_funcall(from, cmp, 1, to))) return INT2FIX(0);
 	result = rb_funcall(rb_funcall(to, '-', 1, from), id_div, 1, step);
@@ -1853,39 +1853,55 @@ ruby_num_interval_step_size(VALUE from, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L1853
     }
 }
 
-#define NUM_STEP_SCAN_ARGS(argc, argv, to, step, hash, desc) do {	\
-    argc = rb_scan_args(argc, argv, "02:", &to, &step, &hash);		\
-    if (!NIL_P(hash)) {							\
-	step = rb_hash_aref(hash, sym_by);				\
-	to = rb_hash_aref(hash, sym_to);				\
-    }									\
-    else {								\
-	/* compatibility */						\
-        if (argc > 1 && NIL_P(step)) {				       	\
-            rb_raise(rb_eTypeError, "step must be numeric");		\
-	}								\
-	if (rb_equal(step, INT2FIX(0))) {				\
-	    rb_raise(rb_eArgError, "step can't be 0");			\
-	}								\
-    }									\
-    if (NIL_P(step)) {							\
-        step = INT2FIX(1);						\
-    }									\
-    desc = !positive_int_p(step);					\
-    if (NIL_P(to)) {							\
-        to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);		\
-    }									\
-} while (0)
+static int
+num_step_scan_args(int argc, const VALUE *argv, VALUE *to, VALUE *step)
+{
+    VALUE hash;
+    int desc;
+
+    argc = rb_scan_args(argc, argv, "02:", to, step, &hash);
+    if (!NIL_P(hash)) {
+	ID keys[2];
+	VALUE values[2];
+	keys[0] = id_to;
+	keys[1] = id_by;
+	rb_get_kwargs(hash, keys, 0, 2, values);
+	if (values[0] != Qundef) {
+	    if (argc > 0) rb_raise(rb_eArgError, "to is given twice");
+	    *to = values[0];
+	}
+	if (values[1] != Qundef) {
+	    if (argc > 1) rb_raise(rb_eArgError, "step is given twice");
+	    *step = values[1];
+	}
+    }
+    else {
+	/* compatibility */
+	if (argc > 1 && NIL_P(*step)) {
+	    rb_raise(rb_eTypeError, "step must be numeric");
+	}
+	if (rb_equal(*step, INT2FIX(0))) {
+	    rb_raise(rb_eArgError, "step can't be 0");
+	}
+    }
+    if (NIL_P(*step)) {
+	*step = INT2FIX(1);
+    }
+    desc = !positive_int_p(*step);
+    if (NIL_P(*to)) {
+	*to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY);
+    }
+    return desc;
+}
 
 static VALUE
 num_step_size(VALUE from, VALUE args, VALUE eobj)
 {
-    VALUE to, step, hash;
-    int desc;
+    VALUE to, step;
     int argc = args ? RARRAY_LENINT(args) : 0;
     VALUE *argv = args ? RARRAY_PTR(args) : 0;
 
-    NUM_STEP_SCAN_ARGS(argc, argv, to, step, hash, desc);
+    num_step_scan_args(argc, argv, &to, &step);
 
     return ruby_num_interval_step_size(from, to, step, FALSE);
 }
@@ -1946,12 +1962,12 @@ num_step_size(VALUE from, VALUE args, VA https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L1962
 static VALUE
 num_step(int argc, VALUE *argv, VALUE from)
 {
-    VALUE to, step, hash;
+    VALUE to, step;
     int desc, inf;
 
     RETURN_SIZED_ENUMERATOR(from, argc, argv, num_step_size);
 
-    NUM_STEP_SCAN_ARGS(argc, argv, to, step, hash, desc);
+    desc = num_step_scan_args(argc, argv, &to, &step);
     if (RTEST(rb_num_coerce_cmp(step, INT2FIX(0), id_eq))) {
 	inf = 1;
     }
@@ -4085,8 +4101,8 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L4101
     rb_define_method(rb_cFloat, "infinite?", flo_is_infinite_p, 0);
     rb_define_method(rb_cFloat, "finite?",   flo_is_finite_p, 0);
 
-    sym_to = ID2SYM(rb_intern("to"));
-    sym_by = ID2SYM(rb_intern("by"));
+    id_to = rb_intern("to");
+    id_by = rb_intern("by");
 }
 
 #undef rb_float_value
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 46660)
+++ ruby_2_1/version.h	(revision 46661)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
-#define RUBY_RELEASE_DATE "2014-07-01"
-#define RUBY_PATCHLEVEL 159
+#define RUBY_RELEASE_DATE "2014-07-03"
+#define RUBY_PATCHLEVEL 160
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 7
-#define RUBY_RELEASE_DAY 1
+#define RUBY_RELEASE_DAY 3
 
 #include "ruby/version.h"
 
Index: ruby_2_1/test/ruby/test_numeric.rb
===================================================================
--- ruby_2_1/test/ruby/test_numeric.rb	(revision 46660)
+++ ruby_2_1/test/ruby/test_numeric.rb	(revision 46661)
@@ -240,6 +240,14 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_numeric.rb#L240
     assert_nothing_raised { 1.step(by: nil) }
     assert_nothing_raised { 1.step(by: nil).size }
 
+    bug9811 = '[ruby-dev:48177] [Bug #9811]'
+    assert_raise(ArgumentError, bug9811) { 1.step(10, foo: nil) {} }
+    assert_raise(ArgumentError, bug9811) { 1.step(10, foo: nil).size }
+    assert_raise(ArgumentError, bug9811) { 1.step(10, to: 11) {} }
+    assert_raise(ArgumentError, bug9811) { 1.step(10, to: 11).size }
+    assert_raise(ArgumentError, bug9811) { 1.step(10, 1, by: 11) {} }
+    assert_raise(ArgumentError, bug9811) { 1.step(10, 1, by: 11).size }
+
     assert_equal(bignum*2+1, (-bignum).step(bignum, 1).size)
     assert_equal(bignum*2, (-bignum).step(bignum-1, 1).size)
 

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r45858-45861,46638


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

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