summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-10 15:08:31 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-10 15:08:31 +0000
commitb0388e77e3668973d291f0d6fec3c4401c15c8df (patch)
tree4b78a26576e6415c7c5891a210470aea25962202 /array.c
parent39a6f7e34e5657cfa775c1108f7efecf196128ea (diff)
* array.c (rb_ary_slice_bang): If an invalid negative index (<=
-size) is given, do not raise an exception but return nil just like slice() does. * test/ruby/test_array.rb (TestArray::test_slice, TestArray::test_slice!): Pull in test cases from trunk. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@14184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/array.c b/array.c
index 44ca19a..c3aeefe 100644
--- a/array.c
+++ b/array.c
@@ -1963,14 +1963,25 @@ rb_ary_slice_bang(argc, argv, ary)
delete_pos_len:
if (pos < 0) {
pos = RARRAY(ary)->len + pos;
+ if (pos < 0) return Qnil;
}
arg2 = rb_ary_subseq(ary, pos, len);
rb_ary_splice(ary, pos, len, Qnil); /* Qnil/rb_ary_new2(0) */
return arg2;
}
- if (!FIXNUM_P(arg1) && rb_range_beg_len(arg1, &pos, &len, RARRAY(ary)->len, 1)) {
- goto delete_pos_len;
+ if (!FIXNUM_P(arg1)) {
+ switch (rb_range_beg_len(arg1, &pos, &len, RARRAY_LEN(ary), 0)) {
+ case Qtrue:
+ /* valid range */
+ goto delete_pos_len;
+ case Qnil:
+ /* invalid range */
+ return Qnil;
+ default:
+ /* not a range */
+ break;
+ }
}
return rb_ary_delete_at(ary, NUM2LONG(arg1));