From d6c31119999d85a10ae4ae5f10b539b5456b59e8 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Mon, 3 Jul 2017 13:36:59 +0200 Subject: [PATCH] Always generate positive object IDs in inspect Sometimes, object_ids are created as signed Integers which are invalid in `inspect`. By using the default implementation of `Object#to_s`, we can get valid object_ids the same way Ruby itself would have created them. For a motivation of this change, see * https://bugs.ruby-lang.org/issues/13397 * https://github.com/ruby-concurrency/concurrent-ruby/pull/651 --- lib/rackstash.rb | 4 ---- lib/rackstash/fields/abstract_collection.rb | 4 ++-- lib/rackstash/flows.rb | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/rackstash.rb b/lib/rackstash.rb index ce81394..4717a23 100644 --- a/lib/rackstash.rb +++ b/lib/rackstash.rb @@ -47,10 +47,6 @@ module Rackstash FIELD_TAGS = 'tags'.freeze FIELD_TIMESTAMP = '@timestamp'.freeze FIELD_VERSION = '@version'.freeze - - # @!visibility private - # we want to look "native" with our inspect values, 7 for 32-bit, 14 for 64-bit - DEFAULT_OBJ_ID_STR_WIDTH = 0.size == 4 ? 7 : 14 end require 'rackstash/logger' diff --git a/lib/rackstash/fields/abstract_collection.rb b/lib/rackstash/fields/abstract_collection.rb index bcf7316..0791005 100644 --- a/lib/rackstash/fields/abstract_collection.rb +++ b/lib/rackstash/fields/abstract_collection.rb @@ -38,8 +38,8 @@ module Rackstash # # @return [String] human-redable details about the object. def inspect - id_str = (object_id << 1).to_s(16).rjust(DEFAULT_OBJ_ID_STR_WIDTH, '0') - "#<#{self.class.name}:0x#{id_str} #{self}>" + id_str = Object.instance_method(:to_s).bind(self).call[2..-2] + "#<#{id_str} #{self}>" end # Provide a copy of the wrapped {#raw} data in a format allowing direct diff --git a/lib/rackstash/flows.rb b/lib/rackstash/flows.rb index cb4e6d7..1195011 100644 --- a/lib/rackstash/flows.rb +++ b/lib/rackstash/flows.rb @@ -81,8 +81,8 @@ module Rackstash # @return [String] a string representation of `self` def inspect - id_str = (object_id << 1).to_s(16).rjust(DEFAULT_OBJ_ID_STR_WIDTH, '0') - "#<#{self.class.name}:0x#{id_str} #{self}>" + id_str = Object.instance_method(:to_s).bind(self).call[2..-2] + "#<#{id_str} #{self}>" end # @return [Integer] the number of elements in `self`. May be zero.