From: akr@... Date: 2017-12-01T10:49:24+00:00 Subject: [ruby-core:84025] [Ruby trunk Feature#14123] Kernel#pp by default Issue #14123 has been updated by akr (Akira Tanaka). mame (Yusuke Endoh) wrote: > Okay, my third try: https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/60948 > It is still not thread safe. Consider a thread context switch at just after defining Kernel#pp before defining PP class. ``` 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 ' # terminated with exception: Traceback (most recent call last): 3: from -e:9:in `block in
' 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 ``` Fix is simple: replacing Kernel#pp at last as r60961. ---------------------------------------- Feature #14123: Kernel#pp by default https://bugs.ruby-lang.org/issues/14123#change-68108 * Author: mame (Yusuke Endoh) * Status: Closed * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: 2.5 ---------------------------------------- Matz, may I commit this? I really want this. ``` diff --git a/prelude.rb b/prelude.rb index 7b98e28285..87f49ac9fb 100644 --- a/prelude.rb +++ b/prelude.rb @@ -141,3 +141,11 @@ def irb irb end end + +module Kernel + def pp(*objs) + undef :pp + require 'pp' + pp(*objs) + end +end ``` -- https://bugs.ruby-lang.org/ Unsubscribe: