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