diff --git a/node.c b/node.c index 2f626cacfd..7c5e1397e6 100644 --- a/node.c +++ b/node.c @@ -1058,6 +1058,7 @@ struct node_buffer_struct { long idx, len; node_buffer_elem_t *head; node_buffer_elem_t *last; + VALUE mark_ary; }; static node_buffer_t * @@ -1068,6 +1069,7 @@ rb_node_buffer_new(void) nb->len = 16; nb->head = nb->last = (node_buffer_elem_t*) &nb[1]; nb->head->next = NULL; + nb->mark_ary = rb_ary_tmp_new(0); return nb; } @@ -1111,13 +1113,17 @@ rb_ast_delete_node(rb_ast_t *ast, NODE *n) rb_ast_t * rb_ast_new(void) { - return (rb_ast_t *)rb_imemo_new(imemo_ast, rb_ary_tmp_new(0), 0, 0, (VALUE)rb_node_buffer_new()); + node_buffer_t *nb = rb_node_buffer_new(); + VALUE mark_ary = nb->mark_ary; + rb_ast_t *ast = (rb_ast_t *)rb_imemo_new(imemo_ast, 0, 0, 0, (VALUE)nb); + RB_GC_GUARD(mark_ary); + return ast; } void rb_ast_mark(rb_ast_t *ast) { - if (ast->node_buffer) rb_gc_mark(ast->mark_ary); + if (ast->node_buffer) rb_gc_mark(ast->node_buffer->mark_ary); } void @@ -1133,11 +1139,11 @@ void rb_ast_dispose(rb_ast_t *ast) { rb_ast_free(ast); - RB_OBJ_WRITE(ast, &ast->mark_ary, Qnil); + if (ast->node_buffer) RB_OBJ_WRITE(ast, &ast->node_buffer->mark_ary, Qnil); } void rb_ast_add_mark_object(rb_ast_t *ast, VALUE obj) { - rb_ary_push(ast->mark_ary, obj); + rb_ary_push(ast->node_buffer->mark_ary, obj); } diff --git a/node.h b/node.h index 4861bdfd1a..4040d07b6c 100644 --- a/node.h +++ b/node.h @@ -474,7 +474,6 @@ typedef struct rb_ast_body_struct { typedef struct rb_ast_struct { VALUE flags; node_buffer_t *node_buffer; - VALUE mark_ary; rb_ast_body_t body; } rb_ast_t; rb_ast_t *rb_ast_new(void);