Pin weakmap references
Weak map references can't move because the st_table needs their address as a key. But, we also need to remove T_NONE from the map so they aren't reused. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b84b8adc89
commit
e900bba945
14
gc.c
14
gc.c
@ -9767,10 +9767,24 @@ wmap_mark_map(st_data_t key, st_data_t val, st_data_t arg)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int
|
||||||
|
wmap_pin_obj(st_data_t key, st_data_t val, st_data_t arg)
|
||||||
|
{
|
||||||
|
rb_objspace_t *objspace = (rb_objspace_t *)arg;
|
||||||
|
VALUE obj = (VALUE)val;
|
||||||
|
if (obj && is_live_object(objspace, obj)) {
|
||||||
|
gc_pin(objspace, obj);
|
||||||
|
} else {
|
||||||
|
return ST_DELETE;
|
||||||
|
}
|
||||||
|
return ST_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmap_mark(void *ptr)
|
wmap_mark(void *ptr)
|
||||||
{
|
{
|
||||||
struct weakmap *w = ptr;
|
struct weakmap *w = ptr;
|
||||||
|
if (w->wmap2obj) st_foreach(w->wmap2obj, wmap_pin_obj, (st_data_t)&rb_objspace);
|
||||||
#if WMAP_DELETE_DEAD_OBJECT_IN_MARK
|
#if WMAP_DELETE_DEAD_OBJECT_IN_MARK
|
||||||
if (w->obj2wmap) st_foreach(w->obj2wmap, wmap_mark_map, (st_data_t)&rb_objspace);
|
if (w->obj2wmap) st_foreach(w->obj2wmap, wmap_mark_map, (st_data_t)&rb_objspace);
|
||||||
#endif
|
#endif
|
||||||
|
@ -40,14 +40,14 @@ class TestWeakRef < Test::Unit::TestCase
|
|||||||
weakrefs << WeakRef.new(obj)
|
weakrefs << WeakRef.new(obj)
|
||||||
ObjectSpace.garbage_collect
|
ObjectSpace.garbage_collect
|
||||||
end
|
end
|
||||||
#assert_nothing_raised(NoMethodError, bug7304) {
|
assert_nothing_raised(NoMethodError, bug7304) {
|
||||||
weakrefs.each do |weak|
|
weakrefs.each do |weak|
|
||||||
begin
|
begin
|
||||||
weak.foo
|
weak.foo
|
||||||
rescue WeakRef::RefError, NoMethodError
|
rescue WeakRef::RefError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
#}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_weakref_finalize
|
def test_weakref_finalize
|
||||||
|
Loading…
x
Reference in New Issue
Block a user