Fix ObjectSpace.trace_object_allocations_stop to not raise if the tracepoint were not initialized

This commit is contained in:
Jean Boussier 2020-04-03 15:28:06 +02:00 коммит произвёл Aaron Patterson
Родитель 7d01d8811b
Коммит a74df67244
2 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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