Skip to content

Avoid use of id2ref for weak mapping #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 3 additions & 35 deletions lib/drb/drb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
require 'monitor'
require_relative 'eq'
require_relative 'version'
require_relative 'weakidconv'

#
# == Overview
Expand Down Expand Up @@ -348,39 +349,6 @@ class DRbError < RuntimeError; end
# protocol.
class DRbConnError < DRbError; end

# Class responsible for converting between an object and its id.
#
# This, the default implementation, uses an object's local ObjectSpace
# __id__ as its id. This means that an object's identification over
# drb remains valid only while that object instance remains alive
# within the server runtime.
#
# For alternative mechanisms, see DRb::TimerIdConv in drb/timeridconv.rb
# and DRbNameIdConv in sample/name.rb in the full drb distribution.
class DRbIdConv

# Convert an object reference id to an object.
#
# This implementation looks up the reference id in the local object
# space and returns the object it refers to.
def to_obj(ref)
ObjectSpace._id2ref(ref)
end

# Convert an object into a reference id.
#
# This implementation returns the object's __id__ in the local
# object space.
def to_id(obj)
case obj
when Object
obj.nil? ? nil : obj.__id__
when BasicObject
obj.__id__
end
end
end

# Mixin module making an object undumpable or unmarshallable.
#
# If an object which includes this module is returned by method
Expand Down Expand Up @@ -1349,7 +1317,7 @@ def alive? # :nodoc:
# started by calling DRb.start_service.
class DRbServer
@@acl = nil
@@idconv = DRbIdConv.new
@@idconv = WeakIdConv.new
@@secondary_server = nil
@@argc_limit = 256
@@load_limit = 0xffffffff
Expand Down Expand Up @@ -1940,4 +1908,4 @@ def fetch_server(uri)
# :stopdoc:
DRbObject = DRb::DRbObject
DRbUndumped = DRb::DRbUndumped
DRbIdConv = DRb::DRbIdConv
DRbIdConv = DRb::WeakIdConv
27 changes: 27 additions & 0 deletions lib/drb/id2refconv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Deprecated: Uses internal API ObjectSpace._id2ref and is replaced
# by WeakIdConv.
module DRb
class DRbIdConv

# Convert an object reference id to an object.
#
# This implementation looks up the reference id in the local object
# space and returns the object it refers to.
def to_obj(ref)
ObjectSpace._id2ref(ref)
end

# Convert an object into a reference id.
#
# This implementation returns the object's __id__ in the local
# object space.
def to_id(obj)
case obj
when Object
obj.nil? ? nil : obj.__id__
when BasicObject
obj.__id__
end
end
end
end
2 changes: 1 addition & 1 deletion lib/drb/timeridconv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module DRb
#
# DRb.install_id_conv TimerIdConv.new 60 # one minute

class TimerIdConv < DRbIdConv
class TimerIdConv
class TimerHolder2 # :nodoc:
include MonitorMixin

Expand Down
7 changes: 1 addition & 6 deletions lib/drb/weakidconv.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# frozen_string_literal: false
require_relative 'drb'
require 'monitor'

module DRb

# To use WeakIdConv:
#
# DRb.start_service(nil, nil, {:idconv => DRb::WeakIdConv.new})

class WeakIdConv < DRbIdConv
class WeakIdConv
class WeakSet
include MonitorMixin
def initialize
Expand Down