summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2020-04-03 15:28:06 +0200
committerAaron Patterson <[email protected]>2020-08-19 08:13:09 -0700
commita74df67244199d1fd1f7a20b49dd5a096d2a13a2 (patch)
tree6a13cf2a124321b187312a8e833652276838a092
parent7d01d8811b47a5af1a4a43b69b7002216103f37d (diff)
Fix ObjectSpace.trace_object_allocations_stop to not raise if the tracepoint were not initialized
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3001
-rw-r--r--ext/objspace/object_tracing.c8
-rw-r--r--test/objspace/test_objspace.rb9
2 files changed, 15 insertions, 2 deletions
diff --git a/ext/objspace/object_tracing.c b/ext/objspace/object_tracing.c
index b6ffca8bd3..4973a7535b 100644
--- a/ext/objspace/object_tracing.c
+++ b/ext/objspace/object_tracing.c
@@ -290,8 +290,12 @@ trace_object_allocations_stop(VALUE self)
}
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 e47917030a..40f1c73a51 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -164,6 +164,15 @@ class TestObjSpace < Test::Unit::TestCase
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