8000 node.c (rb_ast_new): imemo_ast is WB-unprotected · ruby/ruby@86b5e80 · GitHub
[go: up one dir, main page]

Skip to content

Commit 86b5e80

Browse files
committed
node.c (rb_ast_new): imemo_ast is WB-unprotected
Previously imemo_ast was handled as WB-protected which caused a segfault of the following code: ``` M0 = {} M1 = {} ... M100000 = {} ``` My analysis is here: `shareable_constant_value: literal` creates many Hash instances during parsing, and add them to node_buffer of imemo_ast. However, the contents are missed because imemo_ast is incorrectly WB-protected. This changeset makes imemo_ast as WB-unprotected.
1 parent 4ca2719 commit 86b5e80

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

gc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,13 @@ rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
24352435
return newobj_of(v0, flags, v1, v2, v3, TRUE);
24362436
}
24372437

2438+
VALUE
2439+
rb_wb_unprotected_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
2440+
{
2441+
VALUE flags = T_IMEMO | (type << FL_USHIFT);
2442+
return newobj_of(v0, flags, v1, v2, v3, FALSE);
2443+
}
2444+
24382445
static VALUE
24392446
rb_imemo_tmpbuf_new(VALUE v1, VALUE v2, VALUE v3, VALUE v0)
24402447
{

internal/imemo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct MEMO {
130130

131131
typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t;
132132
VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
133+
VALUE rb_wb_unprotected_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
133134
rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
134135
struct vm_ifunc *rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc);
135136
void rb_strterm_mark(VALUE obj);

node.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ rb_ast_t *
12991299
rb_ast_new(void)
13001300
{
13011301
node_buffer_t *nb = rb_node_buffer_new();
1302-
rb_ast_t *ast = (rb_ast_t *)rb_imemo_new(imemo_ast, 0, 0, 0, (VALUE)nb);
1302+
rb_ast_t *ast = (rb_ast_t *)rb_wb_unprotected_imemo_new(imemo_ast, 0, 0, 0, (VALUE)nb);
13031303
return ast;
13041304
}
13051305

0 commit comments

Comments
 (0)
0