ruby-changes:58286
From: Jeremy <ko1@a...>
Date: Thu, 17 Oct 2019 05:00:13 +0900 (JST)
Subject: [ruby-changes:58286] d5744aff3a (master): Fix DRbServer#any_to_s
https://git.ruby-lang.org/ruby.git/commit/?id=d5744aff3a From d5744aff3a164c358f92ef9dc2cda5c7a7612d97 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Mon, 14 Oct 2019 09:00:42 -0700 Subject: Fix DRbServer#any_to_s My previous fix in d0ed935d5bf8c3fce9800742a36e44fb7f63dda4 was not correct, as pointed out by cremno on GitHub. This simplifies things by just using Kernel#to_s. Also switch to bind_call(obj) instead of bind(obj).call for better performance. diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb index 9b4d675..5c7f66a 100644 --- a/lib/drb/drb.rb +++ b/lib/drb/drb.rb @@ -1606,15 +1606,9 @@ module DRb https://github.com/ruby/ruby/blob/trunk/lib/drb/drb.rb#L1606 # Coerce an object to a string, providing our own representation if # to_s is not defined for the object. def any_to_s(obj) - obj.to_s + ":#{obj.class}" + "#{obj}:#{obj.class}" rescue - case obj - when Object - klass = obj.class - else - klass = Kernel.instance_method(:class).bind(obj).call - end - sprintf("#<%s:0x%dx>", klass, obj.__id__) + Kernel.instance_method(:to_s).bind_call(obj) end # Check that a method is callable via dRuby. diff --git a/test/drb/test_drb.rb b/test/drb/test_drb.rb index b439957..15e40ac 100644 --- a/test/drb/test_drb.rb +++ b/test/drb/test_drb.rb @@ -327,6 +327,20 @@ class TestBug4409 < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/drb/test_drb.rb#L327 end end +class TestDRbAnyToS < Test::Unit::TestCase + class BO < BasicObject + end + + def test_any_to_s + server = DRb::DRbServer.new('druby://:0') + server.singleton_class.send(:public, :any_to_s) + assert_equal("foo:String", server.any_to_s("foo")) + assert_match(/\A#<DRbTests::TestDRbAnyToS::BO:0x[0-9a-f]+>\z/, server.any_to_s(BO.new)) + server.stop_service + server.thread.join + end +end + class TestDRbTCP < Test::Unit::TestCase def test_immediate_close server = DRb::DRbServer.new('druby://:0') -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/