Skip to content

Commit 6fe46ff

Browse files
eightbitraptorbyroot
authored andcommitted
When alloc size is too large, only allocate struct
1 parent 31e24a4 commit 6fe46ff

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

struct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ struct_alloc(VALUE klass)
849849
return (VALUE)st;
850850
}
851851
else {
852-
NEWOBJ_OF(st, struct RStruct, klass, flags, embedded_size, 0);
852+
NEWOBJ_OF(st, struct RStruct, klass, flags, sizeof(struct RStruct), 0);
853853

854854
st->as.heap.ptr = struct_heap_alloc((VALUE)st, n);
855855
rb_mem_clear((VALUE *)st->as.heap.ptr, n);

test/ruby/test_struct.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def test_morethan10members
4141
end
4242
end
4343

44+
def test_larger_than_largest_pool
45+
count = (GC::INTERNAL_CONSTANTS[:RVARGC_MAX_ALLOCATE_SIZE] / RbConfig::SIZEOF["void*"]) + 1
46+
list = Array(0..count)
47+
klass = @Struct.new(*list.map { |i| :"a_#{i}"})
48+
struct = klass.new(*list)
49+
assert_equal 0, struct.a_0
50+
end
51+
4452
def test_small_structs
4553
names = [:a, :b, :c, :d]
4654
1.upto(4) {|n|

0 commit comments

Comments
 (0)