keep proc on the stack so it does not move
This commit is contained in:
parent
26e8db6b93
commit
ff9dc10966
@ -42,14 +42,12 @@ set_gc_hook(VALUE module, VALUE proc, rb_event_flag_t event, const char *tp_str,
|
|||||||
{
|
{
|
||||||
VALUE tpval;
|
VALUE tpval;
|
||||||
ID tp_key = rb_intern(tp_str);
|
ID tp_key = rb_intern(tp_str);
|
||||||
ID proc_key = rb_intern(proc_str);
|
|
||||||
|
|
||||||
/* disable previous keys */
|
/* disable previous keys */
|
||||||
if (rb_ivar_defined(module, tp_key) != 0 &&
|
if (rb_ivar_defined(module, tp_key) != 0 &&
|
||||||
RTEST(tpval = rb_ivar_get(module, tp_key))) {
|
RTEST(tpval = rb_ivar_get(module, tp_key))) {
|
||||||
rb_tracepoint_disable(tpval);
|
rb_tracepoint_disable(tpval);
|
||||||
rb_ivar_set(module, tp_key, Qnil);
|
rb_ivar_set(module, tp_key, Qnil);
|
||||||
rb_ivar_set(module, proc_key, Qnil);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RTEST(proc)) {
|
if (RTEST(proc)) {
|
||||||
@ -59,7 +57,6 @@ set_gc_hook(VALUE module, VALUE proc, rb_event_flag_t event, const char *tp_str,
|
|||||||
|
|
||||||
tpval = rb_tracepoint_new(0, event, gc_start_end_i, (void *)proc);
|
tpval = rb_tracepoint_new(0, event, gc_start_end_i, (void *)proc);
|
||||||
rb_ivar_set(module, tp_key, tpval);
|
rb_ivar_set(module, tp_key, tpval);
|
||||||
rb_ivar_set(module, proc_key, proc); /* GC guard */
|
|
||||||
rb_tracepoint_enable(tpval);
|
rb_tracepoint_enable(tpval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,9 +62,11 @@ class TestTracepointObj < Test::Unit::TestCase
|
|||||||
bug8492 = '[ruby-dev:47400] [Bug #8492]: infinite after_gc_start_hook reentrance'
|
bug8492 = '[ruby-dev:47400] [Bug #8492]: infinite after_gc_start_hook reentrance'
|
||||||
assert_nothing_raised(Timeout::Error, bug8492) do
|
assert_nothing_raised(Timeout::Error, bug8492) do
|
||||||
assert_in_out_err(%w[-r-test-/tracepoint], <<-'end;', /\A[1-9]/, timeout: 2)
|
assert_in_out_err(%w[-r-test-/tracepoint], <<-'end;', /\A[1-9]/, timeout: 2)
|
||||||
stress, GC.stress = GC.stress, false
|
|
||||||
count = 0
|
count = 0
|
||||||
Bug.after_gc_start_hook = proc {count += 1}
|
hook = proc {count += 1}
|
||||||
|
def run(hook)
|
||||||
|
stress, GC.stress = GC.stress, false
|
||||||
|
Bug.after_gc_start_hook = hook
|
||||||
begin
|
begin
|
||||||
GC.stress = true
|
GC.stress = true
|
||||||
3.times {Object.new}
|
3.times {Object.new}
|
||||||
@ -72,6 +74,8 @@ class TestTracepointObj < Test::Unit::TestCase
|
|||||||
GC.stress = stress
|
GC.stress = stress
|
||||||
Bug.after_gc_start_hook = nil
|
Bug.after_gc_start_hook = nil
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
run(hook)
|
||||||
puts count
|
puts count
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user