diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-02-01 10:18:34 -0500 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-02-02 09:17:20 -0500 |
commit | 84be7a40893e4bccf836835a9ace0ff8cf4f5cc8 (patch) | |
tree | daae07423fab03cf295137e60305701aad0f88f8 /array.c | |
parent | 3e5a77f1ae73f4a6bf7b2b868be674ab8c714c7a (diff) |
Keep shared arrays WB protected
Sharing an array will cause it to be WB unprotected due to the use
of `RARRAY_PTR`. We don't need to WB unprotect the array because we're
not writing to the buffer of the array.
The following script demonstrates this issue:
```
ary = [1] * 1000
shared = ary[10..20]
puts ObjectSpace.dump(ary)
```
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7224
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -1065,14 +1065,14 @@ ary_make_shared(VALUE ary) * on the transient heap. */ VALUE *ptr = ALLOC_N(VALUE, capa); ARY_SET_PTR(shared, ptr); - ary_memcpy(shared, 0, len, RARRAY_PTR(ary)); + ary_memcpy(shared, 0, len, RARRAY_CONST_PTR(ary)); FL_UNSET_EMBED(ary); ARY_SET_HEAP_LEN(ary, len); ARY_SET_PTR(ary, ptr); } else { - ARY_SET_PTR(shared, RARRAY_PTR(ary)); + ARY_SET_PTR(shared, RARRAY_CONST_PTR(ary)); } ARY_SET_LEN(shared, capa); |