зеркало из https://github.com/github/ruby.git
When alloc size is too large, only allocate struct
This commit is contained in:
Родитель
31e24a42f3
Коммит
6fe46ff967
2
struct.c
2
struct.c
|
@ -849,7 +849,7 @@ struct_alloc(VALUE klass)
|
|||
return (VALUE)st;
|
||||
}
|
||||
else {
|
||||
NEWOBJ_OF(st, struct RStruct, klass, flags, embedded_size, 0);
|
||||
NEWOBJ_OF(st, struct RStruct, klass, flags, sizeof(struct RStruct), 0);
|
||||
|
||||
st->as.heap.ptr = struct_heap_alloc((VALUE)st, n);
|
||||
rb_mem_clear((VALUE *)st->as.heap.ptr, n);
|
||||
|
|
|
@ -41,6 +41,14 @@ module TestStruct
|
|||
end
|
||||
end
|
||||
|
||||
def test_larger_than_largest_pool
|
||||
count = (GC::INTERNAL_CONSTANTS[:RVARGC_MAX_ALLOCATE_SIZE] / RbConfig::SIZEOF["void*"]) + 1
|
||||
list = Array(0..count)
|
||||
klass = @Struct.new(*list.map { |i| :"a_#{i}"})
|
||||
struct = klass.new(*list)
|
||||
assert_equal 0, struct.a_0
|
||||
end
|
||||
|
||||
def test_small_structs
|
||||
names = [:a, :b, :c, :d]
|
||||
1.upto(4) {|n|
|
||||
|
|
Загрузка…
Ссылка в новой задаче