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

ruby-changes:43583

From: ko1 <ko1@a...>
Date: Wed, 13 Jul 2016 14:26:04 +0900 (JST)
Subject: [ruby-changes:43583] ko1:r55656 (trunk): * iseq.c (Init_ISeq): undef ISeq.translate and ISeq.load_iseq

ko1	2016-07-13 14:26:00 +0900 (Wed, 13 Jul 2016)

  New Revision: 55656

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55656

  Log:
    * iseq.c (Init_ISeq): undef ISeq.translate and ISeq.load_iseq
      to prevent calling super classes' methods.
    
      Without this patch, you can write workaround like:
    
        class << RubyVM::InstructionSequence
          def translate; end
          undef translate
        end
    
    * test/ruby/test_iseq.rb: add a test.

  Modified files:
    trunk/ChangeLog
    trunk/iseq.c
    trunk/test/ruby/test_iseq.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55655)
+++ ChangeLog	(revision 55656)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 13 14:22:50 2016  Koichi Sasada  <ko1@a...>
+
+	* iseq.c (Init_ISeq): undef ISeq.translate and ISeq.load_iseq
+	  to prevent calling super classes' methods.
+
+	  Without this patch, you can write workaround like:
+
+	    class << RubyVM::InstructionSequence
+	      def translate; end
+	      undef translate
+	    end
+
+	* test/ruby/test_iseq.rb: add a test.
+
 Wed Jul 13 14:16:03 2016  Koichi Sasada  <ko1@a...>
 
 	* vm_method.c (method_entry_get_without_cache): check
Index: iseq.c
===================================================================
--- iseq.c	(revision 55655)
+++ iseq.c	(revision 55656)
@@ -2462,4 +2462,7 @@ Init_ISeq(void) https://github.com/ruby/ruby/blob/trunk/iseq.c#L2462
     rb_define_singleton_method(rb_cISeq, "disasm", iseqw_s_disasm, 1);
     rb_define_singleton_method(rb_cISeq, "disassemble", iseqw_s_disasm, 1);
     rb_define_singleton_method(rb_cISeq, "of", iseqw_s_of, 1);
+
+    rb_undef_method(CLASS_OF(rb_cISeq), "translate");
+    rb_undef_method(CLASS_OF(rb_cISeq), "load_iseq");
 }
Index: test/ruby/test_iseq.rb
===================================================================
--- test/ruby/test_iseq.rb	(revision 55655)
+++ test/ruby/test_iseq.rb	(revision 55656)
@@ -235,4 +235,14 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L235
     end
     assert_equal([m1, e1.message], [m2, e2.message], feature11951)
   end
+
+  def test_translate_by_object
+    assert_separately([], <<-"end;")
+      class Object
+        def translate
+        end
+      end
+      assert_equal(0, eval("0"))
+    end;
+  end
 end

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

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