[前][次][番号順一覧][スレッド一覧]

ruby-changes:3103

From: ko1@a...
Date: 24 Dec 2007 18:09:40 +0900
Subject: [ruby-changes:3103] ko1 - Ruby:r14595 (trunk): * iseq.c (Init_ISeq): disable ISeq.load() because there is no verifier.

ko1	2007-12-24 18:09:21 +0900 (Mon, 24 Dec 2007)

  New Revision: 14595

  Modified files:
    trunk/ChangeLog
    trunk/iseq.c
    trunk/proc.c

  Log:
    * iseq.c (Init_ISeq): disable ISeq.load() because there is no verifier.
    * iseq.c, proc.c: add ISeq.disasm(method).
    


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14595&r2=14594
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/proc.c?r1=14595&r2=14594
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/iseq.c?r1=14595&r2=14594

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14594)
+++ ChangeLog	(revision 14595)
@@ -1,3 +1,9 @@
+Mon Dec 24 18:05:09 2007  Koichi Sasada  <ko1@a...>
+
+	* iseq.c (Init_ISeq): disable ISeq.load() because there is no verifier.
+
+	* iseq.c, proc.c: add ISeq.disasm(method).
+
 Mon Dec 24 18:06:03 2007  Tanaka Akira  <akr@f...>
 
 	* eval_method.c (Init_eval_method): extracted from Init_eval
Index: iseq.c
===================================================================
--- iseq.c	(revision 14594)
+++ iseq.c	(revision 14595)
@@ -881,6 +881,23 @@
     return str;
 }
 
+static VALUE
+iseq_s_disasm(VALUE klass, VALUE body)
+{
+    extern NODE *rb_method_body(VALUE body);
+    NODE *node;
+    VALUE ret = Qnil;
+
+    if ((node = rb_method_body(body)) != 0) {
+	if (nd_type(node) == RUBY_VM_METHOD_NODE) {
+	    VALUE iseqval = (VALUE)node->nd_body;
+	    ret = ruby_iseq_disasm(iseqval);
+	}
+    }
+
+    return ret;
+}
+
 const char *
 ruby_node_name(int node)
 {
@@ -1250,16 +1267,19 @@
     rb_define_alloc_func(rb_cISeq, iseq_alloc);
     rb_define_method(rb_cISeq, "inspect", iseq_inspect, 0);
     rb_define_method(rb_cISeq, "disasm", ruby_iseq_disasm, 0);
+    rb_define_method(rb_cISeq, "disassemble", ruby_iseq_disasm, 0);
     rb_define_method(rb_cISeq, "to_a", iseq_to_a, 0);
     rb_define_method(rb_cISeq, "eval", iseq_eval, 0);
 
-    rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1);
+    /* disable this feature because there is no verifier. */
+    /* rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1); */
+
     rb_define_singleton_method(rb_cISeq, "compile", iseq_s_compile, -1);
     rb_define_singleton_method(rb_cISeq, "new", iseq_s_compile, -1);
     rb_define_singleton_method(rb_cISeq, "compile_file", iseq_s_compile_file, -1);
-    rb_define_singleton_method(rb_cISeq, "compile_option",
-			       iseq_s_compile_option_get, 0);
-    rb_define_singleton_method(rb_cISeq, "compile_option=",
-			       iseq_s_compile_option_set, 1);
+    rb_define_singleton_method(rb_cISeq, "compile_option", iseq_s_compile_option_get, 0);
+    rb_define_singleton_method(rb_cISeq, "compile_option=", iseq_s_compile_option_set, 1);
+    rb_define_singleton_method(rb_cISeq, "disasm", iseq_s_disasm, 1);
+    rb_define_singleton_method(rb_cISeq, "disassemble", iseq_s_disasm, 1);
 }
 
Index: proc.c
===================================================================
--- proc.c	(revision 14594)
+++ proc.c	(revision 14595)
@@ -652,7 +652,7 @@
  *     eval("param", b)           #=> 99
  */
 
-void
+static void
 bm_mark(struct METHOD *data)
 {
     rb_gc_mark(data->rclass);
@@ -661,6 +661,21 @@
     rb_gc_mark((VALUE)data->body);
 }
 
+NODE *
+rb_method_body(VALUE method)
+{
+    struct METHOD *data;
+
+    if (TYPE(method) == T_DATA &&
+	RDATA(method)->dmark == (RUBY_DATA_FUNC) bm_mark) {
+	Data_Get_Struct(method, struct METHOD, data);
+	return data->body;
+    }
+    else {
+	return 0;
+    }
+}
+
 NODE *rb_get_method_body(VALUE klass, ID id, ID *idp);
 
 static VALUE

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]