mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/weakref.rb (WeakRef::__setobj__): should support
marshaling. [ruby-talk:228508] * lib/delegate.rb (Delegator::marshal_load): need to call __setobj__. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1e8e90612a
commit
1f9981df2a
3 changed files with 27 additions and 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
|
||||
|
|
|
@ -184,6 +184,7 @@ class Delegator
|
|||
# Reinitializes delegation from a serialized object.
|
||||
def marshal_load(obj)
|
||||
initialize_methods(obj)
|
||||
__setobj__(obj)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue