Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112013-07-14T23:59:56ZRuby Issue Tracking System
Redmine Ruby master - Feature #8635 (Open): attr_accessor with default blockhttps://bugs.ruby-lang.org/issues/86352013-07-14T23:59:56Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>=begin</p>
<p>It's quite common to define attributes (like attr_reader, attr_accessor) with default values. It would be useful if Ruby provided a helper method for this case. attr_accessor and attr_reader can support this nicely using a default block:</p>
<p>class Person</p>
<a name="1-Simple-approach"></a>
<h1 >(1) Simple approach<a href="#1-Simple-approach" class="wiki-anchor">¶</a></h1>
<p>attr_writer :name<br>
def name<br>
@name ||= 'Hello'<br>
end</p>
<a name="2-nil-safe-approach"></a>
<h1 >(2) nil-safe approach<a href="#2-nil-safe-approach" class="wiki-anchor">¶</a></h1>
<p>attr_writer :name<br>
def name<br>
return @name if defined? @name<br>
@name = 'Hello'<br>
end</p>
<a name="3-This-proposal"></a>
<h1 >(3) This proposal<a href="#3-This-proposal" class="wiki-anchor">¶</a></h1>
<p>attr_accessor :name do<br>
'Hello'<br>
end<br>
end</p>
<p>p = Person.new<br>
p.instance_variable_get(:@name) # => nil<br>
p.name # => 'Hello'<br>
p.instance_variable_get(:@name) # => 'Hello'</p>
<p>Problems with current approaches:</p>
<ul>
<li>The reader and the writer looks widely different</li>
<li>Solution 1 doesn't work as intended when the default value may evaulate to nil/false</li>
<li>Solution 2 requires you to write the attribute name five times</li>
</ul>
<p>=end</p> Ruby master - Bug #8100 (Closed): Segfault in trunkhttps://bugs.ruby-lang.org/issues/81002013-03-15T20:58:31Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>=begin<br>
Full backtrace (both VM, C and Ruby) is both attached and available at <a href="https://travis-ci.org/rtomayko/tilt/jobs/5479138" class="external">https://travis-ci.org/rtomayko/tilt/jobs/5479138</a></p>
<p>I haven't been able to reproduce it (and thus I can't create a reduced test case).</p>
<p>This is the test that fails: <a href="https://github.com/rtomayko/tilt/blob/581230cbb3b314e88cf5ec9167a24ebb8acc7a93/test/tilt_compilesite_test.rb#L31" class="external">https://github.com/rtomayko/tilt/blob/581230cbb3b314e88cf5ec9167a24ebb8acc7a93/test/tilt_compilesite_test.rb#L31</a></p>
<p>The code in question will do these steps in several threads at the same time:</p>
<ul>
<li><a href="https://github.com/rtomayko/tilt/blob/581230cbb3b314e88cf5ec9167a24ebb8acc7a93/lib/tilt/template.rb#L212" class="external">https://github.com/rtomayko/tilt/blob/581230cbb3b314e88cf5ec9167a24ebb8acc7a93/lib/tilt/template.rb#L212</a></li>
<li>Define a method called "<em>tilt</em>#{Thread.current.id.abs}" on Object</li>
<li>Grab the UnboundMethod</li>
<li>Undefine the method from Object</li>
<li><a href="https://github.com/rtomayko/tilt/blob/581230cbb3b314e88cf5ec9167a24ebb8acc7a93/lib/tilt/template.rb#L144" class="external">https://github.com/rtomayko/tilt/blob/581230cbb3b314e88cf5ec9167a24ebb8acc7a93/lib/tilt/template.rb#L144</a></li>
<li>Then it binds the UnboundMethod to an object and calls it</li>
</ul>
<p>The method is doing some funky <code>class << self</code> to ensure that it gets evaluated under a proper constant scope). It's also caching the methods, so it won't always define a new method, but might re-use another UnboundMethod from a previous compilation (that might have happened on a different thread).</p>
<p>I know it's not much to go after, but at least the backtrace seems to suggest that the error happend in rb_ary_fill in array.c.</p>
<p>I've also had another report of segfault in Tilt + Ruby 2.0.0, but I don't have the full backtrace yet: <a href="https://github.com/rtomayko/tilt/issues/179" class="external">https://github.com/rtomayko/tilt/issues/179</a>. Might this be related?</p>
<p>Let me know if you need more details.<br>
=end</p> Ruby master - Feature #5669 (Rejected): Random thread scheduling based on a seedhttps://bugs.ruby-lang.org/issues/56692011-11-24T21:20:36Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>Just a little idea that popped into my head:</p>
<p>Would it be possible to have "random" thread scheduling (based on a seed)? E.g. it spends a little more time in different threads than usual?</p>
<p>This would be very useful for discovering subtle threading bugs that's often platform dependent.</p> Ruby master - Feature #5400 (Rejected): Remove flip-flops in 2.0https://bugs.ruby-lang.org/issues/54002011-10-04T16:43:20Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>Nobody knows them. Nobody uses them. Let's just get rid of flip-flops, shall we?</p> Ruby master - Bug #5204 (Closed): `defined?(@@foo) && @foo` may failhttps://bugs.ruby-lang.org/issues/52042011-08-19T19:34:45Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>defined?(@@foo) doesn't use the correct cbase.</p>
<p>See <a href="https://github.com/ruby/ruby/pull/44" class="external">https://github.com/ruby/ruby/pull/44</a> for test and patch.</p> Ruby master - Feature #5007 (Assigned): Proc#call_under: Unifying instance_eval and instance_exechttps://bugs.ruby-lang.org/issues/50072011-07-09T23:26:49Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>I'm proposing a method called <code>Proc#call_under</code> (the name could be<br>
discussed) which both unifies <code>instance_eval</code> and <code>instance_exec</code>, and makes<br>
it possible to call a <code>Proc</code> with a block and a scope:</p>
<p><code>Proc#call_under(self, *args, &blk)</code>:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">proc</span> <span class="p">{</span> <span class="nb">self</span> <span class="p">}.</span><span class="nf">call_under</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c1"># => 1</span>
<span class="nb">proc</span> <span class="p">{</span> <span class="o">|</span><span class="n">a</span><span class="o">|</span> <span class="nb">self</span> <span class="o">+</span> <span class="n">a</span> <span class="p">}.</span><span class="nf">call_under</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="c1"># => 3</span>
<span class="nb">proc</span> <span class="p">{</span> <span class="o">|&</span><span class="n">b</span><span class="o">|</span> <span class="nb">self</span> <span class="o">+</span> <span class="n">b</span><span class="p">.</span><span class="nf">call</span> <span class="p">}.</span><span class="nf">call_under</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="p">{</span> <span class="mi">2</span> <span class="p">}</span> <span class="c1"># => 4</span>
</code></pre> Backport192 - Backport #4082 (Closed): Segfault with tailcall_optimization and class definitionhttps://bugs.ruby-lang.org/issues/40822010-11-23T00:21:47Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>=begin<br>
Code:</p>
<pre><code> RubyVM::InstructionSequence.compile_option = {
:tailcall_optimization => true,
:trace_instruction => false
}
RubyVM::InstructionSequence.new(<<-EOF).eval
class Foo
def fact_helper(n, res)
if n == 1
res
else
fact_helper(n - 1, n * res)
end
end
def fact(n)
fact_helper(n, 1)
end
end
EOF
p Foo.new.fact(30000)
</code></pre>
<p>Error:</p>
<pre><code> <compiled>:6: [BUG] Segmentation fault
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
-- control frame ----------
c:0004 p:0031 s:0014 b:0011 l:000010 d:000010 METHOD <compiled>:6
c:0003 p:0078 s:0007 b:0006 l:001588 d:001e68 EVAL -:22
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:001588 d:001588 TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
-:22:in `<main>'
<compiled>:6:in `fact_helper'
-- C level backtrace information -------------------------------------------
[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
Abort trap
</code></pre>
<p>=end</p> Backport191 - Backport #3601 (Closed): class << self doesn't preserve the given blockhttps://bugs.ruby-lang.org/issues/36012010-07-22T21:35:12Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>=begin<br>
$ cat 191_bug.rb<br>
def hello<br>
class << self<br>
yield<br>
end<br>
end</p>
<p>p hello { 123 }</p>
<p>Works in 1.8.7 and 1.9.2. Fails in 1.9.1 (and JRuby + Rubinius).<br>
=end</p> Ruby master - Bug #3423 (Closed): Inconsistent behaviour of Module#const_get with included moduleshttps://bugs.ruby-lang.org/issues/34232010-06-11T04:16:18Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>=begin<br>
module Foo<br>
A = 1<br>
end</p>
<p>class Object<br>
include Foo<br>
end</p>
<p>class Bar<br>
include Foo<br>
end</p>
<p>Object.const_get(:A, false) # => works fine<br>
Bar.const_get(:A, false) # => raises error</p>
<p>Untested patch attached. This might also fix <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Object.const_get(:A, false) can access BasicObject::A (Closed)" href="https://bugs.ruby-lang.org/issues/3422">#3422</a>.<br>
=end</p> Ruby master - Bug #3422 (Closed): Object.const_get(:A, false) can access BasicObject::Ahttps://bugs.ruby-lang.org/issues/34222010-06-11T04:11:23Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>=begin<br>
From the documentation of Module#const_get(sym, inherit=true):</p>
<p>If the constant is not defined or is defined by the ancestors and inherit is false, NameError will be raised.</p>
<p>Yet, this works fine:</p>
<p>BasicObject::A = 1<br>
Object.const_get(:A, false) # => 1</p>
<p>While I haven't tested it, I believe the attached patch should fix the issue.<br>
=end</p> Ruby master - Feature #2169 (Closed): [PATCH] Improvements of Ripper's DummyParserhttps://bugs.ruby-lang.org/issues/21692009-10-01T23:18:49Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>=begin<br>
In order to properly test <a class="issue tracker-4 status-5 priority-4 priority-default closed" title="Backport: Ripper doesn't handle local variables (Closed)" href="https://bugs.ruby-lang.org/issues/1939">#1939</a>, this patch makes the following changes:</p>
<ul>
<li>Removal scanner events which simply returned the first argument. These are already generated by Ripper.</li>
<li>Many of the untested parser events had wrong number of arguments. All untested parser events are now automatically generated.</li>
<li>Basic support for blocks: parse("p { |var| 123 }") # => "[fcall(p,[],&block([var],[123]))]"</li>
</ul>
<p>These changes are fully backward-compatible, and no tests are affected.</p>
<p>The patch is created by "git diff" and should be applied by "patch -p1 < dummyparser.diff". Please let me know if you need it in another format.<br>
=end</p> Backport191 - Backport #1939 (Closed): Ripper doesn't handle local variableshttps://bugs.ruby-lang.org/issues/19392009-08-15T07:19:30Zjudofyr (Magnus Holm)judofyr@gmail.com
<p>=begin<br>
Ruby handles some code different when it encounters a local variable:</p>
<pre><code> whatever /25 # /
</code></pre>
<p>If whatever is a local variable it would be interpreted as "whatever / 25",<br>
if not, "whatever(/25 # /)". Since Ripper doesn't handle local variables, it<br>
will <em>always</em> interpreter it as the last. This makes Ripper pretty much useless<br>
because it can't guarantee to parse it equally to Ruby.<br>
=end</p>