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

ruby-changes:27860

From: nagachika <ko1@a...>
Date: Mon, 25 Mar 2013 01:02:05 +0900 (JST)
Subject: [ruby-changes:27860] nagachika:r39912 (ruby_2_0_0): merge revision(s) 39601 and 39602(partially): [Backport #7983]

nagachika	2013-03-25 01:01:49 +0900 (Mon, 25 Mar 2013)

  New Revision: 39912

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39912

  Log:
    merge revision(s) 39601 and 39602(partially): [Backport #7983]
    
    * class.c (rb_prepend_module): check redefinition of built-in optimized
      methods.  [ruby-dev:47124] [Bug #7983]
    
    * vm.c (rb_vm_check_redefinition_by_prepend): ditto.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/class.c
    branches/ruby_2_0_0/test/ruby/test_module.rb
    branches/ruby_2_0_0/version.h
    branches/ruby_2_0_0/vm.c

Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 39911)
+++ ruby_2_0_0/ChangeLog	(revision 39912)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Mon Mar 25 01:00:03 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* class.c (rb_prepend_module): check redefinition of built-in optimized
+	  methods.  [ruby-dev:47124] [Bug #7983]
+
+	* vm.c (rb_vm_check_redefinition_by_prepend): ditto.
+
 Mon Mar 25 00:51:57 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* Makefile.in (miniruby, ruby): move MAINLIBC because linker arguments
Index: ruby_2_0_0/class.c
===================================================================
--- ruby_2_0_0/class.c	(revision 39911)
+++ ruby_2_0_0/class.c	(revision 39912)
@@ -790,6 +790,7 @@ move_refined_method(st_data_t key, st_da https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/class.c#L790
 void
 rb_prepend_module(VALUE klass, VALUE module)
 {
+    void rb_vm_check_redefinition_by_prepend(VALUE klass);
     VALUE origin;
     int changed = 0;
 
@@ -816,7 +817,10 @@ rb_prepend_module(VALUE klass, VALUE mod https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/class.c#L817
     changed = include_modules_at(klass, klass, module);
     if (changed < 0)
 	rb_raise(rb_eArgError, "cyclic prepend detected");
-    if (changed) rb_clear_cache();
+    if (changed) {
+	rb_clear_cache();
+	rb_vm_check_redefinition_by_prepend(klass);
+    }
 }
 
 /*
Index: ruby_2_0_0/vm.c
===================================================================
--- ruby_2_0_0/vm.c	(revision 39911)
+++ ruby_2_0_0/vm.c	(revision 39912)
@@ -972,28 +972,54 @@ rb_iter_break_value(VALUE val) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm.c#L972
 
 static st_table *vm_opt_method_table = 0;
 
+static int
+vm_redefinition_check_flag(VALUE klass)
+{
+    if (klass == rb_cFixnum) return FIXNUM_REDEFINED_OP_FLAG;
+    if (klass == rb_cFloat)  return FLOAT_REDEFINED_OP_FLAG;
+    if (klass == rb_cString) return STRING_REDEFINED_OP_FLAG;
+    if (klass == rb_cArray)  return ARRAY_REDEFINED_OP_FLAG;
+    if (klass == rb_cHash)   return HASH_REDEFINED_OP_FLAG;
+    if (klass == rb_cBignum) return BIGNUM_REDEFINED_OP_FLAG;
+    if (klass == rb_cSymbol) return SYMBOL_REDEFINED_OP_FLAG;
+    if (klass == rb_cTime)   return TIME_REDEFINED_OP_FLAG;
+    return 0;
+}
+
 static void
 rb_vm_check_redefinition_opt_method(const rb_method_entry_t *me, VALUE klass)
 {
     st_data_t bop;
     if (!me->def || me->def->type == VM_METHOD_TYPE_CFUNC) {
 	if (st_lookup(vm_opt_method_table, (st_data_t)me, &bop)) {
-	    int flag = 0;
-
-	    if      (klass == rb_cFixnum) flag = FIXNUM_REDEFINED_OP_FLAG;
-	    else if (klass == rb_cFloat)  flag = FLOAT_REDEFINED_OP_FLAG;
-	    else if (klass == rb_cString) flag = STRING_REDEFINED_OP_FLAG;
-	    else if (klass == rb_cArray)  flag = ARRAY_REDEFINED_OP_FLAG;
-	    else if (klass == rb_cHash)   flag = HASH_REDEFINED_OP_FLAG;
-	    else if (klass == rb_cBignum) flag = BIGNUM_REDEFINED_OP_FLAG;
-	    else if (klass == rb_cSymbol) flag = SYMBOL_REDEFINED_OP_FLAG;
-	    else if (klass == rb_cTime)   flag = TIME_REDEFINED_OP_FLAG;
+	    int flag = vm_redefinition_check_flag(klass);
 
 	    ruby_vm_redefined_flag[bop] |= flag;
 	}
     }
 }
 
+static int
+check_redefined_method(st_data_t key, st_data_t value, st_data_t data)
+{
+    ID mid = (ID)key;
+    rb_method_entry_t *me = (rb_method_entry_t *)value;
+    VALUE klass = (VALUE)data;
+    rb_method_entry_t *newme = rb_method_entry(klass, mid, NULL);
+
+    if (newme != me)
+	rb_vm_check_redefinition_opt_method(me, me->klass);
+    return ST_CONTINUE;
+}
+
+void
+rb_vm_check_redefinition_by_prepend(VALUE klass)
+{
+    if (!vm_redefinition_check_flag(klass)) return;
+    st_foreach(RCLASS_M_TBL(RCLASS_ORIGIN(klass)), check_redefined_method,
+	       (st_data_t)klass);
+}
+
 static void
 add_opt_method(VALUE klass, ID mid, VALUE bop)
 {
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 39911)
+++ ruby_2_0_0/version.h	(revision 39912)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2013-03-25"
-#define RUBY_PATCHLEVEL 89
+#define RUBY_PATCHLEVEL 90
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_0_0/test/ruby/test_module.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_module.rb	(revision 39911)
+++ ruby_2_0_0/test/ruby/test_module.rb	(revision 39912)
@@ -1475,6 +1475,20 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_module.rb#L1475
     end
   end
 
+  def test_prepend_optmethod
+    bug7983 = '[ruby-dev:47124] [Bug #7983]'
+    assert_separately [], %{
+      module M
+        def /(other)
+          to_f / other
+        end
+      end
+      Fixnum.send(:prepend, M)
+      assert_equal(0.5, 1 / 2, "#{bug7983}")
+    }
+    assert_equal(0, 1 / 2)
+  end
+
   def test_class_variables
     m = Module.new
     m.class_variable_set(:@@foo, 1)

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r39601


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

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