Граф коммитов

122 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 6e704311bb [ruby/pp] Extract pp_hash_pair
The method which prints single pair of a hash, to make extending
pretty printing Hash easier, apart from Hash construct itself.

https://github.com/ruby/pp/commit/3fcf2d1142
2024-02-21 16:45:01 +00:00
Nobuyoshi Nakada 37b8fc7477 [ruby/pp] Get rid of hardcoded class name
So that the `pp` method can work in inherited classes with that
class.

https://github.com/ruby/pp/commit/f204df3aad
2024-02-21 16:45:00 +00:00
Samuel Giddins e0312f90bb [ruby/pp] Print beginless ranges properly
Instead of displaying the start of the range as nil

https://github.com/ruby/pp/commit/1df210d903
2024-01-15 14:04:14 +00:00
Benoit Daloze 1ed3b60375 [ruby/pp] Fix pretty printing a Data subclass instance when the subclass is anonymous
* It would be "#<data  a=42>" (double space) instead of "#<data a=42>" (like #inspect).

https://github.com/ruby/pp/commit/bed72bfcb8
2024-01-11 13:44:01 +00:00
Benoit Daloze 62382a4345 [ruby/pp] Use .class.members for pretty printing Data
* Data#members might not be defined, instead it might be defined
  on Data subclasses or a module included there. This is notably the
  case on TruffleRuby which defines it there for optimization purposes.
  In fact the mere presence of Data#members implies a megamorphic call
  inside, so it seems best to avoid relying on its existence.

https://github.com/ruby/pp/commit/6a97d36fbb
2024-01-11 13:44:00 +00:00
Benoit Daloze 3b9cc22536 [ruby/pp] Use a proper feature check to check if Data is defined
https://github.com/ruby/pp/commit/ed602b9f2b
2024-01-11 13:44:00 +00:00
Hiroshi SHIBATA 0ac39f226d [ruby/pp] Bump up 0.5.0
https://github.com/ruby/pp/commit/6e086e6df9
2023-11-07 01:00:08 +00:00
OKURA Masafumi bf1362306e [Doc] Improve documentation of PP
* Remove mention to `require 'pp'` for `pretty_inspect`
* Mention the need to add `require 'pp'` to customize
  `#pretty_print(pp)` method
2023-10-25 16:49:09 +09:00
Hiroshi SHIBATA 3f8756484f [ruby/pp] Expose PP::VERSION
https://github.com/ruby/pp/commit/3d0e65e79f
2023-04-14 01:49:51 +00:00
manga_osyo 7b7e5153e8 [ruby/pp] [Feature #19045] Add support Data#pretty_print
https://github.com/ruby/pp/commit/343a20d721
2022-10-14 21:31:24 +09:00
Nobuyoshi Nakada c6cf19340a [ruby/pp] [DOC] Update for PP.width_for [Feature #12913]
https://github.com/ruby/pp/commit/cad3cc762c
2021-12-23 18:00:56 +09:00
Charles Oliver Nutter 73da1c5ea3
[ruby/pp] Use etc instead of .so for broader compatibility
The use of `etc.so` here requires that etc is always implemented
as a C extension on-disk. However at least one impl – JRuby –
currently implements it as an internal extension, loaded via a
Ruby script. This require should simply use the base name of the
library, `etc`, to allow Ruby-based implementations to load as
well.

https://github.com/ruby/pp/commit/2061f994e0
2021-12-18 08:38:58 +09:00
Charles Oliver Nutter 5a6baaba38
[ruby/pp] Only do RubyVM patches if class exists
This class does not exist in any implementation except CRuby.

I would recommend moving this code somewhere else, like a separate
file loaded only on CRuby or into CRuby itself. For now this
change is sufficient to load the library on other implementations.

https://github.com/ruby/pp/commit/7d5a220f64
2021-12-18 08:38:58 +09:00
Yusuke Endoh 3288f0d09e lib/pp.rb (width_for): Ignore all syscall errors
According to nobu, Errno::EBAD is raised on Windows.
2021-11-30 13:46:08 +09:00
Yusuke Endoh 20065eabdb lib/pp.rb (width_for): ignore Errno::EINVAL
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)
```
2021-11-30 13:17:54 +09:00
Yusuke Endoh eac347fdb0 lib/pp.rb (PP.pp): Use io/console's winsize by default
[Feature #12913]
2021-11-30 11:43:54 +09:00
Hiroshi SHIBATA 17441a6b1b [ruby/pp] Support < Ruby 3.0
https://github.com/ruby/pp/commit/3ee131ae92
2021-04-21 20:44:55 +09:00
Kazuhiro NISHIYAMA 082114da05
[DOC] Add doc to sharing_detection= [ci skip]
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.
```
2020-12-23 11:13:50 +09:00
Koichi Sasada cae8bbfe62 pp is ractor-ready.
`@sharing_detection` is only one obstruction to support pp on
non-main ractors, so make it ractor-local.
2020-12-22 23:32:18 +09:00
Jeremy Evans 28d31ead34 Fix pp when passed a empty ruby2_keywords-flagged hash as array element
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]
2020-01-22 10:27:02 -08:00
Richard Viney 6a75a46053
Make prettyprint’s cycle detection aware of Delegator instances
Fixes [Bug #13144]

Co-Authored-By: Nobuyoshi Nakada <nobu@ruby-lang.org>
2019-12-16 23:43:49 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
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.
2019-11-18 01:00:25 +02:00
John Hawthorn ebbe396d3c Use ident hash for top-level recursion check
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).
2019-11-04 15:27:15 -08:00
Yusuke Endoh c9fc82983c lib/pp.rb: Use UnboundMethod#bind_call instead of .bind(obj).call(...)
Related to [Feature #15955].
2019-08-30 11:13:00 +09:00
ktsj 9738f96fcf Introduce pattern matching [EXPERIMENTAL]
[ruby-core:87945] [Feature #14912]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 06:48:03 +00:00
mame 2c840bbfef lib/pp.rb (Range#pretty_print): support endless range
`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
2018-12-03 01:39:45 +00:00
nobu afa685398e Refine RubyVM::AbstractSyntaxTree::Node#type
* 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
2018-12-03 01:06:34 +00:00
nobu 87e1dd2982 Add RubyVM::AST#pretty_print
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03 00:24:38 +00:00
nobu a531c579f8 Requiring pp is not required now [ci skip]
- 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
2017-12-18 01:51:53 +00:00
mame 612af3b7cb lib/pp.rb: remove alias for suppressing a redefinition warning.
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
2017-12-11 04:46:57 +00:00
nobu 6d8f47fde1 lib/pp.rb: no rdoc of alias to suppress a warning
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-08 08:38:57 +00:00
nobu 60771d1315 pp.rb: rdoc
* 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
2017-12-08 07:17:34 +00:00
akr add309c496 Replace Kernel#pp after PP class is defined.
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
2017-12-01 10:48:29 +00:00
mame 4ae87f0ad6 lib/pp.rb (Kernel#pp): Fix a race condition
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-01 00:41:17 +00:00
mame 23c1fccf83 prelude.rb: Add Kernel#pp, a trigger for lib/pp.rb
[Feature #14123]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-30 01:31:00 +00:00
akr 70ae0d2a42 Refactored using Method#owner.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-04 12:54:42 +00:00
naruse 66c9bb11aa Add missing :nodoc: comment
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
2016-12-10 18:23:33 +00:00
akr 19e6276125 Enable the document for Kernel[#.]pp.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-11 03:04:38 +00:00
akr ea8990d867 pp prints a multiple lines string prettier.
* 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
2016-10-11 07:44:58 +00:00
akr 68ebbbfebe * lib/open-uri.rb: Remove indicator for "frozen_string_literal: true".
* 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
2015-11-10 11:48:14 +00:00
akr 36ca18b847 Put an line before "frozen_string_literal: true" for emacs.
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
2015-10-05 22:22:56 +00:00
akr 805c20a8e5 * lib/pp.rb: Use frozen_string_literal: true.
* 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
2015-10-05 13:27:48 +00:00
usa d2cee7828c * lib/pp.rb (File::Stat#pritty_print): some platforms (such as Windows)
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
2014-12-05 19:35:19 +00:00
akr 4292fd7798 * lib/pp.rb (object_address_group): Use Kernel#to_s to obtain the class
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
2013-10-22 09:29:53 +00:00
shugo c8151d1235 * bootstraptest/test_autoload.rb, bootstraptest/test_method.rb:
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
2013-06-13 02:01:42 +00:00
zzak a3672d4bf4 * lib/pp.rb: Revert part of r40834 and nodoc PP::ObjectMixin
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-20 02:52:29 +00:00
nobu d6d4573782 * remove trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-19 18:21:05 +00:00
zzak 18ffba64bd * lib/pp.rb: Document PP::ObjectMixin [Fixes GH-312]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-19 18:17:51 +00:00
zzak 531d47d6c1 * lib/pp.rb: Update PP module overview by @geopet
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-28 14:19:18 +00:00
zzak 3952de50bf * lib/pp.rb, lib/prettyprint.rb: Documentation for PP and PrettyPrint
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
2013-02-10 00:10:11 +00:00