summaryrefslogtreecommitdiff
path: root/lib/weakref.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-08-12 07:17:36 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-08-12 07:17:36 +0000
commitec14c2c9b925f6add71f7f4d25e0a281f8adb252 (patch)
tree1c18cec4b2c748514ac3b705b2e68feeb122337e /lib/weakref.rb
parentd3de1ac85bca8d512d2d7ca152dd3aced2fc8867 (diff)
downloadruby-ec14c2c9b925f6add71f7f4d25e0a281f8adb252.tar.gz
* numeric.c (fix_equal, fix_cmp, fix_gt, fix_ge, fix_lt, fix_le):
reduce coercing when a method knows about a operand type. [ruby-dev:26789] * lib/delegate.rb: simplifies Delegator classes; SimpleDelegator now uses method_missing for all methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/weakref.rb')
-rw-r--r--lib/weakref.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/weakref.rb b/lib/weakref.rb
index c790055d01..a398ebf1fe 100644
--- a/lib/weakref.rb
+++ b/lib/weakref.rb
@@ -18,7 +18,8 @@ class WeakRef<Delegator
@@id_map = {} # obj -> [ref,...]
@@id_rev_map = {} # ref -> obj
- @@final = lambda{|id|
+ @@final = lambda {|id|
+ printf "final: %p\n", id
__old_status = Thread.critical
Thread.critical = true
begin
@@ -42,6 +43,7 @@ class WeakRef<Delegator
def initialize(orig)
@__id = orig.object_id
+ printf "orig: %p\n", @__id
ObjectSpace.define_finalizer orig, @@final
ObjectSpace.define_finalizer self, @@final
__old_status = Thread.critical
@@ -53,7 +55,7 @@ class WeakRef<Delegator
end
@@id_map[@__id].push self.object_id
@@id_rev_map[self.object_id] = @__id
- super
+ super
end
def __getobj__
@@ -66,6 +68,8 @@ class WeakRef<Delegator
Kernel::raise RefError, "Illegal Reference - probably recycled", Kernel::caller(2)
end
end
+ def __setobj__(obj)
+ end
def weakref_alive?
@@id_rev_map[self.object_id] == @__id
@@ -73,11 +77,12 @@ class WeakRef<Delegator
end
if __FILE__ == $0
- require 'thread'
+# require 'thread'
foo = Object.new
p foo.to_s # original's class
foo = WeakRef.new(foo)
p foo.to_s # should be same class
ObjectSpace.garbage_collect
+ ObjectSpace.garbage_collect
p foo.to_s # should raise exception (recycled)
end