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
|
@ -1,3 +1,8 @@
|
|||
Thu Dec 7 09:29:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* lib/weakref.rb (WeakRef::__setobj__): should support
|
||||
marshaling. [ruby-talk:228508]
|
||||
|
||||
Wed Dec 6 23:58:36 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* Makefile.in, common.mk (NULLCMD): moved for platforms that empty
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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…
Reference in a new issue