ruby-changes:62653
From: Jean <ko1@a...>
Date: Thu, 20 Aug 2020 00:13:25 +0900 (JST)
Subject: [ruby-changes:62653] a74df67244 (master): Fix ObjectSpace.trace_object_allocations_stop to not raise if the tracepoint were not initialized
https://git.ruby-lang.org/ruby.git/commit/?id=a74df67244 From a74df67244199d1fd1f7a20b49dd5a096d2a13a2 Mon Sep 17 00:00:00 2001 From: Jean Boussier <jean.boussier@g...> Date: Fri, 3 Apr 2020 15:28:06 +0200 Subject: Fix ObjectSpace.trace_object_allocations_stop to not raise if the tracepoint were not initialized diff --git a/ext/objspace/object_tracing.c b/ext/objspace/object_tracing.c index b6ffca8..4973a75 100644 --- a/ext/objspace/object_tracing.c +++ b/ext/objspace/object_tracing.c @@ -290,8 +290,12 @@ trace_object_allocations_stop(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/objspace/object_tracing.c#L290 } if (arg->running == 0) { - rb_tracepoint_disable(arg->newobj_trace); - rb_tracepoint_disable(arg->freeobj_trace); + if (arg->newobj_trace != 0) { + rb_tracepoint_disable(arg->newobj_trace); + } + if (arg->freeobj_trace != 0) { + rb_tracepoint_disable(arg->freeobj_trace); + } } return Qnil; diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index e479170..40f1c73 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -164,6 +164,15 @@ class TestObjSpace < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L164 end; end + def test_trace_object_allocations_stop_first + assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + require "objspace" + # Make sure stoping before the tracepoints are initialized doesn't raise. See [Bug #17020] + ObjectSpace.trace_object_allocations_stop + end; + end + def test_trace_object_allocations ObjectSpace.trace_object_allocations_clear # clear object_table to get rid of erroneous detection for c0 Class.name -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/