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

ruby-changes:5149

From: knu <ko1@a...>
Date: Tue, 27 May 2008 20:19:49 +0900 (JST)
Subject: [ruby-changes:5149] Ruby:r16644 (ruby_1_8): * array.c (rb_ary_slice_bang): Return an empty array instead of

knu	2008-05-27 20:19:35 +0900 (Tue, 27 May 2008)

  New Revision: 16644

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/array.c

  Log:
    * array.c (rb_ary_slice_bang): Return an empty array instead of
      nil when pos is valid and len is adjusted from a valid value to
      zero; caught by RubySpec.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16644&r2=16643&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/array.c?r1=16644&r2=16643&diff_format=u

Index: ruby_1_8/array.c
===================================================================
--- ruby_1_8/array.c	(revision 16643)
+++ ruby_1_8/array.c	(revision 16644)
@@ -2090,18 +2090,19 @@
 	    pos += orig_len;
 	    if (pos < 0) return Qnil;
 	}
-	else if (orig_len <= pos) return Qnil;
+	else if (orig_len < pos) return Qnil;
 	if (orig_len < pos + len) {
 	    len = orig_len - pos;
 	}
+	if (len == 0) return rb_ary_new2(0);
 	arg2 = rb_ary_new4(len, RARRAY_PTR(ary)+pos);
 	RBASIC(arg2)->klass = rb_obj_class(ary);
-	rb_ary_splice(ary, pos, len, Qnil);	/* Qnil/rb_ary_new2(0) */
+	rb_ary_splice(ary, pos, len, Qnil);	/* Qundef in 1.9 */
 	return arg2;
     }
 
     if (!FIXNUM_P(arg1)) {
-	switch (rb_range_beg_len(arg1, &pos, &len, RARRAY(ary)->len, 0)) {
+	switch (rb_range_beg_len(arg1, &pos, &len, RARRAY_LEN(ary), 0)) {
 	  case Qtrue:
 	    /* valid range */
 	    goto delete_pos_len;
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 16643)
+++ ruby_1_8/ChangeLog	(revision 16644)
@@ -1,3 +1,9 @@
+Tue May 27 20:19:22 2008  Akinori MUSHA  <knu@i...>
+
+	* array.c (rb_ary_slice_bang): Return an empty array instead of
+	  nil when pos is valid and len is adjusted from a valid value to
+	  zero; caught by RubySpec.
+
 Tue May 27 19:45:20 2008  Akinori MUSHA  <knu@i...>
 
 	* numeric.c (flo_divmod): Revert the behavior change; do not

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

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