Skip to content

Commit

Permalink
check an NSArray object whether is mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jul 4, 2012
1 parent 281300f commit 76f061c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
13 changes: 12 additions & 1 deletion NSArray.m
Expand Up @@ -1209,7 +1209,7 @@
rary_elt_set(ary, offset, item);
}
else {
[(id)ary replaceObjectAtIndex:(NSUInteger)offset withObject:RB2OC(item)];
TRY_MOP([(id)ary replaceObjectAtIndex:(NSUInteger)offset withObject:RB2OC(item)]);
}
}

Expand Down Expand Up @@ -1322,6 +1322,17 @@
return result;
}

void
rb_ary_modify(VALUE ary)
{
if (IS_RARY(ary)) {
rary_modify(ary);
}
else {
CHECK_MUTABLE((id)ary);
}
}

VALUE
rb_ary_dup(VALUE ary)
{
Expand Down
8 changes: 0 additions & 8 deletions array.h
Expand Up @@ -131,14 +131,6 @@ rary_push(VALUE ary, VALUE item)
RARY(ary)->len++;
}

static inline void
rb_ary_modify(VALUE ary)
{
if (IS_RARY(ary)) {
rary_modify(ary);
}
}

static inline VALUE
to_ary(VALUE ary)
{
Expand Down
1 change: 1 addition & 0 deletions include/ruby/intern.h
Expand Up @@ -43,6 +43,7 @@ VALUE rb_ary_freeze(VALUE);
VALUE rb_ary_aref(int, VALUE *, VALUE);
VALUE rb_ary_subseq(VALUE, long, long);
void rb_ary_store(VALUE, long, VALUE);
void rb_ary_modify(VALUE ary);
VALUE rb_ary_dup(VALUE);
VALUE rb_ary_to_ary(VALUE);
VALUE rb_ary_push(VALUE, VALUE);
Expand Down

0 comments on commit 76f061c

Please sign in to comment.