diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-12-07 15:17:14 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-12-07 15:17:14 +0000 |
commit | dc859c017d45b204533e7491a193c0d4cb1fa5ad (patch) | |
tree | 262adb2b406121a2ebb9981643a616c61472e62e | |
parent | e03d9621a6fd80d9fe4b9cb56c495c0cfc0603ce (diff) |
* lib/weakref.rb (WeakRef::__setobj__): should support
marshaling. [ruby-talk:228508]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/delegate.rb | 2 | ||||
-rw-r--r-- | lib/weakref.rb | 27 |
3 files changed, 19 insertions, 15 deletions
@@ -1,3 +1,8 @@ +Thu Dec 7 09:29:02 2006 Yukihiro Matsumoto <[email protected]> + + * lib/weakref.rb (WeakRef::__setobj__): should support + marshaling. [ruby-talk:228508] + Wed Dec 6 23:58:36 2006 Nobuyoshi Nakada <[email protected]> * Makefile.in, common.mk (NULLCMD): moved for platforms that empty diff --git a/lib/delegate.rb b/lib/delegate.rb index a961cbaad3..8574bc39ec 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -115,7 +115,7 @@ # implementation, see SimpleDelegator. # class Delegator - preserved = ["__id__", "object_id", "__send__", "__send", "__send!", "respond_to?", "send", "funcall"] + preserved = [:__id__, :object_id, :__send__, :__send, :__send!, :respond_to?, :send, :funcall] instance_methods.each do |m| next if preserved.include?(m) undef_method m diff --git a/lib/weakref.rb b/lib/weakref.rb index b1c430523b..048f06f459 100644 --- a/lib/weakref.rb +++ b/lib/weakref.rb @@ -24,7 +24,6 @@ class WeakRef<Delegator @@id_map = {} # obj -> [ref,...] @@id_rev_map = {} # ref -> obj @@final = lambda {|id| - printf "final: %p\n", id __old_status = Thread.critical Thread.critical = true begin @@ -48,19 +47,7 @@ class WeakRef<Delegator # Create a new WeakRef from +orig+. 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 - begin - Thread.critical = true - @@id_map[@__id] = [] unless @@id_map[@__id] - ensure - Thread.critical = __old_status - end - @@id_map[@__id].push self.object_id - @@id_rev_map[self.object_id] = @__id + __setobj__(orig) super end @@ -79,6 +66,18 @@ class WeakRef<Delegator end def __setobj__(obj) + @__id = obj.object_id + ObjectSpace.define_finalizer obj, @@final + ObjectSpace.define_finalizer self, @@final + __old_status = Thread.critical + begin + Thread.critical = true + @@id_map[@__id] = [] unless @@id_map[@__id] + ensure + Thread.critical = __old_status + end + @@id_map[@__id].push self.object_id + @@id_rev_map[self.object_id] = @__id end # Returns true if the referenced object still exists, and false if it has |