[#69616] [Ruby trunk - Feature #11258] add 'x' mode character for O_EXCL — cremno@...
Issue #11258 has been updated by cremno phobia.
3 messages
2015/06/16
[#69643] [Ruby trunk - Misc #11276] [RFC] compile.c: convert to use ccan/list — normalperson@...
Issue #11276 has been updated by Eric Wong.
3 messages
2015/06/17
[#69751] [Ruby trunk - Bug #11001] 2.2.1 Segmentation fault in reserve_stack() function. — kubo@...
Issue #11001 has been updated by Takehiro Kubo.
3 messages
2015/06/27
[ruby-core:69453] [Ruby trunk - Bug #11214] [Open] Cannot Get Correct Binding from inside of C Method
From:
richard.schneeman@...
Date:
2015-06-02 23:52:30 UTC
List:
ruby-core #69453
Issue #11214 has been reported by Richard Schneeman.
----------------------------------------
Bug #11214: Cannot Get Correct Binding from inside of C Method
https://bugs.ruby-lang.org/issues/11214
* Author: Richard Schneeman
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: 2.2.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
I am trying to get the arguments passed into a method using the binding. This is possible using pure Ruby:
```ruby
class RubyBindingClass
def foo(arg = nil)
return binding
end
end
binding = RubyBindingClass.new.foo
puts binding.eval("self")
# => #<RubyBindingClass:0x007fdc5224f7f8>
puts binding.local_variables.inspect
# => [arg]
```
You can see that the `#<RubyBindingClass:0x007fdc5224f7f8>` is returned as self and the `local_variables` correctly reports that `arg` is in scope. When we access the binding from a C method, we do not get the same information
```ruby
# Thanks to Frederick Cheung for the code snippet
require 'inline' # $ gem install RubyInline
random_main_variable = 2
class CBindingClass
inline do |builder|
builder.include "<time.h>"
builder.c_raw <<-SRC, :arity => 1
VALUE foo(VALUE self, VALUE arg){
VALUE ret = rb_funcall(self, rb_intern("binding"), 0);
return ret;
}
SRC
end
end
binding = CBindingClass.new.foo(10)
puts binding.eval("self")
# => main
puts binding.local_variables.inspect
# => [:binding, :random_main_variable]
```
Here you can see that self is reported as `main` and that `local_variables` is returning variables from the main scope instead of from within the C method.
I originally stumbled upon this while trying to get access to arguments via TracePoint: http://stackoverflow.com/questions/30584454/get-method-arguments-using-rubys-tracepoint. Is this binding behavior intentional? Should it be possible to get programatic access to arguments passed into a C defined method?
--
https://bugs.ruby-lang.org/