ruby-changes:5064
From: knu <ko1@a...>
Date: Fri, 23 May 2008 18:01:44 +0900 (JST)
Subject: [ruby-changes:5064] Ruby:r16559 (trunk): * array.c (rb_ary_slice_bang): Be consistent with Array#slice()
knu 2008-05-23 18:01:19 +0900 (Fri, 23 May 2008) New Revision: 16559 Modified files: trunk/ChangeLog trunk/array.c Log: * array.c (rb_ary_slice_bang): Be consistent with Array#slice() and String#slice!(). Just return nil when a negative length or out of boundary index is given instead of raising an exception via internal functions. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=16559&r2=16558&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16559&r2=16558&diff_format=u Index: array.c =================================================================== --- array.c (revision 16558) +++ array.c (revision 16559) @@ -1803,18 +1803,21 @@ rb_ary_slice_bang(int argc, VALUE *argv, VALUE ary) { VALUE arg1, arg2; - long pos, len; + long pos, len, orig_len; if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) { pos = NUM2LONG(arg1); len = NUM2LONG(arg2); delete_pos_len: + if (len < 0) return Qnil; + orig_len = RARRAY_LEN(ary); if (pos < 0) { - pos = RARRAY_LEN(ary) + pos; + pos += orig_len; if (pos < 0) return Qnil; } - if (RARRAY_LEN(ary) < len || RARRAY_LEN(ary) < pos + len) { - len = RARRAY_LEN(ary) - pos; + else if (orig_len <= pos) return Qnil; + if (orig_len < pos + len) { + len = orig_len - pos; } arg2 = rb_ary_new4(len, RARRAY_PTR(ary)+pos); RBASIC(arg2)->klass = rb_obj_class(ary); Index: ChangeLog =================================================================== --- ChangeLog (revision 16558) +++ ChangeLog (revision 16559) @@ -1,3 +1,10 @@ +Fri May 23 17:55:11 2008 Akinori MUSHA <knu@i...> + + * array.c (rb_ary_slice_bang): Be consistent with Array#slice() + and String#slice!(). Just return nil when a negative length or + out of boundary index is given instead of raising an exception + via internal functions. + Fri May 23 16:44:34 2008 Akinori MUSHA <knu@i...> * enumerator.c (Init_Enumerator): Override -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/