[#18440] racc segv revisited — "Akinori MUSHA" <knu@...>

 次のバグの件なんですが、現時点では原因究明を含めて未解決という

24 messages 2002/10/02
[#18617] Re: racc segv revisited — "Akinori MUSHA" <knu@...> 2002/11/02

At Wed, 2 Oct 2002 23:19:59 +0900,

[ruby-dev:18474] Re: weakref

From: nobu.nakada@...
Date: 2002-10-10 05:20:43 UTC
List: ruby-dev #18474
なかだです。

At Thu, 10 Oct 2002 13:35:15 +0900,
Tanaka Akira wrote:
> ということを試すと、70676778 が 2回出てきて、それにともなって weakref
> が復活する(weakref_alive? が true -> false -> true と変化する)ことがあ
> るようなんですが、これはそういうものなんでしょうか。

weakref_alive?の判定方法をこうしてみるのが有効そうな気がします。
あとnilの代入よりもHash#deleteを使うべきかと。


Index: weakref.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/weakref.rb,v
retrieving revision 1.8
diff -u -2 -p -r1.8 weakref.rb
--- weakref.rb	8 Nov 2001 06:43:12 -0000	1.8
+++ weakref.rb	10 Oct 2002 05:19:37 -0000
@@ -26,13 +26,13 @@ class WeakRef<Delegator
       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
@@ -54,9 +54,9 @@ class WeakRef<Delegator
     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
@@ -69,9 +69,5 @@ class WeakRef<Delegator
 
   def weakref_alive?
-    if ID_MAP[@__id]
-      true
-    else
-      false
-    end
+    ID_REV_MAP[self.__id__] == @__id
   end
 end


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread