Thanks to visit codestin.com
Credit goes to github.com

Skip to content

node.c (rb_ast_new): imemo_ast is WB-unprotected #4416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,13 @@ rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
return newobj_of(v0, flags, v1, v2, v3, TRUE);
}

rb_ast_t *
rb_imemo_ast_new(VALUE node_buffer)
{
VALUE flags = T_IMEMO | (imemo_ast << FL_USHIFT);
return (rb_ast_t *)newobj_of(node_buffer, flags, 0, 0, 0, FALSE);
}

static VALUE
rb_imemo_tmpbuf_new(VALUE v1, VALUE v2, VALUE v3, VALUE v0)
{
Expand Down
1 change: 1 addition & 0 deletions internal/imemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct MEMO {

typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t;
VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
struct rb_ast_struct *rb_imemo_ast_new(VALUE node_buffer);
rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
struct vm_ifunc *rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc);
void rb_strterm_mark(VALUE obj);
Expand Down
11 changes: 2 additions & 9 deletions lib/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,17 +480,10 @@ def strptime(date, format, now=self.now)
t
end

# TODO: CI failure on FreeBSD
# http://rubyci.s3.amazonaws.com/freebsd12/ruby-master/log/20210425T203001Z.fail.html.gz
# shareable_constant_value: none

MonthValue = Ractor.make_shareable({ # :nodoc:
MonthValue = { # :nodoc:
'JAN' => 1, 'FEB' => 2, 'MAR' => 3, 'APR' => 4, 'MAY' => 5, 'JUN' => 6,
'JUL' => 7, 'AUG' => 8, 'SEP' => 9, 'OCT' =>10, 'NOV' =>11, 'DEC' =>12
})

# shareable_constant_value: literal

}

#
# Parses +date+ as date-time defined by RFC 2822 and converts it to a Time
Expand Down
2 changes: 1 addition & 1 deletion node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ rb_ast_t *
rb_ast_new(void)
{
node_buffer_t *nb = rb_node_buffer_new();
rb_ast_t *ast = (rb_ast_t *)rb_imemo_new(imemo_ast, 0, 0, 0, (VALUE)nb);
rb_ast_t *ast = rb_imemo_ast_new((VALUE)nb);
return ast;
}

Expand Down
7 changes: 7 additions & 0 deletions test/ruby/test_gc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,11 @@ def test_object_ids_never_repeat
b = 1000.times.map { Object.new.object_id }
assert_empty(a & b)
end

def test_ast_node_buffer
# https://github.com/ruby/ruby/pull/4416
Module.new.class_eval do
eval((["# shareable_constant_value: literal"] + (0..100000).map {|i| "M#{ i } = {}" }).join("\n"))
end
end
end