Ruby Issue Tracking System: Issues
https://bugs.ruby-lang.org/
https://bugs.ruby-lang.org/favicon.ico?1711330511
2020-07-20T17:41:15Z
Ruby Issue Tracking System
Redmine
Ruby master - Bug #17037 (Closed): rounding of Rational#to_f
https://bugs.ruby-lang.org/issues/17037
2020-07-20T17:41:15Z
akr (Akira Tanaka)
akr@fsij.org
<p>I found a doubtful rounding behavior of Rational#to_f.</p>
<pre><code>% ./ruby -ve '
a = 1r
e = Float::EPSILON.to_r
puts "e=#{e}"
n = 100
(0..n).each {|i|
r = a + e * i / n
f = r.to_f
p [i, f, r]
}
'
ruby 2.8.0dev (2020-07-20T06:39:31Z master 935d0b3d05) [x86_64-linux]
e=1/4503599627370496
[0, 1.0, (1/1)]
[1, 1.0, (450359962737049601/450359962737049600)]
[2, 1.0, (225179981368524801/225179981368524800)]
[3, 1.0, (450359962737049603/450359962737049600)]
[4, 1.0, (112589990684262401/112589990684262400)]
[5, 1.0, (90071992547409921/90071992547409920)]
[6, 1.0, (225179981368524803/225179981368524800)]
[7, 1.0, (450359962737049607/450359962737049600)]
[8, 1.0, (56294995342131201/56294995342131200)]
[9, 1.0, (450359962737049609/450359962737049600)]
[10, 1.0, (45035996273704961/45035996273704960)]
[11, 1.0, (450359962737049611/450359962737049600)]
[12, 1.0, (112589990684262403/112589990684262400)]
[13, 1.0, (450359962737049613/450359962737049600)]
[14, 1.0, (225179981368524807/225179981368524800)]
[15, 1.0, (90071992547409923/90071992547409920)]
[16, 1.0, (28147497671065601/28147497671065600)]
[17, 1.0, (450359962737049617/450359962737049600)]
[18, 1.0, (225179981368524809/225179981368524800)]
[19, 1.0, (450359962737049619/450359962737049600)]
[20, 1.0, (22517998136852481/22517998136852480)]
[21, 1.0, (450359962737049621/450359962737049600)]
[22, 1.0, (225179981368524811/225179981368524800)]
[23, 1.0, (450359962737049623/450359962737049600)]
[24, 1.0, (56294995342131203/56294995342131200)]
[25, 1.0, (18014398509481985/18014398509481984)]
[26, 1.0, (225179981368524813/225179981368524800)]
[27, 1.0, (450359962737049627/450359962737049600)]
[28, 1.0, (112589990684262407/112589990684262400)]
[29, 1.0, (450359962737049629/450359962737049600)]
[30, 1.0, (45035996273704963/45035996273704960)]
[31, 1.0, (450359962737049631/450359962737049600)]
[32, 1.0, (14073748835532801/14073748835532800)]
[33, 1.0000000000000002, (450359962737049633/450359962737049600)]
[34, 1.0000000000000002, (225179981368524817/225179981368524800)]
[35, 1.0, (90071992547409927/90071992547409920)]
[36, 1.0000000000000002, (112589990684262409/112589990684262400)]
[37, 1.0000000000000002, (450359962737049637/450359962737049600)]
[38, 1.0000000000000002, (225179981368524819/225179981368524800)]
[39, 1.0000000000000002, (450359962737049639/450359962737049600)]
[40, 1.0, (11258999068426241/11258999068426240)]
[41, 1.0000000000000002, (450359962737049641/450359962737049600)]
[42, 1.0000000000000002, (225179981368524821/225179981368524800)]
[43, 1.0000000000000002, (450359962737049643/450359962737049600)]
[44, 1.0000000000000002, (112589990684262411/112589990684262400)]
[45, 1.0000000000000002, (90071992547409929/90071992547409920)]
[46, 1.0000000000000002, (225179981368524823/225179981368524800)]
[47, 1.0000000000000002, (450359962737049647/450359962737049600)]
[48, 1.0000000000000002, (28147497671065603/28147497671065600)]
[49, 1.0000000000000002, (450359962737049649/450359962737049600)]
[50, 1.0, (9007199254740993/9007199254740992)]
[51, 1.0000000000000002, (450359962737049651/450359962737049600)]
[52, 1.0000000000000002, (112589990684262413/112589990684262400)]
[53, 1.0000000000000002, (450359962737049653/450359962737049600)]
[54, 1.0000000000000002, (225179981368524827/225179981368524800)]
[55, 1.0000000000000002, (90071992547409931/90071992547409920)]
[56, 1.0000000000000002, (56294995342131207/56294995342131200)]
[57, 1.0000000000000002, (450359962737049657/450359962737049600)]
[58, 1.0000000000000002, (225179981368524829/225179981368524800)]
[59, 1.0000000000000002, (450359962737049659/450359962737049600)]
[60, 1.0000000000000002, (22517998136852483/22517998136852480)]
[61, 1.0000000000000002, (450359962737049661/450359962737049600)]
[62, 1.0000000000000002, (225179981368524831/225179981368524800)]
[63, 1.0000000000000002, (450359962737049663/450359962737049600)]
[64, 1.0000000000000002, (7036874417766401/7036874417766400)]
[65, 1.0000000000000002, (90071992547409933/90071992547409920)]
[66, 1.0000000000000002, (225179981368524833/225179981368524800)]
[67, 1.0000000000000002, (450359962737049667/450359962737049600)]
[68, 1.0000000000000002, (112589990684262417/112589990684262400)]
[69, 1.0000000000000002, (450359962737049669/450359962737049600)]
[70, 1.0000000000000002, (45035996273704967/45035996273704960)]
[71, 1.0000000000000002, (450359962737049671/450359962737049600)]
[72, 1.0000000000000002, (56294995342131209/56294995342131200)]
[73, 1.0000000000000002, (450359962737049673/450359962737049600)]
[74, 1.0000000000000002, (225179981368524837/225179981368524800)]
[75, 1.0000000000000002, (18014398509481987/18014398509481984)]
[76, 1.0000000000000002, (112589990684262419/112589990684262400)]
[77, 1.0000000000000002, (450359962737049677/450359962737049600)]
[78, 1.0000000000000002, (225179981368524839/225179981368524800)]
[79, 1.0000000000000002, (450359962737049679/450359962737049600)]
[80, 1.0000000000000002, (5629499534213121/5629499534213120)]
[81, 1.0000000000000002, (450359962737049681/450359962737049600)]
[82, 1.0000000000000002, (225179981368524841/225179981368524800)]
[83, 1.0000000000000002, (450359962737049683/450359962737049600)]
[84, 1.0000000000000002, (112589990684262421/112589990684262400)]
[85, 1.0000000000000002, (90071992547409937/90071992547409920)]
[86, 1.0000000000000002, (225179981368524843/225179981368524800)]
[87, 1.0000000000000002, (450359962737049687/450359962737049600)]
[88, 1.0000000000000002, (56294995342131211/56294995342131200)]
[89, 1.0000000000000002, (450359962737049689/450359962737049600)]
[90, 1.0000000000000002, (45035996273704969/45035996273704960)]
[91, 1.0000000000000002, (450359962737049691/450359962737049600)]
[92, 1.0000000000000002, (112589990684262423/112589990684262400)]
[93, 1.0000000000000002, (450359962737049693/450359962737049600)]
[94, 1.0000000000000002, (225179981368524847/225179981368524800)]
[95, 1.0000000000000002, (90071992547409939/90071992547409920)]
[96, 1.0000000000000002, (14073748835532803/14073748835532800)]
[97, 1.0000000000000002, (450359962737049697/450359962737049600)]
[98, 1.0000000000000002, (225179981368524849/225179981368524800)]
[99, 1.0000000000000002, (450359962737049699/450359962737049600)]
[100, 1.0000000000000002, (4503599627370497/4503599627370496)]
</code></pre>
<p>This sample program tries to convert rationals between<br>
1.0 and 1.0 + Float::EPSILON to float.<br>
Since there is no representable float values between them<br>
(except 1.0 and 1.0 + Float::EPSILON),<br>
I expect that<br>
r.to_f returns 1.0 for r < X and<br>
1.0 + Float::EPSILON for r > X<br>
for some X.</p>
<p>But my expectation is not valid:</p>
<pre><code>[34, 1.0000000000000002, (225179981368524817/225179981368524800)]
[35, 1.0, (90071992547409927/90071992547409920)]
</code></pre>
<p>I.e.</p>
<p><code>1 + Float::EPSILON.to_r * 34 / 100 < 1 + Float::EPSILON.to_r * 35 / 100</code></p>
<p>but</p>
<p><code>(1 + Float::EPSILON.to_r * 34 / 100).to_f > (1 + Float::EPSILON.to_r * 35 / 100).to_f</code></p>
<p>I guess Rational#to_f should round the rational value to a nearest representable float value.</p>
Ruby master - Feature #16345 (Closed): Don't emit deprecation warnings by default.
https://bugs.ruby-lang.org/issues/16345
2019-11-12T07:07:18Z
akr (Akira Tanaka)
akr@fsij.org
<p>We propose that Ruby doesn't emit deprecation warnings by default.</p>
<p>Deprecation warnings are only useful during development for updating Ruby version.<br>
They are not useful during development with current Ruby.<br>
It is especially frustrating when deprecated warnings are generated in gems.<br>
Also, deprecation warnings are totally useless in production environment.</p>
<p>So, we want to emit deprecation warnings only in useful situations.</p>
<p>We propose a command line argument <code>-W:deprecated</code> (or <code>--warning=deprecated</code>)<br>
and the following methods to enable/disable deprecation warnings.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">Warning</span><span class="p">.</span><span class="nf">disable</span><span class="p">(</span><span class="ss">:deprecated</span><span class="p">)</span>
<span class="no">Warning</span><span class="p">.</span><span class="nf">enable</span><span class="p">(</span><span class="ss">:deprecated</span><span class="p">)</span>
<span class="no">Warning</span><span class="p">.</span><span class="nf">enabled?</span><span class="p">(</span><span class="ss">:deprecated</span><span class="p">)</span>
</code></pre>
<p>Currently we don't propose a method to generate a deprecation warning<br>
because currently our main intent is to disable deprecation warnings for<br>
keyword arguments, and the warnings are generated in C level.</p>
<p>Background:</p>
<p>We talked about keyword arguments during a developer meeting (2019-11-12).<br>
<a href="https://bugs.ruby-lang.org/issues/16333" class="external">https://bugs.ruby-lang.org/issues/16333</a><br>
We expect many deprecation warnings to be generated in Ruby 2.7.<br>
They are not useful except for development for Ruby transition, and<br>
they may block transition to Ruby 2.7.</p>
<p>So, we have consensus to disable deprecation warnings by default.<br>
Our design is intentionally minimum because we need this feature for Ruby 2.7.</p>
<p>We chose <code>Warning.disable(:deprecated)</code> instead of<br>
re-defining <code>Warning.warn</code> in order to avoid string object generation.</p>
<p>Of course, we expect to extend this feature:<br>
Ruby-level deprecation warning generation,<br>
warnings other than deprecation,<br>
file-based restriction of warning generation, etc.<br>
But this issue doesn't contain them.</p>
Ruby master - Bug #15599 (Open): Mixing autoload and require causes deadlock and incomplete defin...
https://bugs.ruby-lang.org/issues/15599
2019-02-12T13:40:45Z
akr (Akira Tanaka)
akr@fsij.org
<p>I found that mixing autoload and require causes deadlock and incomplete definition.</p>
<pre><code>% cat a.rb
class A
def a1() end
end
% cat base.rb
autoload :A, './a'
t1 = Thread.new { p A.instance_methods(false) }
t2 = Thread.new { require './a' }
t1.join
t2.join
% ruby base.rb
Traceback (most recent call last):
1: from base.rb:6:in `<main>'
base.rb:6:in `join': No live threads left. Deadlock? (fatal)
3 threads, 3 sleeps current:0x000055cc6943fde0 main thread:0x000055cc6935f4b0
* #<Thread:0x000055cc6938f190 sleep_forever>
rb_thread_t:0x000055cc6935f4b0 native:0x00007f58d256eb40 int:0
base.rb:6:in `join'
base.rb:6:in `<main>'
* #<Thread:0x000055cc6968cfc8@base.rb:3 sleep_forever>
rb_thread_t:0x000055cc69736180 native:0x00007f58ce7b3700 int:0 mutex:0x000055cc6943fde0 cond:1
depended by: tb_thread_id:0x000055cc6935f4b0
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
base.rb:3:in `block in <main>'
* #<Thread:0x000055cc6968ccd0@base.rb:4 sleep_forever>
rb_thread_t:0x000055cc6943fde0 native:0x00007f58ce5b1700 int:0
/tmp/a/a.rb:1:in `<top (required)>'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
base.rb:4:in `block in <main>'
% ruby base.rb
[:a1]
% ruby base.rb
[]
</code></pre>
<p>The last run which prints [] means incomplete definition of A which a1 method is not defined.</p>
Ruby master - Bug #15598 (Open): Deadlock on mutual reference of autoloaded constants
https://bugs.ruby-lang.org/issues/15598
2019-02-11T12:39:41Z
akr (Akira Tanaka)
akr@fsij.org
<p>Mutual reference of autoloaded constants can cause deadlock sporadically.</p>
<p>Assume A is defined in a.rb and it uses B at loading time.<br>
Also, B is defined in b.rb and it uses A at loading time.</p>
<pre><code>% cat a.rb
class A
def a1() end
p [__FILE__, __LINE__, B.instance_methods(false)]
def a2() end
end
% cat b.rb
class B
def b1() end
p [__FILE__, __LINE__, A.instance_methods(false)]
def b2() end
end
</code></pre>
<p>If they are loaded via autoload and constants are referenced sequentially,<br>
it works (no error, at least).</p>
<p>However, incomplete A (which a2 is not defined) is appear in b.rb, though.</p>
<pre><code>% cat base_seq.rb
autoload :A, "./a"
autoload :B, "./b"
A
B
% ruby base_seq.rb
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, [:b1, :b2]]
</code></pre>
<p>However, the constants are referenced in multi threads,<br>
deadlock can occur, or works like sequential version, sporadically.</p>
<pre><code>% cat base_thread_const.rb
autoload :A, "./a"
autoload :B, "./b"
t1 = Thread.new { A }
t2 = Thread.new { B }
t1.join
t2.join
% ruby base_thread_const.rb
Traceback (most recent call last):
1: from base_thread_const.rb:5:in `<main>'
base_thread_const.rb:5:in `join': No live threads left. Deadlock? (fatal)
3 threads, 3 sleeps current:0x000055f9e2fa1b00 main thread:0x000055f9e2ec14b0
* #<Thread:0x000055f9e2eef188 sleep_forever>
rb_thread_t:0x000055f9e2ec14b0 native:0x00007f259bc54b40 int:0
base_thread_const.rb:5:in `join'
base_thread_const.rb:5:in `<main>'
* #<Thread:0x000055f9e31ece30@base_thread_const.rb:3 sleep_forever>
rb_thread_t:0x000055f9e31403c0 native:0x00007f2597e99700 int:0
depended by: tb_thread_id:0x000055f9e2ec14b0
/tmp/h/a.rb:3:in `<class:A>'
/tmp/h/a.rb:1:in `<top (required)>'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
base_thread_const.rb:3:in `block in <main>'
* #<Thread:0x000055f9e31ecbb0@base_thread_const.rb:4 sleep_forever>
rb_thread_t:0x000055f9e2fa1b00 native:0x00007f258ffff700 int:0
/tmp/h/b.rb:3:in `<class:B>'
/tmp/h/b.rb:1:in `<top (required)>'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
base_thread_const.rb:4:in `block in <main>'
% ruby base_thread_const.rb
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, [:b1, :b2]]
</code></pre>
<p>Also, if "require" is used instead of constant references in the threads,<br>
deadlock can occur (sporadically) too.</p>
<p>Note that incomplete A can appear in b.rb and<br>
incomplete B can appear in a.rb.<br>
The incompleteness vary.</p>
<pre><code>% cat base_thread_require.rb
autoload :A, "./a"
autoload :B, "./b"
t1 = Thread.new { require './a' }
t2 = Thread.new { require './b' }
t1.join
t2.join
% ruby base_thread_require.rb
Traceback (most recent call last):
1: from base_thread_require.rb:5:in `<main>'
base_thread_require.rb:5:in `join': No live threads left. Deadlock? (fatal)
3 threads, 3 sleeps current:0x00005591a27f5190 main thread:0x00005591a24264b0
* #<Thread:0x00005591a24531a0 sleep_forever>
rb_thread_t:0x00005591a24264b0 native:0x00007feced36ab40 int:0
base_thread_require.rb:5:in `join'
base_thread_require.rb:5:in `<main>'
* #<Thread:0x00005591a2754cc8@base_thread_require.rb:3 sleep_forever>
rb_thread_t:0x00005591a27f5190 native:0x00007fece95af700 int:0
depended by: tb_thread_id:0x00005591a24264b0
/tmp/h/a.rb:1:in `<top (required)>'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
base_thread_require.rb:3:in `block in <main>'
* #<Thread:0x00005591a2754a98@base_thread_require.rb:4 sleep_forever>
rb_thread_t:0x00005591a2506b00 native:0x00007fece13ad700 int:0 mutex:0x00005591a27f5190 cond:1
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/tmp/h/b.rb:3:in `<class:B>'
/tmp/h/b.rb:1:in `<top (required)>'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require'
base_thread_require.rb:4:in `block in <main>'
% ruby base_thread_require.rb
["/tmp/h/b.rb", 3, []]
["/tmp/h/a.rb", 3, [:b1]]
% repeat 100 (ruby base_thread_require.rb >& /tmp/z && cat /tmp/z)
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/b.rb", 3, []]
["/tmp/h/a.rb", 3, [:b1]]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, [:b1, :b2]]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, [:b1, :b2]]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, [:b1, :b2]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, [:b1, :b2]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, [:b1]]
["/tmp/h/b.rb", 3, [:a1, :a2]]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, [:b1, :b2]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
["/tmp/h/a.rb", 3, []]
["/tmp/h/b.rb", 3, [:a1]]
</code></pre>
<p>I think there are several ways to solve this issue.</p>
<ul>
<li>Prohibit mutual reference.<br>
I.e. raise an error at autoload constant reference currently loading.<br>
Since mutual reference causes incomplete definition, it is dangerous even with single thread.<br>
However, if real application uses such code, this is incompatible.</li>
<li>More coarse locking.<br>
Since the deadlock is caused because two threads lock the constants in different order:<br>
A to B and B to A.<br>
I think it is possible to fix this issue by locking whole autoloading procedure by<br>
single lock, namely "global autoload lock".<br>
Note that it should also be locked by "require" method if it load a file for autoload.</li>
</ul>
Ruby master - Feature #15592 (Open): mode where "autoload" behaves like an immediate "require"
https://bugs.ruby-lang.org/issues/15592
2019-02-07T06:58:16Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about a feature to switch "autoload" behavior to "require" immediately.</p>
<p>autoload is a feature for lazy loading.</p>
<p>matz dislikes autoload as [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: "I strongly discourage the use of autoload in any standard libraries" (Re: autoload will be dead) (Closed)" href="https://bugs.ruby-lang.org/issues/5653">#5653</a>].<br>
I heard that he dislikes class (and other) definitions at arbitrary timing.<br>
I agree that eager loading is safer than lazy loading.</p>
<p>However, lazy loading realize shorter loading time and<br>
it makes development cycle shorter.<br>
It is more important for larger applications as Eregon said in<br>
<a href="https://bugs.ruby-lang.org/issues/5653#note-39" class="external">https://bugs.ruby-lang.org/issues/5653#note-39</a> .<br>
It is especially important when library loading causes I/O (code generation from DB schema).</p>
<p>These two, safety of eager loading and easier development of lazy loading, conflicts.<br>
But if we can distinguish production mode and development mode,<br>
we can enjoy both benefits.</p>
<p>So, I propose a feature to select autoload behavior from two modes:</p>
<ul>
<li>autoload behaves as lazy loading as now in development mode</li>
<li>autoload behaves as eager loading (immediately invokes "require") in production mode.</li>
</ul>
<p>There are several idea to switch the mode:</p>
<ul>
<li>$AUTOLOAD_MODE = :eager or :lazy</li>
<li>RubyVM.autoload_mode = :eager or :lazy</li>
<li>ObjectSpace.autoload_mode = :eager or lazy</li>
</ul>
<p>I'm not sure there is a good enough one in above list, though.</p>
Ruby master - Bug #15138 (Closed): non-symbol keyword in double splat, such as **{2 => 3}, raises...
https://bugs.ruby-lang.org/issues/15138
2018-09-18T17:12:30Z
akr (Akira Tanaka)
akr@fsij.org
<p>I found that non-symbol keyword in double splat, such as <code>**{2 => 3}</code>,<br>
raises TypeError in a situation and doesn't raise in another situation:</p>
<pre><code>% ./ruby -ve '
def m(*a) p a end
m(k: 1, **{2 => 3}) # [{:k=>1, 2=>3}]
m(**{4 => 5}) # hash key 4 is not a Symbol (TypeError)
'
ruby 2.6.0dev (2018-09-18 trunk 64776) [x86_64-linux]
[{:k=>1, 2=>3}]
Traceback (most recent call last):
-e:4:in `<main>': hash key 4 is not a Symbol (TypeError)
</code></pre>
<p>It seems another keyword argument, <code>k: 0</code> here, prevent TypeError.<br>
I think this behavior is not intentional.</p>
Ruby master - Bug #12337 (Closed): inconsistency between Fixnum#coerce and Bignum#coerce
https://bugs.ruby-lang.org/issues/12337
2016-05-01T13:06:54Z
akr (Akira Tanaka)
akr@fsij.org
<p>I found 1.coerce(2.0) is [2.0, 1.0] but<br>
(2**100).coerce(2.0) raises TypeError</p>
<pre><code>% ./ruby -ve 'p 1.coerce(2.0)'
ruby 2.4.0dev (2016-05-01 trunk 54866) [x86_64-linux]
[2.0, 1.0]
% ./ruby -ve 'p (2**100).coerce(2.0)'
ruby 2.4.0dev (2016-05-01 trunk 54866) [x86_64-linux]
-e:1:in `coerce': can't coerce Float to Bignum (TypeError)
from -e:1:in `<main>'
</code></pre>
<p>This is a documented behavior.</p>
<pre><code>% ri Bignum.coerce|cat
= Bignum.coerce
(from ruby core)
------------------------------------------------------------------------------
big.coerce(numeric) -> array
------------------------------------------------------------------------------
Returns an array with both a numeric and a big represented as Bignum objects.
This is achieved by converting numeric to a Bignum.
A TypeError is raised if the numeric is not a Fixnum or Bignum type.
(0x3FFFFFFFFFFFFFFF+1).coerce(42) #=> [42, 4611686018427387904]
</code></pre>
<p>But I think this is bad bahavior.<br>
Fixnum and Bignum should work seamlessly.</p>
<p>For example, this exposes the platform is 32-bit or 64-bit.<br>
2<strong>40 is Fixnum on 32-bit environment and Bignum on 64-bit environment.<br>
So, (2</strong>40).coerce(2.0) behaves differently: returns an array on 64-bit and<br>
raises TypeError on 32-bit platform.</p>
<pre><code>32bit-platform% ./ruby -ve 'p (2**40).coerce(2.0)'
ruby 2.4.0dev (2016-05-01 trunk 54866) [x86_64-linux]
[2.0, 1099511627776.0]
64bit-platform% ./ruby -ve 'p (2**40).coerce(2.0)'
ruby 2.4.0dev (2016-05-01 trunk 54864) [i686-linux]
-e:1:in `coerce': can't coerce Float to Bignum (TypeError)
from -e:1:in `<main>'
</code></pre>
<p>I think the behavior of Bignum#coerce should be changed<br>
to match Fixnum#coerce (actually defined at Numeric).</p>
Ruby master - Bug #11750 (Closed): SEGV with Enumerator, yield and proc.
https://bugs.ruby-lang.org/issues/11750
2015-11-29T16:24:28Z
akr (Akira Tanaka)
akr@fsij.org
<p>I found SEGV as follows.</p>
<pre><code>% cat z.rb
def f
Enumerator.new {|y|
1000000.times {
yield
y.yield
}
}
end
def g
x = proc {}
f(&x)
end
e = g
e.each {}
% ./miniruby z.rb
(snip)
</code></pre>
Ruby master - Bug #11701 (Closed): recvmsg for UDP without argument
https://bugs.ruby-lang.org/issues/11701
2015-11-17T08:19:15Z
akr (Akira Tanaka)
akr@fsij.org
<p>It seems recvmsg without argument doesn't work well for UDP now.</p>
<p>Following example sends a packet which size is 10000 bytes but<br>
receives a packet which size is 4096 bytes.</p>
<pre><code>% ./ruby -rsocket -ve 's1 = Addrinfo.udp("127.0.0.1", 0).bind
s2 = s1.connect_address.connect
s2.send("a"*10000, 0)
ret = s1.recvmsg
p ret[0].length
'
ruby 2.3.0dev (2015-11-17 trunk 52613) [x86_64-linux]
4096
</code></pre>
<p>ruby-2.3.0-preview1 worked well.<br>
It receives a packet which size is 10000 bytes.</p>
<pre><code>% ruby-2.3.0-preview1 -rsocket -ve 's1 = Addrinfo.udp("127.0.0.1", 0).bind
s2 = s1.connect_address.connect
s2.send("a"*10000, 0)
ret = s1.recvmsg
p ret[0].length
'
ruby 2.3.0preview1 (2015-11-11 trunk 52539) [x86_64-linux]
10000
</code></pre>
<p>This behavior (recvmsg without arguments) is documented as follows:</p>
<pre><code>maxmesglen and maxcontrollen can
be nil. In that case, the buffer will be grown until the message is not
truncated. Internally, MSG_PEEK is used and MSG_TRUNC/MSG_CTRUNC are checked.
</code></pre>
Ruby master - Bug #11672 (Closed): refinement
https://bugs.ruby-lang.org/issues/11672
2015-11-09T22:16:15Z
akr (Akira Tanaka)
akr@fsij.org
<p>I found following script behaves different between ruby 2.2.3 and trunk.<br>
Is this difference intentional?</p>
<pre><code>% cat tst.rb
class C
end
module R
refine C do
def m
puts :foo
end
end
end
using R
C.new.m
module R
refine C do
def m
puts :bar
end
end
end
C.new.m
% ./ruby -wv tst.rb
ruby 2.3.0dev (2015-11-10 trunk 52511) [x86_64-linux]
foo
foo
% ruby-2.2.3 -wv tst.rb
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
foo
tst.rb:17: warning: method redefined; discarding old m
tst.rb:6: warning: previous definition of m was here
bar
</code></pre>
Ruby master - Feature #11536 (Closed): File.mkfifo
https://bugs.ruby-lang.org/issues/11536
2015-09-18T06:33:54Z
akr (Akira Tanaka)
akr@fsij.org
<p>I'd like to add File.mkfifo.</p>
<p>It is useful for tests.<br>
FIFO is tricky: open() can block.<br>
So it is troublesome and tests can prevent problems.</p>
<p>mkfifo() is defined POSIX.<br>
Non-POSIX platform may not have it.<br>
If we provide File.mkfifo, we can check the availability as File.respond_to? :mkfifo.<br>
Current way, mkfifo command invocation, is difficult to determine the availability.<br>
This availability checking eases test condition.<br>
So this (non-implemented) method can be useful for non-POSIX platforms.</p>
<p>Several people requested File.mkfifo.<br>
ruby-talk:92371, ruby-core:15675, ruby-list:49868</p>
<p>nobu and Hongli Lai implemented it: ruby-talk:91735 and ruby-core:15822</p>
Ruby master - Bug #11272 (Closed): cross compilation problem
https://bugs.ruby-lang.org/issues/11272
2015-06-17T01:05:05Z
akr (Akira Tanaka)
akr@fsij.org
<p>3月あたりから cross compile に失敗していることに気がつきました。</p>
<p>今日の結果はたとえば<br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-arm/log/20150616T185007Z.fail.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-arm/log/20150616T185007Z.fail.html.gz</a><br>
のようなもので、以下のように失敗しています。</p>
<pre><code>generating enc.mk
./enc/make_encmake.rb:1:in `require': cannot load such file -- arm-linux-uclibcgnueabi-fake (LoadError)
</code></pre>
<p>失敗し始めたのは 3/7 のようです。<br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-arm/log/20150307T184111Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-arm/log/20150307T184111Z.diff.html.gz</a></p>
Ruby master - Bug #11060 (Closed): load(fifo) blocks whole process
https://bugs.ruby-lang.org/issues/11060
2015-04-12T08:21:04Z
akr (Akira Tanaka)
akr@fsij.org
<p>fifo を load しようとすると、プロセス全体がブロックします。</p>
<p>以下では、0.1 秒毎に表示を行うスレッドを作っていますが、<br>
0.5 秒後に load が呼ばれると表示が途切れます。</p>
<pre><code>% mkfifo fifo.rb
% ls -l fifo.rb
prw-r--r-- 1 akr akr 0 Apr 12 17:13 fifo.rb
% ./ruby -ve 'Thread.new { 0.step {|i| p i; sleep 0.1 } }; sleep 0.5; load "fifo.rb"'
ruby 2.3.0dev (2015-04-12 trunk 50257) [x86_64-linux]
0
1
2
3
4
^C5
-e:1:in `new': Interrupt
from -e:1:in `load'
from -e:1:in `<main>'
</code></pre>
<p>当然、timeout も効きません。</p>
<pre><code>% ./ruby -rtimeout -ve 'Thread.new { 0.step {|i| p i; sleep 0.1 } }; sleep 0.5; timeout(1) { load "fifo.rb" }'
ruby 2.3.0dev (2015-04-12 trunk 50257) [x86_64-linux]
0
1
2
3
4
^C5
-e:1:in `new': Interrupt
from -e:1:in `load'
from -e:1:in `block in <main>'
from /home/ruby/tst1/lib/ruby/2.3.0/timeout.rb:89:in `block in timeout'
from /home/ruby/tst1/lib/ruby/2.3.0/timeout.rb:34:in `block in catch'
from /home/ruby/tst1/lib/ruby/2.3.0/timeout.rb:34:in `catch'
from /home/ruby/tst1/lib/ruby/2.3.0/timeout.rb:34:in `catch'
from /home/ruby/tst1/lib/ruby/2.3.0/timeout.rb:104:in `timeout'
from /home/ruby/tst1/lib/ruby/2.3.0/timeout.rb:125:in `timeout'
from -e:1:in `<main>'
</code></pre>
<p>この挙動をバグと考えるべきかどうかはいまひとつ確信が持てないのですが、<br>
いまのところバグであってもおかしくないと思っています。</p>
Ruby master - Feature #10958 (Closed): remove "initial_state" argument of Enumerable#{slice_befor...
https://bugs.ruby-lang.org/issues/10958
2015-03-10T12:49:28Z
akr (Akira Tanaka)
akr@fsij.org
<p>I'd like to remove "initial_state" argument of Enumerable#{slice_before,chunk}.</p>
<p>I think a state management can be implemented using local variable without the argument.<br>
So I'd like to remove it because it is too complex and<br>
not consistent with Enumerable#{slice_when,slice_after} which doesn't have the argument.</p>
<p>Note that I added deprecated warning since Ruby 2.2.<br>
It seems no one complained the warning until now.</p>
Ruby master - Feature #10718 (Closed): IO#close should not raise IOError on closed IO objects.
https://bugs.ruby-lang.org/issues/10718
2015-01-09T01:53:14Z
akr (Akira Tanaka)
akr@fsij.org
<p>I'd like to change IO#close.<br>
It should not raise IOError on closed IO objects.</p>
<p>We sometimes invoke IO#close only when the IO object is not closed as:</p>
<pre><code>f.close if !f.closed?
</code></pre>
<p>If this issue is accepted, we can write it simply as follows.</p>
<pre><code>f.close
</code></pre>
<p>Simple grep finds many examples.<br>
Following examples are just a little excerpt.</p>
<pre><code>lib/webrick/server.rb: sock.close unless sock.closed?
lib/pstore.rb: file.close if !file.closed?
lib/mkmf.rb: @log.close if @log and not @log.closed?
lib/cgi/session.rb: f.close if f and !f.closed?
lib/open-uri.rb: io.close if !io.closed?
lib/net/pop.rb: s.close if s and not s.closed?
lib/net/http.rb: @socket.close if @socket and not @socket.closed?
lib/net/smtp.rb: s.close if s and not s.closed?
lib/shell/process-controller.rb: io.close unless io.closed?
test/ruby/test_io.rb: w.close unless !w || w.closed?
...
</code></pre>
<p>I think there is no problem with the behavior which IO#close doesn't raise an exception on closed IO object.<br>
Because the closed state fulfils the postcondition of the method.<br>
The change means relaxing the precondition which should be harmless.</p>
<p>Moreover raising IOError can smash other exceptions if it is called in ensure clause.<br>
It makes debugging difficult and the proposed behavior ease it.</p>
<p>It also useful to close IO object asynchronously.<br>
Asynchronous close can be used for graceful shutdown.<br>
This issue can eliminate "rescue IOError".<br>
See lib/webrick/server.rb and lib/drb/drb.rb for example.</p>
<p>Note that "double close" is a bad idea in C.<br>
But it is not applicable to Ruby.<br>
A FILE structure is freed on fclose().<br>
But Ruby's IO object is not freed until GC.<br>
So method invocation on closed object doesn't cause invalid memory access.<br>
A file descriptor (FD) can be reused any time because a signal handler or another thread may allocate a FD.<br>
But Ruby's IO object is not reused after close.<br>
So it is impossible to close an IO object unintentionally.</p>
Ruby master - Feature #10714 (Closed): Array#reject! nonlinear performance problem
https://bugs.ruby-lang.org/issues/10714
2015-01-08T02:24:05Z
akr (Akira Tanaka)
akr@fsij.org
<p>I found Array#reject! is too slow.</p>
<p>I measured it and it seems the performance is nonlinear.</p>
<pre><code>% ./ruby -v -e '
20.times {|i|
a = [nil]*i*10000;
t1 = Time.now
a.reject! { true }
t2 = Time.now
t = t2 - t1
p ["*" * (t * 20).to_i , t]
}
'
ruby 2.3.0dev (2015-01-08 trunk 49175) [x86_64-linux]
["", 3.683e-06]
["", 0.019059723]
["*", 0.052964771]
["**", 0.1177318]
["****", 0.208824818]
["******", 0.334757354]
["*********", 0.482717139]
["*************", 0.669606441]
["*****************", 0.866588588]
["**********************", 1.116195389]
["***************************", 1.392828177]
["**********************************", 1.701906753]
["****************************************", 2.013290644]
["************************************************", 2.415258165]
["*******************************************************", 2.783918449]
["*****************************************************************", 3.27417584]
["**************************************************************************", 3.724958298]
["**************************************************************************************", 4.307263787]
["**************************************************************************************************", 4.922179118]
["************************************************************************************************************", 5.403641168]
</code></pre>
<p>Ruby 2.2, 2.1, 2.0, 1.9.3 also have the problem but Ruby 1.9.2 works well.</p>
<pre><code>% ruby-1.9.2-p330 -v -e '
20.times {|i|
a = [nil]*i*10000;
t1 = Time.now
a.reject! { true }
t2 = Time.now
t = t2 - t1
p ["*" * (t * 20).to_i , t]
}
'
ruby 1.9.2p330 (2014-08-07 revision 47094) [x86_64-linux]
["", 2.111e-06]
["", 0.000798623]
["", 0.001441408]
["", 0.00155386]
["", 0.001656242]
["", 0.002166389]
["", 0.002355492]
["", 0.002703977]
["", 0.003123692]
["", 0.00348722]
["", 0.003884792]
["", 0.004300034]
["", 0.004701378]
["", 0.006854893]
["", 0.005485207]
["", 0.005972309]
["", 0.006298597]
["", 0.006901775]
["", 0.007216343]
["", 0.007373332]
</code></pre>
Ruby master - Bug #10699 (Closed): m(*a, **b) doesn't recognize integer options.
https://bugs.ruby-lang.org/issues/10699
2015-01-05T22:19:58Z
akr (Akira Tanaka)
akr@fsij.org
<p>It seems a method defined as m(*a, **b) doesn't recognize integer options.</p>
<pre><code>% ./ruby -v -e '
def m(*a, **b)
p [a, b]
end
m(1, 2 => 3)
m(1, :foo => 3)
'
ruby 2.3.0dev (2015-01-06 trunk 49159) [x86_64-linux]
[[1, {2=>3}], {}]
[[1], {:foo=>3}]
</code></pre>
<p>I think the result should be follows.</p>
<pre><code>[[1], {2=>3}]
[[1], {:foo=>3}]
</code></pre>
<p>I found this problem by <a href="https://github.com/ruby/ruby/pull/808" class="external">https://github.com/ruby/ruby/pull/808</a></p>
Ruby master - Bug #10556 (Closed): shebang handling
https://bugs.ruby-lang.org/issues/10556
2014-11-29T17:18:25Z
akr (Akira Tanaka)
akr@fsij.org
<p>以下のようなスクリプトを ruby で実行すると、途中の #!ruby 以降が<br>
実行されるのは意図されない動作な気がするのですが、なにか理由がありましたっけ?</p>
<pre><code>% cat tst.rb
#!/bin/echo
p 1
#!ruby
p 2
% ./ruby tst.rb
2
% ./ruby -v
ruby 2.2.0dev (2014-11-27 trunk 48614) [x86_64-linux]
</code></pre>
<p>昔 (1.9.2 preview1 以前) は、echo が実行されていたようです。</p>
<pre><code>% all-ruby tst.rb
...
ruby-1.9.2-preview1 tst.rb
ruby-1.9.2-preview3 2
...
</code></pre>
<p>shebang 行に書いてあるのを実行する機能はなくしちゃってもいいような気もしますが。</p>
Ruby master - Bug #10545 (Closed): SEGV: def m(A: a) end
https://bugs.ruby-lang.org/issues/10545
2014-11-26T02:27:27Z
akr (Akira Tanaka)
akr@fsij.org
<p>def m(A: a) end とすると SEGV するようです。</p>
<pre><code>% ./ruby -e 'def m(A: a) end'
-e:1: formal argument must be local variable
def m(A: a) end
^
-e:1: dynamic constant assignment
def m(A: a) end
^
./ruby: [BUG] Segmentation fault at 0x00000000000018
ruby 2.2.0dev (2014-11-26 trunk 48578) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0001 p:0000 s:0002 E:000440 TOP [FINISH]
-- Machine register context ------------------------------------------------
RIP: 0x00007f027ffa1830 RBP: 0x00007fff30389f10 RSP: 0x00007fff30389e90
RAX: 0x0000000000000000 RBX: 0x00007fff3038bf50 RCX: 0x00007f0281fd4200
RDX: 0x0000000000000000 RDI: 0x00007f0281bcca20 RSI: 0x00007f0281fd4200
R8: 0x0000000000000001 R9: 0x00007f0281fccd10 R10: 0x00007fff30389ad0
R11: 0x0000000000000000 R12: 0x00007f027fdec950 R13: 0x00007fff3038c090
R14: 0x0000000000000000 R15: 0x0000000000000000 EFL: 0x0000000000010206
-- C level backtrace information -------------------------------------------
/home/ruby/tst1/ruby/ruby(rb_print_backtrace+0x19) [0x7f027ff25d91] vm_dump.c:693
/home/ruby/tst1/ruby/ruby(rb_vm_bugreport+0xa9) [0x7f027ff26206] vm_dump.c:971
/home/ruby/tst1/ruby/ruby(rb_bug_context+0x113) [0x7f027ff82d6e] error.c:389
/home/ruby/tst1/ruby/ruby(sigsegv+0x5e) [0x7f027fead435] signal.c:849
/lib/x86_64-linux-gnu/libpthread.so.0 [0x7f027f99a8d0]
/home/ruby/tst1/ruby/ruby(new_args_tail_gen+0xb0) [0x7f027ffa1830] parse.y:9718
/home/ruby/tst1/ruby/ruby(ruby_yyparse+0x8fde) [0x7f027ff93b4e] parse.y:4522
/home/ruby/tst1/ruby/ruby(yycompile0+0x189) [0x7f027ff95fb8] parse.y:5489
/home/ruby/tst1/ruby/ruby(rb_suppress_tracing+0x18b) [0x7f027ff2a2a3] vm_trace.c:402
/home/ruby/tst1/ruby/ruby(yycompile+0x7e) [0x7f027ff9616b] parse.y:5522
/home/ruby/tst1/ruby/ruby(parser_compile_string+0xc5) [0x7f027ff96474] parse.y:5590
/home/ruby/tst1/ruby/ruby(rb_parser_compile_string_path+0x3a) [0x7f027ff96554] parse.y:5613
/home/ruby/tst1/ruby/ruby(rb_parser_compile_string+0x39) [0x7f027ff96518] parse.y:5606
./ruby [0x7f027feaa41a]
/home/ruby/tst1/ruby/ruby(ruby_process_options+0xb7) [0x7f027feabc32] ruby.c:1930
/home/ruby/tst1/ruby/ruby(ruby_options+0x11f) [0x7f027fdee499] eval.c:100
/home/ruby/tst1/ruby/ruby(main+0x69) [0x7f027fdecae9] main.c:36
-- Other runtime information -----------------------------------------------
* Loaded script: ./ruby
* Loaded features:
0 enumerator.so
1 rational.so
2 complex.so
3 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
4 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
5 /home/ruby/tst1/lib/ruby/2.2.0/unicode_normalize.rb
6 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/rbconfig.rb
7 thread.rb
8 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
9 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/compatibility.rb
10 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/defaults.rb
11 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/deprecate.rb
12 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/errors.rb
13 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/version.rb
14 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/requirement.rb
15 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/platform.rb
16 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/basic_specification.rb
17 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/stub_specification.rb
18 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/util/stringio.rb
19 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/specification.rb
20 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/exceptions.rb
21 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb
22 /home/ruby/tst1/lib/ruby/2.2.0/monitor.rb
23 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb
24 /home/ruby/tst1/lib/ruby/2.2.0/rubygems.rb
* Process memory map:
7f027dbe9000-7f027dd90000 r--s 00000000 08:01 11804384 /lib/x86_64-linux-gnu/libc-2.19.so
7f027dd90000-7f027e302000 r--s 00000000 08:01 15073377 /home/ruby/tst1/ruby/ruby
7f027e302000-7f027e318000 r-xp 00000000 08:01 11796586 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f027e318000-7f027e517000 ---p 00016000 08:01 11796586 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f027e517000-7f027e518000 rw-p 00015000 08:01 11796586 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f027e518000-7f027e51b000 r-xp 00000000 08:01 15859747 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
7f027e51b000-7f027e71b000 ---p 00003000 08:01 15859747 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
7f027e71b000-7f027e71c000 rw-p 00003000 08:01 15859747 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
7f027e71c000-7f027e71e000 r-xp 00000000 08:01 15859769 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7f027e71e000-7f027e91e000 ---p 00002000 08:01 15859769 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7f027e91e000-7f027e91f000 rw-p 00002000 08:01 15859769 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7f027e91f000-7f027e921000 r-xp 00000000 08:01 15859801 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7f027e921000-7f027eb21000 ---p 00002000 08:01 15859801 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7f027eb21000-7f027eb22000 rw-p 00002000 08:01 15859801 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7f027eb22000-7f027ec23000 rw-p 00000000 00:00 0
7f027ec23000-7f027edc2000 r-xp 00000000 08:01 11804384 /lib/x86_64-linux-gnu/libc-2.19.so
7f027edc2000-7f027efc2000 ---p 0019f000 08:01 11804384 /lib/x86_64-linux-gnu/libc-2.19.so
7f027efc2000-7f027efc6000 r--p 0019f000 08:01 11804384 /lib/x86_64-linux-gnu/libc-2.19.so
7f027efc6000-7f027efc8000 rw-p 001a3000 08:01 11804384 /lib/x86_64-linux-gnu/libc-2.19.so
7f027efc8000-7f027efcc000 rw-p 00000000 00:00 0
7f027efcc000-7f027f0cc000 r-xp 00000000 08:01 11804388 /lib/x86_64-linux-gnu/libm-2.19.so
7f027f0cc000-7f027f2cb000 ---p 00100000 08:01 11804388 /lib/x86_64-linux-gnu/libm-2.19.so
7f027f2cb000-7f027f2cc000 r--p 000ff000 08:01 11804388 /lib/x86_64-linux-gnu/libm-2.19.so
7f027f2cc000-7f027f2cd000 rw-p 00100000 08:01 11804388 /lib/x86_64-linux-gnu/libm-2.19.so
7f027f2cd000-7f027f2d5000 r-xp 00000000 08:01 11804386 /lib/x86_64-linux-gnu/libcrypt-2.19.so
7f027f2d5000-7f027f4d4000 ---p 00008000 08:01 11804386 /lib/x86_64-linux-gnu/libcrypt-2.19.so
7f027f4d4000-7f027f4d5000 r--p 00007000 08:01 11804386 /lib/x86_64-linux-gnu/libcrypt-2.19.so
7f027f4d5000-7f027f4d6000 rw-p 00008000 08:01 11804386 /lib/x86_64-linux-gnu/libcrypt-2.19.so
7f027f4d6000-7f027f504000 rw-p 00000000 00:00 0
7f027f504000-7f027f507000 r-xp 00000000 08:01 11804387 /lib/x86_64-linux-gnu/libdl-2.19.so
7f027f507000-7f027f706000 ---p 00003000 08:01 11804387 /lib/x86_64-linux-gnu/libdl-2.19.so
7f027f706000-7f027f707000 r--p 00002000 08:01 11804387 /lib/x86_64-linux-gnu/libdl-2.19.so
7f027f707000-7f027f708000 rw-p 00003000 08:01 11804387 /lib/x86_64-linux-gnu/libdl-2.19.so
7f027f708000-7f027f789000 r-xp 00000000 08:01 16780134 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7f027f789000-7f027f989000 ---p 00081000 08:01 16780134 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7f027f989000-7f027f98a000 r--p 00081000 08:01 16780134 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7f027f98a000-7f027f98b000 rw-p 00082000 08:01 16780134 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7f027f98b000-7f027f9a3000 r-xp 00000000 08:01 11804379 /lib/x86_64-linux-gnu/libpthread-2.19.so
7f027f9a3000-7f027fba2000 ---p 00018000 08:01 11804379 /lib/x86_64-linux-gnu/libpthread-2.19.so
7f027fba2000-7f027fba3000 r--p 00017000 08:01 11804379 /lib/x86_64-linux-gnu/libpthread-2.19.so
7f027fba3000-7f027fba4000 rw-p 00018000 08:01 11804379 /lib/x86_64-linux-gnu/libpthread-2.19.so
7f027fba4000-7f027fba8000 rw-p 00000000 00:00 0
7f027fba8000-7f027fbc8000 r-xp 00000000 08:01 11804381 /lib/x86_64-linux-gnu/ld-2.19.so
7f027fbd8000-7f027fc7c000 r--s 00000000 08:01 16912861 /usr/lib/debug/lib/x86_64-linux-gnu/libpthread-2.19.so
7f027fc7c000-7f027fc9e000 r--s 00000000 08:01 11804379 /lib/x86_64-linux-gnu/libpthread-2.19.so
7f027fc9e000-7f027fda6000 r--p 00000000 08:01 16783711 /usr/lib/locale/locale-archive
7f027fda6000-7f027fdab000 rw-p 00000000 00:00 0
7f027fdc1000-7f027fdc2000 rw-p 00000000 00:00 0
7f027fdc2000-7f027fdc3000 ---p 00000000 00:00 0
7f027fdc3000-7f027fdc8000 rw-p 00000000 00:00 0 [stack:11510]
7f027fdc8000-7f027fdc9000 r--p 00020000 08:01 11804381 /lib/x86_64-linux-gnu/ld-2.19.so
7f027fdc9000-7f027fdca000 rw-p 00021000 08:01 11804381 /lib/x86_64-linux-gnu/ld-2.19.so
7f027fdca000-7f027fdcb000 rw-p 00000000 00:00 0
7f027fdcb000-7f0280082000 r-xp 00000000 08:01 15073377 /home/ruby/tst1/ruby/ruby
7f0280281000-7f0280287000 rw-p 002b6000 08:01 15073377 /home/ruby/tst1/ruby/ruby
7f0280287000-7f028029a000 rw-p 00000000 00:00 0
7f0281bcb000-7f0281ff5000 rw-p 00000000 00:00 0 [heap]
7fff3036d000-7fff3038e000 rw-p 00000000 00:00 0
7fff303fc000-7fff303fe000 r-xp 00000000 00:00 0 [vdso]
7fff303fe000-7fff30400000 r--p 00000000 00:00 0 [vvar]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
</code></pre>
Ruby master - Bug #10543 (Closed): ruby -c and ripper inconsistency: /(?<n>a(b|\g<n>))/
https://bugs.ruby-lang.org/issues/10543
2014-11-25T23:41:05Z
akr (Akira Tanaka)
akr@fsij.org
<p>以下のように、/(?a(b|\g))/ というだけのソースは<br>
ruby -c では問題無しとなりますが、<br>
Ripper.sexp では構文木でなく nil が返ってきてしまいます。</p>
<pre><code>% cat z.rb
/(?<n>a(b|\g<n>))/
% ./ruby -c z.rb
Syntax OK
% ./ruby -rripper -e 'p Ripper.sexp(STDIN.read)' < z.rb
nil
% ./ruby -v
ruby 2.2.0dev (2014-11-26 trunk 48577) [x86_64-linux]
</code></pre>
Ruby master - Bug #10542 (Closed): out-of-place build from repository builds enc/trans/*.c in the...
https://bugs.ruby-lang.org/issues/10542
2014-11-25T22:15:37Z
akr (Akira Tanaka)
akr@fsij.org
<p>repository から checkout した ruby を out-of-place で build すると、<br>
enc/trans/big5.c などいくつかのファイルが<br>
source directory と build directory の両方に生成されます。<br>
どちらかだけに生成されるのが意図された動作なんじゃないでしょうか。</p>
<pre><code>% cd /tmp
% mkdir r
% cd r
% svn co -q http://svn.ruby-lang.org/repos/ruby/trunk ruby
% cd ruby
% svn info
Path: .
Working Copy Root Path: /tmp/r/ruby
URL: http://svn.ruby-lang.org/repos/ruby/trunk
Relative URL: ^/trunk
Repository Root: http://svn.ruby-lang.org/repos/ruby
Repository UUID: b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Revision: 48577
Node Kind: directory
Schedule: normal
Last Changed Author: akr
Last Changed Rev: 48577
Last Changed Date: 2014-11-26 06:09:34 +0900 (Wed, 26 Nov 2014)
% autoconf
% cd ..
% mkdir o
% cd o
% ../ruby/configure --prefix=/tmp/r >& ../z.configure.log
% make >& ../z.make.log
% ./ruby -v
ruby 2.2.0dev (2014-11-26 trunk 48577) [x86_64-linux]
% cd ..
% ls */enc/trans/*.c
o/enc/trans/big5.c ruby/enc/trans/chinese.c
o/enc/trans/chinese.c ruby/enc/trans/emoji.c
o/enc/trans/emoji.c ruby/enc/trans/emoji_iso2022_kddi.c
o/enc/trans/emoji_iso2022_kddi.c ruby/enc/trans/emoji_sjis_docomo.c
o/enc/trans/emoji_sjis_docomo.c ruby/enc/trans/emoji_sjis_kddi.c
o/enc/trans/emoji_sjis_kddi.c ruby/enc/trans/emoji_sjis_softbank.c
o/enc/trans/emoji_sjis_softbank.c ruby/enc/trans/escape.c
o/enc/trans/escape.c ruby/enc/trans/gb18030.c
o/enc/trans/gb18030.c ruby/enc/trans/gbk.c
o/enc/trans/gbk.c ruby/enc/trans/iso2022.c
o/enc/trans/iso2022.c ruby/enc/trans/japanese.c
o/enc/trans/japanese.c ruby/enc/trans/japanese_euc.c
o/enc/trans/japanese_euc.c ruby/enc/trans/japanese_sjis.c
o/enc/trans/japanese_sjis.c ruby/enc/trans/korean.c
o/enc/trans/korean.c ruby/enc/trans/single_byte.c
o/enc/trans/single_byte.c ruby/enc/trans/transdb.c
o/enc/trans/utf8_mac.c ruby/enc/trans/utf8_mac.c
o/enc/trans/utf_16_32.c ruby/enc/trans/utf_16_32.c
ruby/enc/trans/big5.c
% grep '^generating .*trans.*\.c ' z.make.log
generating enc/trans/big5.c ...
generating enc/trans/chinese.c ...
generating enc/trans/emoji.c ...
generating enc/trans/emoji_iso2022_kddi.c ...
generating enc/trans/emoji_sjis_docomo.c ...
generating enc/trans/emoji_sjis_kddi.c ...
generating enc/trans/emoji_sjis_softbank.c ...
generating enc/trans/escape.c ...
generating enc/trans/gb18030.c ...
generating enc/trans/gbk.c ...
generating enc/trans/iso2022.c ...
generating enc/trans/japanese.c ...
generating enc/trans/japanese_euc.c ...
generating enc/trans/japanese_sjis.c ...
generating enc/trans/korean.c ...
generating enc/trans/single_byte.c ...
generating enc/trans/utf8_mac.c ...
generating enc/trans/utf_16_32.c ...
generating ../ruby/enc/trans/big5.c ...
generating ../ruby/enc/trans/chinese.c ...
generating ../ruby/enc/trans/emoji.c ...
generating ../ruby/enc/trans/emoji_iso2022_kddi.c ...
generating ../ruby/enc/trans/emoji_sjis_docomo.c ...
generating ../ruby/enc/trans/emoji_sjis_kddi.c ...
generating ../ruby/enc/trans/emoji_sjis_softbank.c ...
generating ../ruby/enc/trans/escape.c ...
generating ../ruby/enc/trans/gb18030.c ...
generating ../ruby/enc/trans/gbk.c ...
generating ../ruby/enc/trans/iso2022.c ...
generating ../ruby/enc/trans/japanese.c ...
generating ../ruby/enc/trans/japanese_euc.c ...
generating ../ruby/enc/trans/japanese_sjis.c ...
generating ../ruby/enc/trans/korean.c ...
generating ../ruby/enc/trans/single_byte.c ...
generating ../ruby/enc/trans/utf8_mac.c ...
generating ../ruby/enc/trans/utf_16_32.c ...
% make --version
GNU Make 4.0
このプログラムは x86_64-pc-linux-gnu 用にビルドされました
Copyright (C) 1988-2013 Free Software Foundation, Inc.
ライセンス GPLv3+: GNU GPL バージョン 3 以降 <http://gnu.org/licenses/gpl.html>
これはフリーソフトウェアです: 自由に変更および配布できます.
法律の許す限り、 無保証 です.
%
</code></pre>
<p>なお、Ruby 2.1.5 でも試しましたが同様になります。</p>
Ruby master - Bug #10437 (Closed): ruby -c and ripper inconsistency: /*/
https://bugs.ruby-lang.org/issues/10437
2014-10-28T02:38:24Z
akr (Akira Tanaka)
akr@fsij.org
<p>/*/ という、間違った regexp リテラルは<br>
ruby -c ではちゃんとエラーになるのですが、<br>
Ripper.sexp ではエラーになりません。</p>
<pre><code>% cat z.rb
/*/
% ruby -c z.rb
z.rb:1: target of repeat operator is not specified: /*/
% ruby -rripper -e 'p Ripper.sexp(STDIN.read)' < z.rb
[:program, [[:regexp_literal, [[:@tstring_content, "*", [1, 1]]], [:@regexp_end, "/", [1, 2]]]]]
% ruby -v
ruby 2.2.0dev (2014-10-27 trunk 48168) [x86_64-linux]
</code></pre>
<p>Ripper では regexp object を作らないからでしょうが、<br>
syntax error を調べる目的に対して不都合ではあります。</p>
Ruby master - Bug #10436 (Closed): ruby -c and ripper inconsistency: m(&nil) {}
https://bugs.ruby-lang.org/issues/10436
2014-10-28T01:24:56Z
akr (Akira Tanaka)
akr@fsij.org
<p>m(&nil) {} というまちがったコードは<br>
ruby -c でちゃんとエラーになるのに、<br>
Ripper.sexp ではならないようです。</p>
<pre><code>% cat z.rb
m(&nil) {}
% ruby -c z.rb
z.rb:1: both block arg and actual block given
% ruby -rripper -e 'p Ripper.sexp(STDIN.read)' < z.rb
[:program, [[:method_add_block, [:method_add_arg, [:fcall, [:@ident, "m", [1, 0]]], [:arg_paren, [:args_add_block, [], [:var_ref, [:@kw, "nil", [1, 3]]]]]], [:brace_block, nil, [[:void_stmt]]]]]]
% ruby -v
ruby 2.2.0dev (2014-10-27 trunk 48168) [x86_64-linux]
</code></pre>
Ruby master - Bug #10435 (Closed): ruby -c file can run.
https://bugs.ruby-lang.org/issues/10435
2014-10-28T01:19:26Z
akr (Akira Tanaka)
akr@fsij.org
<p>ruby -c file としたときに、実行が起きてしまうことがあるようです。</p>
<pre><code>% cat z.rb
#! /usr/bin/env ruby -r./z
p :run
% ruby -vc z.rb
ruby 2.2.0dev (2014-10-27 trunk 48168) [x86_64-linux]
:run
Syntax OK
</code></pre>
Ruby master - Bug #10411 (Closed): Ripper.sexp("foo\n .bar") extract a wrong method name ...
https://bugs.ruby-lang.org/issues/10411
2014-10-22T03:29:18Z
akr (Akira Tanaka)
akr@fsij.org
<p>以下のように、ripper が、メソッド名として " .bar" などといった<br>
空白やピリオドの入った文字列を取り出してくることがあります。</p>
<pre><code>% ./ruby -v -rripper -e 'p Ripper.sexp("foo\n .bar")'
ruby 2.2.0dev (2014-10-22 trunk 48083) [x86_64-linux]
[:program, [[:call, [:vcall, [:@ident, "foo", [1, 0]]], :".", [:@ident, " .bar", [2, 0]]]]]
</code></pre>
<p>改行を入れなければ、"bar" という期待するメソッド名が取り出されます。</p>
<pre><code>% ./ruby -rripper -e 'p Ripper.sexp("foo .bar")'
[:program, [[:call, [:vcall, [:@ident, "foo", [1, 0]]], :".", [:@ident, "bar", [1, 13]]]]]
</code></pre>
Ruby master - Bug #10405 (Closed): syntax error inconsistency between ruby -c and ripper
https://bugs.ruby-lang.org/issues/10405
2014-10-20T10:23:00Z
akr (Akira Tanaka)
akr@fsij.org
<p>以下のように、a / b c という内容のファイルを<br>
ruby -c で検査すると syntax error になるのですが<br>
Ripper.sexp に適用するとなにか構文木が返ってきます。</p>
<pre><code>% cat z.rb
a / b c
% ./ruby -c z.rb
z.rb:1: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
zsh: exit 1 ./ruby -c z.rb
% ./ruby -rripper -e 'p Ripper.sexp(STDIN.read)' < z.rb
[:program, [:vcall, [:@ident, "c", [1, 6]]]]
% ./ruby -v
ruby 2.2.0dev (2014-10-20 trunk 48052) [x86_64-linux]
</code></pre>
<p>これは変な気がするんですがどうでしょうか。</p>
Ruby master - Bug #10392 (Closed): Ripper.sexp("<<'E'\n E\n\n")
https://bugs.ruby-lang.org/issues/10392
2014-10-16T05:20:48Z
akr (Akira Tanaka)
akr@fsij.org
<p>以下のようにすると SEGV になります。</p>
<pre><code>% cat z.rb
require 'ripper'
Ripper.sexp("<<'E'\n E\n\n")
% ./ruby z.rb
/home/ruby/tst1/lib/ruby/2.2.0/ripper/sexp.rb:31: [BUG] Segmentation fault at 0x00000000000008
ruby 2.2.0dev (2014-10-16 trunk 47971) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0004 p:---- s:0013 e:000012 CFUNC :parse
c:0003 p:0028 s:0010 e:000009 METHOD /home/ruby/tst1/lib/ruby/2.2.0/ripper/sexp.rb:31
c:0002 p:0021 s:0004 E:000190 EVAL z.rb:2 [FINISH]
c:0001 p:0000 s:0002 E:001920 TOP [FINISH]
-- Ruby level backtrace information ----------------------------------------
z.rb:2:in `<main>'
/home/ruby/tst1/lib/ruby/2.2.0/ripper/sexp.rb:31:in `sexp'
/home/ruby/tst1/lib/ruby/2.2.0/ripper/sexp.rb:31:in `parse'
-- Machine register context ------------------------------------------------
RIP: 0x00007fc0402e08ca RBP: 0x00007fffbe5f1a20 RSP: 0x00007fffbe5f19f0
RAX: 0x0000000000000000 RBX: 0x0000000000000097 RCX: 0x0000000000000097
RDX: 0x00007fffbe5f1a40 RDI: 0x00007fc042a98ae0 RSI: 0x0000000000000097
R8: 0x00007fc042a3fc50 R9: 0x0000000000000003 R10: 0x00007fffbe5f1ac0
R11: 0x00007fc0402eaa06 R12: 0x00007fc040215860 R13: 0x00007fffbe5f3d50
R14: 0x00007fc042a9ab70 R15: 0x00007fc03f04bf20 EFL: 0x0000000000010206
-- C level backtrace information -------------------------------------------
/home/ruby/tst1/ruby/ruby(rb_print_backtrace+0x19) [0x7fc04034c0f1] vm_dump.c:694
/home/ruby/tst1/ruby/ruby(rb_vm_bugreport+0xa9) [0x7fc04034c566] vm_dump.c:972
/home/ruby/tst1/ruby/ruby(rb_bug_context+0x113) [0x7fc0403a90b3] error.c:391
/home/ruby/tst1/ruby/ruby(sigsegv+0x8d) [0x7fc0402d61f8] signal.c:851
/lib/x86_64-linux-gnu/libpthread.so.0 [0x7fc03fdc38d0]
/home/ruby/tst1/ruby/ruby(st_lookup+0x1b) [0x7fc0402e08ca] st.c:386
/home/ruby/tst1/ruby/ruby(lookup_method_table+0x4a) [0x7fc04033cb16] vm_method.c:209
/home/ruby/tst1/ruby/ruby(search_method+0x31) [0x7fc04033d86e] vm_method.c:566
/home/ruby/tst1/ruby/ruby(rb_method_entry_get_without_cache+0x2b) [0x7fc04033d8fa] vm_method.c:591
/home/ruby/tst1/ruby/ruby(rb_method_entry+0xb8) [0x7fc04033dae2] vm_method.c:662
/home/ruby/tst1/ruby/ruby(check_funcall_respond_to+0x2d) [0x7fc0403407fa] vm_eval.c:369
/home/ruby/tst1/ruby/ruby(rb_check_funcall+0x48) [0x7fc040340a13] vm_eval.c:426
/home/ruby/tst1/ruby/ruby(convert_type+0xcc) [0x7fc04027ae48] object.c:2611
/home/ruby/tst1/ruby/ruby(rb_convert_type+0x47) [0x7fc04027afe8] object.c:2647
/home/ruby/tst1/ruby/ruby(rb_str_to_str+0x2b) [0x7fc0402e61f1] string.c:1057
/home/ruby/tst1/ruby/ruby(rb_string_value+0x4b) [0x7fc0402e827a] string.c:1657
/home/ruby/tst1/ruby/ruby(rb_str_append+0x1c) [0x7fc0402eaa22] string.c:2340
/home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so(parser_here_document+0x197) [0x7fc03e72620b] ripper.y:6540
/home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so(parser_yylex+0x5c) [0x7fc03e729345] ripper.y:7676
/home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so(yylex+0x3f) [0x7fc03e72b004] ripper.y:8334
/home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so(ripper_yyparse+0x383) [0x7fc03e71b899] parse.c:4767
/home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so(ripper_parse0+0x3b) [0x7fc03e72d1b8] ripper.y:10853
/home/ruby/tst1/ruby/ruby(rb_ensure+0x148) [0x7fc0402194cf] eval.c:911
/home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so(ripper_parse+0xe5) [0x7fc03e72d2e3] ripper.y:10889
/home/ruby/tst1/ruby/ruby(call_cfunc_0+0x29) [0x7fc040331db2] vm_insnhelper.c:1357
/home/ruby/tst1/ruby/ruby(vm_call_cfunc_with_frame+0x1fc) [0x7fc0403328a6] vm_insnhelper.c:1523
/home/ruby/tst1/ruby/ruby(vm_call_cfunc+0x2b) [0x7fc0403329af] vm_insnhelper.c:1613
/home/ruby/tst1/ruby/ruby(vm_call_method+0x113) [0x7fc040333382] vm_insnhelper.c:1801
/home/ruby/tst1/ruby/ruby(vm_call_general+0x2b) [0x7fc040333bdb] vm_insnhelper.c:1960
/home/ruby/tst1/ruby/ruby(vm_exec_core+0x27d1) [0x7fc040337460] insns.def:1028
/home/ruby/tst1/ruby/ruby(vm_exec+0xe4) [0x7fc040347838] vm.c:1367
/home/ruby/tst1/ruby/ruby(rb_iseq_eval_main+0x34) [0x7fc0403489cc] vm.c:1637
/home/ruby/tst1/ruby/ruby(ruby_exec_internal+0x131) [0x7fc040217bbf] eval.c:253
/home/ruby/tst1/ruby/ruby(ruby_exec_node+0x24) [0x7fc040217ce8] eval.c:318
/home/ruby/tst1/ruby/ruby(ruby_run_node+0x3e) [0x7fc040217cbb] eval.c:310
/home/ruby/tst1/ruby/ruby(main+0x71) [0x7fc040215a01] main.c:36
-- Other runtime information -----------------------------------------------
* Loaded script: z.rb
* Loaded features:
0 enumerator.so
1 rational.so
2 complex.so
3 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
4 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
5 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/rbconfig.rb
6 thread.rb
7 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
8 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/compatibility.rb
9 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/defaults.rb
10 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/deprecate.rb
11 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/errors.rb
12 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/version.rb
13 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/requirement.rb
14 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/platform.rb
15 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/basic_specification.rb
16 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/stub_specification.rb
17 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/util/stringio.rb
18 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/specification.rb
19 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/exceptions.rb
20 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb
21 /home/ruby/tst1/lib/ruby/2.2.0/monitor.rb
22 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb
23 /home/ruby/tst1/lib/ruby/2.2.0/rubygems.rb
24 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so
25 /home/ruby/tst1/lib/ruby/2.2.0/ripper/core.rb
26 /home/ruby/tst1/lib/ruby/2.2.0/ripper/lexer.rb
27 /home/ruby/tst1/lib/ruby/2.2.0/ripper/filter.rb
28 /home/ruby/tst1/lib/ruby/2.2.0/ripper/sexp.rb
29 /home/ruby/tst1/lib/ruby/2.2.0/ripper.rb
* Process memory map:
7fc03dd78000-7fc03df1e000 r--s 00000000 08:01 11799878 /lib/x86_64-linux-gnu/libc-2.19.so
7fc03df1e000-7fc03df95000 r--s 00000000 08:01 15859726 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so
7fc03df95000-7fc03e4fb000 r--s 00000000 08:01 15073361 /home/ruby/tst1/ruby/ruby
7fc03e4fb000-7fc03e511000 r-xp 00000000 08:01 11796487 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fc03e511000-7fc03e710000 ---p 00016000 08:01 11796487 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fc03e710000-7fc03e711000 rw-p 00015000 08:01 11796487 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fc03e711000-7fc03e741000 r-xp 00000000 08:01 15859726 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so
7fc03e741000-7fc03e940000 ---p 00030000 08:01 15859726 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so
7fc03e940000-7fc03e943000 rw-p 0002f000 08:01 15859726 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/ripper.so
7fc03e943000-7fc03e946000 r-xp 00000000 08:01 15859747 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
7fc03e946000-7fc03eb46000 ---p 00003000 08:01 15859747 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
7fc03eb46000-7fc03eb47000 rw-p 00003000 08:01 15859747 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
7fc03eb47000-7fc03eb49000 r-xp 00000000 08:01 15859769 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7fc03eb49000-7fc03ed49000 ---p 00002000 08:01 15859769 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7fc03ed49000-7fc03ed4a000 rw-p 00002000 08:01 15859769 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7fc03ed4a000-7fc03ed4c000 r-xp 00000000 08:01 15859801 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7fc03ed4c000-7fc03ef4b000 ---p 00002000 08:01 15859801 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7fc03ef4b000-7fc03ef4c000 rw-p 00001000 08:01 15859801 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7fc03ef4c000-7fc03f04d000 rw-p 00000000 00:00 0
7fc03f04d000-7fc03f1ec000 r-xp 00000000 08:01 11799878 /lib/x86_64-linux-gnu/libc-2.19.so
7fc03f1ec000-7fc03f3eb000 ---p 0019f000 08:01 11799878 /lib/x86_64-linux-gnu/libc-2.19.so
7fc03f3eb000-7fc03f3ef000 r--p 0019e000 08:01 11799878 /lib/x86_64-linux-gnu/libc-2.19.so
7fc03f3ef000-7fc03f3f1000 rw-p 001a2000 08:01 11799878 /lib/x86_64-linux-gnu/libc-2.19.so
7fc03f3f1000-7fc03f3f5000 rw-p 00000000 00:00 0
7fc03f3f5000-7fc03f4f5000 r-xp 00000000 08:01 11799873 /lib/x86_64-linux-gnu/libm-2.19.so
7fc03f4f5000-7fc03f6f4000 ---p 00100000 08:01 11799873 /lib/x86_64-linux-gnu/libm-2.19.so
7fc03f6f4000-7fc03f6f5000 r--p 000ff000 08:01 11799873 /lib/x86_64-linux-gnu/libm-2.19.so
7fc03f6f5000-7fc03f6f6000 rw-p 00100000 08:01 11799873 /lib/x86_64-linux-gnu/libm-2.19.so
7fc03f6f6000-7fc03f6fe000 r-xp 00000000 08:01 11799883 /lib/x86_64-linux-gnu/libcrypt-2.19.so
7fc03f6fe000-7fc03f8fd000 ---p 00008000 08:01 11799883 /lib/x86_64-linux-gnu/libcrypt-2.19.so
7fc03f8fd000-7fc03f8fe000 r--p 00007000 08:01 11799883 /lib/x86_64-linux-gnu/libcrypt-2.19.so
7fc03f8fe000-7fc03f8ff000 rw-p 00008000 08:01 11799883 /lib/x86_64-linux-gnu/libcrypt-2.19.so
7fc03f8ff000-7fc03f92d000 rw-p 00000000 00:00 0
7fc03f92d000-7fc03f930000 r-xp 00000000 08:01 11796508 /lib/x86_64-linux-gnu/libdl-2.19.so
7fc03f930000-7fc03fb2f000 ---p 00003000 08:01 11796508 /lib/x86_64-linux-gnu/libdl-2.19.so
7fc03fb2f000-7fc03fb30000 r--p 00002000 08:01 11796508 /lib/x86_64-linux-gnu/libdl-2.19.so
7fc03fb30000-7fc03fb31000 rw-p 00003000 08:01 11796508 /lib/x86_64-linux-gnu/libdl-2.19.so
7fc03fb31000-7fc03fbb2000 r-xp 00000000 08:01 16780134 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7fc03fbb2000-7fc03fdb2000 ---p 00081000 08:01 16780134 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7fc03fdb2000-7fc03fdb3000 r--p 00081000 08:01 16780134 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7fc03fdb3000-7fc03fdb4000 rw-p 00082000 08:01 16780134 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7fc03fdb4000-7fc03fdcc000 r-xp 00000000 08:01 11799871 /lib/x86_64-linux-gnu/libpthread-2.19.so
7fc03fdcc000-7fc03ffcb000 ---p 00018000 08:01 11799871 /lib/x86_64-linux-gnu/libpthread-2.19.so
7fc03ffcb000-7fc03ffcc000 r--p 00017000 08:01 11799871 /lib/x86_64-linux-gnu/libpthread-2.19.so
7fc03ffcc000-7fc03ffcd000 rw-p 00018000 08:01 11799871 /lib/x86_64-linux-gnu/libpthread-2.19.so
7fc03ffcd000-7fc03ffd1000 rw-p 00000000 00:00 0
7fc03ffd1000-7fc03fff1000 r-xp 00000000 08:01 11799884 /lib/x86_64-linux-gnu/ld-2.19.so
7fc040002000-7fc0400a6000 r--s 00000000 08:01 16913977 /usr/lib/debug/lib/x86_64-linux-gnu/libpthread-2.19.so
7fc0400a6000-7fc0400c8000 r--s 00000000 08:01 11799871 /lib/x86_64-linux-gnu/libpthread-2.19.so
7fc0400c8000-7fc0401d0000 r--p 00000000 08:01 16781848 /usr/lib/locale/locale-archive
7fc0401d0000-7fc0401d5000 rw-p 00000000 00:00 0
7fc0401ea000-7fc0401eb000 rw-p 00000000 00:00 0
7fc0401eb000-7fc0401ec000 ---p 00000000 00:00 0
7fc0401ec000-7fc0401f1000 rw-p 00000000 00:00 0 [stack:16182]
7fc0401f1000-7fc0401f2000 r--p 00020000 08:01 11799884 /lib/x86_64-linux-gnu/ld-2.19.so
7fc0401f2000-7fc0401f3000 rw-p 00021000 08:01 11799884 /lib/x86_64-linux-gnu/ld-2.19.so
7fc0401f3000-7fc0401f4000 rw-p 00000000 00:00 0
7fc0401f4000-7fc0404a6000 r-xp 00000000 08:01 15073361 /home/ruby/tst1/ruby/ruby
7fc0406a6000-7fc0406ac000 rw-p 002b2000 08:01 15073361 /home/ruby/tst1/ruby/ruby
7fc0406ac000-7fc0406bf000 rw-p 00000000 00:00 0
7fc042631000-7fc042b35000 rw-p 00000000 00:00 0 [heap]
7fffbe5d4000-7fffbe5f5000 rw-p 00000000 00:00 0
7fffbe5fc000-7fffbe5fe000 r-xp 00000000 00:00 0 [vdso]
7fffbe5fe000-7fffbe600000 r--p 00000000 00:00 0 [vvar]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
</code></pre>
Ruby master - Bug #10389 (Closed): SEGV after SEGV
https://bugs.ruby-lang.org/issues/10389
2014-10-15T15:09:33Z
akr (Akira Tanaka)
akr@fsij.org
<p>最近、SEGV したときに、さらに SEGV することがあります。</p>
<pre><code>% ./miniruby -e 'Process.kill(:SEGV, $$)'
-e:1: [BUG] Segmentation fault at 0x0003e800003c63
ruby 2.2.0dev (2014-10-15 trunk 47951) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0003 p:---- s:0009 e:000008 CFUNC :kill
c:0002 p:0015 s:0004 E:000080 EVAL -e:1 [FINISH]
c:0001 p:0000 s:0002 E:0006f0 TOP [FINISH]
-- Ruby level backtrace information ----------------------------------------
-e:1:in `<main>'
zsh: segmentation fault ./miniruby -e 'Process.kill(:SEGV, $$)'
</code></pre>
<p>gdb で動かしてみると、RSTRING_PTR に 0 を渡しているようです。</p>
<pre><code>% gdb miniruby
GNU gdb (Debian 7.7.1+dfsg-3) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from miniruby...done.
(gdb) run -e 'Process.kill(:SEGV, $$)'
Starting program: /home/ruby/tst1/ruby/miniruby -e 'Process.kill(:SEGV, $$)'
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7ff5700 (LWP 15526)]
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6e8d347 in kill () at ../sysdeps/unix/syscall-template.S:81
81 ../sysdeps/unix/syscall-template.S: そのようなファイルやディレクトリはありません.
(gdb) c
Continuing.
-e:1: [BUG] Segmentation fault at 0x0003e800003ca2
ruby 2.2.0dev (2014-10-15 trunk 47951) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0003 p:---- s:0009 e:000008 CFUNC :kill
c:0002 p:0015 s:0004 E:0014e0 EVAL -e:1 [FINISH]
c:0001 p:0000 s:0002 E:001ac0 TOP [FINISH]
-- Ruby level backtrace information ----------------------------------------
-e:1:in `<main>'
Program received signal SIGSEGV, Segmentation fault.
0x000055555572f64c in oldbt_bugreport (arg=0x555555a8a78c, file=93824997590200, line=1, method=0) at vm_backtrace.c:759
759 fprintf(stderr, "%s:%d:in `%s'\n", filename, line, RSTRING_PTR(method));
(gdb) p filename
$1 = 0x555555a704c8 "-e"
(gdb) p line
$2 = 1
(gdb) p method
$3 = 0
(gdb)
</code></pre>
<p>CI の履歴をみると、おそらく r47914 あたりからな気がします。<br>
<a href="http://chkbuild002.hsbt.org/chkbuild/ruby-trunk/log/20141014T080011Z.diff.html.gz" class="external">http://chkbuild002.hsbt.org/chkbuild/ruby-trunk/log/20141014T080011Z.diff.html.gz</a></p>
Ruby master - Bug #10382 (Closed): s = '\x80'; /#{s}/ raises an exception in US-ASCII script
https://bugs.ruby-lang.org/issues/10382
2014-10-14T11:48:01Z
akr (Akira Tanaka)
akr@fsij.org
<p>以下のふたつのスクリプトの動作は一致するべきだと思うのですが、<br>
前者と異なり後者は例外となります。</p>
<pre><code>% cat z1.rb
# -*- encoding: US-ASCII -*-
r = /#{'\x80'}/
p [r, r.encoding]
% ./miniruby -v z1.rb
ruby 2.2.0dev (2014-10-14 trunk 47915) [x86_64-linux]
[/\x80/, #<Encoding:ASCII-8BIT>]
</code></pre>
<pre><code>% cat z2.rb
# -*- encoding: US-ASCII -*-
s = '\x80'
r = /#{s}/
p [r, r.encoding]
% ./miniruby -v z2.rb
ruby 2.2.0dev (2014-10-14 trunk 47915) [x86_64-linux]
z2.rb:3:in `<main>': invalid multibyte escape (ArgumentError)
</code></pre>
<p>後者のスクリプトは前者のスクリプトの文字列 '\x80' を変数に代入してから<br>
使っているだけの違いなので動作が変わる理由はないと思います。</p>
<p>ここでどちらが正しいかというのが問題ですが、前者が正しいのだと思います。</p>
<p>正規表現リテラルはスクリプトエンコーディングというのが原則で、<br>
それだけなら US-ASCII なので \x80 は invalid で例外という後者が正しいのですが、<br>
US-ASCII のスクリプト内で \x80 などを使うと自動的に ASCII-8BIT になるという仕様 ruby-dev:33348 があって、<br>
動的な正規表現に対してこれが実装されていないように思います。</p>
<p>(静的な正規表現に関しての実装は reg_fragment_setenc_gen だと思います。)</p>
Ruby master - Feature #10267 (Closed): Number of processors
https://bugs.ruby-lang.org/issues/10267
2014-09-20T02:49:49Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about a method to obtain number of processors?</p>
<p>Several committers discussed this feature at RubyKaigi 2014.</p>
<p>The number is important to use all available processing power.<br>
Too few processes doesn't use all processors.<br>
Too much processes wastes processing power.</p>
<p>For example, test/lib/test/unit has -j N option for<br>
parallel tests and N is the number of processes to run simultaneously.<br>
But we must specify N explicitly.<br>
I think it should have reasonable default.</p>
<p>I propose a primitive method to obtain number of processors for such purpose:<br>
Etc.nprocessors_online.</p>
<p>It is implemented using sysconf(_SC_NPROCESSORS_ONLN).<br>
It is not standardized but available on many platforms:<br>
GNU/Linux, NetBSD, FreeBSD, OpenBSD, DragonFly BSD,<br>
OpenIndiana, Mac OS X and AIX.</p>
<p>usa-san said he will implement on Windows (after this feature is implemented).</p>
<p>kosaki-san said he will improve the method for container on GNU/Linux.<br>
(If a process is run in a container, usable number of processors may be restricted.<br>
So sysconf(_SC_NPROCESSORS_ONLN) may be not approprate.)</p>
<p>matz accepted this feature including the method name,<br>
Etc.nprocessors_online.</p>
<p>However kosaki-san said he will try to find better name<br>
(by survey container technology).<br>
So I'm waiting.</p>
Ruby master - Bug #10136 (Closed): printf("%.60f\n", 0.1r) shows 0.100000000000000005551115123125...
https://bugs.ruby-lang.org/issues/10136
2014-08-15T02:52:43Z
akr (Akira Tanaka)
akr@fsij.org
<p>printf shows 0.1r (rational) not 0.1 as follows.</p>
<pre><code>% ./ruby -ve 'printf "%.60f\n", 0.1r'
ruby 2.2.0dev (2014-08-15 trunk 47187) [x86_64-linux]
0.100000000000000005551115123125782702118158340454101562500000
</code></pre>
<p>It seems printf converts the rational argument to a float.</p>
<p>I expect 0.100000000000000000000000000000000000000000000000000000000000 instead of<br>
0.100000000000000005551115123125782702118158340454101562500000.</p>
Ruby master - Feature #9880 (Closed): Dir#fileno
https://bugs.ruby-lang.org/issues/9880
2014-05-29T11:40:37Z
akr (Akira Tanaka)
akr@fsij.org
<p>Dir#fileno を追加したいのですがどうでしょうか。</p>
<p>最近、fd を close せずに終わるテストを調べています。<br>
そのために、テストの前後で、Dir.entries("/proc/#$$/fd") として、<br>
fd が変化しているかどうか調べているのですが、<br>
これには少し問題があります。</p>
<p>現在使われている fd のリストを得るために<br>
Dir.entries("/proc/#{$$}/fd") とすると、<br>
以下のようにひとつ余計なものが出てきます。</p>
<pre><code>% ruby -ve '
system("ls /proc/#$$/fd")
p Dir.entries("/proc/#$$/fd")
system("ls /proc/#$$/fd")
'
ruby 2.2.0dev (2014-05-18 trunk 45984) [x86_64-linux]
0 1 2 3 4 5 6
[".", "..", "0", "1", "2", "3", "4", "5", "6", "7"]
0 1 2 3 4 5 6
</code></pre>
<p>前後の system("ls /proc/#$$/fd") では 6 までしかないのに、<br>
Dir.entries では 7 まで出てきます。</p>
<p>ひとつ余計な fd が出てくる理由は Dir.entries 自身がひとつ fd を使っているからです。<br>
内部的には opendir がひとつ fd を生成します。</p>
<p>この挙動のため、テストが close しなかった fd ではなく、<br>
Dir.entries が内部で使う fd が報告されることがあります。</p>
<p>というわけで、opendir の fd を取り除きたいのですが、<br>
この fd を Ruby レベルで得るメソッドがありません。</p>
<p>しかし、POSIX では dirfd() という関数があって、DIR 構造体から<br>
fd を取り出せます。<br>
(4.3BSD Reno にあって、POSIX 2008 に入ったものです。)</p>
<p>というわけで、Dir#fileno を加えるのはどうでしょうか。<br>
これがあれば、以下のように、/proc/#$$/fd を読むための fd を取り除けます。</p>
<pre><code>% ./ruby -ve '
system("ls /proc/#$$/fd")
p Dir.open("/proc/#$$/fd") {|d|
a = []
while fn = d.read
a << fn
end
a - [d.fileno.to_s]
}
system("ls /proc/#$$/fd")
'
ruby 2.2.0dev (2014-05-29 trunk 46224) [x86_64-linux]
0 1 2 3 4 5 6
[".", "..", "0", "1", "2", "3", "4", "5", "6"]
0 1 2 3 4 5 6
</code></pre>
<p>名前は Dir#dirfd と Dir#fileno のどちらかだと思うのですが、<br>
IO#fileno との一貫性による覚えやすさをとって<br>
Dir#fileno がいいんじゃないかと思っています。</p>
<p>あと、dirfd がないときは NotImplementedError です。</p>
<p>どうでしょうか。</p>
Ruby master - Bug #9865 (Closed): frozen IO object causes RuntimeError with inspect and fileno
https://bugs.ruby-lang.org/issues/9865
2014-05-27T01:04:28Z
akr (Akira Tanaka)
akr@fsij.org
<p>IO object を freeze すると、inspect や fileno が RuntimeError になるんですが、<br>
これはよろしくないんじゃないかと思います。</p>
<pre><code>% ./ruby -e 'f = open("."); f.freeze; p f'
-e:1:in `inspect': can't modify frozen File (RuntimeError)
from -e:1:in `p'
from -e:1:in `<main>'
% ./ruby -e 'f = open("."); f.freeze; p f.fileno'
-e:1:in `fileno': can't modify frozen File (RuntimeError)
from -e:1:in `<main>'
% ./ruby -v
ruby 2.2.0dev (2014-05-27 trunk 46150) [x86_64-linux]
</code></pre>
<p>あるいは、なにか理由がありましたっけ?</p>
Ruby master - Bug #9859 (Closed): An object with 6 instance variables causes SEGV
https://bugs.ruby-lang.org/issues/9859
2014-05-23T19:33:28Z
akr (Akira Tanaka)
akr@fsij.org
<p>気がついたのですが、以下のようにすると SEGV します。</p>
<pre><code>% ./miniruby -e '
class C
def initialize
@a = nil
@b = nil
@c = nil
@d = nil
@e = nil
@f = nil
end
end
GC.stress = true
C.new
'
-e:9: [BUG] Segmentation fault at 0x00000000000070
ruby 2.2.0dev (2014-05-24 trunk 46062) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0004 p:0039 s:0011 e:000009 METHOD -e:9 [FINISH]
c:0003 p:---- s:0007 e:000006 CFUNC :new
c:0002 p:0035 s:0004 E:0008d8 EVAL -e:14 [FINISH]
c:0001 p:0000 s:0002 E:0020e8 TOP [FINISH]
-- Ruby level backtrace information ----------------------------------------
-e:14:in `<main>'
-e:14:in `new'
-e:9:in `initialize'
-- C level backtrace information -------------------------------------------
/home/ruby/tst1/ruby/miniruby(rb_print_backtrace+0x19) [0x7f07d0e0c3fb] vm_dump.c:685
/home/ruby/tst1/ruby/miniruby(rb_vm_bugreport+0x93) [0x7f07d0e0c4a4] vm_dump.c:824
/home/ruby/tst1/ruby/miniruby(report_bug+0x18d) [0x7f07d0c9cb4a] error.c:312
/home/ruby/tst1/ruby/miniruby(rb_bug+0xdf) [0x7f07d0c9ccc4] error.c:339
/home/ruby/tst1/ruby/miniruby(sigsegv+0x86) [0x7f07d0d7eba4] signal.c:815
/lib/x86_64-linux-gnu/libpthread.so.0 [0x7f07d0806890]
/home/ruby/tst1/ruby/miniruby(gc_marked+0x42) [0x7f07d0cbe70c] gc.c:3595
/home/ruby/tst1/ruby/miniruby(rgengc_check_relation+0x7f) [0x7f07d0cbe89b] gc.c:3620
/home/ruby/tst1/ruby/miniruby(gc_mark+0x58) [0x7f07d0cbe943] gc.c:3643
/home/ruby/tst1/ruby/miniruby(gc_mark_children+0x6ac) [0x7f07d0cbf12c] gc.c:3956
/home/ruby/tst1/ruby/miniruby(gc_mark_stacked_objects+0x44) [0x7f07d0cbf3a5] gc.c:4033
/home/ruby/tst1/ruby/miniruby(gc_marks_body+0x107) [0x7f07d0cbf6f5] gc.c:4223
/home/ruby/tst1/ruby/miniruby(gc_marks+0x54) [0x7f07d0cbfa16] gc.c:4579
/home/ruby/tst1/ruby/miniruby(garbage_collect_body+0x1fa) [0x7f07d0cc0e3e] gc.c:5101
/home/ruby/tst1/ruby/miniruby(garbage_collect+0x97) [0x7f07d0cc0fd2] gc.c:5156
/home/ruby/tst1/ruby/miniruby(garbage_collect_with_gvl+0x4b) [0x7f07d0cc105b] gc.c:5178
/home/ruby/tst1/ruby/miniruby(objspace_malloc_increase+0x105) [0x7f07d0cc341c] gc.c:6133
/home/ruby/tst1/ruby/miniruby(objspace_xrealloc+0x128) [0x7f07d0cc36c4] gc.c:6274
/home/ruby/tst1/ruby/miniruby(ruby_sized_xrealloc2+0x8a) [0x7f07d0cc3a0c] gc.c:6361
/home/ruby/tst1/ruby/miniruby(ruby_xrealloc2+0x2d) [0x7f07d0cc3a3b] gc.c:6367
/home/ruby/tst1/ruby/miniruby(rb_ivar_set+0x335) [0x7f07d0dcd4eb] variable.c:1183
/home/ruby/tst1/ruby/miniruby(vm_setivar+0x2c5) [0x7f07d0df0190] vm_insnhelper.c:574
/home/ruby/tst1/ruby/miniruby(vm_setinstancevariable+0x3c) [0x7f07d0df0203] vm_insnhelper.c:586
/home/ruby/tst1/ruby/miniruby(vm_exec_core+0x436) [0x7f07d0df560d] insns.def:146
/home/ruby/tst1/ruby/miniruby(vm_exec+0xe7) [0x7f07d0e07ab9] vm.c:1335
/home/ruby/tst1/ruby/miniruby(vm_call0_body+0x181) [0x7f07d0e005f8] vm_eval.c:175
/home/ruby/tst1/ruby/miniruby(vm_call0+0xaa) [0x7f07d0e0016b] vm_eval.c:54
/home/ruby/tst1/ruby/miniruby(rb_call0+0xae) [0x7f07d0e00c4b] vm_eval.c:333
/home/ruby/tst1/ruby/miniruby(rb_call+0x50) [0x7f07d0e01610] vm_eval.c:595
/home/ruby/tst1/ruby/miniruby(rb_funcallv+0x34) [0x7f07d0e01e9e] vm_eval.c:810
/home/ruby/tst1/ruby/miniruby(rb_obj_call_init+0x67) [0x7f07d0ca55e6] eval.c:1342
/home/ruby/tst1/ruby/miniruby(rb_class_new_instance+0x38) [0x7f07d0d06b07] object.c:1842
/home/ruby/tst1/ruby/miniruby(call_cfunc_m1+0x2f) [0x7f07d0df20a8] vm_insnhelper.c:1330
/home/ruby/tst1/ruby/miniruby(vm_call_cfunc_with_frame+0x216) [0x7f07d0df2c57] vm_insnhelper.c:1502
/home/ruby/tst1/ruby/miniruby(vm_call_cfunc+0x2b) [0x7f07d0df2d64] vm_insnhelper.c:1592
/home/ruby/tst1/ruby/miniruby(vm_call_method+0x113) [0x7f07d0df3879] vm_insnhelper.c:1786
/home/ruby/tst1/ruby/miniruby(vm_call_general+0x2b) [0x7f07d0df40ea] vm_insnhelper.c:1941
/home/ruby/tst1/ruby/miniruby(vm_exec_core+0x27cd) [0x7f07d0df79a4] insns.def:1028
/home/ruby/tst1/ruby/miniruby(vm_exec+0xe7) [0x7f07d0e07ab9] vm.c:1335
/home/ruby/tst1/ruby/miniruby(rb_iseq_eval_main+0x34) [0x7f07d0e08c02] vm.c:1599
/home/ruby/tst1/ruby/miniruby(ruby_exec_internal+0x134) [0x7f07d0ca2b9a] eval.c:252
/home/ruby/tst1/ruby/miniruby(ruby_exec_node+0x24) [0x7f07d0ca2cc3] eval.c:317
/home/ruby/tst1/ruby/miniruby(ruby_run_node+0x3e) [0x7f07d0ca2c96] eval.c:309
/home/ruby/tst1/ruby/miniruby(main+0x71) [0x7f07d0c57596] main.c:36
-- Other runtime information -----------------------------------------------
* Loaded script: -e
* Loaded features:
0 enumerator.so
* Process memory map:
7f07cf096000-7f07cf23e000 r--s 00000000 08:02 2884067 /lib/x86_64-linux-gnu/libc-2.18.so
7f07cf23e000-7f07cf77f000 r--s 00000000 08:02 12981089 /home/ruby/tst1/ruby/miniruby
7f07cf77f000-7f07cf795000 r-xp 00000000 08:02 2884113 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f07cf795000-7f07cf994000 ---p 00016000 08:02 2884113 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f07cf994000-7f07cf995000 rw-p 00015000 08:02 2884113 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f07cf995000-7f07cfa96000 rw-p 00000000 00:00 0
7f07cfa96000-7f07cfc36000 r-xp 00000000 08:02 2884067 /lib/x86_64-linux-gnu/libc-2.18.so
7f07cfc36000-7f07cfe36000 ---p 001a0000 08:02 2884067 /lib/x86_64-linux-gnu/libc-2.18.so
7f07cfe36000-7f07cfe3a000 r--p 001a0000 08:02 2884067 /lib/x86_64-linux-gnu/libc-2.18.so
7f07cfe3a000-7f07cfe3c000 rw-p 001a4000 08:02 2884067 /lib/x86_64-linux-gnu/libc-2.18.so
7f07cfe3c000-7f07cfe40000 rw-p 00000000 00:00 0
7f07cfe40000-7f07cff41000 r-xp 00000000 08:02 2884071 /lib/x86_64-linux-gnu/libm-2.18.so
7f07cff41000-7f07d0141000 ---p 00101000 08:02 2884071 /lib/x86_64-linux-gnu/libm-2.18.so
7f07d0141000-7f07d0142000 r--p 00101000 08:02 2884071 /lib/x86_64-linux-gnu/libm-2.18.so
7f07d0142000-7f07d0143000 rw-p 00102000 08:02 2884071 /lib/x86_64-linux-gnu/libm-2.18.so
7f07d0143000-7f07d014b000 r-xp 00000000 08:02 2884069 /lib/x86_64-linux-gnu/libcrypt-2.18.so
7f07d014b000-7f07d034a000 ---p 00008000 08:02 2884069 /lib/x86_64-linux-gnu/libcrypt-2.18.so
7f07d034a000-7f07d034b000 r--p 00007000 08:02 2884069 /lib/x86_64-linux-gnu/libcrypt-2.18.so
7f07d034b000-7f07d034c000 rw-p 00008000 08:02 2884069 /lib/x86_64-linux-gnu/libcrypt-2.18.so
7f07d034c000-7f07d037a000 rw-p 00000000 00:00 0
7f07d037a000-7f07d037d000 r-xp 00000000 08:02 2884070 /lib/x86_64-linux-gnu/libdl-2.18.so
7f07d037d000-7f07d057c000 ---p 00003000 08:02 2884070 /lib/x86_64-linux-gnu/libdl-2.18.so
7f07d057c000-7f07d057d000 r--p 00002000 08:02 2884070 /lib/x86_64-linux-gnu/libdl-2.18.so
7f07d057d000-7f07d057e000 rw-p 00003000 08:02 2884070 /lib/x86_64-linux-gnu/libdl-2.18.so
7f07d057e000-7f07d05f5000 r-xp 00000000 08:02 24906866 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7f07d05f5000-7f07d07f5000 ---p 00077000 08:02 24906866 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7f07d07f5000-7f07d07f6000 r--p 00077000 08:02 24906866 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7f07d07f6000-7f07d07f7000 rw-p 00078000 08:02 24906866 /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
7f07d07f7000-7f07d080f000 r-xp 00000000 08:02 2883744 /lib/x86_64-linux-gnu/libpthread-2.18.so
7f07d080f000-7f07d0a0e000 ---p 00018000 08:02 2883744 /lib/x86_64-linux-gnu/libpthread-2.18.so
7f07d0a0e000-7f07d0a0f000 r--p 00017000 08:02 2883744 /lib/x86_64-linux-gnu/libpthread-2.18.so
7f07d0a0f000-7f07d0a10000 rw-p 00018000 08:02 2883744 /lib/x86_64-linux-gnu/libpthread-2.18.so
7f07d0a10000-7f07d0a14000 rw-p 00000000 00:00 0
7f07d0a14000-7f07d0a34000 r-xp 00000000 08:02 2883965 /lib/x86_64-linux-gnu/ld-2.18.so
7f07d0a43000-7f07d0ae7000 r--s 00000000 08:02 24905885 /usr/lib/debug/lib/x86_64-linux-gnu/libpthread-2.18.so
7f07d0ae7000-7f07d0b09000 r--s 00000000 08:02 2883744 /lib/x86_64-linux-gnu/libpthread-2.18.so
7f07d0b09000-7f07d0c11000 r--p 00000000 08:02 24911940 /usr/lib/locale/locale-archive
7f07d0c11000-7f07d0c16000 rw-p 00000000 00:00 0
7f07d0c2c000-7f07d0c2d000 rw-p 00000000 00:00 0
7f07d0c2d000-7f07d0c2e000 ---p 00000000 00:00 0
7f07d0c2e000-7f07d0c33000 rw-p 00000000 00:00 0 [stack:16068]
7f07d0c33000-7f07d0c34000 r--p 0001f000 08:02 2883965 /lib/x86_64-linux-gnu/ld-2.18.so
7f07d0c34000-7f07d0c35000 rw-p 00020000 08:02 2883965 /lib/x86_64-linux-gnu/ld-2.18.so
7f07d0c35000-7f07d0c36000 rw-p 00000000 00:00 0
7f07d0c36000-7f07d0ed8000 r-xp 00000000 08:02 12981089 /home/ruby/tst1/ruby/miniruby
7f07d10d8000-7f07d10de000 rw-p 002a2000 08:02 12981089 /home/ruby/tst1/ruby/miniruby
7f07d10de000-7f07d1105000 rw-p 00000000 00:00 0
7f07d2e0f000-7f07d2f9f000 rw-p 00000000 00:00 0 [heap]
7fff4135c000-7fff4137d000 rw-p 00000000 00:00 0
7fff413fe000-7fff41400000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
</code></pre>
Ruby master - Feature #9842 (Closed): system configuration variables (sysconf(), confstr(), pathc...
https://bugs.ruby-lang.org/issues/9842
2014-05-15T11:45:46Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about providing methods to obtain system configuration variables?</p>
<p>POSIX defines sysconf(), confstr(), pathconf() and fpathconf().<br>
I implemented following methods in ext/etc.</p>
<ul>
<li>Etc.sysconf(name)</li>
<li>Etc.confstr(name)</li>
<li>IO.pathconf(name)</li>
<li>IO#pathconf(name)</li>
</ul>
<p>POSIX defines some names.<br>
Various operating sysmtems define additional names.</p>
<p>They can be used as follows:</p>
<pre><code>Etc.sysconf(Etc::SC_ARG_MAX) #=> 2097152
Etc.sysconf(Etc::SC_NPROCESSORS_ONLN) #=> 4
Etc.confstr(Etc::CS_PATH) #=> "/bin:/usr/bin"
Etc.confstr(Etc::CS_GNU_LIBC_VERSION) #=> "glibc 2.18"
IO.pathconf("/", Etc::PC_NAME_MAX) #=> 255
open("/") {|f| p f.pathconf(Etc::PC_TIMESTAMP_RESOLUTION) } #=> 1
</code></pre>
<p>I implemented them in ext/etc because I interpreted "etc" as<br>
system configuration.</p>
<p>Any idea?</p>
Ruby master - Feature #9834 (Closed): Float#{next_float,prev_float}
https://bugs.ruby-lang.org/issues/9834
2014-05-13T09:48:38Z
akr (Akira Tanaka)
akr@fsij.org
<p>I'd like to add Float#next_float and Float#prev_float which<br>
returns next representable floating-point number and<br>
previous representable floating-point number.</p>
<pre><code>p 3.0.next_float #=> 3.0000000000000004
p 3.0.prev_float #=> 2.9999999999999996
</code></pre>
<p>These methods can be useful to examine the behavior of floating-point numbers.</p>
<p>For example, they can be used to examine floating-point error in 0.1 + 0.1 + ... + 0.1.</p>
<pre><code>f = 0.0
100.times { f += 0.1 }
p f #=> 9.99999999999998 # should be 10.0 in the ideal world.
p 10-f #=> 1.9539925233402755e-14 # the floating-point error.
p(10.0.next_float-10) #=> 1.7763568394002505e-15 # 1 ulp (units in the last place).
p((10-f)/(10.0.next_float-10)) #=> 11.0 # the error is 11 ulp.
p "%a" % f #=> "0x1.3fffffffffff5p+3" # the last hex digit is 5. 16 - 5 = 11 ulp.
</code></pre>
<p>The methods are implemented using nextafter() function described in<br>
IEEE 754 (Appendix), C99 and POSIX.<br>
It seems the function is pretty portable on Unix variants.</p>
<p>However I implemented missing/nextafter.c for environments which don't have the function.</p>
<p>Any idea?</p>
Ruby master - Feature #9826 (Closed): Enumerable#slice_between
https://bugs.ruby-lang.org/issues/9826
2014-05-10T11:57:17Z
akr (Akira Tanaka)
akr@fsij.org
<p>I'd like to add a new method, Enumerable#slice_between.</p>
<p>It is similar to Enumerable#slice_before but it can use<br>
not only the element after the slice position<br>
but also the element before the slice position.</p>
<pre><code>enum.slice_between(pattern_before, pattern_after=nil) -> an_enumerator
enum.slice_between {|elt_before, elt_after| bool } -> an_enumerator
</code></pre>
<p>I found several people try to use Enumerable#slice_before for<br>
compacting sequence of integers using hyphens:<br>
1,2,4,9,10,11,12,15,16,19,20,21 to 1,2,4,9-12,15,16,19-21.</p>
<ul>
<li>ruby-talk:370132 Dave Thomas and James Edward Gray II</li>
<li>
<a href="http://d.hatena.ne.jp/keyesberry/20120107/p1" class="external">http://d.hatena.ne.jp/keyesberry/20120107/p1</a> (in Japanese)</li>
</ul>
<p><code>slice_before</code> needs state management to do it.<br>
<code>slice_between</code> can be used more easily for this situation:</p>
<pre><code>a = [1,2,4,9,10,11,12,15,16,19,20,21]
p a.slice_between {|i, j| i+1 != j }.map {|a| a.length < 3 ? a : "#{a.first}-#{a.last}" }.join(",")
</code></pre>
<p>Or more verbosely as:</p>
<pre><code>a = [1,2,4,9,10,11,12,15,16,19,20,21]
b = a.slice_between {|i, j| i+1 != j }
p b.to_a #=> [[1, 2], [4], [9, 10, 11, 12], [15, 16], [19, 20, 21]]
c = b.map {|a| a.length < 3 ? a : "#{a.first}-#{a.last}" }
p c #=> [[1, 2], [4], "9-12", [15, 16], "19-21"]
d = c.join(",")
p d #=> "1,2,4,9-12,15,16,19-21"
</code></pre>
<p>Also, I found several usages for Enumerable#slice_between.</p>
<ul>
<li>ruby-talk:359255 split logs where interval is 30s or more.</li>
<li><a href="http://stackoverflow.com/questions/6258971/how-do-i-return-a-group-of-sequential-numbers-that-might-exist-in-an-array" class="external">http://stackoverflow.com/questions/6258971/how-do-i-return-a-group-of-sequential-numbers-that-might-exist-in-an-array</a></li>
<li>ruby-talk:415057 collects same elements. (Enumerable#chunk can be used, though.)</li>
</ul>
<p>Any idea?</p>
Ruby master - Bug #9820 (Closed): miniruby -e 'Process.kill(:INT, $$)' hang under cron
https://bugs.ruby-lang.org/issues/9820
2014-05-09T08:06:42Z
akr (Akira Tanaka)
akr@fsij.org
<p>最近、しばたさんが運用を始めた chkbuild で、<br>
TestBeginEndBlock#test_propagate_signaled が hang しています。<br>
<a href="http://chkbuild002.hsbt.org/chkbuild/ruby-trunk/log/20140509T060013Z.fail.html.gz" class="external">http://chkbuild002.hsbt.org/chkbuild/ruby-trunk/log/20140509T060013Z.fail.html.gz</a></p>
<p>調べて再現コードを小さくしていった結果、</p>
<p>miniruby -e 'Process.kill(:INT, $$)'</p>
<p>というのを cron から動かしたときは hang し、<br>
端末から動かしたときは hang しない、ということが判明しました。</p>
<p>strace した結果をみると、<br>
cron 下では timer thread が prctl の直後に poll を呼び出してそれが終わらないという挙動なのに対し、<br>
端末ではそのあたりで context switch が起きている、ような気がします。</p>
<p>strace の結果を strace.cron.log と strace.term.log として添付します。</p>
<p>なにかわかるひとはいますでしょうか?</p>
<pre><code>% ./miniruby -v
ruby 2.2.0dev (2014-05-09 trunk 45884) [x86_64-linux]
% uname -mrsv
Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64
% lsb_release -idrc
Distributor ID: Debian
Description: Debian GNU/Linux 7.5 (wheezy)
Release: 7.5
Codename: wheezy
</code></pre>
<p>なお、コミッタならしばたさんに頼むとそのマシンにアカウントを作ってくれる模様です。</p>
Ruby master - Feature #9770 (Closed): Etc.uname
https://bugs.ruby-lang.org/issues/9770
2014-04-23T14:16:42Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about Etc.uname method to call the uname(2) system call?</p>
<pre><code>% ./ruby -rpp -retc -e 'pp Etc.uname'
{:sysname=>"Linux",
:nodename=>"boron",
:release=>"2.6.18-6-xen-686",
:version=>"#1 SMP Thu Nov 5 19:54:42 UTC 2009",
:machine=>"i686"}
</code></pre>
<p>Sometimes we need to obtain OS (kernel) version or similar system information.</p>
<p>For example, there are several tests which invokes uname command (and function via Win32API):</p>
<pre><code>test/ruby/test_io.rb: return false if (`/bin/uname -r`.split('.') <=> %w[3 8]) < 0
test/ruby/test_io.rb: return false if (`/bin/uname -r`.split('.') <=> %w[3 5]) < 0
test/ruby/test_io.rb: return false if (`/bin/uname -r`.split('.') <=> %w[3 8]) < 0
test/ruby/test_sleep.rb: 4.98 if /Linux ([\d.]+)/ =~ `uname -sr` && ($1.split('.')<=>%w/2 6 18/)<1
test/socket/test_socket.rb: (`uname -r`[/[0-9.]+/].split('.').map(&:to_i) <=> [2,6,18]) <= 0
test/dbm/test_dbm.rb: uname = Win32API.new('cygwin1', 'uname', 'P', 'I')
</code></pre>
<p>Etc.uname provides clean replacement for them.<br>
<code>uname -r</code> can be changed to Etc.uname[:release].</p>
<p>uname function is defined by POSIX.<br>
So it is pretty portable.<br>
If the function is not available, NotImplementedError is raised.</p>
<p>I chose Etc module because uname() returns system wide information.</p>
<p>The return value is a plain hash because:</p>
<ul>
<li>Struct is marshal-incompatible if some OS add fields. (glibc has "domainname", for example. Current implementation doesn't support it, though.)</li>
<li>No inspect method required to view contents.</li>
</ul>
<p>Any idea?</p>
Ruby master - Bug #9717 (Closed): [BUG] setup_arg: unknown node: NODE_DVAR
https://bugs.ruby-lang.org/issues/9717
2014-04-09T10:42:52Z
akr (Akira Tanaka)
akr@fsij.org
<pre><code>以下のようにすると、[BUG] setup_arg: unknown node: NODE_DVAR というメッセージが出て異常終了します。
% ./miniruby -e 'GC.stress = true; eval("foo += bar")'
-e:1: [BUG] setup_arg: unknown node: NODE_DVAR
ruby 2.2.0dev (2014-04-09 trunk 45540) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0003 p:---- s:0008 e:000007 CFUNC :eval
c:0002 p:0021 s:0004 E:0006e8 EVAL -e:1 [FINISH]
c:0001 p:0000 s:0002 E:000ed8 TOP [FINISH]
-- Ruby level backtrace information ----------------------------------------
-e:1:in `<main>'
-e:1:in `eval'
-- C level backtrace information -------------------------------------------
-e:1: [BUG] Segmentation fault at 0x00000000000041
ruby 2.2.0dev (2014-04-09 trunk 45540) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0003 p:---- s:0008 e:000007 CFUNC :eval
c:0002 p:0021 s:0004 E:0006e8 EVAL -e:1 [FINISH]
c:0001 p:0000 s:0002 E:000ed8 TOP [FINISH]
-- Ruby level backtrace information ----------------------------------------
-e:1:in `<main>'
-e:1:in `eval'
-- C level backtrace information -------------------------------------------
/home/akr/tst1/ruby/miniruby(rb_print_backtrace+0x19) [0x7f8fa358cd0a] vm_dump.c:685
/home/akr/tst1/ruby/miniruby(rb_vm_bugreport+0x93) [0x7f8fa358cdb3] vm_dump.c:824
/home/akr/tst1/ruby/miniruby(report_bug+0x18d) [0x7f8fa341e4c2] error.c:312
/home/akr/tst1/ruby/miniruby(rb_bug+0xdf) [0x7f8fa341e63c] error.c:339
/home/akr/tst1/ruby/miniruby(sigsegv+0x86) [0x7f8fa34ff9ad] signal.c:731
/lib/x86_64-linux-gnu/libpthread.so.0 [0x7f8fa2f88880]
/home/akr/tst1/ruby/miniruby(rb_dump_backtrace_with_lines+0x164) [0x7f8fa35a3eeb] addr2line.c:672
/home/akr/tst1/ruby/miniruby(rb_print_backtrace+0x2d) [0x7f8fa358cd1e] vm_dump.c:687
/home/akr/tst1/ruby/miniruby(rb_vm_bugreport+0x93) [0x7f8fa358cdb3] vm_dump.c:824
/home/akr/tst1/ruby/miniruby(report_bug+0x18d) [0x7f8fa341e4c2] error.c:312
/home/akr/tst1/ruby/miniruby(rb_bug+0xdf) [0x7f8fa341e63c] error.c:339
/home/akr/tst1/ruby/miniruby(setup_args+0x3c1) [0x7f8fa3559a2f] compile.c:3149
/home/akr/tst1/ruby/miniruby(iseq_compile_each+0x66fc) [0x7f8fa35602f2] compile.c:4444
/home/akr/tst1/ruby/miniruby(iseq_compile_each+0x3ffe) [0x7f8fa355dbf4] compile.c:3918
/home/akr/tst1/ruby/miniruby(rb_iseq_compile_node+0x4bb) [0x7f8fa3553182] compile.c:507
/home/akr/tst1/ruby/miniruby(rb_iseq_new_with_bopt_and_opt+0x9c) [0x7f8fa3569c98] iseq.c:449
/home/akr/tst1/ruby/miniruby(rb_iseq_new_with_opt+0x58) [0x7f8fa3569d02] iseq.c:460
/home/akr/tst1/ruby/miniruby(rb_iseq_compile_with_option+0x27a) [0x7f8fa356a809] iseq.c:618
/home/akr/tst1/ruby/miniruby(eval_string_with_cref+0x3f7) [0x7f8fa3583c60] vm_eval.c:1263
/home/akr/tst1/ruby/miniruby(eval_string+0x42) [0x7f8fa35843b8] vm_eval.c:1329
/home/akr/tst1/ruby/miniruby(rb_f_eval+0xc8) [0x7f8fa3584482] vm_eval.c:1368
/home/akr/tst1/ruby/miniruby(call_cfunc_m1+0x2f) [0x7f8fa3572edd] vm_insnhelper.c:1330
/home/akr/tst1/ruby/miniruby(vm_call_cfunc_with_frame+0x216) [0x7f8fa3573a8c] vm_insnhelper.c:1502
/home/akr/tst1/ruby/miniruby(vm_call_cfunc+0x2b) [0x7f8fa3573b99] vm_insnhelper.c:1592
/home/akr/tst1/ruby/miniruby(vm_call_method+0x113) [0x7f8fa35746ae] vm_insnhelper.c:1786
/home/akr/tst1/ruby/miniruby(vm_call_general+0x2b) [0x7f8fa3574f1f] vm_insnhelper.c:1941
/home/akr/tst1/ruby/miniruby(vm_exec_core+0x27cd) [0x7f8fa35787da] insns.def:1028
/home/akr/tst1/ruby/miniruby(vm_exec+0xe7) [0x7f8fa35887bb] vm.c:1328
/home/akr/tst1/ruby/miniruby(rb_iseq_eval_main+0x34) [0x7f8fa3589730] vm.c:1586
/home/akr/tst1/ruby/miniruby(ruby_exec_internal+0x134) [0x7f8fa34244f2] eval.c:251
/home/akr/tst1/ruby/miniruby(ruby_exec_node+0x24) [0x7f8fa342461b] eval.c:316
/home/akr/tst1/ruby/miniruby(ruby_run_node+0x3e) [0x7f8fa34245ee] eval.c:308
/home/akr/tst1/ruby/miniruby(main+0x71) [0x7f8fa33d9586] main.c:36
*** Error in `./miniruby': double free or corruption (out): 0x00007f8fa55e00c0 ***
zsh: segmentation fault ./miniruby -e 'GC.stress = true; eval("foo += bar")'
%
</code></pre>
Ruby master - Bug #9523 (Closed): marshal_dump and callcc causes SEGV
https://bugs.ruby-lang.org/issues/9523
2014-02-16T23:05:34Z
akr (Akira Tanaka)
akr@fsij.org
<pre><code>Ruby dumps core as follows.
% ./ruby -rcontinuation -e '
class C
def marshal_dump
callcc {|c| $c = c }
nil
end
def marshal_load(v)
end
end
p Marshal.dump(C.new)
$c.call
'
"\x04\bU:\x06C0"
-e:10: [BUG] Segmentation fault at 0x00000000000001
ruby 2.2.0dev (2014-02-17 trunk 45016) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0003 p:---- s:0009 e:000008 CFUNC :dump
c:0002 p:0031 s:0005 E:001e08 EVAL -e:10 [FINISH]
c:0001 p:0000 s:0002 E:0008f8 TOP [FINISH]
-- Ruby level backtrace information ----------------------------------------
-e:10:in `<main>'
-e:10:in `dump'
-- C level backtrace information -------------------------------------------
./ruby(+0x173e12) [0x7fa9014b7e12]
./ruby(+0x173ee7) [0x7fa9014b7ee7]
./ruby(+0x1cf3ff) [0x7fa9015133ff]
./ruby(rb_bug+0xdf) [0x7fa901513579]
./ruby(+0xececa) [0x7fa901430eca]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xf210) [0x7fa900f13210] ../nptl/sysdeps/pthread/funlockfile.c:29
./ruby(st_lookup+0x18) [0x7fa90143ac13]
./ruby(+0x62e50) [0x7fa9013a6e50]
./ruby(+0x637a4) [0x7fa9013a77a4]
./ruby(+0x64988) [0x7fa9013a8988]
./ruby(+0x15a006) [0x7fa90149e006]
./ruby(+0x15abb5) [0x7fa90149ebb5]
./ruby(+0x15acc2) [0x7fa90149ecc2]
./ruby(+0x15b7a8) [0x7fa90149f7a8]
./ruby(+0x15c019) [0x7fa9014a0019]
./ruby(+0x15f908) [0x7fa9014a3908]
./ruby(+0x16f7e9) [0x7fa9014b37e9]
./ruby(rb_iseq_eval_main+0x34) [0x7fa9014b4756]
./ruby(+0x230c8) [0x7fa9013670c8]
./ruby(ruby_exec_node+0x24) [0x7fa9013671e1]
./ruby(ruby_run_node+0x3e) [0x7fa9013671b4]
./ruby(+0x21236) [0x7fa901365236]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7fa9001c8995] eval_error.c:65
./ruby(+0x210d9) [0x7fa9013650d9]
-- Other runtime information -----------------------------------------------
* Loaded script: -e
* Loaded features:
0 enumerator.so
1 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
2 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
3 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/rbconfig.rb
4 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/compatibility.rb
5 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/defaults.rb
6 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/deprecate.rb
7 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/errors.rb
8 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/version.rb
9 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/requirement.rb
10 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/platform.rb
11 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/basic_specification.rb
12 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/stub_specification.rb
13 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/util/stringio.rb
14 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/specification.rb
15 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/exceptions.rb
16 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb
17 thread.rb
18 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
19 /home/ruby/tst1/lib/ruby/2.2.0/monitor.rb
20 /home/ruby/tst1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb
21 /home/ruby/tst1/lib/ruby/2.2.0/rubygems.rb
22 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/continuation.so
* Process memory map:
7fa8ff687000-7fa8ff69c000 r-xp 00000000 08:02 2883588 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa8ff69c000-7fa8ff89c000 ---p 00015000 08:02 2883588 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa8ff89c000-7fa8ff89d000 rw-p 00015000 08:02 2883588 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa8ff89d000-7fa8ff89e000 r-xp 00000000 08:02 19663128 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/continuation.so
7fa8ff89e000-7fa8ffa9d000 ---p 00001000 08:02 19663128 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/continuation.so
7fa8ffa9d000-7fa8ffa9e000 rw-p 00000000 08:02 19663128 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/continuation.so
7fa8ffa9e000-7fa8ffaa1000 r-xp 00000000 08:02 19660804 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
7fa8ffaa1000-7fa8ffca0000 ---p 00003000 08:02 19660804 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
7fa8ffca0000-7fa8ffca1000 rw-p 00002000 08:02 19660804 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/thread.so
7fa8ffca1000-7fa8ffca3000 r-xp 00000000 08:02 19660862 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7fa8ffca3000-7fa8ffea3000 ---p 00002000 08:02 19660862 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7fa8ffea3000-7fa8ffea4000 rw-p 00002000 08:02 19660862 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7fa8ffea4000-7fa8ffea6000 r-xp 00000000 08:02 19663116 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7fa8ffea6000-7fa9000a5000 ---p 00002000 08:02 19663116 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7fa9000a5000-7fa9000a6000 rw-p 00001000 08:02 19663116 /home/ruby/tst1/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7fa9000a6000-7fa9001a7000 rw-p 00000000 00:00 0
7fa9001a7000-7fa90034a000 r-xp 00000000 08:02 2883602 /lib/x86_64-linux-gnu/libc-2.17.so
7fa90034a000-7fa900549000 ---p 001a3000 08:02 2883602 /lib/x86_64-linux-gnu/libc-2.17.so
7fa900549000-7fa90054d000 r--p 001a2000 08:02 2883602 /lib/x86_64-linux-gnu/libc-2.17.so
7fa90054d000-7fa90054f000 rw-p 001a6000 08:02 2883602 /lib/x86_64-linux-gnu/libc-2.17.so
7fa90054f000-7fa900553000 rw-p 00000000 00:00 0
7fa900553000-7fa90064f000 r-xp 00000000 08:02 2883608 /lib/x86_64-linux-gnu/libm-2.17.so
7fa90064f000-7fa90084f000 ---p 000fc000 08:02 2883608 /lib/x86_64-linux-gnu/libm-2.17.so
7fa90084f000-7fa900850000 r--p 000fc000 08:02 2883608 /lib/x86_64-linux-gnu/libm-2.17.so
7fa900850000-7fa900851000 rw-p 000fd000 08:02 2883608 /lib/x86_64-linux-gnu/libm-2.17.so
7fa900851000-7fa900859000 r-xp 00000000 08:02 2883607 /lib/x86_64-linux-gnu/libcrypt-2.17.so
7fa900859000-7fa900a58000 ---p 00008000 08:02 2883607 /lib/x86_64-linux-gnu/libcrypt-2.17.so
7fa900a58000-7fa900a59000 r--p 00007000 08:02 2883607 /lib/x86_64-linux-gnu/libcrypt-2.17.so
7fa900a59000-7fa900a5a000 rw-p 00008000 08:02 2883607 /lib/x86_64-linux-gnu/libcrypt-2.17.so
7fa900a5a000-7fa900a88000 rw-p 00000000 00:00 0
7fa900a88000-7fa900a8b000 r-xp 00000000 08:02 2883601 /lib/x86_64-linux-gnu/libdl-2.17.so
7fa900a8b000-7fa900c8a000 ---p 00003000 08:02 2883601 /lib/x86_64-linux-gnu/libdl-2.17.so
7fa900c8a000-7fa900c8b000 r--p 00002000 08:02 2883601 /lib/x86_64-linux-gnu/libdl-2.17.so
7fa900c8b000-7fa900c8c000 rw-p 00003000 08:02 2883601 /lib/x86_64-linux-gnu/libdl-2.17.so
7fa900c8c000-7fa900cfb000 r-xp 00000000 08:02 24908368 /usr/lib/x86_64-linux-gnu/libgmp.so.10.1.3
7fa900cfb000-7fa900efa000 ---p 0006f000 08:02 24908368 /usr/lib/x86_64-linux-gnu/libgmp.so.10.1.3
7fa900efa000-7fa900efb000 r--p 0006e000 08:02 24908368 /usr/lib/x86_64-linux-gnu/libgmp.so.10.1.3
7fa900efb000-7fa900f04000 rw-p 0006f000 08:02 24908368 /usr/lib/x86_64-linux-gnu/libgmp.so.10.1.3
7fa900f04000-7fa900f1b000 r-xp 00000000 08:02 2883595 /lib/x86_64-linux-gnu/libpthread-2.17.so
7fa900f1b000-7fa90111a000 ---p 00017000 08:02 2883595 /lib/x86_64-linux-gnu/libpthread-2.17.so
7fa90111a000-7fa90111b000 r--p 00016000 08:02 2883595 /lib/x86_64-linux-gnu/libpthread-2.17.so
7fa90111b000-7fa90111c000 rw-p 00017000 08:02 2883595 /lib/x86_64-linux-gnu/libpthread-2.17.so
7fa90111c000-7fa901120000 rw-p 00000000 00:00 0
7fa901120000-7fa901141000 r-xp 00000000 08:02 2883593 /lib/x86_64-linux-gnu/ld-2.17.so
7fa901219000-7fa901321000 r--p 00000000 08:02 24931804 /usr/lib/locale/locale-archive
7fa901321000-7fa901326000 rw-p 00000000 00:00 0
7fa90133a000-7fa90133b000 rw-p 00000000 00:00 0
7fa90133b000-7fa90133c000 ---p 00000000 00:00 0
7fa90133c000-7fa901341000 rw-p 00000000 00:00 0 [stack:9285]
7fa901341000-7fa901342000 r--p 00021000 08:02 2883593 /lib/x86_64-linux-gnu/ld-2.17.so
7fa901342000-7fa901344000 rw-p 00022000 08:02 2883593 /lib/x86_64-linux-gnu/ld-2.17.so
7fa901344000-7fa9015e1000 r-xp 00000000 08:02 12981165 /home/ruby/tst1/ruby/ruby
7fa9017e0000-7fa9017e6000 rw-p 0029c000 08:02 12981165 /home/ruby/tst1/ruby/ruby
7fa9017e6000-7fa90180d000 rw-p 00000000 00:00 0
7fa903158000-7fa9035d4000 rw-p 00000000 00:00 0 [heap]
7fffb3797000-7fffb37b8000 rw-p 00000000 00:00 0
7fffb37fe000-7fffb3800000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
</code></pre>
Ruby master - Feature #9513 (Closed): Hide Rational internal
https://bugs.ruby-lang.org/issues/9513
2014-02-12T12:00:40Z
akr (Akira Tanaka)
akr@fsij.org
<p>I'd like to hide C-level Ratinal internal.<br>
I made a patch to do it.<br>
This is similar to [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Hide a Bignum definition (Closed)" href="https://bugs.ruby-lang.org/issues/6083">#6083</a>] for struct RBignum.</p>
<p>If the internal is hidden, we can change it without compatibility problem.<br>
For example, we can use GMP.</p>
<p>The patch moves struct RRational and related macros to internal.h.<br>
It also provides two accessors, rb_rational_num and rb_rational_den and<br>
changes ext/bigdecimal/bigdecimal.c and ext/date/date_core.c to<br>
use these accessors.</p>
<p>How do you think, tadf?</p>
Ruby master - Feature #9502 (Closed): Remove deprecated definitions
https://bugs.ruby-lang.org/issues/9502
2014-02-08T15:16:23Z
akr (Akira Tanaka)
akr@fsij.org
<p>I'd like to remove deprecated definitions.<br>
This means C level API change.</p>
<p>The list of functions, macros and types are follows.<br>
(This list doesn't contain definitions deprecated after 2.1.0 release.)</p>
<p>VA VD NAME<br>
old 193 Check_SafeStr -> SafeStringValue<br>
old 193 rb_check_safe_str -> SafeStringValue<br>
old 193 rb_quad_pack -> rb_integer_pack<br>
old 193 rb_quad_unpack -> rb_integer_unpack<br>
old 193 rb_read_check : access struct FILE internal. no replacement.<br>
old 193 rb_struct_iv_get : internal function. no replacement.<br>
191 * struct rb_blocking_region_buffer : internal type. no replacement.<br>
191 193 rb_thread_blocking_region_begin -> rb_thread_call_without_gvl family<br>
191 193 rb_thread_blocking_region_end -> rb_thread_call_without_gvl family<br>
old 193 TRAP_BEG -> rb_thread_call_without_gvl family<br>
old 193 TRAP_END -> rb_thread_call_without_gvl family<br>
old 193 rb_thread_select -> rb_thread_fd_select<br>
191 * struct rb_exec_arg : internal type. no replacement.<br>
191 200 rb_exec : internal function. no replacement.<br>
191 200 rb_exec_arg_addopt : internal function. no replacement.<br>
191 200 rb_exec_arg_fixup : internal function. no replacement.<br>
191 200 rb_exec_arg_init : internal function. no replacement.<br>
192 200 rb_exec_err : internal function. no replacement.<br>
191 200 rb_fork : internal function. no replacement.<br>
192 200 rb_fork_err : internal function. no replacement.<br>
191 200 rb_proc_exec_n : internal function. no replacement.<br>
191 200 rb_run_exec_options : internal function. no replacement.<br>
192 200 rb_run_exec_options_err : internal function. no replacement.<br>
191 200 rb_thread_blocking_region -> rb_thread_call_without_gvl family<br>
old 200 rb_thread_polling -> rb_thread_wait_for<br>
186 210 rb_big2str0 : internal function. no replacement.<br>
193 210 rb_big2ulong_pack -> rb_integer_pack<br>
193 210 rb_gc_set_params : internal function. no replacement.</p>
<p>VA is the version that the definition is available since.<br>
"old" means it is available since 1.8.5 at least.</p>
<p>VD is the version that the definition is deprecated to cause warnings.<br>
"*" means struct type.<br>
struct types are not a target of deprecation warning.</p>
<p>It seems the half of definitions have replacements.</p>
<p>The rest are removed without replacement because they are ruby internals.</p>
Ruby master - Bug #9426 (Closed): Segmentation fault with signal in test_tracks_objspace_count
https://bugs.ruby-lang.org/issues/9426
2014-01-18T11:28:13Z
akr (Akira Tanaka)
akr@fsij.org
<p>test-all 中に Control-C で割り込んだときに SEGV することがあって、<br>
調べたところ、test_tracks_objspace_count でそういうことが起きるようです。</p>
<p>以下のようにテスト内に Process.kill を仕込んで再現させることができました。</p>
<pre><code>% uname -mrsv
Linux 3.10-3-amd64 #1 SMP Debian 3.10.11-1 (2013-09-10) x86_64
% lsb_release -idrc
Distributor ID: Debian
Description: Debian GNU/Linux testing (jessie)
Release: testing
Codename: jessie
% svn diff
Index: test/-ext-/tracepoint/test_tracepoint.rb
===================================================================
--- test/-ext-/tracepoint/test_tracepoint.rb (revision 44636)
+++ test/-ext-/tracepoint/test_tracepoint.rb (working copy)
@@ -34,6 +34,7 @@
GC.disable
GC.stat(stat1)
result = Bug.tracepoint_track_objspace_events{
+ Process.kill(:TERM, $$)
GC.enable
1_000_000.times{''}
GC.disable
% ./ruby -I.ext/x86_64-linux test/-ext-/tracepoint/test_tracepoint.rb -n test_tracks_objspace_count
Run options: -n test_tracks_objspace_count
# Running tests:
[1/1] TestTracepointObj#test_tracks_objspace_count/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:871: [BUG] Segmentation fault at 0x00000000000000
ruby 2.2.0dev (2014-01-18 trunk 44636) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0022 p:0004 s:0100 e:000099 BLOCK /home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:871
c:0021 p:0062 s:0097 e:000095 METHOD /home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:872
c:0020 p:0069 s:0091 e:000090 METHOD /home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1265
c:0019 p:0019 s:0083 e:000082 METHOD /home/akr/tst3/lib/ruby/2.2.0/test/unit/testcase.rb:17
c:0018 p:0068 s:0079 e:000078 BLOCK /home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:940 [FINISH]
c:0017 p:---- s:0073 e:000072 CFUNC :map
c:0016 p:0103 s:0070 e:000069 METHOD /home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:933
c:0015 p:0015 s:0060 e:000058 BLOCK /home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:663 [FINISH]
c:0014 p:---- s:0055 e:000054 CFUNC :each
c:0013 p:0067 s:0052 e:000051 METHOD /home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:661
c:0012 p:0135 s:0046 e:000045 METHOD /home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:884
c:0011 p:0009 s:0036 e:000035 METHOD /home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1092
c:0010 p:0009 s:0033 e:000032 BLOCK /home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1079 [FINISH]
c:0009 p:---- s:0030 e:000029 CFUNC :each
c:0008 p:0048 s:0027 e:000026 METHOD /home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1078
c:0007 p:0017 s:0023 e:000022 METHOD /home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1066
c:0006 p:0019 s:0019 e:000018 METHOD /home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:27
c:0005 p:0010 s:0015 e:000014 METHOD /home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:780
c:0004 p:0027 s:0010 e:000008 BLOCK /home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:372
c:0003 p:0031 s:0007 e:000006 METHOD /home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:33
c:0002 p:0024 s:0004 e:000003 BLOCK /home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:371 [FINISH]
c:0001 p:0000 s:0002 E:0011b8 TOP [FINISH]
/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:371:in `block in autorun'
/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:33:in `run_once'
/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:372:in `block (2 levels) in autorun'
/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:780:in `run'
/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:27:in `run'
/home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1066:in `run'
/home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1078:in `_run'
/home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1078:in `each'
/home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1079:in `block in _run'
/home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1092:in `run_tests'
/home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:884:in `_run_anything'
/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:661:in `_run_suites'
/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:661:in `each'
/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:663:in `block in _run_suites'
/home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:933:in `_run_suite'
/home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:933:in `map'
/home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:940:in `block in _run_suite'
/home/akr/tst3/lib/ruby/2.2.0/test/unit/testcase.rb:17:in `run'
/home/akr/tst3/lib/ruby/2.2.0/minitest/unit.rb:1265:in `run'
/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:872:in `run_test'
/home/akr/tst3/lib/ruby/2.2.0/test/unit.rb:871:in `ensure in run_test'
-- C level backtrace information -------------------------------------------
zsh: segmentation fault ./ruby -I.ext/x86_64-linux test/-ext-/tracepoint/test_tracepoint.rb -n
% gdb ruby
GNU gdb (GDB) 7.6.1 (Debian 7.6.1-1)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/akr/tst3/ruby/ruby...done.
(gdb) handle SIGTERM noprint
Signal Stop Print Pass to program Description
SIGTERM No No Yes Terminated
(gdb) run -I.ext/x86_64-linux test/-ext-/tracepoint/test_tracepoint.rb -n test_tracks_objspace_count
Starting program: /home/akr/tst3/ruby/ruby -I.ext/x86_64-linux test/-ext-/tracepoint/test_tracepoint.rb -n test_tracks_objspace_count
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7ff7700 (LWP 21427)]
Run options: -n test_tracks_objspace_count
# Running tests:
[1/1] TestTracepointObj#test_tracks_objspace_count
Program received signal SIGSEGV, Segmentation fault.
0x00005555556bd8c6 in vm_call0 (th=0x12, recv=17870283871161941922, id=3458764880324436804, argc=1073741909,
argv=0xa00000555555a347, me=0x8800000000000012, defined_class=17870283321406128128) at vm_eval.c:51
51 }
(gdb) bt
#0 0x00005555556bd8c6 in vm_call0 (th=0x12, recv=17870283871161941922, id=3458764880324436804, argc=1073741909,
argv=0xa00000555555a347, me=0x8800000000000012, defined_class=17870283321406128128) at vm_eval.c:51
#1 0x0100000000000000 in ?? ()
#2 0xf800000000000000 in ?? ()
#3 0x8800000000000012 in ?? ()
#4 0x300000555555a347 in ?? ()
#5 0xf800000001f7fd99 in ?? ()
#6 0x500000555555a246 in ?? ()
#7 0xa00000555555a798 in ?? ()
#8 0x400000555555a1e6 in ?? ()
#9 0xd300007fffffffa3 in ?? ()
#10 0x0000005555556bed in ?? ()
#11 0x0100000000000000 in ?? ()
#12 0xf800000000000000 in ?? ()
#13 0x8800000000000012 in ?? ()
#14 0x180000555555a347 in ?? ()
#15 0xa000000000000053 in ?? ()
#16 0x600000555555a1e6 in ?? ()
#17 0x3500007fffffffa4 in ?? ()
#18 0xd000005555556bf6 in ?? ()
#19 0x9000000000000052 in ?? ()
#20 0xf800000000560425 in ?? ()
#21 0x8800000000000012 in ?? ()
#22 0xb00000555555a347 in ?? ()
#23 0x0000007fffffffa3 in ?? ()
#24 0xb000000000000000 in ?? ()
#25 0xf600007fffffffa3 in ?? ()
#26 0xd000005555556b04 in ?? ()
#27 0x4000000000000052 in ?? ()
#28 0x300000555555ea0b in ?? ()
#29 0xa000007ffff7fd99 in ?? ()
#30 0xb00000555555a1e6 in ?? ()
#31 0xf800007fffffffa4 in ?? ()
#32 0x5000000000000012 in ?? ()
#33 0x090000555555e678 in ?? ()
---Type <return> to continue, or q <return> to quit---
#34 0x3000007ffff7eda3 in ?? ()
#35 0xa000007ffff7fd99 in ?? ()
#36 0x200000555555a1e6 in ?? ()
#37 0x0100007fffffffa4 in ?? ()
#38 0x3800005555000000 in ?? ()
#39 0x580000000055a35b in ?? ()
#40 0xd000007fffffffa4 in ?? ()
#41 0x9000000000000052 in ?? ()
#42 0x9000005555560307 in ?? ()
#43 0x300000555555a277 in ?? ()
#44 0x7000005555560428 in ?? ()
#45 0x0e00007fffffffa4 in ?? ()
#46 0xa000005555556bb6 in ?? ()
#47 0x300000555555a1e6 in ?? ()
#48 0x1000007ffff7fd99 in ?? ()
#49 0x7000007ffff7fda0 in ?? ()
#50 0x3700007fffffffa4 in ?? ()
#51 0x09000055555557a0 in ?? ()
#52 0x8000007ffff7eda3 in ?? ()
#53 0x2800007fffffffa4 in ?? ()
#54 0x800000555555575c in ?? ()
#55 0x8800007fffffffa4 in ?? ()
#56 0xb00000555555a347 in ?? ()
#57 0x3000007fffffffa4 in ?? ()
#58 0xd0000055555557a1 in ?? ()
#59 0x0b00000000000052 in ?? ()
#60 0xd000000000000014 in ?? ()
#61 0x8800007fffffffa4 in ?? ()
#62 0xe00000555555a347 in ?? ()
#63 0xc100007fffffffa4 in ?? ()
#64 0x08000055555568a2 in ?? ()
#65 0xa000005555560308 in ?? ()
#66 0x300000555555a842 in ?? ()
#67 0xc000007ffff7fd99 in ?? ()
#68 0x900000555555a842 in ?? ()
---Type <return> to continue, or q <return> to quit---
#69 0x6600007fffffffaf in ?? ()
#70 0x6000005555556b30 in ?? ()
#71 0x5800007ffff7eda2 in ?? ()
#72 0x4000007ffff7eda2 in ?? ()
#73 0x4800007fffffffa5 in ?? ()
#74 0x0800005555556acc in ?? ()
#75 0x0100000000000000 in ?? ()
#76 0x0000000000000000 in ?? ()
(gdb) l
46 ci->defined_class = defined_class;
47 ci->argc = argc;
48 ci->me = me;
49
50 return vm_call0_body(th, ci, argv);
51 }
52
53 #if OPT_CALL_CFUNC_WITHOUT_FRAME
54 static VALUE
55 vm_call0_cfunc(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv)
(gdb)
</code></pre>
<p>上記の結果は Debian GNU/Linux testing (jessie) でのものですが、<br>
boron (つまり Debian GNU/Linux 6.0.8 (squeeze)) でも再現できました。</p>
<p>ただ、どちらの環境でも configure に optflags=-O0 として最適化をしないようにしてあります。<br>
(デフォルトの -O3 だと再現しません)</p>
Ruby master - Bug #9102 (Closed): ObjectSpace.dump_all creates a FD without close-on-exec flag
https://bugs.ruby-lang.org/issues/9102
2013-11-11T16:02:24Z
akr (Akira Tanaka)
akr@fsij.org
<p>I found test/objspace/test_objspace.rb creates a file descriptor without<br>
O_CLOEXEC.</p>
<p>Ruby should create all file descriptors with close-on-exec since Ruby 2.0.0.<br>
So, this behavior is a bug (on OS which supports O_CLOEXEC).</p>
<p>% strace -oz -f -e open ./ruby test/objspace/test_objspace.rb<br>
Run options:</p>
<a name="Running-tests"></a>
<h1 >Running tests:<a href="#Running-tests" class="wiki-anchor">¶</a></h1>
<p>Finished tests in 3.411053s, 4.1043 tests/s, 18316.3380 assertions/s.<br>
14 tests, 62478 assertions, 0 failures, 0 errors, 0 skips</p>
<p>ruby -v: ruby 2.1.0dev (2013-11-11 trunk 43646) [x86_64-linux]<br>
% grep -v O_CLOEXEC z<br>
9832 --- SIGCHLD (Child exited) @ 0 (0) ---<br>
9836 --- SIGCHLD (Child exited) @ 0 (0) ---<br>
9838 open("/tmp/rubyheapAk8lt8", O_RDWR|O_CREAT|O_EXCL, 0600) = 7<br>
9840 --- SIGCHLD (Child exited) @ 0 (0) ---<br>
9843 --- SIGCHLD (Child exited) @ 0 (0) ---<br>
9847 --- SIGCHLD (Child exited) @ 0 (0) ---<br>
% ./ruby -v<br>
ruby 2.1.0dev (2013-11-11 trunk 43646) [x86_64-linux]</p>
<p>I think we cannot use mkstemp().</p>
Ruby master - Bug #9090 (Closed): [BUG] object allocation during garbage collection phase
https://bugs.ruby-lang.org/issues/9090
2013-11-07T09:54:09Z
akr (Akira Tanaka)
akr@fsij.org
<p>昨日の夜、r43558 で make check を 300回動かしてみたところ、<br>
なんかずいぶんと [BUG] が出ました。</p>
<p>% ./ruby -v<br>
ruby 2.1.0dev (2013-11-06 trunk 43558) [x86_64-linux]<br>
% fgrep '[BUG]' zd10/*/log<br>
zd10/1/log:TestGem#test_looks_for_gemdeps_files_automatically_on_start = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/27/log:TestGem#test_gem_path_ordering = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/34/log:TestGemDependencyInstaller#test_install_version = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/45/log:TestGemSourceInstalled#test_spaceship = /home/akr/tst1/ruby/lib/rubygems/package.rb:419: [BUG] rb_gc_mark(): 0x002b969501c870 is T_ZOMBIE<br>
zd10/51/log:TestWeakRef#test_weakref_finalize = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/52/log:TestGem#test_looks_for_gemdeps_files_automatically_on_start = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/56/log:TestGemInstaller#test_generate_bin_symlink_update_older = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/73/log:TestCSV::Features#test_gzip_writer_bug_fix = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/74/log:TestGemDependencyInstaller#test_install_minimal_deps = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/88/log:TestGemDependencyInstaller#test_install_dependency_old = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/99/log:TestGemCommandsInstallCommand#test_execute_prerelease_skipped_when_non_pre_available = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/102/log:TestGemUninstaller#test_uninstall_doesnt_prompt_when_other_gem_satifies_requirement = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/104/log:TestWeakRef#test_weakref_finalize = /home/akr/tst1/ruby/lib/webrick/utils.rb:165: [BUG] object allocation during garbage collection phase<br>
zd10/120/log:TestGemSpecFetcher#test_available_specs_prerelease = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/127/log:TestGemDependencyInstaller#test_install_dependency_development_shallow = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/132/log:TestGemSourceSpecificFile#test_spec = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/157/log:TestGemUninstaller#test_remove_executables_user_format = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/172/log:TestGemSourceLocal#test_find_gem_prerelease = /home/akr/tst1/ruby/lib/webrick/utils.rb:165: [BUG] Segmentation fault<br>
zd10/173/log:TestGem#test_looks_for_gemdeps_files_automatically_on_start = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/193/log:TestGemSourceLocal#test_find_gem_prerelease = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/195/log:TestGem#test_looks_for_gemdeps_files_automatically_on_start = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/196/log:TestGemUninstaller#test_remove_executables_user = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/197/log:TestGemUninstaller#test_uninstall_prompt_includes_dep_type = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/215/log:TestWeakRef#test_weakref_finalize = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/216/log:TestGem#test_looks_for_gemdeps_files_automatically_on_start = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/217/log:TestGemDependencyInstaller#test_install_dependency_development_deep = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/227/log:TestGemCommandsCleanupCommand#test_handle_options_dry_run = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/234/log:TestGemInstaller#test_install_extension_flat = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/239/log:TestGemUninstaller#test_uninstall_only_lists_unsatified_deps = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/246/log:TestGemDependencyInstaller#test_install_install_dir = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/255/log:TestWeakRef#test_weakref_finalize = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/270/log:TestGemDependencyInstaller#test_install_dependencies_satisfied = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/288/log:TestWeakRef#test_weakref_finalize = /home/akr/tst1/ruby/lib/rinda/tuplespace.rb:325: [BUG] object allocation during garbage collection phase<br>
zd10/291/log:TestWeakRef#test_weakref_finalize = /home/akr/tst1/ruby/lib/webrick/utils.rb:165: [BUG] object allocation during garbage collection phase</p>
<p>一昨日の夜、r43539 でやったときは出なかったので、<br>
r43539 から r43558 のあいだのどれかだとおもうのですが、<br>
心当たりのある方はいませんか。</p>
<a name="-svn-log-r4353943558"></a>
<h2 >% svn log -r43539:43558<a href="#-svn-log-r4353943558" class="wiki-anchor">¶</a></h2>
<p>r43539 | tarui | 2013-11-05 20:15:21 +0900 (Tue, 05 Nov 2013) | 3 lines</p>
<pre><code>* gc.c (is_live_object): A hidden object may be a live object.
<a href="/issues/9072">[ruby-dev:47788]</a> [Bug #9072]
</code></pre>
<hr>
<p>r43540 | akr | 2013-11-05 21:25:15 +0900 (Tue, 05 Nov 2013) | 4 lines</p>
<ul>
<li>test/ruby/test_thread.rb (test_thread_join_in_trap):<br>
Run the test in a different process.</li>
</ul>
<hr>
<p>r43541 | tenderlove | 2013-11-06 04:15:40 +0900 (Wed, 06 Nov 2013) | 4 lines</p>
<ul>
<li>ext/psych/lib/psych/visitors/to_ruby.rb: process merge keys before<br>
reviving objects. Fixes GH psych #168</li>
<li>test/psych/test_merge_keys.rb: test for change<br>
<a href="https://github.com/tenderlove/psych/issues/168" class="external">https://github.com/tenderlove/psych/issues/168</a>
</li>
</ul>
<hr>
<p>r43542 | svn | 2013-11-06 04:15:46 +0900 (Wed, 06 Nov 2013) | 1 line</p>
<ul>
<li>2013-11-06</li>
</ul>
<hr>
<p>r43543 | ko1 | 2013-11-06 07:13:08 +0900 (Wed, 06 Nov 2013) | 3 lines</p>
<ul>
<li>benchmark/gc/gcbench.rb: add some options to make quiet.</li>
</ul>
<hr>
<p>r43544 | ko1 | 2013-11-06 07:13:51 +0900 (Wed, 06 Nov 2013) | 3 lines</p>
<ul>
<li>gc.c (Init_GC): add GC::OPTS to show options.</li>
</ul>
<hr>
<p>r43545 | eregon | 2013-11-06 07:27:27 +0900 (Wed, 06 Nov 2013) | 1 line</p>
<ul>
<li>benchmark/gc/gcbench.rb: fix typo of r43543</li>
</ul>
<hr>
<p>r43546 | ko1 | 2013-11-06 09:14:26 +0900 (Wed, 06 Nov 2013) | 3 lines</p>
<ul>
<li>gc.c: define RGENGC_ESTIMATE_OLDSPACE == 0 if USE_RGENGC is 0.</li>
</ul>
<hr>
<p>r43547 | ko1 | 2013-11-06 09:17:14 +0900 (Wed, 06 Nov 2013) | 12 lines</p>
<ul>
<li>benchmark/bm_vm1_gc_short_lived.rb: added.<br>
These GC benchmarks do not reflect practical applications.<br>
They are only for tuning.</li>
<li>benchmark/bm_vm1_gc_short_with_complex_long.rb: added.</li>
<li>benchmark/bm_vm1_gc_short_with_long.rb: added.</li>
<li>benchmark/bm_vm1_gc_short_with_symbol.rb: added.</li>
<li>benchmark/bm_vm1_gc_wb_ary.rb: added.</li>
<li>benchmark/bm_vm1_gc_wb_obj.rb: added.</li>
<li>benchmark/bm_vm_thread_queue.rb: added.<br>
Thie benchmark is added to know how fast C verion of thread.so.</li>
</ul>
<hr>
<p>r43548 | nobu | 2013-11-06 09:21:05 +0900 (Wed, 06 Nov 2013) | 1 line</p>
<ul>
<li>properties.</li>
</ul>
<hr>
<p>r43549 | glass | 2013-11-06 10:39:55 +0900 (Wed, 06 Nov 2013) | 1 line</p>
<ul>
<li>array.c (rb_ary_and): defer hash creation and some refactoring.</li>
</ul>
<hr>
<p>r43550 | glass | 2013-11-06 11:50:28 +0900 (Wed, 06 Nov 2013) | 2 lines</p>
<ul>
<li>array.c (rb_ary_sample): use RARRAY_AREF() and RARRAY_PTR_USE()<br>
instead of RARRAY_PTR().</li>
</ul>
<hr>
<p>r43551 | naruse | 2013-11-06 15:23:27 +0900 (Wed, 06 Nov 2013) | 1 line</p>
<a name="Suppress-Warnings-instance-variable-installed_by_version-not-initialized"></a>
<h2 >Suppress Warnings: instance variable @installed_by_version not initialized<a href="#Suppress-Warnings-instance-variable-installed_by_version-not-initialized" class="wiki-anchor">¶</a></h2>
<p>r43552 | naruse | 2013-11-06 15:23:29 +0900 (Wed, 06 Nov 2013) | 1 line</p>
<a name="Suppress-warnings-Fileexists-is-a-deprecated-name"></a>
<h2 >Suppress warnings: File.exists? is a deprecated name<a href="#Suppress-warnings-Fileexists-is-a-deprecated-name" class="wiki-anchor">¶</a></h2>
<p>r43553 | naruse | 2013-11-06 15:25:18 +0900 (Wed, 06 Nov 2013) | 1 line</p>
<a name="Suppress-warnings-ambiguous-first-argument-put-parentheses-or-even-spaces"></a>
<h2 >Suppress warnings: ambiguous first argument; put parentheses or even spaces<a href="#Suppress-warnings-ambiguous-first-argument-put-parentheses-or-even-spaces" class="wiki-anchor">¶</a></h2>
<p>r43554 | duerst | 2013-11-06 16:32:56 +0900 (Wed, 06 Nov 2013) | 1 line</p>
<a name="libopen3rb-tweaked-grammar-in-comments"></a>
<h2 >lib/open3.rb: tweaked grammar in comments<a href="#libopen3rb-tweaked-grammar-in-comments" class="wiki-anchor">¶</a></h2>
<p>r43555 | tarui | 2013-11-06 19:32:40 +0900 (Wed, 06 Nov 2013) | 2 lines</p>
<pre><code>* common.mk (help): add texts about gcbench.
</code></pre>
<hr>
<p>r43556 | glass | 2013-11-06 21:09:31 +0900 (Wed, 06 Nov 2013) | 1 line</p>
<ul>
<li>array.c (rb_ary_reverse): use RARRAY_PTR_USE().</li>
</ul>
<hr>
<p>r43557 | glass | 2013-11-06 21:20:39 +0900 (Wed, 06 Nov 2013) | 2 lines</p>
<ul>
<li>array.c (rb_ary_shift_m): use RARRAY_PTR_USE() without WB because<br>
there are not new relations.</li>
</ul>
<hr>
<p>r43558 | tarui | 2013-11-06 21:36:34 +0900 (Wed, 06 Nov 2013) | 12 lines</p>
<pre><code>* gc.c (gc_before_sweep): Change algorithm of malloc_limit to
conservative for closing to memory consumption of ruby 2.0.
* gc.c (GC_MALLOC_LIMIT, GC_MALLOC_LIMIT_GROWTH_FACTOR):
Adjust parameters for new algorithm.
Example: make gcbench-rdoc on a pc
time maxrss
2.0.0p343 285.27 281853952
trunk before patch 207.19 690405376
trunk after patch 211.59 312500224
</code></pre>
<hr>
<p>いちおう、失敗した場合のログを添付しておきます。</p>
Ruby master - Bug #9088 (Closed): SEGV with set_trace_func and break
https://bugs.ruby-lang.org/issues/9088
2013-11-06T20:12:28Z
akr (Akira Tanaka)
akr@fsij.org
<p>以下のようにすると SEGV します。</p>
<p>% ./ruby -e '<br>
set_trace_func proc {raise rescue nil}<br>
1.times do<br>
break<br>
end<br>
'<br>
-e:2: [BUG] Segmentation fault<br>
ruby 2.1.0dev (2013-11-06 trunk 43555) [x86_64-linux]</p>
<p>-- Control frame information -----------------------------------------------<br>
c:0005 p:---- s:0012 e:000011 CFUNC :raise<br>
c:0004 p:0007 s:0009 e:000008 BLOCK -e:2 [FINISH]<br>
c:0003 p:---- s:0007 e:000006 CFUNC :times<br>
c:0002 p:0014 s:0004 E:001d28 EVAL -e:3 [FINISH]<br>
c:0001 p:0000 s:0002 E:0025c8 TOP [FINISH]</p>
<p>-e:3:in <code><main>' -e:3:in </code>times'<br>
-e:2:in <code>block in <main>' -e:2:in </code>raise'</p>
<p>-- C level backtrace information -------------------------------------------<br>
./ruby(+0x178767) [0x7f2bc62dd767]<br>
./ruby(+0x17883c) [0x7f2bc62dd83c]<br>
./ruby(+0x1d4156) [0x7f2bc6339156]<br>
./ruby(rb_bug+0xdf) [0x7f2bc63392d0]<br>
./ruby(+0xef229) [0x7f2bc6254229]<br>
/lib/x86_64-linux-gnu/libpthread.so.0(+0xf030) [0x7f2bc5d36030] ../nptl/sysdeps/pthread/funlockfile.c:30<br>
./ruby(+0x16aca1) [0x7f2bc62cfca1]<br>
./ruby(+0x16aded) [0x7f2bc62cfded]<br>
./ruby(+0x16da81) [0x7f2bc62d2a81]<br>
./ruby(rb_check_funcall+0x48) [0x7f2bc62d2c95]<br>
./ruby(+0x783b2) [0x7f2bc61dd3b2]<br>
./ruby(rb_check_convert_type+0x50) [0x7f2bc61dd546]<br>
./ruby(rb_check_string_type+0x2b) [0x7f2bc6265f9c]<br>
./ruby(+0x2790a) [0x7f2bc618c90a]<br>
./ruby(rb_make_exception+0x25) [0x7f2bc618ca8f]<br>
./ruby(+0x2789b) [0x7f2bc618c89b]<br>
./ruby(+0x15eb7b) [0x7f2bc62c3b7b]<br>
./ruby(+0x15f725) [0x7f2bc62c4725]<br>
./ruby(+0x15f832) [0x7f2bc62c4832]<br>
./ruby(+0x1646ec) [0x7f2bc62c96ec]<br>
./ruby(+0x17413d) [0x7f2bc62d913d]<br>
./ruby(+0x172af7) [0x7f2bc62d7af7]<br>
./ruby(+0x172d61) [0x7f2bc62d7d61]<br>
./ruby(+0x172e09) [0x7f2bc62d7e09]<br>
./ruby(rb_proc_call_with_block+0x68) [0x7f2bc6190140]<br>
./ruby(+0x17cf70) [0x7f2bc62e1f70]<br>
./ruby(+0x17c2c4) [0x7f2bc62e12c4]<br>
./ruby(+0x17c478) [0x7f2bc62e1478]<br>
./ruby(+0x17c568) [0x7f2bc62e1568]<br>
./ruby(+0x1742d3) [0x7f2bc62d92d3]<br>
./ruby(rb_iseq_eval_main+0x34) [0x7f2bc62da0ae]<br>
./ruby(+0x26d8d) [0x7f2bc618bd8d]<br>
./ruby(ruby_exec_node+0x24) [0x7f2bc618bea6]<br>
./ruby(ruby_run_node+0x3e) [0x7f2bc618be79]<br>
./ruby(+0x24dc1) [0x7f2bc6189dc1]<br>
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd) [0x7f2bc4e87ead] libc-start.c:228<br>
./ruby(+0x24c49) [0x7f2bc6189c49]</p>
<p>-- Other runtime information -----------------------------------------------</p>
<ul>
<li>
<p>Loaded script: -e</p>
</li>
<li>
<p>Loaded features:</p>
<p>0 enumerator.so<br>
1 /home/ruby/tst1/lib/ruby/2.1.0/x86_64-linux/enc/encdb.so<br>
2 /home/ruby/tst1/lib/ruby/2.1.0/x86_64-linux/enc/trans/transdb.so<br>
3 /home/ruby/tst1/lib/ruby/2.1.0/x86_64-linux/rbconfig.rb<br>
4 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/compatibility.rb<br>
5 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/defaults.rb<br>
6 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/deprecate.rb<br>
7 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/errors.rb<br>
8 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/version.rb<br>
9 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/requirement.rb<br>
10 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/platform.rb<br>
11 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/basic_specification.rb<br>
12 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/stub_specification.rb<br>
13 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/specification.rb<br>
14 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/exceptions.rb<br>
15 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/core_ext/kernel_gem.rb<br>
16 /home/ruby/tst1/lib/ruby/2.1.0/thread.rb<br>
17 /home/ruby/tst1/lib/ruby/2.1.0/monitor.rb<br>
18 /home/ruby/tst1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb<br>
19 /home/ruby/tst1/lib/ruby/2.1.0/rubygems.rb</p>
</li>
<li>
<p>Process memory map:</p>
</li>
</ul>
<p>7f2bc4663000-7f2bc4678000 r-xp 00000000 08:01 2416670 /lib/x86_64-linux-gnu/libgcc_s.so.1<br>
7f2bc4678000-7f2bc4878000 ---p 00015000 08:01 2416670 /lib/x86_64-linux-gnu/libgcc_s.so.1<br>
7f2bc4878000-7f2bc4879000 rw-p 00015000 08:01 2416670 /lib/x86_64-linux-gnu/libgcc_s.so.1<br>
7f2bc4879000-7f2bc487b000 r-xp 00000000 08:01 4186651 /home/ruby/tst1/lib/ruby/2.1.0/x86_64-linux/enc/trans/transdb.so<br>
7f2bc487b000-7f2bc4a7b000 ---p 00002000 08:01 4186651 /home/ruby/tst1/lib/ruby/2.1.0/x86_64-linux/enc/trans/transdb.so<br>
7f2bc4a7b000-7f2bc4a7c000 rw-p 00002000 08:01 4186651 /home/ruby/tst1/lib/ruby/2.1.0/x86_64-linux/enc/trans/transdb.so<br>
7f2bc4a7c000-7f2bc4a7e000 r-xp 00000000 08:01 4186632 /home/ruby/tst1/lib/ruby/2.1.0/x86_64-linux/enc/encdb.so<br>
7f2bc4a7e000-7f2bc4c7d000 ---p 00002000 08:01 4186632 /home/ruby/tst1/lib/ruby/2.1.0/x86_64-linux/enc/encdb.so<br>
7f2bc4c7d000-7f2bc4c7e000 rw-p 00001000 08:01 4186632 /home/ruby/tst1/lib/ruby/2.1.0/x86_64-linux/enc/encdb.so<br>
7f2bc4c7e000-7f2bc4e69000 r--p 00000000 08:01 9978604 /usr/lib/locale/locale-archive<br>
7f2bc4e69000-7f2bc4fe9000 r-xp 00000000 08:01 2419615 /lib/x86_64-linux-gnu/libc-2.13.so<br>
7f2bc4fe9000-7f2bc51e9000 ---p 00180000 08:01 2419615 /lib/x86_64-linux-gnu/libc-2.13.so<br>
7f2bc51e9000-7f2bc51ed000 r--p 00180000 08:01 2419615 /lib/x86_64-linux-gnu/libc-2.13.so<br>
7f2bc51ed000-7f2bc51ee000 rw-p 00184000 08:01 2419615 /lib/x86_64-linux-gnu/libc-2.13.so<br>
7f2bc51ee000-7f2bc51f3000 rw-p 00000000 00:00 0<br>
7f2bc51f3000-7f2bc5274000 r-xp 00000000 08:01 2417137 /lib/x86_64-linux-gnu/libm-2.13.so<br>
7f2bc5274000-7f2bc5473000 ---p 00081000 08:01 2417137 /lib/x86_64-linux-gnu/libm-2.13.so<br>
7f2bc5473000-7f2bc5474000 r--p 00080000 08:01 2417137 /lib/x86_64-linux-gnu/libm-2.13.so<br>
7f2bc5474000-7f2bc5475000 rw-p 00081000 08:01 2417137 /lib/x86_64-linux-gnu/libm-2.13.so<br>
7f2bc5475000-7f2bc547d000 r-xp 00000000 08:01 2419616 /lib/x86_64-linux-gnu/libcrypt-2.13.so<br>
7f2bc547d000-7f2bc567c000 ---p 00008000 08:01 2419616 /lib/x86_64-linux-gnu/libcrypt-2.13.so<br>
7f2bc567c000-7f2bc567d000 r--p 00007000 08:01 2419616 /lib/x86_64-linux-gnu/libcrypt-2.13.so<br>
7f2bc567d000-7f2bc567e000 rw-p 00008000 08:01 2419616 /lib/x86_64-linux-gnu/libcrypt-2.13.so<br>
7f2bc567e000-7f2bc56ac000 rw-p 00000000 00:00 0<br>
7f2bc56ac000-7f2bc56ae000 r-xp 00000000 08:01 2417131 /lib/x86_64-linux-gnu/libdl-2.13.so<br>
7f2bc56ae000-7f2bc58ae000 ---p 00002000 08:01 2417131 /lib/x86_64-linux-gnu/libdl-2.13.so<br>
7f2bc58ae000-7f2bc58af000 r--p 00002000 08:01 2417131 /lib/x86_64-linux-gnu/libdl-2.13.so<br>
7f2bc58af000-7f2bc58b0000 rw-p 00003000 08:01 2417131 /lib/x86_64-linux-gnu/libdl-2.13.so<br>
7f2bc58b0000-7f2bc5917000 r-xp 00000000 08:01 10274367 /usr/lib/x86_64-linux-gnu/libgmp.so.10.0.5<br>
7f2bc5917000-7f2bc5b17000 ---p 00067000 08:01 10274367 /usr/lib/x86_64-linux-gnu/libgmp.so.10.0.5<br>
7f2bc5b17000-7f2bc5b1f000 rw-p 00067000 08:01 10274367 /usr/lib/x86_64-linux-gnu/libgmp.so.10.0.5<br>
7f2bc5b1f000-7f2bc5b26000 r-xp 00000000 08:01 2417134 /lib/x86_64-linux-gnu/librt-2.13.so<br>
7f2bc5b26000-7f2bc5d25000 ---p 00007000 08:01 2417134 /lib/x86_64-linux-gnu/librt-2.13.so<br>
7f2bc5d25000-7f2bc5d26000 r--p 00006000 08:01 2417134 /lib/x86_64-linux-gnu/librt-2.13.so<br>
7f2bc5d26000-7f2bc5d27000 rw-p 00007000 08:01 2417134 /lib/x86_64-linux-gnu/librt-2.13.so<br>
7f2bc5d27000-7f2bc5d3e000 r-xp 00000000 08:01 2417030 /lib/x86_64-linux-gnu/libpthread-2.13.so<br>
7f2bc5d3e000-7f2bc5f3d000 ---p 00017000 08:01 2417030 /lib/x86_64-linux-gnu/libpthread-2.13.so<br>
7f2bc5f3d000-7f2bc5f3e000 r--p 00016000 08:01 2417030 /lib/x86_64-linux-gnu/libpthread-2.13.so<br>
7f2bc5f3e000-7f2bc5f3f000 rw-p 00017000 08:01 2417030 /lib/x86_64-linux-gnu/libpthread-2.13.so<br>
7f2bc5f3f000-7f2bc5f43000 rw-p 00000000 00:00 0<br>
7f2bc5f43000-7f2bc5f63000 r-xp 00000000 08:01 2419619 /lib/x86_64-linux-gnu/ld-2.13.so<br>
7f2bc603c000-7f2bc6142000 rw-p 00000000 00:00 0<br>
7f2bc6154000-7f2bc6155000 rw-p 00000000 00:00 0<br>
7f2bc6155000-7f2bc615c000 r--s 00000000 08:01 10388551 /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache<br>
7f2bc615c000-7f2bc615d000 ---p 00000000 00:00 0<br>
7f2bc615d000-7f2bc6162000 rw-p 00000000 00:00 0<br>
7f2bc6162000-7f2bc6163000 r--p 0001f000 08:01 2419619 /lib/x86_64-linux-gnu/ld-2.13.so<br>
7f2bc6163000-7f2bc6164000 rw-p 00020000 08:01 2419619 /lib/x86_64-linux-gnu/ld-2.13.so<br>
7f2bc6164000-7f2bc6165000 rw-p 00000000 00:00 0<br>
7f2bc6165000-7f2bc6407000 r-xp 00000000 08:01 1584001 /home/ruby/tst1/ruby/ruby<br>
7f2bc6607000-7f2bc660d000 rw-p 002a2000 08:01 1584001 /home/ruby/tst1/ruby/ruby<br>
7f2bc660d000-7f2bc6634000 rw-p 00000000 00:00 0<br>
7f2bc7be7000-7f2bc8049000 rw-p 00000000 00:00 0 [heap]<br>
7fffda08e000-7fffda0af000 rw-p 00000000 00:00 0 [stack]<br>
7fffda1c4000-7fffda1c5000 r-xp 00000000 00:00 0 [vdso]<br>
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]</p>
<p>[NOTE]<br>
You may have encountered a bug in the Ruby interpreter or extension libraries.<br>
Bug reports are welcome.<br>
For details: <a href="http://www.ruby-lang.org/bugreport.html" class="external">http://www.ruby-lang.org/bugreport.html</a></p>
Ruby master - Bug #9072 (Closed): test_weakref.rb failure
https://bugs.ruby-lang.org/issues/9072
2013-11-02T10:03:13Z
akr (Akira Tanaka)
akr@fsij.org
<p>test_weakref.rb を単独で動かすと、以下のように失敗します。</p>
<p>boron% ./ruby -v -e 'load("test/test_weakref.rb")'<br>
ruby 2.1.0dev (2013-11-01 trunk 43510) [i686-linux]<br>
test/test_weakref.rb:19: warning: assigned but unused variable - str<br>
Run options:</p>
<a name="Running-tests"></a>
<h1 >Running tests:<a href="#Running-tests" class="wiki-anchor">¶</a></h1>
<p>[2/4] TestWeakRef#test_recycled = 0.01 s</p>
<ol>
<li>Failure:<br>
TestWeakRef#test_recycled [test/test_weakref.rb:25]:<br>
Expected "." to not be weakref_alive?.</li>
</ol>
<p>Finished tests in 0.140466s, 28.4766 tests/s, 64.0724 assertions/s.<br>
4 tests, 9 assertions, 1 failures, 0 errors, 0 skips</p>
<p>ruby -v: ruby 2.1.0dev (2013-11-01 trunk 43510) [i686-linux]</p>
<p>いろいろと疑問はあるのですが、<br>
とりあえず weakref_alive? の結果を確認して見ようと思って<br>
test/test_weakref.rb に以下のように p を入れてみました。</p>
<p>def test_recycled<br>
weak, str = make_weakref<br>
assert_nothing_raised(WeakRef::RefError) {weak.to_s}<br>
assert_predicate(weak, :weakref_alive?)<br>
ObjectSpace.garbage_collect<br>
ObjectSpace.garbage_collect<br>
assert_raise(WeakRef::RefError) {weak.to_s}<br>
p weak.weakref_alive?<br>
assert_not_predicate(weak, :weakref_alive?)<br>
end</p>
<p>そうすると、以下のようになりました。</p>
<p>boron% ./ruby -v -e 'load("test/test_weakref.rb")'<br>
ruby 2.1.0dev (2013-11-01 trunk 43510) [i686-linux]<br>
test/test_weakref.rb:19: warning: assigned but unused variable - str<br>
Run options:</p>
<a name="Running-tests-2"></a>
<h1 >Running tests:<a href="#Running-tests-2" class="wiki-anchor">¶</a></h1>
<p>[2/4] TestWeakRef#test_recyclednil<br>
= 0.01 s</p>
<ol>
<li>Failure:<br>
TestWeakRef#test_recycled [test/test_weakref.rb:26]:<br>
Expected [] to not be weakref_alive?.</li>
</ol>
<p>Finished tests in 0.164603s, 24.3009 tests/s, 54.6770 assertions/s.<br>
4 tests, 9 assertions, 1 failures, 0 errors, 0 skips</p>
<p>ruby -v: ruby 2.1.0dev (2013-11-01 trunk 43510) [i686-linux]</p>
<p>weakref_alive? は nil を返しているようですがそれはともかく、<br>
ここで奇妙なのは、Expected の次に出てくるのが "." から [] に変わっていることです。</p>
<p>さらにもうひとつ p を入れてみました。</p>
<p>def test_recycled<br>
weak, str = make_weakref<br>
assert_nothing_raised(WeakRef::RefError) {weak.to_s}<br>
assert_predicate(weak, :weakref_alive?)<br>
ObjectSpace.garbage_collect<br>
ObjectSpace.garbage_collect<br>
assert_raise(WeakRef::RefError) {weak.to_s}<br>
p weak.weakref_alive?<br>
p weak.weakref_alive?<br>
assert_not_predicate(weak, :weakref_alive?)<br>
end</p>
<p>そうすると以下のようになりました。</p>
<p>boron% ./ruby -v -e 'load("test/test_weakref.rb")'<br>
ruby 2.1.0dev (2013-11-01 trunk 43510) [i686-linux]<br>
test/test_weakref.rb:19: warning: assigned but unused variable - str<br>
Run options:</p>
<a name="Running-tests-3"></a>
<h1 >Running tests:<a href="#Running-tests-3" class="wiki-anchor">¶</a></h1>
<p>[2/4] TestWeakRef#test_recyclednil<br>
nil<br>
= 0.01 s</p>
<ol>
<li>Failure:<br>
TestWeakRef#test_recycled [test/test_weakref.rb:27]:<br>
Expected {Object=>:never} to not be weakref_alive?.</li>
</ol>
<p>Finished tests in 0.140746s, 28.4200 tests/s, 63.9450 assertions/s.<br>
4 tests, 9 assertions, 1 failures, 0 errors, 0 skips</p>
<p>ruby -v: ruby 2.1.0dev (2013-11-01 trunk 43510) [i686-linux]</p>
<p>Expected の次に出てくるのは今度は {Object=>:never} になっています。</p>
<p>思うのですが、Expected の次に出てくるのがこのように変わるのはあまりに奇妙ではないでしょうか。</p>
Ruby master - Bug #9069 (Closed): test_weakref.rb with GC.stress causes [BUG] rb_gc_mark(): 0x802...
https://bugs.ruby-lang.org/issues/9069
2013-11-01T15:40:31Z
akr (Akira Tanaka)
akr@fsij.org
<p>気がついたのですが、GC.stress = true で test/test_weakref.rb を動かすと、<br>
[BUG] rb_gc_mark(): 0x8024ee94 is T_ZOMBIE<br>
というようなメッセージで異常終了することがあります。</p>
<p>たとえば、boron の ~akr/tst1 に install したものでは以下のようになりました。</p>
<p>boron% pwd<br>
/home/akr/tst1/ruby<br>
boron% ./ruby -e 'GC.stress = true; load("test/test_weakref.rb")'<br>
Run options:</p>
<a name="Running-tests"></a>
<h1 >Running tests:<a href="#Running-tests" class="wiki-anchor">¶</a></h1>
<p>[2/4] TestWeakRef#test_recycled = 1.02 s</p>
<ol>
<li>Failure:<br>
TestWeakRef#test_recycled [test/test_weakref.rb:20]:<br>
Exception raised:<br>
<#<WeakRef::RefError: Invalid Reference - probably recycled>>.</li>
</ol>
<p>[3/4] TestWeakRef#test_ref/home/akr/tst1/lib/ruby/2.1.0/weakref.rb:84: [BUG] rb_gc_mark(): 0x8024ee94 is T_ZOMBIE<br>
ruby 2.1.0dev (2013-11-01 trunk 43497) [i686-linux]</p>
<p>-- Control frame information -----------------------------------------------<br>
c:0028 p:---- s:0123 e:000122 CFUNC :===<br>
c:0027 p:0011 s:0121 e:000119 METHOD /home/akr/tst1/lib/ruby/2.1.0/weakref.rb:84 [FINISH]<br>
c:0026 p:---- s:0116 e:000115 CFUNC :new<br>
c:0025 p:0015 s:0112 e:000111 BLOCK test/test_weakref.rb:9 [FINISH]<br>
c:0024 p:---- s:0110 e:000109 CFUNC :times<br>
c:0023 p:0033 s:0107 e:000106 METHOD test/test_weakref.rb:9<br>
c:0022 p:0007 s:0101 e:000100 METHOD test/test_weakref.rb:14<br>
c:0021 p:0038 s:0096 e:000095 METHOD /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:869<br>
c:0020 p:0069 s:0091 e:000090 METHOD /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1265<br>
c:0019 p:0019 s:0083 e:000082 METHOD /home/akr/tst1/lib/ruby/2.1.0/test/unit/testcase.rb:17<br>
c:0018 p:0068 s:0079 e:000078 BLOCK /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:940 [FINISH]<br>
c:0017 p:---- s:0073 e:000072 CFUNC :map<br>
c:0016 p:0103 s:0070 e:000069 METHOD /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:933<br>
c:0015 p:0015 s:0060 e:000058 BLOCK /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:663 [FINISH]<br>
c:0014 p:---- s:0055 e:000054 CFUNC :each<br>
c:0013 p:0067 s:0052 e:000051 METHOD /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:661<br>
c:0012 p:0135 s:0046 e:000045 METHOD /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:884<br>
c:0011 p:0009 s:0036 e:000035 METHOD /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1092<br>
c:0010 p:0009 s:0033 e:000032 BLOCK /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1079 [FINISH]<br>
c:0009 p:---- s:0030 e:000029 CFUNC :each<br>
c:0008 p:0048 s:0027 e:000026 METHOD /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1078<br>
c:0007 p:0017 s:0023 e:000022 METHOD /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1066<br>
c:0006 p:0019 s:0019 e:000018 METHOD /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:27<br>
c:0005 p:0010 s:0015 e:000014 METHOD /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:780<br>
c:0004 p:0027 s:0010 e:000008 BLOCK /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:372<br>
c:0003 p:0031 s:0007 e:000006 METHOD /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:33<br>
c:0002 p:0024 s:0004 e:000003 BLOCK /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:371 [FINISH]<br>
c:0001 p:0000 s:0002 E:fffff04c TOP [FINISH]</p>
<p>/home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:371:in <code>block in autorun' /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:33:in </code>run_once'<br>
/home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:372:in <code>block (2 levels) in autorun' /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:780:in </code>run'<br>
/home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:27:in <code>run' /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1066:in </code>run'<br>
/home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1078:in <code>_run' /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1078:in </code>each'<br>
/home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1079:in <code>block in _run' /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1092:in </code>run_tests'<br>
/home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:884:in <code>_run_anything' /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:661:in </code>_run_suites'<br>
/home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:661:in <code>each' /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:663:in </code>block in _run_suites'<br>
/home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:933:in <code>_run_suite' /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:933:in </code>map'<br>
/home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:940:in <code>block in _run_suite' /home/akr/tst1/lib/ruby/2.1.0/test/unit/testcase.rb:17:in </code>run'<br>
/home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb:1265:in <code>run' /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb:869:in </code>run_test'<br>
test/test_weakref.rb:14:in <code>test_ref' test/test_weakref.rb:9:in </code>make_weakref'<br>
test/test_weakref.rb:9:in <code>times' test/test_weakref.rb:9:in </code>block in make_weakref'<br>
test/test_weakref.rb:9:in <code>new' /home/akr/tst1/lib/ruby/2.1.0/weakref.rb:84:in </code>initialize'<br>
/home/akr/tst1/lib/ruby/2.1.0/weakref.rb:84:in `==='</p>
<p>-- C level backtrace information -------------------------------------------<br>
-e: TestWeakRef#test_ref(+0x1463e7) [0x801463e7]<br>
-e: TestWeakRef#test_ref(+0x1464d2) [0x801464d2]<br>
-e: TestWeakRef#test_ref(+0x1972bd) [0x801972bd]<br>
-e: TestWeakRef#test_ref(rb_bug+0x5f) [0x801973bb]<br>
-e: TestWeakRef#test_ref(+0x30503) [0x80030503]<br>
-e: TestWeakRef#test_ref(+0x305ad) [0x800305ad]<br>
-e: TestWeakRef#test_ref(+0x30783) [0x80030783]<br>
-e: TestWeakRef#test_ref(+0x3084a) [0x8003084a]<br>
-e: TestWeakRef#test_ref(+0x308a9) [0x800308a9]<br>
-e: TestWeakRef#test_ref(+0x3172b) [0x8003172b]<br>
-e: TestWeakRef#test_ref(+0x31864) [0x80031864]<br>
-e: TestWeakRef#test_ref(+0x2be55) [0x8002be55]<br>
-e: TestWeakRef#test_ref(rb_newobj_of+0x30) [0x8002bfbd]<br>
-e: TestWeakRef#test_ref(+0x15b54a) [0x8015b54a]<br>
-e: TestWeakRef#test_ref(+0x15b642) [0x8015b642]<br>
-e: TestWeakRef#test_ref(rb_ary_new_capa+0x29) [0x8015b677]<br>
-e: TestWeakRef#test_ref(rb_ary_new_from_args+0x1d) [0x8015b6ae]<br>
-e: TestWeakRef#test_ref(+0x2d3b6) [0x8002d3b6]<br>
-e: TestWeakRef#test_ref(+0x2d565) [0x8002d565]<br>
-e: TestWeakRef#test_ref(+0x2d59e) [0x8002d59e]<br>
-e: TestWeakRef#test_ref(+0x2d634) [0x8002d634]<br>
-e: TestWeakRef#test_ref(+0x2d675) [0x8002d675]<br>
-e: TestWeakRef#test_ref(rb_postponed_job_flush+0xc9) [0x8014b953]<br>
-e: TestWeakRef#test_ref(+0x15001b) [0x8015001b]<br>
-e: TestWeakRef#test_ref(+0x13c934) [0x8013c934]<br>
-e: TestWeakRef#test_ref(+0x13c214) [0x8013c214]<br>
-e: TestWeakRef#test_ref(+0x13cbd1) [0x8013cbd1]<br>
-e: TestWeakRef#test_ref(+0x13d57d) [0x8013d57d]<br>
-e: TestWeakRef#test_ref(rb_funcall+0x9f) [0x8013dd3e]<br>
-e: TestWeakRef#test_ref(rb_equal+0x43) [0x80061959]<br>
-e: TestWeakRef#test_ref(+0x130491) [0x80130491]<br>
-e: TestWeakRef#test_ref(+0x13c393) [0x8013c393]<br>
-e: TestWeakRef#test_ref(+0x13c462) [0x8013c462]<br>
-e: TestWeakRef#test_ref(+0x13c5aa) [0x8013c5aa]<br>
-e: TestWeakRef#test_ref(+0x13c214) [0x8013c214]<br>
-e: TestWeakRef#test_ref(+0x12f59a) [0x8012f59a]<br>
-e: TestWeakRef#test_ref(+0x1346f5) [0x801346f5]<br>
-e: TestWeakRef#test_ref(+0x142718) [0x80142718]<br>
-e: TestWeakRef#test_ref(+0x13c58c) [0x8013c58c]<br>
-e: TestWeakRef#test_ref(+0x13c214) [0x8013c214]<br>
-e: TestWeakRef#test_ref(+0x13cbd1) [0x8013cbd1]<br>
-e: TestWeakRef#test_ref(+0x13d57d) [0x8013d57d]<br>
-e: TestWeakRef#test_ref(rb_funcallv+0x2e) [0x8013dd7f]<br>
-e: TestWeakRef#test_ref(rb_obj_call_init+0x64) [0x8001cab3]<br>
-e: TestWeakRef#test_ref(rb_class_new_instance+0x39) [0x800635fb]<br>
-e: TestWeakRef#test_ref(+0x130462) [0x80130462]<br>
-e: TestWeakRef#test_ref(+0x130e69) [0x80130e69]<br>
-e: TestWeakRef#test_ref(+0x130f36) [0x80130f36]<br>
-e: TestWeakRef#test_ref(+0x134fee) [0x80134fee]<br>
-e: TestWeakRef#test_ref(+0x142718) [0x80142718]<br>
-e: TestWeakRef#test_ref(+0x141294) [0x80141294]<br>
-e: TestWeakRef#test_ref(+0x1413ca) [0x801413ca]<br>
-e: TestWeakRef#test_ref(+0x13e02a) [0x8013e02a]<br>
-e: TestWeakRef#test_ref(rb_yield+0x37) [0x8013e063]<br>
-e: TestWeakRef#test_ref(+0x5fb83) [0x8005fb83]<br>
-e: TestWeakRef#test_ref(+0x130475) [0x80130475]<br>
-e: TestWeakRef#test_ref(+0x130e69) [0x80130e69]<br>
-e: TestWeakRef#test_ref(+0x130f36) [0x80130f36]<br>
-e: TestWeakRef#test_ref(+0x134f06) [0x80134f06]<br>
-e: TestWeakRef#test_ref(+0x142718) [0x80142718]<br>
-e: TestWeakRef#test_ref(+0x141294) [0x80141294]<br>
-e: TestWeakRef#test_ref(+0x1413ca) [0x801413ca]<br>
-e: TestWeakRef#test_ref(+0x13e02a) [0x8013e02a]<br>
-e: TestWeakRef#test_ref(rb_yield+0x37) [0x8013e063]<br>
-e: TestWeakRef#test_ref(+0x16136d) [0x8016136d]<br>
-e: TestWeakRef#test_ref(+0x130475) [0x80130475]<br>
-e: TestWeakRef#test_ref(+0x130e69) [0x80130e69]<br>
-e: TestWeakRef#test_ref(+0x130f36) [0x80130f36]<br>
-e: TestWeakRef#test_ref(+0x134f06) [0x80134f06]<br>
-e: TestWeakRef#test_ref(+0x142718) [0x80142718]<br>
-e: TestWeakRef#test_ref(+0x141294) [0x80141294]<br>
-e: TestWeakRef#test_ref(+0x1413ca) [0x801413ca]<br>
-e: TestWeakRef#test_ref(+0x13e02a) [0x8013e02a]<br>
-e: TestWeakRef#test_ref(rb_yield+0x37) [0x8013e063]<br>
-e: TestWeakRef#test_ref(rb_ary_each+0x90) [0x8015f1d8]<br>
-e: TestWeakRef#test_ref(+0x130475) [0x80130475]<br>
-e: TestWeakRef#test_ref(+0x130e69) [0x80130e69]<br>
-e: TestWeakRef#test_ref(+0x130f36) [0x80130f36]<br>
-e: TestWeakRef#test_ref(+0x1317ce) [0x801317ce]<br>
-e: TestWeakRef#test_ref(+0x131dfc) [0x80131dfc]<br>
-e: TestWeakRef#test_ref(+0x134f06) [0x80134f06]<br>
-e: TestWeakRef#test_ref(+0x142718) [0x80142718]<br>
-e: TestWeakRef#test_ref(+0x141294) [0x80141294]<br>
-e: TestWeakRef#test_ref(+0x1413ca) [0x801413ca]<br>
-e: TestWeakRef#test_ref(+0x13e02a) [0x8013e02a]<br>
-e: TestWeakRef#test_ref(rb_yield+0x37) [0x8013e063]<br>
-e: TestWeakRef#test_ref(rb_ary_each+0x90) [0x8015f1d8]<br>
-e: TestWeakRef#test_ref(+0x130475) [0x80130475]<br>
-e: TestWeakRef#test_ref(+0x130e69) [0x80130e69]<br>
-e: TestWeakRef#test_ref(+0x130f36) [0x80130f36]<br>
-e: TestWeakRef#test_ref(+0x1317ce) [0x801317ce]<br>
-e: TestWeakRef#test_ref(+0x131dfc) [0x80131dfc]<br>
-e: TestWeakRef#test_ref(+0x134f06) [0x80134f06]<br>
-e: TestWeakRef#test_ref(+0x142718) [0x80142718]<br>
-e: TestWeakRef#test_ref(+0x141294) [0x80141294]<br>
-e: TestWeakRef#test_ref(+0x14148c) [0x8014148c]<br>
-e: TestWeakRef#test_ref(+0x14151d) [0x8014151d]<br>
-e: TestWeakRef#test_ref(rb_proc_call+0x80) [0x8001e3ec]<br>
-e: TestWeakRef#test_ref(+0x1a016) [0x8001a016]<br>
-e: TestWeakRef#test_ref(rb_exec_end_proc+0x185) [0x8001a2e0]<br>
-e: TestWeakRef#test_ref(+0x1a5cf) [0x8001a5cf]<br>
-e: TestWeakRef#test_ref(ruby_cleanup+0x158) [0x8001a778]<br>
-e: TestWeakRef#test_ref(ruby_run_node+0x40) [0x8001aaec]<br>
-e: TestWeakRef#test_ref(+0x1921a) [0x8001921a]<br>
/lib/i686/nosegneg/libc.so.6(__libc_start_main+0xe6) [0xb7d45ca6] libc-start.c:228<br>
-e: TestWeakRef#test_ref(+0x190d1) [0x800190d1]</p>
<p>-- Other runtime information -----------------------------------------------</p>
<ul>
<li>
<p>Loaded script: -e: TestWeakRef#test_ref</p>
</li>
<li>
<p>Loaded features:</p>
<p>0 enumerator.so<br>
1 /home/akr/tst1/lib/ruby/2.1.0/i686-linux/enc/encdb.so<br>
2 /home/akr/tst1/lib/ruby/2.1.0/i686-linux/enc/trans/transdb.so<br>
3 /home/akr/tst1/lib/ruby/2.1.0/i686-linux/rbconfig.rb<br>
4 /home/akr/tst1/lib/ruby/2.1.0/rubygems/compatibility.rb<br>
5 /home/akr/tst1/lib/ruby/2.1.0/rubygems/defaults.rb<br>
6 /home/akr/tst1/lib/ruby/2.1.0/rubygems/deprecate.rb<br>
7 /home/akr/tst1/lib/ruby/2.1.0/rubygems/errors.rb<br>
8 /home/akr/tst1/lib/ruby/2.1.0/rubygems/version.rb<br>
9 /home/akr/tst1/lib/ruby/2.1.0/rubygems/requirement.rb<br>
10 /home/akr/tst1/lib/ruby/2.1.0/rubygems/platform.rb<br>
11 /home/akr/tst1/lib/ruby/2.1.0/rubygems/basic_specification.rb<br>
12 /home/akr/tst1/lib/ruby/2.1.0/rubygems/stub_specification.rb<br>
13 /home/akr/tst1/lib/ruby/2.1.0/rubygems/specification.rb<br>
14 /home/akr/tst1/lib/ruby/2.1.0/rubygems/exceptions.rb<br>
15 /home/akr/tst1/lib/ruby/2.1.0/rubygems/core_ext/kernel_gem.rb<br>
16 /home/akr/tst1/lib/ruby/2.1.0/thread.rb<br>
17 /home/akr/tst1/lib/ruby/2.1.0/monitor.rb<br>
18 /home/akr/tst1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb<br>
19 /home/akr/tst1/lib/ruby/2.1.0/rubygems.rb<br>
20 /home/akr/tst1/lib/ruby/2.1.0/rubygems/dependency.rb<br>
21 /home/akr/tst1/lib/ruby/2.1.0/rubygems/path_support.rb<br>
22 /home/akr/tst1/lib/ruby/2.1.0/optparse.rb<br>
23 /home/akr/tst1/lib/ruby/2.1.0/minitest/unit.rb<br>
24 /home/akr/tst1/lib/ruby/2.1.0/prettyprint.rb<br>
25 /home/akr/tst1/lib/ruby/2.1.0/pp.rb<br>
26 /home/akr/tst1/lib/ruby/2.1.0/test/unit/assertions.rb<br>
27 /home/akr/tst1/lib/ruby/2.1.0/test/unit/testcase.rb<br>
28 /home/akr/tst1/lib/ruby/2.1.0/test/unit.rb<br>
29 /home/akr/tst1/lib/ruby/2.1.0/delegate.rb<br>
30 /home/akr/tst1/lib/ruby/2.1.0/weakref.rb<br>
31 /home/akr/tst1/lib/ruby/2.1.0/open3.rb<br>
32 /home/akr/tst1/lib/ruby/2.1.0/timeout.rb<br>
33 /home/akr/tst1/ruby/test/ruby/envutil.rb<br>
34 /home/akr/tst1/lib/ruby/2.1.0/i686-linux/io/console.so</p>
</li>
<li>
<p>Process memory map:</p>
</li>
</ul>
<p>80000000-80225000 r-xp 00000000 ca:03 319812 /home/akr/tst1/ruby/ruby<br>
80225000-80229000 rw-p 00225000 ca:03 319812 /home/akr/tst1/ruby/ruby<br>
80229000-80594000 rw-p 80229000 00:00 0 [heap]<br>
b7c7d000-b7c9a000 r-xp 00000000 ca:02 278530 /lib/libgcc_s.so.1<br>
b7c9a000-b7c9b000 rw-p 0001c000 ca:02 278530 /lib/libgcc_s.so.1<br>
b7ca8000-b7cab000 r-xp 00000000 ca:03 468021 /home/akr/tst1/lib/ruby/2.1.0/i686-linux/io/console.so<br>
b7cab000-b7cac000 rw-p 00002000 ca:03 468021 /home/akr/tst1/lib/ruby/2.1.0/i686-linux/io/console.so<br>
b7cac000-b7d2f000 rw-p b7cac000 00:00 0<br>
b7d2f000-b7e72000 r-xp 00000000 ca:02 83914 /lib/i686/nosegneg/libc-2.11.3.so<br>
b7e72000-b7e74000 r--p 00143000 ca:02 83914 /lib/i686/nosegneg/libc-2.11.3.so<br>
b7e74000-b7e75000 rw-p 00145000 ca:02 83914 /lib/i686/nosegneg/libc-2.11.3.so<br>
b7e75000-b7e78000 rw-p b7e75000 00:00 0<br>
b7e78000-b7e9c000 r-xp 00000000 ca:02 83026 /lib/i686/nosegneg/libm-2.11.3.so<br>
b7e9c000-b7e9d000 r--p 00023000 ca:02 83026 /lib/i686/nosegneg/libm-2.11.3.so<br>
b7e9d000-b7e9e000 rw-p 00024000 ca:02 83026 /lib/i686/nosegneg/libm-2.11.3.so<br>
b7e9e000-b7ea7000 r-xp 00000000 ca:02 83251 /lib/i686/nosegneg/libcrypt-2.11.3.so<br>
b7ea7000-b7ea8000 r--p 00008000 ca:02 83251 /lib/i686/nosegneg/libcrypt-2.11.3.so<br>
b7ea8000-b7ea9000 rw-p 00009000 ca:02 83251 /lib/i686/nosegneg/libcrypt-2.11.3.so<br>
b7ea9000-b7ed0000 rw-p b7ea9000 00:00 0<br>
b7ed0000-b7ed2000 r-xp 00000000 ca:02 83024 /lib/i686/nosegneg/libdl-2.11.3.so<br>
b7ed2000-b7ed3000 r--p 00001000 ca:02 83024 /lib/i686/nosegneg/libdl-2.11.3.so<br>
b7ed3000-b7ed4000 rw-p 00002000 ca:02 83024 /lib/i686/nosegneg/libdl-2.11.3.so<br>
b7ed4000-b7ed5000 rw-p b7ed4000 00:00 0<br>
b7ed5000-b7f32000 r-xp 00000000 ca:02 170351 /usr/lib/libgmp.so.3.5.2<br>
b7f32000-b7f33000 rw-p 0005d000 ca:02 170351 /usr/lib/libgmp.so.3.5.2<br>
b7f33000-b7f3a000 r-xp 00000000 ca:02 83913 /lib/i686/nosegneg/librt-2.11.3.so<br>
b7f3a000-b7f3b000 r--p 00006000 ca:02 83913 /lib/i686/nosegneg/librt-2.11.3.so<br>
b7f3b000-b7f3c000 rw-p 00007000 ca:02 83913 /lib/i686/nosegneg/librt-2.11.3.so<br>
b7f3c000-b7f51000 r-xp 00000000 ca:02 83903 /lib/i686/nosegneg/libpthread-2.11.3.so<br>
b7f51000-b7f52000 r--p 00014000 ca:02 83903 /lib/i686/nosegneg/libpthread-2.11.3.so<br>
b7f52000-b7f53000 rw-p 00015000 ca:02 83903 /lib/i686/nosegneg/libpthread-2.11.3.so<br>
b7f53000-b7f55000 rw-p b7f53000 00:00 0<br>
b7f56000-b7f57000 rw-p b7f56000 00:00 0<br>
b7f57000-b7f5a000 r-xp 00000000 ca:03 467993 /home/akr/tst1/lib/ruby/2.1.0/i686-linux/enc/trans/transdb.so<br>
b7f5a000-b7f5b000 rw-p 00002000 ca:03 467993 /home/akr/tst1/lib/ruby/2.1.0/i686-linux/enc/trans/transdb.so<br>
b7f5b000-b7f5d000 r-xp 00000000 ca:03 467962 /home/akr/tst1/lib/ruby/2.1.0/i686-linux/enc/encdb.so<br>
b7f5d000-b7f5e000 rw-p 00001000 ca:03 467962 /home/akr/tst1/lib/ruby/2.1.0/i686-linux/enc/encdb.so<br>
b7f5e000-b7f5f000 ---p b7f5e000 00:00 0<br>
b7f5f000-b7f66000 rw-p b7f5f000 00:00 0<br>
b7f66000-b7f67000 r-xp b7f66000 00:00 0 [vdso]<br>
b7f67000-b7f82000 r-xp 00000000 ca:02 278816 /lib/ld-2.11.3.so<br>
b7f82000-b7f83000 r--p 0001b000 ca:02 278816 /lib/ld-2.11.3.so<br>
b7f83000-b7f84000 rw-p 0001c000 ca:02 278816 /lib/ld-2.11.3.so<br>
bfe6b000-bfe81000 rw-p bfe6b000 00:00 0 [stack]</p>
<p>[NOTE]<br>
You may have encountered a bug in the Ruby interpreter or extension libraries.<br>
Bug reports are welcome.<br>
For details: <a href="http://www.ruby-lang.org/bugreport.html" class="external">http://www.ruby-lang.org/bugreport.html</a></p>
<p>zsh: abort ./ruby -e 'GC.stress = true; load("test/test_weakref.rb")'</p>
<p>boron は以下のように Debian GNU/Linux 6.0.8 (squeeze) です。</p>
<p>boron% lsb_release -idrc<br>
Distributor ID: Debian<br>
Description: Debian GNU/Linux 6.0.8 (squeeze)<br>
Release: 6.0.8<br>
Codename: squeeze<br>
boron% uname -mrsv<br>
Linux 2.6.18-6-xen-686 #1 SMP Thu Nov 5 19:54:42 UTC 2009 i686</p>
<p>なお、この結果はあまり安定したものではないようで、異常終了しない環境もあります。</p>
Ruby master - Feature #8976 (Closed): file-scope freeze_string directive
https://bugs.ruby-lang.org/issues/8976
2013-10-02T10:49:13Z
akr (Akira Tanaka)
akr@fsij.org
<p>Yesterday, we had a face-to-face developer meeting.<br>
<a href="https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20131001Japan" class="external">https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20131001Japan</a><br>
Several committers attended.<br>
matz didn't attended, though. (This means this issue is not concluded.)</p>
<p>We believe we found a better way to freeze static string literals for<br>
less GC pressure.<br>
"static string literal" is a string literal without dynamic expression.</p>
<p>Currently, <code>f</code>-suffix, <code>"..."f</code>, is used to freeze a string literal to avoid<br>
String object allocation.</p>
<p>There are several problems for <code>f</code>-suffix:</p>
<ul>
<li>The notation is ugly.</li>
<li>Syntax error on Ruby 2.0.<br>
We cannot use the feature in version independent libraries.<br>
So, it is difficult to deploy.</li>
<li>Need to modify for each string literal.<br>
This is cumbersome.</li>
</ul>
<p>The new way we found is a file-scope directive as follows</p>
<a name="freeze_string-true"></a>
<h1 >freeze_string: true<a href="#freeze_string-true" class="wiki-anchor">¶</a></h1>
<p>The above comment at top of a file changes semantics of<br>
static string literals in the file.<br>
The static string literals will be frozen and always returns same object.<br>
(The semantics of dynamic string literals is not changed.)</p>
<p>This way has following benefits:</p>
<ul>
<li>No ugly <code>f</code>-suffix.</li>
<li>No syntax error on older Ruby.</li>
<li>We need only a line for each file.</li>
</ul>
<p>We can write version independent library using frozen static string literals as follows.</p>
<ul>
<li>Use the directive at top of the file: <code># freeze_string: true</code><br>
Older Ruby ignore this as a comment.</li>
<li>Use <code>"...".dup</code> for strings to be modified.<br>
Older Ruby has small disadvantage: useless <code>dup</code> is called.</li>
</ul>
<p>Note that the directive effects all static string literals regardless of<br>
single quotes, double quotes, <code>%q</code>-string, <code>%qq</code>-string and here documents.<br>
The reason that the directive is effective not only single quotes is<br>
we want to use escape sequences such as <code>\n</code> in frozen string literals.</p>
<p>Also note that similar directive is already exist:</p>
<pre><code>% ruby -w -e '
def m
end
'
-e:3: warning: mismatched indentations at 'end' with 'def' at 2
% ruby -w -e '# -*- warn_indent: false -*-
def m
end
'
</code></pre>
<p>The directive, <code>warn_indent: false</code>, disables "mismatched indentations" warning.</p>
<p>nobu implemented this feature in the meeting.<br>
Please attach the patch, nobu.</p>
Ruby master - Bug #8893 (Closed): make install fails with cross compilation after r42850-r42864
https://bugs.ruby-lang.org/issues/8893
2013-09-11T12:49:53Z
akr (Akira Tanaka)
akr@fsij.org
<p>r42850 から r42864 までのあいだで、cross compile したときに<br>
make install が失敗するようになっています。<br>
Debian GNU/Linux (wheezy) であれば以下のように再現できます。</p>
<p>% dpkg -l|grep gcc-mingw-w64<br>
ii gcc-mingw-w64 4.6.3-14+8 all GNU C compiler for MinGW-w64<br>
ii gcc-mingw-w64-base 4.6.3-14+8 amd64 GNU Compiler Collection for MinGW-w64 (base package)<br>
ii gcc-mingw-w64-i686 4.6.3-14+8 amd64 GNU C compiler for MinGW-w64 targeting Win32<br>
ii gcc-mingw-w64-x86-64 4.6.3-14+8 amd64 GNU C compiler for MinGW-w64 targeting Win64</p>
<p>% ruby -v<br>
ruby 2.1.0dev (2013-09-09 trunk 42896) [x86_64-linux]</p>
<p>% svn co <a href="http://svn.ruby-lang.org/repos/ruby/trunk" class="external">http://svn.ruby-lang.org/repos/ruby/trunk</a> ruby<br>
% cd ruby<br>
% autoconf<br>
% ./configure --prefix=/tmp/a --build=x86_64-unknown-linux-gnu --host=i686-w64-mingw32<br>
% make<br>
% make install<br>
...<br>
ruby --disable=gems -I/tmp/a/ruby -ri386-mingw32-fake -I<code>cd ./lib; pwd</code> -- --disable-gems -r./i386-mingw32-fake ./tool/rbinstall.rb --make="make" --dest-dir="" --extout=".ext" --mflags="" --make-flags="" --data-mode=0644 --prog-mode=0755 --installed-list .installed.list --mantype="doc" --install=all --rdoc-output=".ext/rdoc"<br>
ruby: No such file or directory -- --disable-gems (LoadError)<br>
make: *** [do-install-all] エラー 1</p>
<p>気がついたのは boron でやっている chkbuild で失敗していることで、<br>
上で示した手順の mingw-w64 だけでなく、他の環境でもことごとく失敗しています。</p>
<p><a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-aarch64/log/20130906T200134Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-aarch64/log/20130906T200134Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-amd64/log/20130906T201128Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-amd64/log/20130906T201128Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-android/log/20130906T213908Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-android/log/20130906T213908Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-arm/log/20130906T202000Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-arm/log/20130906T202000Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-armeb/log/20130906T202827Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-armeb/log/20130906T202827Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-cygwin/log/20130906T221527Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-cygwin/log/20130906T221527Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-i386/log/20130906T203633Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-i386/log/20130906T203633Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-mingw/log/20130906T195217Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-mingw/log/20130906T195217Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-mips/log/20130906T204410Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-mips/log/20130906T204410Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-mipsandroid/log/20130906T220611Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-mipsandroid/log/20130906T220611Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-mipsel/log/20130906T205305Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-mipsel/log/20130906T205305Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-powerpc/log/20130906T210204Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-powerpc/log/20130906T210204Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-sh/log/20130906T211050Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-sh/log/20130906T211050Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-sparc/log/20130906T211937Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-sparc/log/20130906T211937Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-x86android/log/20130906T215437Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-x86android/log/20130906T215437Z.diff.html.gz</a><br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-xtensa/log/20130906T212745Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-xtensa/log/20130906T212745Z.diff.html.gz</a></p>
Ruby master - Feature #8887 (Closed): min(n), max(n), min_by(n), max_by(n)
https://bugs.ruby-lang.org/issues/8887
2013-09-10T22:28:02Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about adding an optional argument, n, for Enumerable#{min,max,min_by,max_by} to<br>
return minimum/maximum n elements as an array.</p>
<p>Example:</p>
<ul>
<li>[6, 0, 3, 3, 8, 3, 5, 0, 6].min(4) #=> [0, 0, 3, 3]</li>
<li>[6, 0, 3, 3, 8, 3, 5, 0, 6].max(4) #=> [5, 6, 6, 8]</li>
<li>[6, 0, 3, 3, 8, 3, 5, 0, 6].min_by(4) {|v| (v-5)**2 } #=> [5, 6, 6, 3]</li>
<li>[6, 0, 3, 3, 8, 3, 5, 0, 6].max_by(4) {|v| (v-5)**2 } #=> [3, 8, 0, 0]</li>
</ul>
<p>These methods are similar to sort follows first or last.</p>
<ul>
<li>e.min(n) is similar to e.sort.first(n)</li>
<li>e.max(n) is similar to e.sort.last(n)</li>
<li>e.min_by(n) {...} is similar to e.sort_by {...}.first(n)</li>
<li>e.max_by(n) {...} is similar to e.sort_by {...}.last(n)</li>
</ul>
<p>However e.min(n), e.max(n), e.min_by(n), e.max_by(n) are<br>
less memory consuming and can be faster.<br>
They use memory proportional to n, not e.<br>
They doesn't sort whole e.</p>
<p>I feel their use is not rare.<br>
I found several use after searching.</p>
<p>[ruby-talk:123508], [ruby-list:40939], [ruby-talk:273980]<br>
<a href="http://d.hatena.ne.jp/mjh/20101024/1287901875" class="external">http://d.hatena.ne.jp/mjh/20101024/1287901875</a><br>
<a href="http://stackoverflow.com/questions/11094874/get-top-n-elements-from-ruby-array-of-hash-values" class="external">http://stackoverflow.com/questions/11094874/get-top-n-elements-from-ruby-array-of-hash-values</a><br>
<a href="http://www.math.kobe-u.ac.jp/~kodama/tips-ruby-sized_pqueue.html" class="external">http://www.math.kobe-u.ac.jp/~kodama/tips-ruby-sized_pqueue.html</a><br>
<a href="https://bitbucket.org/sterlingcamden/topn" class="external">https://bitbucket.org/sterlingcamden/topn</a></p>
<p>Also, e.max(n) can be used to implement weighted random sampling.</p>
<p>Pavlos S. Efraimidis, Paul G. Spirakis<br>
Weighted random sampling with a reservoir<br>
Information Processing Letters<br>
Volume 97, Issue 5 (16 March 2006)</p>
<pre><code> % ./ruby -e '
module Enumerable
def wsample(n)
self.max_by(n) {|v| rand ** (1.0/yield(v)) }
end
end
e = (-20..20).to_a*10000
a = e.wsample(20000) {|x|
Math.exp(-(x/5.0)**2) # normal distribution
}
# a is 20000 samples from e.
p a.length
h = a.group_by {|x| x }
-10.upto(10) {|x| puts "*" * (h[x].length/30.0).to_i if h[x] }
'
20000
*
***
******
***********
******************
*****************************
*****************************************
****************************************************
***************************************************************
********************************************************************
***********************************************************************
***********************************************************************
**************************************************************
****************************************************
***************************************
***************************
******************
***********
*******
***
*
</code></pre>
<p>Any comments?</p>
Ruby master - Feature #8809 (Closed): Process.clock_getres
https://bugs.ruby-lang.org/issues/8809
2013-08-22T23:33:36Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about Process.clock_getres method?</p>
<p>POSIX defines clock_getres function to provide resolution information<br>
of clocks.</p>
<p>I made a pacth to invoke clock_getres function.</p>
<p>Process.clock_getres(Process::CLOCK_MONOTONIC) #=> 1.0e-09<br>
Process.clock_getres(Process::CLOCK_MONOTONIC_COARSE) #=> 0.00400025</p>
<p>The result means that the resolution of CLOCK_MONOTONIC is 1ns and<br>
the resolution of CLOCK_MONOTONIC_COARSE is 4.00025ms.</p>
<p>Process.clock_getres has optional unit argument as Process.clock_gettime.</p>
<p>Process.clock_getres(Process::CLOCK_MONOTONIC, :nanosecond) #=> 1<br>
Process.clock_getres(Process::CLOCK_MONOTONIC_COARSE, :nanosecond) #=> 4000250</p>
<p>It supports emulated clocks as well.</p>
<p>Process.clock_getres(:SUS_GETTIMEOFDAY_BASED_CLOCK_REALTIME) #=> 1.0000000000000002e-06<br>
Process.clock_getres(:SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) #=> 1.0000000000000002e-06</p>
<p>The unit argument can be :hertz, which means the reciprocal of the second.</p>
<p>Process.clock_getres(:SUS_GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) #=> 1000000.0</p>
<p>Note that<br>
Process.clock_getres(:POSIX_TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) is the clock ticks per second (CLK_TCK) and<br>
Process.clock_getres(:ISO_C_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) is CLOCK_PER_SEC.<br>
I wanted to access them easily to investigate emulated clock behaviors on<br>
various OSes.</p>
<p>Any comments?</p>
Ruby master - Feature #8748 (Rejected): Integer#popcount (Fixnum#popcount and Bignum#popcount)
https://bugs.ruby-lang.org/issues/8748
2013-08-07T21:51:37Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about adding <code>Integer#popcoun</code> t method?<br>
(actually <code>Fixnum#popcount</code> and <code>Bignum#popcount</code> )</p>
<pre><code>0.popcount #=> 0
1.popcount #=> 1
255.popcount #=> 8
256.popcount #=> 1
(10**100).popcount #=> 105
(257**257).popcount #=> 999
</code></pre>
<p>It counts the number of one bits in the integer.<br>
If the integer is negative, the one bits in the absolute number is counted.</p>
<p>popcount has various applications.<br>
Hamming distance, rank/select for succinct data structure,<br>
brightness of monochrome image, etc.</p>
<p>In general, popcount is useful when an array is encoded as an integer.</p>
<p>Several lower layers provides this feature.<br>
gcc and clang has <code>__builtin_popcount</code>.<br>
Intel and AMD provides popcnt instruction.</p>
<p>Several languages and libraries provides this feature:</p>
<p>absolute number: Mathmatica(<code>DigitCount</code>)<br>
two's complement: Java(<code>java.math.BigInteger#bitCount</code>), Scala(<code>bitCount</code>), CommonLisp(<code>logcount</code>), CLN(<code>logcount</code>)<br>
other behavior: GMP(<code>mpz_popcount</code>), Haskell(<code>popCount</code>), Scheme(<code>bitwise-bit-count</code>)<br>
fixed size: gcc (<code>__builtin_popcount</code>), Intel/AMD(<code>popcnt</code>), Java(<code>java.lang.Integer.bitCount</code>)</p>
<p>For negative numbers, my implementation counts bits in <code>abs(n)</code>.<br>
I think this is easy to understand, at least.<br>
However many software counts bits in two's complement representation.</p>
<p>There are several names.<br>
I think <code>popcount</code> is popular but <code>bitcount</code> is also a possible name.<br>
I don't like <code>logcount</code>.</p>
<p>Any comments?</p>
<p>Details of the other software:</p>
<p>Mathmatica has <code>DigitCount</code> which can be used as <code>popcount</code>.<br>
<code>n.popcount</code> can be implemented as <code>DigitCount[n, 2, 1]</code>.<br>
It seems work for <code>abs(n)</code>. (I tested with Wolfram Alpha.)<br>
<a href="http://reference.wolfram.com/mathematica/ref/DigitCount.html" class="external">http://reference.wolfram.com/mathematica/ref/DigitCount.html</a></p>
<p>Java has <code>bitCount</code> method in <code>java.lang.Integer</code> and <code>java.math.BigInteger</code>.<br>
<code>java.lang.Integer</code> counts one-bits in two's complement representation<br>
(so it is not applicable for infinite precision integer).<br>
<code>java.math.BigInteger</code> counts bits which is different to sign bit in<br>
two's complement representation.<br>
<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#bitCount(int)" class="external">http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#bitCount(int)</a><br>
<a href="http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#bitCount()" class="external">http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#bitCount()</a></p>
<p>Scala has <code>bitCount</code> method too.<br>
It works as Java.<br>
<a href="http://www.scala-lang.org/api/current/index.html#scala.math.BigInt" class="external">http://www.scala-lang.org/api/current/index.html#scala.math.BigInt</a></p>
<p>CommonLisp has <code>logcount</code> function.<br>
<a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_logcou.htm" class="external">http://www.lispworks.com/documentation/HyperSpec/Body/f_logcou.htm</a></p>
<p>CLN has <code>logcount</code> function.<br>
<a href="http://www.ginac.de/CLN/cln.html#Exact-numbers" class="external">http://www.ginac.de/CLN/cln.html#Exact-numbers</a></p>
<p>GMP has <code>mpz_popcount</code>.<br>
It returns a some constant for negative values.<br>
<a href="http://gmplib.org/manual/Integer-Logic-and-Bit-Fiddling.html#Integer-Logic-and-Bit-Fiddling" class="external">http://gmplib.org/manual/Integer-Logic-and-Bit-Fiddling.html#Integer-Logic-and-Bit-Fiddling</a></p>
<p>Haskell has <code>popCount</code>.<br>
It seems hang for negative values.<br>
<a href="http://www.haskell.org/ghc/docs/7.6.2/html/libraries/base/Data-Bits.html#t:Bits" class="external">http://www.haskell.org/ghc/docs/7.6.2/html/libraries/base/Data-Bits.html#t:Bits</a></p>
<p>Scheme has <code>bitwise-bit-count</code>.<br>
It returns negative result for negative values.<br>
<a href="http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-12.html#node_sec_11.1" class="external">http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-12.html#node_sec_11.1</a></p>
Ruby master - Bug #8744 (Closed): SIZEOF_UNSIGNED___INT128
https://bugs.ruby-lang.org/issues/8744
2013-08-06T23:59:39Z
akr (Akira Tanaka)
akr@fsij.org
<p>気がついたのですが、config.h で、SIZEOF_UINT128_T の定義として<br>
SIZEOF_UNSIGNED___INT128 が使われるのですが、<br>
定義されないようです。</p>
<p>% grep INT128 .ext/include/x86_64-linux/ruby/config.h<br>
#define SIZEOF___INT128 16<br>
#define HAVE_INT128_T 1<br>
#define SIZEOF_INT128_T SIZEOF___INT128<br>
#define HAVE_UINT128_T 1<br>
#define SIZEOF_UINT128_T SIZEOF_UNSIGNED___INT128<br>
% ./ruby -v<br>
ruby 2.1.0dev (2013-08-06 trunk 42393) [x86_64-linux]</p>
Ruby master - Feature #8738 (Rejected): Integer#single_bit? (Actually Fixnum#single_bit? and Bign...
https://bugs.ruby-lang.org/issues/8738
2013-08-05T22:03:14Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about a new method Integer#single_bit?<br>
(Actually Fixnum#single_bit? and Bignum#single_bit?)</p>
<p>n.single_bit? returns true for abs(n) is 1, 2, 4, ..., 2**i for some i.</p>
<p>Sometimes we need to test an integer contains only one bit or not.</p>
<p>It can be written as x != 0 && (x.abs & (x.abs-1)) == 0 but it is not<br>
so easy to understand and it needs several Bignum allocations if x is Bignum.</p>
<p>I propose this method mainly because it assists<br>
Integer#bit_length to determine an integer fits in a fixed size<br>
two's complement format.<br>
If Integer#bit_length works for abs(n) as I proposed as [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Integer#bitsize (actually Fixnum#bitsize and Bignum#bitsize) (Closed)" href="https://bugs.ruby-lang.org/issues/8700">#8700</a>],<br>
-2**m should be tested for two's complement format and<br>
Integer#single_bit? can be used for that without<br>
Bignum allocation.<br>
(If Integer#bit_length works for two's complement number as Java,<br>
Integer#single_bit? can be used to test abs(n).bit_length without Bignum<br>
allocation. Integer#single_bit? is useful anyway.)</p>
<p>Integer#single_bit? has other use cases.</p>
<p>Some algorithms can be simplified if an input is a power of two.<br>
For example, multiplication and division can be a bit shift.<br>
Another example, FFT require input size is a power of two.</p>
<p>I think it can be used for various applications because<br>
powers of two are special numbers for binary computer.</p>
<p>Several considerations:</p>
<p>There are several method names I considered.</p>
<ul>
<li>single_bit?</li>
<li>power_of_two?</li>
<li>power_of_2?</li>
<li>pow2?<br>
I feel power_of_two? returns false for negative numbers: (-1).power_of_two? => false.<br>
So I choose single_bit?.</li>
</ul>
<p>This method should behave for an absolute number<br>
because I want to test -2**m.<br>
I'd like to avoid n.abs.single_bit? because n.abs can allocate<br>
a Bignum object.</p>
<p>I considered Integer#popcount which returns number of one bits in abs(n).<br>
n.single_bit? can be implemented as n.popcount == 1.<br>
I think Integer#popcount is interesting and good to have.<br>
However Integer#single_bit? can be faster because it can return false<br>
when it finds second one bit.<br>
Also, n.popcount may need to allocate a Bignum if n is very big.<br>
(n.bit_length also needs a Bignum allocation in such case, though.)</p>
<p>Any comments?</p>
Ruby master - Feature #8700 (Closed): Integer#bitsize (actually Fixnum#bitsize and Bignum#bitsize)
https://bugs.ruby-lang.org/issues/8700
2013-07-28T22:56:20Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about adding Integer#bitsize (actually Fixnum#bitsize and Bignum#bitsize)?</p>
<p>Integer#bitsize returns the position of the most significant bit in the absolute value.<br>
(The position of the least significant bit is 1.)<br>
It returns 0 if no bit set (i.e. the value 0).</p>
<p>Mathematically, n.bitsize is ceil(log2(abs(n)+1)).</p>
<p>Sometimes we want to know the size of a integer.</p>
<ul>
<li>
<p>Determine the size of an integer in some format.<br>
Although there are various formats, bitsize is a key property to determine the result size.<br>
Several examples:</p>
<ul>
<li>If a format is 4 bytes for absolute value, it overflows if 32 <= n.bitsize.</li>
<li>If a format is 4 bytes for sign bit with absolute value, it overflows if 31 <= n.bitsize.</li>
<li>If a format is 4 bytes for 2's complement format, it overflow if 31 <= n.bitsize && n != -2**31.</li>
<li>BER-compressed integer needs (n.bitsize+6)/7 bytes when n > 0.<br>
BER-compressed integer is an example of VLQ.<br>
<a href="http://en.wikipedia.org/wiki/Variable-length_quantity" class="external">http://en.wikipedia.org/wiki/Variable-length_quantity</a>
</li>
<li>Elias gamma coding needs 2*n.bitsize-1 bits.<br>
<a href="https://en.wikipedia.org/wiki/Elias_gamma_coding" class="external">https://en.wikipedia.org/wiki/Elias_gamma_coding</a>
</li>
<li>Elias delta coding needs 2*n.bitsize.bitsize+n.bitsize-2 bits.<br>
<a href="https://en.wikipedia.org/wiki/Elias_delta_coding" class="external">https://en.wikipedia.org/wiki/Elias_delta_coding</a>
</li>
</ul>
</li>
<li>
<p>bitsize may be used to estimate the time or space cost of an algorithm.<br>
For example, the result size of integer multiplication, x*y, is x.bitsize + y.bitsize.<br>
The number of comparisons of binary search is sorted_array.length.bitsize, etc.<br>
This is because n.bitsize is an approximation of log2(abs(n)).<br>
So Math.log2 can be used for this purpose too.<br>
However bitsize may be preferable if floating point error is not desirable.</p>
</li>
</ul>
<p>There are several software which has similar feature.</p>
<ul>
<li>
<p>Python 3.1 has int.bit_length().<br>
<a href="http://docs.python.org/dev/library/stdtypes.html" class="external">http://docs.python.org/dev/library/stdtypes.html</a><br>
<a href="http://docs.python.org/3.1/whatsnew/3.1.html" class="external">http://docs.python.org/3.1/whatsnew/3.1.html</a><br>
<a href="http://bugs.python.org/issue3439" class="external">http://bugs.python.org/issue3439</a></p>
</li>
<li>
<p>Java java.math.BigInteger has bitLength() method.<br>
<a href="http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#bitLength()" class="external">http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#bitLength()</a></p>
</li>
<li>
<p>Mathematica has BitLength.<br>
<a href="http://reference.wolfram.com/mathematica/ref/BitLength.html" class="external">http://reference.wolfram.com/mathematica/ref/BitLength.html</a></p>
</li>
<li>
<p>GMP has mpz_sizeinbase(n, base).<br>
<a href="http://gmplib.org/manual/Miscellaneous-Integer-Functions.html" class="external">http://gmplib.org/manual/Miscellaneous-Integer-Functions.html</a></p>
</li>
<li>
<p>NetBSD 5.0 has ilog2().<br>
<a href="http://netbsd.gw.com/cgi-bin/man-cgi?ilog2++NetBSD-6.0" class="external">http://netbsd.gw.com/cgi-bin/man-cgi?ilog2++NetBSD-6.0</a></p>
</li>
</ul>
<p>I think there are two concerns for this issue.</p>
<ul>
<li>method name</li>
<li>behavior for zero and negative number</li>
</ul>
<p>I named the method as bitsize, mainly because<br>
there is Fixnum#size and Bignum#size.<br>
However I'm open for other names such as:</p>
<ul>
<li>bitlength</li>
<li>numbits</li>
<li>ilog2</li>
<li>maxbit<br>
Some names may suggest different behavior, though.</li>
</ul>
<p>The behavior for zero and negative number is not trivial.</p>
<p>Python adopts ceil(log2(abs(n)+1)) but<br>
Java and Mathematica adopts ceil(log2(n < 0 ? -n : n+1)).<br>
The difference is absolute number v.s. 2's complement number.</p>
<p>Some people may prefer ilog2, which name suggests ilog2(0) raise an error.</p>
<p>I choose ceil(log2(abs(n)+1)). (i.e. absolute number, same as Python).<br>
I think absolute number is easier to understand than 2's complement for many people.</p>
<p>I attached the implementation as bitsize.patch.<br>
The patch implements both Bignum#bitsize and Fixnum#bitsize in bignum.c.<br>
It is because Fixnum#bitsize uses bitsize macro and it is defined in bignum.c.<br>
Maybe, the macro should be moved to internal.h and the implementation of<br>
Fixnum#bitsize should be moved to numeric.c.</p>
<p>Any comments?</p>
Ruby master - Feature #8658 (Closed): Process.clock_gettime
https://bugs.ruby-lang.org/issues/8658
2013-07-19T21:32:52Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about adding a new method, Process.clock_gettime(clk_id) ?</p>
<p>Recently there were two feature request for measuring time.<br>
Feature <a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: Add Time#elapsed to return nanoseconds since creation (Open)" href="https://bugs.ruby-lang.org/issues/8640">#8640</a> <a href="https://bugs.ruby-lang.org/issues/8640" class="external">https://bugs.ruby-lang.org/issues/8640</a><br>
Feature <a class="issue tracker-2 status-7 priority-4 priority-default closed" title="Feature: introduce Time.current_timestamp (Feedback)" href="https://bugs.ruby-lang.org/issues/8096">#8096</a> <a href="https://bugs.ruby-lang.org/issues/8096" class="external">https://bugs.ruby-lang.org/issues/8096</a></p>
<p>It seems they are somewhat different.</p>
<p>clock_gettime() function defined by POSIX is a good<br>
candidate for providing as a method.<br>
I think it can supports the both request.</p>
<p>Also, it has less possible design choices than the requests<br>
because clock_gettime() is defined by POSIX.<br>
People familiar to POSIX can learn the method more easily.</p>
<p>I wrote a patch to implement Process.clock_gettime.<br>
This method can be used as follows.</p>
<p>% ./ruby -e 'p Process.clock_gettime(Process::CLOCK_MONOTONIC)'<br>
2701692957811563</p>
<p>Several considerations:</p>
<p>I implemented the method as a module function of Process.<br>
It is same as Process.times.<br>
I expect clock_gettime is used mainly for measuring<br>
time interval and wall clock time is not important.<br>
So I didn't use Time.</p>
<p>The method returns a number of nanoseconds as an integer.<br>
It is not so unexpected if user knows clock_gettime() in POSIX.</p>
<p>clock_gettime() returns it as struct timespec<br>
which contains two fields: tv_sec and tv_nsec.</p>
<p>Although tv_sec is time_t, Time is not appropriate because<br>
the origin (zero) can be other than the Epoch.<br>
Actually CLOCK_MONOTONIC means elapsed time since<br>
the system start-up time on Linux.</p>
<p>Also, I expect the result is subtracted in most case:<br>
t1 = Process.clock_gettime(...)<br>
...<br>
t2 = Process.clock_gettime(...)<br>
t = t2 - t1<br>
So the result should be easy to subtract.<br>
An array such as [sec, nsec] is difficult to subtract.</p>
<p>The result is an integer, not a float.<br>
IEEE 754 double is not enough to represent the result<br>
of clock_gettime(CLOCK_REALTIME).<br>
It contains 19 digits in decimal now but IEEE 754 double<br>
can represent only 15 digits.</p>
<p>On LP64 systems, Fixnum can represent 2<strong>62-1.<br>
So (2</strong>62-1)/(365.25<em>24</em>60<em>60</em>1e9)=146.1 years are representable<br>
without object allocation.</p>
<p>On ILP32 and LLP64 systems, Fixnum can represent 2<strong>30-1.<br>
So (2</strong>30-1)/1e9=1.07 seconds are representable<br>
without object allocation.<br>
This means Bignum allocations are mostly required except<br>
the origin is very recent.</p>
<p>clock_gettime() is defined by POSIX.<br>
Linux, NetBSD, FreeBSD, OpenBSD has it, at least.</p>
<p>If clock_gettime() is not available,<br>
an emulation layer for CLOCK_REALTIME is implementable<br>
using gettimeofday().<br>
(not implemented yet, though.)</p>
<p>Any comments?</p>
Ruby master - Bug #8624 (Closed): illegal hardware instruction in csv test
https://bugs.ruby-lang.org/issues/8624
2013-07-11T23:51:11Z
akr (Akira Tanaka)
akr@fsij.org
<p>以下のように illegal hardware instruction になることがあるようです。</p>
<p>% ./ruby -v<br>
ruby 2.1.0dev (2013-07-11 trunk 41923) [x86_64-linux]<br>
% ./ruby ../../ruby/test/runner.rb ../../ruby/test/csv<br>
Run options:</p>
<a name="Running-tests"></a>
<h1 >Running tests:<a href="#Running-tests" class="wiki-anchor">¶</a></h1>
<p>[ 36/302] TestCSV::Encodings#test_can_write_csv_in_any_encoding<br>
zsh: illegal hardware instruction ./ruby ../../ruby/test/runner.rb ../../ruby/test/csv</p>
<p>コンパイラは clang です。</p>
<p>% clang -v<br>
clang version 3.3 (tags/RELEASE_33/final)<br>
Target: x86_64-unknown-linux-gnu<br>
Thread model: posix</p>
<p>valgrind では以下のように問題が検出されます。</p>
<p>==21333== Memcheck, a memory error detector<br>
==21333== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.<br>
==21333== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info<br>
==21333== Command: ./ruby ../../ruby/test/runner.rb ../../ruby/test/csv<br>
==21333== Parent PID: 16519<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9135EF3: utf16be_mbc_to_code (utf_16be.c:112)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x3BDC27: rb_enc_ascget (encoding.c:958)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333== by 0x389A4D: invoke_block_from_c (vm.c:646)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x2A9DC7: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333== by 0x389A4D: invoke_block_from_c (vm.c:646)<br>
==21333== by 0x38DF29: vm_yield (vm.c:677)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9B56BC3: utf16le_mbc_enc_len (utf_16le.c:64)<br>
==21333== by 0x3BDA52: rb_enc_precise_mbclen (encoding.c:935)<br>
==21333== by 0x3BDBD2: rb_enc_ascget (encoding.c:954)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9B56D53: utf16le_mbc_to_code (utf_16le.c:102)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9B56E14: utf16le_mbc_to_code (utf_16le.c:107)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9B56E37: utf16le_mbc_to_code (utf_16le.c:107)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9D58C4D: utf32be_mbc_to_code (utf_32be.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9D58C6A: utf32be_mbc_to_code (utf_32be.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9D58C8E: utf32be_mbc_to_code (utf_32be.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9D58CAB: utf32be_mbc_to_code (utf_32be.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9D58CCF: utf32be_mbc_to_code (utf_32be.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9F5AC2A: utf32le_mbc_to_code (utf_32le.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9F5AC4E: utf32le_mbc_to_code (utf_32le.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9F5AC6B: utf32le_mbc_to_code (utf_32le.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9F5AC8F: utf32le_mbc_to_code (utf_32le.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9F5ACAC: utf32le_mbc_to_code (utf_32le.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== Conditional jump or move depends on uninitialised value(s)<br>
==21333== at 0x9F5ACCF: utf32le_mbc_to_code (utf_32le.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
vex amd64->IR: unhandled instruction bytes: 0xF 0xB 0x48 0x8B 0x45 0xF8 0xF 0xB6<br>
==21333== valgrind: Unrecognised instruction at address 0x9f5acb2.<br>
==21333== at 0x9F5ACB2: utf32le_mbc_to_code (utf_32le.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333== by 0x389A4D: invoke_block_from_c (vm.c:646)<br>
==21333== by 0x38DF29: vm_yield (vm.c:677)<br>
==21333== by 0x37FCA2: rb_yield_0 (vm_eval.c:937)<br>
==21333== by 0x37FC64: rb_yield (vm_eval.c:947)<br>
==21333== by 0x3E6C7D: rb_ary_collect (array.c:2553)<br>
==21333== by 0x3907F2: call_cfunc_0 (vm_insnhelper.c:1354)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x371FFA: vm_exec_core (insns.def:1002)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333== by 0x38EF2B: vm_call0_body (vm_eval.c:170)<br>
==21333== by 0x37E5C2: vm_call0 (vm_eval.c:49)<br>
==21333== by 0x38E29D: rb_call0 (vm_eval.c:324)<br>
==21333== by 0x37F597: rb_call (vm_eval.c:585)<br>
==21333== by 0x37C600: rb_funcallv (vm_eval.c:807)<br>
==21333== by 0x131296: rb_obj_call_init (eval.c:1286)<br>
==21333== by 0x1B666F: rb_class_new_instance (object.c:1817)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333== by 0x389A4D: invoke_block_from_c (vm.c:646)<br>
==21333== by 0x38DF29: vm_yield (vm.c:677)<br>
==21333== by 0x37FCA2: rb_yield_0 (vm_eval.c:937)<br>
==21333== by 0x37FC64: rb_yield (vm_eval.c:947)<br>
==21333== by 0x3CE12A: rb_ary_each (array.c:1700)<br>
==21333== by 0x3907F2: call_cfunc_0 (vm_insnhelper.c:1354)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x371FFA: vm_exec_core (insns.def:1002)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333== by 0x389A4D: invoke_block_from_c (vm.c:646)<br>
==21333== by 0x38DF29: vm_yield (vm.c:677)<br>
==21333== by 0x37FCA2: rb_yield_0 (vm_eval.c:937)<br>
==21333== by 0x37FC64: rb_yield (vm_eval.c:947)<br>
==21333== by 0x3E6C7D: rb_ary_collect (array.c:2553)<br>
==21333== by 0x3907F2: call_cfunc_0 (vm_insnhelper.c:1354)<br>
==21333== Your program just tried to execute an instruction that Valgrind<br>
==21333== did not recognise. There are two possible reasons for this.<br>
==21333== 1. Your program has a bug and erroneously jumped to a non-code<br>
==21333== location. If you are running Memcheck and you just saw a<br>
==21333== warning about a bad jump, it's probably your program's fault.<br>
==21333== 2. The instruction is legitimate but Valgrind doesn't handle it,<br>
==21333== i.e. it's Valgrind's fault. If you think this is the case or<br>
==21333== you are not sure, please let us know and we'll try to fix it.<br>
==21333== Either way, Valgrind will now raise a SIGILL signal which will<br>
==21333== probably kill your program.<br>
==21333==<br>
==21333== Process terminating with default action of signal 4 (SIGILL)<br>
==21333== Illegal opcode at address 0x9F5ACB2<br>
==21333== at 0x9F5ACB2: utf32le_mbc_to_code (utf_32le.c:62)<br>
==21333== by 0x3BDC1C: rb_enc_ascget (encoding.c:957)<br>
==21333== by 0x2A9DC1: str_fill_term (string.c:1508)<br>
==21333== by 0x2AA226: rb_str_fill_terminator (string.c:1549)<br>
==21333== by 0x32A661: str_encode_associate (transcode.c:2763)<br>
==21333== by 0x3234CA: encoded_dup (transcode.c:2898)<br>
==21333== by 0x324FF0: str_encode (transcode.c:2873)<br>
==21333== by 0x3907C9: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==21333== by 0x3965D3: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==21333== by 0x394DD4: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==21333== by 0x37216C: vm_exec_core (insns.def:1017)<br>
==21333== by 0x383A6F: vm_exec (vm.c:1198)<br>
==21333==<br>
==21333== HEAP SUMMARY:<br>
==21333== in use at exit: 13,054,473 bytes in 64,423 blocks<br>
==21333== total heap usage: 332,942 allocs, 268,519 frees, 132,063,934 bytes allocated<br>
==21333==<br>
==21333== LEAK SUMMARY:<br>
==21333== definitely lost: 264 bytes in 1 blocks<br>
==21333== indirectly lost: 1,057 bytes in 32 blocks<br>
==21333== possibly lost: 272 bytes in 1 blocks<br>
==21333== still reachable: 13,052,880 bytes in 64,389 blocks<br>
==21333== suppressed: 0 bytes in 0 blocks<br>
==21333== Rerun with --leak-check=full to see details of leaked memory<br>
==21333==<br>
==21333== For counts of detected and suppressed errors, rerun with: -v<br>
==21333== Use --track-origins=yes to see where uninitialised values come from<br>
==21333== ERROR SUMMARY: 5292 errors from 18 contexts (suppressed: 4 from 4)</p>
<p>現時点では、gcc で再現できていないのですが、<br>
gcc でも、valgrind ではそれなりに問題が検出されます。</p>
<p>dew(23:18:29)% valgrind ./ruby test/runner.rb test/csv<br>
==16910== Memcheck, a memory error detector<br>
==16910== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.<br>
==16910== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info<br>
==16910== Command: ./ruby test/runner.rb test/csv<br>
==16910==<br>
Run options:</p>
<a name="Running-tests-2"></a>
<h1 >Running tests:<a href="#Running-tests-2" class="wiki-anchor">¶</a></h1>
<p>[ 33/302] TestCSV::Encodings#test_auto_line_ending_detection==16910== Conditional jump or move depends on uninitialised value(s)<br>
==16910== at 0x2887E7: rb_enc_ascget (encoding.c:958)<br>
==16910== by 0x1FC905: str_fill_term (string.c:1508)<br>
==16910== by 0x1FCBD5: rb_str_fill_terminator (string.c:1549)<br>
==16910== by 0x22979B: str_encode_associate (transcode.c:2763)<br>
==16910== by 0x229ADA: encoded_dup (transcode.c:2898)<br>
==16910== by 0x2299C5: str_encode (transcode.c:2873)<br>
==16910== by 0x258616: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==16910== by 0x259206: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==16910== by 0x259340: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==16910== by 0x25DFE8: vm_exec_core (insns.def:1017)<br>
==16910== by 0x26D3E0: vm_exec (vm.c:1198)<br>
==16910== by 0x26BE91: invoke_block_from_c (vm.c:646)<br>
==16910==<br>
==16910== Conditional jump or move depends on uninitialised value(s)<br>
==16910== at 0x1FC908: str_fill_term (string.c:1508)<br>
==16910== by 0x1FCBD5: rb_str_fill_terminator (string.c:1549)<br>
==16910== by 0x22979B: str_encode_associate (transcode.c:2763)<br>
==16910== by 0x229ADA: encoded_dup (transcode.c:2898)<br>
==16910== by 0x2299C5: str_encode (transcode.c:2873)<br>
==16910== by 0x258616: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==16910== by 0x259206: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==16910== by 0x259340: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==16910== by 0x25DFE8: vm_exec_core (insns.def:1017)<br>
==16910== by 0x26D3E0: vm_exec (vm.c:1198)<br>
==16910== by 0x26BE91: invoke_block_from_c (vm.c:646)<br>
==16910== by 0x26BFD6: vm_yield (vm.c:677)<br>
==16910==<br>
[ 36/302] TestCSV::Encodings#test_can_write_csv_in_any_encoding==16910== Conditional jump or move depends on uninitialised value(s)<br>
==16910== at 0x9164A58: utf16le_mbc_enc_len (utf_16le.c:64)<br>
==16910== by 0x2886E9: rb_enc_precise_mbclen (encoding.c:935)<br>
==16910== by 0x2887B3: rb_enc_ascget (encoding.c:954)<br>
==16910== by 0x1FC905: str_fill_term (string.c:1508)<br>
==16910== by 0x1FCBD5: rb_str_fill_terminator (string.c:1549)<br>
==16910== by 0x22979B: str_encode_associate (transcode.c:2763)<br>
==16910== by 0x229ADA: encoded_dup (transcode.c:2898)<br>
==16910== by 0x2299C5: str_encode (transcode.c:2873)<br>
==16910== by 0x258616: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==16910== by 0x259206: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==16910== by 0x259340: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==16910== by 0x25DFE8: vm_exec_core (insns.def:1017)<br>
==16910==<br>
==16910== Conditional jump or move depends on uninitialised value(s)<br>
==16910== at 0x9164B27: utf16le_mbc_to_code (utf_16le.c:102)<br>
==16910== by 0x2887DF: rb_enc_ascget (encoding.c:957)<br>
==16910== by 0x1FC905: str_fill_term (string.c:1508)<br>
==16910== by 0x1FCBD5: rb_str_fill_terminator (string.c:1549)<br>
==16910== by 0x22979B: str_encode_associate (transcode.c:2763)<br>
==16910== by 0x229ADA: encoded_dup (transcode.c:2898)<br>
==16910== by 0x2299C5: str_encode (transcode.c:2873)<br>
==16910== by 0x258616: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==16910== by 0x259206: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==16910== by 0x259340: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==16910== by 0x25DFE8: vm_exec_core (insns.def:1017)<br>
==16910== by 0x26D3E0: vm_exec (vm.c:1198)<br>
==16910==<br>
[ 54/302] TestCSV::Encodings::DifferentOFS#test_can_write_csv_in_any_encoding==16910== Conditional jump or move depends on uninitialised value(s)<br>
==16910== at 0x9164A6F: utf16le_mbc_enc_len (utf_16le.c:67)<br>
==16910== by 0x2886E9: rb_enc_precise_mbclen (encoding.c:935)<br>
==16910== by 0x2887B3: rb_enc_ascget (encoding.c:954)<br>
==16910== by 0x1FC905: str_fill_term (string.c:1508)<br>
==16910== by 0x1FCBD5: rb_str_fill_terminator (string.c:1549)<br>
==16910== by 0x22979B: str_encode_associate (transcode.c:2763)<br>
==16910== by 0x229ADA: encoded_dup (transcode.c:2898)<br>
==16910== by 0x2299C5: str_encode (transcode.c:2873)<br>
==16910== by 0x258616: call_cfunc_m1 (vm_insnhelper.c:1348)<br>
==16910== by 0x259206: vm_call_cfunc_with_frame (vm_insnhelper.c:1492)<br>
==16910== by 0x259340: vm_call_cfunc (vm_insnhelper.c:1582)<br>
==16910== by 0x25DFE8: vm_exec_core (insns.def:1017)<br>
==16910==<br>
[150/302] TestCSV::Interface#test_enumerators_are_supported==16910== Warning: client switching stacks? SP change: 0x7feffbfd8 --> 0x40b5fe8<br>
==16910== to suppress, use: --max-stackframe=34275090416 or greater<br>
==16910== Warning: client switching stacks? SP change: 0x40b3f88 --> 0x7feffbfe0<br>
==16910== to suppress, use: --max-stackframe=34275098712 or greater<br>
[171/302] TestCSV::Interface::DifferentOFS#test_enumerators_are_supported==16910== Warning: client switching stacks? SP change: 0x7feffbea8 --> 0x4135fe8<br>
==16910== to suppress, use: --max-stackframe=34274565824 or greater<br>
==16910== further instances of this message will not be shown.<br>
Finished tests in 55.632943s, 5.4284 tests/s, 141.5348 assertions/s.<br>
302 tests, 7874 assertions, 0 failures, 0 errors, 0 skips</p>
<p>ruby -v: ruby 2.1.0dev (2013-07-11 trunk 41923) [x86_64-linux]<br>
==16910==<br>
==16910== HEAP SUMMARY:<br>
==16910== in use at exit: 5,802,437 bytes in 49,345 blocks<br>
==16910== total heap usage: 846,278 allocs, 796,933 frees, 401,745,300 bytes allocated<br>
==16910==<br>
==16910== LEAK SUMMARY:<br>
==16910== definitely lost: 1,444,516 bytes in 9,335 blocks<br>
==16910== indirectly lost: 2,525,593 bytes in 26,492 blocks<br>
==16910== possibly lost: 0 bytes in 0 blocks<br>
==16910== still reachable: 1,832,328 bytes in 13,518 blocks<br>
==16910== suppressed: 0 bytes in 0 blocks<br>
==16910== Rerun with --leak-check=full to see details of leaked memory<br>
==16910==<br>
==16910== For counts of detected and suppressed errors, rerun with: -v<br>
==16910== Use --track-origins=yes to see where uninitialised values come from<br>
==16910== ERROR SUMMARY: 4703 errors from 5 contexts (suppressed: 4 from 4)</p>
Ruby master - Feature #8553 (Closed): Bignum#size (and Fixnum#size)
https://bugs.ruby-lang.org/issues/8553
2013-06-21T10:37:41Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about changing Bignum#size to a well defined behavior?</p>
<p>Recently I changed Bignum implementation to use 128 bit integer type<br>
if the type is available. (r41379)</p>
<p>After that, rubyspec fails with Bignum#size as follows:</p>
<p>| 1)<br>
| Bignum#size returns the number of bytes in the machine representation in multiples of four FAILED<br>
| Expected 16<br>
| to equal 12<br>
|<br>
<a href="http://a.mrkn.jp/~mrkn/chkbuild/mavericks/ruby-trunk-m64-o3/log/20130620T231101Z.log.html.gz" class="external">http://a.mrkn.jp/~mrkn/chkbuild/mavericks/ruby-trunk-m64-o3/log/20130620T231101Z.log.html.gz</a></p>
<p>I think this failure itself is not a problem.<br>
This is just an over-specification of rubyspec.<br>
Actually the test also fails before r41379 on platforms which doesn't support 64 bit integer type.</p>
<p>It is because the Bignum#size returns multiples of sizeof(BDIGIT), not 4.<br>
sizeof(BDIGIT) can be 2 or 4 before r41379 or 8 since r41379.<br>
The test only considers platforms sizeof(BDIGIT) is 4.</p>
<p>However this test failure reminds me that I always felt that current<br>
Bignum#size (and Fixnum#size) behavior is not useful.</p>
<p>I guess almost all people doesn't interest sizeof(BDIGIT).</p>
<p>So I'd like to change Bignum#size to return number of bytes.<br>
It means val.size returns n if val is a Bignum and<br>
256<strong>n <= abs(val) < 256</strong>(n+1).</p>
<p>One exception is that val.size returns 0 if val is Bignum zero.</p>
<p>My considerations:</p>
<ul>
<li>
<p>The above Bignum#size behavior is based on absolute values, abs(n).<br>
This is compatible to current behavior and easy to understand.<br>
There are other possibilities: exception on negative values and<br>
definition on 2's complement value.<br>
I think exception is too different from current behavior.<br>
A definition based on 2's complement is difficult to treat sign bits.</p>
</li>
<li>
<p>Bignum#size returns number of bytes, not bits.<br>
I think some method which returns number of bits may be useful but<br>
it is different from current Bignum#size.<br>
It is better to name another one, such as bitsize and it is not this issue.</p>
</li>
<li>
<p>Fixnum#size is difficult to change.<br>
Currently Fixnum#size returns sizeof(long).<br>
Some programs, mspec for example, uses it to obtain a word size.<br>
So it is difficult to change because compatibility.<br>
However I doubt such use is correct.<br>
If a program want to detect 64bit platform, Fixnum#size should not be used<br>
because it returns 4 on LLP64 platforms (64bit Windows).<br>
It is better to use [0].pack("l!").size for sizof(long) and<br>
[nil].pack("p").size for sizeof(char *).</p>
<p>However some people may hope Fixnum and Bignum consistent.<br>
For that purpose, Fixnum#size should also be changed same way.<br>
It will breaks some applications, though.</p>
</li>
</ul>
<p>Any opinion?</p>
Ruby master - Feature #8509 (Closed): Use 128 bit integer type in Bignum
https://bugs.ruby-lang.org/issues/8509
2013-06-10T21:59:47Z
akr (Akira Tanaka)
akr@fsij.org
<p>How about Bignum uses 128 bit integer type?</p>
<p>I found that recent gcc (since gcc 4.6) supports 128 bit integer type,<br>
__int128, on some platforms.<br>
<a href="http://gcc.gnu.org/gcc-4.6/changes.html" class="external">http://gcc.gnu.org/gcc-4.6/changes.html</a></p>
<p>It seems gcc supports it on x86_64 and not on i386.</p>
<p>Currently Ruby implements Bignum on top of 32 bit integer type (BDIGIT)<br>
and 64 bit integer type (BDIGIT_DBL).<br>
(Ruby uses two integer types for multiplication.<br>
BDIGIT_DBL can represent any value of BDIGIT * BDIGIT.)</p>
<p>Historically, Ruby supported platforms without 64 bit integer type.<br>
Ruby used 16 bit integer type (BDIGIT) and 32 bit integer type (BDIGIT_DBL)<br>
on such platform.<br>
However I guess no one use such platforms today.</p>
<p>So with gcc 4.6 or later, we can use 64 bit integer type (BDIGIT) and<br>
128 bit integer type (BDIGIT_DBL).</p>
<p>This may gain performance.</p>
<p>I implemented it. (int128-bignum.patch)</p>
<p>Simple benchmark on Debian GNU/Linux 7.0 (wheezy) x86_64:</p>
<p>trunk% time ./ruby -e 'v = 3<strong>1000; u = 1; 1000.times { u *= v }'<br>
./ruby -e 'v = 3</strong>1000; u = 1; 1000.times { u *= v }' 1.64s user 0.00s system 99% cpu 1.655 total<br>
128bit% time ./ruby -e 'v = 3<strong>1000; u = 1; 1000.times { u *= v }'<br>
./ruby -e 'v = 3</strong>1000; u = 1; 1000.times { u *= v }' 1.21s user 0.01s system 99% cpu 1.222 total</p>
<p>I think larger integer type reduces control overhead and compiler will have more opportunity for optimization.</p>
<p>However the patch has API incompatibility.</p>
<p>BDIGIT and BDIGIT_DBL and related definitions are defined in a public headers,<br>
ruby/defines.h.</p>
<p>So third party extensions may be broken with the change.</p>
<p>Note that BDIGIT_DBL is a macro (not typedef name), compiler used for third party extension<br>
don't need to support __int128 unless the extension actually uses BDIGIT_DBL.</p>
<p>If a program try to extract information from a Bignum and assumes BDIGIT is 32 bit integer,<br>
the result may be invalid.<br>
In this situation rb_big_pack/rb_big_unpack or rb_integer_pack/rb_integer_unpack <a href="/issues/6065">[ruby-core:55408]</a> may help.</p>
<p>However BDIGIT size change itself may cause problems.</p>
<p>One example I patched is about rb_big_pow.<br>
int128-bignum.patch contains following modification for rb_big_pow.</p>
<ul>
<li>
<pre><code> const long BIGLEN_LIMIT = BITSPERDIG*1024*1024;
</code></pre>
</li>
</ul>
<ul>
<li>
<pre><code> const long BIGLEN_LIMIT = 32*1024*1024;
</code></pre>
</li>
</ul>
<p>BIGLEN_LIMIT controls the rb_big_pow generates a Bignum or a Float.<br>
If it is not modified, a test causes memory allocation failure.</p>
<p>Another problem is bigdecimal tests.<br>
bigdecimal tests failed with int128-bignum.patch as follows.</p>
<ol>
<li>
<p>Failure:<br>
TestBigDecimal#test_power_of_three [/home/akr/tst1/ruby/test/bigdecimal/test_bigdecimal.rb:1006]:<br>
<(1/81)> expected but was<br>
<#<BigDecimal:2b72eab381d8,'0.1234567901 2345679012 3456790123 4567901234 5679012345 6790123456 7901234567 9012345679 0123456790 1234567901 2345679012 3456790123 4567901234 57E-1',133(133)>>.</p>
</li>
<li>
<p>Failure:<br>
TestBigDecimal#test_power_with_prec [/home/akr/tst1/ruby/test/bigdecimal/test_bigdecimal.rb:1110]:<br>
<#<BigDecimal:2b72e939bf20,'0.2245915771 8361045473E2',38(57)>> expected but was<br>
<#<BigDecimal:2b72e93b57b8,'0.2061448331 0990090312E2',38(114)>>.</p>
</li>
<li>
<p>Failure:<br>
TestBigDecimal#test_power_without_prec [/home/akr/tst1/ruby/test/bigdecimal/test_bigdecimal.rb:1103]:<br>
<#<BigDecimal:2b72e93b7ab8,'0.2245915771 8361045473 4271522045 4373502758 9315133996 7843873233 068E2',95(95)>> expected but was<br>
<#<BigDecimal:2b72eaa0d5d8,'0.2061448331 0990090311 8271522045 4373474226 6494929516 0232192991 9587472564 291161E2',95(171)>>.</p>
</li>
<li>
<p>Failure:<br>
TestBigDecimal#test_sqrt_bigdecimal [/home/akr/tst1/ruby/test/bigdecimal/test_bigdecimal.rb:796]:<br>
<1267650600228229401496703205376> expected but was<br>
<#<BigDecimal:2b72eaaa25c0,'0.1267650600 2282294014 9670320537 5999999999 9999999999 9999999999 9999999995 234375E31',95(114)>>.</p>
</li>
<li>
<p>Failure:<br>
TestBigMath#test_atan [/home/akr/tst1/ruby/test/bigdecimal/test_bigmath.rb:60]:<br>
<a href="/issues/3267">[ruby-dev:41257]</a>.<br>
<#<BigDecimal:2b72eac54cd8,'0.8238407534 1863629176 9355073102 5140889593 4562402795 2954058347 0231225394 89E0',76(95)>> expected but was<br>
<#<BigDecimal:2b72eabf2ec0,'0.8238407534 1863629176 9355073102 5140889593 4562402795 2954062036 3719372813 99E0',76(228)>>.</p>
</li>
</ol>
<p>I guess bigdecimal determines precision depend on sizeof(BDIGIT).<br>
I think it is not a good way to use BDIGIT.</p>
<p>How do you think, mrkn?</p>
<p>Also, we cannot define PRI_BDIGIT_DBL_PREFIX because<br>
there is no printf directive for __int128.</p>
<p>Anyway, is Bignum with __int128 worth to support?<br>
Any opinion?</p>
Ruby master - Bug #8443 (Closed): -Lprefix/lib
https://bugs.ruby-lang.org/issues/8443
2013-05-24T10:05:56Z
akr (Akira Tanaka)
akr@fsij.org
<p>最近試しているクロスコンパイルな CI で、<br>
思い立って DESTDIR を使って気がついたんですが、<br>
configure に --prefix=/usr と指定すると、<br>
/usr にあるライブラリを使ってしまうことがあるようです。</p>
<p>クロスコンパイルなので、ビルド環境の /usr は使ってほしくないんですが、<br>
どうでしょうか。</p>
<p>実際に問題が出た環境は buildroot で作った i386 環境と、<br>
Android (x86) の環境です。<br>
ビルド環境 (x86_64) と中途半端に似ていると問題が起きやすいようです。</p>
<p>まず i386 は<br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-i386/log/20130522T080000Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-i386/log/20130522T080000Z.diff.html.gz</a><br>
というように、curses のところで -ltermcap が見つからないというエラーになっています。</p>
<p>compiling curses.c<br>
linking shared-object curses.so<br>
/extdisk/chkbuild/buildroot/i386/buildroot-2013.02/output/host/usr/lib/gcc/i586-buildroot-linux-uclibc/4.6.3/../../../../i586-buildroot-linux-uclibc/bin/ld:<br>
cannot find -ltermcap</p>
<p>ext/curses/mkmf.log をみると以下のように -ltermcap は見つかっています。<br>
(改行を入れてあります)</p>
<p>have_library: checking for tgetent() in -ltermcap... -------------------- yes</p>
<p>"i586-buildroot-linux-uclibc-gcc -o conftest<br>
-I../../.ext/include/i586-linux-uclibc -I../.././include<br>
-I../.././ext/curses<br>
-O3 -fno-fast-math<br>
-ggdb3<br>
-Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long<br>
-Wno-missing-field-initializers -Wunused-variable -Wpointer-arith<br>
-Wwrite-strings -Wdeclaration-after-statement<br>
-Wimplicit-function-declaration<br>
conftest.c<br>
-L. -L../.. -L.<br>
-rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/usr/lib -L/usr/lib<br>
-lruby-static -ltermcap -lpthread -ldl -lcrypt -lm -lc"<br>
conftest.c: In function 't':<br>
conftest.c:13:57: error: 'tgetent' undeclared (first use in this function)<br>
conftest.c:13:57: note: each undeclared identifier is reported only<br>
once for each function it appears in<br>
conftest.c:13:32: warning: variable 'p' set but not used<br>
[-Wunused-but-set-variable]<br>
checked program was:<br>
/* begin */<br>
1: #include "ruby.h"<br>
2:<br>
3: /<em>top</em>/<br>
4: extern int t(void);<br>
5: int main(int argc, char *<em>argv)<br>
6: {<br>
7: if (argc > 1000000) {<br>
8: printf("%p", &t);<br>
9: }<br>
10:<br>
11: return 0;<br>
12: }<br>
13: int t(void) { void ((<em>volatile p)()); p = (void ((</em>)()))tgetent; return 0; }<br>
/</em> end */</p>
<p>それに対し、make -n で実際のコマンドを調べて実行すると、リンクできません。</p>
<p>% i586-buildroot-linux-uclibc-gcc -shared <br>
-o ../../.ext/i586-linux-uclibc/curses.so curses.o <br>
-L. -L../.. -L. -rdynamic -Wl,-export-dynamic <br>
-lncurses -ltermcap -lpthread -ldl -lcrypt -lm -lc<br>
/extdisk/chkbuild/buildroot/i386/buildroot-2013.02/output/host/usr/lib/gcc/i586-buildroot-linux-uclibc/4.6.3/../../../../i586-buildroot-linux-uclibc/bin/ld:<br>
cannot find -ltermcap<br>
collect2: ld returned 1 exit status</p>
<p>比較すると、mkmf.log には -L/usr/lib があるので<br>
試しに足してみるとリンクできますが、それはおそらく間違いでしょう。</p>
<p>また、Android (x86) では、<br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-x86android/log/20130522T093235Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-x86android/log/20130522T093235Z.diff.html.gz</a><br>
というように ruby のリンクのところで失敗しています。</p>
<p>linking ruby<br>
/extdisk/chkbuild/android/x86/bin/../sysroot/usr/lib/crtbegin_dynamic.o(.text+0x19):<br>
error: undefined reference to '__libc_init'<br>
eval_error.c:8: error: undefined reference to '__stack_chk_guard'<br>
file.c:1023: error: undefined reference to '__stack_chk_guard'<br>
file.c:1066: error: undefined reference to '__stack_chk_guard'<br>
以下略</p>
<p>make -n で調べると失敗するコマンドラインは以下のようになっています。</p>
<p>i686-linux-android-gcc -O3 -fno-fast-math -ggdb3 <br>
-Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long <br>
-Wno-missing-field-initializers -Wunused-variable -Werror=pointer-arith <br>
-Werror=write-strings -Werror=declaration-after-statement <br>
-Werror=implicit-function-declaration <br>
-ansi -std=iso9899:199409 <br>
-L. -fstack-protector -rdynamic -Wl,-export-dynamic <br>
-fstack-protector -pie <br>
main.o <br>
-Wl,-R -Wl,/usr/lib -L/usr/lib <br>
-lruby-static -ldl -lm <br>
-o ruby</p>
<p>この場合、-L/usr/lib を削るとリンクに成功します。</p>
<h2>-Lprefix/lib というのは、少なくともクロスコンパイルでは間違いだと思うんですが、<br>
どうですかねぇ。</h2>
<p>[田中 哲][たなか あきら][Tanaka Akira]</p>
Ruby master - Bug #8401 (Closed): BigDecimal.new("2").power(1e20) is zero.
https://bugs.ruby-lang.org/issues/8401
2013-05-14T00:14:44Z
akr (Akira Tanaka)
akr@fsij.org
<p>ふと見つけたのですが、BigDecimal.new("2").power(1e20) が 0.0 になります。</p>
<p>% ./ruby -v -rbigdecimal -e 'puts BigDecimal.new("2").power(1e20)'<br>
ruby 2.1.0dev (2013-05-13 trunk 40697) [x86_64-linux]<br>
0.0</p>
<p>以下のように、power の引数が<br>
1e1 や 1e2 なら値が出てきて、<br>
1e10 ならエラーになるのに、<br>
1e20 になるとまたエラーじゃなくなって 0.0 になっちゃうのは<br>
変ではないでしょうか。</p>
<p>% ./ruby -rbigdecimal -e 'puts BigDecimal.new("2").power(1e1)'<br>
0.1024E4<br>
% ./ruby -rbigdecimal -e 'puts BigDecimal.new("2").power(1e2)'<br>
0.1267650600228229401496703205376E31<br>
% ./ruby -rbigdecimal -e 'puts BigDecimal.new("2").power(1e10)'<br>
-e:1:in <code>power': integer 10000000000 too big to convert to </code>int' (RangeError)<br>
from -e:1:in `'</p>
Ruby master - Bug #8397 (Closed): TestBignum#test_interrupt_during_bigdivrem failure
https://bugs.ruby-lang.org/issues/8397
2013-05-12T23:53:44Z
akr (Akira Tanaka)
akr@fsij.org
<p>稀に、TestBignum#test_interrupt_during_bigdivrem が失敗することがあるようです。</p>
<p><a href="http://c5664.rubyci.org/~chkbuild/ruby-trunk/log/20130509T193301Z.log.html.gz" class="external">http://c5664.rubyci.org/~chkbuild/ruby-trunk/log/20130509T193301Z.log.html.gz</a><br>
で見つけました。</p>
<ol start="8">
<li>Failure:<br>
test_interrupt_during_bigdivrem(TestBignum) [/usr/home/chkbuild/build/20130129T130201Z/ruby/test/ruby/test_bignum.rb:604]:<br>
<2847123494(中略)4504476080> expected but was<br>
<2847123494(中略)4068253180>.</li>
</ol>
<p>探してみると、<br>
<a href="http://fbsd.rubyci.org/~chkbuild/ruby-trunk/log/20130129T130201Z.log.html.gz" class="external">http://fbsd.rubyci.org/~chkbuild/ruby-trunk/log/20130129T130201Z.log.html.gz</a><br>
にもありました。</p>
<ol start="9">
<li>Failure:<br>
TestBignum#test_interrupt_during_bigdivrem [/home/chkbuild/build/20130509T193301Z/ruby/test/ruby/test_bignum.rb:601]:<br>
<2847123494(中略)4504476080> expected but was<br>
<2847123494(中略)5740373054>.</li>
</ol>
Ruby master - Bug #8379 (Closed): json dependency problem
https://bugs.ruby-lang.org/issues/8379
2013-05-07T23:39:12Z
akr (Akira Tanaka)
akr@fsij.org
<p>json の Makefile の依存関係ですが、generator.o と parser.o の依存先の<br>
ヘッダファイルが足りないようです。</p>
<p>過不足を調べてくれるスクリプト (update-deps) によれば、以下が足りないようです。</p>
<p>ext/json/generator/generator.o は以下が依存先として記述されていない:<br>
include/ruby.h<br>
include/ruby/ruby.h<br>
.ext/include/i686-linux/ruby/config.h<br>
include/ruby/defines.h<br>
include/ruby/missing.h<br>
include/ruby/intern.h<br>
include/ruby/st.h<br>
include/ruby/subst.h<br>
include/ruby/encoding.h<br>
include/ruby/oniguruma.h<br>
include/ruby/re.h<br>
include/ruby/regex.h</p>
<p>ext/json/parser/parser.o は以下が依存先として記述されていない:<br>
ext/json/parser/parser.rl<br>
include/ruby.h<br>
include/ruby/ruby.h<br>
.ext/include/i686-linux/ruby/config.h<br>
include/ruby/defines.h<br>
include/ruby/missing.h<br>
include/ruby/intern.h<br>
include/ruby/st.h<br>
include/ruby/subst.h<br>
include/ruby/encoding.h<br>
include/ruby/oniguruma.h</p>
<p><a href="http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20130507T121000Z.log.html.gz#update-deps" class="external">http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20130507T121000Z.log.html.gz#update-deps</a></p>
<p>たとえば、generator.o について試すと、<br>
以下のように ruby.h を更新した (ゴミをつけくわえた) 後に<br>
make しても 再コンパイルされません。</p>
<p>% cd ext/json/generator<br>
% make<br>
installing default generator libraries<br>
% ls -l ../../../include/ruby.h generator.o<br>
-rw-r--r-- 1 akr akr 868 May 7 23:31 ../../../include/ruby.h<br>
-rw-r--r-- 1 akr akr 214264 May 7 23:31 generator.o<br>
% echo foo >> ../../../include/ruby.h<br>
% make<br>
installing default generator libraries</p>
<p>そして、generator.o を消して make すると再コンパイルされ、<br>
(ruby.h にゴミがついているので) エラーになります。</p>
<p>% rm generator.o<br>
% make<br>
compiling generator.c<br>
In file included from ../../.././include/ruby/encoding.h:23,<br>
from ../fbuffer/fbuffer.h:29,<br>
from generator.c:1:<br>
../../.././include/ruby/oniguruma.h:101: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘<strong>attribute</strong>’ before ‘#pragma’<br>
In file included from ../../.././include/ruby/re.h:25,<br>
from generator.h:11,<br>
from generator.c:2:<br>
../../.././include/ruby/regex.h:27: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘<strong>attribute</strong>’ before ‘#pragma’</p>
<p>つまり、generator.o の生成のためには ruby.h が必要ですが、<br>
Makefile にその依存関係が記述されていないため、<br>
ruby.h が更新されるだけでは make で generator.o が更新されないという<br>
問題があります。</p>
Ruby master - Bug #8378 (Closed): json/generator/generator.c: warning: array subscript has type '...
https://bugs.ruby-lang.org/issues/8378
2013-05-07T22:26:28Z
akr (Akira Tanaka)
akr@fsij.org
<p>ふと、cygwin を target とする cross-compile をしてみたところ、<br>
以下の警告を見つけました。<br>
(たぶん cross でなくても警告されると思います)</p>
<p>make[2]: Entering directory `/extdisk/chkbuild/chkbuild/tmp/build/20130507T115727Z/ruby/ext/json/generator'<br>
compiling generator.c<br>
generator.c: In function 'isArrayOrObject':<br>
generator.c:897:5: warning: array subscript has type 'char' [-Wchar-subscripts]<br>
generator.c:898:5: warning: array subscript has type 'char' [-Wchar-subscripts]<br>
linking shared-object json/ext/generator.so</p>
<p><a href="http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-cygwin/log/20130507T115727Z.log.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/crossruby-trunk-cygwin/log/20130507T115727Z.log.html.gz</a></p>
<p>コードを見てみると以下のようになっていて、<br>
char * を dereference した結果を isspace に渡しています。</p>
<p>895 char *p = RSTRING_PTR(string), *q = p + string_len - 1;<br>
896 if (string_len < 2) return 0;<br>
897 for (; p < q && isspace(*p); p++);<br>
898 for (; q > p && isspace(*q); q--);<br>
899 return (*p == '[' && *q == ']') || (*p == '{' && *q == '}');</p>
<p>char が signed な環境では、*p や *q は負になるかもしれないのでよろしくなくて、<br>
*(unsigned char *)p とかにしたほうがいんじゃないでしょうか。</p>
Ruby master - Feature #8368 (Closed): Socket.getifaddrs
https://bugs.ruby-lang.org/issues/8368
2013-05-04T16:57:31Z
akr (Akira Tanaka)
akr@fsij.org
<p>I'd like to add a method: Socket.getifaddrs.</p>
<p>This method is a wrapper to getifaddrs() function.<br>
The result is an array of instances of Socket::Ifaddr class as follows.</p>
<p>% ./ruby -rpp -rsocket -e 'pp Socket.getifaddrs'<br>
[#<Socket::Ifaddr lo UP,LOOPBACK,RUNNING,0x10000 [PACKET protocol:0 lo hatype:772 HOST hwaddr:00:00:00:00:00:00]>,<br>
#<Socket::Ifaddr eth0 UP,BROADCAST,RUNNING,MULTICAST,0x10000 [PACKET protocol:0 eth0 hatype:1 HOST hwaddr:00:16:3e:95:88:bb] broadcast:[PACKET protocol:0 eth0 hatype:1 HOST hwaddr:ff:ff:ff:ff:ff:ff]>,<br>
#<Socket::Ifaddr sit0 NOARP [PACKET protocol:0 sit0 hatype:776 HOST hwaddr:00:00:00:00]>,<br>
#<Socket::Ifaddr lo UP,LOOPBACK,RUNNING,0x10000 [127.0.0.1] netmask:[255.0.0.0]>,<br>
#<Socket::Ifaddr eth0 UP,BROADCAST,RUNNING,MULTICAST,0x10000 [221.186.184.67] netmask:[255.255.255.240] broadcast:[221.186.184.79]>,<br>
#<Socket::Ifaddr lo UP,LOOPBACK,RUNNING,0x10000 [::1] netmask:[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]>,<br>
#<Socket::Ifaddr eth0 UP,BROADCAST,RUNNING,MULTICAST,0x10000 [fe80::216:3eff:fe95:88bb%eth0] netmask:[ffff:ffff:ffff:ffff::]>]</p>
<p>This method can be used to choose multicast-enabled interfaces.<br>
Multicast applications needs to identify a such interface to sending a multicast datagram.</p>
<p>% ./ruby -rpp -rsocket -e '<br>
pp Socket.getifaddrs.reject {|ifaddr|<br>
!ifaddr.addr.ip? || (ifaddr.flags & Socket::IFF_MULTICAST == 0)<br>
}.map {|ifaddr| [ifaddr.name, ifaddr.ifindex, ifaddr.addr] }'<br>
[["eth0", 2, #<Addrinfo: 221.186.184.67>],<br>
["eth0", 2, #<Addrinfo: fe80::216:3eff:fe95:88bb%eth0>]]</p>
<p>This method can be used to obtain broadcast addresses to send a broadcast<br>
messages. (use case: [ruby-talk:329921])</p>
<p>Also, the broadcast addresses can be used to receive broadcast messages.<br>
(Programming UNIX Sockets in C: 4.12. How can I write a multi-homed server?<br>
<a href="http://www.faqs.org/faqs/unix-faq/socket/" class="external">http://www.faqs.org/faqs/unix-faq/socket/</a> )</p>
<p>getifaddrs() is not standardized but many platforms have.<br>
BSDI, FreeBSD, NetBSD, OpenBSD, DragonFly, MirOS, GNU/Linux, MacOS X, SunOS 5.11 (OpenIndiana), Cygwin 1.7.15</p>
<p>From Gnulib document, getifaddrs() is not exist on<br>
AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, mingw, MSVC 9, Interix 3.5, BeOS.<br>
<a href="http://www.gnu.org/software/gnulib/manual/html_node/getifaddrs.html" class="external">http://www.gnu.org/software/gnulib/manual/html_node/getifaddrs.html</a></p>
<p>I implemented new Socket::Ifaddr class for return value of Socket.getifaddrs,<br>
instead of constructing the result from currentn data structures such as Array.<br>
This choice make us possible to implement Socket::Ifaddr#inspect to show flags as its names (UP,...).<br>
Also, struct getifaddrs contains Address-specific data, ifa_data which may be extended by platforms.<br>
When we find a way to extract some data from ifa_data, we can add a method for that.</p>
<p>Socket::Ifaddr is different from Socket::Interface by<br>
<a href="http://bugs.ruby-lang.org/issues/8075" class="external">http://bugs.ruby-lang.org/issues/8075</a> .<br>
They have no one-to-one mapping.<br>
For example, Socket.getifaddrs returns two or more elements for one interface.</p>
Ruby master - Feature #8338 (Closed): compilation failure in nkf with Bionic (Android's libc)
https://bugs.ruby-lang.org/issues/8338
2013-04-28T01:04:30Z
akr (Akira Tanaka)
akr@fsij.org
<p>buildroot 以外での cross compile もしてみようかと思って、<br>
Android を試したところ、nkf のところで compile に失敗します。</p>
<p>Bionic (Android の libc) には langinfo.h がないのが原因のようです。</p>
<p>nkf.h を見たところ、どう修正するのが適切なのかわからなかったので<br>
issue としておきます。</p>
<p>私の環境 (x86_64 な Debian GNU/Linux (squeeze)) では以下のようにすれば再現できます。<br>
(wget しているのは Android NDK で、<br>
<a href="http://developer.android.com/tools/sdk/ndk/index.html" class="external">http://developer.android.com/tools/sdk/ndk/index.html</a> に載っていたものです。<br>
Linux 64-bit (x86) 以外のものもあるので、他の環境でも試せるかもしれません)</p>
<p>% ruby -v<br>
ruby 2.1.0dev (2013-04-24 trunk 40443) [x86_64-linux]<br>
% A=$HOME/a<br>
% mkdir $A<br>
% cd $A<br>
% wget <a href="http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86_64.tar.bz2" class="external">http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86_64.tar.bz2</a><br>
% tar xf android-ndk-r8e-linux-x86_64.tar.bz2<br>
% android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -v |& grep Target<br>
Target: arm-linux-androideabi<br>
% svn co <a href="http://svn.ruby-lang.org/repos/ruby/trunk" class="external">http://svn.ruby-lang.org/repos/ruby/trunk</a> ruby<br>
...<br>
Checked out revision 40502.<br>
% cd ruby<br>
% autoconf<br>
% ./configure --prefix=$A --host=arm-linux-androideabi CC="$A/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=$A/android-ndk-r8e/platforms/android-14/arch-arm"<br>
% make<br>
...<br>
gmake[2]: Entering directory <code>/home/akr/a/ruby/ext/nkf' compiling nkf.c In file included from nkf-utf8/nkf.c:30:0, from nkf.c:62: nkf-utf8/nkf.h:166:22: fatal error: langinfo.h: No such file or directory compilation terminated. gmake[2]: *** [nkf.o] Error 1 gmake[2]: Leaving directory </code>/home/akr/a/ruby/ext/nkf'<br>
gmake[1]: *** [ext/nkf/all] Error 2<br>
gmake[1]: Leaving directory `/home/akr/a/ruby'<br>
gmake: *** [build-ext] Error 2<br>
zsh: exit 2</p>
<p>langinfo.h というファイルを探してみると、たしかにないようです。</p>
<p>% find $A -name langinfo.h<br>
%</p>
<p>また、<br>
<a href="https://android.googlesource.com/platform/bionic/+/android-4.2.2_r1.2/libc/README" class="external">https://android.googlesource.com/platform/bionic/+/android-4.2.2_r1.2/libc/README</a><br>
とかには</p>
<ul>
<li>no support for locales<br>
と書いてあるのでないのはそういうものなのでしょう。</li>
</ul>
<p>なお、現状ではそもそも Android で動くべきということないと思うので、Feature にしておきます。</p>
Ruby master - Feature #8331 (Closed): Update config.guess and config.sub for AArch64 (ARM64)
https://bugs.ruby-lang.org/issues/8331
2013-04-26T22:25:14Z
akr (Akira Tanaka)
akr@fsij.org
<p>ふと cross compile のやり方を知ってしまって、いろいろと試していると、<br>
AArch64 (ARM64) で configure で失敗することに気がつきました。</p>
<p>% ruby -v<br>
ruby 2.1.0dev (2013-04-24 trunk 40443) [x86_64-linux]<br>
% cd<br>
% B=$HOME/b<br>
% mkdir $B<br>
% cd $B<br>
% wget <a href="http://buildroot.uclibc.org/downloads/buildroot-2013.02.tar.bz2" class="external">http://buildroot.uclibc.org/downloads/buildroot-2013.02.tar.bz2</a><br>
% tar xf buildroot-2013.02.tar.bz2<br>
% cd buildroot-2013.02<br>
% make menuconfig<br>
Select "Target Architecture (i386) --->" and select "AArch64".<br>
Then select and .<br>
% make<br>
% $B/buildroot-2013.02/output/host/usr/bin/aarch64-linux-gnu-gcc -v<br>
...<br>
Target: aarch64-linux-gnu<br>
...<br>
% cd ..<br>
% svn co <a href="http://svn.ruby-lang.org/repos/ruby/trunk" class="external">http://svn.ruby-lang.org/repos/ruby/trunk</a> ruby<br>
% cd ruby<br>
% svn info|grep Rev:<br>
Last Changed Rev: 40481<br>
% autoconf<br>
% ./configure --host=aarch64-linux-gnu CC=$B/buildroot-2013.02/output/host/usr/bin/aarch64-linux-gnu-gcc<br>
configure: WARNING: if you wanted to set the --build type, don't use --host.<br>
If a cross compiler is detected then cross compile mode will be used<br>
checking build system type... x86_64-unknown-linux-gnu<br>
checking host system type... Invalid configuration <code>aarch64-linux-gnu': machine </code>aarch64' not recognized<br>
configure: error: /bin/bash tool/config.sub aarch64-linux-gnu failed<br>
zsh: exit 1 ./configure --host=aarch64-linux-gnu</p>
<p>どうも、config.guess と config.sub を更新する必要があるようです。</p>
<p>% git clone git://git.savannah.gnu.org/config.git # <a href="http://savannah.gnu.org/projects/config/" class="external">http://savannah.gnu.org/projects/config/</a><br>
% grep timestamp config/config.guess|head -1<br>
timestamp='2013-04-24'<br>
% grep timestamp config/config.sub|head -1<br>
timestamp='2013-04-24'<br>
% cp config/config.guess config/config.sub tool<br>
% ./configure --host=aarch64-linux-gnu CC=$B/buildroot-2013.02/output/host/usr/bin/aarch64-linux-gnu-gcc<br>
configure: WARNING: if you wanted to set the --build type, don't use --host.<br>
If a cross compiler is detected then cross compile mode will be used<br>
checking build system type... x86_64-unknown-linux-gnu<br>
checking host system type... aarch64-unknown-linux-gnu<br>
checking target system type... aarch64-unknown-linux-gnu<br>
...<br>
checking for nroff... /usr/bin/nroff<br>
.ext/include/aarch64-linux/ruby/config.h updated<br>
verconf.h updated<br>
ruby library version = 2.1.0<br>
configure: creating ./config.status<br>
config.status: creating GNUmakefile<br>
config.status: creating Makefile<br>
config.status: creating ruby-2.1.pc<br>
% make<br>
% make install DESTDIR=$B/root</p>
<p>config.guess と config.sub を更新すれば、install まではいきます。<br>
(実行してないのでその先はわかりません)</p>
Ruby master - Bug #8256 (Closed): dependency to include/ruby/version.h
https://bugs.ruby-lang.org/issues/8256
2013-04-12T00:19:25Z
akr (Akira Tanaka)
akr@fsij.org
<p>気がついたのですが、in-place で ruby を build した場合に<br>
include/ruby/version.h を更新して make しても version.o が更新されません。</p>
<p>以下では、include/ruby/version.h を更新して、<br>
更新時刻が version.o よりも include/ruby/version.h のほうが新しくなっていますが、<br>
make version.o としても、結局、<br>
gmake: `version.o' is up to date.<br>
といわれてしまって更新されません。(version.o の更新時刻が変わりません)</p>
<p>% echo '/**/' >> include/ruby/version.h<br>
% ls -l version.o include/ruby/version.h<br>
-rw-r--r-- 1 akr akr 1870 Apr 11 23:54 include/ruby/version.h<br>
-rw-r--r-- 1 akr akr 206584 Apr 11 23:45 version.o<br>
% make version.o<br>
running CONFIG_SHELL=/bin/bash /bin/bash ./configure --prefix=/home/akr/ruby/tst6 CC=/home/src/gcc/bin/gcc --disable-install-doc --with-valgrind CPPFLAGS=-DRUBY_DEBUG_ENV optflags=-O0 debugflags=-save-temps=obj -g3 warnflags=-W -Wall -Wformat=2 -Wundef -Wno-parentheses -Wno-unused-parameter -Wno-missing-field-initializers --no-create --no-recursion<br>
checking build system type... x86_64-unknown-linux-gnu<br>
...<br>
checking for nroff... /usr/bin/nroff<br>
.ext/include/x86_64-linux/ruby/config.h unchanged<br>
verconf.h unchanged<br>
ruby library version = 2.1.0<br>
configure: creating ./config.status<br>
MAKE=gmake /bin/sh ./config.status<br>
config.status: creating GNUmakefile<br>
config.status: creating Makefile<br>
config.status: creating ruby-2.1.pc<br>
Makefile unchanged<br>
MAKE=gmake /bin/sh ./config.status<br>
config.status: creating GNUmakefile<br>
config.status: creating Makefile<br>
config.status: creating ruby-2.1.pc<br>
Makefile unchanged<br>
gmake: `version.o' is up to date.<br>
% ls -l version.o include/ruby/version.h<br>
-rw-r--r-- 1 akr akr 1870 Apr 11 23:54 include/ruby/version.h<br>
-rw-r--r-- 1 akr akr 206584 Apr 11 23:45 version.o</p>
<p>gcc の -MM オプションで実際に include しているファイルを調べてみると、<br>
以下のように include/ruby/version.h は含まれているので、version.o も<br>
更新されるのが適切でしょう。</p>
<p>version.o: version.c verconf.h include/ruby/ruby.h <br>
.ext/include/x86_64-linux/ruby/config.h include/ruby/defines.h <br>
include/ruby/missing.h include/ruby/intern.h include/ruby/defines.h <br>
include/ruby/st.h include/ruby/subst.h version.h include/ruby/version.h <br>
revision.h</p>
<p>そして、common.mk には以下のように、include/ruby 下の version.h を示す、<br>
{$(VPATH)}version.h がちゃんと書いてあります。<br>
そして、ソースディレクトリ直下の version.h を示す $(srcdir)/version.h も書いてあります。</p>
<p>version.$(OBJEXT): {$(VPATH)}version.c $(RUBY_H_INCLUDES) <br>
{$(VPATH)}version.h $(srcdir)/version.h $(srcdir)/revision.h {$(VPATH)}config.h <br>
verconf.h</p>
<p>問題は、 version.h という名前のファイルが include/ruby だけでなく<br>
ソースディレクトリ直下にもあることです。<br>
gmake は VPATH に従ったディレクトリを探す前にカレントディレクトリを探すので<br>
カレントディレクトリの version.h を見つけてそちらへの依存だと判断してしまいます。<br>
これは make -p で make が読み取った依存関係を調べると確認できます。</p>
<p>% make -p |grep '^version.o'<br>
...<br>
version.o: version.c version.c ./include/ruby/ruby.h .ext/include/x86_64-linux/ruby/config.h ./include/ruby/defines.h ./include/ruby/intern.h ./include/ruby/missing.h ./include/ruby/st.h ./include/ruby/subst.h version.h version.h revision.h .ext/include/x86_64-linux/ruby/config.h verconf.h .ext/include/x86_64-linux/ruby/config.h ./include/ruby/missing.h</p>
<p>ここでは version.h がふたつあって、{$(VPATH)}version.h と $(srcdir)/version.h の両方が<br>
version.h に展開されていることが分かります。</p>
<p>根本的には、version.h という同名のファイルがあるのが問題なので、<br>
外部に公開されていないソースディレクトリ直下の version.h を rename すればいいんじゃないかと思うんですが<br>
どうでしょうか。</p>
<p>で、新しい名前は verdata.h とかどうでしょう。<br>
RUBY_VERSION とかの実際のデータが定義されているので。</p>
<p>なお、version.h は自動更新されるのでそちらの仕掛けも調整しないといけないと思います。</p>
Backport200 - Backport #8209 (Closed): mkmf.log contains misplaced messages
https://bugs.ruby-lang.org/issues/8209
2013-04-03T11:44:34Z
akr (Akira Tanaka)
akr@fsij.org
<p>mkmf.log の内容が奇妙なものになることがあります。</p>
<p>以下は Debian GNU/Linux squeeze でのビルドの結果から<br>
調べたものですが、<br>
ext/-test-/win32/dln の mkmf.log にその拡張ライブラリ以外 (tk とか win32ole<br>
とか) に関するメッセージが出ています。<br>
また、なぜ ext/-test-/win32/dln がビルドされないかという理由が残っていません。<br>
同様に、tk の mkmf には win32ole に関するメッセージが入っていて、<br>
なぜ tk がビルドされないかという理由が入っていません。</p>
<p>boron% cat ext/-test-/win32/dln/mkmf.log<br>
Failed to configure -test-/win32/dln. It will not be installed.<br>
Failed to configure -test-/win32/fd_setsize. It will not be installed.<br>
Failed to configure dl/win32. It will not be installed.<br>
Failed to configure fiddle/win32. It will not be installed.<br>
Failed to configure tk. It will not be installed.<br>
Failed to configure tk/tkutil. It will not be installed.<br>
Failed to configure win32ole. It will not be installed.<br>
boron% cat ext/tk/mkmf.log<br>
Failed to configure tk. It will not be installed.<br>
Failed to configure tk/tkutil. It will not be installed.<br>
Failed to configure win32ole. It will not be installed.</p>
<p>boron% pwd<br>
/home/akr/chkbuild/tmp/build/ruby-trunk/20130403T000400Z/ruby<br>
boron% svn info<br>
Path: .<br>
URL: <a href="http://svn.ruby-lang.org/repos/ruby/trunk" class="external">http://svn.ruby-lang.org/repos/ruby/trunk</a><br>
Repository Root: <a href="http://svn.ruby-lang.org/repos/ruby" class="external">http://svn.ruby-lang.org/repos/ruby</a><br>
Repository UUID: b2dd03c8-39d4-4d8f-98ff-823fe69b080e<br>
Revision: 40075<br>
Node Kind: directory<br>
Schedule: normal<br>
Last Changed Author: svn<br>
Last Changed Rev: 40073<br>
Last Changed Date: 2013-04-03 00:09:41 +0900 (Wed, 03 Apr 2013)</p>
<p>なお、気がついたきっかけは socket をいじったときで、<br>
ext/-test-/win32/dln や ext/tk 固有の問題ではないと思います。</p>
Backport193 - Backport #7775 (Closed): backport r38993 (ignore truncated part of socket address) ...
https://bugs.ruby-lang.org/issues/7775
2013-02-03T21:04:48Z
akr (Akira Tanaka)
akr@fsij.org
<p>Please apply the attached patch,<br>
sockaddr-ignore-truncated-r38993-to-193.patch, to Ruby 1.9.3.</p>
<p>The patch modifies returned addrlen after getsockaddr, getpeername and accept.</p>
<p>They takes a buffer with the length and<br>
kernel returns a socket address in the buffer and returns its length.</p>
<p>When a socket address length is longer than the buffer length,<br>
Most OS returns the real socket address length.<br>
(Exception: NetBSD returns the buffer length.)</p>
<p>Apart from that, some OS provide a way to create Unix domain socket<br>
longer than sockaddr_un.</p>
<p>For example, since GNU/Linux adds a NUL for pathname which is not NUL-terminated,<br>
giving sizeof(sun_path) non-NUL-terminated path to bind() creates a<br>
socket address which is one byte longer than sizeof(struct sockaddr_un).</p>
<p>In that case, rb_str_new(socketaddress->sun_path, returned_length),<br>
rb_str_new reads a byte just after the buffer.</p>
<p>The patch modifies the returned length as shorten to the buffer length<br>
to avoid such read.<br>
It is not a problem on GNU/Linux because the truncated data is always a NUL<br>
because GNU/Linux forbid a pathname longer than sizeof(sun_path) for<br>
Unix domain socket.</p>
<p>Note that providing larger buffer for getsockname/getpeername/accept<br>
seems a practical option but it is another issue.<br>
Also note that retrying the system calls is not general solution because<br>
accept() is not retryable -- retrying accept() waits a next connection.</p>
Ruby master - Bug #6751 (Closed): remove tempfiles early.
https://bugs.ruby-lang.org/issues/6751
2012-07-18T20:37:41Z
akr (Akira Tanaka)
akr@fsij.org
<p>cgi.rb で、テンポラリファイル (Tempfile) をなるべく早く消すようにすると良いと<br>
思うのですがいかがでしょうか。</p>
<p>いずれ GC で消されるはずなので、Bug というほどの話ではありませんが。</p>
<p>./ruby test/runner.rb test/cgi の各テストでテンポラリファイルが残らないように<br>
したものを cgi-tempfile.patch として作ってみました。</p>
<ul>
<li>read_multipart で params に入れないものはそこで消す</li>
<li>read_multipart で例外が起きたら、内部で作ったものはすべて消す</li>
<li>テスト内で作ったものはテストが終わる前に消す</li>
</ul>
<p>なお、テスト毎に残っていないか確認するのは以下のようにして行いました。</p>
<a name="Index-libminitestunitrb"></a>
<h1 >Index: lib/minitest/unit.rb<a href="#Index-libminitestunitrb" class="wiki-anchor">¶</a></h1>
<p>--- lib/minitest/unit.rb (revision 36442)<br>
+++ lib/minitest/unit.rb (working copy)<br>
@@ -1082,6 +1082,10 @@ module MiniTest<br>
end<br>
trap 'INFO', 'DEFAULT' if SUPPORTS_INFO_SIGNAL<br>
end</p>
<ul>
<li>
<pre><code> if !(live_tempfiles = ObjectSpace.each_object(Tempfile).find_all {|t| t.path }).empty?
</code></pre>
</li>
<li>
<pre><code> puts nil, "after #{self.__name__}", *live_tempfiles.map {|t| t.inspect }
</code></pre>
</li>
<li>
<pre><code> live_tempfiles.each {|t| t.unlink }
</code></pre>
</li>
<li>
<pre><code> end
result
end
</code></pre>
</li>
</ul>
<p>どうでしょうか。</p>
Ruby master - Bug #6741 (Closed): (1 << 103).to_f.to_s is "10141204801825835000000000000000.0"
https://bugs.ruby-lang.org/issues/6741
2012-07-16T21:07:17Z
akr (Akira Tanaka)
akr@fsij.org
<p>気がついたのですが、Float#to_s が実際には 0 でない桁を 0 とした文字列を生成することがあります。</p>
<p>% ./ruby -ve '1.upto(200) {|i| p [i, (1 << i).to_f.to_s] }'<br>
ruby 2.0.0dev (2012-07-15 trunk 36395) [x86_64-linux]<br>
[1, "2.0"]<br>
[2, "4.0"]<br>
[3, "8.0"]<br>
[4, "16.0"]<br>
[5, "32.0"]<br>
[6, "64.0"]<br>
[7, "128.0"]<br>
[8, "256.0"]<br>
...<br>
[54, "18014398509481984.0"]<br>
[55, "36028797018963970.0"]<br>
[56, "72057594037927940.0"]<br>
[57, "144115188075855870.0"]<br>
[58, "288230376151711740.0"]<br>
[59, "576460752303423500.0"]<br>
[60, "1152921504606847000.0"]<br>
[61, "2305843009213694000.0"]<br>
[62, "4611686018427388000.0"]<br>
[63, "9223372036854776000.0"]<br>
[64, "18446744073709552000.0"]<br>
[65, "36893488147419103000.0"]<br>
[66, "73786976294838210000.0"]<br>
[67, "147573952589676410000.0"]<br>
[68, "295147905179352830000.0"]<br>
[69, "590295810358705700000.0"]<br>
[70, "1180591620717411300000.0"]<br>
[71, "2361183241434822600000.0"]<br>
[72, "4722366482869645000000.0"]<br>
[73, "9444732965739290000000.0"]<br>
[74, "18889465931478580000000.0"]<br>
[75, "37778931862957160000000.0"]<br>
[76, "75557863725914320000000.0"]<br>
[77, "151115727451828650000000.0"]<br>
[78, "302231454903657300000000.0"]<br>
[79, "604462909807314600000000.0"]<br>
[80, "1208925819614629200000000.0"]<br>
[81, "2417851639229258300000000.0"]<br>
[82, "4835703278458517000000000.0"]<br>
[83, "9671406556917033000000000.0"]<br>
[84, "19342813113834067000000000.0"]<br>
[85, "38685626227668134000000000.0"]<br>
[86, "77371252455336270000000000.0"]<br>
[87, "154742504910672530000000000.0"]<br>
[88, "309485009821345100000000000.0"]<br>
[89, "618970019642690200000000000.0"]<br>
[90, "1237940039285380300000000000.0"]<br>
[91, "2475880078570760500000000000.0"]<br>
[92, "4951760157141521000000000000.0"]<br>
[93, "9903520314283042000000000000.0"]<br>
[94, "19807040628566084000000000000.0"]<br>
[95, "39614081257132170000000000000.0"]<br>
[96, "79228162514264340000000000000.0"]<br>
[97, "158456325028528680000000000000.0"]<br>
[98, "316912650057057350000000000000.0"]<br>
[99, "633825300114114700000000000000.0"]<br>
[100, "1267650600228229400000000000000.0"]<br>
[101, "2535301200456459000000000000000.0"]<br>
[102, "5070602400912918000000000000000.0"]<br>
[103, "10141204801825835000000000000000.0"]<br>
[104, "2.028240960365167e+31"]<br>
...<br>
[200, "1.6069380442589903e+60"]</p>
<p>この例では、(1 << 55).to_f から (1 << 103).to_f で、整数部分の<br>
下のほうの桁が 0 になっています。</p>
<p>(1 << n) の整数部最下位桁は 0 にはならないので、これはまちがっています。</p>
<p>おそらく、そういう間違った桁を表示するようになってしまう状況では<br>
指数形式を使って、そのあたりの桁は表示しないようにするべきなのだと思います。</p>
<p>また、実際、1.8.7 ではそのように動作します。</p>
<p>% ruby-1.8.7p370 -ve '1.upto(200) {|i| p [i, (1 << i).to_f.to_s] }'<br>
ruby 1.8.7 (2012-06-29 patchlevel 370) [x86_64-linux]<br>
[1, "2.0"]<br>
[2, "4.0"]<br>
...<br>
[46, "70368744177664.0"]<br>
[47, "1.40737488355328e+14"]<br>
...</p>
Ruby master - Feature #6733 (Open): New inspect framework
https://bugs.ruby-lang.org/issues/6733
2012-07-14T18:06:18Z
akr (Akira Tanaka)
akr@fsij.org
<p>After we discussed <a href="http://bugs.ruby-lang.org/issues/6291" class="external">http://bugs.ruby-lang.org/issues/6291</a> at a developer meeting,<br>
we re-realized new inspect framework may be useful.</p>
<p>Problem:</p>
<ul>
<li>inspect method may generate too long string but sometimes whole string is not required.<br>
For example, first 70 characters are enough for error messages (backtrace).</li>
<li>inspect can't know a encoding to be expected.</li>
<li>inspect generates may short strings and discard them immediately.</li>
</ul>
<p>If we have a new method, inspect_to(buffer), and<br>
it (or overridden method in subclass) adds the inspected result to buffer,<br>
we can solve above problems.<br>
buffer has a method, <<.<br>
It may be a string, IO or other object.</p>
<p>For too long string, buffer itself can throw (or raise) when buffered output is reached to a specified limit.</p>
<p>For encoding, buffer can record an encoding.<br>
(p method creates a buffer object using $stdout's encoding.)</p>
<p>For small strings, in C level, we can create a rb_buffer_add(VALUE buffer, const char *p, long len) and<br>
it don't need to allocate a String object.</p>
<p>This is big change but we can preserve compatibility by following default inspect_to method:</p>
<p>class Object<br>
def inspect_to(buffer)<br>
buffer << self.inspect<br>
end<br>
end</p>
<p>If legacy class which has inspect but not inspect_to,<br>
Object#inspect_to calls inspect and use the result.</p>
Ruby master - Feature #6643 (Closed): io.seek(off, :end)
https://bugs.ruby-lang.org/issues/6643
2012-06-25T19:31:38Z
akr (Akira Tanaka)
akr@fsij.org
<p>IO#seek メソッドの whence 引数としてシンボルを受け付けるようにしませんか。</p>
<p>つまり、<br>
io.seek(0, IO::SEEK_END)<br>
のかわりに<br>
io.seek(0, :end)<br>
とかけるようにする、ということです。</p>
<p>IO::SEEK_END と等価な指定として :end,<br>
IO::SEEK_CUR と等価な指定として :cur,<br>
IO::SEEK_SET と等価な指定として :set を<br>
受け付けるようにします。</p>
<p>思い立ったきっかけとしては、<br>
ひさしぶりに seek を使ったら、<br>
io.seek(IO::SEEK_END)<br>
と書いてしまって、これは私の環境では IO::SEEK_END が 2 なので、<br>
io.seek(2)<br>
つまり<br>
io.seek(2, IO::SEEK_SET)<br>
と解釈されてしまって、ちょっと悩んだためです。</p>
<p>もし同様な間違いをしてしまっても、IO::SEEK_END でなく :end と<br>
書いたのであれば、<br>
io.seek(:end)<br>
は can't convert Symbol into Integer (TypeError) となるので悩まなくて済んだのに、<br>
と思いました。</p>
<p>なお、その間違いをしたのは私だけではないようで、検索すると<br>
<a href="http://jira.codehaus.org/browse/JRUBY-1897" class="external">http://jira.codehaus.org/browse/JRUBY-1897</a><br>
<a href="http://rubyforge.org/pipermail/biocatalogue-developers/attachments/20100512/2eacb73c/attachment-0001.html" class="external">http://rubyforge.org/pipermail/biocatalogue-developers/attachments/20100512/2eacb73c/attachment-0001.html</a><br>
というふたつの例が見つかります。</p>
<p>どうでしょうか。</p>
Ruby master - Bug #6046 (Third Party's Issue): Berkeley DB dbm_open in libc is called even if --w...
https://bugs.ruby-lang.org/issues/6046
2012-02-19T12:27:02Z
akr (Akira Tanaka)
akr@fsij.org
<p>FreeBSD 8.2 で、--with-dbm-type=gdbm_compat として ext/dbm に GDBM を<br>
使わせようとしたときに、(libc 中の) Berkeley DB の dbm_open を呼んで<br>
しまうようです。</p>
<p>再現手順は以下のとおりです。</p>
<p>% uname -a<br>
FreeBSD freebsd82-64 8.2-RELEASE-p3 FreeBSD 8.2-RELEASE-p3 #0: Tue Sep 27 18:45:57 UTC 2011 <a href="mailto:root@amd64-builder.daemonology.net" class="email">root@amd64-builder.daemonology.net</a>:/usr/obj/usr/src/sys/GENERIC amd64<br>
% mkdir g<br>
% cd g<br>
% prefix=<code>pwd</code><br>
% echo $prefix<br>
/home/akr/g<br>
% fetch <a href="ftp://ftp.jaist.ac.jp/pub/GNU/gdbm/gdbm-1.10.tar.gz" class="external">ftp://ftp.jaist.ac.jp/pub/GNU/gdbm/gdbm-1.10.tar.gz</a><br>
% tar xf gdbm-1.10.tar.gz<br>
% ./configure --prefix=$prefix --enable-libgdbm-compat<br>
% make<br>
% make install<br>
% cd ..<br>
% export LD_RUN_PATH=$prefix/lib<br>
% svn co <a href="http://svn.ruby-lang.org/repos/ruby/trunk" class="external">http://svn.ruby-lang.org/repos/ruby/trunk</a> ruby<br>
% cd ruby<br>
% autoconf<br>
% ./configure --prefix=$prefix --with-opt-dir=$prefix --with-dbm-type=gdbm_compat<br>
% make<br>
% make install<br>
% ./ruby -v<br>
ruby 2.0.0dev (2012-02-19 trunk 34688) [x86_64-freebsd8.2]<br>
% ./ruby -rdbm -e 'DBM.open("a")'<br>
-e:1: [BUG] Segmentation fault<br>
ruby 2.0.0dev (2012-02-19 trunk 34688) [x86_64-freebsd8.2]</p>
<p>-- Control frame information -----------------------------------------------<br>
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC :open<br>
c:0003 p:0017 s:0006 b:0006 l:001d88 d:001f08 EVAL -e:1<br>
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH<br>
c:0001 p:0000 s:0002 b:0002 l:001d88 d:001d88 TOP</p>
<p>-- Ruby level backtrace information ----------------------------------------<br>
-e:1:in <code><main>' -e:1:in </code>open'</p>
<p>-- Other runtime information -----------------------------------------------</p>
<ul>
<li>
<p>Loaded script: -e</p>
</li>
<li>
<p>Loaded features:</p>
<p>0 enumerator.so<br>
1 /home/akr/g/lib/ruby/2.0.0/x86_64-freebsd8.2/enc/encdb.so<br>
2 /home/akr/g/lib/ruby/2.0.0/x86_64-freebsd8.2/enc/trans/transdb.so<br>
3 /home/akr/g/lib/ruby/2.0.0/rubygems/defaults.rb<br>
4 /home/akr/g/lib/ruby/2.0.0/x86_64-freebsd8.2/rbconfig.rb<br>
5 /home/akr/g/lib/ruby/2.0.0/rubygems/deprecate.rb<br>
6 /home/akr/g/lib/ruby/2.0.0/rubygems/exceptions.rb<br>
7 /home/akr/g/lib/ruby/2.0.0/rubygems/custom_require.rb<br>
8 /home/akr/g/lib/ruby/2.0.0/rubygems.rb<br>
9 /home/akr/g/lib/ruby/2.0.0/x86_64-freebsd8.2/dbm.so</p>
</li>
</ul>
<p>[NOTE]<br>
You may have encountered a bug in the Ruby interpreter or extension libraries.<br>
Bug reports are welcome.<br>
For details: <a href="http://www.ruby-lang.org/bugreport.html" class="external">http://www.ruby-lang.org/bugreport.html</a></p>
<p>zsh: abort (core dumped) ./ruby -rdbm -e 'DBM.open("a")'</p>
<p>% ls -l a.*<br>
-rw-r--r-- 1 akr akr 0 Feb 19 12:07 a.db<br>
% file a.db<br>
a.db: empty</p>
<p>まず、BUS Error が起きていますが、これは、libc の dbm_open を呼んでしまうのに、<br>
dbm_pagfno は GDBM のものを呼んでしまうためです。<br>
(dbm_pagfno は libc には入っていないので、選択の余地なく GDBM のが呼ばれます)</p>
<p>本質的な問題は、生成された a.db というファイル名からわかるように、<br>
dbm_open は libc に入っている、Berkeley DB のものが呼ばれていることです。<br>
(ファイルが空なのは dbm_close せずに BUS Error で終わっているからでしょう)</p>
<p>ldd で調べると、dbm.so にはちゃんと GDBM がリンクされています。</p>
<p>% ldd .ext/x86_64-freebsd8.2/dbm.so<br>
.ext/x86_64-freebsd8.2/dbm.so:<br>
libgdbm_compat.so.4 => /home/akr/g/lib/libgdbm_compat.so.4 (0x800c00000)<br>
libgdbm.so.4 => /home/akr/g/lib/libgdbm.so.4 (0x800d03000)<br>
libthr.so.3 => /lib/libthr.so.3 (0x800e0b000)<br>
librt.so.1 => /usr/lib/librt.so.1 (0x800f24000)<br>
libcrypt.so.5 => /lib/libcrypt.so.5 (0x801029000)<br>
libm.so.5 => /lib/libm.so.5 (0x801142000)<br>
libc.so.7 => /lib/libc.so.7 (0x800647000)</p>
<p>また、LD_PRELOAD で libgdbm_compat.so.4 を最初に読み込ませてやれば、<br>
意図どおりに GDBM の dbm_open が呼ばれます。</p>
<p>% LD_PRELOAD=$prefix/lib/libgdbm_compat.so.4 ./ruby -rdbm -e 'DBM.open("a")'<br>
% ls -l a.*<br>
-rw-r--r-- 1 akr akr 16 Feb 19 12:10 a.dir<br>
-rw-r--r-- 1 akr akr 49152 Feb 19 12:10 a.pag<br>
% file a.*<br>
a.dir: GNU dbm 2.x database<br>
a.pag: data</p>
<p>で、FreeBSD で、LD_PRELOAD とか変なことをせずに<br>
dbm.so から、GDBM の dbm_open を呼び出すにはどうしたらいいんでしょう?</p>
<p>まぁ、FreeBSD で、GDBM を (gdbm 拡張でなく、わざわざ) dbm 拡張経由で<br>
使うというのはまずない状況という気はするんですが。</p>
Ruby master - Bug #5808 (Closed): "a = []; a << a; puts JSON.dump(a)" aborted
https://bugs.ruby-lang.org/issues/5808
2011-12-26T12:45:32Z
akr (Akira Tanaka)
akr@fsij.org
<p>ふと a = []; a << a; puts JSON.dump(a) としてみたら、abort しました。</p>
<p>% ./ruby -rjson -ve 'a = []; a << a; puts JSON.dump(a)'<br>
ruby 2.0.0dev (2011-12-26 trunk 34127) [x86_64-linux]<br>
/home/ruby/tcstate/lib/ruby/1.9.1/json/common.rb:216: stack level too deep (SystemStackError)<br>
*** glibc detected *** ./ruby: double free or corruption (out): 0x00007fd5c0c18240 ***<br>
======= Backtrace: =========<br>
/lib/libc.so.6(+0x71ad6)[0x7fd5bdf81ad6]<br>
/lib/libc.so.6(cfree+0x6c)[0x7fd5bdf8684c]<br>
./ruby(+0x14053d)[0x7fd5bf0b253d]<br>
./ruby(ruby_vm_destruct+0x66)[0x7fd5bf0b1e68]<br>
./ruby(ruby_cleanup+0x386)[0x7fd5bef9401f]<br>
./ruby(ruby_run_node+0x45)[0x7fd5bef941e5]<br>
./ruby(+0x2088d)[0x7fd5bef9288d]<br>
/lib/libc.so.6(__libc_start_main+0xfd)[0x7fd5bdf2ec4d]<br>
./ruby(+0x20749)[0x7fd5bef92749]<br>
======= Memory map: ========<br>
7fd5b8000000-7fd5b8021000 rw-p 00000000 00:00 0<br>
7fd5b8021000-7fd5bc000000 ---p 00000000 00:00 0<br>
7fd5bcaf3000-7fd5bcb09000 r-xp 00000000 08:01 6627331 /lib/libgcc_s.so.1<br>
7fd5bcb09000-7fd5bcd08000 ---p 00016000 08:01 6627331 /lib/libgcc_s.so.1<br>
7fd5bcd08000-7fd5bcd09000 rw-p 00015000 08:01 6627331 /lib/libgcc_s.so.1<br>
7fd5bcd09000-7fd5bcd11000 r-xp 00000000 08:01 14934439 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/json/ext/generator.so<br>
7fd5bcd11000-7fd5bcf10000 ---p 00008000 08:01 14934439 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/json/ext/generator.so<br>
7fd5bcf10000-7fd5bcf11000 rw-p 00007000 08:01 14934439 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/json/ext/generator.so<br>
7fd5bcf11000-7fd5bcf12000 r-xp 00000000 08:01 14934499 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_32le.so<br>
7fd5bcf12000-7fd5bd112000 ---p 00001000 08:01 14934499 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_32le.so<br>
7fd5bd112000-7fd5bd113000 rw-p 00001000 08:01 14934499 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_32le.so<br>
7fd5bd113000-7fd5bd114000 r-xp 00000000 08:01 14934502 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_32be.so<br>
7fd5bd114000-7fd5bd314000 ---p 00001000 08:01 14934502 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_32be.so<br>
7fd5bd314000-7fd5bd315000 rw-p 00001000 08:01 14934502 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_32be.so<br>
7fd5bd315000-7fd5bd317000 r-xp 00000000 08:01 14934492 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_16le.so<br>
7fd5bd317000-7fd5bd516000 ---p 00002000 08:01 14934492 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_16le.so<br>
7fd5bd516000-7fd5bd517000 rw-p 00001000 08:01 14934492 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_16le.so<br>
7fd5bd517000-7fd5bd519000 r-xp 00000000 08:01 14934483 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_16be.so<br>
7fd5bd519000-7fd5bd718000 ---p 00002000 08:01 14934483 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_16be.so<br>
7fd5bd718000-7fd5bd719000 rw-p 00001000 08:01 14934483 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/utf_16be.so<br>
7fd5bd719000-7fd5bd720000 r-xp 00000000 08:01 14934440 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/json/ext/parser.so<br>
7fd5bd720000-7fd5bd91f000 ---p 00007000 08:01 14934440 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/json/ext/parser.so<br>
7fd5bd91f000-7fd5bd920000 rw-p 00006000 08:01 14934440 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/json/ext/parser.so<br>
7fd5bd920000-7fd5bd922000 r-xp 00000000 08:01 14934465 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/trans/transdb.so<br>
7fd5bd922000-7fd5bdb22000 ---p 00002000 08:01 14934465 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/trans/transdb.so<br>
7fd5bdb22000-7fd5bdb23000 rw-p 00002000 08:01 14934465 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/trans/transdb.so<br>
7fd5bdb23000-7fd5bdb25000 r-xp 00000000 08:01 14934498 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so<br>
7fd5bdb25000-7fd5bdd24000 ---p 00002000 08:01 14934498 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so<br>
7fd5bdd24000-7fd5bdd25000 rw-p 00001000 08:01 14934498 /home/ruby/tcstate/lib/ruby/1.9.1/x86_64-linux/enc/encdb.so<br>
7fd5bdd25000-7fd5bdf10000 r--p 00000000 08:01 18989057 /usr/lib/locale/locale-archive<br>
7fd5bdf10000-7fd5be068000 r-xp 00000000 08:01 6627339 /lib/libc-2.11.2.so<br>
7fd5be068000-7fd5be267000 ---p 00158000 08:01 6627339 /lib/libc-2.11.2.so<br>
7fd5be267000-7fd5be26b000 r--p 00157000 08:01 6627339 /lib/libc-2.11.2.so<br>
7fd5be26b000-7fd5be26c000 rw-p 0015b000 08:01 6627339 /lib/libc-2.11.2.so<br>
7fd5be26c000-7fd5be271000 rw-p 00000000 00:00 0<br>
7fd5be271000-7fd5be2f1000 r-xp 00000000 08:01 6627348 /lib/libm-2.11.2.so<br>
7fd5be2f1000-7fd5be4f1000 ---p 00080000 08:01 6627348 /lib/libm-2.11.2.so<br>
7fd5be4f1000-7fd5be4f2000 r--p 00080000 08:01 6627348 /lib/libm-2.11.2.so<br>
7fd5be4f2000-7fd5be4f3000 rw-p 00081000 08:01 6627348 /lib/libm-2.11.2.so<br>
7fd5be4f3000-7fd5be4fb000 r-xp 00000000 08:01 6627350 /lib/libcrypt-2.11.2.so<br>
7fd5be4fb000-7fd5be6fa000 ---p 00008000 08:01 6627350 /lib/libcrypt-2.11.2.so<br>
7fd5be6fa000-7fd5be6fb000 r--p 00007000 08:01 6627350 /lib/libcrypt-2.11.2.so<br>
7fd5be6fb000-7fd5be6fc000 rw-p 00008000 08:01 6627350 /lib/libcrypt-2.11.2.so<br>
7fd5be6fc000-7fd5be72a000 rw-p 00000000 00:00 0<br>
7fd5be72a000-7fd5be72c000 r-xp 00000000 08:01 6627338 /lib/libdl-2.11.2.so<br>
7fd5be72c000-7fd5be92c000 ---p 00002000 08:01 6627338 /lib/libdl-2.11.2.so<br>
7fd5be92c000-7fd5be92d000 r--p 00002000 08:01 6627338 /lib/libdl-2.11.2.so<br>
7fd5be92d000-7fd5be92e000 rw-p 00003000 08:01 6627338 /lib/libdl-2.11.2.so<br>
7fd5be92e000-7fd5be935000 r-xp 00000000 08:01 6627341 /lib/librt-2.11.2.so<br>
7fd5be935000-7fd5beb34000 ---p 00007000 08:01 6627341 /lib/librt-2.11.2.so<br>
7fd5beb34000-7fd5beb35000 r--p 00006000 08:01 6627341 /lib/librt-2.11.2.so<br>
7fd5beb35000-7fd5beb36000 rw-p 00007000 08:01 6627341 /lib/librt-2.11.2.so<br>
7fd5beb36000-7fd5beb4d000 r-xp 00000000 08:01 6627340 /lib/libpthread-2.11.2.so<br>
7fd5beb4d000-7fd5bed4c000 ---p 00017000 08:01 6627340 /lib/libpthread-2.11.2.so<br>
7fd5bed4c000-7fd5bed4d000 r--p 00016000 08:01 6627340 /lib/libpthread-2.11.2.so<br>
7fd5bed4d000-7fd5bed4e000 rw-p 00017000 08:01 6627340 /lib/libpthread-2.11.2.so<br>
7fd5bed4e000-7fd5bed52000 rw-p 00000000 00:00 0<br>
7fd5bed52000-7fd5bed70000 r-xp 00000000 08:01 6627351 /lib/ld-2.11.2.so<br>
7fd5bef57000-7fd5bef5c000 rw-p 00000000 00:00 0<br>
7fd5bef68000-7fd5bef69000 rw-p 00000000 00:00 0<br>
7fd5bef69000-7fd5bef6a000 ---p 00000000 00:00 0<br>
7fd5bef6a000-7fd5bef6f000 rw-p 00000000 00:00 0<br>
7fd5bef6f000-7fd5bef70000 r--p 0001d000 08:01 6627351 /lib/ld-2.11.2.so<br>
7fd5bef70000-7fd5bef71000 rw-p 0001e000 08:01 6627351 /lib/ld-2.11.2.so<br>
7fd5bef71000-7fd5bef72000 rw-p 00000000 00:00 0<br>
7fd5bef72000-7fd5bf1ad000 r-xp 00000000 08:01 14797288 /home/ruby/tcstate/ruby/ruby<br>
7fd5bf3ac000-7fd5bf3b2000 rw-p 0023a000 08:01 14797288 /home/ruby/tcstate/ruby/ruby<br>
7fd5bf3b2000-7fd5bf3d0000 rw-p 00000000 00:00 0<br>
7fd5c0bb3000-7fd5c0efa000 rw-p 00000000 00:00 0 [heap]<br>
7fffaca6b000-7fffad26a000 rw-p 00000000 00:00 0 [stack]<br>
7fffad3ff000-7fffad400000 r-xp 00000000 00:00 0 [vdso]<br>
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]<br>
zsh: abort ./ruby -rjson -ve 'a = []; a << a; puts JSON.dump(a)'</p>
Ruby master - Bug #5728 (Closed): SystemExit.new(bool, message)
https://bugs.ruby-lang.org/issues/5728
2011-12-08T17:45:31Z
akr (Akira Tanaka)
akr@fsij.org
<p>I found SystemExit.new doesn't take a bool as exit status:</p>
<p>It works well if an integer is given for status.</p>
<p>% ./ruby -e 'SystemExit.new(0, "msg")'<br>
% ./ruby -e 'SystemExit.new(1, "msg")'</p>
<p>But it doesn't work if the status is a bool.</p>
<p>% ./ruby -e 'SystemExit.new(true, "msg")'<br>
-e:1:in <code>initialize': wrong number of arguments (2 for 0..1) (ArgumentError) from -e:1:in </code>initialize'<br>
from -e:1:in <code>new' from -e:1:in </code>'<br>
% ./ruby -e 'SystemExit.new(false, "msg")'<br>
-e:1:in <code>initialize': wrong number of arguments (2 for 0..1) (ArgumentError) from -e:1:in </code>initialize'<br>
from -e:1:in <code>new' from -e:1:in </code>'</p>
<p>% ./ruby -v<br>
ruby 2.0.0dev (2011-12-08 trunk 33981) [x86_64-linux]</p>
<p>I think SystemExit.new should accept a bool.</p>
Ruby master - Feature #5726 (Closed): Process::EXIT_SUCCESS and Process::EXIT_FAILURE
https://bugs.ruby-lang.org/issues/5726
2011-12-08T14:15:38Z
akr (Akira Tanaka)
akr@fsij.org
<p>I'd like to define Process::EXIT_SUCCESS and Process::EXIT_FAILURE.</p>
<p>I want to use them to test my command line application.<br>
The test calls the main routine of the application and<br>
traps SystemExit.<br>
I'd like to compare status of the exception and EXIT_SUCCESS/EXIT_FAILURE<br>
but Ruby doesn't have constants for them.</p>
<p>Note that the test doesn't spawn a process.<br>
So, there is no Process::Status object and Process::Status#success? is not usable.</p>
Ruby master - Bug #5708 (Closed): Tempfile.new(pre) with block in test_autoclose
https://bugs.ruby-lang.org/issues/5708
2011-12-04T23:46:14Z
akr (Akira Tanaka)
akr@fsij.org
<p>気がついたのですが、test/ruby/test_io.rb の test_autoclose で、<br>
Tempfile.new をブロック付きで使っています。</p>
<p>Tempfile.new はブロックを呼び出さないので、バグではないかと思われます。</p>
<p>test/ruby/test_io.rb:</p>
<p>def test_autoclose<br>
feature2250 = '<a href="/issues/2250">[ruby-core:26222]</a>'<br>
pre = 'ft2250'</p>
<pre><code>Tempfile.new(pre) do |t|
f = IO.for_fd(t.fileno)
assert_equal(true, f.autoclose?)
f.autoclose = false
assert_equal(false, f.autoclose?)
f.close
assert_nothing_raised(Errno::EBADF) {t.close}
t.open
f = IO.for_fd(t.fileno, autoclose: false)
assert_equal(false, f.autoclose?)
f.autoclose = true
assert_equal(true, f.autoclose?)
f.close
assert_raise(Errno::EBADF) {t.close}
end
Tempfile.new(pre) do |t|
try_fdopen(t.fileno)
assert_raise(Errno::EBADF) {t.close}
end
Tempfile.new(pre) do |t|
try_fdopen(f.fileno, false)
assert_nothing_raised(Errno::EBADF) {t.close}
end
</code></pre>
<p>end</p>
Ruby master - Feature #5707 (Closed): temporary file creation without finalizer and delegate.
https://bugs.ruby-lang.org/issues/5707
2011-12-04T23:31:56Z
akr (Akira Tanaka)
akr@fsij.org
<p>Tempfile always uses finalizer and delegate.<br>
Sometimes we don't need them.</p>
<p>For example, following test creates a temporary file<br>
using Tempfile.open but the file is used only in the block.<br>
The file is removed when the Tempfile object is collected but<br>
it is possible to remove just after the block return.</p>
<p>test/ruby/test_io.rb:<br>
def test_fcntl_dupfd<br>
Tempfile.open(self.class.name) do |f|<br>
fd = f.fcntl(Fcntl::F_DUPFD, 63)<br>
begin<br>
assert_operator(fd, :>=, 63)<br>
ensure<br>
IO.for_fd(fd).close<br>
end<br>
end<br>
end</p>
<p>So I propose a method, Tempfile.open2, to create temporary file without finalizer and delegate.</p>
<p>The arguments of Tempfile.open2 is same as Tempfile.open.<br>
The return value is File object instead of Tempfile object.</p>
<p>If a block is given, the temporary file is removed after the block returns.</p>
<p>If a block is not given, the temporary file is not removed.<br>
It should be removed using File.unlink.<br>
Non-block form can be used to create non-temporary file.<br>
If you need to change temporary file to non-temporary file, File.rename can be used.</p>
<p>I made a patch to implement Tempfile.open2.<br>
I also made a patch to change tests to use Tempfile.open2 to show usage of it.</p>
<p>A problem of this proposal is the method name.<br>
Tempfile.open2 is not a good name.<br>
Better idea is welcome.</p>
Ruby master - Bug #5577 (Closed): test/testunit/test_parallel.rb causes NoMethodError when file d...
https://bugs.ruby-lang.org/issues/5577
2011-11-06T13:17:35Z
akr (Akira Tanaka)
akr@fsij.org
<p>ulimit -n 30 として、file descriptor を 30個に制限した状態で、<br>
test/testunit/test_parallel.rb をテストすると以下のように失敗します。</p>
<p>失敗する事自体は問題ではないのですが、<br>
undefined method <code>close' for nil:NilClass (NoMethodError) NoMethodError: undefined method </code>chomp' for nil:NilClass<br>
などと存在しないメソッドを呼んでしまっているのはよろしくないのではないでしょうか。</p>
<p>失敗の原因がわかるメッセージが出ると良いのではないかと思います。</p>
<p>% (ulimit -n 30; make test-all TESTS='test/testunit/test_parallel.rb')<br>
./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems "./test/runner.rb" --ruby="./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems" test/testunit/test_parallel.rb<br>
Run options: "--ruby=./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems"</p>
<a name="Running-tests"></a>
<h1 >Running tests:<a href="#Running-tests" class="wiki-anchor">¶</a></h1>
<p>.FFFF/home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:137:in <code>ensure in run': undefined method </code>close' for nil:NilClass (NoMethodError)<br>
from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:138:in <code>run' from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:156:in </code>'<br>
F/home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:137:in <code>ensure in run': undefined method </code>close' for nil:NilClass (NoMethodError)<br>
from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:138:in <code>run' from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:156:in </code>'<br>
F/home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:137:in <code>ensure in run': undefined method </code>close' for nil:NilClass (NoMethodError)<br>
from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:138:in <code>run' from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:156:in </code>'<br>
E/home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:137:in <code>ensure in run': undefined method </code>close' for nil:NilClass (NoMethodError)<br>
from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:138:in <code>run' from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:156:in </code>'<br>
F/home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:137:in <code>ensure in run': undefined method </code>close' for nil:NilClass (NoMethodError)<br>
from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:138:in <code>run' from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:156:in </code>'<br>
F/home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:137:in <code>ensure in run': undefined method </code>close' for nil:NilClass (NoMethodError)<br>
from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:138:in <code>run' from /home/akr/ruby/tst2/ruby/test/testunit/../../lib/test/unit/parallel.rb:156:in </code>'<br>
F</p>
<p>Finished tests in 5.751803s, 1.9124 tests/s, 1.9124 assertions/s.</p>
<pre><code>1) Failure:
</code></pre>
<p>test_jobs_status(TestParallel::TestParallel) [/home/akr/ruby/tst2/ruby/test/testunit/test_parallel.rb:177]:<br>
Expected /\d+=ptest_(first|second|third|forth) */ to match "Run options: --ruby "./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems" -j t1 --jobs-status\n\n# Running tests:\n\n/home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:137:in <code>ensure in run': undefined method </code>close' for nil:NilClass (NoMethodError)\n\tfrom /home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:138:in <code>run'\n\tfrom /home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:156:in </code>'\n\nSome worker was crashed. It seems ruby interpreter's bug\nor, a bug of test/unit/parallel.rb. try again without -j\noption.\n\n".</p>
<pre><code>2) Failure:
</code></pre>
<p>test_no_retry_option(TestParallel::TestParallel) [/home/akr/ruby/tst2/ruby/test/testunit/test_parallel.rb:171]:<br>
Expected /^ +\d+) Failure:\ntest_fail_at_worker(TestD)/ to match "Run options: --ruby "./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems" -j t1 --no-retry\n\n# Running tests:\n\n/home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:137:in <code>ensure in run': undefined method </code>close' for nil:NilClass (NoMethodError)\n\tfrom /home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:138:in <code>run'\n\tfrom /home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:156:in </code>'\n\nSome worker was crashed. It seems ruby interpreter's bug\nor, a bug of test/unit/parallel.rb. try again without -j\noption.\n\n".</p>
<pre><code>3) Failure:
</code></pre>
<p>test_should_retry_failed_on_workers(TestParallel::TestParallel) [/home/akr/ruby/tst2/ruby/test/testunit/test_parallel.rb:164]:<br>
Expected /^Retrying.+$/ to match "Run options: --ruby "./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems" -j t1\n\n# Running tests:\n\n/home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:137:in <code>ensure in run': undefined method </code>close' for nil:NilClass (NoMethodError)\n\tfrom /home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:138:in <code>run'\n\tfrom /home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:156:in </code>'\n\nSome worker was crashed. It seems ruby interpreter's bug\nor, a bug of test/unit/parallel.rb. try again without -j\noption.\n\n".</p>
<pre><code>4) Failure:
</code></pre>
<p>test_should_run_all_without_any_leaks(TestParallel::TestParallel) [/home/akr/ruby/tst2/ruby/test/testunit/test_parallel.rb:158]:<br>
Expected /^[SF.]{7}$/ to match "Run options: --ruby "./miniruby -I./lib -I. -I.ext/common ./tool/runruby.rb --extout=.ext -- --disable-gems" -j t1\n\n# Running tests:\n\n/home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:137:in <code>ensure in run': undefined method </code>close' for nil:NilClass (NoMethodError)\n\tfrom /home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:138:in <code>run'\n\tfrom /home/akr/ruby/tst2/ruby/lib/test/unit/parallel.rb:156:in </code>'\n\nSome worker was crashed. It seems ruby interpreter's bug\nor, a bug of test/unit/parallel.rb. try again without -j\noption.\n\n".</p>
<pre><code>5) Failure:
</code></pre>
<p>test_accept_run_command_multiple_times(TestParallel::TestParallelWorker) [/home/akr/ruby/tst2/ruby/test/testunit/test_parallel.rb:64]:<br>
Expected /^ready/ to match nil.</p>
<pre><code>6) Failure:
</code></pre>
<p>test_run(TestParallel::TestParallelWorker) [/home/akr/ruby/tst2/ruby/test/testunit/test_parallel.rb:40]:<br>
Expected /^ready/ to match nil.</p>
<pre><code>7) Failure:
</code></pre>
<p>test_run_multiple_testcase_in_one_file(TestParallel::TestParallelWorker) [/home/akr/ruby/tst2/ruby/test/testunit/test_parallel.rb:51]:<br>
Expected /^ready/ to match nil.</p>
<pre><code>8) Failure:
</code></pre>
<p>test_quit(TestParallel::TestParallelWorker) [/home/akr/ruby/tst2/ruby/test/testunit/test_parallel.rb:116]:<br>
Expected /^bye$/m to match "".</p>
<pre><code>9) Failure:
</code></pre>
<p>test_done(TestParallel::TestParallelWorker) [/home/akr/ruby/tst2/ruby/test/testunit/test_parallel.rb:96]:<br>
Expected /^done (.+?)$/ to match nil.</p>
<ol start="10">
<li>Error:<br>
test_p(TestParallel::TestParallelWorker):<br>
NoMethodError: undefined method <code>chomp' for nil:NilClass /home/akr/ruby/tst2/ruby/test/testunit/test_parallel.rb:86:in </code>block in test_p'</li>
</ol>
<p>11 tests, 11 assertions, 9 failures, 1 errors, 0 skips</p>
<p>ruby -v: ruby 2.0.0dev (2011-11-06 trunk 33645) [x86_64-linux]<br>
make: *** [yes-test-all] エラー 10<br>
zsh: exit 2 ( ulimit -n 30; make test-all TESTS='test/testunit/test_parallel.rb'; )<br>
% ./ruby -v<br>
ruby 2.0.0dev (2011-11-06 trunk 33645) [x86_64-linux]</p>
Ruby master - Bug #5084 (Closed): Re: [ruby-changes:20573] nobu:r32621 (trunk): * object.c (rb_m...
https://bugs.ruby-lang.org/issues/5084
2011-07-23T12:08:29Z
akr (Akira Tanaka)
akr@fsij.org
<p>2011/7/22 nobu <a href="mailto:ko1@atdot.net" class="email">ko1@atdot.net</a>:</p>
<blockquote>
<p>nobu 2011-07-22 21:06:42 +0900 (Fri, 22 Jul 2011)</p>
<p>New Revision: 32621</p>
<p><a href="http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32621" class="external">http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32621</a></p>
<p>Log:</p>
<ul>
<li>object.c (rb_mod_{const,cvar}_defined, rb_obj_ivar_defined):<br>
avoid inadvertent symbol creation in reflection methods. based<br>
on a patch by Jeremy Evans at <a href="/issues/5072">[ruby-core:38367]</a>. [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed behind-schedule" title="Feature: Avoid inadvertent symbol creation in reflection methods (Closed)" href="https://bugs.ruby-lang.org/issues/5072">#5072</a>]</li>
<li>vm_method.c (rb_mod_method_defined)<br>
(rb_mod_{public,private,protected}_method_defined)<br>
(obj_respond_to): ditto.</li>
<li>parse.y (rb_check_id): new function returns already interned ID<br>
or 0.</li>
</ul>
</blockquote>
<p>これ以降、RSS のテストで失敗して、RubySpec で SEGV しています。</p>
<a name="httpwwwrubyistnetakrchkbuilddebianruby-trunklog20110722T122400Zdiffhtmlgz"></a>
<h2 ><a href="http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20110722T122400Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20110722T122400Z.diff.html.gz</a><a href="#httpwwwrubyistnetakrchkbuilddebianruby-trunklog20110722T122400Zdiffhtmlgz" class="wiki-anchor">¶</a></h2>
<p>[田中 哲][たなか あきら][Tanaka Akira]</p>
Ruby master - Feature #5041 (Closed): Set FD_CLOEXEC for all fds (except 0, 1, 2)
https://bugs.ruby-lang.org/issues/5041
2011-07-18T01:15:44Z
akr (Akira Tanaka)
akr@fsij.org
<p>I'd like to set FD_CLOEXEC for all file descriptors (except 0, 1, 2,<br>
i.e. standard input/output/error).</p>
<p>I talked this issue with kosaki and matz at RubyKaigi 2011 and<br>
matz said "do it" and see that someone will cry or not.</p>
<p>FD_CLOEXEC prevents fd leakage for command execution.<br>
See the problem of fd leakage for<br>
"FIO42-C. Ensure files are properly closed when they are no longer needed".<br>
<a href="https://www.securecoding.cert.org/confluence/display/seccode/FIO42-C.+Ensure+files+are+properly+closed+when+they+are+no+longer+needed" class="external">https://www.securecoding.cert.org/confluence/display/seccode/FIO42-C.+Ensure+files+are+properly+closed+when+they+are+no+longer+needed</a></p>
<p>This is an incompatible change for programs which use fd leakage intentionally.<br>
For example, valgrind has options such as --log-fd=, --input-fd=, etc.<br>
gpg has --status-fd, --logger-fd, etc.<br>
openssl command has -passin fd:number and -passout fd:number.<br>
xterm has -S option which takes a fd.<br>
...</p>
<p>Currently, system() and exec() method leak fds.<br>
But IO.popen() and spawn() doesn't leak fds.<br>
Windows doesn't inherit fds for child processes.<br>
So this issue is only affected to system() and exec() on Unix.</p>
<p>(spawn(), which is available since Ruby 1.9.1, doesn't leak fds because<br>
:close_others option is true by default.<br>
IO.popen() doesn't leak fds since <a href="https://blade.ruby-lang.org/ruby-dev/457">[ruby-dev:457]</a>.<br>
The behavior is preserved for Ruby 1.9 by :close_others is true by default<br>
for IO.popen().)</p>
<p>If a program uses fd leakage, system() and exec() call should be changed.<br>
For example,<br>
system("valgrind", "--log-fd=#{N}", ...) should be changed to<br>
system("valgrind", "--log-fd=#{N}", ..., N=>N).<br>
See the document of spawn() for details of the option N=>N.<br>
This option, N=>N, can be used since Ruby 1.9.1.</p>
<p>FD_CLOEXEC is set by fcntl(F_SETFD) on Unix.<br>
However Ruby can use O_CLOEXEC, dup3 and other new mechanisms to avoid<br>
race conditions if they are available.</p>
<p>The race condition is real problem because Ruby invokes open() system call in<br>
a blocking region to open a named pipe without stucking.<br>
So, new fd can be born at any point.<br>
This means the new fd (without FD_CLOEXEC) may be born just before fork().<br>
This race can be fixed by O_CLOEXEC (if available).<br>
The semantics of "FD_CLOEXEC for all fds" makes us possible to use O_CLOEXEC<br>
without harm.</p>
Ruby master - Bug #5039 (Closed): Re: socket related errors on chkbuild
https://bugs.ruby-lang.org/issues/5039
2011-07-17T21:34:58Z
akr (Akira Tanaka)
akr@fsij.org
<p>2011年7月16日23:09 Tanaka Akira <a href="mailto:akr@fsij.org" class="email">akr@fsij.org</a>:</p>
<blockquote>
<blockquote>
<ol>
<li>Error:<br>
test_write_nonblock(OpenSSL::TestPair):</li>
</ol>
</blockquote>
<p>これは原因が違うようで、直っていません。</p>
</blockquote>
<p>これが起き始めたのはそんなに古くないのですね。<br>
<a href="http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20110624T071200Z.diff.html.gz" class="external">http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20110624T071200Z.diff.html.gz</a><br>
からなんですが、</p>
<p>+Fri Jun 24 15:54:14 2011 Hiroshi Nakamura <a href="mailto:nahi@ruby-lang.org" class="email">nahi@ruby-lang.org</a><br>
+</p>
<ul>
<li>
<pre><code> * ext/openssl/ossl_ssl.c (ossl_ssl_shutdown): Try to shutdown SSL
</code></pre>
</li>
<li>
<pre><code> connection more gracefully. Call SSL_shutdown() max 4 times until it
</code></pre>
</li>
<li>
<pre><code> returns 1 (success). Bi-directional SSL close has several states but
</code></pre>
</li>
<li>
<pre><code> SSL_shutdown() kicks only 1 transition per call. Max 4 is from
</code></pre>
</li>
<li>
<pre><code> mod_ssl.c of Apache httpd that says 'max 2x pending + 2x data = 4'.
</code></pre>
</li>
<li>
<pre><code> See #4237.
</code></pre>
</li>
</ul>
<a name="というコミット以来のようです"></a>
<h2 >というコミット以来のようです。<a href="#というコミット以来のようです" class="wiki-anchor">¶</a></h2>
<p>[田中 哲][たなか あきら][Tanaka Akira]</p>
Ruby master - Feature #4351 (Closed): Server Name Indication (SNI) for net/http
https://bugs.ruby-lang.org/issues/4351
2011-01-31T21:11:49Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
ふと、SSL で name based vitual をやる話 (SNI - RFC 3546) はどうなったんだっけ、<br>
と思って探したら、以下を見つけたので、net/http にも対処を<br>
入れるのはどうですかね。</p>
<p>ssl - OpenSSL Server Name Indication support in Ruby - Stack Overflow<br>
<a href="http://stackoverflow.com/questions/4685736/openssl-server-name-indication-support-in-ruby" class="external">http://stackoverflow.com/questions/4685736/openssl-server-name-indication-support-in-ruby</a></p>
<p>対処を入れると、以下がエラーにならなくなります。</p>
<p>ruby -ropen-uri -e 'URI("<a href="https://gmail.com/.well-known/host-meta%22).read" class="external">https://gmail.com/.well-known/host-meta").read</a>'</p>
<h1>% svn diff --diff-cmd diff -x -u lib/net/http.rb<br>
Index: lib/net/http.rb</h1>
<p>--- lib/net/http.rb (revision 30734)<br>
+++ lib/net/http.rb (working copy)<br>
@@ -780,6 +780,7 @@<br>
@socket.writeline ''<br>
HTTPResponse.read_new(@socket).value<br>
end</p>
<ul>
<li>
<pre><code> s.hostname = @address
timeout(@open_timeout) { s.connect }
if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
s.post_connection_check(@address)
</code></pre>
</li>
</ul>
<p>--<br>
[田中 哲][たなか あきら][Tanaka Akira]<br>
=end</p>
Ruby master - Feature #4151 (Rejected): Enumerable#categorize
https://bugs.ruby-lang.org/issues/4151
2010-12-12T20:14:17Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
Hi.</p>
<p>How about a method for converting enumerable to hash?</p>
<p>enum.categorize([opts]) {|elt| [key1, ..., val] } -> hash</p>
<p>categorizes the elements in <em>enum</em> and returns a hash.</p>
<p>The block is called for each elements in <em>enum</em>.<br>
The block should return an array which contains<br>
one or more keys and one value.</p>
<p>p (0..10).categorize {|e| [e % 3, e % 5] }<br>
#=> {0=>[0, 3, 1, 4], 1=>[1, 4, 2, 0], 2=>[2, 0, 3]}</p>
<p>The keys and value are used to construct the result hash.<br>
If two or more keys are provided<br>
(i.e. the length of the array is longer than 2),<br>
the result hash will be nested.</p>
<p>p (0..10).categorize {|e| [e&4, e&2, e&1, e] }<br>
#=> {0=>{0=>{0=>[0, 8],</p>
<a name="1gt1-9"></a>
<h1 >1=>[1, 9]},<a href="#1gt1-9" class="wiki-anchor">¶</a></h1>
<a name="2gt0gt2-10"></a>
<h1 >2=>{0=>[2, 10],<a href="#2gt0gt2-10" class="wiki-anchor">¶</a></h1>
<a name="1gt3"></a>
<h1 >1=>[3]}},<a href="#1gt3" class="wiki-anchor">¶</a></h1>
<a name="4gt0gt0gt4"></a>
<h1 >4=>{0=>{0=>[4],<a href="#4gt0gt0gt4" class="wiki-anchor">¶</a></h1>
<a name="1gt5"></a>
<h1 >1=>[5]},<a href="#1gt5" class="wiki-anchor">¶</a></h1>
<a name="2gt0gt6"></a>
<h1 >2=>{0=>[6],<a href="#2gt0gt6" class="wiki-anchor">¶</a></h1>
<a name="1gt7"></a>
<h1 >1=>[7]}}}<a href="#1gt7" class="wiki-anchor">¶</a></h1>
<p>The value of innermost hash is an array which contains values for<br>
corresponding keys.<br>
This behavior can be customized by :seed, :op and :update option.</p>
<p>This method can take an option hash.<br>
Available options are follows:</p>
<ul>
<li>:seed specifies seed value.</li>
<li>:op specifies a procedure from seed and value to next seed.</li>
<li>:update specifies a procedure from seed and block value to next seed.</li>
</ul>
<p>:seed, :op and :update customizes how to generate<br>
the innermost hash value.<br>
:seed and :op behavies like Enumerable#inject.</p>
<p>If <em>seed</em> and <em>op</em> is specified, the result value is generated as follows.<br>
op.call(..., op.call(op.call(seed, v0), v1), ...)</p>
<p>:update works as :op except the second argument is the block value itself<br>
instead of the last value of the block value.</p>
<p>If :seed option is not given, the first value is used as the seed.</p>
<a name="The-arguments-for-op-option-procedure-are-the-seed-and-the-value"></a>
<h1 >The arguments for :op option procedure are the seed and the value.<a href="#The-arguments-for-op-option-procedure-are-the-seed-and-the-value" class="wiki-anchor">¶</a></h1>
<a name="ie-the-last-element-of-the-array-returned-from-the-block"></a>
<h1 >(i.e. the last element of the array returned from the block.)<a href="#ie-the-last-element-of-the-array-returned-from-the-block" class="wiki-anchor">¶</a></h1>
<p>r = [0].categorize(:seed => :s,<br>
:op => lambda {|x,y|<br>
p [x,y] #=> [:s, :v]<br>
1<br>
}) {|e|<br>
p e #=> 0<br>
[:k, :v]<br>
}<br>
p r #=> {:k=>1}</p>
<a name="The-arguments-for-update-option-procedure-are-the-seed-and-the-array"></a>
<h1 >The arguments for :update option procedure are the seed and the array<a href="#The-arguments-for-update-option-procedure-are-the-seed-and-the-array" class="wiki-anchor">¶</a></h1>
<a name="returned-from-the-block"></a>
<h1 >returned from the block.<a href="#returned-from-the-block" class="wiki-anchor">¶</a></h1>
<p>r = [0].categorize(:seed => :s,<br>
:update => lambda {|x,y|<br>
p [x,y] #=> [:s, [:k, :v]]<br>
1<br>
}) {|e|<br>
p e #=> 0<br>
[:k, :v]<br>
}<br>
p r #=> {:k=>1}</p>
<p>The default behavior, array construction, can be implemented as follows.<br>
:seed => nil<br>
:op => lambda {|s, v| !s ? [v] : (s << v) }</p>
<p>Note that matz doesn't find satisfact in the method name, "categorize".<br>
<a href="https://blade.ruby-lang.org/ruby-dev/42681">[ruby-dev:42681]</a></p>
<h2>Also note that matz wants another method than this method,<br>
which the hash value is the last value, not an array of all values.<br>
This can be implemented by enum.categorize(:op=>lambda {|x,y| y}) { ... }.<br>
But good method name is not found yet.<br>
<a href="https://blade.ruby-lang.org/ruby-dev/42643">[ruby-dev:42643]</a></h2>
<p>Tanaka Akira</p>
<p>Attachment: enum-categorize.patch<br>
=end</p>
Ruby master - Bug #4063 (Closed): Array#to_csv(ascii-subset-of-iso-8859-1, utf-8)
https://bugs.ruby-lang.org/issues/4063
2010-11-17T11:46:11Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
Array#to_csv still has an encoding problem.</p>
<p>% ./ruby -rcsv -ve '<br>
a = ["foo".force_encoding("ISO-8859-1"), "\u3042"]<br>
puts a[0].dump<br>
puts a[1].dump<br>
p a.map {|v| v.encoding }<br>
s = a.to_csv<br>
puts s.dump<br>
p s.encoding'<br>
ruby 1.9.3dev (2010-11-17 trunk 29809) [i686-linux]<br>
"foo"<br>
"\u{3042}"<br>
[#<a href="Encoding:ISO-8859-1" class="external">Encoding:ISO-8859-1</a>, #<a href="Encoding:UTF-8" class="external">Encoding:UTF-8</a>]<br>
"foo,\xE3\x81\x82\n"<br>
#<a href="Encoding:ISO-8859-1" class="external">Encoding:ISO-8859-1</a></p>
<p>The encoding of the first string is ISO-8859-1 but<br>
contains only ASCII characters.</p>
<p>The encoding of the second string is UTF-8 and<br>
contains a UTF-8 (non-ASCII, non-ISO-8859-1) character.<br>
(The character U+3042 is HIRAGANA LETTER A.)</p>
<h2>The encoding of the result of Array#to_csv is ISO-8859-1 but<br>
it contains the bytes of HIRAGANA LETTER A in UTF-8.</h2>
<p>Tanaka Akira<br>
=end</p>
Ruby master - Bug #4041 (Closed): Array#to_csv generates invalid US-ASCII string
https://bugs.ruby-lang.org/issues/4041
2010-11-11T07:58:18Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
I found Array#to_csv method generates a string with invalid encoding.</p>
<p>% ./ruby -rcsv -ve '<br>
a = ["foo".force_encoding("US-ASCII"), "\u3042"]<br>
p a.map {|v| v.encoding }<br>
s = a.to_csv<br>
p s<br>
p s.encoding'<br>
ruby 1.9.3dev (2010-11-10 trunk 29738) [i686-linux]<br>
[#<a href="Encoding:US-ASCII" class="external">Encoding:US-ASCII</a>, #<a href="Encoding:UTF-8" class="external">Encoding:UTF-8</a>]<br>
"foo,\xE3\x81\x82\n"<br>
#<a href="Encoding:US-ASCII" class="external">Encoding:US-ASCII</a></p>
<p>The array to convert to CSV using Array#to_csv contains US-ASCII string and<br>
UTF-8 string.<br>
But the result is US-ASCII string which contains 8-bit bytes.</p>
<a name="I-think-the-result-should-be-UTF-8-string"></a>
<h2 >I think the result should be UTF-8 string.<a href="#I-think-the-result-should-be-UTF-8-string" class="wiki-anchor">¶</a></h2>
<p>Tanaka Akira<br>
=end</p>
Backport192 - Backport #3662 (Closed): call File.lchmod via rb_funcall [BUG] vm_call0: unsupport...
https://bugs.ruby-lang.org/issues/3662
2010-08-07T09:40:59Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
unimplemented method を rb_funcall で呼び出すと [BUG] になるようです。</p>
<p>pathname で Pathname#lchmod を実装するのに File.lchmod を呼び出そうとして<br>
rb_funcall(rb_cFile, rb_intern("lchmod"), 2, mode, get_strpath(self))<br>
としたら、File.lchmod が unimplemented method な GNU/Linux では、以下のように<br>
[BUG] vm_call0: unsupported method type (7)<br>
となりました。</p>
<p>% ./ruby -rpathname -e 'Pathname("foo").lchmod(nil)'<br>
-e:1: [BUG] vm_call0: unsupported method type (7)<br>
ruby 1.9.3dev (2010-08-07 trunk 28891) [i686-linux]</p>
<h2>-- control frame ----------<br>
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC :lchmod<br>
c:0003 p:0018 s:0006 b:0006 l:000ff4 d:0021ec EVAL -e:1<br>
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH<br>
c:0001 p:0000 s:0002 b:0002 l:000ff4 d:000ff4 TOP</h2>
<p>-- Ruby level backtrace information ----------------------------------------<br>
-e:1:in <code><main>' -e:1:in </code>lchmod'</p>
<p>-- C level backtrace information -------------------------------------------<br>
./ruby [0x8155332]<br>
./ruby [0x818a7cf]<br>
./ruby(rb_bug+0x36) [0x818a82a]<br>
./ruby [0x814d630]<br>
./ruby [0x814e404]<br>
./ruby [0x814e357]<br>
./ruby(rb_funcall+0xa2) [0x814e4ae]<br>
/tmp/o0/lib/ruby/1.9.1/i686-linux/pathname.so [0xb77c68da]<br>
./ruby [0x814a426]<br>
./ruby [0x814a2c9]<br>
./ruby [0x814989d]<br>
./ruby [0x814548a]<br>
./ruby [0x81526b6]<br>
./ruby [0x8152e8f]<br>
./ruby [0x805b262]<br>
./ruby(ruby_exec_node+0x1c) [0x805b36b]<br>
./ruby(ruby_run_node+0x3b) [0x805b33f]<br>
./ruby [0x8059d88]<br>
/lib/i686/cmov/libc.so.6(__libc_start_main+0xe5) [0xb75f0455]<br>
./ruby [0x8059c81]</p>
<p>[NOTE]<br>
You may have encountered a bug in the Ruby interpreter or extension libraries.<br>
Bug reports are welcome.<br>
For details: <a href="http://www.ruby-lang.org/bugreport.html" class="external">http://www.ruby-lang.org/bugreport.html</a></p>
<p>zsh: abort ./ruby -rpathname -e 'Pathname("foo").lchmod(nil)'</p>
<p>なお、File.lchmod を Ruby から呼び出すのは問題なく可能です。</p>
<h2>% ./ruby -e 'File.lchmod(nil, "foo")'<br>
-e:1:in <code>lchmod': lchmod() function is unimplemented on this machine (NotImplementedError) from -e:1:in </code>'</h2>
<p>[田中 哲][たなか あきら][Tanaka Akira]<br>
=end</p>
Ruby master - Bug #3605 (Closed): undefined symbol: strlcpy
https://bugs.ruby-lang.org/issues/3605
2010-07-23T06:43:16Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
以下のように test_pty.rb で undefined symbol: strlcpy になります。</p>
<h2>% ./ruby test/test_pty.rb<br>
Loaded suite test/test_pty<br>
Started<br>
./ruby: symbol lookup error:<br>
/home/akr/chkbuild/tmp/build/ruby-trunk/20100723T040700/lib/ruby/1.9.1/i686-linux/pty.so:<br>
undefined symbol: strlcpy<br>
zsh: exit 127 ./ruby test/test_pty.rb<br>
% ./ruby -v<br>
ruby 1.9.3dev (2010-07-22 trunk 28717) [i686-linux]</h2>
<p>[田中 哲][たなか あきら][Tanaka Akira]<br>
=end</p>
Ruby master - Bug #3582 (Closed): test file don't run test.
https://bugs.ruby-lang.org/issues/3582
2010-07-17T14:32:08Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
以下のようにテストを実行してもテストされません。</p>
<p>% ./ruby test/test_find.rb<br>
% ./ruby -v<br>
ruby 1.9.3dev (2010-07-17 trunk 28662) [i686-linux]</p>
<p>本来は、以下のようにテストが動作するはずです。</p>
<p>% ./ruby test/test_find.rb<br>
Loaded suite test/test_find<br>
Started<br>
...............<br>
Finished in 0.009122 seconds.</p>
<p>15 tests, 17 assertions, 0 failures, 0 errors, 0 skips</p>
<a name="Test-run-options-seed-59714"></a>
<h2 >Test run options: --seed 59714<a href="#Test-run-options-seed-59714" class="wiki-anchor">¶</a></h2>
<p>[田中 哲][たなか あきら][Tanaka Akira]<br>
=end</p>
Ruby master - Bug #3543 (Third Party's Issue): GNU/Linux select hang on a socket which TCP state ...
https://bugs.ruby-lang.org/issues/3543
2010-07-06T22:21:54Z
akr (Akira Tanaka)
akr@fsij.org
<p>GNU/Linux で、以下のプログラムがハングします。</p>
<p>% uname -mrsv<br>
Linux 2.6.26-2-486 #1 Sat Dec 26 08:37:39 UTC 2009 i686<br>
% ./ruby -rsocket -ve '<br>
BasicSocket.do_not_reverse_lookup = true<br>
serv = TCPServer.open("127.0.0.1", 0)<br>
s1 = TCPSocket.open("127.0.0.1", serv.addr[1])<br>
s2 = serv.accept<br>
s2.close<br>
s1.write("a") rescue p $!<br>
s1.write("a") rescue p $!<br>
Thread.new {<br>
s1.write("a")<br>
}.join'<br>
ruby 1.9.3dev (2010-07-06 trunk 28554) [i686-linux]<br>
#<Errno::EPIPE: Broken pipe><br>
ここでハング</p>
<p>FreeBSD ではハングしません。</p>
<p>% ./ruby -rsocket -ve '<br>
BasicSocket.do_not_reverse_lookup = true<br>
serv = TCPServer.open("127.0.0.1", 0)<br>
s1 = TCPSocket.open("127.0.0.1", serv.addr[1])<br>
s2 = serv.accept<br>
s2.close<br>
s1.write("a") rescue p $!<br>
s1.write("a") rescue p $!<br>
Thread.new {<br>
s1.write("a")<br>
}.join'<br>
ruby 1.9.3dev (2010-07-06 trunk 28554) [i386-freebsd8.0]<br>
#<Errno::EPIPE: Broken pipe><br>
-e:10:in <code>write': Broken pipe (Errno::EPIPE) from -e:10:in </code>block in '</p>
<p>まぁ、<a href="https://blade.ruby-lang.org/ruby-core/31065">[ruby-core:31065]</a>, <a href="https://blade.ruby-lang.org/ruby-core/31068">[ruby-core:31068]</a> の話なんですが。</p>
<a name="そういえばruby-dev34567-というのもありましたが同じかな"></a>
<h2 >そういえば、<a href="https://blade.ruby-lang.org/ruby-dev/34567">[ruby-dev:34567]</a> というのもありましたが同じかな。<a href="#そういえばruby-dev34567-というのもありましたが同じかな" class="wiki-anchor">¶</a></h2>
<p>[田中 哲][たなか あきら][Tanaka Akira]</p>
Ruby master - Bug #3542 (Closed): Psych dumps the timezone offset incorrectly at Newfoundland
https://bugs.ruby-lang.org/issues/3542
2010-07-06T11:47:38Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
Psych dumps the timezone offset incorrectly at Newfoundland.</p>
<p>% TZ=Canada/Newfoundland date '+%z'<br>
-0230<br>
% TZ=Canada/Newfoundland ./ruby -rpsych -e 't = Time.now; p t, Psych.dump(t)'<br>
2010-07-06 00:13:03 -0230<br>
"--- 2010-07-06 00:13:03.676510668 -03:30\n"<br>
% ./ruby -v<br>
ruby 1.9.3dev (2010-07-06 trunk 28554) [i686-linux]</p>
<a name="The-timezone-offset-should-be-0230-but-psych-outputs-0330"></a>
<h2 >The timezone offset should be -02:30 but psych outputs -03:30.<a href="#The-timezone-offset-should-be-0230-but-psych-outputs-0330" class="wiki-anchor">¶</a></h2>
<p>Tanaka Akira<br>
=end</p>
Ruby master - Bug #3538 (Closed): psych tests sometimes fail
https://bugs.ruby-lang.org/issues/3538
2010-07-05T22:24:40Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
psych tests sometimes fail.</p>
<p>% ./ruby test/runner.rb psych<br>
Loaded suite test/runner<br>
Started<br>
...(snip)...<br>
Finished in 1.003971 seconds.</p>
<ol>
<li>
<p>Failure:<br>
test_time_utc_no_z(Psych::Visitors::TestToRuby)<br>
[/home/ruby/tcio/ruby/test/psych/visitors/test_to_ruby.rb:134]:<br>
Expected 2010-07-05 13:21:36 UTC, not 2010-07-05 22:21:36 +0900.</p>
</li>
<li>
<p>Failure:<br>
test_time_utc(Psych::Visitors::TestToRuby)<br>
[/home/ruby/tcio/ruby/test/psych/visitors/test_to_ruby.rb:126]:<br>
Expected 2010-07-05 13:21:36 UTC, not 2010-07-05 13:21:36 UTC.</p>
</li>
<li>
<p>Failure:<br>
test_time(Psych::Visitors::TestToRuby)<br>
[/home/ruby/tcio/ruby/test/psych/visitors/test_to_ruby.rb:118]:<br>
Expected 2010-07-05 22:21:36 +0900, not 2010-07-05 22:21:36 +0900.</p>
</li>
<li>
<p>Failure:<br>
test_time(Psych::Visitors::TestYAMLTree)<br>
[/home/ruby/tcio/ruby/test/psych/visitors/test_yaml_tree.rb:57]:<br>
Expected 2010-07-05 22:21:36 +0900, not 2010-07-05 22:21:36 +0900.</p>
</li>
</ol>
<p>321 tests, 954 assertions, 4 failures, 0 errors, 0 skips</p>
<p>Test run options: --seed 25269<br>
zsh: exit 1 ./ruby test/runner.rb psych<br>
% ./ruby -v<br>
ruby 1.9.3dev (2010-07-05 trunk 28542) [i686-linux]</p>
<p>I run psych tests 1000 times.<br>
It seems the 6 tests can fail.</p>
<h2>% grep '^test' log|sort|uniq -c<br>
89 test_round_trip(Psych::TestDateTime)<br>
[/home/ruby/tcio/ruby/test/psych/test_date_time.rb:14]:<br>
101 test_time(Psych::Visitors::TestToRuby)<br>
[/home/ruby/tcio/ruby/test/psych/visitors/test_to_ruby.rb:118]:<br>
100 test_time(Psych::Visitors::TestYAMLTree)<br>
[/home/ruby/tcio/ruby/test/psych/visitors/test_yaml_tree.rb:57]:<br>
111 test_time_now_cycle(Psych_Unit_Tests)<br>
[/home/ruby/tcio/ruby/test/psych/test_yaml.rb:1157]:<br>
102 test_time_utc(Psych::Visitors::TestToRuby)<br>
[/home/ruby/tcio/ruby/test/psych/visitors/test_to_ruby.rb:126]:<br>
101 test_time_utc_no_z(Psych::Visitors::TestToRuby)<br>
[/home/ruby/tcio/ruby/test/psych/visitors/test_to_ruby.rb:134]:</h2>
<p>Tanaka Akira<br>
=end</p>
Ruby master - Bug #3530 (Closed): psych failures at Adelaide
https://bugs.ruby-lang.org/issues/3530
2010-07-03T19:54:54Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
Several psych tests fail as follows when the timezone is set to<br>
Australia/Adelaide.</p>
<p>% ./ruby -v<br>
ruby 1.9.3dev (2010-07-03 trunk 28532) [i686-linux]<br>
% TZ=Australia/Adelaide ./ruby test/runner.rb psych<br>
Loaded suite test/runner<br>
Started<br>
...(snip)...<br>
Finished in 1.000350 seconds.</p>
<ol>
<li>
<p>Failure:<br>
test_round_trip(Psych::TestDateTime)<br>
[/home/ruby/tcstate/ruby/test/psych/test_date_time.rb:14]:<br>
Expected #<DateTime: 2010-07-03T20:21:29+09:30<br>
(212144914289388924893/86400000000000,19/48,2299161)>, not #<DateTime:<br>
2010-07-03T20:51:29+09:30<br>
(212144916089388924893/86400000000000,19/48,2299161)>.</p>
</li>
<li>
<p>Failure:<br>
test_time(Psych::Visitors::TestToRuby)<br>
[/home/ruby/tcstate/ruby/test/psych/visitors/test_to_ruby.rb:118]:<br>
Expected 2010-07-03 20:21:29 +0930, not 2010-07-03 20:51:29 +0930.</p>
</li>
<li>
<p>Failure:<br>
test_time(Psych::Visitors::TestYAMLTree)<br>
[/home/ruby/tcstate/ruby/test/psych/visitors/test_yaml_tree.rb:57]:<br>
Expected 2010-07-03 20:21:29 +0930, not 2010-07-03 20:51:29 +0930.</p>
</li>
<li>
<p>Failure:<br>
test_time_now_cycle(Psych_Unit_Tests)<br>
[/home/ruby/tcstate/ruby/test/psych/test_yaml.rb:1157]:<br>
Expected 2010-07-03 20:21:30 +0930, not 2010-07-03 20:51:30 +0930.</p>
</li>
</ol>
<p>321 tests, 938 assertions, 4 failures, 0 errors, 0 skips</p>
<a name="Test-run-options-seed-57308"></a>
<h2 >Test run options: --seed 57308<a href="#Test-run-options-seed-57308" class="wiki-anchor">¶</a></h2>
<p>Tanaka Akira<br>
=end</p>
Ruby master - Bug #3417 (Closed): undef load and backtrace
https://bugs.ruby-lang.org/issues/3417
2010-06-10T00:18:37Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
以下のようにすると SEGV します。</p>
<p>% cat t.rb<br>
class C<br>
def initialize<br>
<a class="user active user-mention" href="https://bugs.ruby-lang.org/users/52980">@A (A A)</a> = @b = @c = @d = nil<br>
end<br>
end<br>
GC.stress = true<br>
module Kernel<br>
undef load<br>
end<br>
C.new<br>
raise<br>
% ./ruby -ve 'load "t.rb"'<br>
ruby 1.9.3dev (2010-06-08 trunk 28202) [i686-linux]<br>
t.rb:11: [BUG] Segmentation fault<br>
ruby 1.9.3dev (2010-06-08 trunk 28202) [i686-linux]</p>
<p>-- control frame ----------<br>
c:0006 p:0063 s:0014 b:0014 l:000013 d:000013 TOP t.rb:11<br>
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH<br>
zsh: segmentation fault (core dumped) ./ruby -ve 'load "t.rb"'<br>
% RUBY_DEBUG=core ./ruby -ve 'load "t.rb"'<br>
ruby 1.9.3dev (2010-06-08 trunk 28202) [i686-linux]<br>
zsh: segmentation fault (core dumped) RUBY_DEBUG=core ./ruby -ve 'load "t.rb"'<br>
% gdb ruby core.5445<br>
GNU gdb 6.8-debian<br>
Copyright (C) 2008 Free Software Foundation, Inc.<br>
License GPLv3+: GNU GPL version 3 or later <a href="http://gnu.org/licenses/gpl.html" class="external">http://gnu.org/licenses/gpl.html</a><br>
This is free software: you are free to change and redistribute it.<br>
There is NO WARRANTY, to the extent permitted by law. Type "show copying"<br>
and "show warranty" for details.<br>
This GDB was configured as "i486-linux-gnu"...</p>
<p>warning: Can't read pathname for load map: Input/output error.<br>
Reading symbols from /lib/i686/cmov/libpthread.so.0...Reading symbols<br>
from /usr/lib/debug/lib/i686/cmov/libpthread-2.7.so...done.<br>
done.<br>
Loaded symbols for /lib/i686/cmov/libpthread.so.0<br>
Reading symbols from /lib/i686/cmov/librt.so.1...Reading symbols from<br>
/usr/lib/debug/lib/i686/cmov/librt-2.7.so...done.<br>
done.<br>
Loaded symbols for /lib/i686/cmov/librt.so.1<br>
Reading symbols from /lib/i686/cmov/libdl.so.2...Reading symbols from<br>
/usr/lib/debug/lib/i686/cmov/libdl-2.7.so...done.<br>
done.<br>
Loaded symbols for /lib/i686/cmov/libdl.so.2<br>
Reading symbols from /lib/i686/cmov/libcrypt.so.1...Reading symbols<br>
from /usr/lib/debug/lib/i686/cmov/libcrypt-2.7.so...done.<br>
done.<br>
Loaded symbols for /lib/i686/cmov/libcrypt.so.1<br>
Reading symbols from /lib/i686/cmov/libm.so.6...Reading symbols from<br>
/usr/lib/debug/lib/i686/cmov/libm-2.7.so...done.<br>
done.<br>
Loaded symbols for /lib/i686/cmov/libm.so.6<br>
Reading symbols from /lib/i686/cmov/libc.so.6...Reading symbols from<br>
/usr/lib/debug/lib/i686/cmov/libc-2.7.so...done.<br>
done.<br>
Loaded symbols for /lib/i686/cmov/libc.so.6<br>
Reading symbols from /lib/ld-linux.so.2...Reading symbols from<br>
/usr/lib/debug/lib/ld-2.7.so...done.<br>
done.<br>
Loaded symbols for /lib/ld-linux.so.2<br>
Reading symbols from<br>
/home/ruby/tcio/lib/ruby/1.9.1/i686-linux/enc/encdb.so...done.<br>
Loaded symbols for /home/ruby/tcio/lib/ruby/1.9.1/i686-linux/enc/encdb.so<br>
Reading symbols from<br>
/home/ruby/tcio/lib/ruby/1.9.1/i686-linux/enc/euc_jp.so...done.<br>
Loaded symbols for /home/ruby/tcio/lib/ruby/1.9.1/i686-linux/enc/euc_jp.so<br>
Reading symbols from<br>
/home/ruby/tcio/lib/ruby/1.9.1/i686-linux/enc/trans/transdb.so...done.<br>
Loaded symbols for<br>
/home/ruby/tcio/lib/ruby/1.9.1/i686-linux/enc/trans/transdb.so<br>
Core was generated by `./ruby -ve load "t.rb"'.<br>
Program terminated with signal 11, Segmentation fault.<br>
[New process 5445]<br>
[New process 5446]<br>
#0 0x08154da2 in vm_backtrace_each (th=0x87cb030, lev=-2,<br>
init=0x8154dfe <vm_backtrace_alloc>,<br>
iter=0x8154e18 <vm_backtrace_push>, arg=0xbff27034) at vm.c:741<br>
741 id = cfp->me->def->original_id;<br>
(gdb) bt<br>
#0 0x08154da2 in vm_backtrace_each (th=0x87cb030, lev=-2,<br>
init=0x8154dfe <vm_backtrace_alloc>,<br>
iter=0x8154e18 <vm_backtrace_push>, arg=0xbff27034) at vm.c:741<br>
#1 0x08154f86 in vm_backtrace (th=0x87cb030, lev=-1) at vm.c:784<br>
#2 0x08153492 in rb_make_backtrace () at vm_eval.c:1610<br>
#3 0x0805f194 in setup_exception (th=0x87cb030, tag=6,<br>
mesg=142541120) at eval.c:389<br>
#4 0x0805f81c in rb_raise_jump (mesg=4) at eval.c:589<br>
#5 0x0805f606 in rb_f_raise (argc=0, argv=0xb7a46044) at eval.c:519<br>
<a class="issue tracker-1 status-5 priority-4 priority-default closed behind-schedule" title="Bug: sprintf() of %f on Windows(MSVCRT) (Closed)" href="https://bugs.ruby-lang.org/issues/6">#6</a> 0x0814d8a1 in call_cfunc (func=0x805f5c3 <rb_f_raise>,<br>
recv=142587860, len=-1, argc=0, argv=0xb7a46044)<br>
at vm_insnhelper.c:314<br>
#7 0x0814d779 in vm_call_cfunc (th=0x87cb030, reg_cfp=0xb7ac5f00,<br>
num=0, recv=142587860, blockptr=0x0, me=0x880f730)<br>
at vm_insnhelper.c:401<br>
#8 0x0814cd4d in vm_call_method (th=0x87cb030, cfp=0xb7ac5f00, num=0,<br>
blockptr=0x0, flag=24, id=2752, me=0x880f730,<br>
recv=142587860) at vm_insnhelper.c:523<br>
#9 0x0814893a in vm_exec_core (th=0x87cb030, initial=0) at insns.def:1006<br>
#10 0x08155b59 in vm_exec (th=0x87cb030) at vm.c:1145<br>
<a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: prelude.c compilation problem on mswin32 (Closed)" href="https://bugs.ruby-lang.org/issues/11">#11</a> 0x081562f9 in rb_iseq_eval (iseqval=142496180) at vm.c:1372<br>
#12 0x081914b1 in rb_load_internal (fname=142497460, wrap=0) at load.c:302<br>
#13 0x081916b6 in rb_f_load (argc=1, argv=0xb7a46024) at load.c:375<br>
<a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: test issue for ruby-1.9 (Closed)" href="https://bugs.ruby-lang.org/issues/14">#14</a> 0x0814d8a1 in call_cfunc (func=0x81915ff <rb_f_load>,<br>
recv=142587860, len=-1, argc=1, argv=0xb7a46024)<br>
at vm_insnhelper.c:314<br>
#15 0x0814d779 in vm_call_cfunc (th=0x87cb030, reg_cfp=0xb7ac5f84,<br>
num=1, recv=142587860, blockptr=0x0, me=0x88476c8)<br>
at vm_insnhelper.c:401<br>
<a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: example issue for ruby-1.8 (Closed)" href="https://bugs.ruby-lang.org/issues/16">#16</a> 0x0814cd4d in vm_call_method (th=0x87cb030, cfp=0xb7ac5f84, num=1,<br>
blockptr=0x0, flag=8, id=5944, me=0x88476c8,<br>
recv=142587860) at vm_insnhelper.c:523<br>
<a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: deadlock detection for 1.9 (Closed)" href="https://bugs.ruby-lang.org/issues/17">#17</a> 0x0814893a in vm_exec_core (th=0x87cb030, initial=0) at insns.def:1006<br>
#18 0x08155b59 in vm_exec (th=0x87cb030) at vm.c:1145<br>
#19 0x08156332 in rb_iseq_eval_main (iseqval=142497640) at vm.c:1386<br>
#20 0x0805edb8 in ruby_exec_internal (n=0x87e5768) at eval.c:214<br>
<a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: should terminate @receiver_thread of Net::IMAP safely (Closed)" href="https://bugs.ruby-lang.org/issues/21">#21</a> 0x0805eec1 in ruby_exec_node (n=0x87e5768) at eval.c:261<br>
#22 0x0805ee95 in ruby_run_node (n=0x87e5768) at eval.c:254<br>
#23 0x0805d908 in main (argc=3, argv=0xbff287f4) at main.c:35<br>
(gdb)</p>
<h2>なお、これは RUBY_DEBUG=gc_stress で<br>
rubyspec/core/kernel/autoload_spec.rb というのから見つけたものです。</h2>
<p>[田中 哲][たなか あきら][Tanaka Akira]<br>
=end</p>
Ruby master - Bug #3394 (Closed): spec/rubyspec/core/array/product_spec.rb SEGV
https://bugs.ruby-lang.org/issues/3394
2010-06-06T09:09:19Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
と、いうわけで、とりあえず spec/rubyspec/core/array/product_spec.rb は<br>
SEGV するようです。</p>
<p>(RUBY_DEBUG のためコンパイルでは RUBY_DEBUG_ENV マクロをつけてあります。)</p>
<p>% RUBY_DEBUG=gc_stress ./ruby spec/mspec/bin/mspec-run -f s<br>
spec/rubyspec/core/array/product_spec.rb</p>
<p>Array#product</p>
<ul>
<li>returns converted arguments using :to_ary</li>
<li>returns the expected result</li>
<li>has no required argument</li>
<li>returns an empty array when the argument is an empty array</li>
</ul>
<p>Array#product when given a block</p>
<ul>
<li>yields all combinations in<br>
turn/home/ruby/tcio/ruby/spec/rubyspec/core/array/product_spec.rb:31:<br>
[BUG] Segmentation fault<br>
ruby 1.9.3dev (2010-06-05 trunk 28178) [i686-linux]</li>
</ul>
<h2>-- control frame ----------<br>
c:0038 p:---- s:0124 b:0124 l:000123 d:000123 CFUNC :product<br>
c:0037 p:0021 s:0119 b:0119 l:0026fc d:000118 BLOCK<br>
/home/ruby/tcio/ruby/spec/rubyspec/core/array/product_spec.rb:31<br>
c:0036 p:---- s:0116 b:0116 l:000115 d:000115 FINISH<br>
c:0035 p:---- s:0114 b:0114 l:000113 d:000113 CFUNC :instance_eval<br>
c:0034 p:0017 s:0111 b:0111 l:000110 d:000110 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:68<br>
c:0033 p:0021 s:0105 b:0105 l:000092 d:000104 BLOCK<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:179<br>
c:0032 p:---- s:0102 b:0102 l:000101 d:000101 FINISH<br>
c:0031 p:---- s:0100 b:0100 l:000095 d:000099 IFUNC<br>
c:0030 p:---- s:0098 b:0098 l:000097 d:000097 CFUNC :each<br>
c:0029 p:---- s:0096 b:0096 l:000095 d:000095 CFUNC :all?<br>
c:0028 p:0053 s:0093 b:0093 l:000092 d:000092 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:179<br>
c:0027 p:0101 s:0087 b:0087 l:000076 d:000086 BLOCK<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:207<br>
c:0026 p:---- s:0082 b:0082 l:000081 d:000081 FINISH<br>
c:0025 p:---- s:0080 b:0080 l:000079 d:000079 CFUNC :each<br>
c:0024 p:0127 s:0077 b:0077 l:000076 d:000076 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:199<br>
c:0023 p:0011 s:0074 b:0074 l:000065 d:000073 BLOCK<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:228<br>
c:0022 p:---- s:0071 b:0071 l:000070 d:000070 FINISH<br>
c:0021 p:---- s:0069 b:0069 l:000068 d:000068 CFUNC :each<br>
c:0020 p:0216 s:0066 b:0066 l:000065 d:000065 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:228<br>
c:0019 p:0109 s:0063 b:0063 l:000062 d:000062 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:37<br>
c:0018 p:0029 s:0056 b:0056 l:000055 d:000055 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/object.rb:11<br>
c:0017 p:0065 s:0049 b:0049 l:0026fc d:0026fc TOP<br>
/home/ruby/tcio/ruby/spec/rubyspec/core/array/product_spec.rb:4<br>
c:0016 p:---- s:0047 b:0047 l:000046 d:000046 FINISH<br>
c:0015 p:---- s:0045 b:0045 l:000044 d:000044 CFUNC :load<br>
c:0014 p:0018 s:0041 b:0041 l:002110 d:000040 BLOCK<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:56<br>
c:0013 p:---- s:0039 b:0039 l:000038 d:000038 FINISH<br>
c:0012 p:---- s:0037 b:0037 l:000036 d:000036 CFUNC :instance_eval<br>
c:0011 p:0017 s:0034 b:0034 l:000033 d:000033 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:68<br>
c:0010 p:0081 s:0028 b:0028 l:002110 d:001220 BLOCK<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:56<br>
c:0009 p:---- s:0025 b:0025 l:000024 d:000024 FINISH<br>
c:0008 p:---- s:0023 b:0023 l:000022 d:000022 CFUNC :each<br>
c:0007 p:0055 s:0020 b:0020 l:002110 d:002110 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:50<br>
c:0006 p:0023 s:0016 b:0016 l:000015 d:000015 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:42<br>
c:0005 p:0063 s:0013 b:0013 l:000012 d:000012 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/commands/mspec-run.rb:87<br>
c:0004 p:0098 s:0010 b:0010 l:000009 d:000009 METHOD<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/utils/script.rb:217<br>
c:0003 p:0067 s:0006 b:0006 l:0007ec d:00122c EVAL spec/mspec/bin/mspec-run:8<br>
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH<br>
c:0001 p:0000 s:0002 b:0002 l:0007ec d:0007ec TOP</h2>
<p>-- Ruby level backtrace information ----------------------------------------<br>
spec/mspec/bin/mspec-run:8:in <code><main>' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/utils/script.rb:217:in </code>main'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/commands/mspec-run.rb:87:in <code>run' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:42:in </code>process'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:50:in <code>files' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:50:in </code>each'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:56:in <code>block in files' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:68:in </code>protect'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:68:in <code>instance_eval' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:56:in </code>block<br>
(2 levels) in files'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:56:in <code>load' /home/ruby/tcio/ruby/spec/rubyspec/core/array/product_spec.rb:4:in </code><top (required)>'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/object.rb:11:in <code>describe' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:37:in </code>describe'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:228:in <code>process' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:228:in </code>each'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:228:in<br>
<code>block in process' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:199:in </code>process'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:199:in <code>each' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:207:in </code>block in process'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:179:in <code>protect' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:179:in </code>all?'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:179:in <code>each' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/context.rb:179:in </code>block in protect'<br>
/home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:68:in <code>protect' /home/ruby/tcio/ruby/spec/mspec/lib/mspec/runner/mspec.rb:68:in </code>instance_eval'<br>
/home/ruby/tcio/ruby/spec/rubyspec/core/array/product_spec.rb:31:in<br>
<code>block (4 levels) in <top (required)>' /home/ruby/tcio/ruby/spec/rubyspec/core/array/product_spec.rb:31:in </code>product'</p>
<p>-- C level backtrace information -------------------------------------------<br>
./ruby(rb_vm_bugreport+0x73) [0x8158622]<br>
./ruby [0x818d693]<br>
./ruby(rb_bug+0x36) [0x818d6ee]<br>
./ruby [0x80eedd7]<br>
[0xb7f06410]<br>
./ruby(rb_ary_entry+0x4d) [0x8166daf]<br>
./ruby [0x8170c17]<br>
./ruby [0x814d731]<br>
./ruby [0x814d609]<br>
./ruby [0x814cbdd]<br>
./ruby [0x81487ca]<br>
./ruby [0x81559e9]<br>
./ruby [0x81546ef]<br>
./ruby [0x81544d8]<br>
./ruby [0x8152ab9]<br>
./ruby [0x8152c09]<br>
./ruby(rb_obj_instance_eval+0x51) [0x8152d77]<br>
./ruby [0x814d731]<br>
./ruby [0x814d609]<br>
./ruby [0x814cbdd]<br>
./ruby [0x81487ca]<br>
./ruby [0x81559e9]<br>
./ruby [0x81546ef]<br>
./ruby [0x815477d]<br>
./ruby [0x81519b5]<br>
./ruby(rb_yield_values2+0x18) [0x8151a73]<br>
./ruby [0x818777d]<br>
./ruby [0x814564d]<br>
./ruby [0x8154722]<br>
./ruby [0x815477d]<br>
./ruby [0x81519b5]<br>
./ruby(rb_yield+0x3a) [0x815198b]<br>
./ruby(rb_ary_each+0x7c) [0x816857b]<br>
./ruby [0x814d747]<br>
./ruby [0x8150672]<br>
./ruby [0x8151744]<br>
./ruby [0x8151697]<br>
./ruby [0x8151e32]<br>
./ruby(rb_iterate+0xd4) [0x8151c79]<br>
./ruby(rb_block_call+0x3f) [0x8151e77]<br>
./ruby [0x8187814]<br>
./ruby [0x814d747]<br>
./ruby [0x814d609]<br>
./ruby [0x814cbdd]<br>
./ruby [0x81487ca]<br>
./ruby [0x81559e9]<br>
./ruby [0x81546ef]<br>
./ruby [0x815477d]<br>
./ruby [0x81519b5]<br>
./ruby(rb_yield+0x3a) [0x815198b]<br>
./ruby(rb_ary_each+0x7c) [0x816857b]<br>
./ruby [0x814d747]<br>
./ruby [0x814d609]<br>
./ruby [0x814cbdd]<br>
./ruby [0x81487ca]<br>
./ruby [0x81559e9]<br>
./ruby [0x81546ef]<br>
./ruby [0x815477d]<br>
./ruby [0x81519b5]<br>
./ruby(rb_yield+0x3a) [0x815198b]<br>
./ruby(rb_ary_each+0x7c) [0x816857b]<br>
./ruby [0x814d747]<br>
./ruby [0x814d609]<br>
./ruby [0x814cbdd]<br>
./ruby [0x81487ca]<br>
./ruby [0x81559e9]<br>
./ruby(rb_iseq_eval+0x2b) [0x8156189]<br>
./ruby [0x8191265]<br>
./ruby [0x819146a]<br>
./ruby [0x814d731]<br>
./ruby [0x814d609]<br>
./ruby [0x814cbdd]<br>
./ruby [0x81487ca]<br>
./ruby [0x81559e9]<br>
./ruby [0x81546ef]<br>
./ruby [0x81544d8]<br>
./ruby [0x8152ab9]<br>
./ruby [0x8152c09]<br>
./ruby(rb_obj_instance_eval+0x51) [0x8152d77]<br>
./ruby [0x814d731]<br>
./ruby [0x814d609]<br>
./ruby [0x814cbdd]<br>
./ruby [0x81487ca]<br>
./ruby [0x81559e9]<br>
./ruby [0x81546ef]<br>
./ruby [0x815477d]<br>
./ruby [0x81519b5]<br>
./ruby(rb_yield+0x3a) [0x815198b]<br>
./ruby(rb_ary_each+0x7c) [0x816857b]<br>
./ruby [0x814d747]<br>
./ruby [0x814d609]<br>
./ruby [0x814cbdd]<br>
./ruby [0x81487ca]<br>
./ruby [0x81559e9]<br>
./ruby(rb_iseq_eval_main+0x2b) [0x81561c2]<br>
./ruby [0x805edb8]<br>
./ruby(ruby_exec_node+0x1c) [0x805eec1]<br>
./ruby(ruby_run_node+0x3b) [0x805ee95]<br>
./ruby(main+0x74) [0x805d908]<br>
/lib/i686/cmov/libc.so.6(__libc_start_main+0xe5) [0xb7d26455]<br>
./ruby [0x805d801]</p>
<h2>[NOTE]<br>
You may have encountered a bug in the Ruby interpreter or extension libraries.<br>
Bug reports are welcome.<br>
For details: <a href="http://www.ruby-lang.org/bugreport.html" class="external">http://www.ruby-lang.org/bugreport.html</a>
</h2>
<p>[田中 哲][たなか あきら][Tanaka Akira]<br>
=end</p>
Ruby master - Bug #3377 (Closed): 100000.times { Time.allocate }: [FATAL] failed to allocate memory
https://bugs.ruby-lang.org/issues/3377
2010-06-01T23:07:58Z
akr (Akira Tanaka)
akr@fsij.org
<p>=begin<br>
以下のように<br>
[FATAL] failed to allocate memory<br>
というエラーが出ます。</p>
<p>% ./ruby -ve '100000.times { Time.allocate }'<br>
ruby 1.9.3dev (2010-05-28 trunk 28053) [i686-linux]<br>
[FATAL] failed to allocate memory</p>
<p>ここでは Time オブジェクトをたくさん生成していますが、<br>
参照はすぐに消えるはずなので、GC されてメモリは<br>
足りるはずではないでしょうか。</p>
<p>LazySweep が入る前の r28052 ではエラーにはなりませんでした。</p>
<h2>% ./ruby -ve '100000.times { Time.allocate }'<br>
ruby 1.9.3dev (2010-05-28 trunk 28052) [i686-linux]</h2>
<p>[田中 哲][たなか あきら][Tanaka Akira]<br>
=end</p>