Project

General

Profile

Bug #7833 ยป drb-basicobject-7833.patch

jeremyevans0 (Jeremy Evans), 08/07/2019 06:06 PM

View differences:

lib/drb/drb.rb
# This implementation returns the object's __id__ in the local
# object space.
def to_id(obj)
obj.nil? ? nil : obj.__id__
case obj
when Object
obj.nil? ? nil : obj.__id__
when BasicObject
obj.__id__
end
end
end
......
end
def dump(obj, error=false) # :nodoc:
obj = make_proxy(obj, error) if obj.kind_of? DRbUndumped
case obj
when DRbUndumped
obj = make_proxy(obj, error)
when Object
# nothing
else
obj = make_proxy(obj, error)
end
begin
str = Marshal::dump(obj)
rescue
......
def initialize(obj, uri=nil)
@uri = nil
@ref = nil
if obj.nil?
case obj
when Object
is_nil = obj.nil?
when BasicObject
is_nil = false
end
if is_nil
return if uri.nil?
@uri, option = DRbProtocol.uri_option(uri, DRb.config)
@ref = DRbURIOption.new(option) unless option.nil?
......
def any_to_s(obj)
obj.to_s + ":#{obj.class}"
rescue
sprintf("#<%s:0x%lx>", obj.class, obj.__id__)
case obj
when Object
klass = obj.class
else
klass = Kernel.instance_method(:class).bind(obj).call
end
sprintf("#<%s:0x%dx>", klass, obj.__id__)
end
# Check that a method is callable via dRuby.
......
raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
if obj.private_methods.include?(msg_id)
desc = any_to_s(obj)
raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
elsif obj.protected_methods.include?(msg_id)
desc = any_to_s(obj)
raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
case obj
when Object
if obj.private_methods.include?(msg_id)
desc = any_to_s(obj)
raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
elsif obj.protected_methods.include?(msg_id)
desc = any_to_s(obj)
raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
else
true
end
else
true
if Kernel.instance_method(:private_methods).bind(obj).call.include?(msg_id)
desc = any_to_s(obj)
raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
elsif Kernel.instance_method(:protected_methods).bind(obj).call.include?(msg_id)
desc = any_to_s(obj)
raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
else
true
end
end
end
public :check_insecure_method
......
end
end
@succ = true
if @msg_id == :to_ary && @result.class == Array
@result = DRbArray.new(@result)
case @result
when Array
if @msg_id == :to_ary
@result = DRbArray.new(@result)
end
end
return @succ, @result
rescue StandardError, ScriptError, Interrupt
test/drb/drbtest.rb
end
end
def test_02_basic_object
obj = @there.basic_object
assert_kind_of(DRb::DRbObject, obj)
assert_equal(1, obj.foo)
assert_raise(NoMethodError){obj.prot}
assert_raise(NoMethodError){obj.priv}
end
def test_02_unknown
obj = @there.unknown_class
assert_kind_of(DRb::DRbUnknown, obj)
test/drb/ut_drb.rb
FooBar.new
end
class BO < ::BasicObject
def foo; 1 end
protected def prot; 2; end
private def priv; 3; end
end
def basic_object
BO.new
end
def unknown_class
Unknown2.new
end
    (1-1/1)