Project

General

Profile

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

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

View differences:

lib/drb/drb.rb
377 377
    # This implementation returns the object's __id__ in the local
378 378
    # object space.
379 379
    def to_id(obj)
380
      obj.nil? ? nil : obj.__id__
380
      case obj
381
      when Object
382
        obj.nil? ? nil : obj.__id__
383
      when BasicObject
384
        obj.__id__
385
      end
381 386
    end
382 387
  end
383 388

  
......
560 565
    end
561 566

  
562 567
    def dump(obj, error=false)  # :nodoc:
563
      obj = make_proxy(obj, error) if obj.kind_of? DRbUndumped
568
      case obj
569
      when DRbUndumped
570
        obj = make_proxy(obj, error)
571
      when Object
572
        # nothing
573
      else
574
        obj = make_proxy(obj, error)
575
      end
564 576
      begin
565 577
        str = Marshal::dump(obj)
566 578
      rescue
......
1092 1104
    def initialize(obj, uri=nil)
1093 1105
      @uri = nil
1094 1106
      @ref = nil
1095
      if obj.nil?
1107
      case obj
1108
      when Object
1109
        is_nil = obj.nil?
1110
      when BasicObject
1111
        is_nil = false
1112
      end
1113

  
1114
      if is_nil
1096 1115
        return if uri.nil?
1097 1116
        @uri, option = DRbProtocol.uri_option(uri, DRb.config)
1098 1117
        @ref = DRbURIOption.new(option) unless option.nil?
......
1527 1546
    def any_to_s(obj)
1528 1547
      obj.to_s + ":#{obj.class}"
1529 1548
    rescue
1530
      sprintf("#<%s:0x%lx>", obj.class, obj.__id__)
1549
      case obj
1550
      when Object
1551
        klass = obj.class
1552
      else
1553
        klass = Kernel.instance_method(:class).bind(obj).call
1554
      end
1555
      sprintf("#<%s:0x%dx>", klass, obj.__id__)
1531 1556
    end
1532 1557

  
1533 1558
    # Check that a method is callable via dRuby.
......
1543 1568
      raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
1544 1569
      raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
1545 1570

  
1546
      if obj.private_methods.include?(msg_id)
1547
        desc = any_to_s(obj)
1548
        raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
1549
      elsif obj.protected_methods.include?(msg_id)
1550
        desc = any_to_s(obj)
1551
        raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
1571
      case obj
1572
      when Object
1573
        if obj.private_methods.include?(msg_id)
1574
          desc = any_to_s(obj)
1575
          raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
1576
        elsif obj.protected_methods.include?(msg_id)
1577
          desc = any_to_s(obj)
1578
          raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
1579
        else
1580
          true
1581
        end
1552 1582
      else
1553
        true
1583
        if Kernel.instance_method(:private_methods).bind(obj).call.include?(msg_id)
1584
          desc = any_to_s(obj)
1585
          raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
1586
        elsif Kernel.instance_method(:protected_methods).bind(obj).call.include?(msg_id)
1587
          desc = any_to_s(obj)
1588
          raise NoMethodError, "protected method `#{msg_id}' called for #{desc}"
1589
        else
1590
          true
1591
        end
1554 1592
      end
1555 1593
    end
1556 1594
    public :check_insecure_method
......
1596 1634
          end
1597 1635
        end
1598 1636
        @succ = true
1599
        if @msg_id == :to_ary && @result.class == Array
1600
          @result = DRbArray.new(@result)
1637
        case @result
1638
        when Array
1639
          if @msg_id == :to_ary
1640
            @result = DRbArray.new(@result)
1641
          end
1601 1642
        end
1602 1643
        return @succ, @result
1603 1644
      rescue StandardError, ScriptError, Interrupt
test/drb/drbtest.rb
158 158
    end
159 159
  end
160 160

  
161
  def test_02_basic_object
162
    obj = @there.basic_object
163
    assert_kind_of(DRb::DRbObject, obj)
164
    assert_equal(1, obj.foo)
165
    assert_raise(NoMethodError){obj.prot}
166
    assert_raise(NoMethodError){obj.priv}
167
  end
168

  
161 169
  def test_02_unknown
162 170
    obj = @there.unknown_class
163 171
    assert_kind_of(DRb::DRbUnknown, obj)
test/drb/ut_drb.rb
63 63
    FooBar.new
64 64
  end
65 65

  
66
  class BO < ::BasicObject
67
    def foo; 1 end
68
    protected def prot; 2; end
69
    private def priv; 3; end
70
  end
71
  def basic_object
72
    BO.new
73
  end
74

  
66 75
  def unknown_class
67 76
    Unknown2.new
68 77
  end
69
-