Project

General

Profile

Actions

Bug #13144

closed

prettyprint doesn't detect cycles when wrapped inside Delegators

Added by richardviney (Richard Viney) about 7 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:79210]

Description

The line count of the pretty print output for the following class grows factorially with the number of self-referencing SimpleDelegator instances created by the initializer. With an n of 8 the line count of the pretty print output is almost one million! This occurs because the cycle detection in lib/pp.rb doesn't detect the already printed object due to it being wrapped inside a Delegator instance. The same problem occurs with pretty printing cycles wrapped inside WeakRef because it is a subclass of Delegator.

class Foo
def initialize(n)
n.times { |i| instance_variable_set "@a#{i}", SimpleDelegator.new(self) }
end
end

Updated by richardviney (Richard Viney) about 7 years ago

Pull request with my fix and new test case: https://github.com/ruby/ruby/pull/1518

Actions #2

Updated by richardviney (Richard Viney) over 4 years ago

  • Status changed from Open to Closed

Applied in changeset git|6a75a460536a32fb62184dc5d8d66ddd737a9bad.


Make prettyprint’s cycle detection aware of Delegator instances

Fixes [Bug #13144]

Co-Authored-By: Nobuyoshi Nakada

Actions

Also available in: Atom PDF

Like0
Like0Like0