diff options
author | nagachika <nagachika@ruby-lang.org> | 2023-03-21 12:00:17 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2023-03-21 12:00:17 +0900 |
commit | eba3f787cbd38acf60fff6bdb450aacfc2e9c3a1 (patch) | |
tree | 823ff47ff9e0e5671f98e1cb36add1181e7a4094 | |
parent | 3efc43aace4e051f618b10e82bd82e93076dc757 (diff) | |
download | ruby-eba3f787cbd38acf60fff6bdb450aacfc2e9c3a1.tar.gz |
merge revision(s) 837ef8911c638c3e2bdb6af710de7c1fac7b5f90: [Backport #19305]
Fix crash in TracePoint c_call for removed method
trace_arg->id is the ID of the original method of an aliased method. If
the original method is removed, then the lookup will fail. We should use
trace_arg->called_id instead, which is the ID of the aliased method.
Fixes [Bug #19305]
---
test/ruby/test_settracefunc.rb | 23 +++++++++++++++++++++++
vm_trace.c | 2 +-
2 files changed, 24 insertions(+), 1 deletion(-)
-rw-r--r-- | test/ruby/test_settracefunc.rb | 23 | ||||
-rw-r--r-- | version.h | 2 | ||||
-rw-r--r-- | vm_trace.c | 16 |
3 files changed, 32 insertions, 9 deletions
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index c25debb38e..73d8aee6a2 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -50,6 +50,29 @@ class TestSetTraceFunc < Test::Unit::TestCase assert_equal([], events) end + def test_c_call_removed_method + # [Bug #19305] + klass = Class.new do + attr_writer :bar + alias_method :set_bar, :bar= + remove_method :bar= + end + + obj = klass.new + method_id = nil + parameters = nil + + TracePoint.new(:c_call) { |tp| + method_id = tp.method_id + parameters = tp.parameters + }.enable { + obj.set_bar(1) + } + + assert_equal(:bar=, method_id) + assert_equal([[:req]], parameters) + end + def test_call events = [] name = "#{self.class}\##{__method__}" @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 4 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 194 +#define RUBY_PATCHLEVEL 195 #define RUBY_RELEASE_YEAR 2023 #define RUBY_RELEASE_MONTH 3 diff --git a/vm_trace.c b/vm_trace.c index 466856341d..a9127b7811 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -903,14 +903,14 @@ rb_tracearg_parameters(rb_trace_arg_t *trace_arg) } case RUBY_EVENT_C_CALL: case RUBY_EVENT_C_RETURN: { - fill_id_and_klass(trace_arg); - if (trace_arg->klass && trace_arg->id) { - const rb_method_entry_t *me; - VALUE iclass = Qnil; - me = rb_method_entry_without_refinements(trace_arg->klass, trace_arg->id, &iclass); - return rb_unnamed_parameters(rb_method_entry_arity(me)); - } - break; + fill_id_and_klass(trace_arg); + if (trace_arg->klass && trace_arg->id) { + const rb_method_entry_t *me; + VALUE iclass = Qnil; + me = rb_method_entry_without_refinements(trace_arg->klass, trace_arg->called_id, &iclass); + return rb_unnamed_parameters(rb_method_entry_arity(me)); + } + break; } case RUBY_EVENT_RAISE: case RUBY_EVENT_LINE: |