1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-10-17 14:01:01 +00:00

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
This commit is contained in:
Holger Just 2017-07-03 13:36:59 +02:00
parent 4eecc559a4
commit d6c3111999
3 changed files with 4 additions and 8 deletions

View File

@ -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'

View File

@ -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

View File

@ -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.