Skip to content

Commit 5f62751

Browse files
committed
Store in-flight child iseq in an array
This prevents them from being GC'd during compilation. Then we nil out the array later so it gets freed.
1 parent d2189d8 commit 5f62751

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

compile.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ new_child_iseq(rb_iseq_t *iseq, const NODE *const node,
12261226
rb_iseq_path(iseq), rb_iseq_realpath(iseq),
12271227
INT2FIX(line_no), parent, type, ISEQ_COMPILE_DATA(iseq)->option);
12281228
debugs("[new_child_iseq]< ---------------------------------------\n");
1229-
iseq_add_mark_object_compile_time(iseq, (VALUE)ret_iseq);
1229+
rb_ary_push(ISEQ_COMPILE_DATA(iseq)->child_iseq, (VALUE)ret_iseq);
12301230
return ret_iseq;
12311231
}
12321232

@@ -1241,7 +1241,7 @@ new_child_iseq_ifunc(rb_iseq_t *iseq, const struct vm_ifunc *ifunc,
12411241
rb_iseq_path(iseq), rb_iseq_realpath(iseq),
12421242
INT2FIX(line_no), parent, type, ISEQ_COMPILE_DATA(iseq)->option);
12431243
debugs("[new_child_iseq_ifunc]< ---------------------------------------\n");
1244-
iseq_add_mark_object(iseq, (VALUE)ret_iseq);
1244+
rb_ary_push(ISEQ_COMPILE_DATA(iseq)->child_iseq, (VALUE)ret_iseq);
12451245
return ret_iseq;
12461246
}
12471247

@@ -2161,6 +2161,8 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
21612161
iseq->body->insns_info.positions = positions;
21622162
iseq->body->insns_info.size = insns_info_index;
21632163

2164+
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->child_iseq, 0); /* free */
2165+
21642166
return COMPILE_OK;
21652167
}
21662168

iseq.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ rb_iseq_mark(const rb_iseq_t *iseq)
218218
else if (ISEQ_COMPILE_DATA(iseq) != NULL) {
219219
const struct iseq_compile_data *const compile_data = ISEQ_COMPILE_DATA(iseq);
220220
RUBY_MARK_UNLESS_NULL(compile_data->mark_ary);
221+
RUBY_MARK_UNLESS_NULL(compile_data->child_iseq);
221222
RUBY_MARK_UNLESS_NULL(compile_data->err_info);
222223
RUBY_MARK_UNLESS_NULL(compile_data->catch_table_ary);
223224
}
@@ -413,6 +414,7 @@ prepare_iseq_build(rb_iseq_t *iseq,
413414
ISEQ_COMPILE_DATA_ALLOC(iseq);
414415
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, err_info);
415416
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->mark_ary, rb_ary_tmp_new(3));
417+
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->child_iseq, rb_ary_tmp_new(3));
416418

417419
ISEQ_COMPILE_DATA(iseq)->storage_head = ISEQ_COMPILE_DATA(iseq)->storage_current =
418420
(struct iseq_compile_data_storage *)

iseq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct iseq_compile_data {
9999
/* GC is needed */
100100
const VALUE err_info;
101101
VALUE mark_ary;
102+
VALUE child_iseq;
102103
const VALUE catch_table_ary; /* Array */
103104

104105
/* GC is not needed */

0 commit comments

Comments
 (0)