diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-12-07 15:15:05 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-12-07 15:15:05 +0000 |
| commit | c48ef0082c21118f63a329d2b7bef54192c63a85 (patch) | |
| tree | 191efc9f9def16eba2e785ab5b8d9b842fdb70e3 | |
| parent | 4056fb6901a64bfdd235917086765d0fb98d4f0c (diff) | |
| download | ruby-c48ef0082c21118f63a329d2b7bef54192c63a85.tar.gz ruby-c48ef0082c21118f63a329d2b7bef54192c63a85.tar.xz ruby-c48ef0082c21118f63a329d2b7bef54192c63a85.zip | |
* lib/weakref.rb (WeakRef::__setobj__): should support
marshaling. [ruby-talk:228508]
* lib/delegate.rb (Delegator::marshal_load): need to call
__setobj__.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@11363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 8 | ||||
| -rw-r--r-- | lib/delegate.rb | 1 | ||||
| -rw-r--r-- | lib/weakref.rb | 30 |
3 files changed, 27 insertions, 12 deletions
@@ -1,3 +1,11 @@ +Thu Dec 7 09:29:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org> + + * lib/weakref.rb (WeakRef::__setobj__): should support + marshaling. [ruby-talk:228508] + + * lib/delegate.rb (Delegator::marshal_load): need to call + __setobj__. + Wed Dec 6 23:56:14 2006 Nobuyoshi Nakada <nobu@ruby-lang.org> * Makefile.in, common.mk (NULLCMD): moved for platforms that empty diff --git a/lib/delegate.rb b/lib/delegate.rb index 93c9803a1..d810ccad4 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -184,6 +184,7 @@ class Delegator # Reinitializes delegation from a serialized object. def marshal_load(obj) initialize_methods(obj) + __setobj__(obj) end end diff --git a/lib/weakref.rb b/lib/weakref.rb index 7d43f7126..591819c94 100644 --- a/lib/weakref.rb +++ b/lib/weakref.rb @@ -48,18 +48,7 @@ class WeakRef<Delegator # Create a new WeakRef from +orig+. def initialize(orig) super - @__id = orig.__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.__id__ - @@id_rev_map[self.__id__] = @__id + __setobj__(orig) end # Return the object this WeakRef references. Raises RefError if the object @@ -76,6 +65,23 @@ class WeakRef<Delegator end end + def __setobj__(obj) + @__id = obj.__id__ + __old_status = Thread.critical + begin + Thread.critical = true + unless @@id_rev_map.key?(self) + ObjectSpace.define_finalizer obj, @@final + ObjectSpace.define_finalizer self, @@final + end + @@id_map[@__id] = [] unless @@id_map[@__id] + ensure + Thread.critical = __old_status + end + @@id_map[@__id].push self.__id__ + @@id_rev_map[self.__id__] = @__id + end + # Returns true if the referenced object still exists, and false if it has # been garbage collected. def weakref_alive? |
