From 48c5321dca85025b8b11e43c8db2726fccb45b9d Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 12 Sep 2014 12:42:39 +0900 Subject: constify pointer from RARRAY_PTR to detect potential write barrier bugs. if you see compiler errors due to this commit, you'd better to use array-modifying functions, e.g. mrb_ary_set() or mrb_ary_push(), otherwise you might see nasty GC bugs in the future. if you are sure what you are doing, replace `RARRAY_PTR(ary)` by `mrb_ary_ptr(ary)->ptr`. but be warned. --- mrbgems/mruby-random/src/random.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'mrbgems/mruby-random/src/random.c') diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c index 86c54bc88..3be3ac81c 100644 --- a/mrbgems/mruby-random/src/random.c +++ b/mrbgems/mruby-random/src/random.c @@ -221,8 +221,8 @@ mrb_ary_shuffle_bang(mrb_state *mrb, mrb_value ary) j = mrb_fixnum(mrb_random_mt_rand(mrb, random, mrb_fixnum_value(RARRAY_LEN(ary)))); tmp = RARRAY_PTR(ary)[i]; - RARRAY_PTR(ary)[i] = RARRAY_PTR(ary)[j]; - RARRAY_PTR(ary)[j] = tmp; + mrb_ary_ptr(ary)->ptr[i] = RARRAY_PTR(ary)[j]; + mrb_ary_ptr(ary)->ptr[j] = tmp; } } @@ -305,11 +305,10 @@ mrb_ary_sample(mrb_state *mrb, mrb_value ary) } break; } - RARRAY_PTR(result)[i] = mrb_fixnum_value(r); - RARRAY_LEN(result)++; + mrb_ary_push(mrb, result, mrb_fixnum_value(r)); } for (i=0; i