summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-12-24 16:23:10 -0500
committerPeter Zhu <peter@peterzhu.ca>2023-12-24 20:37:59 -0500
commit70618a48f7f9f12943e963bf121b56af4153f394 (patch)
treece963477e7961c1549bbcc68018f33448100ece6 /gc.c
parent260bf60e52ffdfa625be1153624b0d123fc305f8 (diff)
Fix off-by-one error for declarative marking
The for loops for marking and reference updating declaratively marked TypedData objects did not mark/reference update the very last element. When RGENGC_CHECK_MODE is turned on, this caused the test in Enumerator to fail with: tool/lib/test/unit/testcase.rb:173:in `rescue in run': failed to allocate memory (NoMemoryError)
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/gc.c b/gc.c
index b14550f88c..6d62ca293d 100644
--- a/gc.c
+++ b/gc.c
@@ -7444,7 +7444,7 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj)
if (RTYPEDDATA_P(obj) && gc_declarative_marking_p(any->as.typeddata.type)) {
size_t *offset_list = (size_t *)RANY(obj)->as.typeddata.type->function.dmark;
- for (size_t offset = *offset_list; *offset_list != RUBY_REF_END; offset = *offset_list++) {
+ for (size_t offset = *offset_list; offset != RUBY_REF_END; offset = *offset_list++) {
rb_gc_mark_movable(*(VALUE *)((char *)ptr + offset));
}
}
@@ -10814,7 +10814,7 @@ gc_update_object_references(rb_objspace_t *objspace, VALUE obj)
if (RTYPEDDATA_P(obj) && gc_declarative_marking_p(any->as.typeddata.type)) {
size_t *offset_list = (size_t *)RANY(obj)->as.typeddata.type->function.dmark;
- for (size_t offset = *offset_list; *offset_list != RUBY_REF_END; offset = *offset_list++) {
+ for (size_t offset = *offset_list; offset != RUBY_REF_END; offset = *offset_list++) {
VALUE *ref = (VALUE *)((char *)ptr + offset);
if (SPECIAL_CONST_P(*ref)) continue;
*ref = rb_gc_location(*ref);