[#18121] [Ruby 1.8.7 - Bug #405] (Open) ssl.rb:31: [BUG] Bus Error — Anonymous <redmine@...>

Issue #405 has been reported by Anonymous.

14 messages 2008/08/04

[#18130] Re: New array methods cycle, choice, shuffle (plus bug in cycle) — Brian Candler <B.Candler@...>

> Seriously though... Array.first is a noun.

10 messages 2008/08/05

[#18319] NEW Command: absolute_path() -- — "C.E. Thornton" <admin@...>

Core,

14 messages 2008/08/16
[#18321] Re: NEW Command: absolute_path() -- — Yukihiro Matsumoto <matz@...> 2008/08/18

Hi,

[#18381] [Bug #496] DRb.start_service(nil) is very slow — Hongli Lai <redmine@...>

Bug #496: DRb.start_service(nil) is very slow

11 messages 2008/08/25

[ruby-core:18362] Re: Retrieving bytecode for method

From: Michael Neumann <mneumann@...>
Date: 2008-08-21 07:56:57 UTC
List: ruby-core #18362
Michael Neumann wrote:
> Hi,
> 
> I'd like to get the bytecode of a method in Ruby 1.9. I know that I
> can compile a string or file into bytecode with:
> 
>   iseq = RubyVM::InstructionSequence.compile_file("name_of_file")
> 
> But is there a method which allows me to do access the bytecode
> of a method from a running script as shown below:
> 
>   class A
>     def b
>       1 + 2
>     end
>   end
> 
>   iseq = A.bytecode_for_method(:b) # => RubyVM::InstructionSequence

I solved this myself with extending class Method and UnboundMethod for
method #iseq. See the attached patch.

Regards,

   Michael

Attachments (1)

ruby.iseq.diff (1.2 KB, text/x-diff)
Index: proc.c
===================================================================
--- proc.c	(revision 18724)
+++ proc.c	(working copy)
@@ -1332,6 +1332,18 @@
     return method;
 }
 
+static VALUE
+method_iseq(VALUE method)
+{
+    struct METHOD *data;
+
+    Data_Get_Struct(method, struct METHOD, data);
+
+    VALUE iseqval = (VALUE)data->body->nd_body;
+
+    return iseqval;
+}
+
 int
 rb_node_arity(NODE* body)
 {
@@ -1790,6 +1802,7 @@
     rb_define_method(rb_cMethod, "name", method_name, 0);
     rb_define_method(rb_cMethod, "owner", method_owner, 0);
     rb_define_method(rb_cMethod, "unbind", method_unbind, 0);
+    rb_define_method(rb_cMethod, "iseq", method_iseq, 0);
     rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
     rb_define_method(rb_mKernel, "public_method", rb_obj_public_method, 1);
 
@@ -1807,6 +1820,7 @@
     rb_define_method(rb_cUnboundMethod, "name", method_name, 0);
     rb_define_method(rb_cUnboundMethod, "owner", method_owner, 0);
     rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1);
+    rb_define_method(rb_cUnboundMethod, "iseq", method_iseq, 0);
 
     /* Module#*_method */
     rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, 1);

In This Thread

Prev Next