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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e03d9621a6
commit
dc859c017d
3 changed files with 19 additions and 15 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue