Skip to content

Commit

Permalink
Add RB_GC_GUARD for ast_value
Browse files Browse the repository at this point in the history
I think this change fixes the following assertion failure:

```
[BUG] unexpected rb_parser_ary_data_type (2114076960) for script lines
```

It seems that `ast_value` is collected then `rb_parser_build_script_lines_from`
touches invalid memory address.
This change prevents `ast_value` from being collected by RB_GC_GUARD.
  • Loading branch information
yui-knk committed Jun 30, 2024
1 parent a2c27ba commit 9d76a0a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion iseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ iseq_translate(rb_iseq_t *iseq)
}

rb_iseq_t *
rb_iseq_new_with_opt(const VALUE ast_value, VALUE name, VALUE path, VALUE realpath,
rb_iseq_new_with_opt(VALUE ast_value, VALUE name, VALUE path, VALUE realpath,
int first_lineno, const rb_iseq_t *parent, int isolated_depth,
enum rb_iseq_type type, const rb_compile_option_t *option,
VALUE script_lines)
Expand Down Expand Up @@ -1004,6 +1004,7 @@ rb_iseq_new_with_opt(const VALUE ast_value, VALUE name, VALUE path, VALUE realpa

rb_iseq_compile_node(iseq, node);
finish_iseq_build(iseq);
RB_GC_GUARD(ast_value);

return iseq_translate(iseq);
}
Expand Down
2 changes: 1 addition & 1 deletion vm_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ rb_iseq_t *rb_iseq_new (const VALUE ast_value, VALUE name, VALUE path, V
rb_iseq_t *rb_iseq_new_top (const VALUE ast_value, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent);
rb_iseq_t *rb_iseq_new_main (const VALUE ast_value, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt);
rb_iseq_t *rb_iseq_new_eval (const VALUE ast_value, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth);
rb_iseq_t *rb_iseq_new_with_opt(const VALUE ast_value, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth,
rb_iseq_t *rb_iseq_new_with_opt( VALUE ast_value, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth,
enum rb_iseq_type, const rb_compile_option_t*,
VALUE script_lines);

Expand Down

0 comments on commit 9d76a0a

Please sign in to comment.