aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pp.rb
Commit message (Collapse)AuthorAgeFilesLines
* lib/pp.rb (width_for): Ignore all syscall errorsYusuke Endoh2021-11-301-1/+1
| | | | According to nobu, Errno::EBAD is raised on Windows.
* lib/pp.rb (width_for): ignore Errno::EINVALYusuke Endoh2021-11-301-1/+1
| | | | | | | | | | | The error is raised on Solaris http://rubyci.s3.amazonaws.com/solaris10-gcc/ruby-master/log/20211130T030003Z.fail.html.gz ``` 1) Failure: TestRubyOptions#test_require [/export/home/users/chkbuild/cb-gcc/tmp/build/20211130T030003Z/ruby/test/ruby/test_rubyoptions.rb:265]: pid 7386 exit 1 | /export/home/users/chkbuild/cb-gcc/tmp/build/20211130T030003Z/ruby/lib/pp.rb:67:in `winsize': Invalid argument - <STDOUT> (Errno::EINVAL) ```
* lib/pp.rb (PP.pp): Use io/console's winsize by defaultYusuke Endoh2021-11-301-1/+10
| | | | [Feature #12913]
* [ruby/pp] Support < Ruby 3.0Hiroshi SHIBATA2021-04-211-1/+1
| | | | https://github.com/ruby/pp/commit/3ee131ae92
* [DOC] Add doc to sharing_detection= [ci skip]Kazuhiro NISHIYAMA2020-12-231-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: ``` $ ri sharing_detection= = .sharing_detection= (from ruby core) === Implementation from PP ------------------------------------------------------------------------ sharing_detection=(b) ------------------------------------------------------------------------ Returns the sharing detection flag as a boolean value. It is false by default. ``` After: ``` $ ri sharing_detection= = .sharing_detection= (from ruby core) === Implementation from PP ------------------------------------------------------------------------ sharing_detection=(b) ------------------------------------------------------------------------ Sets the sharing detection flag to b. ```
* pp is ractor-ready.Koichi Sasada2020-12-221-5/+18
| | | | | `@sharing_detection` is only one obstruction to support pp on non-main ractors, so make it ractor-local.
* Fix pp when passed a empty ruby2_keywords-flagged hash as array elementJeremy Evans2020-01-221-1/+1
| | | | | | | | | | | | | | This causes problems because the hash is passed to a block not accepting keywords. Because the hash is empty and keyword flagged, it is removed before calling the block. This doesn't cause an ArgumentError because it is a block and not a lambda. Just like any other block not passed required arguments, arguments not passed are set to nil. Issues like this are a strong reason not to have ruby2_keywords by default. Fixes [Bug #16519]
* Make prettyprint’s cycle detection aware of Delegator instancesRichard Viney2019-12-161-0/+4
| | | | | | Fixes [Bug #13144] Co-Authored-By: Nobuyoshi Nakada <nobu@ruby-lang.org>
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-3/+3
| | | | | | This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby.
* Use ident hash for top-level recursion checkJohn Hawthorn2019-11-041-8/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We track recursion in order to not infinite loop in ==, inspect, and similar methods by keeping a thread-local 1 or 2 level hash. This allows us to track when we have seen the same object (ex. using inspect) or same pair of objects (ex. using ==) in this stack before and to treat that differently. Previously both levels of this Hash used the object's memory_id as a key (using object_id would be slow and wasteful). Unfortunately, prettyprint (pp.rb) uses this thread local variable to "pretend" to be inspect and inherit its same recursion behaviour. This commit changes the top-level hash to be an identity hash and to use objects as keys instead of their object_ids. I'd like to have also converted the 2nd level hash to an ident hash, but it would have prevented an optimization which avoids allocating a 2nd level hash for only a single element, which we want to keep because it's by far the most common case. So the new format of this hash is: { object => true } (not paired) { lhs_object => rhs_object_memory_id } (paired, single object) { lhs_object => { rhs_object_memory_id => true, ... } } (paired, many objects) We must also update pp.rb to match this (using identity hashes).
* lib/pp.rb: Use UnboundMethod#bind_call instead of .bind(obj).call(...)Yusuke Endoh2019-08-301-5/+5
| | | | Related to [Feature #15955].
* Introduce pattern matching [EXPERIMENTAL]ktsj2019-04-171-0/+4
| | | | | | [ruby-core:87945] [Feature #14912] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* lib/pp.rb (Range#pretty_print): support endless rangemame2018-12-031-1/+1
| | | | | | `pp(1..)` should print `"(1..)"` instead of `"(1..nil)"`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Refine RubyVM::AbstractSyntaxTree::Node#typenobu2018-12-031-4/+4
| | | | | | | * ast.c (rb_ast_node_type): simplified to return a Symbol without "NODE_" prefix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add RubyVM::AST#pretty_printnobu2018-12-031-0/+30
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Requiring pp is not required now [ci skip]nobu2017-12-181-4/+0
| | | | | | | | - Followup of https://bugs.ruby-lang.org/issues/14123 From: Prathamesh Sonpatki <csonpatki@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* lib/pp.rb: remove alias for suppressing a redefinition warning.mame2017-12-111-4/+0
| | | | | | Because there is now the same guard in prelude.rb (alias pp pp). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* lib/pp.rb: no rdoc of alias to suppress a warningnobu2017-12-081-0/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* pp.rb: rdocnobu2017-12-081-1/+1
| | | | | | | * lib/pp.rb (pp): move pp alias before its rdoc, not to prevent parsing. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Replace Kernel#pp after PP class is defined.akr2017-12-011-26/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Avoid a race condition which a context switch occur after replacing Kernel#pp but before defining PP class. Following patch, inserting sleep, makes this problem reproducible. ``` Index: lib/pp.rb =================================================================== --- lib/pp.rb (revision 60960) +++ lib/pp.rb (working copy) @@ -26,6 +26,7 @@ module Kernel end undef __pp_backup__ if method_defined?(:__pp_backup__) module_function :pp + sleep 1 # thread context switch end ## ``` With the above patch, "uninitialized constant Kernel::PP" can happen as as follows. ``` % ./ruby -w -Ilib -e ' t1 = Thread.new { Thread.current.report_on_exception = true pp :foo1 } t2 = Thread.new { Thread.current.report_on_exception = true sleep 0.5 pp :foo2 } t1.join rescue nil t2.join rescue nil ' #<Thread:0x000055dbf926eaa0@-e:6 run> terminated with exception: Traceback (most recent call last): 3: from -e:9:in `block in <main>' 2: from /home/ruby/tst2/ruby/lib/pp.rb:22:in `pp' 1: from /home/ruby/tst2/ruby/lib/pp.rb:22:in `each' /home/ruby/tst2/ruby/lib/pp.rb:23:in `block in pp': uninitialized constant Kernel::PP (NameError) :foo1 ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* lib/pp.rb (Kernel#pp): Fix a race conditionmame2017-12-011-1/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* prelude.rb: Add Kernel#pp, a trigger for lib/pp.rbmame2017-11-301-0/+1
| | | | | | [Feature #14123] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Refactored using Method#owner.akr2017-04-041-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add missing :nodoc: commentnaruse2016-12-101-2/+2
| | | | | | | | | | We were missing a `:nodoc:` magic comment that was making automated tools show that this method was missing documentation, when it really didn't need to be documented. by Devon Estes <devon.c.estes@gmail.com> https://github.com/ruby/ruby/pull/1482 fix GH-1482 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Enable the document for Kernel[#.]pp.akr2016-11-111-3/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* pp prints a multiple lines string prettier.akr2016-10-111-0/+15
| | | | | | | | | | * lib/pp.rb (String#pretty_print): Defined to print a string as multiple lines. [ruby-core:76800] [Feature#12664] proposed by Petr Chalupa. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/open-uri.rb: Remove indicator for "frozen_string_literal: true".akr2015-11-101-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib/pp.rb: Ditto. * lib/prettyprint.rb: Ditto. * lib/resolv.rb: Ditto. * lib/securerandom.rb: Ditto. * lib/tmpdir.rb: Ditto. * lib/unicode_normalize/tables.rb: Ditto. * test/net/ftp/test_buffered_socket.rb: Ditto. * test/net/ftp/test_mlsx_entry.rb: Ditto. * test/open-uri/test_open-uri.rb: Ditto. * test/open-uri/test_ssl.rb: Ditto. * test/pathname/test_pathname.rb: Ditto. * test/test_pp.rb: Ditto. * test/test_prettyprint.rb: Ditto. * tool/transcode-tblgen.rb: Ditto. * ext/pathname/lib/pathname.rb: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Put an line before "frozen_string_literal: true" for emacs.akr2015-10-051-0/+1
| | | | | | | https://bugs.ruby-lang.org/issues/8976#note-49 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb: Use frozen_string_literal: true.akr2015-10-051-2/+4
| | | | | | | | | | | | | | | | | | * lib/prettyprint.rb: Ditto. * lib/resolv.rb: Ditto. * lib/tmpdir.rb: Ditto. * test/test_pp.rb: Ditto. * test/test_prettyprint.rb: Ditto. * tool/transcode-tblgen.rb: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb (File::Stat#pritty_print): some platforms (such as Windows)usa2014-12-051-2/+4
| | | | | | | does not have major/minor parts of device. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb (object_address_group): Use Kernel#to_s to obtain the classakr2013-10-221-13/+3
| | | | | | | | | | | name and object address. This fix a problem caused by %p in C generates variable length address. Reported by ko1 via IRC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * bootstraptest/test_autoload.rb, bootstraptest/test_method.rb:shugo2013-06-131-3/+3
| | | | | | | | | remove tests for $SAFE=4. * lib/pp.rb: use taint instead of untrust to avoid warnings when $VERBOSE is set to true. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb: Revert part of r40834 and nodoc PP::ObjectMixinzzak2013-05-201-29/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * remove trailing spaces.nobu2013-05-191-5/+5
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb: Document PP::ObjectMixin [Fixes GH-312]zzak2013-05-191-0/+28
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb: Update PP module overview by @geopetzzak2013-04-281-13/+26
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb, lib/prettyprint.rb: Documentation for PP and PrettyPrintzzak2013-02-101-33/+58
| | | | | | | Based on a patch by Vincent Batts [ruby-core:51253] [Bug #7656] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Kernel#inspect: improve consistency and do not call #to_s.eregon2012-08-151-10/+1
| | | | | | | | | | | | | | | | | | | | * object.c (rb_obj_inspect): Kernel#inspect: do not call #to_s. A class can now benefit from the nice default #inspect even if it defines #to_s. Also, there is no more unexpected change in #inspect result. * NEWS: Add note about the change. * bignum.c, io.c, numeric.c, object.c, proc.c, vm.c (Init_*): Adapt internal structures (by aliasing #inspect to #to_s) so they don't rely on the removed behavior (#inspect calling overridden #to_s). * test/ruby/test_object.rb (test_inspect): add tests for Kernel#inspect. * lib/pp.rb (class PP): do not call #to_s anymore, as #inspect no more does (mame). * test/test_pp.rb (class PPInspectTest): remove related assertion (mame). [ruby-core:43238][Feature #6130] * test/drb/drbtest.rb (DRbCore#teardown, DRbAry#teardown): adapt DRb tests with the new change (shirosaki). [ruby-core:47182][Bug #6866] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Revert r36699 and r36700. [Feature #6130]naruse2012-08-151-1/+10
| | | | | | | | | | | | | Revert "Kernel#inspect: improve consistency and do not call #to_s." Revert "update PP with recent Kernel#inspect change. Patch by Yusuke Endoh." r36699 cause test-all failure on test/drb/test_drb.rb and test/drb/test_drbssl.rb. Run test-all before commit. Moreover its ChangeLog formst is wrong: see CommitterHowto https://bugs.ruby-lang.org/projects/ruby/wiki/CommitterHowto#ChangeLog git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* update PP with recent Kernel#inspect change. Patch by Yusuke Endoh.eregon2012-08-141-10/+1
| | | | | | | | * lib/pp.rb (class PP): do not call #to_s anymore, as #inspect no more does. * test/test_pp.rb (class PPInspectTest): remove related assertion. [ruby-core:43238][Feature #6130] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb: fix rdoc.ktsj2011-12-041-3/+5
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb: Move PP documentation to top of class PP. Patch bydrbrain2011-10-101-22/+21
| | | | | | | Sylvain Daubert. [Ruby 1.9 - Bug #5430] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb: describe superclasses explicitly.akr2010-08-011-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28828 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb: use [""].pack("p").size to detect the pointer size.akr2010-04-241-7/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb (PP::ObjectMixin#pretty_print): use to_s regardless ofakr2009-11-071-3/+2
| | | | | | | instance variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb (Kernel#pp): returns its arguments, like Kernel#p.mame2009-09-291-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb (PP:ObjectMixin#pretty_print): delegates has no inspectakr2009-09-271-2/+16
| | | | | | | method. [ruby-core:25804] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb (guard_inspect_key): untrust internal hash to preventmame2009-08-041-3/+3
| | | | | | | | unexpected SecurityError. * test/ruby/test_object.rb: add a test for [ruby-dev:38982]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/pp.rb (Struct#pretty_print): coerce to a string sincenobu2009-04-271-1/+1
| | | | | | | anonymous class has name no longer. [ruby-dev:38349] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/test_pp.rb: extract from lib/pp.rb.akr2009-02-141-183/+0
| | | | | | | | | * test/test_prettyprint.rb: extract from lib/prettyprint.rb. * test/test_tsort.rb: extract from lib/tsort.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e