summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-24 20:21:59 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-24 20:21:59 +0000
commita412a7e00d3a2315e8cf252096b83350957e1346 (patch)
tree106eea3d7f3b542742efae167e19ed5961aa06cd /array.c
parentfa0c521a2159ed4cfa25c9898290f2ca7f17f85a (diff)
Merge from ruby_1_8.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@16583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/array.c b/array.c
index a0b608c..3026f19 100644
--- a/array.c
+++ b/array.c
@@ -2078,17 +2078,24 @@ rb_ary_slice_bang(argc, argv, ary)
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(ary)->len + pos;
+ pos += orig_len;
if (pos < 0) return Qnil;
}
- arg2 = rb_ary_subseq(ary, pos, len);
+ 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);
rb_ary_splice(ary, pos, len, Qnil); /* Qnil/rb_ary_new2(0) */
return arg2;
}