From 84be7a40893e4bccf836835a9ace0ff8cf4f5cc8 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 1 Feb 2023 10:18:34 -0500 Subject: [PATCH] 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) ``` --- array.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/array.c b/array.c index c1cbf488b4..514eb5be77 100644 --- a/array.c +++ b/array.c @@ -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);