https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-07-05T22:59:49ZRuby Issue Tracking SystemRuby master - Bug #11214: Cannot Get Correct Binding from inside of C Methodhttps://redmine.ruby-lang.org/issues/11214?journal_id=791422019-07-05T22:59:49Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>I'm fairly sure having <code>binding</code> capture arguments passed to C methods is not possible. Ruby doesn't know the C function's parameter names at runtime. Even if that were possible, you wouldn't be able to handle cases where a C function takes a variable number of arguments (<code>VALUE func(int argc, VALUE *argv, VALUE self)</code>). So that's why the binding does not include C-level information. It is similar to not being able to get the parameter names for methods defined in C via <code>Method#parameters</code>.</p>
<p>In terms of why <code>binding</code> returns variables from the surrounding scope if called from C, I'm not sure. I think the only alternative would be raising an exception. I'm guessing we don't want to change the behavior, as there are libraries that appear to be relying on it:</p>
<ul>
<li><a href="https://github.com/FluxAugur/danddnext/blob/e0c4371527569970243ca1a76768ae0ced015474/vendor/gems/interception-0.5/ext/interception.c#L31" class="external">https://github.com/FluxAugur/danddnext/blob/e0c4371527569970243ca1a76768ae0ced015474/vendor/gems/interception-0.5/ext/interception.c#L31</a></li>
<li><a href="https://github.com/Charo-IT/libgdbruby/blob/3109f4b3da26dbe7d7e723936ce332d7c57353be/libgdbruby/libgdbruby.cpp#L170" class="external">https://github.com/Charo-IT/libgdbruby/blob/3109f4b3da26dbe7d7e723936ce332d7c57353be/libgdbruby/libgdbruby.cpp#L170</a></li>
<li><a href="https://github.com/tario/evalmimic/blob/3bf84e38ceb03ffc4fe5cfd41da63bb501e0f118/ext/evalmimic_base/evalmimic_base.c#L35" class="external">https://github.com/tario/evalmimic/blob/3bf84e38ceb03ffc4fe5cfd41da63bb501e0f118/ext/evalmimic_base/evalmimic_base.c#L35</a></li>
</ul>
<p>Do you still consider this a bug?</p> Ruby master - Bug #11214: Cannot Get Correct Binding from inside of C Methodhttps://redmine.ruby-lang.org/issues/11214?journal_id=791442019-07-05T23:03:43Zchrisseaton (Chris Seaton)chris@chrisseaton.com
<ul></ul><blockquote>
<p>I'm fairly sure having binding capture arguments passed to C methods is not possible.</p>
</blockquote>
<p>TruffleRuby could do that! Sorry I know it's boasting and not relevant to MRI :)</p> Ruby master - Bug #11214: Cannot Get Correct Binding from inside of C Methodhttps://redmine.ruby-lang.org/issues/11214?journal_id=806682019-08-12T23:22:35Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Closed</i></li></ul>