mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ObjectSpace._id2ref should check liveness.
objspace->id_to_obj_tbl can contain died objects because of lazy sweep, so that it should check liveness.
This commit is contained in:
parent
672a61b97f
commit
a96f8cecc2
2 changed files with 22 additions and 1 deletions
3
gc.c
3
gc.c
|
@ -3644,7 +3644,8 @@ id2ref(VALUE objid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st_lookup(objspace->id_to_obj_tbl, objid, &orig)) {
|
if (st_lookup(objspace->id_to_obj_tbl, objid, &orig) &&
|
||||||
|
is_live_object(objspace, orig)) {
|
||||||
return orig;
|
return orig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,26 @@ End
|
||||||
deftest_id2ref(false)
|
deftest_id2ref(false)
|
||||||
deftest_id2ref(nil)
|
deftest_id2ref(nil)
|
||||||
|
|
||||||
|
def test_id2ref_liveness
|
||||||
|
assert_normal_exit <<-EOS
|
||||||
|
ids = []
|
||||||
|
10.times{
|
||||||
|
1_000.times{
|
||||||
|
ids << 'hello'.object_id
|
||||||
|
}
|
||||||
|
objs = ids.map{|id|
|
||||||
|
begin
|
||||||
|
ObjectSpace._id2ref(id)
|
||||||
|
rescue RangeError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
}
|
||||||
|
GC.start
|
||||||
|
objs.each{|e| e.inspect}
|
||||||
|
}
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
def test_count_objects
|
def test_count_objects
|
||||||
h = {}
|
h = {}
|
||||||
ObjectSpace.count_objects(h)
|
ObjectSpace.count_objects(h)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue