Skip to content

Commit c4c4bca

Browse files
committed
Set capcity incrementally while constructing buffer
Allocating frames can trigger GC and we only want to be marking values that point to objects.
1 parent ffb9527 commit c4c4bca

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ext/stack_frames/buffer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ static VALUE buffer_initialize(VALUE self, VALUE size) {
5858
TypedData_Get_Struct(self, buffer_t, &buffer_data_type, buffer);
5959
buffer->profile_frames = ALLOC_N(VALUE, capacity);
6060
buffer->lines = ALLOC_N(int, capacity);
61-
buffer->capacity = capacity;
6261
buffer->frames = ALLOC_N(VALUE, capacity);
6362

63+
buffer->capacity = 0;
6464
for (int i = 0; i < capacity; i++) {
6565
buffer->frames[i] = stack_frame_new(self, i);
66+
buffer->capacity++;
6667
}
6768
return Qnil;
6869
}

test/stack_frames/buffer_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ def test_find
9898
assert_nil(buffer.find { |frame| false })
9999
end
100100

101+
def test_gc_stress
102+
GC.stress = true
103+
StackFrames::Buffer.new(10)
104+
ensure
105+
GC.stress = false
106+
end
107+
101108
private
102109

103110
def frame1

0 commit comments

Comments
 (0)