Feature #578
closedadd method to disassemble Proc objects
Description
=begin
Currently
RubyVM::InstructionSequence.disassemble
works only for methods.
I wasn't sure how to patch
RubyVM::InstructionSequence.disassemble
to work with proc objects AND methods, so added a new method
RubyVM::InstructionSequence.disassemble_proc
which works for proc objects, in the accompanying patch.
Either way would work.
Hope this can be included before the feature freeze, if possible :)
-=R
=end
Files
Updated by rogerdpack (Roger Pack) about 16 years ago
=begin
Question: any chance of getting this [or something like it] included before feature freezing all the way?
Thanks all. Ruby rox :)
=end
Updated by ko1 (Koichi Sasada) almost 16 years ago
- Priority changed from Normal to 3
=begin
I want to fix it with modifying ISeq#disasm to receive Proc object on 1.9.2. Sorry for late response.
=end
Updated by rogerdpack (Roger Pack) almost 16 years ago
=begin
thanks for looking into that :)
-=R
=end
Updated by rogerdpack (Roger Pack) over 15 years ago
=begin
Any progress on this? any way I can help?
Thanks!
-=r
=end
Updated by nobu (Nobuyoshi Nakada) over 15 years ago
=begin
Hi,
At Sun, 21 Sep 2008 03:02:44 +0900,
Roger Pack wrote in [ruby-core:18762]:
I wasn't sure how to patch
RubyVM::InstructionSequence.disassemble
to work with proc objects AND methods, so added a new method
RubyVM::InstructionSequence.disassemble_proc
which works for proc objects, in the accompanying patch.
Either way would work.
It's pretty easy.
Index: iseq.c
--- iseq.c (revision 23974)
+++ iseq.c (working copy)
@@ -1007,4 +1007,13 @@ iseq_s_disasm(VALUE klass, VALUE body)
}
}
-
else {
-
rb_proc_t *proc;
-
VALUE iseqval;
-
GetProcPtr(body, proc);
-
iseqval = proc->block.iseq->self;
-
if (RUBY_VM_NORMAL_ISEQ_P(iseqval)) {
-
ret = rb_iseq_disasm(iseqval);
-
}
-
}
return ret;
--
Nobu Nakada
=end
Updated by rocky (Rocky Bernstein) over 15 years ago
=begin
Another possiblility would be to add an instruction-sequence method (iseq) into Proc. Off of the instruction sequence, one could use the methods like disasm or to_a.
The actual additional code (put in the right place) for this seems pretty small:
VALUE
proc_iseq(VALUE self)
{
rb_proc_t *proc;
rb_iseq_t *iseq;
VALUE rb_iseq;
GetProcPtr(self, proc);
iseq = proc->block.iseq;
if (!iseq) return Qnil;
rb_iseq = iseq_alloc_shared(rb_cISeq);
RDATA(rb_iseq)->data = iseq;
return rb_iseq;
}
rb_define_method(rb_cProc, "iseq", proc_iseq, 0);
Warning: the above may have flaws in it.
=end
Updated by rogerdpack (Roger Pack) about 15 years ago
=begin
Would it be possible for somebody to commit this? Do we need more approval?
Thanks.
-r
=end
Updated by matz (Yukihiro Matsumoto) about 15 years ago
=begin
Hi,
In message "Re: [ruby-core:25962] [Feature #578] add method to disassemble Proc objects"
on Tue, 6 Oct 2009 20:55:57 +0900, Roger Pack redmine@ruby-lang.org writes:
|Would it be possible for somebody to commit this? Do we need more approval?
Yea, a patch from Nobu in [ruby-core:24169] needs permission from
Koichi.
matz.
=end
Updated by ko1 (Koichi Sasada) about 15 years ago
=begin
Roger Pack wrote::
Yea, a patch from Nobu in [ruby-core:24169] needs permission from
Koichi.Ok. Koichi do you have any feedback on the patch?
no. go ahead.
--
// SASADA Koichi at atdot dot net
=end
Updated by nobu (Nobuyoshi Nakada) about 15 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
Applied in changeset r25258.
=end
Updated by rogerdpack (Roger Pack) almost 15 years ago
=begin
The fact that we can get backtraces from the VM easily almost makes me wonder if the following API is possible:
Thread#backtrace_with_bindings
=>
[[file, line, method, [[:arg1_name, current_value], [:arg2_name, current_value]]
or
[[file, line, method, binding]] # so you can lookup argument values if so desired
mostly inspired by http://barelyenough.org/blog/2005/04/ruby-backtraces/ -- not sure if it's actually necessary/high priority since you can get somewhat higher quality backtraces using ruby-debug already (http://github.com/rdp/backtracer)
Thoughts?
-r
=end
Updated by marcandre (Marc-Andre Lafortune) almost 15 years ago
- Category set to core
- Status changed from Closed to Open
- Target version changed from 2.0.0 to 1.9.2
=begin
I didn't check the code, but isn't it supposed to make the following work?
$ rubydev -e 'RubyVM::InstructionSequence.disassemble(Proc.new{40+2})'
-e:1:in disassemble': wrong argument type proc (expected method) (TypeError) from -e:1:in
'
=end
Updated by rogerdpack (Roger Pack) almost 15 years ago
=begin
This diff appears to fix it, if somebody could take a look at it.
Thanks.
-r
=end
Updated by rogerdpack (Roger Pack) almost 15 years ago
- Status changed from Open to Closed
=begin
Appears fixed now. Thanks!
r26363
=end