Ruby Issue Tracking System: Issueshttps://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112023-12-05T19:52:32ZRuby Issue Tracking System
Redmine Ruby master - Bug #20041 (Open): Array destructuring and default values in parametershttps://bugs.ruby-lang.org/issues/200412023-12-05T19:52:32Ztenderlovemaking (Aaron Patterson)tenderlove@ruby-lang.org
<p>It's possible to set the default value of a parameter to a previous parameter. For example:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">a</span><span class="p">)</span>
<span class="n">b</span>
<span class="k">end</span>
<span class="n">foo</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"># => [1, 2]</span>
</code></pre>
<p>However, if the parameters are destructured, the destructring happens <em>after</em> default parameter assignment. For example:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">foo</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span> <span class="n">b</span> <span class="o">=</span> <span class="n">x</span><span class="p">)</span>
<span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">b</span><span class="p">]</span>
<span class="k">end</span>
<span class="n">foo</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"># => [1, 2, nil]</span>
</code></pre>
<p>Is this expected behavior? I would have expected the parameters to be "evaluated" from left to right, and the array destructuring to happen <em>before</em> the default parameter assignment.</p>
<p>Thanks!</p> Ruby master - Feature #7788 (Open): YAML Tag Schema Supporthttps://bugs.ruby-lang.org/issues/77882013-02-06T05:05:55Ztrans (Thomas Sawyer)
<p>=begin<br>
I have endeavoured to add proper Schema support to Psych (see ((<YAML Spec|URL:<a href="http://www.yaml.org/spec/1.2/spec.html#Schema%3E" class="external">http://www.yaml.org/spec/1.2/spec.html#Schema></a>)) on Schemas). The primary reasons for supporting schemas are two fold: security and global tag conflict. The first is well known b/c of recent events. The second is less realized, but consider is it same problem as using global variables. Different apps have different tags; two identical local tags may have different meanings and thus cause conflict.</p>
<p>The API works like this:</p>
<pre><code>class Foo
end
foo_schema = YAML::Schema.new do |s|
s.tag '!foo', Foo
end
YAML.load('foo.yml', :schema=>foo_schema)
</code></pre>
<p>This code would allow only failsafe and json schema tags (core defaults), plus the specifically defined !foo tag.<br>
Also, %TAG prefix is supported:</p>
<pre><code>foo_schema = YAML::Schema.new(:prefix=>{'!'=>'tag:foo.org/'}) do |s|
s.tag '!foo', Foo
end
</code></pre>
<p>This will add tag 'tag:foo.org/foo<code>instead of local</code>!foo` tag.</p>
<p>To properly support schema, object's must store the tag with which they were loaded in order to ensure correct round tripping. For this there is <code>tag_uri</code> attribute.<br>
(Note: I am not sure if it best to store as instance variable, which it currently is, or to store in global table. Need feedback.)</p>
<p>In the process of adding schema support I was able to clean up and generalize loading code. For immutable types and class factories, adding (({ClassName.new_with(coder)})) can be used to instantiate class.</p>
<p>Implementation is close to complete, I believe this is all that remains:</p>
<ol>
<li>ScalarScanner needs to respect schema (basically if failsafe and/or json schemas are not used).</li>
<li>Dumping needs to take :schema option to limit it to schema tags.</li>
<li>Dumping needs to look to tag_uri for tag by default.</li>
<li>There is one bug I have yet to figure out (test_spec_builtin_map).</li>
<li>I have questions about Coder, b/c it seems more complex than it needs to be.</li>
</ol>
<p>I am also considering refactoring Schemas as modules that can be included into other schema. Currently they are classes/objects that can be subclassed or merged via <code>+</code>, e.g.</p>
<pre><code>LEGACY_SCHEMA = CORE_SCHEMA + RUBY_SCHEMA + OBJECT_SCHEMA + SYCK_SCHEMA
</code></pre>
<p>Of course, as with any new code, there's sure to be corner cases to work out. Having other pound on it for a while would be very helpful. Oh, and I should also mention I am documenting as much of the code as can.</p>
<p>Feel free to ask me any questions for more details about the code. You can find the branch here: <a href="https://github.com/trans/psych/tree/isotag" class="external">https://github.com/trans/psych/tree/isotag</a><br>
=end</p> Ruby master - Feature #7518 (Assigned): Fiddle::Pointer#to_str and Fiddle::Pointer#to_int should ...https://bugs.ruby-lang.org/issues/75182012-12-05T23:38:35Zngoto (Naohisa Goto)ngotogenome@gmail.com
<p>There are Fiddle::Pointer#to_str and to_int, to be used for implicit conversion to String and Integer, respectively. I think those implicit conversion methods should be removed.<br>
(Note that there are to_s and to_i, explicit conversion to String and Integer, respectively.)</p>
<p>About to_str: Because Fiddle::Pointer is not always a pointer of char *, and careless conversion of invalid pointer to a string would frequently cause SEGV. So, I think implicit conversion to string is very danger and it should be removed.</p>
<p>About to_int: Unlike to_str, pointer arithmetic methods are available in Fiddle::Pointer, but it lacks many methods for treating it as integer, and I think Fiddle::Pointer is not suitable for implicit conversion to integer.</p> Ruby master - Feature #7488 (Assigned): Receiving object_id in object creation probeshttps://bugs.ruby-lang.org/issues/74882012-12-01T23:24:08ZauthorNari (Narihiro Nakamura)authorNari@gmail.com
<p>Hi.</p>
<p>I want to get a object id in object creation probes to know a creation<br>
point of a suspect object.</p>
<p>I've wrote a patch for above.<br>
<a href="https://gist.github.com/4182140" class="external">https://gist.github.com/4182140</a></p>
<p>Could you check it?</p>
<a name="Im-sorry-I-dont-have-a-Mac-so-I-do-not-execute-dtraces-tests"></a>
<h1 >I'm sorry, I don't have a Mac so I do not execute dtrace's tests...<a href="#Im-sorry-I-dont-have-a-Mac-so-I-do-not-execute-dtraces-tests" class="wiki-anchor">¶</a></h1>
<p>Thanks!</p>