diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-09-12 12:42:39 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-09-12 12:42:39 +0900 |
| commit | 48c5321dca85025b8b11e43c8db2726fccb45b9d (patch) | |
| tree | 26f72cf0dfdfae040bc92b31c99f870c8c5fcf01 /mrbgems/mruby-random/src/random.c | |
| parent | 7ea8803e06d349105c12e4470b34626b60447599 (diff) | |
| download | mruby-48c5321dca85025b8b11e43c8db2726fccb45b9d.tar.gz mruby-48c5321dca85025b8b11e43c8db2726fccb45b9d.zip | |
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.
Diffstat (limited to 'mrbgems/mruby-random/src/random.c')
| -rw-r--r-- | mrbgems/mruby-random/src/random.c | 9 |
1 files changed, 4 insertions, 5 deletions
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<n; i++) { - RARRAY_PTR(result)[i] = RARRAY_PTR(ary)[mrb_fixnum(RARRAY_PTR(result)[i])]; + mrb_ary_set(mrb, result, i, RARRAY_PTR(ary)[mrb_fixnum(RARRAY_PTR(result)[i])]); } return result; } |
