1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/weakref.rb (WeakRef::@@final): use Hash#delete.

* lib/weakref.rb (WeakRef::__getobj__): examin if alive or not by
  ID_REV_MAP to deal with recycled object.  [ruby-dev:18472]

* lib/weakref.rb (WeakRef::weakref_alive?): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2002-10-10 07:00:07 +00:00
parent ca7549b203
commit 99ebeaee0a
2 changed files with 16 additions and 11 deletions

View file

@ -1,3 +1,12 @@
Thu Oct 10 15:20:18 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* lib/weakref.rb (WeakRef::@@final): use Hash#delete.
* lib/weakref.rb (WeakRef::__getobj__): examin if alive or not by
ID_REV_MAP to deal with recycled object. [ruby-dev:18472]
* lib/weakref.rb (WeakRef::weakref_alive?): ditto.
Wed Oct 9 07:11:25 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* gc.c (gc_sweep): also adjust heaps_limits when free unused heap

View file

@ -25,15 +25,15 @@ class WeakRef<Delegator
rids = ID_MAP[id]
if rids
for rid in rids
ID_REV_MAP[rid] = nil
ID_REV_MAP.delete(rid)
end
ID_MAP[id] = nil
ID_MAP.delete(id)
end
rid = ID_REV_MAP[id]
if rid
ID_REV_MAP[id] = nil
ID_REV_MAP.delete(id)
ID_MAP[rid].delete(id)
ID_MAP[rid] = nil if ID_MAP[rid].empty?
ID_MAP.delete(rid) if ID_MAP[rid].empty?
end
ensure
Thread.critical = __old_status
@ -53,11 +53,11 @@ class WeakRef<Delegator
Thread.critical = __old_status
end
ID_MAP[@__id].push self.__id__
ID_REV_MAP[self.id] = @__id
ID_REV_MAP[self.__id__] = @__id
end
def __getobj__
unless ID_MAP[@__id]
unless ID_REV_MAP[self.__id__] == @__id
raise RefError, "Illegal Reference - probably recycled", caller(2)
end
begin
@ -68,11 +68,7 @@ class WeakRef<Delegator
end
def weakref_alive?
if ID_MAP[@__id]
true
else
false
end
ID_REV_MAP[self.__id__] == @__id
end
end