diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2025-01-14 17:51:27 -0800 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2025-01-14 17:51:27 -0800 |
| commit | 745fe4cf7e0c297879b46045a4838b3e5e2dfeb9 (patch) | |
| tree | 47b6ea47ad8b24d919f32b7ccef037f53b0475b1 /test/ruby | |
| parent | 1e48631e0f318a3b73cd39bdbda4619017383aac (diff) | |
merge revision(s) 660b995365f719fa59ed6f2809bb1527e6470d14: [Backport #20915]
[Bug #20915] Fix SEGV with `TracePoint#parameters` and aliased C method
The following snippet results with a SEGV:
```ruby
C = Class.new do
alias_method :new_to_s, :to_s
end
TracePoint.new(:c_call, &:parameters).enable { C.new.new_to_s }
```
at MRI 3.3.6 and ruby 3.4.0dev
The root cause of the issue lies in the `rb_tracearg_parameters` function
within the `RUBY_EVENT_C_RETURN` branch. Specifically, when the invoked
method is an alias for a C function,
`rb_method_entry_without_refinements(..., trace_arg->called_id, ...)`
may return NULL. In that case we can fallback to `trace_arg->id`.
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_settracefunc.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index a90c885247..bf040681a1 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -93,6 +93,22 @@ class TestSetTraceFunc < Test::Unit::TestCase assert_equal([[:req]], parameters) end + def test_c_call_aliased_method + # [Bug #20915] + klass = Class.new do + alias_method :new_method, :method + end + + instance = klass.new + parameters = nil + + TracePoint.new(:c_call) do |tp| + parameters = tp.parameters + end.enable { instance.new_method(:to_s) } + + assert_equal([[:req]], parameters) + end + def test_call events = [] name = "#{self.class}\##{__method__}" |
