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)
```
This commit is contained in:
Peter Zhu 2023-02-01 10:18:34 -05:00
parent 3e5a77f1ae
commit 84be7a4089
Notes: git 2023-02-02 14:17:39 +00:00

View File

@ -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);