Skip to content

Commit 7d8683a

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 5e4aac5 commit 7d8683a

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

compile.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ new_child_iseq(rb_iseq_t *iseq, const NODE *const node,
12101210
rb_iseq_path(iseq), rb_iseq_realpath(iseq),
12111211
INT2FIX(line_no), parent, type, ISEQ_COMPILE_DATA(iseq)->option);
12121212
debugs("[new_child_iseq]< ---------------------------------------\n");
1213-
iseq_add_mark_object_compile_time(iseq, (VALUE)ret_iseq);
1213+
rb_ary_push(ISEQ_COMPILE_DATA(iseq)->child_iseq, (VALUE)ret_iseq);
12141214
return ret_iseq;
12151215
}
12161216

@@ -2108,6 +2108,8 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
21082108
iseq->body->insns_info = insns_info;
21092109
iseq->body->insns_info_size = insns_info_index;
21102110

2111+
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->child_iseq, 0); /* free */
2112+
21112113
return COMPILE_OK;
21122114
}
21132115

iseq.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ rb_iseq_mark(const rb_iseq_t *iseq)
207207
else if (ISEQ_COMPILE_DATA(iseq) != NULL) {
208208
const struct iseq_compile_data *const compile_data = ISEQ_COMPILE_DATA(iseq);
209209
RUBY_MARK_UNLESS_NULL(compile_data->mark_ary);
210+
RUBY_MARK_UNLESS_NULL(compile_data->child_iseq);
210211
RUBY_MARK_UNLESS_NULL(compile_data->err_info);
211212
RUBY_MARK_UNLESS_NULL(compile_data->catch_table_ary);
212213
}
@@ -402,6 +403,7 @@ prepare_iseq_build(rb_iseq_t *iseq,
402403
ISEQ_COMPILE_DATA_ALLOC(iseq);
403404
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->err_info, err_info);
404405
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->mark_ary, rb_ary_tmp_new(3));
406+
RB_OBJ_WRITE(iseq, &ISEQ_COMPILE_DATA(iseq)->child_iseq, rb_ary_tmp_new(3));
405407

406408
ISEQ_COMPILE_DATA(iseq)->storage_head = ISEQ_COMPILE_DATA(iseq)->storage_current =
407409
(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)