summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-27 11:19:35 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-27 11:19:35 +0000
commitc8b99039e6c368d78a85c3c056e5e5dfd00285b6 (patch)
treed0290f2b6b86c5f14c3290c6dfa823bda1b92704 /array.c
parent78287c3d2e570c3ffd6eaf4a73be7135e23bf40a (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/array.c b/array.c
index 3026f195c8..fcbb7d4c30 100644
--- a/array.c
+++ b/array.c
@@ -2090,18 +2090,19 @@ rb_ary_slice_bang(argc, argv, ary)
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;