[前][次][番号順一覧][スレッド一覧]

ruby-changes:60582

From: Alan <ko1@a...>
Date: Mon, 30 Mar 2020 19:15:45 +0900 (JST)
Subject: [ruby-changes:60582] b5fa156b79 (ruby_2_7): Clear all trace events during teardown

https://git.ruby-lang.org/ruby.git/commit/?id=b5fa156b79

From b5fa156b7907b8ea1baf8b9f0cb6a66b0fecb3d4 Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Wed, 11 Mar 2020 10:37:14 -0400
Subject: Clear all trace events during teardown

Since 0c2d81dada, not all trace events are cleared during VM teardown.
This causes a crash when there is a tracepoint for
`RUBY_INTERNAL_EVENT_GC_EXIT` active during teardown.

The commit looks like a refactoring commit so I think this change was
unintentional.

[Bug #16682]

(cherry picked from commit b385f7670ffa420790bc548747fa4b58c4c5d8f6)

diff --git a/eval.c b/eval.c
index f2fde81..08f7ba9 100644
--- a/eval.c
+++ b/eval.c
@@ -26,6 +26,7 @@ https://github.com/ruby/ruby/blob/trunk/eval.c#L26
 
 NORETURN(void rb_raise_jump(VALUE, VALUE));
 void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec);
+void rb_ec_clear_all_trace_func(const rb_execution_context_t *ec);
 
 static int rb_ec_cleanup(rb_execution_context_t *ec, volatile int ex);
 static int rb_ec_exec_node(rb_execution_context_t *ec, void *n);
@@ -140,7 +141,7 @@ rb_ec_teardown(rb_execution_context_t *ec) https://github.com/ruby/ruby/blob/trunk/eval.c#L141
     }
     EC_POP_TAG();
     rb_ec_exec_end_proc(ec);
-    rb_ec_clear_current_thread_trace_func(ec);
+    rb_ec_clear_all_trace_func(ec);
 }
 
 static void
diff --git a/ext/-test-/tracepoint/gc_hook.c b/ext/-test-/tracepoint/gc_hook.c
index 2e695a9..54b469d 100644
--- a/ext/-test-/tracepoint/gc_hook.c
+++ b/ext/-test-/tracepoint/gc_hook.c
@@ -73,8 +73,16 @@ set_after_gc_start(VALUE module, VALUE proc) https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/gc_hook.c#L73
 		       "__set_after_gc_start_tpval__", "__set_after_gc_start_proc__");
 }
 
+static VALUE
+start_after_gc_exit(VALUE module, VALUE proc)
+{
+    return set_gc_hook(module, proc, RUBY_INTERNAL_EVENT_GC_EXIT,
+                       "__set_after_gc_exit_tpval__", "__set_after_gc_exit_proc__");
+}
+
 void
 Init_gc_hook(VALUE module)
 {
     rb_define_module_function(module, "after_gc_start_hook=", set_after_gc_start, 1);
+    rb_define_module_function(module, "after_gc_exit_hook=", start_after_gc_exit, 1);
 }
diff --git a/test/-ext-/tracepoint/test_tracepoint.rb b/test/-ext-/tracepoint/test_tracepoint.rb
index e0fafdc..60bdefd 100644
--- a/test/-ext-/tracepoint/test_tracepoint.rb
+++ b/test/-ext-/tracepoint/test_tracepoint.rb
@@ -79,4 +79,8 @@ class TestTracepointObj < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/tracepoint/test_tracepoint.rb#L79
     end
   end
 
+  def test_teardown_with_active_GC_end_hook
+    assert_separately([], 'require("-test-/tracepoint"); Bug.after_gc_exit_hook = proc {}')
+  end
+
 end
diff --git a/vm_trace.c b/vm_trace.c
index 9a60481..241b929 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -276,6 +276,12 @@ rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L276
     rb_threadptr_remove_event_hook(ec, rb_ec_thread_ptr(ec), 0, Qundef);
 }
 
+void
+rb_ec_clear_all_trace_func(const rb_execution_context_t *ec)
+{
+    rb_threadptr_remove_event_hook(ec, MATCH_ANY_FILTER_TH, 0, Qundef);
+}
+
 /* invoke hooks */
 
 static void
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]