Skip to content

Commit 3b9e1dc

Browse files
tenderlovejhawthorn
andcommitted
Handle frame labels being nil after refinement
Co-authored-by: John Hawthorn <[email protected]>
1 parent fb7aa91 commit 3b9e1dc

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

ext/vernier/vernier.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ static const char *gvl_event_name(rb_event_flag_t event) {
7878
struct FrameInfo {
7979
static const char *label_cstr(VALUE frame) {
8080
VALUE label = rb_profile_frame_full_label(frame);
81+
// Currently (2025-03-22, Ruby 3.4.2) this occurs when an iseq method
82+
// entry is replaced with a refinement
83+
if (NIL_P(label)) return "(nil)";
8184
return StringValueCStr(label);
8285
}
8386

@@ -86,7 +89,7 @@ struct FrameInfo {
8689
if (NIL_P(file))
8790
file = rb_profile_frame_path(frame);
8891
if (NIL_P(file)) {
89-
return "";
92+
return "(nil)";
9093
} else {
9194
return StringValueCStr(file);
9295
}

test/test_stack_table.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,26 @@ def test_convert
144144
assert_equal expected, actual
145145
end
146146

147+
def test_replacing_with_a_refinement
148+
klass = Class.new do
149+
def foo
150+
stack_table = Vernier::StackTable.new
151+
stack_table.stack(stack_table.current_stack)
152+
end
153+
end
154+
155+
stack = klass.new.foo
156+
157+
Module.new do
158+
refine klass do
159+
def foo
160+
end
161+
end
162+
end
163+
164+
assert_includes stack[0].to_s, "(nil) at (nil)"
165+
end
166+
147167
def test_backtrace
148168
stack_table = Vernier::StackTable.new
149169
expected = caller_locations(0); index = stack_table.current_stack

0 commit comments

Comments
 (0)